]> khamidou — GitHub mirrors - electron.git/commitdiff
Put common code of OpenURLFromTab to CommonWebContentsDelegate
authorCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 09:45:17 +0000 (17:45 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 09:45:17 +0000 (17:45 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/common_web_contents_delegate.cc
atom/browser/common_web_contents_delegate.h
atom/browser/native_window.cc

index 18bfc7a53f5fe8452b109f3bf1c97e2034d1b5b4..3678be78529bca6bb809828383d0c933f9f03f01 100644 (file)
@@ -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(
index 564efe7edd15e2eff587b7df2b882bb8d81c96d3..1cf75cf021ef6414caa4fabb4a97c6bbe9f27d66 100644 (file)
@@ -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,
index 30545e2e40432ed6b442f2e09fe5b0dddb635f51..84564e0ce7433dee2fa01967af662471bd1bb351 100644 (file)
@@ -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;
index 60a9eb27f2d25eeb4b96227dbe9f207679f5466f..8eb05cb9b0f22f413d6077ddf6403412d796a412 100644 (file)
@@ -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(