diff options
author | Michal Klocek <michal.klocek@qt.io> | 2018-04-30 09:44:58 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2018-05-18 10:49:35 +0000 |
commit | 7d6f72463ef372aabf4c4e6f212b9d331ef1338a (patch) | |
tree | dfc6f4cfc208170488bb415a259b71a7f3c399ae /src/core/web_contents_adapter.cpp | |
parent | 216f19d52ce9e920349da9247afc2c8e85df2c56 (diff) |
Remove keeping browser context as shared pointer in web context adapter
In widgets we document that web contents can not out live browser
context ie. WebEngineProfile can not be deleted before WebEnginePage
which uses it.
In qml we can not be sure the order in which objects are garbage
collected. We used shared pointers to keep order of destruction.
Unfortunately shared pointers do not work well with corner cases,
and we added more and more code to deal with that (shutdown methods
+ qpointers wrapping qsharedpointers). In order to remove growing
complexity remove usage of shared pointers to keep strict deletion order.
Remove shared pointer from WebContentsAdapter and simply track the WebContents,
that is used by the given BrowserContext. Force deletion of webcontents first.
Change-Id: I05f886a0094d971b03f9a35e12c4b4672f0fe4ce
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r-- | src/core/web_contents_adapter.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 3145583c3..6c4810c33 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -382,7 +382,8 @@ QSharedPointer<WebContentsAdapter> WebContentsAdapter::createFromSerializedNavig } WebContentsAdapter::WebContentsAdapter(content::WebContents *webContents) - : m_webContents(webContents) + : m_browserContextAdapter(nullptr) + , m_webContents(webContents) , m_webChannel(nullptr) , m_webChannelWorld(0) , m_adapterClient(nullptr) @@ -408,7 +409,7 @@ void WebContentsAdapter::setClient(WebContentsAdapterClient *adapterClient) 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(); + m_browserContextAdapter = adapterClient->browserContextAdapter().data(); Q_ASSERT(m_browserContextAdapter); // This might replace any adapter that has been initialized with this WebEngineSettings. @@ -892,7 +893,7 @@ BrowserContextQt* WebContentsAdapter::browserContext() BrowserContextAdapter* WebContentsAdapter::browserContextAdapter() { - return m_browserContextAdapter ? m_browserContextAdapter.data() : m_webContents ? static_cast<BrowserContextQt*>(m_webContents->GetBrowserContext())->adapter() : 0; + return m_browserContextAdapter ? m_browserContextAdapter : m_webContents ? static_cast<BrowserContextQt*>(m_webContents->GetBrowserContext())->adapter() : 0; } #ifndef QT_NO_ACCESSIBILITY |