From a3fe8bc7859a84bbdd91f3ce73108878798b3986 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 9 Jan 2018 17:52:58 +0100 Subject: Protect QML profiles as well as core Moves QWebEngineBrowserContext to core and makes use of it from both widget and qml. Change-Id: I34748f302b0515b11b5831690d28478dfa6a852b Reviewed-by: Michal Klocek Reviewed-by: Alexandru Croitor --- src/webengine/api/qquickwebengineprofile.cpp | 20 ++++++++++++-------- src/webengine/api/qquickwebengineprofile_p.h | 7 ++++--- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/webengine/api') diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 3364e4169..e051d8755 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -142,9 +142,8 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointer browserContext) : m_settings(new QQuickWebEngineSettings()) - , m_browserContextRef(browserContext) + , m_browserContext(new QWebEngineBrowserContext(browserContext, this)) { - m_browserContextRef->addClient(this); m_settings->d_ptr->initDefaults(browserContext->isOffTheRecord()); // Fullscreen API was implemented before the supported setting, so we must // make it default true to avoid change in default API behavior. @@ -153,21 +152,26 @@ QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointersetRequestInterceptor(nullptr); - - m_browserContextRef->removeClient(this); - - Q_FOREACH (QQuickWebEngineDownloadItem* download, m_ongoingDownloads) { + Q_FOREACH (QQuickWebEngineDownloadItem *download, m_ongoingDownloads) { if (download) download->cancel(); } m_ongoingDownloads.clear(); + + if (m_browserContext) + m_browserContext->shutdown(); +} + +QSharedPointer QQuickWebEngineProfilePrivate::browserContext() const +{ + return m_browserContext ? m_browserContext->browserContextRef : nullptr; } void QQuickWebEngineProfilePrivate::cancelDownload(quint32 downloadId) { - browserContext()->cancelDownload(downloadId); + if (m_browserContext) + m_browserContext->browserContextRef->cancelDownload(downloadId); } void QQuickWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId) diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h index 1828f8085..660433fd9 100644 --- a/src/webengine/api/qquickwebengineprofile_p.h +++ b/src/webengine/api/qquickwebengineprofile_p.h @@ -52,8 +52,9 @@ // #include "browser_context_adapter_client.h" -#include "qquickwebengineprofile_p.h" #include "browser_context_adapter.h" +#include "qwebenginebrowsercontext_p.h" +#include "qquickwebengineprofile_p.h" #include #include @@ -71,7 +72,7 @@ public: QQuickWebEngineProfilePrivate(QSharedPointer browserContext); ~QQuickWebEngineProfilePrivate(); - QSharedPointer browserContext() const { return m_browserContextRef; } + QSharedPointer browserContext() const; QQuickWebEngineSettings *settings() const { return m_settings.data(); } void cancelDownload(quint32 downloadId); @@ -90,7 +91,7 @@ private: friend class QQuickWebEngineViewPrivate; QQuickWebEngineProfile *q_ptr; QScopedPointer m_settings; - QSharedPointer m_browserContextRef; + QPointer m_browserContext; QMap > m_ongoingDownloads; QList m_userScripts; }; -- cgit v1.2.3