diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-06-30 17:41:31 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-07-01 18:31:43 +0000 |
commit | 06864c75f4d009bf8fd4e9f88215bb88341ed873 (patch) | |
tree | ad39aa23e8cc53b3c79a8717ada6aa71371e1a0c /src/core | |
parent | ea503a2f07f2505d8d91a7d7999a1fb1b1d6b57c (diff) |
Switch WebContentsAdapter to using shared pointers
QExplicitSharedDataPointer is meant for value objects, not for shared
objects. Instead switch to using QSharedPointer.
Change-Id: Ib3791bbcfde627a67508f2819e141d8c538a4a50
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 6 | ||||
-rw-r--r-- | src/core/web_contents_adapter.h | 6 | ||||
-rw-r--r-- | src/core/web_contents_adapter_client.h | 2 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 17 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.h | 2 | ||||
-rw-r--r-- | src/core/web_engine_settings.h | 1 |
6 files changed, 13 insertions, 21 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 709efe9b3..f447b5480 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -321,14 +321,14 @@ WebContentsAdapterPrivate::~WebContentsAdapterPrivate() webContents.reset(); } -QExplicitlySharedDataPointer<WebContentsAdapter> WebContentsAdapter::createFromSerializedNavigationHistory(QDataStream &input, WebContentsAdapterClient *adapterClient) +QSharedPointer<WebContentsAdapter> WebContentsAdapter::createFromSerializedNavigationHistory(QDataStream &input, WebContentsAdapterClient *adapterClient) { int currentIndex; ScopedVector<content::NavigationEntry> entries; deserializeNavigationHistory(input, ¤tIndex, &entries, adapterClient->browserContextAdapter()->browserContext()); if (currentIndex == -1) - return QExplicitlySharedDataPointer<WebContentsAdapter>(); + return QSharedPointer<WebContentsAdapter>(); // Unlike WebCore, Chromium only supports Restoring to a new WebContents instance. content::WebContents* newWebContents = createBlankWebContents(adapterClient, adapterClient->browserContextAdapter()->browserContext()); @@ -346,7 +346,7 @@ QExplicitlySharedDataPointer<WebContentsAdapter> WebContentsAdapter::createFromS content::ChildProcessSecurityPolicy::GetInstance()->GrantReadFile(id, *file); } - return QExplicitlySharedDataPointer<WebContentsAdapter>(new WebContentsAdapter(newWebContents)); + return QSharedPointer<WebContentsAdapter>::create(newWebContents); } WebContentsAdapter::WebContentsAdapter(content::WebContents *webContents) diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index ce033bdb4..0d9218d38 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -41,7 +41,7 @@ #include "web_contents_adapter_client.h" #include <QScopedPointer> -#include <QSharedData> +#include <QSharedPointer> #include <QString> #include <QUrl> @@ -61,9 +61,9 @@ class BrowserContextQt; class MessagePassingInterface; class WebContentsAdapterPrivate; -class QWEBENGINE_EXPORT WebContentsAdapter : public QSharedData { +class QWEBENGINE_EXPORT WebContentsAdapter : public QEnableSharedFromThis<WebContentsAdapter> { public: - static QExplicitlySharedDataPointer<WebContentsAdapter> createFromSerializedNavigationHistory(QDataStream &input, WebContentsAdapterClient *adapterClient); + static QSharedPointer<WebContentsAdapter> createFromSerializedNavigationHistory(QDataStream &input, WebContentsAdapterClient *adapterClient); // Takes ownership of the WebContents. WebContentsAdapter(content::WebContents *webContents = 0); ~WebContentsAdapter(); diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index f0927c9e5..449f382cf 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -206,7 +206,7 @@ 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(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect & initialGeometry) = 0; + virtual void adoptNewWindow(QSharedPointer<WebContentsAdapter> newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect & initialGeometry) = 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 bf12537d1..97f0e515d 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -93,7 +93,7 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents { content::WebContents *target = source; if (params.disposition != CURRENT_TAB) { - WebContentsAdapter *targetAdapter = createWindow(0, params.disposition, gfx::Rect(), params.user_gesture); + QSharedPointer<WebContentsAdapter> targetAdapter = createWindow(0, params.disposition, gfx::Rect(), params.user_gesture); if (targetAdapter) target = targetAdapter->webContents(); } @@ -139,7 +139,7 @@ bool WebContentsDelegateQt::ShouldPreserveAbortedURLs(content::WebContents *sour void WebContentsDelegateQt::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture, bool* was_blocked) { Q_UNUSED(source) - WebContentsAdapter *newAdapter = createWindow(new_contents, disposition, initial_pos, user_gesture); + QWeakPointer<WebContentsAdapter> newAdapter = createWindow(new_contents, disposition, initial_pos, user_gesture); if (was_blocked) *was_blocked = !newAdapter; } @@ -372,20 +372,13 @@ void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *, conte m_viewClient->webEngineSettings()->overrideWebPreferences(webPreferences); } -WebContentsAdapter *WebContentsDelegateQt::createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) +QWeakPointer<WebContentsAdapter> WebContentsDelegateQt::createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) { - WebContentsAdapter *newAdapter = new WebContentsAdapter(new_contents); - // Do the first ref-count manually to be able to know if the application is handling adoptNewWindow through the public API. - newAdapter->ref.ref(); + QSharedPointer<WebContentsAdapter> newAdapter = QSharedPointer<WebContentsAdapter>::create(new_contents); m_viewClient->adoptNewWindow(newAdapter, static_cast<WebContentsAdapterClient::WindowOpenDisposition>(disposition), user_gesture, toQt(initial_pos)); - if (!newAdapter->ref.deref()) { - // adoptNewWindow didn't increase the ref-count, newAdapter and its new_contents (if non-null) need to be discarded. - delete newAdapter; - newAdapter = 0; - } - + // If the client didn't reference the adapter, it will be deleted now, and the weak pointer zeroed. return newAdapter; } diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index 7ead8dc7c..9aace06dd 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -117,7 +117,7 @@ public: void launchExternalURL(const QUrl &url, ui::PageTransition page_transition, bool is_main_frame); private: - WebContentsAdapter *createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture); + QWeakPointer<WebContentsAdapter> createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture); WebContentsAdapterClient *m_viewClient; QString m_lastSearchedString; diff --git a/src/core/web_engine_settings.h b/src/core/web_engine_settings.h index 3d3d734d0..3036a31a6 100644 --- a/src/core/web_engine_settings.h +++ b/src/core/web_engine_settings.h @@ -39,7 +39,6 @@ #include "qtwebenginecoreglobal.h" -#include <QExplicitlySharedDataPointer> #include <QScopedPointer> #include <QHash> #include <QUrl> |