Commit 9151242d authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

Move ShouldProactivelySwapBrowsingInstance into RenderFrameHostManager

As part of crrev.com/c/2121522.

Bug: 977562
Change-Id: Ica0a6ecd7cbf0246f64850b59c5083007d2da574
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2224880
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773945}
parent f76048b7
......@@ -119,67 +119,6 @@ bool ShouldSwapBrowsingInstancesForDynamicIsolation(
future_isolation_context, destination_effective_url);
}
ShouldSwapBrowsingInstance ShouldProactivelySwapBrowsingInstance(
RenderFrameHostImpl* current_rfh,
const GURL& destination_effective_url) {
// Back-forward cache triggers proactive swap when the current url can be
// stored in the back-forward cache.
if (!IsProactivelySwapBrowsingInstanceEnabled() &&
!IsBackForwardCacheEnabled())
return ShouldSwapBrowsingInstance::kNo_ProactiveSwapDisabled;
// Only main frames are eligible to swap BrowsingInstances.
if (!current_rfh->frame_tree_node()->IsMainFrame())
return ShouldSwapBrowsingInstance::kNo_NotMainFrame;
// Skip cases when there are other windows that might script this one.
SiteInstanceImpl* current_instance = current_rfh->GetSiteInstance();
if (current_instance->GetRelatedActiveContentsCount() > 1u)
return ShouldSwapBrowsingInstance::kNo_HasRelatedActiveContents;
// "about:blank" and chrome-native-URL do not "use" a SiteInstance. This
// allows the SiteInstance to be reused cross-site. Starting a new
// BrowsingInstance would prevent the SiteInstance to be reused, that's why
// this case is excluded here.
if (!current_instance->HasSite())
return ShouldSwapBrowsingInstance::kNo_DoesNotHaveSite;
// Exclude non http(s) schemes. Some tests don't expect navigations to
// data-URL or to about:blank to switch to a different BrowsingInstance.
const GURL& current_url = current_rfh->GetLastCommittedURL();
if (!current_url.SchemeIsHTTPOrHTTPS())
return ShouldSwapBrowsingInstance::kNo_SourceURLSchemeIsNotHTTPOrHTTPS;
if (!destination_effective_url.SchemeIsHTTPOrHTTPS())
return ShouldSwapBrowsingInstance::kNo_DestinationURLSchemeIsNotHTTPOrHTTPS;
// Nothing prevents two pages with the same website to live in different
// BrowsingInstance. However many tests are making this assumption. The scope
// of ProactivelySwapBrowsingInstance experiment doesn't include them. The
// cost of getting a new process on same-site navigation would (probably?) be
// too high.
if (SiteInstanceImpl::IsSameSite(current_instance->GetIsolationContext(),
current_url, destination_effective_url,
true)) {
return ShouldSwapBrowsingInstance::kNo_SameSiteNavigation;
}
if (IsProactivelySwapBrowsingInstanceEnabled())
return ShouldSwapBrowsingInstance::kYes_ProactiveSwap;
// If BackForwardCache is enabled, swap BrowsingInstances only when needed
// for back-forward cache.
DCHECK(IsBackForwardCacheEnabled());
NavigationControllerImpl* controller = static_cast<NavigationControllerImpl*>(
current_rfh->frame_tree_node()->navigator().GetController());
if (controller->GetBackForwardCache().IsAllowed(
current_rfh->GetLastCommittedURL())) {
return ShouldSwapBrowsingInstance::kYes_ProactiveSwap;
} else {
return ShouldSwapBrowsingInstance::kNo_NotNeededForBackForwardCache;
}
}
// This function implements the COOP matching algorithm as detailed in [1].
// Note that COEP is also provided since the COOP enum does not have a
// "same-origin + COEP" value.
......@@ -1433,6 +1372,68 @@ RenderFrameHostManager::ShouldSwapBrowsingInstancesForNavigation(
destination_effective_url);
}
ShouldSwapBrowsingInstance
RenderFrameHostManager::ShouldProactivelySwapBrowsingInstance(
RenderFrameHostImpl* current_rfh,
const GURL& destination_effective_url) {
// Back-forward cache triggers proactive swap when the current url can be
// stored in the back-forward cache.
if (!IsProactivelySwapBrowsingInstanceEnabled() &&
!IsBackForwardCacheEnabled())
return ShouldSwapBrowsingInstance::kNo_ProactiveSwapDisabled;
// Only main frames are eligible to swap BrowsingInstances.
if (!current_rfh->frame_tree_node()->IsMainFrame())
return ShouldSwapBrowsingInstance::kNo_NotMainFrame;
// Skip cases when there are other windows that might script this one.
SiteInstanceImpl* current_instance = current_rfh->GetSiteInstance();
if (current_instance->GetRelatedActiveContentsCount() > 1u)
return ShouldSwapBrowsingInstance::kNo_HasRelatedActiveContents;
// "about:blank" and chrome-native-URL do not "use" a SiteInstance. This
// allows the SiteInstance to be reused cross-site. Starting a new
// BrowsingInstance would prevent the SiteInstance to be reused, that's why
// this case is excluded here.
if (!current_instance->HasSite())
return ShouldSwapBrowsingInstance::kNo_DoesNotHaveSite;
// Exclude non http(s) schemes. Some tests don't expect navigations to
// data-URL or to about:blank to switch to a different BrowsingInstance.
const GURL& current_url = current_rfh->GetLastCommittedURL();
if (!current_url.SchemeIsHTTPOrHTTPS())
return ShouldSwapBrowsingInstance::kNo_SourceURLSchemeIsNotHTTPOrHTTPS;
if (!destination_effective_url.SchemeIsHTTPOrHTTPS())
return ShouldSwapBrowsingInstance::kNo_DestinationURLSchemeIsNotHTTPOrHTTPS;
// Nothing prevents two pages with the same website to live in different
// BrowsingInstance. However many tests are making this assumption. The scope
// of ProactivelySwapBrowsingInstance experiment doesn't include them. The
// cost of getting a new process on same-site navigation would (probably?) be
// too high.
if (SiteInstanceImpl::IsSameSite(current_instance->GetIsolationContext(),
current_url, destination_effective_url,
true)) {
return ShouldSwapBrowsingInstance::kNo_SameSiteNavigation;
}
if (IsProactivelySwapBrowsingInstanceEnabled())
return ShouldSwapBrowsingInstance::kYes_ProactiveSwap;
// If BackForwardCache is enabled, swap BrowsingInstances only when needed
// for back-forward cache.
DCHECK(IsBackForwardCacheEnabled());
NavigationControllerImpl* controller = static_cast<NavigationControllerImpl*>(
current_rfh->frame_tree_node()->navigator().GetController());
if (controller->GetBackForwardCache().IsAllowed(
current_rfh->GetLastCommittedURL())) {
return ShouldSwapBrowsingInstance::kYes_ProactiveSwap;
} else {
return ShouldSwapBrowsingInstance::kNo_NotNeededForBackForwardCache;
}
}
scoped_refptr<SiteInstance>
RenderFrameHostManager::GetSiteInstanceForNavigation(
const GURL& dest_url,
......
......@@ -613,6 +613,10 @@ class CONTENT_EXPORT RenderFrameHostManager
bool cross_origin_opener_policy_mismatch,
bool was_server_redirect);
ShouldSwapBrowsingInstance ShouldProactivelySwapBrowsingInstance(
RenderFrameHostImpl* current_rfh,
const GURL& destination_url);
// Returns the SiteInstance to use for the navigation.
scoped_refptr<SiteInstance> GetSiteInstanceForNavigation(
const GURL& dest_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