Commit 36f8ca1e authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

Add SameSite level to ProactivelySwapBrowsingInstance

Adds the "SameSite" level to the ProactivelySwapBrowsingInstance feature
flag. This CL also adds helper functions (to parametrize tests, etc.).
The implementation for same-site proactive BI swap is done in another
CL - crrev.com/c/2121522.
Non-content uses of the functions: crrev.com/c/2210605,
crrev.com/c/2196105, and a few others.

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

Bug: 977562
Change-Id: I283ad31297ce6dd93bb6f02e8159488d62c5d989
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214588Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarFergal Daly <fergal@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774980}
parent fb87b8dc
......@@ -47,7 +47,8 @@ constexpr base::FeatureParam<ProactivelySwapBrowsingInstanceLevel>::Option
{ProactivelySwapBrowsingInstanceLevel::kCrossSiteSwapProcess,
"CrossSiteSwapProcess"},
{ProactivelySwapBrowsingInstanceLevel::kCrossSiteReuseProcess,
"CrossSiteReuseProcess"}};
"CrossSiteReuseProcess"},
{ProactivelySwapBrowsingInstanceLevel::kSameSite, "SameSite"}};
const base::FeatureParam<ProactivelySwapBrowsingInstanceLevel>
proactively_swap_browsing_instance_level{
&features::kProactivelySwapBrowsingInstance,
......@@ -55,6 +56,24 @@ const base::FeatureParam<ProactivelySwapBrowsingInstanceLevel>
ProactivelySwapBrowsingInstanceLevel::kDisabled,
&proactively_swap_browsing_instance_levels};
std::string GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel level) {
return proactively_swap_browsing_instance_level.GetName(level);
}
std::array<std::string,
static_cast<size_t>(ProactivelySwapBrowsingInstanceLevel::kMaxValue)>
ProactivelySwapBrowsingInstanceFeatureEnabledLevelValues() {
return {
GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel::kCrossSiteSwapProcess),
GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel::kCrossSiteReuseProcess),
GetProactivelySwapBrowsingInstanceLevelName(
ProactivelySwapBrowsingInstanceLevel::kSameSite),
};
}
ProactivelySwapBrowsingInstanceLevel GetProactivelySwapBrowsingInstanceLevel() {
if (base::FeatureList::IsEnabled(features::kProactivelySwapBrowsingInstance))
return proactively_swap_browsing_instance_level.Get();
......@@ -70,6 +89,12 @@ bool IsProactivelySwapBrowsingInstanceWithProcessReuseEnabled() {
return GetProactivelySwapBrowsingInstanceLevel() >=
ProactivelySwapBrowsingInstanceLevel::kCrossSiteReuseProcess;
}
bool IsProactivelySwapBrowsingInstanceOnSameSiteNavigationEnabled() {
return GetProactivelySwapBrowsingInstanceLevel() >=
ProactivelySwapBrowsingInstanceLevel::kSameSite;
}
const char kRenderDocumentLevelParameterName[] = "level";
constexpr base::FeatureParam<RenderDocumentLevel>::Option
......
......@@ -24,12 +24,33 @@ enum class ProactivelySwapBrowsingInstanceLevel {
// Swap BrowsingInstance on cross-site navigations, but try to reuse the
// current renderer process if possible.
kCrossSiteReuseProcess = 2,
// TODO(rakina): Add another level for BrowsingInstance swap on same-site
// navigations with process reuse.
// Swap BrowsingInstance swap on same-site navigations, with process reuse.
kSameSite = 3,
kMaxValue = kSameSite,
};
// Levels of ProactivelySwapBrowsingInstance as strings (excluding kDisabled).
CONTENT_EXPORT std::array<
std::string,
static_cast<size_t>(ProactivelySwapBrowsingInstanceLevel::kMaxValue)>
ProactivelySwapBrowsingInstanceFeatureEnabledLevelValues();
// Whether ProactivelySwapBrowsingInstance is enabled or not. Will return true
// if the value is set to either of {kCrossSiteSwapProcess,
// kCrossSiteReuseProcess, kSameSite}.
CONTENT_EXPORT bool IsProactivelySwapBrowsingInstanceEnabled();
// Whether ProactivelySwapBrowsingInstance with process reuse is enabled or not.
// Will return true if the value is set to either of {kCrossSiteReuseProcess,
// kSameSite}.
CONTENT_EXPORT bool IsProactivelySwapBrowsingInstanceWithProcessReuseEnabled();
// Whether ProactivelySwapBrowsingInstance for same-site navigation is enabled
// or not. Will return true if the value is set to kSameSite.
CONTENT_EXPORT bool
IsProactivelySwapBrowsingInstanceOnSameSiteNavigationEnabled();
CONTENT_EXPORT extern const char
kProactivelySwapBrowsingInstanceLevelParameterName[];
......
......@@ -24,6 +24,7 @@
#include "build/build_config.h"
#include "content/browser/frame_host/render_frame_host_delegate.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/common/content_navigation_policy.h"
#include "content/public/browser/browser_child_process_host_iterator.h"
#include "content/public/browser/browser_plugin_guest_delegate.h"
#include "content/public/browser/browser_task_traits.h"
......@@ -209,6 +210,12 @@ void IsolateAllSitesForTesting(base::CommandLine* command_line) {
command_line->AppendSwitch(switches::kSitePerProcess);
}
bool CanSameSiteMainFrameNavigationsChangeRenderFrameHosts() {
// TODO(crbug.com/936696): Also return true when RenderDocument for main frame
// is enabled.
return IsProactivelySwapBrowsingInstanceOnSameSiteNavigationEnabled();
}
GURL GetWebUIURL(const std::string& host) {
return GURL(GetWebUIURLString(host));
}
......
......@@ -100,6 +100,11 @@ bool AreDefaultSiteInstancesEnabled();
// the test; the flag will be read on the first real navigation.
void IsolateAllSitesForTesting(base::CommandLine* command_line);
// Whether same-site navigations might result in a change of RenderFrameHosts -
// this will happen when ProactivelySwapBrowsingInstance or RenderDocument
// is enabled on same-site main frame navigations.
bool CanSameSiteMainFrameNavigationsChangeRenderFrameHosts();
// Returns a GURL constructed from the WebUI scheme and the given host.
GURL GetWebUIURL(const std::string& host);
......
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