83 lines
4.2 KiB
Diff
83 lines
4.2 KiB
Diff
diff --git a/content/browser/frame_host/render_frame_host_manager.cc b/content/browser/frame_host/render_frame_host_manager.cc
|
|
index b682235b0f87..0c88f4bf86b6 100644
|
|
--- a/content/browser/frame_host/render_frame_host_manager.cc
|
|
+++ b/content/browser/frame_host/render_frame_host_manager.cc
|
|
@@ -1912,6 +1912,18 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
|
bool was_server_redirect = request.navigation_handle() &&
|
|
request.navigation_handle()->WasServerRedirect();
|
|
|
|
+ BrowserContext* browser_context =
|
|
+ delegate_->GetControllerForRenderManager().GetBrowserContext();
|
|
+ // If the navigation can swap SiteInstances, compute the SiteInstance it
|
|
+ // should use.
|
|
+ // TODO(clamy): We should also consider as a candidate SiteInstance the
|
|
+ // speculative SiteInstance that was computed on redirects.
|
|
+ scoped_refptr<SiteInstance> candidate_site_instance =
|
|
+ speculative_render_frame_host_
|
|
+ ? speculative_render_frame_host_->GetSiteInstance()
|
|
+ : content::SiteInstance::CreateForURL(browser_context,
|
|
+ request.common_params().url);
|
|
+
|
|
if (frame_tree_node_->IsMainFrame()) {
|
|
// Renderer-initiated main frame navigations that may require a
|
|
// SiteInstance swap are sent to the browser via the OpenURL IPC and are
|
|
@@ -1931,6 +1943,19 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
|
request.common_params().url));
|
|
no_renderer_swap_allowed |=
|
|
request.from_begin_navigation() && !can_renderer_initiate_transfer;
|
|
+
|
|
+ bool has_response_started =
|
|
+ (request.state() == NavigationRequest::RESPONSE_STARTED ||
|
|
+ request.state() == NavigationRequest::FAILED) &&
|
|
+ !speculative_render_frame_host_;
|
|
+ // Gives user a chance to choose a custom site instance.
|
|
+ SiteInstance* client_custom_instance = nullptr;
|
|
+ GetContentClient()->browser()->OverrideSiteInstanceForNavigation(
|
|
+ render_frame_host_.get(), browser_context, request.common_params().url,
|
|
+ has_response_started, candidate_site_instance.get(),
|
|
+ &client_custom_instance);
|
|
+ if (client_custom_instance)
|
|
+ return scoped_refptr<SiteInstance>(client_custom_instance);
|
|
} else {
|
|
// Subframe navigations will use the current renderer, unless specifically
|
|
// allowed to swap processes.
|
|
@@ -1942,18 +1967,9 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
|
if (no_renderer_swap_allowed)
|
|
return scoped_refptr<SiteInstance>(current_site_instance);
|
|
|
|
- // If the navigation can swap SiteInstances, compute the SiteInstance it
|
|
- // should use.
|
|
- // TODO(clamy): We should also consider as a candidate SiteInstance the
|
|
- // speculative SiteInstance that was computed on redirects.
|
|
- SiteInstance* candidate_site_instance =
|
|
- speculative_render_frame_host_
|
|
- ? speculative_render_frame_host_->GetSiteInstance()
|
|
- : nullptr;
|
|
-
|
|
scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation(
|
|
request.common_params().url, request.source_site_instance(),
|
|
- request.dest_site_instance(), candidate_site_instance,
|
|
+ request.dest_site_instance(), candidate_site_instance.get(),
|
|
request.common_params().transition,
|
|
request.state() == NavigationRequest::FAILED,
|
|
request.restore_type() != RestoreType::NONE, request.is_view_source(),
|
|
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
|
|
index 3ca627448e33..7d0c9ed7e1af 100644
|
|
--- a/content/public/browser/content_browser_client.h
|
|
+++ b/content/public/browser/content_browser_client.h
|
|
@@ -186,6 +186,15 @@ class CONTENT_EXPORT ContentBrowserClient {
|
|
public:
|
|
virtual ~ContentBrowserClient() {}
|
|
|
|
+ // Electron: Allows overriding the SiteInstance when navigating.
|
|
+ virtual void OverrideSiteInstanceForNavigation(
|
|
+ RenderFrameHost* render_frame_host,
|
|
+ BrowserContext* browser_context,
|
|
+ const GURL& dest_url,
|
|
+ bool has_response_started,
|
|
+ SiteInstance* candidate_site_instance,
|
|
+ SiteInstance** new_instance) {}
|
|
+
|
|
// Allows the embedder to set any number of custom BrowserMainParts
|
|
// implementations for the browser startup code. See comments in
|
|
// browser_main_parts.h.
|