diff --git a/addons/gdcef/demos/2D/CEF.gd b/addons/gdcef/demos/2D/CEF.gd index 97ea241..33f2575 100644 --- a/addons/gdcef/demos/2D/CEF.gd +++ b/addons/gdcef/demos/2D/CEF.gd @@ -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 = "

Failed to load URL " + node.get_url() - if aborted: - html = html + " aborted by the user!

" - else: - html = html + " with error " + msg_err + "!" + var html = "" \ + + "

Failed to load URL " + node.get_url() + "!

" \ + + "

Error code: " + str(err_code) + "

" \ + + "

Error message: " + err_msg + "!

" \ + + "" node.load_data_uri(html, "text/html") pass diff --git a/addons/gdcef/demos/3D/GUI.gd b/addons/gdcef/demos/3D/GUI.gd index 3062135..04a24ea 100644 --- a/addons/gdcef/demos/3D/GUI.gd +++ b/addons/gdcef/demos/3D/GUI.gd @@ -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 # ============================================================================== diff --git a/addons/gdcef/gdcef/src/gdbrowser.cpp b/addons/gdcef/gdcef/src/gdbrowser.cpp index 3a0bd35..2d339f8 100644 --- a/addons/gdcef/gdcef/src/gdbrowser.cpp +++ b/addons/gdcef/gdcef/src/gdbrowser.cpp @@ -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"), @@ -300,15 +300,18 @@ void GDBrowserView::onLoadEnd(CefRefPtr /*browser*/, //------------------------------------------------------------------------------ void GDBrowserView::onLoadError(CefRefPtr /*browser*/, CefRefPtr 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); } } diff --git a/addons/gdcef/gdcef/src/gdbrowser.hpp b/addons/gdcef/gdcef/src/gdbrowser.hpp index 141187c..383fe9d 100644 --- a/addons/gdcef/gdcef/src/gdbrowser.hpp +++ b/addons/gdcef/gdcef/src/gdbrowser.hpp @@ -217,7 +217,12 @@ 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 browser, CefRefPtr frame, @@ -225,7 +230,7 @@ class GDBrowserView : public godot::Node 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 @@ -582,7 +587,7 @@ class GDBrowserView : public godot::Node //! \brief Called by GDBrowserView::Impl::OnLoadError // ------------------------------------------------------------------------- void onLoadError(CefRefPtr browser, CefRefPtr 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