From b4a6f39ab2d6ebb21b38b577ee432749afbb26dc Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 15 Jun 2017 09:22:37 -0700 Subject: [PATCH] Use HandleWindowEvent() from C callbacks Avoids issues with exceptions. Also remove worthless null pointer checks, the pointer has already been dereferenced, and GetEventHandler() never returns NULL --- src/gtk/webview_webkit.cpp | 26 ++++++++------------------ src/gtk/webview_webkit2.cpp | 25 ++++++++----------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index a5b0a526f0..44c95e3dab 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -63,8 +63,7 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget, webKitCtrl->GetId(), url, target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); } else if (status == WEBKIT_LOAD_COMMITTED) { @@ -73,8 +72,7 @@ wxgtk_webview_webkit_load_status(GtkWidget* widget, webKitCtrl->GetId(), url, target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); } } @@ -99,9 +97,8 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, wxString(uri, wxConvUTF8), target); - if(webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); - + webKitCtrl->HandleWindowEvent(event); + webkit_web_policy_decision_ignore(policy_decision); return TRUE; } @@ -123,8 +120,7 @@ wxgtk_webview_webkit_navigation(WebKitWebView *, wxString( uri, wxConvUTF8 ), target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); if (!event.IsAllowed()) { @@ -297,10 +293,7 @@ wxgtk_webview_webkit_error(WebKitWebView*, event.SetString(description); event.SetInt(type); - if (webKitWindow && webKitWindow->GetEventHandler()) - { - webKitWindow->GetEventHandler()->ProcessEvent(event); - } + webKitWindow->HandleWindowEvent(event); return FALSE; } @@ -321,8 +314,7 @@ wxgtk_webview_webkit_new_window(WebKitWebView*, wxString( uri, wxConvUTF8 ), target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); //We always want the user to handle this themselves webkit_web_policy_decision_ignore(policy_decision); @@ -341,9 +333,7 @@ wxgtk_webview_webkit_title_changed(WebKitWebView*, ""); event.SetString(wxString(title, wxConvUTF8)); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); - + webKitCtrl->HandleWindowEvent(event); } static void diff --git a/src/gtk/webview_webkit2.cpp b/src/gtk/webview_webkit2.cpp index 42f9387160..e2591f6636 100644 --- a/src/gtk/webview_webkit2.cpp +++ b/src/gtk/webview_webkit2.cpp @@ -44,8 +44,7 @@ wxgtk_webview_webkit_load_changed(GtkWidget *, webKitCtrl->GetId(), url, target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); } else if (load_event == WEBKIT_LOAD_COMMITTED) { @@ -54,8 +53,7 @@ wxgtk_webview_webkit_load_changed(GtkWidget *, webKitCtrl->GetId(), url, target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); } } @@ -80,9 +78,8 @@ wxgtk_webview_webkit_navigation(WebKitWebView *web_view, wxString(uri, wxConvUTF8), target); - if(webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); - + webKitCtrl->HandleWindowEvent(event); + webkit_policy_decision_ignore(decision); return TRUE; } @@ -104,8 +101,7 @@ wxgtk_webview_webkit_navigation(WebKitWebView *web_view, wxString( uri, wxConvUTF8 ), target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); if (!event.IsAllowed()) { @@ -256,10 +252,7 @@ wxgtk_webview_webkit_load_failed(WebKitWebView *, event.SetString(description); event.SetInt(type); - if (webKitWindow && webKitWindow->GetEventHandler()) - { - webKitWindow->GetEventHandler()->ProcessEvent(event); - } + webKitWindow->HandleWindowEvent(event); return FALSE; } @@ -279,8 +272,7 @@ wxgtk_webview_webkit_new_window(WebKitPolicyDecision *decision, wxString( uri, wxConvUTF8 ), target); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); //We always want the user to handle this themselves webkit_policy_decision_ignore(decision); @@ -318,8 +310,7 @@ wxgtk_webview_webkit_title_changed(GtkWidget* widget, ""); event.SetString(wxString(title, wxConvUTF8)); - if (webKitCtrl && webKitCtrl->GetEventHandler()) - webKitCtrl->GetEventHandler()->ProcessEvent(event); + webKitCtrl->HandleWindowEvent(event); g_free(title); }