summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2017-07-28 13:31:06 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2017-10-27 14:14:21 +0000
commit399d77a38ff52d33dc871a5b221db253308b7436 (patch)
tree7ed6964bf383e3981b41a9182e90c2ddd3bba094
parent3938260c7dcceee5cbf184d497b3b72d8b7a4910 (diff)
Destruct BrowserContextAdapter together with WebEngineContext in widget
BrowserContext needs IO thread to be destructed properly. Without WebEngineContext dependency it would be destructed together with the corresponding QWebEngineProfile which can outlive the WebEngineContext. Task-number: QTBUG-62147 Change-Id: Ia34215f379c6c803499848bf009e25a64b5cdb98 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp32
-rw-r--r--src/webenginewidgets/api/qwebengineprofile_p.h19
2 files changed, 41 insertions, 10 deletions
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index a4810d27..f120ae51 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -145,24 +145,35 @@ using QtWebEngineCore::BrowserContextAdapter;
\sa QWebEngineDownloadItem
*/
-QWebEngineProfilePrivate::QWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter> browserContext)
+QWebEngineBrowserContext::QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, QWebEngineProfilePrivate *profile)
+ : QObject(BrowserContextAdapter::globalQObjectRoot())
+ , browserContextRef(browserContext)
+ , m_profile(profile)
+{
+ browserContextRef->addClient(m_profile);
+}
+
+QWebEngineBrowserContext::~QWebEngineBrowserContext()
+{
+ 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);
+}
+
+QWebEngineProfilePrivate::QWebEngineProfilePrivate(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext)
: m_settings(new QWebEngineSettings())
, m_scriptCollection(new QWebEngineScriptCollection(new QWebEngineScriptCollectionPrivate(browserContext->userResourceController())))
- , m_browserContextRef(browserContext)
+ , m_browserContext(new QWebEngineBrowserContext(browserContext, this))
{
- m_browserContextRef->addClient(this);
m_settings->d_ptr->initDefaults(browserContext->isOffTheRecord());
}
QWebEngineProfilePrivate::~QWebEngineProfilePrivate()
{
- // 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_browserContextRef->setRequestInterceptor(nullptr);
-
delete m_settings;
m_settings = 0;
- m_browserContextRef->removeClient(this);
Q_FOREACH (QWebEngineDownloadItem* download, m_ongoingDownloads) {
if (download)
@@ -172,6 +183,11 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate()
m_ongoingDownloads.clear();
}
+QSharedPointer<QtWebEngineCore::BrowserContextAdapter> QWebEngineProfilePrivate::browserContext() const
+{
+ return m_browserContext->browserContextRef;
+}
+
void QWebEngineProfilePrivate::cancelDownload(quint32 downloadId)
{
browserContext()->cancelDownload(downloadId);
diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h
index 4d31c5a8..067a5bd7 100644
--- a/src/webenginewidgets/api/qwebengineprofile_p.h
+++ b/src/webenginewidgets/api/qwebengineprofile_p.h
@@ -65,15 +65,30 @@ class BrowserContextAdapter;
QT_BEGIN_NAMESPACE
+class QWebEngineProfilePrivate;
class QWebEngineSettings;
+// 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 QWebEngineBrowserContext : public QObject {
+public:
+ QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, QWebEngineProfilePrivate *profile);
+ ~QWebEngineBrowserContext();
+
+ QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextRef;
+
+private:
+ QWebEngineProfilePrivate *m_profile;
+};
+
class QWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient {
public:
Q_DECLARE_PUBLIC(QWebEngineProfile)
QWebEngineProfilePrivate(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext);
~QWebEngineProfilePrivate();
- QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext() const { return m_browserContextRef; }
+ QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext() const;
QWebEngineSettings *settings() const { return m_settings; }
void cancelDownload(quint32 downloadId);
@@ -86,7 +101,7 @@ private:
QWebEngineProfile *q_ptr;
QWebEngineSettings *m_settings;
QScopedPointer<QWebEngineScriptCollection> m_scriptCollection;
- QSharedPointer<QtWebEngineCore::BrowserContextAdapter> m_browserContextRef;
+ QPointer<QWebEngineBrowserContext> m_browserContext;
QMap<quint32, QPointer<QWebEngineDownloadItem> > m_ongoingDownloads;
};