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
|
2020-01-29 12:01:37 +00:00
|
|
|
index f49ec7e1456751e506609a797f0b3b97b3e86a56..c7198c08d9292981d6fba12d5941f606c03b5d35 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/browser/browsing_instance.cc
|
|
|
|
+++ b/content/browser/browsing_instance.cc
|
2020-01-29 12:01:37 +00:00
|
|
|
@@ -84,6 +84,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-26 19:18:32 +00:00
|
|
|
index 906a1ee4ac58b0744a32153bbaafeac4322a60e4..c90f4aead36cbf3767dc5094728963c24798e204 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);
|
2019-12-11 00:22:35 +00:00
|
|
|
diff --git a/content/browser/frame_host/navigation_request.cc b/content/browser/frame_host/navigation_request.cc
|
2020-01-29 12:01:37 +00:00
|
|
|
index 0fd355a218cc454380c9e48ae299872484078f4d..8824293926782106cb7f8fb1eb76adda6963b97d 100644
|
2019-12-11 00:22:35 +00:00
|
|
|
--- a/content/browser/frame_host/navigation_request.cc
|
|
|
|
+++ b/content/browser/frame_host/navigation_request.cc
|
2020-01-21 17:39:37 +00:00
|
|
|
@@ -1198,6 +1198,24 @@ void NavigationRequest::BeginNavigation() {
|
2019-12-11 00:22:35 +00:00
|
|
|
TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
|
|
|
|
"ResponseStarted");
|
|
|
|
|
|
|
|
+ // In Electron, a new process is started for every navigation when node is
|
|
|
|
+ // integrated in the renderer. Since GetFrameHostForNavigation is called more
|
|
|
|
+ // than once per navigation, we want to return the same frame host once
|
|
|
|
+ // the response has started, otherwise if the frame host that started the response
|
|
|
|
+ // and the frame host that is available for commit don't match then request will
|
|
|
|
+ // be cancelled. We rely on the NavigationRequest::state_ to determine this
|
|
|
|
+ // factor
|
|
|
|
+ //
|
|
|
|
+ // bool has_response_started =
|
|
|
|
+ // (request->state() >= NavigationRequest::WILL_PROCESS_RESPONSE &&
|
|
|
|
+ // !speculative_render_frame_host_);
|
|
|
|
+ //
|
|
|
|
+ // Hence this call is necesary before the call to GetFrameHostForNavigation. Also
|
|
|
|
+ // the state_ here is anyway going to end up being READY_TO_COMMIT because of
|
|
|
|
+ // ReadyToCommitNavigation a few lines later, so will not affect normal chromium
|
|
|
|
+ // request cycle.
|
|
|
|
+ state_ = READY_TO_COMMIT;
|
|
|
|
+
|
|
|
|
// Select an appropriate RenderFrameHost.
|
|
|
|
render_frame_host_ =
|
|
|
|
frame_tree_node_->render_manager()->GetFrameHostForNavigation(this);
|
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
|
2020-01-29 21:45:08 +00:00
|
|
|
index d55a185f524c004e060936e43229568b36cad8a9..a82d6547951e42b1ef2af260c42e5c426baac896 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
|
2020-01-29 21:45:08 +00:00
|
|
|
@@ -2173,6 +2173,16 @@ bool RenderFrameHostManager::InitRenderView(
|
2019-01-12 01:00:43 +00:00
|
|
|
scoped_refptr<SiteInstance>
|
|
|
|
RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
2019-09-21 14:51:28 +00:00
|
|
|
NavigationRequest* request) {
|
2019-11-05 23:41:20 +00:00
|
|
|
+ // Compute the SiteInstance that the navigation should use, which will be
|
|
|
|
+ // either the current SiteInstance or a new one.
|
|
|
|
+ //
|
|
|
|
+ // TODO(clamy): We should also consider as a candidate SiteInstance the
|
|
|
|
+ // speculative SiteInstance that was computed on redirects.
|
|
|
|
+ SiteInstanceImpl* 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
|
2020-01-29 21:45:08 +00:00
|
|
|
@@ -2192,10 +2202,60 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
2019-11-05 23:41:20 +00:00
|
|
|
//
|
2019-05-31 22:47:18 +00:00
|
|
|
// 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-11-05 23:41:20 +00:00
|
|
|
- speculative_render_frame_host_
|
|
|
|
- ? speculative_render_frame_host_->GetSiteInstance()
|
|
|
|
- : nullptr;
|
|
|
|
+ if (!GetContentClient()->browser()->CanUseCustomSiteInstance() &&
|
|
|
|
+ frame_tree_node_->IsMainFrame()) {
|
|
|
|
+ BrowserContext* browser_context =
|
|
|
|
+ delegate_->GetControllerForRenderManager().GetBrowserContext();
|
|
|
|
+ bool has_navigation_started = request->state() != NavigationRequest::NOT_STARTED;
|
|
|
|
+ bool has_response_started =
|
2019-12-11 00:22:35 +00:00
|
|
|
+ (request->state() >= NavigationRequest::WILL_PROCESS_RESPONSE &&
|
|
|
|
+ !speculative_render_frame_host_);
|
2019-11-05 23:41:20 +00:00
|
|
|
+ // Gives user a chance to choose a custom site instance.
|
|
|
|
+ SiteInstance* affinity_site_instance = nullptr;
|
|
|
|
+ scoped_refptr<SiteInstance> overriden_site_instance;
|
|
|
|
+ bool should_register_site_instance = false;
|
|
|
|
+ ContentBrowserClient::SiteInstanceForNavigationType siteInstanceType =
|
|
|
|
+ GetContentClient()->browser()->ShouldOverrideSiteInstanceForNavigation(
|
|
|
|
+ current_frame_host(), speculative_frame_host(), browser_context,
|
|
|
|
+ request->common_params().url, has_navigation_started,
|
|
|
|
+ has_response_started, &affinity_site_instance);
|
|
|
|
+ switch (siteInstanceType) {
|
|
|
|
+ case ContentBrowserClient::SiteInstanceForNavigationType::
|
|
|
|
+ FORCE_CANDIDATE_OR_NEW:
|
|
|
|
+ overriden_site_instance =
|
|
|
|
+ candidate_site_instance
|
|
|
|
+ ? candidate_site_instance
|
|
|
|
+ : current_site_instance->CreateRelatedSiteInstance(
|
|
|
|
+ request->common_params().url);
|
|
|
|
+ should_register_site_instance = true;
|
|
|
|
+ break;
|
|
|
|
+ case ContentBrowserClient::SiteInstanceForNavigationType::FORCE_NEW:
|
|
|
|
+ overriden_site_instance = current_site_instance->CreateRelatedSiteInstance(
|
|
|
|
+ request->common_params().url);
|
|
|
|
+ should_register_site_instance = true;
|
|
|
|
+ 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 (should_register_site_instance) {
|
|
|
|
+ GetContentClient()->browser()->RegisterPendingSiteInstance(
|
|
|
|
+ render_frame_host_.get(), overriden_site_instance.get());
|
|
|
|
+ }
|
|
|
|
+ return overriden_site_instance;
|
|
|
|
+ }
|
2019-05-31 22:47:18 +00:00
|
|
|
+ }
|
|
|
|
|
2020-01-29 21:45:08 +00:00
|
|
|
// Account for renderer-initiated reload as well.
|
|
|
|
// Needed as a workaround for https://crbug.com/1045524, remove it when it is
|
|
|
|
@@ -2215,6 +2275,9 @@ RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
|
2019-09-21 14:51:28 +00:00
|
|
|
request->GetRestoreType() != RestoreType::NONE, request->is_view_source(),
|
2019-11-05 23:41:20 +00:00
|
|
|
request->WasServerRedirect());
|
2018-12-05 08:03:39 +00:00
|
|
|
|
|
|
|
+ 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
|
2020-01-29 21:45:08 +00:00
|
|
|
index eb20d84de260b35049cac72fdc8d0645688fdd9a..eb3106ece80f3b347b7b13efbd77b11a60e03169 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/browser/site_instance_impl.cc
|
|
|
|
+++ b/content/browser/site_instance_impl.cc
|
2020-01-29 21:45:08 +00:00
|
|
|
@@ -427,6 +427,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
|
2020-01-17 18:41:52 +00:00
|
|
|
index caa100b3889e17a9afdc8127e0e13bb6b86e8042..f08d3a2eb28f0f6fff89b5759eff5369b7111821 100644
|
2019-06-03 20:23:15 +00:00
|
|
|
--- a/content/browser/site_instance_impl.h
|
|
|
|
+++ b/content/browser/site_instance_impl.h
|
2020-01-17 18:41:52 +00:00
|
|
|
@@ -98,6 +98,7 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance,
|
2019-06-03 20:23:15 +00:00
|
|
|
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
|
2020-01-29 12:01:37 +00:00
|
|
|
index 930e043a0fdf40ef0e48a19597da567c8603878c..b6ba4dfad79d6031efd725de795bf901bab1a06c 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
|
2020-01-17 18:41:52 +00:00
|
|
|
@@ -50,6 +50,21 @@
|
2019-08-15 20:50:58 +00:00
|
|
|
|
|
|
|
namespace content {
|
2018-12-05 08:03:39 +00:00
|
|
|
|
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,
|
2019-08-08 18:48:33 +00:00
|
|
|
+ bool has_navigation_started,
|
2018-12-05 08:03:39 +00:00
|
|
|
+ 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
|
2020-01-29 21:45:08 +00:00
|
|
|
index 1fcc4c057ac5686f47eba791d1f0cf2c8c639574..c5eb6fbfc4b6aab5e830c725899f270aff3b4b46 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
|
2020-01-29 21:45:08 +00:00
|
|
|
@@ -233,8 +233,45 @@ class CONTENT_EXPORT ContentBrowserClient {
|
2020-01-17 18:41:52 +00:00
|
|
|
using IsClipboardPasteAllowedCallback =
|
|
|
|
base::OnceCallback<void(ClipboardPasteAllowed)>;
|
|
|
|
|
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,
|
|
|
|
+
|
2019-08-08 18:48:33 +00:00
|
|
|
+ // Use a new, unrelated site instance.
|
|
|
|
+ FORCE_NEW,
|
|
|
|
+
|
2018-12-05 08:03:39 +00:00
|
|
|
+ // 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,
|
2019-08-08 18:48:33 +00:00
|
|
|
+ bool has_navigation_started,
|
2019-06-04 03:44:12 +00:00
|
|
|
+ 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
|
2020-01-17 18:41:52 +00:00
|
|
|
index e3095f34c057ccf25b46beb809fbb88a440cc230..9d4472415d87455468cff86217e7489d39383e4e 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
|