Commit 50d126fb authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

Same-site Proactive BrowsingInstance Swap

This CL adds the capability of doing proactive BrowsingInstance swap on
same-site main-frame navigations when the "SameSite" level is set on the
"ProactivelySwapBrowsingInstance" flag. With that, some main-frame
same-site navigations will result in a new BrowsingInstance,
SiteInstance, RenderFrameHost, RenderView, etc.

This CL does not include:
- Updates for tests that fails because they didn't expect a change of
RenderFrameHosts, etc. on same-site main frame navigations. These are
handled in other CLs.
- Fix to ensure order of unload handlers on same-site cross-RFH
navigations (will be fixed on a future CL)
- Fix to ensure WebPreferences are carried over for cross-RFH same-site
navigations (will be fixed on a future CL)

For more details, see doc: https://docs.google.com/document/d/1lHdkKLUe8H6ZP6ALwj-dsus7oYcuc93HkSCHCcerItg/edit?usp=sharing

Bug: 977562
Change-Id: I455e598d1c422984cb707bb3a8b54fa926bb5911
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2121522
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779712}
parent 618ec90b
......@@ -606,12 +606,15 @@ class CONTENT_EXPORT RenderFrameHostManager
ui::PageTransition transition,
bool is_failure,
bool is_reload,
bool is_same_document,
bool cross_origin_opener_policy_mismatch,
bool was_server_redirect);
bool was_server_redirect,
bool should_replace_current_entry);
ShouldSwapBrowsingInstance ShouldProactivelySwapBrowsingInstance(
RenderFrameHostImpl* current_rfh,
const GURL& destination_url);
const GURL& destination_url,
bool is_reload,
bool should_replace_current_entry);
// Returns the SiteInstance to use for the navigation.
scoped_refptr<SiteInstance> GetSiteInstanceForNavigation(
......@@ -622,10 +625,12 @@ class CONTENT_EXPORT RenderFrameHostManager
ui::PageTransition transition,
bool is_failure,
bool is_reload,
bool is_same_document,
bool dest_is_restore,
bool dest_is_view_source_mode,
bool was_server_redirect,
bool cross_origin_opener_policy_mismatch);
bool cross_origin_opener_policy_mismatch,
bool should_replace_current_entry);
// Returns a descriptor of the appropriate SiteInstance object for the given
// |dest_url|, possibly reusing the current, source or destination
......
......@@ -24,9 +24,15 @@ enum class ShouldSwapBrowsingInstance {
kNo_AlreadyHasMatchingBrowsingInstance = 9,
kNo_RendererDebugURL = 10,
kNo_NotNeededForBackForwardCache = 11,
kYes_ProactiveSwap = 12,
kYes_CrossSiteProactiveSwap = 12,
kYes_SameSiteProactiveSwap = 13,
kNo_SameDocumentNavigation = 14,
kNo_SamePageNavigation = 15,
kNo_WillReplaceEntry = 16,
kNo_Reload = 17,
kNo_Guest = 18,
kMaxValue = kYes_ProactiveSwap
kMaxValue = kNo_Guest
};
} // namespace content
......
......@@ -326,8 +326,10 @@ RenderProcessHost* SiteInstanceImpl::GetProcess() {
void SiteInstanceImpl::ReuseCurrentProcessIfPossible(
RenderProcessHost* current_process) {
if (IsGuest() || HasProcess() || RequiresDedicatedProcess())
DCHECK(!IsGuest());
if (HasProcess())
return;
// We should not reuse the current process if the destination uses
// process-per-site. Note that this includes the case where the process for
// the site is not there yet (so we're going to create a new process).
......@@ -335,13 +337,19 @@ void SiteInstanceImpl::ReuseCurrentProcessIfPossible(
// process is used for a process-per-site site, it is ok to reuse this for the
// new page (regardless of the site).
if (HasSite() && RenderProcessHostImpl::ShouldUseProcessPerSite(
browsing_instance_->GetBrowserContext(), site_))
browsing_instance_->GetBrowserContext(), site_)) {
return;
}
// Do not reuse the process if it's not suitable for this SiteInstance. For
// example, this won't allow reusing a process if it's locked to a site that's
// different from this SiteInstance's site.
if (!current_process->MayReuseHost() ||
!RenderProcessHostImpl::IsSuitableHost(
current_process, GetIsolationContext(), site_.site_url(), lock_url(),
IsGuest()))
IsGuest())) {
return;
}
SetProcessInternal(current_process);
}
......
......@@ -94,12 +94,18 @@ bool NavigateToURL(Shell* window,
bool NavigateToURLFromRenderer(const ToRenderFrameHost& adapter,
const GURL& url) {
return NavigateToURLFromRenderer(adapter, url, url);
}
bool NavigateToURLFromRenderer(const ToRenderFrameHost& adapter,
const GURL& url,
const GURL& expected_commit_url) {
RenderFrameHost* rfh = adapter.render_frame_host();
TestFrameNavigationObserver nav_observer(rfh);
if (!ExecJs(rfh, JsReplace("location = $1", url)))
return false;
nav_observer.Wait();
return nav_observer.last_committed_url() == url &&
return nav_observer.last_committed_url() == expected_commit_url &&
nav_observer.last_navigation_succeeded();
}
......
......@@ -93,6 +93,13 @@ WARN_UNUSED_RESULT bool NavigateToURL(Shell* window,
WARN_UNUSED_RESULT bool NavigateToURLFromRenderer(
const ToRenderFrameHost& adapter,
const GURL& url);
// Similar to above but takes in an additional URL, |expected_commit_url|, to
// which the navigation should eventually commit. (See the browser-initiated
// counterpart for more details).
WARN_UNUSED_RESULT bool NavigateToURLFromRenderer(
const ToRenderFrameHost& adapter,
const GURL& url,
const GURL& expected_commit_url);
WARN_UNUSED_RESULT bool NavigateToURLFromRendererWithoutUserGesture(
const ToRenderFrameHost& adapter,
const GURL& url);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment