From bf4064cda667ca64b323223d3adada43f5c8413e Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Wed, 13 Aug 2014 16:52:51 +0200 Subject: Handle new window/tab modifiers also on normal navigations AddNewContents is only called when window.open is called from JavaScript. We also want the shift/ctrl modifiers to trigger normal links to open in the requested disposition. In this case OpenURLFromTab will pass the detected disposition and we must create a new WebContents ourselves. Use the same code path going through WebContentsAdapterClient::adoptNewWindow except that we pass a null WebContents pointer to the WebContentsAdapter constructor and let it create its own when initialized. Change-Id: I817b0e72aec12723bf92d9b7ad85c1cecbf5e408 Reviewed-by: Andras Becsi --- src/core/web_contents_delegate_qt.cpp | 46 ++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'src/core/web_contents_delegate_qt.cpp') diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 08f11cf5c..77d50140a 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -47,8 +47,8 @@ #include "media_capture_devices_dispatcher.h" #include "type_conversion.h" -#include "web_contents_adapter.h" #include "web_contents_adapter_client.h" +#include "web_contents_adapter_p.h" #include "web_engine_context.h" #include "web_engine_settings.h" #include "web_engine_visited_links_manager.h" @@ -84,8 +84,12 @@ WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents *webContents, content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents *source, const content::OpenURLParams ¶ms) { - // We already carry the disposition to the application through AddNewContents. - Q_UNUSED(params.disposition); + content::WebContents *target = source; + if (params.disposition != CURRENT_TAB) { + WebContentsAdapter *targetAdapter = createWindow(0, params.disposition, gfx::Rect(), params.user_gesture); + if (targetAdapter) + target = targetAdapter->d_func()->webContents.get(); + } content::NavigationController::LoadURLParams load_url_params(params.url); load_url_params.referrer = params.referrer; @@ -98,8 +102,8 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents if (params.transferred_global_request_id != content::GlobalRequestID()) load_url_params.transferred_global_request_id = params.transferred_global_request_id; - source->GetController().LoadURLWithParams(load_url_params); - return source; + target->GetController().LoadURLWithParams(load_url_params); + return target; } void WebContentsDelegateQt::NavigationStateChanged(const content::WebContents* source, unsigned changed_flags) @@ -112,18 +116,7 @@ void WebContentsDelegateQt::NavigationStateChanged(const content::WebContents* s 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(disposition), user_gesture, toQt(initial_pos)); - - if (!newAdapter->ref.deref()) { - // adoptNewWindow didn't increase the ref-count, new_contents needs to be discarded. - delete newAdapter; - newAdapter = 0; - } - + WebContentsAdapter *newAdapter = createWindow(new_contents, disposition, initial_pos, user_gesture); if (was_blocked) *was_blocked = !newAdapter; } @@ -257,6 +250,7 @@ void WebContentsDelegateQt::UpdateTargetURL(content::WebContents *source, int32 Q_UNUSED(page_id) m_viewClient->didUpdateTargetURL(toQt(url)); } + void WebContentsDelegateQt::DidNavigateAnyFrame(const content::LoadCommittedDetails &, const content::FrameNavigateParams ¶ms) { if (!params.should_update_history) @@ -264,7 +258,25 @@ void WebContentsDelegateQt::DidNavigateAnyFrame(const content::LoadCommittedDeta WebEngineContext::current()->visitedLinksManager()->addUrl(params.url); } + void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *, WebPreferences *webPreferences) { m_viewClient->webEngineSettings()->overrideWebPreferences(webPreferences); } + +WebContentsAdapter *WebContentsDelegateQt::createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) +{ + 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(disposition), user_gesture, toQt(initial_pos)); + + if (!newAdapter->ref.deref()) { + // adoptNewWindow didn't increase the ref-count, newAdapter and its new_contents (if non-null) need to be discarded. + delete newAdapter; + newAdapter = 0; + } + + return newAdapter; +} -- cgit v1.2.3