summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2018-01-12 13:44:07 +0100
committerMichal Klocek <michal.klocek@qt.io>2018-05-23 09:42:34 +0000
commitf012238341216c2355dc724ea8e7de74fa764cc0 (patch)
tree1aef35f411c4e1e788e191ad5809771572bc0841
parent45ec7b64755546438943caf68629dc84e0068d36 (diff)
Track BrowserContextAdapter in WebEngineContext
Instead of keeping BrowserContextAdapter as a child of global object add them to the list kept by WebEngineContext. Change-Id: I626ca6ff6dec3eb76530e3cfb6d589cb961a5795 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/browser_context_adapter.cpp19
-rw-r--r--src/core/net/url_request_custom_job_proxy.cpp1
-rw-r--r--src/core/web_engine_context.cpp26
-rw-r--r--src/core/web_engine_context.h7
4 files changed, 38 insertions, 15 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index 75f936f21..2b12b8bd3 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -76,29 +76,25 @@ inline QString buildLocationFromStandardPath(const QString &standardPath, const
namespace QtWebEngineCore {
-BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord)
- : QObject(BrowserContextAdapter::globalQObjectRoot())
- , m_offTheRecord(offTheRecord)
+BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord):
+ m_offTheRecord(offTheRecord)
, m_browserContext(new BrowserContextQt(this))
, m_httpCacheType(DiskHttpCache)
, m_persistentCookiesPolicy(AllowPersistentCookies)
, m_visitedLinksPolicy(TrackVisitedLinksOnDisk)
, m_httpCacheMaxSize(0)
{
- WebEngineContext::current(); // Ensure the WebEngineContext has been initialized
-
+ WebEngineContext::current()->addBrowserContext(this);
// Mark the context as live. This prevents the use-after-free DCHECK in
// AssertBrowserContextWasntDestroyed from being triggered when a new
// BrowserContextQt object is allocated at the same address as a previously
// destroyed one. Needs to be called after WebEngineContext initialization.
BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(m_browserContext.data());
-
content::BrowserContext::Initialize(m_browserContext.data(), toFilePath(dataPath()));
}
-BrowserContextAdapter::BrowserContextAdapter(const QString &storageName)
- : QObject(BrowserContextAdapter::globalQObjectRoot())
- , m_name(storageName)
+BrowserContextAdapter::BrowserContextAdapter(const QString &storageName):
+ m_name(storageName)
, m_offTheRecord(false)
, m_browserContext(new BrowserContextQt(this))
, m_httpCacheType(DiskHttpCache)
@@ -106,19 +102,18 @@ BrowserContextAdapter::BrowserContextAdapter(const QString &storageName)
, m_visitedLinksPolicy(TrackVisitedLinksOnDisk)
, m_httpCacheMaxSize(0)
{
- WebEngineContext::current(); // Ensure the WebEngineContext has been initialized
-
+ WebEngineContext::current()->addBrowserContext(this);
// Mark the context as live. This prevents the use-after-free DCHECK in
// AssertBrowserContextWasntDestroyed from being triggered when a new
// BrowserContextQt object is allocated at the same address as a previously
// destroyed one. Needs to be called after WebEngineContext initialization.
BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(m_browserContext.data());
-
content::BrowserContext::Initialize(m_browserContext.data(), toFilePath(dataPath()));
}
BrowserContextAdapter::~BrowserContextAdapter()
{
+ WebEngineContext::current()->removeBrowserContext(this);
m_browserContext->ShutdownStoragePartitions();
if (m_downloadManagerDelegate) {
m_browserContext->GetDownloadManager(m_browserContext.data())->Shutdown();
diff --git a/src/core/net/url_request_custom_job_proxy.cpp b/src/core/net/url_request_custom_job_proxy.cpp
index 411e1c868..38fbd7670 100644
--- a/src/core/net/url_request_custom_job_proxy.cpp
+++ b/src/core/net/url_request_custom_job_proxy.cpp
@@ -44,6 +44,7 @@
#include "browser_context_adapter.h"
#include "type_conversion.h"
#include "content/public/browser/browser_thread.h"
+#include "web_engine_context.h"
using namespace net;
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index af22c5e7f..3e3a99f7a 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -186,7 +186,28 @@ bool WebEngineContext::m_destroyed = false;
void WebEngineContext::destroyBrowserContext()
{
if (m_defaultBrowserContext)
- qWarning() << "PostMainMessageLoopRun is done, but global profile still exists !";
+ qWarning("PostMainMessageLoopRun is done, but global profile still exists !");
+}
+
+void WebEngineContext::addBrowserContext(BrowserContextAdapter *contextAdapter)
+{
+ Q_ASSERT(!m_browserContextAdapters.contains(contextAdapter));
+ const QString path = contextAdapter->dataPath();
+ if (!path.isEmpty()) {
+ for (auto browserContextAdapter : m_browserContextAdapters) {
+ if (browserContextAdapter->dataPath() == path) {
+ // QTBUG-66068
+ qWarning("Using the same data path for profile, may corrupt the data.");
+ break;
+ }
+ }
+ }
+ m_browserContextAdapters.append(contextAdapter);
+}
+
+void WebEngineContext::removeBrowserContext(BrowserContextAdapter *contextAdapter)
+{
+ m_browserContextAdapters.removeAll(contextAdapter);
}
void WebEngineContext::destroy()
@@ -201,6 +222,8 @@ void WebEngineContext::destroy()
// Delete the global object and thus custom profiles
m_defaultBrowserContext.reset();
m_globalQObject.reset();
+ while (m_browserContextAdapters.count())
+ delete m_browserContextAdapters.first();
// Handle any events posted by browser-context shutdown.
while (delegate->DoWork()) { }
@@ -224,6 +247,7 @@ WebEngineContext::~WebEngineContext()
Q_ASSERT(!m_globalQObject);
Q_ASSERT(!m_devtoolsServer);
Q_ASSERT(!m_browserRunner);
+ Q_ASSERT(m_browserContextAdapters.isEmpty());
}
WebEngineContext *WebEngineContext::current()
diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h
index 7e9d546a4..73bda03fb 100644
--- a/src/core/web_engine_context.h
+++ b/src/core/web_engine_context.h
@@ -47,8 +47,7 @@
#include "base/memory/ref_counted.h"
#include "base/values.h"
#include "printing/features/features.h"
-
-#include <QScopedPointer>
+#include <QVector>
namespace base {
class RunLoop;
@@ -88,6 +87,8 @@ public:
printing::PrintJobManager* getPrintJobManager();
#endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
void destroyBrowserContext();
+ void addBrowserContext(BrowserContextAdapter*);
+ void removeBrowserContext(BrowserContextAdapter*);
void destroy();
private:
@@ -103,6 +104,8 @@ private:
std::unique_ptr<QObject> m_globalQObject;
std::unique_ptr<BrowserContextAdapter> m_defaultBrowserContext;
std::unique_ptr<DevToolsServerQt> m_devtoolsServer;
+ QVector<BrowserContextAdapter*> m_browserContextAdapters;
+
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
std::unique_ptr<printing::PrintJobManager> m_printJobManager;
#endif // BUILDFLAG(ENABLE_BASIC_PRINTING)