diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-08-27 16:36:03 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-09-02 12:18:24 +0200 |
commit | 7146fcc14dcd69f39f20a3e49a9b371bd306bb53 (patch) | |
tree | 708cbbe9e6fa39edcccd334b09eba9ec123224c9 /lib/web_contents_view_qt.cpp | |
parent | b7210ab328438038bbf1c0e03f19616d6ce56c76 (diff) |
Implement window creation through QWebEnginePage::createWindow.
This makes the necessary changes to handle
WebContentsDelegateQt::AddNewContents and funnel the callback
through createWindow in QWebEnginePage and QWebEngineView.
- Expose the AddNewContents callback through WebContentsAdapterClient
- Allow creating a WebContentsAdapter attached only on the Chromium side,
leaving the choice to QWebEnginePage to either adopt it and call
WebContentsAdapter::initialize to attach itself as the client, or
destroy it if the application isn't handling the call.
- Delay the InitAsChild handling in RenderWidgetHostViewQt when
it is called before an adapter client has been attached.
- Since WebContentsAdapterClient::CreateRenderWidgetHostViewQtDelegate
is only a factory method, not creating any link with the callee client,
allow using the creating window's adapter client to create the RWHVQtDelegate.
This allows an unparented delegate to be created instead of needing to
add numerous null-checks in RWHVQt.
Use content::WebContents::CreateParams::context for this purpose,
which can be used both when creating a WebContents ourselves and when
a new window's WebContents is created for us.
Change-Id: I032262e867931dc40a7c2eca0c993027a555f56e
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'lib/web_contents_view_qt.cpp')
-rw-r--r-- | lib/web_contents_view_qt.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/lib/web_contents_view_qt.cpp b/lib/web_contents_view_qt.cpp index db991d84b..b74b7325a 100644 --- a/lib/web_contents_view_qt.cpp +++ b/lib/web_contents_view_qt.cpp @@ -47,24 +47,49 @@ #include "content/browser/renderer_host/render_view_host_impl.h" +void WebContentsViewQt::initialize(WebContentsAdapterClient* client) +{ + m_client = client; + + // Check if a RWHV was created before the initialization. + if (m_webContents->GetRenderWidgetHostView()) + static_cast<RenderWidgetHostViewQt *>(m_webContents->GetRenderWidgetHostView())->setAdapterClient(client); +} + content::RenderWidgetHostView* WebContentsViewQt::CreateViewForWidget(content::RenderWidgetHost* render_widget_host) { RenderWidgetHostViewQt *view = new RenderWidgetHostViewQt(render_widget_host); - RenderWidgetHostViewQtDelegate* viewDelegate = m_client->CreateRenderWidgetHostViewQtDelegate(); - view->SetDelegate(viewDelegate); - // The delegate has been bound to its view, now initialize it. - // gfx::NativeView logically maps to our client here but the reinterpret_cast is still ugly. - // The alternative is be to have a duplicated method with the proper signature. - view->InitAsChild(reinterpret_cast<gfx::NativeView>(m_client)); + + Q_ASSERT(m_factoryClient); + RenderWidgetHostViewQtDelegate* viewDelegate = m_factoryClient->CreateRenderWidgetHostViewQtDelegate(); + view->setDelegate(viewDelegate); + if (m_client) + view->setAdapterClient(m_client); + + // Tell the RWHV delegate to attach itself to the native view container. + view->InitAsChild(0); return view; } +void WebContentsViewQt::CreateView(const gfx::Size& initial_size, gfx::NativeView context) +{ + // This is passed through content::WebContents::CreateParams::context either as the native view's client + // directly or, in the case of a page-created new window, the client of the creating window's native view. + m_factoryClient = reinterpret_cast<WebContentsAdapterClient *>(context); +} + void WebContentsViewQt::SetPageTitle(const string16& title) { m_client->titleChanged(toQt(title)); } +gfx::NativeView WebContentsViewQt::GetNativeView() const +{ + // Hack to provide the client to WebContentsImpl::CreateNewWindow. + return reinterpret_cast<gfx::NativeView>(m_client); +} + void WebContentsViewQt::GetContainerBounds(gfx::Rect* out) const { const QRectF r(m_client->viewportRect()); |