Send WEBVIEW_ERROR event after CEF finishing loading.
Currently, WEBVIEW_ERROR event is sent to client on CEF::OnLoadError(), which may cause the error message of wxInfoBar disapear. CEF::OnLoadEnd will be invoked after CEF::OnloadError, if WEBVIEW_ERROR event get processed before CEF::LoadEnd, the wxInfoBar's message will disappear since the webpage will get loaded in CEF::LoadEnd. CEF will return "data:text/html,chromewebdata" when url is invalid.
This commit is contained in:
parent
450bece977
commit
cd7df9c28b
2 changed files with 14 additions and 12 deletions
|
|
@ -39,7 +39,7 @@ class ClientHandler : public CefClient,
|
|||
public CefLoadHandler
|
||||
{
|
||||
public:
|
||||
ClientHandler() {};
|
||||
ClientHandler():m_loadErrorCode(-1) {};
|
||||
virtual ~ClientHandler() {};
|
||||
|
||||
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() { return this; }
|
||||
|
|
@ -108,7 +108,9 @@ private:
|
|||
CefRefPtr<CefBrowser> m_browser;
|
||||
wxWebViewChromium *m_webview;
|
||||
int m_browserId;
|
||||
|
||||
// Record the load error code: enum wxWebViewNavigationError
|
||||
// -1 means no error.
|
||||
int m_loadErrorCode;
|
||||
IMPLEMENT_REFCOUNTING(ClientHandler);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -554,9 +554,17 @@ void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|||
wxString url = frame->GetURL().ToString();
|
||||
wxString target = frame->GetName().ToString();
|
||||
|
||||
// Send webview_error event in case of loading error.
|
||||
if (m_loadErrorCode != -1)
|
||||
{
|
||||
m_loadErrorCode = -1;
|
||||
wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_ERROR, m_webview->GetId(), url, target);
|
||||
event.SetEventObject(m_webview);
|
||||
m_webview->HandleWindowEvent(event);
|
||||
}
|
||||
|
||||
wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATED, m_webview->GetId(), url, target);
|
||||
event.SetEventObject(m_webview);
|
||||
|
||||
m_webview->HandleWindowEvent(event);
|
||||
|
||||
if(frame->IsMain())
|
||||
|
|
@ -659,13 +667,5 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
|||
ERROR_TYPE_CASE(ERR_CACHE_MISS, wxWEBVIEW_NAV_ERR_OTHER);
|
||||
ERROR_TYPE_CASE(ERR_INSECURE_RESPONSE, wxWEBVIEW_NAV_ERR_SECURITY);
|
||||
}
|
||||
|
||||
wxString url = failedUrl.ToString();
|
||||
wxString target = frame->GetName().ToString();
|
||||
wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_ERROR, m_webview->GetId(), url, target);
|
||||
event.SetEventObject(m_webview);
|
||||
event.SetInt(type);
|
||||
event.SetString(errorText.ToString());
|
||||
|
||||
m_webview->HandleWindowEvent(event);
|
||||
m_loadErrorCode = type;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue