Implement AddUserScript() for edge backend
This commit is contained in:
@@ -38,6 +38,8 @@ public:
|
|||||||
wxString m_pendingURL;
|
wxString m_pendingURL;
|
||||||
int m_pendingContextMenuEnabled;
|
int m_pendingContextMenuEnabled;
|
||||||
int m_pendingAccessToDevToolsEnabled;
|
int m_pendingAccessToDevToolsEnabled;
|
||||||
|
wxVector<wxString> m_pendingUserScripts;
|
||||||
|
wxVector<wxString> m_userScriptIds;
|
||||||
wxString m_scriptMsgHandlerName;
|
wxString m_scriptMsgHandlerName;
|
||||||
|
|
||||||
// WebView Events tokens
|
// WebView Events tokens
|
||||||
@@ -59,6 +61,7 @@ public:
|
|||||||
HRESULT OnContentLoading(ICoreWebView2* sender, ICoreWebView2ContentLoadingEventArgs* args);
|
HRESULT OnContentLoading(ICoreWebView2* sender, ICoreWebView2ContentLoadingEventArgs* args);
|
||||||
HRESULT OnContainsFullScreenElementChanged(ICoreWebView2* sender, IUnknown* args);
|
HRESULT OnContainsFullScreenElementChanged(ICoreWebView2* sender, IUnknown* args);
|
||||||
HRESULT OnWebMessageReceived(ICoreWebView2* sender, ICoreWebView2WebMessageReceivedEventArgs* args);
|
HRESULT OnWebMessageReceived(ICoreWebView2* sender, ICoreWebView2WebMessageReceivedEventArgs* args);
|
||||||
|
HRESULT OnAddScriptToExecuteOnDocumentedCreatedCompleted(HRESULT errorCode, LPCWSTR id);
|
||||||
|
|
||||||
HRESULT OnEnvironmentCreated(HRESULT result, ICoreWebView2Environment* environment);
|
HRESULT OnEnvironmentCreated(HRESULT result, ICoreWebView2Environment* environment);
|
||||||
HRESULT OnWebViewCreated(HRESULT result, ICoreWebView2Controller* webViewController);
|
HRESULT OnWebViewCreated(HRESULT result, ICoreWebView2Controller* webViewController);
|
||||||
|
@@ -92,6 +92,9 @@ public:
|
|||||||
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE;
|
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE;
|
||||||
virtual bool AddScriptMessageHandler(const wxString& name) wxOVERRIDE;
|
virtual bool AddScriptMessageHandler(const wxString& name) wxOVERRIDE;
|
||||||
virtual bool RemoveScriptMessageHandler(const wxString& name) wxOVERRIDE;
|
virtual bool RemoveScriptMessageHandler(const wxString& name) wxOVERRIDE;
|
||||||
|
virtual bool AddUserScript(const wxString& javascript,
|
||||||
|
wxWebViewUserScriptInjectionTime injectionTime = wxWEBVIEW_INJECT_AT_DOCUMENT_START) wxOVERRIDE;
|
||||||
|
virtual void RemoveAllUserScripts() wxOVERRIDE;
|
||||||
|
|
||||||
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
|
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
|
||||||
|
|
||||||
|
@@ -423,6 +423,14 @@ HRESULT wxWebViewEdgeImpl::OnWebViewCreated(HRESULT result, ICoreWebView2Control
|
|||||||
settings->put_IsWebMessageEnabled(!m_scriptMsgHandlerName.empty());
|
settings->put_IsWebMessageEnabled(!m_scriptMsgHandlerName.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_pendingUserScripts.empty())
|
||||||
|
{
|
||||||
|
for (wxVector<wxString>::iterator it = m_pendingUserScripts.begin();
|
||||||
|
it != m_pendingUserScripts.end(); ++it)
|
||||||
|
m_ctrl->AddUserScript(*it);
|
||||||
|
m_pendingUserScripts.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_pendingURL.empty())
|
if (!m_pendingURL.empty())
|
||||||
{
|
{
|
||||||
m_ctrl->LoadURL(m_pendingURL);
|
m_ctrl->LoadURL(m_pendingURL);
|
||||||
@@ -834,6 +842,46 @@ bool wxWebViewEdge::RemoveScriptMessageHandler(const wxString& WXUNUSED(name))
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT wxWebViewEdgeImpl::OnAddScriptToExecuteOnDocumentedCreatedCompleted(HRESULT errorCode, LPCWSTR id)
|
||||||
|
{
|
||||||
|
if (SUCCEEDED(errorCode))
|
||||||
|
m_userScriptIds.push_back(id);
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxWebViewEdge::AddUserScript(const wxString& javascript,
|
||||||
|
wxWebViewUserScriptInjectionTime injectionTime)
|
||||||
|
{
|
||||||
|
// Currently only AT_DOCUMENT_START is supported
|
||||||
|
if (injectionTime != wxWEBVIEW_INJECT_AT_DOCUMENT_START)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_impl->m_webView)
|
||||||
|
{
|
||||||
|
HRESULT hr = m_impl->m_webView->AddScriptToExecuteOnDocumentCreated(javascript.wc_str(),
|
||||||
|
Callback<ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler>(m_impl,
|
||||||
|
&wxWebViewEdgeImpl::OnAddScriptToExecuteOnDocumentedCreatedCompleted).Get());
|
||||||
|
if (FAILED(hr))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_impl->m_pendingUserScripts.push_back(javascript);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxWebViewEdge::RemoveAllUserScripts()
|
||||||
|
{
|
||||||
|
m_impl->m_pendingUserScripts.clear();
|
||||||
|
for (wxVector<wxString>::iterator it = m_impl->m_userScriptIds.begin();
|
||||||
|
it != m_impl->m_userScriptIds.end(); ++it)
|
||||||
|
{
|
||||||
|
HRESULT hr = m_impl->m_webView->RemoveScriptToExecuteOnDocumentCreated(it->wc_str());
|
||||||
|
if (FAILED(hr))
|
||||||
|
wxLogApiError("RemoveScriptToExecuteOnDocumentCreated", hr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxWebViewEdge::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
|
void wxWebViewEdge::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
|
||||||
{
|
{
|
||||||
// TODO: could maybe be implemented via IWebView2WebView5::add_WebResourceRequested
|
// TODO: could maybe be implemented via IWebView2WebView5::add_WebResourceRequested
|
||||||
|
Reference in New Issue
Block a user