Merge pull request #508 from electron/enable_plznavigate

Update SiteInstance creation logic for Plznavigate
This commit is contained in:
Cheng Zhao 2018-04-06 16:22:09 +09:00 коммит произвёл GitHub
Родитель a1c127ed92 f1fc5cfb3d
Коммит 90df5e9e88
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 81 добавлений и 65 удалений

Просмотреть файл

@ -120,7 +120,7 @@ patches:
file: dom_storage_map.patch
description: null
-
owners: zcbenz
owners: zcbenz, deepak1556
file: frame_host_manager.patch
description: null
-
@ -135,10 +135,6 @@ patches:
owners: zcbenz
file: net_url_request_job.patch
description: null
-
owners: MarshallOfSound
file: new_site_instance.patch
description: null
-
owners: alexeykuzmin
file: no_stack_dumping.patch

Просмотреть файл

@ -126,10 +126,10 @@ index 5c2ab72ff537..3e7c25009c6a 100644
bool opener_suppressed,
bool* no_javascript_access) {
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index a3d217fd9446..1a6354a291b7 100644
index 61c108c53b92..d475ea55b085 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -129,6 +129,7 @@ class RenderFrameHost;
@@ -134,6 +134,7 @@ class RenderFrameHost;
class RenderProcessHost;
class RenderViewHost;
class ResourceContext;
@ -137,22 +137,7 @@ index a3d217fd9446..1a6354a291b7 100644
class SiteInstance;
class SpeechRecognitionManagerDelegate;
class StoragePartition;
@@ -153,6 +154,14 @@ class CONTENT_EXPORT ContentBrowserClient {
public:
virtual ~ContentBrowserClient() {}
+ // Electron: Allows overriding the SiteInstance when navigating.
+ virtual void OverrideSiteInstanceForNavigation(
+ RenderFrameHost* render_frame_host,
+ BrowserContext* browser_context,
+ SiteInstance* current_instance,
+ const GURL& dest_url,
+ 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.
@@ -509,6 +518,8 @@ class CONTENT_EXPORT ContentBrowserClient {
@@ -577,6 +578,8 @@ class CONTENT_EXPORT ContentBrowserClient {
const std::string& frame_name,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& features,

Просмотреть файл

@ -1,32 +1,83 @@
diff --git a/content/browser/frame_host/render_frame_host_manager.cc b/content/browser/frame_host/render_frame_host_manager.cc
index 1bbf60fac4e1..ca71865f89e8 100644
index f409294d982c..2de46b47ae40 100644
--- a/content/browser/frame_host/render_frame_host_manager.cc
+++ b/content/browser/frame_host/render_frame_host_manager.cc
@@ -1167,6 +1167,19 @@ RenderFrameHostManager::GetSiteInstanceForNavigation(
@@ -1996,6 +1996,18 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
bool was_server_redirect = request.navigation_handle() &&
request.navigation_handle()->WasServerRedirect();
SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
+ // Gives user a chance to pass a custom side instance.
+ SiteInstance* client_custom_instance = current_instance;
+ GetContentClient()->browser()->OverrideSiteInstanceForNavigation(
+ render_frame_host_.get(),
+ delegate_->GetControllerForRenderManager().GetBrowserContext(),
+ current_instance,
+ dest_url,
+ &client_custom_instance);
+ if (client_custom_instance != current_instance) {
+ GetContentClient()->browser()->OnCreateSiteInstanceForNavigation(client_custom_instance, render_frame_host_.get());
+ return client_custom_instance;
+ }
+ 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);
+
// We do not currently swap processes for navigations in webview tag guests.
if (current_instance->GetSiteURL().SchemeIs(kGuestScheme))
return current_instance;
@@ -1265,6 +1278,7 @@ RenderFrameHostManager::GetSiteInstanceForNavigation(
// BrowserContext.
DCHECK_EQ(new_instance->GetBrowserContext(), browser_context);
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
@@ -2012,6 +2024,19 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
+ GetContentClient()->browser()->OnCreateSiteInstanceForNavigation(new_instance.get(), render_frame_host_.get());
// If |new_instance| is a new SiteInstance for a subframe with an isolated
// origin, set its process reuse policy so that such subframes are
// consolidated into existing processes for that isolated origin.
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.
@@ -2023,18 +2048,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.restore_type() != RestoreType::NONE, request.is_view_source(),
was_server_redirect);
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index 61c108c53b92..a68b77ed429c 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -163,6 +163,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.

Просмотреть файл

@ -1,16 +0,0 @@
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index 3d9979e895f6..8b085fe8de0d 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -171,6 +171,11 @@ class CONTENT_EXPORT ContentBrowserClient {
const scoped_refptr<base::TaskRunner>& task_runner,
base::OnceClosure task);
+ // Electron: Allows intercepting the SiteInstance being created for navigation
+ virtual void OnCreateSiteInstanceForNavigation(
+ SiteInstance* new_instance,
+ RenderFrameHost* render_frame_host) {}
+
// Allows the embedder to indicate whether it considers startup to be
// complete. May be called on any thread. This should be called on a one-off
// basis; if you need to poll this function constantly, use the above