summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2018-01-11 11:24:48 +0100
committerMichal Klocek <michal.klocek@qt.io>2018-05-18 10:49:44 +0000
commitcfddf26f78e521809a17d4fab5bb7cfe18d3f08e (patch)
tree5da7f2d15afd944f6b0bcdfab4e798063f2e582f /src/core
parent7d6f72463ef372aabf4c4e6f212b9d331ef1338a (diff)
Change BrowserContextAdapter to be QPointer
BrowserContextAdapter is living and accessed only in UI thread, remove QSharedPointer usage and change QWebengineProfile to use QPointer. Prevent BrowserContextAdapter outliving WebEngineContext by setting globalObject as a parent to track WebEngineContext destruction. This commits tries to simplify the life cycle handling of browser context, it removes profile shutdown methods and QWebEngineBrowserContext, which was used to track profile destruction. Task-number: QTBUG-62147 Change-Id: I79f2c38a123cd053e3a59f4900afbdc759a396fe Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io> Reviewed-by: Michael Brüning <michael.bruning@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/api/core_api.pro2
-rw-r--r--src/core/api/qwebenginebrowsercontext.cpp73
-rw-r--r--src/core/api/qwebenginebrowsercontext_p.h83
-rw-r--r--src/core/browser_context_adapter.cpp15
-rw-r--r--src/core/browser_context_adapter.h6
-rw-r--r--src/core/browser_context_qt.cpp7
-rw-r--r--src/core/net/custom_protocol_handler.cpp2
-rw-r--r--src/core/net/custom_protocol_handler.h6
-rw-r--r--src/core/net/url_request_context_getter_qt.cpp62
-rw-r--r--src/core/net/url_request_context_getter_qt.h13
-rw-r--r--src/core/net/url_request_custom_job.cpp2
-rw-r--r--src/core/net/url_request_custom_job.h4
-rw-r--r--src/core/net/url_request_custom_job_proxy.cpp11
-rw-r--r--src/core/net/url_request_custom_job_proxy.h6
-rw-r--r--src/core/web_contents_adapter.cpp8
-rw-r--r--src/core/web_contents_adapter_client.h2
-rw-r--r--src/core/web_contents_delegate_qt.cpp2
-rw-r--r--src/core/web_engine_context.cpp17
-rw-r--r--src/core/web_engine_context.h7
19 files changed, 86 insertions, 242 deletions
diff --git a/src/core/api/core_api.pro b/src/core/api/core_api.pro
index 632034a9d..727d82b8a 100644
--- a/src/core/api/core_api.pro
+++ b/src/core/api/core_api.pro
@@ -33,7 +33,6 @@ HEADERS = \
qwebenginecallback_p.h \
qtwebenginecoreglobal.h \
qtwebenginecoreglobal_p.h \
- qwebenginebrowsercontext_p.h \
qwebenginecookiestore.h \
qwebenginecookiestore_p.h \
qwebenginehttprequest.h \
@@ -47,7 +46,6 @@ HEADERS = \
SOURCES = \
qtwebenginecoreglobal.cpp \
- qwebenginebrowsercontext.cpp \
qwebenginecookiestore.cpp \
qwebenginehttprequest.cpp \
qwebenginequotarequest.cpp \
diff --git a/src/core/api/qwebenginebrowsercontext.cpp b/src/core/api/qwebenginebrowsercontext.cpp
deleted file mode 100644
index c3ab16460..000000000
--- a/src/core/api/qwebenginebrowsercontext.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwebenginebrowsercontext_p.h"
-
-#include "browser_context_adapter.h"
-#include <qtwebenginecoreglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-QWebEngineBrowserContext::QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext,
- QtWebEngineCore::BrowserContextAdapterClient *profile)
- : QObject(QtWebEngineCore::BrowserContextAdapter::globalQObjectRoot())
- , browserContextRef(browserContext)
- , m_profile(profile)
-{
- browserContextRef->addClient(m_profile);
-}
-
-QWebEngineBrowserContext::~QWebEngineBrowserContext()
-{
- if (m_profile)
- shutdown();
-}
-
-void QWebEngineBrowserContext::shutdown()
-{
- Q_ASSERT(m_profile);
- // In the case the user sets this profile as the parent of the interceptor
- // it can be deleted before the browser-context still referencing it is.
- browserContextRef->setRequestInterceptor(nullptr);
- browserContextRef->removeClient(m_profile);
- m_profile = 0;
- deleteLater();
-}
-
-QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginebrowsercontext_p.h b/src/core/api/qwebenginebrowsercontext_p.h
deleted file mode 100644
index 713ab730e..000000000
--- a/src/core/api/qwebenginebrowsercontext_p.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QWEBENGINEBROWSERCONTEXT_P_H
-#define QWEBENGINEBROWSERCONTEXT_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-#include "qtwebenginecoreglobal_p.h"
-
-#include <QObject>
-#include <QSharedPointer>
-
-namespace QtWebEngineCore {
-class BrowserContextAdapter;
-class BrowserContextAdapterClient;
-}
-
-QT_BEGIN_NAMESPACE
-
-// This is a wrapper class for BrowserContextAdapter. BrowserContextAdapter must be destructed before WebEngineContext
-// is destructed. Therefore access it via the QWebEngineBrowserContext which parent is the WebEngineContext::globalQObject.
-// This guarantees the destruction together with the WebEngineContext.
-class QWEBENGINE_PRIVATE_EXPORT QWebEngineBrowserContext : public QObject {
-public:
- QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, QtWebEngineCore::BrowserContextAdapterClient *profile);
- ~QWebEngineBrowserContext();
-
- void shutdown();
-
- QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextRef;
-
-private:
- QtWebEngineCore::BrowserContextAdapterClient *m_profile;
-};
-
-QT_END_NAMESPACE
-
-#endif // QWEBENGINEBROWSERCONTEXT_P_H
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index b0f244393..75f936f21 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -77,7 +77,8 @@ inline QString buildLocationFromStandardPath(const QString &standardPath, const
namespace QtWebEngineCore {
BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord)
- : m_offTheRecord(offTheRecord)
+ : QObject(BrowserContextAdapter::globalQObjectRoot())
+ , m_offTheRecord(offTheRecord)
, m_browserContext(new BrowserContextQt(this))
, m_httpCacheType(DiskHttpCache)
, m_persistentCookiesPolicy(AllowPersistentCookies)
@@ -96,7 +97,8 @@ BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord)
}
BrowserContextAdapter::BrowserContextAdapter(const QString &storageName)
- : m_name(storageName)
+ : QObject(BrowserContextAdapter::globalQObjectRoot())
+ , m_name(storageName)
, m_offTheRecord(false)
, m_browserContext(new BrowserContextQt(this))
, m_httpCacheType(DiskHttpCache)
@@ -117,12 +119,7 @@ BrowserContextAdapter::BrowserContextAdapter(const QString &storageName)
BrowserContextAdapter::~BrowserContextAdapter()
{
- Q_ASSERT(!m_downloadManagerDelegate);
m_browserContext->ShutdownStoragePartitions();
-}
-
-void BrowserContextAdapter::shutdown()
-{
if (m_downloadManagerDelegate) {
m_browserContext->GetDownloadManager(m_browserContext.data())->Shutdown();
m_downloadManagerDelegate.reset();
@@ -202,8 +199,6 @@ void BrowserContextAdapter::addClient(BrowserContextAdapterClient *adapterClient
void BrowserContextAdapter::removeClient(BrowserContextAdapterClient *adapterClient)
{
m_clients.removeOne(adapterClient);
- if (m_clients.isEmpty() && this != WebEngineContext::current()->m_defaultBrowserContext.data())
- shutdown();
}
void BrowserContextAdapter::cancelDownload(quint32 downloadId)
@@ -221,7 +216,7 @@ void BrowserContextAdapter::resumeDownload(quint32 downloadId)
downloadManagerDelegate()->resumeDownload(downloadId);
}
-QSharedPointer<BrowserContextAdapter> BrowserContextAdapter::defaultContext()
+BrowserContextAdapter *BrowserContextAdapter::defaultContext()
{
return WebEngineContext::current()->defaultBrowserContext();
}
diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h
index b647bc30c..e13c62a38 100644
--- a/src/core/browser_context_adapter.h
+++ b/src/core/browser_context_adapter.h
@@ -63,18 +63,16 @@ class DownloadManagerDelegateQt;
class UserResourceControllerHost;
class VisitedLinksManagerQt;
-class QWEBENGINE_EXPORT BrowserContextAdapter : public QEnableSharedFromThis<BrowserContextAdapter>
+class QWEBENGINE_EXPORT BrowserContextAdapter : public QObject
{
public:
explicit BrowserContextAdapter(bool offTheRecord = false);
explicit BrowserContextAdapter(const QString &storagePrefix);
virtual ~BrowserContextAdapter();
- static QSharedPointer<BrowserContextAdapter> defaultContext();
+ static BrowserContextAdapter* defaultContext();
static QObject* globalQObjectRoot();
- void shutdown();
-
VisitedLinksManagerQt *visitedLinksManager();
DownloadManagerDelegateQt *downloadManagerDelegate();
diff --git a/src/core/browser_context_qt.cpp b/src/core/browser_context_qt.cpp
index 96bfde443..32dbe0666 100644
--- a/src/core/browser_context_qt.cpp
+++ b/src/core/browser_context_qt.cpp
@@ -195,9 +195,12 @@ content::PermissionManager *BrowserContextQt::GetPermissionManager()
return permissionManager.get();
}
-net::URLRequestContextGetter *BrowserContextQt::CreateRequestContext(content::ProtocolHandlerMap *protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors)
+net::URLRequestContextGetter *BrowserContextQt::CreateRequestContext(
+ content::ProtocolHandlerMap *protocol_handlers,
+ content::URLRequestInterceptorScopedVector request_interceptors)
{
- url_request_getter_ = new URLRequestContextGetterQt(m_adapter->sharedFromThis(), protocol_handlers, std::move(request_interceptors));
+ url_request_getter_ = new URLRequestContextGetterQt(m_adapter, protocol_handlers,
+ std::move(request_interceptors));
return url_request_getter_.get();
}
diff --git a/src/core/net/custom_protocol_handler.cpp b/src/core/net/custom_protocol_handler.cpp
index 402df04ba..3620bc10c 100644
--- a/src/core/net/custom_protocol_handler.cpp
+++ b/src/core/net/custom_protocol_handler.cpp
@@ -46,7 +46,7 @@
namespace QtWebEngineCore {
-CustomProtocolHandler::CustomProtocolHandler(QWeakPointer<const BrowserContextAdapter> adapter)
+CustomProtocolHandler::CustomProtocolHandler(QPointer<BrowserContextAdapter> adapter)
: m_adapter(adapter)
{
}
diff --git a/src/core/net/custom_protocol_handler.h b/src/core/net/custom_protocol_handler.h
index 5d3838834..1568c269e 100644
--- a/src/core/net/custom_protocol_handler.h
+++ b/src/core/net/custom_protocol_handler.h
@@ -45,7 +45,7 @@
#include <QtCore/QByteArray>
#include <QtCore/QObject>
-#include <QtCore/QWeakPointer>
+#include <QtCore/QPointer>
QT_FORWARD_DECLARE_CLASS(QIODevice)
@@ -63,13 +63,13 @@ class BrowserContextAdapter;
class QWEBENGINE_EXPORT CustomProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
public:
- CustomProtocolHandler(QWeakPointer<const BrowserContextAdapter> adapter);
+ CustomProtocolHandler(QPointer<BrowserContextAdapter> adapter);
net::URLRequestJob *MaybeCreateJob(net::URLRequest *request, net::NetworkDelegate *networkDelegate) const override;
private:
DISALLOW_COPY_AND_ASSIGN(CustomProtocolHandler);
- QWeakPointer<const BrowserContextAdapter> m_adapter;
+ QPointer<BrowserContextAdapter> m_adapter;
};
} // namespace
diff --git a/src/core/net/url_request_context_getter_qt.cpp b/src/core/net/url_request_context_getter_qt.cpp
index 904130611..89c048d18 100644
--- a/src/core/net/url_request_context_getter_qt.cpp
+++ b/src/core/net/url_request_context_getter_qt.cpp
@@ -90,7 +90,9 @@ namespace QtWebEngineCore {
using content::BrowserThread;
-URLRequestContextGetterQt::URLRequestContextGetterQt(QSharedPointer<BrowserContextAdapter> browserContext, content::ProtocolHandlerMap *protocolHandlers, content::URLRequestInterceptorScopedVector request_interceptors)
+URLRequestContextGetterQt::URLRequestContextGetterQt(BrowserContextAdapter *browserContext,
+ content::ProtocolHandlerMap *protocolHandlers,
+ content::URLRequestInterceptorScopedVector request_interceptors)
: m_ignoreCertificateErrors(false)
, m_mutex(QMutex::Recursive)
, m_contextInitialized(false)
@@ -99,7 +101,7 @@ URLRequestContextGetterQt::URLRequestContextGetterQt(QSharedPointer<BrowserConte
, m_updateHttpCache(false)
, m_updateJobFactory(true)
, m_updateUserAgent(false)
- , m_browserContext(browserContext)
+ , m_browserContextAdapter(browserContext)
, m_baseJobFactory(0)
, m_cookieDelegate(new CookieMonsterDelegateQt())
, m_requestInterceptors(std::move(request_interceptors))
@@ -116,7 +118,6 @@ URLRequestContextGetterQt::URLRequestContextGetterQt(QSharedPointer<BrowserConte
QMutexLocker lock(&m_mutex);
m_cookieDelegate->setClient(browserContext->cookieStore());
- setFullConfiguration(browserContext);
updateStorageSettings();
}
@@ -127,21 +128,19 @@ URLRequestContextGetterQt::~URLRequestContextGetterQt()
}
-void URLRequestContextGetterQt::setFullConfiguration(QSharedPointer<BrowserContextAdapter> browserContext)
+void URLRequestContextGetterQt::setFullConfiguration()
{
- if (!browserContext)
- return;
-
- m_requestInterceptor = browserContext->requestInterceptor();
- m_persistentCookiesPolicy = browserContext->persistentCookiesPolicy();
- m_cookiesPath = browserContext->cookiesPath();
- m_channelIdPath = browserContext->channelIdPath();
- m_httpAcceptLanguage = browserContext->httpAcceptLanguage();
- m_httpUserAgent = browserContext->httpUserAgent();
- m_httpCacheType = browserContext->httpCacheType();
- m_httpCachePath = browserContext->httpCachePath();
- m_httpCacheMaxSize = browserContext->httpCacheMaxSize();
- m_customUrlSchemes = browserContext->customUrlSchemes();
+ Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ m_requestInterceptor = m_browserContextAdapter->requestInterceptor();
+ m_persistentCookiesPolicy = m_browserContextAdapter->persistentCookiesPolicy();
+ m_cookiesPath = m_browserContextAdapter->cookiesPath();
+ m_channelIdPath = m_browserContextAdapter->channelIdPath();
+ m_httpAcceptLanguage = m_browserContextAdapter->httpAcceptLanguage();
+ m_httpUserAgent = m_browserContextAdapter->httpUserAgent();
+ m_httpCacheType = m_browserContextAdapter->httpCacheType();
+ m_httpCachePath = m_browserContextAdapter->httpCachePath();
+ m_httpCacheMaxSize = m_browserContextAdapter->httpCacheMaxSize();
+ m_customUrlSchemes = m_browserContextAdapter->customUrlSchemes();
}
net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext()
@@ -168,7 +167,7 @@ void URLRequestContextGetterQt::updateStorageSettings()
Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
QMutexLocker lock(&m_mutex);
- setFullConfiguration(m_browserContext.toStrongRef());
+ setFullConfiguration();
if (!m_updateAllStorage) {
m_updateAllStorage = true;
@@ -287,9 +286,9 @@ void URLRequestContextGetterQt::updateCookieStore()
{
Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
QMutexLocker lock(&m_mutex);
- m_persistentCookiesPolicy = m_browserContext.data()->persistentCookiesPolicy();
- m_cookiesPath = m_browserContext.data()->cookiesPath();
- m_channelIdPath = m_browserContext.data()->channelIdPath();
+ m_persistentCookiesPolicy = m_browserContextAdapter->persistentCookiesPolicy();
+ m_cookiesPath = m_browserContextAdapter->cookiesPath();
+ m_channelIdPath = m_browserContextAdapter->channelIdPath();
if (m_contextInitialized && !m_updateAllStorage && !m_updateCookieStore) {
m_updateCookieStore = true;
@@ -373,8 +372,8 @@ void URLRequestContextGetterQt::updateUserAgent()
{
Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
QMutexLocker lock(&m_mutex);
- m_httpAcceptLanguage = m_browserContext.data()->httpAcceptLanguage();
- m_httpUserAgent = m_browserContext.data()->httpUserAgent();
+ m_httpAcceptLanguage = m_browserContextAdapter->httpAcceptLanguage();
+ m_httpUserAgent = m_browserContextAdapter->httpUserAgent();
if (m_contextInitialized && !m_updateAllStorage && !m_updateUserAgent) {
m_updateUserAgent = true;
@@ -400,12 +399,12 @@ void URLRequestContextGetterQt::updateHttpCache()
{
Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
QMutexLocker lock(&m_mutex);
- m_httpCacheType = m_browserContext.data()->httpCacheType();
- m_httpCachePath = m_browserContext.data()->httpCachePath();
- m_httpCacheMaxSize = m_browserContext.data()->httpCacheMaxSize();
+ m_httpCacheType = m_browserContextAdapter->httpCacheType();
+ m_httpCachePath = m_browserContextAdapter->httpCachePath();
+ m_httpCacheMaxSize = m_browserContextAdapter->httpCacheMaxSize();
if (m_httpCacheType == BrowserContextAdapter::NoCache) {
- content::BrowsingDataRemover *remover = content::BrowserContext::GetBrowsingDataRemover(m_browserContext.data()->browserContext());
+ content::BrowsingDataRemover *remover = content::BrowserContext::GetBrowsingDataRemover(m_browserContextAdapter->browserContext());
remover->Remove(base::Time(), base::Time::Max(),
content::BrowsingDataRemover::DATA_TYPE_CACHE,
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB);
@@ -422,7 +421,8 @@ void URLRequestContextGetterQt::updateJobFactory()
{
Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
QMutexLocker lock(&m_mutex);
- m_customUrlSchemes = m_browserContext.data()->customUrlSchemes();
+
+ m_customUrlSchemes = m_browserContextAdapter->customUrlSchemes();
if (m_contextInitialized && !m_updateJobFactory) {
m_updateJobFactory = true;
@@ -435,7 +435,7 @@ void URLRequestContextGetterQt::updateRequestInterceptor()
{
Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
QMutexLocker lock(&m_mutex);
- m_requestInterceptor = m_browserContext.data()->requestInterceptor();
+ m_requestInterceptor = m_browserContextAdapter->requestInterceptor();
// We in this case do not need to regenerate any Chromium classes.
}
@@ -584,7 +584,7 @@ void URLRequestContextGetterQt::generateJobFactory()
m_installedCustomSchemes = m_customUrlSchemes;
Q_FOREACH (const QByteArray &scheme, m_installedCustomSchemes) {
- jobFactory->SetProtocolHandler(scheme.toStdString(), std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>(new CustomProtocolHandler(m_browserContext)));
+ jobFactory->SetProtocolHandler(scheme.toStdString(), std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>(new CustomProtocolHandler(m_browserContextAdapter)));
}
m_baseJobFactory = jobFactory.get();
@@ -627,7 +627,7 @@ void URLRequestContextGetterQt::regenerateJobFactory()
m_installedCustomSchemes = m_customUrlSchemes;
Q_FOREACH (const QByteArray &scheme, m_installedCustomSchemes) {
- m_baseJobFactory->SetProtocolHandler(scheme.toStdString(), std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>(new CustomProtocolHandler(m_browserContext)));
+ m_baseJobFactory->SetProtocolHandler(scheme.toStdString(), std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>(new CustomProtocolHandler(m_browserContextAdapter)));
}
}
diff --git a/src/core/net/url_request_context_getter_qt.h b/src/core/net/url_request_context_getter_qt.h
index 0eb4a2fe4..fbc445e4f 100644
--- a/src/core/net/url_request_context_getter_qt.h
+++ b/src/core/net/url_request_context_getter_qt.h
@@ -70,7 +70,9 @@ namespace QtWebEngineCore {
// FIXME: This class should be split into a URLRequestContextGetter and a ProfileIOData, similar to what chrome does.
class URLRequestContextGetterQt : public net::URLRequestContextGetter {
public:
- URLRequestContextGetterQt(QSharedPointer<BrowserContextAdapter> browserContext, content::ProtocolHandlerMap *protocolHandlers, content::URLRequestInterceptorScopedVector request_interceptors);
+ URLRequestContextGetterQt(BrowserContextAdapter *browserContext,
+ content::ProtocolHandlerMap *protocolHandlers,
+ content::URLRequestInterceptorScopedVector request_interceptors);
net::URLRequestContext *GetURLRequestContext() override;
scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const override;
@@ -82,6 +84,7 @@ public:
void updateHttpCache();
void updateJobFactory();
void updateRequestInterceptor();
+ void setFullConfiguration();
private:
virtual ~URLRequestContextGetterQt();
@@ -98,10 +101,7 @@ private:
net::HttpNetworkSession::Params generateNetworkSessionParams();
net::HttpNetworkSession::Context generateNetworkSessionContext();
- void setFullConfiguration(QSharedPointer<BrowserContextAdapter> browserContext);
-
bool m_ignoreCertificateErrors;
-
QMutex m_mutex;
bool m_contextInitialized;
bool m_updateAllStorage;
@@ -110,9 +110,10 @@ private:
bool m_updateJobFactory;
bool m_updateUserAgent;
- QWeakPointer<BrowserContextAdapter> m_browserContext;
+ // m_browserContext is never dereferenced in IO thread and it is passed by
+ // qpointer in generateJobFactory
+ QPointer<BrowserContextAdapter> m_browserContextAdapter;
content::ProtocolHandlerMap m_protocolHandlers;
-
QAtomicPointer<net::ProxyConfigService> m_proxyConfigService;
std::unique_ptr<net::URLRequestContext> m_urlRequestContext;
std::unique_ptr<NetworkDelegateQt> m_networkDelegate;
diff --git a/src/core/net/url_request_custom_job.cpp b/src/core/net/url_request_custom_job.cpp
index cf96cd6d9..d9337687b 100644
--- a/src/core/net/url_request_custom_job.cpp
+++ b/src/core/net/url_request_custom_job.cpp
@@ -51,7 +51,7 @@ namespace QtWebEngineCore {
URLRequestCustomJob::URLRequestCustomJob(URLRequest *request,
NetworkDelegate *networkDelegate,
const std::string &scheme,
- QWeakPointer<const BrowserContextAdapter> adapter)
+ QPointer<BrowserContextAdapter> adapter)
: URLRequestJob(request, networkDelegate)
, m_proxy(new URLRequestCustomJobProxy(this, scheme, adapter))
, m_device(nullptr)
diff --git a/src/core/net/url_request_custom_job.h b/src/core/net/url_request_custom_job.h
index 021cf3204..71c8d2613 100644
--- a/src/core/net/url_request_custom_job.h
+++ b/src/core/net/url_request_custom_job.h
@@ -42,7 +42,7 @@
#include "net/url_request/url_request_job.h"
#include "url/gurl.h"
-#include <QtCore/QWeakPointer>
+#include <QtCore/QPointer>
QT_FORWARD_DECLARE_CLASS(QIODevice)
@@ -58,7 +58,7 @@ public:
URLRequestCustomJob(net::URLRequest *request,
net::NetworkDelegate *networkDelegate,
const std::string &scheme,
- QWeakPointer<const BrowserContextAdapter> adapter);
+ QPointer<BrowserContextAdapter> adapter);
void Start() override;
void Kill() override;
int ReadRawData(net::IOBuffer *buf, int buf_size) override;
diff --git a/src/core/net/url_request_custom_job_proxy.cpp b/src/core/net/url_request_custom_job_proxy.cpp
index 6c9824bb9..411e1c868 100644
--- a/src/core/net/url_request_custom_job_proxy.cpp
+++ b/src/core/net/url_request_custom_job_proxy.cpp
@@ -51,7 +51,7 @@ namespace QtWebEngineCore {
URLRequestCustomJobProxy::URLRequestCustomJobProxy(URLRequestCustomJob *job,
const std::string &scheme,
- QWeakPointer<const BrowserContextAdapter> adapter)
+ QPointer<BrowserContextAdapter> adapter)
: m_job(job)
, m_started(false)
, m_scheme(scheme)
@@ -160,10 +160,11 @@ void URLRequestCustomJobProxy::initialize(GURL url, std::string method, base::Op
if (initiator.has_value())
initiatorOrigin = toQt(initiator.value().GetURL());
- QWebEngineUrlSchemeHandler *schemeHandler = 0;
- QSharedPointer<const BrowserContextAdapter> browserContext = m_adapter.toStrongRef();
- if (browserContext)
- schemeHandler = browserContext->customUrlSchemeHandlers()[toQByteArray(m_scheme)];
+ QWebEngineUrlSchemeHandler *schemeHandler = nullptr;
+
+ if (m_adapter)
+ schemeHandler = m_adapter->customUrlSchemeHandlers()[toQByteArray(m_scheme)];
+
if (schemeHandler) {
m_delegate = new URLRequestCustomJobDelegate(this, toQt(url),
QByteArray::fromStdString(method),
diff --git a/src/core/net/url_request_custom_job_proxy.h b/src/core/net/url_request_custom_job_proxy.h
index 603ad5840..34d526348 100644
--- a/src/core/net/url_request_custom_job_proxy.h
+++ b/src/core/net/url_request_custom_job_proxy.h
@@ -44,7 +44,7 @@
#include "base/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
-#include <QtCore/QWeakPointer>
+#include <QtCore/QPointer>
QT_FORWARD_DECLARE_CLASS(QIODevice)
@@ -62,7 +62,7 @@ class URLRequestCustomJobProxy
public:
URLRequestCustomJobProxy(URLRequestCustomJob *job,
const std::string &scheme,
- QWeakPointer<const BrowserContextAdapter> adapter);
+ QPointer<BrowserContextAdapter> adapter);
~URLRequestCustomJobProxy();
// Called from URLRequestCustomJobDelegate via post:
@@ -82,7 +82,7 @@ public:
// UI thread owned:
std::string m_scheme;
URLRequestCustomJobDelegate *m_delegate;
- QWeakPointer<const BrowserContextAdapter> m_adapter;
+ QPointer<BrowserContextAdapter> m_adapter;
};
} // namespace QtWebEngineCore
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 6c4810c33..c7d36cb67 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -407,9 +407,7 @@ void WebContentsAdapter::setClient(WebContentsAdapterClient *adapterClient)
{
Q_ASSERT(!isInitialized());
m_adapterClient = adapterClient;
- // We keep a reference to browserContextAdapter to keep it alive as long as we use it.
- // This is needed in case the QML WebEngineProfile is garbage collected before the WebEnginePage.
- m_browserContextAdapter = adapterClient->browserContextAdapter().data();
+ m_browserContextAdapter = adapterClient->browserContextAdapter();
Q_ASSERT(m_browserContextAdapter);
// This might replace any adapter that has been initialized with this WebEngineSettings.
@@ -893,7 +891,9 @@ BrowserContextQt* WebContentsAdapter::browserContext()
BrowserContextAdapter* WebContentsAdapter::browserContextAdapter()
{
- return m_browserContextAdapter ? m_browserContextAdapter : m_webContents ? static_cast<BrowserContextQt*>(m_webContents->GetBrowserContext())->adapter() : 0;
+ return m_browserContextAdapter ?
+ m_browserContextAdapter : m_webContents ?
+ static_cast<BrowserContextQt*>(m_webContents->GetBrowserContext())->adapter() : nullptr;
}
#ifndef QT_NO_ACCESSIBILITY
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 4c5133772..2d057160d 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -453,7 +453,7 @@ public:
virtual const QObject *holdingQObject() const = 0;
virtual void setToolTip(const QString& toolTipText) = 0;
- virtual QSharedPointer<BrowserContextAdapter> browserContextAdapter() = 0;
+ virtual BrowserContextAdapter *browserContextAdapter() = 0;
virtual WebContentsAdapter* webContentsAdapter() = 0;
};
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index 2de8fd64a..b98c822b0 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -287,7 +287,7 @@ void WebContentsDelegateQt::DidFinishNavigation(content::NavigationHandle *navig
return;
if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
- BrowserContextAdapter *browserContextAdapter = m_viewClient->browserContextAdapter().data();
+ BrowserContextAdapter *browserContextAdapter = m_viewClient->browserContextAdapter();
// VisistedLinksMaster asserts !IsOffTheRecord().
if (navigation_handle->ShouldUpdateHistory() && browserContextAdapter->trackVisitedLinks()) {
for (const GURL &url : navigation_handle->GetRedirectChain())
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index 35402cdb0..922846fff 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -199,7 +199,8 @@ bool usingSoftwareDynamicGL()
void WebEngineContext::destroyBrowserContext()
{
- m_defaultBrowserContext.reset();
+ if (m_defaultBrowserContext)
+ qWarning() << "PostMainMessageLoopRun is done, but global profile still exists !";
}
void WebEngineContext::destroy()
@@ -211,11 +212,12 @@ void WebEngineContext::destroy()
// Flush the UI message loop before quitting.
while (delegate->DoWork()) { }
- if (m_defaultBrowserContext)
- m_defaultBrowserContext->shutdown();
// Delete the global object and thus custom profiles
+ m_defaultBrowserContext.reset();
delete m_globalQObject;
m_globalQObject = nullptr;
+
+
// Handle any events posted by browser-context shutdown.
while (delegate->DoWork()) { }
@@ -223,7 +225,7 @@ void WebEngineContext::destroy()
m_devtoolsServer.reset();
m_runLoop->AfterRun();
- // Force to destroy RenderProcessHostImpl by destroying BrowserMainRunner.
+ // Fixme: Force to destroy RenderProcessHostImpl by destroying BrowserMainRunner.
// RenderProcessHostImpl should be destroyed before WebEngineContext since
// default BrowserContext might be used by the RenderprocessHostImpl's destructor.
m_browserRunner.reset();
@@ -254,11 +256,12 @@ WebEngineContext *WebEngineContext::current()
return sContext.get();
}
-QSharedPointer<BrowserContextAdapter> WebEngineContext::defaultBrowserContext()
+BrowserContextAdapter *WebEngineContext::defaultBrowserContext()
{
+ Q_ASSERT(!s_destroyed);
if (!m_defaultBrowserContext)
- m_defaultBrowserContext = QSharedPointer<BrowserContextAdapter>::create(QStringLiteral("Default"));
- return m_defaultBrowserContext;
+ m_defaultBrowserContext.reset(new BrowserContextAdapter(QStringLiteral("Default")));
+ return m_defaultBrowserContext.data();
}
QObject *WebEngineContext::globalQObject()
diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h
index c1640bdf2..63dbe9f23 100644
--- a/src/core/web_engine_context.h
+++ b/src/core/web_engine_context.h
@@ -48,7 +48,7 @@
#include "base/values.h"
#include "printing/features/features.h"
-#include <QSharedPointer>
+#include <QScopedPointer>
namespace base {
class RunLoop;
@@ -80,7 +80,8 @@ class WebEngineContext : public base::RefCounted<WebEngineContext> {
public:
static WebEngineContext *current();
- QSharedPointer<BrowserContextAdapter> defaultBrowserContext();
+ BrowserContextAdapter *defaultBrowserContext();
+
QObject *globalQObject();
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
printing::PrintJobManager* getPrintJobManager();
@@ -99,7 +100,7 @@ private:
std::unique_ptr<content::ContentMainRunner> m_contentRunner;
std::unique_ptr<content::BrowserMainRunner> m_browserRunner;
QObject* m_globalQObject;
- QSharedPointer<BrowserContextAdapter> m_defaultBrowserContext;
+ QScopedPointer<BrowserContextAdapter> m_defaultBrowserContext;
std::unique_ptr<DevToolsServerQt> m_devtoolsServer;
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
std::unique_ptr<printing::PrintJobManager> m_printJobManager;