Identify script handler in message event

This commit is contained in:
Tobias Taschner
2021-02-26 16:45:50 +01:00
parent c78147b267
commit c3d0d7d000
4 changed files with 19 additions and 5 deletions

View File

@@ -270,9 +270,10 @@ public:
wxWebViewEvent() {} wxWebViewEvent() {}
wxWebViewEvent(wxEventType type, int id, const wxString& url, wxWebViewEvent(wxEventType type, int id, const wxString& url,
const wxString target, 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), : 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; } const wxString& GetTarget() const { return m_target; }
wxWebViewNavigationActionFlags GetNavigationAction() const { return m_actionFlags; } wxWebViewNavigationActionFlags GetNavigationAction() const { return m_actionFlags; }
const wxString& GetMessageHandler() const { return m_messageHandler; }
virtual wxEvent* Clone() const wxOVERRIDE { return new wxWebViewEvent(*this); } virtual wxEvent* Clone() const wxOVERRIDE { return new wxWebViewEvent(*this); }
private: private:
wxString m_url; wxString m_url;
wxString m_target; wxString m_target;
wxWebViewNavigationActionFlags m_actionFlags; wxWebViewNavigationActionFlags m_actionFlags;
wxString m_messageHandler;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent); wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
}; };

View File

@@ -1111,7 +1111,8 @@ public:
wxWebViewEvent(); wxWebViewEvent();
wxWebViewEvent(wxEventType type, int id, const wxString href, wxWebViewEvent(wxEventType type, int id, const wxString href,
const wxString target, 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 Get the name of the target frame which the url of this event
@@ -1132,6 +1133,14 @@ public:
@since 3.1.2 @since 3.1.2
*/ */
wxWebViewNavigationActionFlags GetNavigationAction() const; 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;
}; };

View File

@@ -910,7 +910,7 @@ void WebFrame::OnFullScreenChanged(wxWebViewEvent & evt)
void WebFrame::OnScriptMessage(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)) void WebFrame::OnSetPage(wxCommandEvent& WXUNUSED(evt))

View File

@@ -923,7 +923,9 @@ WX_API_AVAILABLE_MACOS(10, 12)
wxWebViewEvent event(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, wxWebViewEvent event(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED,
webKitWindow->GetId(), webKitWindow->GetId(),
webKitWindow->GetCurrentURL(), webKitWindow->GetCurrentURL(),
""); "",
wxWEBVIEW_NAV_ACTION_NONE,
wxCFStringRef::AsString(message.name));
if ([message.body isKindOfClass:NSString.class]) if ([message.body isKindOfClass:NSString.class])
event.SetString(wxCFStringRef::AsString(message.body)); event.SetString(wxCFStringRef::AsString(message.body));
else if ([message.body isKindOfClass:NSNumber.class]) else if ([message.body isKindOfClass:NSNumber.class])