diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-08-16 14:51:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-08-23 15:10:33 +0000 |
commit | 8a4091c2104913294b4dc7b06c8e9fb2c022f51e (patch) | |
tree | f7564d80d440fcb94849eb3026001f7dc81a634f /src | |
parent | e9b510bbf2b1311761c2a2f98d4410ab9b17f9e5 (diff) |
Fix crash when trying to navigate in new window but is blocked
Ensure that if QWebEnginePage::createWindow returns 'this' that we fall
back to navigating in current tab.
Change-Id: Idffe25dcafaaf3c824815b3cf1f0e400eaec2923
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 11 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 97f0e515d..5e9157069 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -97,6 +97,7 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents if (targetAdapter) target = targetAdapter->webContents(); } + Q_ASSERT(target); content::NavigationController::LoadURLParams load_url_params(params.url); load_url_params.referrer = params.referrer; diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index dbbac1aed..f10833b9b 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -279,9 +279,14 @@ void QWebEnginePagePrivate::adoptNewWindow(QSharedPointer<WebContentsAdapter> ne if (newPage->d_func() == this) { // If createWindow returns /this/ we must delay the adoption. Q_ASSERT(q == newPage); - QTimer::singleShot(0, q, [this, newPage, newWebContents, initialGeometry] () { - adoptNewWindowImpl(newPage, newWebContents, initialGeometry); - }); + // WebContents might be null if we just opened a new page for navigation, in that case + // avoid referencing newWebContents so that it is deleted and WebContentsDelegateQt::OpenURLFromTab + // will fall back to navigating current page. + if (newWebContents->webContents()) { + QTimer::singleShot(0, q, [this, newPage, newWebContents, initialGeometry] () { + adoptNewWindowImpl(newPage, newWebContents, initialGeometry); + }); + } } else { adoptNewWindowImpl(newPage, newWebContents, initialGeometry); } |