Skip to content

Commit

Permalink
Ignore ERR_ABORT on callback on_page_failed #68
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Sep 5, 2024
1 parent 824a526 commit 406a201
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
20 changes: 11 additions & 9 deletions addons/gdcef/demos/2D/CEF.gd
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ func _on_page_loaded(brower):

# ==============================================================================
# Callback when a page has ended to load with failure.
# Display a load error message using a data: URI.
# Display an error message in a generated HTML page, using data URI.
# List of error are defined in the following file:
# gdcef/addons/gdcef/thirdparty/cef_binary/include/base/internal/cef_net_error_list.h
# ==============================================================================
func _on_page_failed_loading(aborted, msg_err, node):
# FIXME: I dunno why the radio page is considered as canceled by the user
if node.get_url() == RADIO_PAGE:
func _on_page_failed_loading(err_code, err_msg, node):
# Don't display an error for downloaded files.
if err_code == -3:
return
var html = "<html><body bgcolor=\"white\"><h2>Failed to load URL " + node.get_url()
if aborted:
html = html + " aborted by the user!</h2></body></html>"
else:
html = html + " with error " + msg_err + "!</h2></body></html>"
var html = "<html><body bgcolor=\"white\">" \
+ "<h2>Failed to load URL " + node.get_url() + "!</h2>" \
+ "<p>Error code: " + str(err_code) + "</p>" \
+ "<p>Error message: " + err_msg + "!</p>" \
+ "</body></html>"
node.load_data_uri(html, "text/html")
pass

Expand Down
7 changes: 5 additions & 2 deletions addons/gdcef/demos/3D/GUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ func _on_page_loaded(node):
# Callback when a page has ended to load with failure.
# Display a load error message using a data: URI.
# ==============================================================================
func _on_page_failed_loading(aborted, msg_err, node):
print("The browser " + node.name + " did not load " + node.get_url())
func _on_page_failed_loading(err_code, err_msg, node):
if err_code == -3:
return
push_error("The browser " + node.name + " failed loading " + \
node.get_url() + ": " + err_msg)
pass

# ==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion addons/gdcef/doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ This class is instanciate by `GDCef` by `create_browser`.
|-------------------------|-------------------------------------------------------------|-------------------|------------------------------------------------------------------------------------------------------|
| `on_browser_paint` | `node`: GDBrowserView | | Triggered when a page has been painted in the texture. |
| `on_page_loaded` | `node`: GDBrowserView | | Triggered when a page has been successfuly loaded. |
| `on_page_failed_loading` | `aborted`: bool, `err_msg`: string, `node`: GDBrowserView | | Triggered when a page has been failed loading: aborted by the user or failure |
| `on_page_failed_loading` | `err_code`: int, `err_msg`: string, `node`: GDBrowserView | | Triggered when a page has been failed loading |
11 changes: 7 additions & 4 deletions addons/gdcef/gdcef/src/gdbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void GDBrowserView::_bind_methods()
"AudioStreamGeneratorPlayback"), "set_audio_stream", "get_audio_stream");

ADD_SIGNAL(MethodInfo("on_page_loaded", PropertyInfo(Variant::OBJECT, "node")));
ADD_SIGNAL(MethodInfo("on_page_failed_loading", PropertyInfo(Variant::BOOL, "aborted"),
ADD_SIGNAL(MethodInfo("on_page_failed_loading", PropertyInfo(Variant::INT, "err_code"),
PropertyInfo(Variant::STRING, "err_msg"), PropertyInfo(Variant::OBJECT, "node")));
ADD_SIGNAL(MethodInfo("on_browser_paint", PropertyInfo(Variant::OBJECT, "node")));
ADD_SIGNAL(MethodInfo("on_html_content_requested", PropertyInfo(Variant::STRING, "html"),
Expand Down Expand Up @@ -300,15 +300,18 @@ void GDBrowserView::onLoadEnd(CefRefPtr<CefBrowser> /*browser*/,
//------------------------------------------------------------------------------
void GDBrowserView::onLoadError(CefRefPtr<CefBrowser> /*browser*/,
CefRefPtr<CefFrame> frame,
const bool aborted, const CefString& errorText)
const int errCode,
const CefString& errorText)
{
CEF_REQUIRE_UI_THREAD();

if (frame->IsMain())
{
std::string str = errorText.ToString();
BROWSER_ERROR("has failed loading " << frame->GetURL() << ": " << str);
godot::String err(str.c_str());
godot::String msg(str.c_str());
// Emit signal for Godot script
emit_signal("on_page_failed_loading", aborted, err, this);
emit_signal("on_page_failed_loading", errCode, msg, this);
}
}

Expand Down
11 changes: 8 additions & 3 deletions addons/gdcef/gdcef/src/gdbrowser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,20 @@ class GDBrowserView : public godot::Node
}

// ---------------------------------------------------------------------
//! \brief Called when a navigation fails or is canceled.
//! \brief Called when a navigation fails or is canceled. This method may
//! be called by itself if before commit or in combination with
//! OnLoadStart/OnLoadEnd if after commit. |errorCode| is the error code
//! number, |errorText| is the error text and |failedUrl| is the URL that
//! failed to load. See net\base\net_error_list.h for complete descriptions
//! of the error codes.
// ---------------------------------------------------------------------
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl) override
{
m_owner.onLoadError(browser, frame, errorCode == ERR_ABORTED, errorText);
m_owner.onLoadError(browser, frame, int(errorCode), errorText);
}

private: // CefAudioHandler interfaces
Expand Down Expand Up @@ -582,7 +587,7 @@ class GDBrowserView : public godot::Node
//! \brief Called by GDBrowserView::Impl::OnLoadError
// -------------------------------------------------------------------------
void onLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const bool aborted, const CefString& errorText);
const int errCode, const CefString& errorText);

// -------------------------------------------------------------------------
//! \brief Called on a browser audio capture thread when the browser starts
Expand Down

0 comments on commit 406a201

Please sign in to comment.