Implement script message for edge backend

This commit is contained in:
Tobias Taschner 2021-02-15 16:15:29 +01:00
parent 011035ef08
commit edcaf5210e
No known key found for this signature in database
GPG Key ID: AE6ECD71294F87FD
2 changed files with 21 additions and 0 deletions

View File

@ -47,6 +47,7 @@ public:
EventRegistrationToken m_documentTitleChangedToken = { };
EventRegistrationToken m_contentLoadingToken = { };
EventRegistrationToken m_containsFullScreenElementChangedToken = { };
EventRegistrationToken m_webMessageReceivedToken = { };
// WebView Event handlers
HRESULT OnNavigationStarting(ICoreWebView2* sender, ICoreWebView2NavigationStartingEventArgs* args);
@ -56,6 +57,7 @@ public:
HRESULT OnDocumentTitleChanged(ICoreWebView2* sender, IUnknown* args);
HRESULT OnContentLoading(ICoreWebView2* sender, ICoreWebView2ContentLoadingEventArgs* args);
HRESULT OnContainsFullScreenElementChanged(ICoreWebView2* sender, IUnknown* args);
HRESULT OnWebMessageReceived(ICoreWebView2* sender, ICoreWebView2WebMessageReceivedEventArgs* args);
HRESULT OnEnvironmentCreated(HRESULT result, ICoreWebView2Environment* environment);
HRESULT OnWebViewCreated(HRESULT result, ICoreWebView2Controller* webViewController);

View File

@ -73,6 +73,7 @@ wxWebViewEdgeImpl::~wxWebViewEdgeImpl()
m_webView->remove_DocumentTitleChanged(m_documentTitleChangedToken);
m_webView->remove_ContentLoading(m_contentLoadingToken);
m_webView->remove_ContainsFullScreenElementChanged(m_containsFullScreenElementChangedToken);
m_webView->remove_WebMessageReceived(m_webMessageReceivedToken);
}
}
@ -318,6 +319,20 @@ HRESULT wxWebViewEdgeImpl::OnContainsFullScreenElementChanged(ICoreWebView2* WXU
return S_OK;
}
HRESULT wxWebViewEdgeImpl::OnWebMessageReceived(ICoreWebView2* WXUNUSED(sender), ICoreWebView2WebMessageReceivedEventArgs* args)
{
wxCoTaskMemPtr<wchar_t> msgContent;
wxWebViewEvent event(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, m_ctrl->GetId(),
m_ctrl->GetCurrentURL(), wxString());
event.SetEventObject(m_ctrl);
if (SUCCEEDED(args->get_WebMessageAsJson(&msgContent)))
event.SetString(wxString(msgContent));
m_ctrl->HandleWindowEvent(event);
return S_OK;
}
HRESULT wxWebViewEdgeImpl::OnWebViewCreated(HRESULT result, ICoreWebView2Controller* webViewController)
{
if (FAILED(result))
@ -367,6 +382,10 @@ HRESULT wxWebViewEdgeImpl::OnWebViewCreated(HRESULT result, ICoreWebView2Control
Callback<ICoreWebView2ContainsFullScreenElementChangedEventHandler>(
this, &wxWebViewEdgeImpl::OnContainsFullScreenElementChanged).Get(),
&m_containsFullScreenElementChangedToken);
m_webView->add_WebMessageReceived(
Callback<ICoreWebView2WebMessageReceivedEventHandler>(
this, &wxWebViewEdgeImpl::OnWebMessageReceived).Get(),
&m_webMessageReceivedToken);
if (m_pendingContextMenuEnabled != -1)
{