[go: nahoru, domu]

Skip to content

Commit

Permalink
Webview: Filter context menu on windows
Browse files Browse the repository at this point in the history
# Conflicts:
#	IPlug/Extras/WebView/IPlugWebView.cpp
  • Loading branch information
olilarkin committed Mar 17, 2024
1 parent 5cccba0 commit c867f6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
18 changes: 10 additions & 8 deletions IPlug/Extras/WebView/IPlugWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ void* IWebView::OpenWebView(void* pParent, float x, float y, float w, float h, f
->CreateCoreWebView2Controller(
mParentWnd,
Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
[&, x, y, w, h](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {
if (controller != nullptr) {
[&, x, y, w, h, enableDevTools](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {
if (controller != nullptr)
{
mWebViewCtrlr = controller;
mWebViewCtrlr->get_CoreWebView2(&mWebViewWnd);
}
Expand All @@ -73,15 +74,16 @@ void* IWebView::OpenWebView(void* pParent, float x, float y, float w, float h, f
Settings->put_IsScriptEnabled(TRUE);
Settings->put_AreDefaultScriptDialogsEnabled(TRUE);
Settings->put_IsWebMessageEnabled(TRUE);
Settings->put_AreDefaultContextMenusEnabled(FALSE);
Settings->put_AreDefaultContextMenusEnabled(enableDevTools);
Settings->put_AreDevToolsEnabled(enableDevTools);

// this script adds a function IPlugSendMsg that is used to call the platform webview messaging function in JS
mWebViewWnd->AddScriptToExecuteOnDocumentCreated(L"function IPlugSendMsg(m) {window.chrome.webview.postMessage(m)};",
Callback<ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler>(
[this](HRESULT error, PCWSTR id) -> HRESULT {
return S_OK;
}).Get());
mCoreWebView->AddScriptToExecuteOnDocumentCreated(
L"function IPlugSendMsg(m) {window.chrome.webview.postMessage(m)};",
Callback<ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler>([this](HRESULT error,
PCWSTR id) -> HRESULT {
return S_OK;
}).Get());

mWebViewWnd->add_WebMessageReceived(
Callback<ICoreWebView2WebMessageReceivedEventHandler>(
Expand Down
1 change: 1 addition & 0 deletions IPlug/Extras/WebView/IPlugWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class IWebView
wil::com_ptr<ICoreWebView2> mWebViewWnd;
EventRegistrationToken mWebMessageReceivedToken;
EventRegistrationToken mNavigationCompletedToken;
EventRegistrationToken mContextMenuRequestedToken;
bool mShowOnLoad = true;
#endif
};
Expand Down

0 comments on commit c867f6f

Please sign in to comment.