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_delegate_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_delegate_qt.cpp')
-rw-r--r-- | lib/web_contents_delegate_qt.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/web_contents_delegate_qt.cpp b/lib/web_contents_delegate_qt.cpp index a4148e677..78de00620 100644 --- a/lib/web_contents_delegate_qt.cpp +++ b/lib/web_contents_delegate_qt.cpp @@ -63,6 +63,24 @@ void WebContentsDelegateQt::NavigationStateChanged(const content::WebContents* s m_viewClient->urlChanged(toQt(m_webContents->GetVisibleURL())); } +void WebContentsDelegateQt::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture, bool* was_blocked) +{ + WebContentsAdapter *newAdapter = new WebContentsAdapter(new_contents); + // Do the first ref-count manually to be able to know if the application is handling adoptNewWindow through the public API. + newAdapter->ref.ref(); + + m_viewClient->adoptNewWindow(newAdapter, static_cast<WebContentsAdapterClient::WindowOpenDisposition>(disposition)); + + if (!newAdapter->ref.deref()) { + // adoptNewWindow didn't increase the ref-count, new_contents needs to be discarded. + delete newAdapter; + newAdapter = 0; + } + + if (was_blocked) + *was_blocked = !newAdapter; +} + void WebContentsDelegateQt::LoadingStateChanged(content::WebContents* source) { m_viewClient->loadingStateChanged(); |