Restart renderer process for all navigations and reloads, fixes #157.

This commit is contained in:
Cheng Zhao 2014-01-14 16:03:01 +08:00
parent 931182b677
commit 249366c90a
5 changed files with 45 additions and 2 deletions

View 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(

View 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);

View 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,

View 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

View 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_;