diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-01-26 15:39:10 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-03-12 13:27:21 +0000 |
commit | a984c64b0a17d62ca5cd866ad64bd0679a0cca96 (patch) | |
tree | 203e2470c5b651bf33f9d28f5b42854b3a1480a3 /src/webenginewidgets | |
parent | 2cf54e48922a7d379fb7e212966d05bc402e475d (diff) |
Clean up global profiles and ownership
This patch removes the unused global off-the-record browser-contexts
and changes all browser-contexts to be ref-counted by an API level
profile.
The API default profiles are now owned by a global QObject and are
deleted on exit.
Change-Id: Id7c9eafa24829118105f58b66663a6348216823d
Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 28 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.h | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile_p.h | 5 |
3 files changed, 17 insertions, 18 deletions
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index eb502d050..e63519d2c 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -102,15 +102,12 @@ using QtWebEngineCore::BrowserContextAdapter; \sa QWebEngineDownloadItem */ -QWebEngineProfilePrivate::QWebEngineProfilePrivate(BrowserContextAdapter* browserContext, bool ownsContext) +QWebEngineProfilePrivate::QWebEngineProfilePrivate(BrowserContextAdapter* browserContext) : scriptCollection(new QWebEngineScriptCollectionPrivate(browserContext->userScriptController())) , m_settings(new QWebEngineSettings()) - , m_browserContext(browserContext) + , m_browserContextRef(browserContext) { - if (ownsContext) - m_browserContextRef = browserContext; - - m_browserContext->setClient(this); + m_browserContextRef->addClient(this); m_settings->d_ptr->initDefaults(browserContext->isOffTheRecord()); } @@ -118,7 +115,7 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate() { delete m_settings; m_settings = 0; - m_browserContext->setClient(0); + m_browserContextRef->removeClient(this); Q_FOREACH (QWebEngineDownloadItem* download, m_ongoingDownloads) { if (download) @@ -130,7 +127,7 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate() void QWebEngineProfilePrivate::cancelDownload(quint32 downloadId) { - m_browserContext->cancelDownload(downloadId); + browserContext()->cancelDownload(downloadId); } void QWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId) @@ -196,7 +193,7 @@ void QWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info) */ QWebEngineProfile::QWebEngineProfile(QObject *parent) : QObject(parent) - , d_ptr(new QWebEngineProfilePrivate(new BrowserContextAdapter(true), true)) + , d_ptr(new QWebEngineProfilePrivate(new BrowserContextAdapter(false))) { d_ptr->q_ptr = this; } @@ -213,15 +210,16 @@ QWebEngineProfile::QWebEngineProfile(QObject *parent) */ QWebEngineProfile::QWebEngineProfile(const QString &storageName, QObject *parent) : QObject(parent) - , d_ptr(new QWebEngineProfilePrivate(new BrowserContextAdapter(storageName), true)) + , d_ptr(new QWebEngineProfilePrivate(new BrowserContextAdapter(storageName))) { d_ptr->q_ptr = this; } /*! \internal */ -QWebEngineProfile::QWebEngineProfile(QWebEngineProfilePrivate *privatePtr) - : d_ptr(privatePtr) +QWebEngineProfile::QWebEngineProfile(QWebEngineProfilePrivate *privatePtr, QObject *parent) + : QObject(parent) + , d_ptr(privatePtr) { d_ptr->q_ptr = this; } @@ -455,8 +453,10 @@ QWebEngineScriptCollection &QWebEngineProfile::scripts() */ QWebEngineProfile *QWebEngineProfile::defaultProfile() { - static QWebEngineProfile profile(new QWebEngineProfilePrivate(BrowserContextAdapter::defaultContext(), false)); - return &profile; + static QWebEngineProfile* profile = new QWebEngineProfile( + new QWebEngineProfilePrivate(BrowserContextAdapter::defaultContext()), + BrowserContextAdapter::globalQObjectRoot()); + return profile; } /*! diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h index a25cbcccd..d65db24ab 100644 --- a/src/webenginewidgets/api/qwebengineprofile.h +++ b/src/webenginewidgets/api/qwebengineprofile.h @@ -107,7 +107,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QWebEngineProfile) - QWebEngineProfile(QWebEngineProfilePrivate *); + QWebEngineProfile(QWebEngineProfilePrivate *, QObject *parent = 0); friend class QWebEnginePagePrivate; friend class QWebEngineUrlSchemeHandler; diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h index 6ae9f9ca9..b0bfc88b9 100644 --- a/src/webenginewidgets/api/qwebengineprofile_p.h +++ b/src/webenginewidgets/api/qwebengineprofile_p.h @@ -55,10 +55,10 @@ class QWebEngineSettings; class QWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient { public: Q_DECLARE_PUBLIC(QWebEngineProfile) - QWebEngineProfilePrivate(QtWebEngineCore::BrowserContextAdapter* browserContext, bool ownsContext); + QWebEngineProfilePrivate(QtWebEngineCore::BrowserContextAdapter* browserContext); ~QWebEngineProfilePrivate(); - QtWebEngineCore::BrowserContextAdapter *browserContext() const { return m_browserContext; } + QtWebEngineCore::BrowserContextAdapter *browserContext() const { return m_browserContextRef.data(); } QWebEngineSettings *settings() const { return m_settings; } void cancelDownload(quint32 downloadId); @@ -76,7 +76,6 @@ public: private: QWebEngineProfile *q_ptr; QWebEngineSettings *m_settings; - QtWebEngineCore::BrowserContextAdapter *m_browserContext; QExplicitlySharedDataPointer<QtWebEngineCore::BrowserContextAdapter> m_browserContextRef; QMap<quint32, QPointer<QWebEngineDownloadItem> > m_ongoingDownloads; QMap<QByteArray, QPointer<QWebEngineUrlSchemeHandler> > m_urlSchemeHandlers; |