diff options
| author | Kaloyan Chehlarski <kaloyan.chehlarski@qt.io> | 2025-08-29 11:39:10 +0200 |
|---|---|---|
| committer | Kaloyan Chehlarski <kaloyan.chehlarski@qt.io> | 2025-09-03 15:05:22 +0200 |
| commit | 5c29704a2ed0003edcf9ee7e591e4d392cce4d04 (patch) | |
| tree | ac3efe39af65b87e0631d56b04b154005c9ada65 /src | |
| parent | 1880d612336e616f8fc5f35e4a73c1ec8c619356 (diff) | |
WebView2: Block creation of new windows not controlled by Qt
By default, an unhandled NewWindowRequested event will trigger
the creation of a window not controlled by us, and which can
outive the spawning process. This is inconsistent with other backends,
so handle the event and don't pass a window handle so the new window is
never created in the first place.
Fixes: QTBUG-139641
Pick-to: 6.10
Change-Id: I75ed8ae376be1695f0f75c7286fed7dd3c7b3670
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/windows/qwebview2webview.cpp | 19 | ||||
| -rw-r--r-- | src/plugins/windows/qwebview2webview_p.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/plugins/windows/qwebview2webview.cpp b/src/plugins/windows/qwebview2webview.cpp index c1f5444..ff179c8 100644 --- a/src/plugins/windows/qwebview2webview.cpp +++ b/src/plugins/windows/qwebview2webview.cpp @@ -239,6 +239,16 @@ void QWebView2WebViewPrivate::initialize(HWND hWnd) &token); Q_ASSERT_SUCCEEDED(hr); + hr = m_webview->add_NewWindowRequested( + Microsoft::WRL::Callback<ICoreWebView2NewWindowRequestedEventHandler>( + [this](ICoreWebView2 *webview, + ICoreWebView2NewWindowRequestedEventArgs *args) -> HRESULT { + return this->onNewWindowRequested(webview, args); + }) + .Get(), + &token); + Q_ASSERT_SUCCEEDED(hr); + ComPtr<ICoreWebView2_22> webview22; hr = m_webview->QueryInterface(IID_PPV_ARGS(&webview22)); Q_ASSERT_SUCCEEDED(hr); @@ -606,6 +616,15 @@ HRESULT QWebView2WebViewPrivate::onContentLoading(ICoreWebView2* webview, ICoreW return S_OK; } +HRESULT QWebView2WebViewPrivate::onNewWindowRequested(ICoreWebView2* webview, ICoreWebView2NewWindowRequestedEventArgs* args) +{ + Q_UNUSED(webview); + // This blocks the spawning of new windows we don't control + // FIXME actually handle new windows when QWebView has the API for them + args->put_Handled(TRUE); + return S_OK; +} + void QWebView2WebViewPrivate::updateWindowGeometry() { if (m_webviewController) { diff --git a/src/plugins/windows/qwebview2webview_p.h b/src/plugins/windows/qwebview2webview_p.h index 5273ce5..09f2dd8 100644 --- a/src/plugins/windows/qwebview2webview_p.h +++ b/src/plugins/windows/qwebview2webview_p.h @@ -89,6 +89,7 @@ private Q_SLOTS: HRESULT onNavigationCompleted(ICoreWebView2* webview, ICoreWebView2NavigationCompletedEventArgs* args); HRESULT onWebResourceRequested(ICoreWebView2* sender, ICoreWebView2WebResourceRequestedEventArgs* args); HRESULT onContentLoading(ICoreWebView2* webview, ICoreWebView2ContentLoadingEventArgs* args); + HRESULT onNewWindowRequested(ICoreWebView2* webview, ICoreWebView2NewWindowRequestedEventArgs* args); void updateWindowGeometry(); void initialize(HWND hWnd); |
