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/core | |
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/core')
-rw-r--r-- | src/core/browser_context_adapter.cpp | 14 | ||||
-rw-r--r-- | src/core/browser_context_adapter.h | 13 | ||||
-rw-r--r-- | src/core/download_manager_delegate_qt.cpp | 18 | ||||
-rw-r--r-- | src/core/web_engine_context.cpp | 10 | ||||
-rw-r--r-- | src/core/web_engine_context.h | 11 |
5 files changed, 45 insertions, 21 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; }; |