summaryrefslogtreecommitdiffstats
path: root/src/webengine/api/qquickwebengineprofile.cpp
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/webengine/api/qquickwebengineprofile.cpp
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/webengine/api/qquickwebengineprofile.cpp')
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index 1dead56ac..68cc701e0 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -142,10 +142,11 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC
The \a download argument holds the state of the finished download instance.
*/
-QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter> browserContext)
+QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(BrowserContextAdapter *browserContext)
: m_settings(new QQuickWebEngineSettings())
- , m_browserContext(new QWebEngineBrowserContext(browserContext, this))
+ , m_browserContextAdapter(browserContext)
{
+ m_browserContextAdapter->addClient(this);
m_settings->d_ptr->initDefaults();
// Fullscreen API was implemented before the supported setting, so we must
// make it default true to avoid change in default API behavior.
@@ -154,10 +155,18 @@ QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointer<Brow
QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate()
{
+
while (!m_webContentsAdapterClients.isEmpty()) {
m_webContentsAdapterClients.first()->destroy();
}
+ if (m_browserContextAdapter) {
+ // 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.
+ m_browserContextAdapter->setRequestInterceptor(nullptr);
+ m_browserContextAdapter->removeClient(this);
+ }
+
Q_FOREACH (QQuickWebEngineDownloadItem *download, m_ongoingDownloads) {
if (download)
download->cancel();
@@ -165,8 +174,8 @@ QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate()
m_ongoingDownloads.clear();
- if (m_browserContext)
- m_browserContext->shutdown();
+ if (q_ptr != QQuickWebEngineProfile::defaultProfile())
+ delete m_browserContextAdapter;
}
void QQuickWebEngineProfilePrivate::addWebContentsAdapterClient(QQuickWebEngineViewPrivate *adapter)
@@ -179,15 +188,10 @@ void QQuickWebEngineProfilePrivate::removeWebContentsAdapterClient(QQuickWebEngi
m_webContentsAdapterClients.removeAll(adapter);
}
-QSharedPointer<QtWebEngineCore::BrowserContextAdapter> QQuickWebEngineProfilePrivate::browserContext() const
-{
- return m_browserContext ? m_browserContext->browserContextRef : nullptr;
-}
-
void QQuickWebEngineProfilePrivate::cancelDownload(quint32 downloadId)
{
- if (m_browserContext)
- m_browserContext->browserContextRef->cancelDownload(downloadId);
+ if (m_browserContextAdapter)
+ m_browserContextAdapter->cancelDownload(downloadId);
}
void QQuickWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId)
@@ -322,7 +326,7 @@ void QQuickWebEngineProfilePrivate::userScripts_clear(QQmlListProperty<QQuickWeb
*/
QQuickWebEngineProfile::QQuickWebEngineProfile(QObject *parent)
: QObject(parent),
- d_ptr(new QQuickWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter>::create(false)))
+ d_ptr(new QQuickWebEngineProfilePrivate(new QtWebEngineCore::BrowserContextAdapter(true)))
{
// Sets up the global WebEngineContext
QQuickWebEngineProfile::defaultProfile();