From 45c217646e3742070af15267df8fdb40c2a6c81a Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 23 May 2022 15:14:56 +0200 Subject: Protect against default profile being deleted before its pages Can really only happen in QML on exit. Pick-to: 6.3 6.4 Task-number: QTBUG-99445 Change-Id: I1a04d57b6c4c40ae264b5519d2e41c57bca79a61 Reviewed-by: Michal Klocek --- src/core/api/qwebengineprofile.cpp | 2 ++ src/core/profile_adapter.cpp | 11 ++++++++--- src/core/profile_adapter.h | 1 + src/webenginequick/api/qquickwebengineprofile.cpp | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/api/qwebengineprofile.cpp b/src/core/api/qwebengineprofile.cpp index 5fb0491ec..3f33b2f2c 100644 --- a/src/core/api/qwebengineprofile.cpp +++ b/src/core/api/qwebengineprofile.cpp @@ -184,6 +184,8 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate() if (m_profileAdapter != QtWebEngineCore::ProfileAdapter::defaultProfileAdapter()) delete m_profileAdapter; + else if (m_profileAdapter) + m_profileAdapter->releaseAllWebContentsAdapterClients(); delete m_settings; } diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp index 7bcdaf4bc..81fe4dc0e 100644 --- a/src/core/profile_adapter.cpp +++ b/src/core/profile_adapter.cpp @@ -118,9 +118,8 @@ ProfileAdapter::~ProfileAdapter() { m_cancelableTaskTracker->TryCancelAll(); m_profile->NotifyWillBeDestroyed(); - while (!m_webContentsAdapterClients.isEmpty()) { - m_webContentsAdapterClients.first()->releaseProfile(); - } + releaseAllWebContentsAdapterClients(); + WebEngineContext::current()->removeProfileAdapter(this); if (m_downloadManagerDelegate) { m_profile->GetDownloadManager()->Shutdown(); @@ -673,6 +672,12 @@ void ProfileAdapter::removeWebContentsAdapterClient(WebContentsAdapterClient *cl m_webContentsAdapterClients.removeAll(client); } +void ProfileAdapter::releaseAllWebContentsAdapterClients() +{ + while (!m_webContentsAdapterClients.isEmpty()) + m_webContentsAdapterClients.first()->releaseProfile(); +} + void ProfileAdapter::resetVisitedLinksManager() { m_visitedLinksManager.reset(new VisitedLinksManagerQt(m_profile.data(), persistVisitedLinks())); diff --git a/src/core/profile_adapter.h b/src/core/profile_adapter.h index 49945a4a3..548915437 100644 --- a/src/core/profile_adapter.h +++ b/src/core/profile_adapter.h @@ -139,6 +139,7 @@ public: void addWebContentsAdapterClient(WebContentsAdapterClient *client); void removeWebContentsAdapterClient(WebContentsAdapterClient *client); + void releaseAllWebContentsAdapterClients(); // KEEP IN SYNC with API or add mapping layer enum HttpCacheType { diff --git a/src/webenginequick/api/qquickwebengineprofile.cpp b/src/webenginequick/api/qquickwebengineprofile.cpp index 3dfb862e4..2d68f58f5 100644 --- a/src/webenginequick/api/qquickwebengineprofile.cpp +++ b/src/webenginequick/api/qquickwebengineprofile.cpp @@ -181,6 +181,8 @@ QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate() if (m_profileAdapter != QtWebEngineCore::ProfileAdapter::defaultProfileAdapter()) delete m_profileAdapter; + else if (m_profileAdapter) + m_profileAdapter->releaseAllWebContentsAdapterClients(); } void QQuickWebEngineProfilePrivate::addWebContentsAdapterClient(QtWebEngineCore::WebContentsAdapterClient *adapter) -- cgit v1.2.3