summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-01-26 15:39:10 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-03-12 13:27:21 +0000
commita984c64b0a17d62ca5cd866ad64bd0679a0cca96 (patch)
tree203e2470c5b651bf33f9d28f5b42854b3a1480a3
parent2cf54e48922a7d379fb7e212966d05bc402e475d (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>
-rw-r--r--src/core/browser_context_adapter.cpp14
-rw-r--r--src/core/browser_context_adapter.h13
-rw-r--r--src/core/download_manager_delegate_qt.cpp18
-rw-r--r--src/core/web_engine_context.cpp10
-rw-r--r--src/core/web_engine_context.h11
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp26
-rw-r--r--src/webengine/api/qquickwebengineprofile_p.h2
-rw-r--r--src/webengine/api/qquickwebengineprofile_p_p.h5
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp28
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.h2
-rw-r--r--src/webenginewidgets/api/qwebengineprofile_p.h5
11 files changed, 78 insertions, 56 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index cb606a8b5..fa51575e3 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -72,7 +72,6 @@ BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord)
, m_httpCacheType(DiskHttpCache)
, m_persistentCookiesPolicy(AllowPersistentCookies)
, m_visitedLinksPolicy(TrackVisitedLinksOnDisk)
- , m_client(0)
, m_httpCacheMaxSize(0)
{
}
@@ -133,9 +132,14 @@ DownloadManagerDelegateQt *BrowserContextAdapter::downloadManagerDelegate()
return m_downloadManagerDelegate.data();
}
-void BrowserContextAdapter::setClient(BrowserContextAdapterClient *adapterClient)
+void BrowserContextAdapter::addClient(BrowserContextAdapterClient *adapterClient)
{
- m_client = adapterClient;
+ m_clients.append(adapterClient);
+}
+
+void BrowserContextAdapter::removeClient(BrowserContextAdapterClient *adapterClient)
+{
+ m_clients.removeOne(adapterClient);
}
void BrowserContextAdapter::cancelDownload(quint32 downloadId)
@@ -148,9 +152,9 @@ BrowserContextAdapter* BrowserContextAdapter::defaultContext()
return WebEngineContext::current()->defaultBrowserContext();
}
-BrowserContextAdapter* BrowserContextAdapter::offTheRecordContext()
+QObject* BrowserContextAdapter::globalQObjectRoot()
{
- return WebEngineContext::current()->offTheRecordBrowserContext();
+ return WebEngineContext::current()->globalQObject();
}
QString BrowserContextAdapter::dataPath() const
diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h
index 0e5a3605d..42787bc23 100644
--- a/src/core/browser_context_adapter.h
+++ b/src/core/browser_context_adapter.h
@@ -39,15 +39,17 @@
#include "qtwebenginecoreglobal.h"
+#include <QList>
#include <QScopedPointer>
#include <QSharedData>
#include <QString>
#include <QVector>
+QT_FORWARD_DECLARE_CLASS(QObject)
+
namespace QtWebEngineCore {
class BrowserContextAdapterClient;
-
class BrowserContextQt;
class CustomUrlSchemeHandler;
class DownloadManagerDelegateQt;
@@ -62,14 +64,15 @@ public:
virtual ~BrowserContextAdapter();
static BrowserContextAdapter* defaultContext();
- static BrowserContextAdapter* offTheRecordContext();
+ static QObject* globalQObjectRoot();
WebEngineVisitedLinksManager *visitedLinksManager();
DownloadManagerDelegateQt *downloadManagerDelegate();
- BrowserContextAdapterClient* client() { return m_client; }
+ QList<BrowserContextAdapterClient*> clients() { return m_clients; }
+ void addClient(BrowserContextAdapterClient *adapterClient);
+ void removeClient(BrowserContextAdapterClient *adapterClient);
- void setClient(BrowserContextAdapterClient *adapterClient);
void cancelDownload(quint32 downloadId);
BrowserContextQt *browserContext();
@@ -144,7 +147,7 @@ private:
PersistentCookiesPolicy m_persistentCookiesPolicy;
VisitedLinksPolicy m_visitedLinksPolicy;
QVector<CustomUrlSchemeHandler*> m_customUrlSchemeHandlers;
- BrowserContextAdapterClient *m_client;
+ QList<BrowserContextAdapterClient*> m_clients;
int m_httpCacheMaxSize;
Q_DISABLE_COPY(BrowserContextAdapter)
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index e84ca5f2c..c01dcf63d 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -127,7 +127,8 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
}
item->AddObserver(this);
- if (m_contextAdapter->client()) {
+ QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
+ if (!clients.isEmpty()) {
BrowserContextAdapterClient::DownloadItemInfo info = {
item->GetId(),
toQt(item->GetURL()),
@@ -137,7 +138,12 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
suggestedFilePath,
false /* accepted */
};
- m_contextAdapter->client()->downloadRequested(info);
+
+ Q_FOREACH (BrowserContextAdapterClient *client, clients) {
+ client->downloadRequested(info);
+ if (info.accepted)
+ break;
+ }
suggestedFile.setFile(info.path);
@@ -173,7 +179,8 @@ void DownloadManagerDelegateQt::GetSaveDir(content::BrowserContext* browser_cont
void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *download)
{
- if (m_contextAdapter->client()) {
+ QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
+ if (!clients.isEmpty()) {
BrowserContextAdapterClient::DownloadItemInfo info = {
download->GetId(),
toQt(download->GetURL()),
@@ -183,7 +190,10 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
QString(),
true /* accepted */
};
- m_contextAdapter->client()->downloadUpdated(info);
+
+ Q_FOREACH (BrowserContextAdapterClient *client, clients) {
+ client->downloadUpdated(info);
+ }
}
}
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index 5d8fe79e6..b830110a7 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -138,6 +138,9 @@ bool usingQtQuick2DRenderer()
WebEngineContext::~WebEngineContext()
{
+ m_defaultBrowserContext = 0;
+ delete m_globalQObject;
+ m_globalQObject = 0;
base::MessagePump::Delegate *delegate = m_runLoop->loop_;
// Flush the UI message loop before quitting.
while (delegate->DoWork()) { }
@@ -162,11 +165,9 @@ BrowserContextAdapter* WebEngineContext::defaultBrowserContext()
return m_defaultBrowserContext.data();
}
-BrowserContextAdapter* WebEngineContext::offTheRecordBrowserContext()
+QObject *WebEngineContext::globalQObject()
{
- if (!m_offTheRecordBrowserContext)
- m_offTheRecordBrowserContext = new BrowserContextAdapter(true);
- return m_offTheRecordBrowserContext.data();
+ return m_globalQObject;
}
#ifndef CHROMIUM_VERSION
@@ -178,6 +179,7 @@ WebEngineContext::WebEngineContext()
: m_mainDelegate(new ContentMainDelegateQt)
, m_contentRunner(content::ContentMainRunner::Create())
, m_browserRunner(content::BrowserMainRunner::Create())
+ , m_globalQObject(new QObject())
{
QList<QByteArray> args;
Q_FOREACH (const QString& arg, QCoreApplication::arguments())
diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h
index 5f45aad98..a3795b0a9 100644
--- a/src/core/web_engine_context.h
+++ b/src/core/web_engine_context.h
@@ -37,6 +37,8 @@
#ifndef WEB_ENGINE_CONTEXT_H
#define WEB_ENGINE_CONTEXT_H
+#include "qtwebenginecoreglobal.h"
+
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -51,19 +53,22 @@ class BrowserMainRunner;
class ContentMainRunner;
}
+QT_FORWARD_DECLARE_CLASS(QObject)
+
namespace QtWebEngineCore {
+
class BrowserContextAdapter;
class ContentMainDelegateQt;
class DevToolsHttpHandlerDelegateQt;
class SurfaceFactoryQt;
-}
+} // namespace
class WebEngineContext : public base::RefCounted<WebEngineContext> {
public:
static scoped_refptr<WebEngineContext> current();
QtWebEngineCore::BrowserContextAdapter *defaultBrowserContext();
- QtWebEngineCore::BrowserContextAdapter *offTheRecordBrowserContext();
+ QObject *globalQObject();
private:
friend class base::RefCounted<WebEngineContext>;
@@ -77,8 +82,8 @@ private:
#if defined(OS_ANDROID)
scoped_ptr<QtWebEngineCore::SurfaceFactoryQt> m_surfaceFactory;
#endif
+ QObject* m_globalQObject;
QExplicitlySharedDataPointer<QtWebEngineCore::BrowserContextAdapter> m_defaultBrowserContext;
- QExplicitlySharedDataPointer<QtWebEngineCore::BrowserContextAdapter> m_offTheRecordBrowserContext;
scoped_ptr<QtWebEngineCore::DevToolsHttpHandlerDelegateQt> m_devtools;
};
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index 718007c35..545352861 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -50,20 +50,17 @@ using QtWebEngineCore::BrowserContextAdapter;
QT_BEGIN_NAMESPACE
-QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(BrowserContextAdapter* browserContext, bool ownsContext)
+QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(BrowserContextAdapter* browserContext)
: m_settings(new QQuickWebEngineSettings())
- , 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());
}
QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate()
{
- m_browserContext->setClient(0);
+ m_browserContextRef->removeClient(this);
Q_FOREACH (QQuickWebEngineDownloadItem* download, m_ongoingDownloads) {
if (download)
@@ -75,7 +72,7 @@ QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate()
void QQuickWebEngineProfilePrivate::cancelDownload(quint32 downloadId)
{
- m_browserContext->cancelDownload(downloadId);
+ browserContext()->cancelDownload(downloadId);
}
void QQuickWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId)
@@ -161,13 +158,14 @@ void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info
*/
QQuickWebEngineProfile::QQuickWebEngineProfile()
- : d_ptr(new QQuickWebEngineProfilePrivate(new BrowserContextAdapter(false), true))
+ : d_ptr(new QQuickWebEngineProfilePrivate(new BrowserContextAdapter(false)))
{
d_ptr->q_ptr = this;
}
-QQuickWebEngineProfile::QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *privatePtr)
- : d_ptr(privatePtr)
+QQuickWebEngineProfile::QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *privatePtr, QObject *parent)
+ : QObject(parent)
+ , d_ptr(privatePtr)
{
d_ptr->q_ptr = this;
}
@@ -399,8 +397,10 @@ void QQuickWebEngineProfile::setHttpCacheMaximumSize(int maximumSize)
QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
{
- static QQuickWebEngineProfile profile(new QQuickWebEngineProfilePrivate(BrowserContextAdapter::defaultContext(), false));
- return &profile;
+ static QQuickWebEngineProfile *profile = new QQuickWebEngineProfile(
+ new QQuickWebEngineProfilePrivate(BrowserContextAdapter::defaultContext()),
+ BrowserContextAdapter::globalQObjectRoot());
+ return profile;
}
QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h
index ee91d7728..3978fc5e0 100644
--- a/src/webengine/api/qquickwebengineprofile_p.h
+++ b/src/webengine/api/qquickwebengineprofile_p.h
@@ -121,7 +121,7 @@ signals:
private:
Q_DECLARE_PRIVATE(QQuickWebEngineProfile)
- QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *);
+ QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *, QObject *parent = 0);
QQuickWebEngineSettings *settings() const;
friend class QQuickWebEngineSettings;
diff --git a/src/webengine/api/qquickwebengineprofile_p_p.h b/src/webengine/api/qquickwebengineprofile_p_p.h
index 0cf11acec..a702a8a1d 100644
--- a/src/webengine/api/qquickwebengineprofile_p_p.h
+++ b/src/webengine/api/qquickwebengineprofile_p_p.h
@@ -52,10 +52,10 @@ class QQuickWebEngineSettings;
class QQuickWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient {
public:
Q_DECLARE_PUBLIC(QQuickWebEngineProfile)
- QQuickWebEngineProfilePrivate(QtWebEngineCore::BrowserContextAdapter* browserContext, bool ownsContext);
+ QQuickWebEngineProfilePrivate(QtWebEngineCore::BrowserContextAdapter* browserContext);
~QQuickWebEngineProfilePrivate();
- QtWebEngineCore::BrowserContextAdapter *browserContext() const { return m_browserContext; }
+ QtWebEngineCore::BrowserContextAdapter *browserContext() const { return m_browserContextRef.data(); }
QQuickWebEngineSettings *settings() const { return m_settings.data(); }
void cancelDownload(quint32 downloadId);
@@ -68,7 +68,6 @@ private:
friend class QQuickWebEngineViewPrivate;
QQuickWebEngineProfile *q_ptr;
QScopedPointer<QQuickWebEngineSettings> m_settings;
- QtWebEngineCore::BrowserContextAdapter *m_browserContext;
QExplicitlySharedDataPointer<QtWebEngineCore::BrowserContextAdapter> m_browserContextRef;
QMap<quint32, QPointer<QQuickWebEngineDownloadItem> > m_ongoingDownloads;
};
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;