From 04d22cc9f67955250efa3ce94e67f42a2fed95ad Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 26 Feb 2021 16:50:48 +0100 Subject: [PATCH] Add RemoveScriptMessage handler and return bool --- include/wx/osx/webview_webkit.h | 3 ++- include/wx/webview.h | 3 ++- src/osx/webview_webkit.mm | 9 ++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index 8b31ffdd34..e7900cfbb8 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -89,7 +89,8 @@ public: virtual bool IsEditable() const wxOVERRIDE; bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE; - virtual void AddScriptMessageHandler(const wxString& name) wxOVERRIDE; + virtual bool AddScriptMessageHandler(const wxString& name) wxOVERRIDE; + virtual bool RemoveScriptMessageHandler(const wxString& name) wxOVERRIDE; //Virtual Filesystem Support virtual void RegisterHandler(wxSharedPtr handler) wxOVERRIDE; diff --git a/include/wx/webview.h b/include/wx/webview.h index 987f3bdb1f..aadba6bfc7 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -182,7 +182,8 @@ public: virtual void RegisterHandler(wxSharedPtr handler) = 0; virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) = 0; virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const = 0; - virtual void AddScriptMessageHandler(const wxString& WXUNUSED(name)) { } + virtual bool AddScriptMessageHandler(const wxString& WXUNUSED(name)) { return false; } + virtual bool RemoveScriptMessageHandler(const wxString& WXUNUSED(name)) { return false; } virtual void SetEditable(bool enable = true) = 0; void SetPage(const wxString& html, const wxString& baseUrl) { diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index fe76d79883..9e3abda81a 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -394,10 +394,17 @@ bool wxWebViewWebKit::RunScript(const wxString& javascript, wxString* output) co return true; } -void wxWebViewWebKit::AddScriptMessageHandler(const wxString& name) +bool wxWebViewWebKit::AddScriptMessageHandler(const wxString& name) { [m_webView.configuration.userContentController addScriptMessageHandler: [[WebViewScriptMessageHandler alloc] initWithWxWindow:this] name:wxCFStringRef(name).AsNSString()]; + return true; +} + +bool wxWebViewWebKit::RemoveScriptMessageHandler(const wxString& name) +{ + [m_webView.configuration.userContentController removeScriptMessageHandlerForName:wxCFStringRef(name).AsNSString()]; + return true; } void wxWebViewWebKit::LoadURL(const wxString& url)