Commit e5531f4c authored by Jocelyn Turcotte's avatar Jocelyn Turcotte Committed by Zeno Albisser
Browse files

Fix the segfault on exit.


The WebEngineContext member was declared after the WebContentsDelegateQt
in WebContentsAdapter. This means that the delegate was destroyed after
the context and would cause the crash.

Reorder the declaration and move the WebContentsDelegateQt also to the
private class to reduce future confusion.

Change-Id: I343504d4fd1ede80feb710446368fdf12f360b15
Reviewed-by: default avatarZeno Albisser <zeno.albisser@digia.com>
Showing with 17 additions and 11 deletions
......@@ -53,19 +53,25 @@
// Used to maintain a WebEngineContext for as long as we need one
class WebContentsAdapterPrivate {
public:
WebContentsAdapterPrivate() : engineContext(WebEngineContext::current()) { }
WebContentsAdapterPrivate();
scoped_refptr<WebEngineContext> engineContext;
QScopedPointer<WebContentsDelegateQt> webContentsDelegate;
};
WebContentsAdapterPrivate::WebContentsAdapterPrivate()
// This has to be the first thing we create, and the last we destroy.
: engineContext(WebEngineContext::current())
{
}
WebContentsAdapter::WebContentsAdapter(WebContentsAdapterClient *adapterClient)
// This has to be the first thing we do.
: d(new WebContentsAdapterPrivate())
: d_ptr(new WebContentsAdapterPrivate)
{
Q_D(WebContentsAdapter);
content::BrowserContext* browserContext = ContentBrowserClientQt::Get()->browser_context();
webContentsDelegate.reset(new WebContentsDelegateQt(browserContext, NULL, MSG_ROUTING_NONE, gfx::Size()));
webContentsDelegate->m_viewClient = adapterClient;
WebContentsViewQt* contentsView = static_cast<WebContentsViewQt*>(webContentsDelegate->web_contents()->GetView());
d->webContentsDelegate.reset(new WebContentsDelegateQt(browserContext, NULL, MSG_ROUTING_NONE, gfx::Size()));
d->webContentsDelegate->m_viewClient = adapterClient;
WebContentsViewQt* contentsView = static_cast<WebContentsViewQt*>(d->webContentsDelegate->web_contents()->GetView());
contentsView->SetClient(adapterClient);
}
......@@ -139,6 +145,7 @@ QString WebContentsAdapter::pageTitle() const
content::WebContents *WebContentsAdapter::webContents() const
{
Q_ASSERT(webContentsDelegate);
return webContentsDelegate->web_contents();
Q_D(const WebContentsAdapter);
Q_ASSERT(d->webContentsDelegate);
return d->webContentsDelegate->web_contents();
}
......@@ -51,7 +51,6 @@ namespace content {
class WebContents;
}
class WebContentsAdapterClient;
class WebContentsDelegateQt;
class WebContentsAdapterPrivate;
class QWEBENGINE_EXPORT WebContentsAdapter {
......@@ -72,7 +71,7 @@ public:
private:
inline content::WebContents* webContents() const;
QScopedPointer<WebContentsDelegateQt> webContentsDelegate;
QScopedPointer<WebContentsAdapterPrivate> d;
Q_DECLARE_PRIVATE(WebContentsAdapter);
QScopedPointer<WebContentsAdapterPrivate> d_ptr;
};
#endif // WEB_CONTENTS_ADAPTER_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment