2018-10-24 18:24:11 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-09-21 00:30:26 +00:00
|
|
|
From: deepak1556 <hop2deep@gmail.com>
|
2018-11-14 15:14:10 +00:00
|
|
|
Date: Wed, 14 Nov 2018 20:38:46 +0530
|
2018-09-21 00:30:26 +00:00
|
|
|
Subject: frame_host_manager.patch
|
|
|
|
|
2018-11-14 15:14:10 +00:00
|
|
|
Allows embedder to intercept site instances chosen by chromium
|
2019-05-31 22:47:18 +00:00
|
|
|
and respond with custom instance. Also allows for us to at-runtime
|
|
|
|
enable or disable this patch.
|
2018-09-21 00:30:26 +00:00
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/content/browser/frame_host/render_frame_host_manager.cc b/content/browser/frame_host/render_frame_host_manager.cc
|
2019-05-31 22:47:18 +00:00
|
|
|
index b5301d164138f21ca8ae01abfb153efde51ec324..886b6d3beb3e2d7b13a15af830bea6fb5a567cba 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/browser/frame_host/render_frame_host_manager.cc
|
|
|
|
+++ b/content/browser/frame_host/render_frame_host_manager.cc
|
2019-05-31 22:47:18 +00:00
|
|
|
@@ -2127,6 +2127,20 @@ bool RenderFrameHostManager::InitRenderView(
|
2019-01-12 01:00:43 +00:00
|
|
|
scoped_refptr<SiteInstance>
|
|
|
|
RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
|
|
|
const NavigationRequest& request) {
|
2019-05-31 22:47:18 +00:00
|
|
|
+ BrowserContext* browser_context = nullptr;
|
|
|
|
+ scoped_refptr<SiteInstance> candidate_site_instance;
|
|
|
|
+ if (!GetContentClient()->browser()->CanUseCustomSiteInstance()) {
|
|
|
|
+ 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.
|
|
|
|
+ candidate_site_instance =
|
|
|
|
+ speculative_render_frame_host_
|
|
|
|
+ ? speculative_render_frame_host_->GetSiteInstance()
|
|
|
|
+ : nullptr;
|
|
|
|
+ }
|
2019-01-12 01:00:43 +00:00
|
|
|
// First, check if the navigation can switch SiteInstances. If not, the
|
|
|
|
// navigation should use the current SiteInstance.
|
|
|
|
SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance();
|
2019-05-31 22:47:18 +00:00
|
|
|
@@ -2159,6 +2173,53 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
2019-01-12 01:00:43 +00:00
|
|
|
request.common_params().url);
|
2018-09-14 05:02:16 +00:00
|
|
|
no_renderer_swap_allowed |=
|
|
|
|
request.from_begin_navigation() && !can_renderer_initiate_transfer;
|
|
|
|
+
|
2019-05-31 22:47:18 +00:00
|
|
|
+ if (!GetContentClient()->browser()->CanUseCustomSiteInstance()) {
|
|
|
|
+ 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* affinity_site_instance = nullptr;
|
|
|
|
+ scoped_refptr<SiteInstance> overriden_site_instance;
|
|
|
|
+ ContentBrowserClient::SiteInstanceForNavigationType siteInstanceType =
|
|
|
|
+ GetContentClient()->browser()->ShouldOverrideSiteInstanceForNavigation(
|
|
|
|
+ current_frame_host(), speculative_frame_host(), browser_context,
|
|
|
|
+ request.common_params().url, has_response_started,
|
|
|
|
+ &affinity_site_instance);
|
|
|
|
+ switch (siteInstanceType) {
|
|
|
|
+ case ContentBrowserClient::SiteInstanceForNavigationType::
|
|
|
|
+ FORCE_CANDIDATE_OR_NEW:
|
|
|
|
+ overriden_site_instance =
|
|
|
|
+ candidate_site_instance
|
|
|
|
+ ? candidate_site_instance
|
|
|
|
+ : SiteInstance::CreateForURL(browser_context,
|
|
|
|
+ request.common_params().url);
|
|
|
|
+ break;
|
|
|
|
+ case ContentBrowserClient::SiteInstanceForNavigationType::FORCE_CURRENT:
|
|
|
|
+ overriden_site_instance = render_frame_host_->GetSiteInstance();
|
|
|
|
+ break;
|
|
|
|
+ case ContentBrowserClient::SiteInstanceForNavigationType::FORCE_AFFINITY:
|
|
|
|
+ DCHECK(affinity_site_instance);
|
|
|
|
+ overriden_site_instance =
|
|
|
|
+ scoped_refptr<SiteInstance>(affinity_site_instance);
|
|
|
|
+ break;
|
|
|
|
+ case ContentBrowserClient::SiteInstanceForNavigationType::ASK_CHROMIUM:
|
|
|
|
+ DCHECK(!affinity_site_instance);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (overriden_site_instance) {
|
|
|
|
+ if (siteInstanceType ==
|
|
|
|
+ ContentBrowserClient::SiteInstanceForNavigationType::
|
|
|
|
+ FORCE_CANDIDATE_OR_NEW) {
|
|
|
|
+ GetContentClient()->browser()->RegisterPendingSiteInstance(
|
|
|
|
+ render_frame_host_.get(), overriden_site_instance.get());
|
|
|
|
+ }
|
|
|
|
+ return overriden_site_instance;
|
2018-12-05 08:03:39 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
2018-09-14 05:02:16 +00:00
|
|
|
} else {
|
|
|
|
// Subframe navigations will use the current renderer, unless specifically
|
|
|
|
// allowed to swap processes.
|
2019-05-31 22:47:18 +00:00
|
|
|
@@ -2170,23 +2231,28 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
2019-01-12 01:00:43 +00:00
|
|
|
if (no_renderer_swap_allowed && !should_swap_for_error_isolation)
|
2018-09-14 05:02:16 +00:00
|
|
|
return scoped_refptr<SiteInstance>(current_site_instance);
|
|
|
|
|
2019-05-31 22:47:18 +00:00
|
|
|
+ if (GetContentClient()->browser()->CanUseCustomSiteInstance()) {
|
|
|
|
// 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.
|
2018-09-14 05:02:16 +00:00
|
|
|
- SiteInstance* candidate_site_instance =
|
2019-05-31 22:47:18 +00:00
|
|
|
+ candidate_site_instance =
|
|
|
|
speculative_render_frame_host_
|
|
|
|
? speculative_render_frame_host_->GetSiteInstance()
|
|
|
|
: nullptr;
|
|
|
|
+ }
|
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
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,
|
2018-09-14 18:03:43 +00:00
|
|
|
request.state() == NavigationRequest::FAILED,
|
2018-09-14 05:02:16 +00:00
|
|
|
request.restore_type() != RestoreType::NONE, request.is_view_source(),
|
2018-12-05 08:03:39 +00:00
|
|
|
was_server_redirect);
|
|
|
|
|
|
|
|
+ GetContentClient()->browser()->RegisterPendingSiteInstance(
|
|
|
|
+ render_frame_host_.get(), dest_site_instance.get());
|
|
|
|
+
|
|
|
|
return dest_site_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc
|
2019-05-31 22:47:18 +00:00
|
|
|
index 787cd81b26508d3e04956721f0e7cec2f457aa60..8e62a5dd26595411757e03078ed0e44646c47a52 100644
|
2018-12-05 08:03:39 +00:00
|
|
|
--- a/content/public/browser/content_browser_client.cc
|
|
|
|
+++ b/content/public/browser/content_browser_client.cc
|
2019-05-31 22:47:18 +00:00
|
|
|
@@ -51,6 +51,20 @@ void OverrideOnBindInterface(const service_manager::BindSourceInfo& remote_info,
|
2018-12-05 08:03:39 +00:00
|
|
|
handle);
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:47:18 +00:00
|
|
|
+bool ContentBrowserClient::CanUseCustomSiteInstance() {
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
2018-12-05 08:03:39 +00:00
|
|
|
+ContentBrowserClient::SiteInstanceForNavigationType ContentBrowserClient::ShouldOverrideSiteInstanceForNavigation(
|
|
|
|
+ content::RenderFrameHost* current_rfh,
|
|
|
|
+ content::RenderFrameHost* speculative_rfh,
|
|
|
|
+ content::BrowserContext* browser_context,
|
|
|
|
+ const GURL& url,
|
|
|
|
+ bool has_request_started,
|
|
|
|
+ content::SiteInstance** affinity_site_instance) const {
|
|
|
|
+ return SiteInstanceForNavigationType::ASK_CHROMIUM;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
BrowserMainParts* ContentBrowserClient::CreateBrowserMainParts(
|
|
|
|
const MainFunctionParams& parameters) {
|
|
|
|
return nullptr;
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
|
2019-05-31 22:47:18 +00:00
|
|
|
index bf9b3a601fc16d5070e4467a258a047f47b059f3..3c35eddc2498157c2b98bab55991d8aa195954f6 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/public/browser/content_browser_client.h
|
|
|
|
+++ b/content/public/browser/content_browser_client.h
|
2019-05-31 22:47:18 +00:00
|
|
|
@@ -211,8 +211,40 @@ CONTENT_EXPORT void OverrideOnBindInterface(
|
2018-12-05 08:03:39 +00:00
|
|
|
// the observer interfaces.)
|
|
|
|
class CONTENT_EXPORT ContentBrowserClient {
|
2018-09-14 05:02:16 +00:00
|
|
|
public:
|
2018-12-05 08:03:39 +00:00
|
|
|
+ // Identifies the type of site instance to use for a navigation.
|
|
|
|
+ enum SiteInstanceForNavigationType {
|
|
|
|
+ // Use either the candidate site instance or, if it doesn't exist
|
|
|
|
+ // a new, unrelated site instance for the navigation.
|
|
|
|
+ FORCE_CANDIDATE_OR_NEW = 0,
|
|
|
|
+
|
|
|
|
+ // Use the current site instance for the navigation.
|
|
|
|
+ FORCE_CURRENT,
|
|
|
|
+
|
|
|
|
+ // Use the provided affinity site instance for the navigation.
|
|
|
|
+ FORCE_AFFINITY,
|
|
|
|
+
|
|
|
|
+ // Delegate the site instance creation to Chromium.
|
|
|
|
+ ASK_CHROMIUM
|
|
|
|
+ };
|
2018-09-14 05:02:16 +00:00
|
|
|
virtual ~ContentBrowserClient() {}
|
|
|
|
|
2019-05-31 22:47:18 +00:00
|
|
|
+ // Electron: Allows disabling the below ShouldOverride patch
|
|
|
|
+ virtual bool CanUseCustomSiteInstance();
|
|
|
|
+
|
2018-09-14 05:02:16 +00:00
|
|
|
+ // Electron: Allows overriding the SiteInstance when navigating.
|
2018-12-05 08:03:39 +00:00
|
|
|
+ virtual SiteInstanceForNavigationType ShouldOverrideSiteInstanceForNavigation(
|
|
|
|
+ content::RenderFrameHost* current_rfh,
|
|
|
|
+ content::RenderFrameHost* speculative_rfh,
|
|
|
|
+ content::BrowserContext* browser_context,
|
|
|
|
+ const GURL& url,
|
|
|
|
+ bool has_request_started,
|
|
|
|
+ content::SiteInstance** affinity_site_instance) const;
|
|
|
|
+
|
|
|
|
+ // Electron: Registers a pending site instance during a navigation.
|
|
|
|
+ virtual void RegisterPendingSiteInstance(
|
|
|
|
+ content::RenderFrameHost* rfh,
|
2019-02-27 01:43:34 +00:00
|
|
|
+ content::SiteInstance* pending_site_instance) {}
|
2018-09-14 05:02:16 +00:00
|
|
|
+
|
|
|
|
// Allows the embedder to set any number of custom BrowserMainParts
|
|
|
|
// implementations for the browser startup code. See comments in
|
|
|
|
// browser_main_parts.h.
|