diff --git a/include/wx/webview.h b/include/wx/webview.h index 7771f4797b..987f3bdb1f 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -270,9 +270,10 @@ public: wxWebViewEvent() {} wxWebViewEvent(wxEventType type, int id, const wxString& url, const wxString target, - wxWebViewNavigationActionFlags flags = wxWEBVIEW_NAV_ACTION_NONE) + wxWebViewNavigationActionFlags flags = wxWEBVIEW_NAV_ACTION_NONE, + const wxString& messageHandler = wxString()) : wxNotifyEvent(type, id), m_url(url), m_target(target), - m_actionFlags(flags) + m_actionFlags(flags), m_messageHandler(messageHandler) {} @@ -280,12 +281,14 @@ public: const wxString& GetTarget() const { return m_target; } wxWebViewNavigationActionFlags GetNavigationAction() const { return m_actionFlags; } + const wxString& GetMessageHandler() const { return m_messageHandler; } virtual wxEvent* Clone() const wxOVERRIDE { return new wxWebViewEvent(*this); } private: wxString m_url; wxString m_target; wxWebViewNavigationActionFlags m_actionFlags; + wxString m_messageHandler; wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent); }; diff --git a/interface/wx/webview.h b/interface/wx/webview.h index dced7e269a..942bcf845e 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -1111,7 +1111,8 @@ public: wxWebViewEvent(); wxWebViewEvent(wxEventType type, int id, const wxString href, const wxString target, - wxWebViewNavigationActionFlags flags = wxWEBVIEW_NAV_ACTION_NONE); + wxWebViewNavigationActionFlags flags = wxWEBVIEW_NAV_ACTION_NONE, + const wxString& messageHandler = wxString()); /** Get the name of the target frame which the url of this event @@ -1132,6 +1133,14 @@ public: @since 3.1.2 */ wxWebViewNavigationActionFlags GetNavigationAction() const; + + /** + Get the name of the script handler. Only valid for events of type + @c wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED + + @since 3.1.5 + */ + const wxString& GetMessageHandler() const; }; diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 792430b167..2084857801 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -910,7 +910,7 @@ void WebFrame::OnFullScreenChanged(wxWebViewEvent & evt) void WebFrame::OnScriptMessage(wxWebViewEvent& evt) { - wxLogMessage("Script message recieved; value = %s", evt.GetString()); + wxLogMessage("Script message recieved; value = %s, handler = %s", evt.GetString(), evt.GetMessageHandler()); } void WebFrame::OnSetPage(wxCommandEvent& WXUNUSED(evt)) diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index 56647b98ed..fe76d79883 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -923,7 +923,9 @@ WX_API_AVAILABLE_MACOS(10, 12) wxWebViewEvent event(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, webKitWindow->GetId(), webKitWindow->GetCurrentURL(), - ""); + "", + wxWEBVIEW_NAV_ACTION_NONE, + wxCFStringRef::AsString(message.name)); if ([message.body isKindOfClass:NSString.class]) event.SetString(wxCFStringRef::AsString(message.body)); else if ([message.body isKindOfClass:NSNumber.class])