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>
|
2019-06-04 03:44:12 +00:00
|
|
|
Date: Mon, 3 Jun 2019 14:20:05 -0700
|
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
|
|
|
|
2019-06-03 20:23:15 +00:00
|
|
|
diff --git a/content/browser/browsing_instance.cc b/content/browser/browsing_instance.cc
|
2019-07-24 22:58:51 +00:00
|
|
|
index 0726c4fbc873e40991262b2951557b7be169e624..7520514de6f56d84afee6c612584f0be1ec41227 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/browser/browsing_instance.cc
|
|
|
|
+++ b/content/browser/browsing_instance.cc
|
2019-07-03 01:22:09 +00:00
|
|
|
@@ -83,6 +83,13 @@ scoped_refptr<SiteInstanceImpl> BrowsingInstance::GetSiteInstanceForURL(
|
2019-06-03 20:23:15 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
+scoped_refptr<SiteInstanceImpl> BrowsingInstance::CreateSiteInstanceForURL(
|
|
|
|
+ const GURL& url) {
|
|
|
|
+ scoped_refptr<SiteInstanceImpl> instance = new SiteInstanceImpl(this);
|
|
|
|
+ instance->SetSite(url);
|
|
|
|
+ return instance;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void BrowsingInstance::GetSiteAndLockForURL(const GURL& url,
|
|
|
|
bool allow_default_instance,
|
|
|
|
GURL* site_url,
|
|
|
|
diff --git a/content/browser/browsing_instance.h b/content/browser/browsing_instance.h
|
2019-07-03 01:22:09 +00:00
|
|
|
index acbf074f6e408cdc3817580b9601ee40c036c4dd..e56456c5b6024b92dbd025a8f25d4bde5f8afe27 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/browser/browsing_instance.h
|
|
|
|
+++ b/content/browser/browsing_instance.h
|
|
|
|
@@ -136,6 +136,11 @@ class CONTENT_EXPORT BrowsingInstance final
|
|
|
|
const GURL& url,
|
|
|
|
bool allow_default_instance);
|
|
|
|
|
|
|
|
+ // Create a new SiteInstance for the given URL bound the current
|
|
|
|
+ // BrowsingInstance.
|
|
|
|
+ scoped_refptr<SiteInstanceImpl> CreateSiteInstanceForURL(
|
|
|
|
+ const GURL& url);
|
|
|
|
+
|
|
|
|
// Adds the given SiteInstance to our map, to ensure that we do not create
|
|
|
|
// another SiteInstance for the same site.
|
|
|
|
void RegisterSiteInstance(SiteInstanceImpl* site_instance);
|
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-07-24 22:58:51 +00:00
|
|
|
index 8ca7df4cc21892d9769527df717ab5fd3945e9c7..dbaf878eaf5259697469e06d5ae15fbc463aa7c6 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-07-24 22:58:51 +00:00
|
|
|
@@ -2180,6 +2180,21 @@ 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;
|
2019-07-03 01:22:09 +00:00
|
|
|
+ scoped_refptr<SiteInstanceImpl> candidate_site_instance;
|
2019-05-31 22:47:18 +00:00
|
|
|
+ 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-07-03 01:22:09 +00:00
|
|
|
+
|
2019-01-12 01:00:43 +00:00
|
|
|
SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance();
|
2019-07-03 01:22:09 +00:00
|
|
|
|
|
|
|
// All children of MHTML documents must be MHTML documents. They all live in
|
2019-07-24 22:58:51 +00:00
|
|
|
@@ -2217,6 +2232,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
|
2019-06-03 20:23:15 +00:00
|
|
|
+ : current_site_instance->CreateRelatedSiteInstance(
|
2019-05-31 22:47:18 +00:00
|
|
|
+ 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-07-24 22:58:51 +00:00
|
|
|
@@ -2228,23 +2290,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.
|
2019-07-03 01:22:09 +00:00
|
|
|
- SiteInstanceImpl* 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;
|
|
|
|
}
|
|
|
|
|
2019-06-03 20:23:15 +00:00
|
|
|
diff --git a/content/browser/site_instance_impl.cc b/content/browser/site_instance_impl.cc
|
2019-07-24 22:58:51 +00:00
|
|
|
index b29e2479caed43a3ace1f0e5ce923fd6c7fb760e..4999c89b3a8e54ab6030b85fbf172af3fedd0836 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/browser/site_instance_impl.cc
|
|
|
|
+++ b/content/browser/site_instance_impl.cc
|
2019-07-03 01:22:09 +00:00
|
|
|
@@ -356,6 +356,10 @@ bool SiteInstanceImpl::HasRelatedSiteInstance(const GURL& url) {
|
2019-06-03 20:23:15 +00:00
|
|
|
return browsing_instance_->HasSiteInstance(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
+scoped_refptr<SiteInstance> SiteInstanceImpl::CreateRelatedSiteInstance(const GURL& url) {
|
|
|
|
+ return browsing_instance_->CreateSiteInstanceForURL(url);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
scoped_refptr<SiteInstance> SiteInstanceImpl::GetRelatedSiteInstance(
|
|
|
|
const GURL& url) {
|
|
|
|
return browsing_instance_->GetSiteInstanceForURL(
|
|
|
|
diff --git a/content/browser/site_instance_impl.h b/content/browser/site_instance_impl.h
|
2019-07-24 22:58:51 +00:00
|
|
|
index 17b08b2749a93a3f4e8c0409fc292c76331bfbb3..bec401c170b68f416cefde4ad309b9c3aa255243 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/browser/site_instance_impl.h
|
|
|
|
+++ b/content/browser/site_instance_impl.h
|
|
|
|
@@ -83,6 +83,7 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance,
|
|
|
|
BrowserContext* GetBrowserContext() override;
|
|
|
|
const GURL& GetSiteURL() override;
|
|
|
|
scoped_refptr<SiteInstance> GetRelatedSiteInstance(const GURL& url) override;
|
2019-06-04 03:44:12 +00:00
|
|
|
+ scoped_refptr<SiteInstance> CreateRelatedSiteInstance(const GURL& url) override;
|
2019-06-03 20:23:15 +00:00
|
|
|
bool IsRelatedSiteInstance(const SiteInstance* instance) override;
|
|
|
|
size_t GetRelatedActiveContentsCount() override;
|
|
|
|
bool RequiresDedicatedProcess() override;
|
2018-12-05 08:03:39 +00:00
|
|
|
diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc
|
2019-07-24 22:58:51 +00:00
|
|
|
index 06984e1da1512c3d8577716432920a1755524cf8..87140030f883a0149e5c373f2c6391020974dcfc 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-06-04 03:44:12 +00:00
|
|
|
@@ -52,6 +52,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;
|
|
|
|
+}
|
|
|
|
+
|
2019-06-04 03:44:12 +00:00
|
|
|
std::unique_ptr<BrowserMainParts> ContentBrowserClient::CreateBrowserMainParts(
|
2018-12-05 08:03:39 +00:00
|
|
|
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-07-24 22:58:51 +00:00
|
|
|
index 52cf099889768bbc14acc3f32fcfba5ab7640a1d..b62c08de3ee8efc3090876531a80ea43e4ac6a07 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-07-24 22:58:51 +00:00
|
|
|
@@ -209,8 +209,41 @@ 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
|
|
|
|
+ };
|
2019-06-04 03:44:12 +00:00
|
|
|
+
|
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(
|
2019-06-04 03:44:12 +00:00
|
|
|
+ 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;
|
2018-12-05 08:03:39 +00:00
|
|
|
+
|
|
|
|
+ // 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.
|
2019-06-03 20:23:15 +00:00
|
|
|
diff --git a/content/public/browser/site_instance.h b/content/public/browser/site_instance.h
|
2019-06-04 03:44:12 +00:00
|
|
|
index a3e880e20e51d988175f0e8e2c42e7f5c1740104..faadd39d01530092f4f31a896ecb60f235e7f63f 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/public/browser/site_instance.h
|
|
|
|
+++ b/content/public/browser/site_instance.h
|
|
|
|
@@ -121,6 +121,11 @@ class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> {
|
|
|
|
// corresponds to a site URL with the host "example.com".
|
|
|
|
virtual const GURL& GetSiteURL() = 0;
|
|
|
|
|
2019-06-04 03:44:12 +00:00
|
|
|
+ // Create a SiteInstance for the given URL that shares the current
|
|
|
|
+ // BrowsingInstance.
|
|
|
|
+ virtual scoped_refptr<SiteInstance> CreateRelatedSiteInstance(
|
|
|
|
+ const GURL& url) = 0;
|
2019-06-03 20:23:15 +00:00
|
|
|
+
|
|
|
|
// Gets a SiteInstance for the given URL that shares the current
|
|
|
|
// BrowsingInstance, creating a new SiteInstance if necessary. This ensures
|
|
|
|
// that a BrowsingInstance only has one SiteInstance per site, so that pages
|