From af62b7b5c9518fdc89e10dda8e07da01c8a3c5e1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 17:45:17 +0800 Subject: [PATCH] Put common code of OpenURLFromTab to CommonWebContentsDelegate --- atom/browser/api/atom_api_web_contents.cc | 14 +---------- atom/browser/common_web_contents_delegate.cc | 25 ++++++++++++++++++++ atom/browser/common_web_contents_delegate.h | 3 +++ atom/browser/native_window.cc | 14 +---------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 18bfc7a53f5..3678be78529 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -195,19 +195,7 @@ content::WebContents* WebContents::OpenURLFromTab( if (Emit("will-navigate", params.url)) return nullptr; - content::NavigationController::LoadURLParams load_url_params(params.url); - load_url_params.referrer = params.referrer; - load_url_params.transition_type = params.transition; - load_url_params.extra_headers = params.extra_headers; - load_url_params.should_replace_current_entry = - params.should_replace_current_entry; - load_url_params.is_renderer_initiated = params.is_renderer_initiated; - load_url_params.transferred_global_request_id = - params.transferred_global_request_id; - load_url_params.should_clear_history_list = true; - - web_contents()->GetController().LoadURLWithParams(load_url_params); - return web_contents(); + return CommonWebContentsDelegate::OpenURLFromTab(source, params); } void WebContents::HandleKeyboardEvent( diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 564efe7edd1..1cf75cf021e 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -15,6 +15,7 @@ #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" +#include "content/public/common/renderer_preferences.h" #include "storage/browser/fileapi/isolated_context.h" namespace atom { @@ -101,6 +102,12 @@ void CommonWebContentsDelegate::InitWithWebContents( owner_window_ = owner_window; web_contents->SetDelegate(this); + // Tell renderer to handle all navigations in browser. + auto preferences = web_contents->GetMutableRendererPrefs(); + preferences->browser_handles_non_local_top_level_requests = true; + preferences->browser_handles_all_top_level_requests = true; + web_contents->GetRenderViewHost()->SyncRendererPrefs(); + // Create InspectableWebContents. web_contents_.reset(brightray::InspectableWebContents::Create(web_contents)); web_contents_->SetDelegate(this); @@ -123,6 +130,24 @@ CommonWebContentsDelegate::GetDevToolsWebContents() const { return web_contents_->GetDevToolsWebContents(); } +content::WebContents* CommonWebContentsDelegate::OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) { + content::NavigationController::LoadURLParams load_url_params(params.url); + load_url_params.referrer = params.referrer; + load_url_params.transition_type = params.transition; + load_url_params.extra_headers = params.extra_headers; + load_url_params.should_replace_current_entry = + params.should_replace_current_entry; + load_url_params.is_renderer_initiated = params.is_renderer_initiated; + load_url_params.transferred_global_request_id = + params.transferred_global_request_id; + load_url_params.should_clear_history_list = true; + + source->GetController().LoadURLWithParams(load_url_params); + return source; +} + void CommonWebContentsDelegate::RequestToLockMouse( content::WebContents* web_contents, bool user_gesture, diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index 30545e2e404..84564e0ce74 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -48,6 +48,9 @@ class CommonWebContentsDelegate protected: // content::WebContentsDelegate: + content::WebContents* OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) override; void RequestToLockMouse(content::WebContents* web_contents, bool user_gesture, bool last_unlocked_by_target) override; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 60a9eb27f2d..8eb05cb9b0f 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -542,19 +542,7 @@ content::WebContents* NativeWindow::OpenURLFromTab( if (prevent_default) return nullptr; - content::NavigationController::LoadURLParams load_url_params(params.url); - load_url_params.referrer = params.referrer; - load_url_params.transition_type = params.transition; - load_url_params.extra_headers = params.extra_headers; - load_url_params.should_replace_current_entry = - params.should_replace_current_entry; - load_url_params.is_renderer_initiated = params.is_renderer_initiated; - load_url_params.transferred_global_request_id = - params.transferred_global_request_id; - load_url_params.should_clear_history_list = true; - - source->GetController().LoadURLWithParams(load_url_params); - return source; + return CommonWebContentsDelegate::OpenURLFromTab(source, params); } void NativeWindow::RenderViewCreated(