Restart renderer process for all navigations and reloads, fixes #157.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 14 Jan 2014 08:03:01 +0000 (16:03 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 14 Jan 2014 08:03:01 +0000 (16:03 +0800)
browser/atom_browser_client.cc
browser/native_window.cc
browser/native_window.h
renderer/atom_renderer_client.cc
renderer/atom_renderer_client.h

index 3c38721e52ffbd442aa4bcc26d022f67f20c487e..19617002a816d1ef4d08028865594ffda2176bdf 100644 (file)
@@ -50,8 +50,8 @@ bool AtomBrowserClient::ShouldSwapProcessesForNavigation(
     content::SiteInstance* site_instance,
     const GURL& current_url,
     const GURL& new_url) {
-  // Restart renderer process if navigating to the same url.
-  return current_url == new_url;
+  // Restart renderer process for all navigations.
+  return true;
 }
 
 brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
index 8aa0a266e3aae30d1183255e2fd4e700e9927a54..7b923adf2c3bc20c2bdfba2a2ac7459b163a2fd9 100644 (file)
@@ -283,6 +283,30 @@ void NativeWindow::NotifyWindowBlur() {
   FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
 }
 
+// In atom-shell all reloads and navigations started by renderer process would
+// be redirected to this method, so we can have precise control of how we
+// would open the url (in our case, is to restart the renderer process). See
+// AtomRendererClient::ShouldFork for how this is done.
+content::WebContents* NativeWindow::OpenURLFromTab(
+    content::WebContents* source,
+    const content::OpenURLParams& params) {
+  if (params.disposition != CURRENT_TAB)
+      return NULL;
+
+  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;
+
+  source->GetController().LoadURLWithParams(load_url_params);
+  return source;
+}
+
 content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager() {
   if (!dialog_manager_)
     dialog_manager_.reset(new AtomJavaScriptDialogManager);
index 4978ef9bdb771cd5b7a11b4fdf26852a3fd10c03..54cb539d755de01453a2191b257ab0ab496ca801 100644 (file)
@@ -157,6 +157,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
       const std::vector<DraggableRegion>& regions) = 0;
 
   // Implementations of content::WebContentsDelegate.
+  virtual content::WebContents* OpenURLFromTab(
+      content::WebContents* source,
+      const content::OpenURLParams& params) OVERRIDE;
   virtual content::JavaScriptDialogManager*
       GetJavaScriptDialogManager() OVERRIDE;
   virtual void BeforeUnloadFired(content::WebContents* tab,
index 176ca280efbc1f7de2dd98c5c072c7475097902d..c89b6c256e68723b999951498a96b133d9d35351 100644 (file)
@@ -98,4 +98,14 @@ void AtomRendererClient::WillReleaseScriptContext(
   }
 }
 
+bool AtomRendererClient::ShouldFork(WebKit::WebFrame* frame,
+                                    const GURL& url,
+                                    const std::string& http_method,
+                                    bool is_initial_navigation,
+                                    bool is_server_redirect,
+                                    bool* send_referrer) {
+  // Handle all the navigations and reloads in browser.
+  return true;
+}
+
 }  // namespace atom
index aa0a7bc7a2413ae270016665d131eefc64b36ea7..3dde5eb1d95058e3b8cfe1bd20f42693b370df5e 100644 (file)
@@ -35,6 +35,12 @@ class AtomRendererClient : public content::ContentRendererClient {
   virtual void WillReleaseScriptContext(WebKit::WebFrame* frame,
                                         v8::Handle<v8::Context>,
                                         int world_id) OVERRIDE;
+  virtual bool ShouldFork(WebKit::WebFrame* frame,
+                          const GURL& url,
+                          const std::string& http_method,
+                          bool is_initial_navigation,
+                          bool is_server_redirect,
+                          bool* send_referrer);
 
   std::vector<node::Environment*> web_page_envs_;