diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2020-04-23 12:55:58 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2020-04-26 18:10:39 +0200 |
commit | 6c7148af789af401b39f0283f8060624432c5b56 (patch) | |
tree | 81988d97a69741602f80ae7e31f0982c0f1a3f0e /src/core | |
parent | d4004e30ba9a09f75a810d4734dd6be18616b5e5 (diff) |
Restore behavior of OpenURLFromTab if createWindow returns this
Instead of using QSharedPointer's reference count to communicate
adoption/non-adoption, change adoptNewWindow to return a adapter pointer, with
null meaning non-adoption. Then change QWebEnginePage's implementation to reuse
already existing adapters if possible, restoring previous behavior of
OpenURLFromTab when createWindow returns this.
Task-number: QTBUG-80596
Change-Id: I8ee7c31e4294aabd3207c504cba67d6171c66cb0
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/web_contents_adapter_client.h | 5 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 13 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.h | 5 |
3 files changed, 16 insertions, 7 deletions
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 250801f51..04df99f0e 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -469,7 +469,10 @@ public: virtual void loadFinished(bool success, const QUrl &url, bool isErrorPage = false, int errorCode = 0, const QString &errorDescription = QString()) = 0; virtual void focusContainer() = 0; virtual void unhandledKeyEvent(QKeyEvent *event) = 0; - virtual void adoptNewWindow(QSharedPointer<WebContentsAdapter> newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect & initialGeometry, const QUrl &targetUrl) = 0; + virtual QSharedPointer<WebContentsAdapter> + adoptNewWindow(QSharedPointer<WebContentsAdapter> newWebContents, + WindowOpenDisposition disposition, bool userGesture, + const QRect &initialGeometry, const QUrl &targetUrl) = 0; virtual bool isBeingAdopted() = 0; virtual void close() = 0; virtual void windowCloseRejected() = 0; diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 3c37286f8..216e4faf1 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -663,14 +663,17 @@ void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *webCont m_viewClient->webEngineSettings()->overrideWebPreferences(webContents, webPreferences); } -QWeakPointer<WebContentsAdapter> WebContentsDelegateQt::createWindow(std::unique_ptr<content::WebContents> new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) +QSharedPointer<WebContentsAdapter> +WebContentsDelegateQt::createWindow(std::unique_ptr<content::WebContents> new_contents, + WindowOpenDisposition disposition, const gfx::Rect &initial_pos, + bool user_gesture) { QSharedPointer<WebContentsAdapter> newAdapter = QSharedPointer<WebContentsAdapter>::create(std::move(new_contents)); - m_viewClient->adoptNewWindow(newAdapter, static_cast<WebContentsAdapterClient::WindowOpenDisposition>(disposition), user_gesture, toQt(initial_pos), m_initialTargetUrl); - - // If the client didn't reference the adapter, it will be deleted now, and the weak pointer zeroed. - return newAdapter; + return m_viewClient->adoptNewWindow( + std::move(newAdapter), + static_cast<WebContentsAdapterClient::WindowOpenDisposition>(disposition), user_gesture, + toQt(initial_pos), m_initialTargetUrl); } void WebContentsDelegateQt::allowCertificateError(const QSharedPointer<CertificateErrorController> &errorController) diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index a8c9561ea..bfef9a1df 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -201,7 +201,10 @@ public: base::WeakPtr<WebContentsDelegateQt> AsWeakPtr() { return m_weakPtrFactory.GetWeakPtr(); } private: - QWeakPointer<WebContentsAdapter> createWindow(std::unique_ptr<content::WebContents> new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture); + QSharedPointer<WebContentsAdapter> + createWindow(std::unique_ptr<content::WebContents> new_contents, + WindowOpenDisposition disposition, const gfx::Rect &initial_pos, + bool user_gesture); void EmitLoadStarted(const QUrl &url, bool isErrorPage = false); void EmitLoadFinished(bool success, const QUrl &url, bool isErrorPage = false, int errorCode = 0, const QString &errorDescription = QString()); void EmitLoadCommitted(); |