Commit 6d24bd2f authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[bfcache] Add ability to enable SW support from chrome://flags

Add chrome://flags entry to allow pages controlled by a Service
Worker to be put into back-forward.

This support is highly experimental, so please use with care.

In order to make this possible, BackForwardCacheWithServiceWorker
feature is replaced with a parameter on BackForwardCache parameter.

R=arthursonzogni@chromium.org

Change-Id: I741aefed9a54f87a4c6ece2003be0e8664ddd470
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807328
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697335}
parent c3077cdb
...@@ -1332,6 +1332,17 @@ const FeatureEntry::FeatureVariation kQuietNotificationPromptsVariations[] = { ...@@ -1332,6 +1332,17 @@ const FeatureEntry::FeatureVariation kQuietNotificationPromptsVariations[] = {
}; };
#endif // !OS_ANDROID #endif // !OS_ANDROID
// TODO(crbug.com/991082): Remove after proper service worker support for
// back-forward cache is implemented.
const FeatureEntry::FeatureParam kBackForwardCache_ServiceWorkerSupport[] = {
{"service_worker_supported", "true"},
};
const FeatureEntry::FeatureVariation kBackForwardCacheVariations[] = {
{" even for ServiceWorker-controlled pages",
kBackForwardCache_ServiceWorkerSupport, 1, nullptr},
};
// RECORDING USER METRICS FOR FLAGS: // RECORDING USER METRICS FOR FLAGS:
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// The first line of the entry is the internal name. // The first line of the entry is the internal name.
...@@ -4537,7 +4548,9 @@ const FeatureEntry kFeatureEntries[] = { ...@@ -4537,7 +4548,9 @@ const FeatureEntry kFeatureEntries[] = {
{"back-forward-cache", flag_descriptions::kBackForwardCacheName, {"back-forward-cache", flag_descriptions::kBackForwardCacheName,
flag_descriptions::kBackForwardCacheDescription, kOsAll, flag_descriptions::kBackForwardCacheDescription, kOsAll,
FEATURE_VALUE_TYPE(features::kBackForwardCache)}, FEATURE_WITH_PARAMS_VALUE_TYPE(features::kBackForwardCache,
kBackForwardCacheVariations,
"BackForwardCache")},
// NOTE: Adding a new flag requires adding a corresponding entry to enum // NOTE: Adding a new flag requires adding a corresponding entry to enum
// "LoginCustomFlags" in tools/metrics/histograms/enums.xml. See "Flag // "LoginCustomFlags" in tools/metrics/histograms/enums.xml. See "Flag
......
...@@ -51,14 +51,13 @@ class BackForwardCacheBrowserTest : public ContentBrowserTest { ...@@ -51,14 +51,13 @@ class BackForwardCacheBrowserTest : public ContentBrowserTest {
switches::kUseFakeUIForMediaStream); switches::kUseFakeUIForMediaStream);
base::CommandLine::ForCurrentProcess()->AppendSwitch( base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kIgnoreCertificateErrors); switches::kIgnoreCertificateErrors);
feature_list_.InitWithFeatures(FeaturesToEnable(), {}); feature_list_.InitAndEnableFeatureWithParameters(
features::kBackForwardCache, GetFeatureParams());
ContentBrowserTest::SetUpCommandLine(command_line); ContentBrowserTest::SetUpCommandLine(command_line);
} }
virtual std::vector<base::Feature> FeaturesToEnable() { virtual base::FieldTrialParams GetFeatureParams() { return {}; }
return std::vector<base::Feature>({features::kBackForwardCache});
}
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1"); host_resolver()->AddRule("*", "127.0.0.1");
...@@ -1828,11 +1827,8 @@ class BackForwardCacheBrowserTestWithServiceWorkerEnabled ...@@ -1828,11 +1827,8 @@ class BackForwardCacheBrowserTestWithServiceWorkerEnabled
~BackForwardCacheBrowserTestWithServiceWorkerEnabled() override {} ~BackForwardCacheBrowserTestWithServiceWorkerEnabled() override {}
protected: protected:
std::vector<base::Feature> FeaturesToEnable() override { base::FieldTrialParams GetFeatureParams() override {
std::vector<base::Feature> result = return {{"service_worker_supported", "true"}};
BackForwardCacheBrowserTest::FeaturesToEnable();
result.push_back(kBackForwardCacheWithServiceWorker);
return result;
} }
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "content/browser/frame_host/render_frame_host_impl.h" #include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/common/page_messages.h" #include "content/common/page_messages.h"
#include "content/public/common/content_features.h"
#include "content/public/common/navigation_policy.h" #include "content/public/common/navigation_policy.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "third_party/blink/public/common/scheduler/web_scheduler_tracked_feature.h" #include "third_party/blink/public/common/scheduler/web_scheduler_tracked_feature.h"
...@@ -91,6 +92,12 @@ bool CanStoreRenderFrameHost(RenderFrameHostImpl* rfh, ...@@ -91,6 +92,12 @@ bool CanStoreRenderFrameHost(RenderFrameHostImpl* rfh,
return true; return true;
} }
bool IsServiceWorkerSupported() {
static constexpr base::FeatureParam<bool> service_worker_supported(
&features::kBackForwardCache, "service_worker_supported", false);
return service_worker_supported.Get();
}
uint64_t GetDisallowedFeatures() { uint64_t GetDisallowedFeatures() {
// TODO(lowell): Finalize disallowed feature list, and test for each // TODO(lowell): Finalize disallowed feature list, and test for each
// disallowed feature. // disallowed feature.
...@@ -120,7 +127,7 @@ uint64_t GetDisallowedFeatures() { ...@@ -120,7 +127,7 @@ uint64_t GetDisallowedFeatures() {
uint64_t result = kAlwaysDisallowedFeatures; uint64_t result = kAlwaysDisallowedFeatures;
if (!base::FeatureList::IsEnabled(kBackForwardCacheWithServiceWorker)) { if (!IsServiceWorkerSupported()) {
result |= result |=
ToFeatureBit(WebSchedulerTrackedFeature::kServiceWorkerControlledPage); ToFeatureBit(WebSchedulerTrackedFeature::kServiceWorkerControlledPage);
} }
...@@ -129,9 +136,6 @@ uint64_t GetDisallowedFeatures() { ...@@ -129,9 +136,6 @@ uint64_t GetDisallowedFeatures() {
} // namespace } // namespace
const base::Feature kBackForwardCacheWithServiceWorker = {
"BackForwardCacheWithServiceWorker", base::FEATURE_DISABLED_BY_DEFAULT};
BackForwardCache::BackForwardCache() : weak_factory_(this) {} BackForwardCache::BackForwardCache() : weak_factory_(this) {}
BackForwardCache::~BackForwardCache() = default; BackForwardCache::~BackForwardCache() = default;
......
...@@ -147,12 +147,6 @@ class CONTENT_EXPORT BackForwardCache { ...@@ -147,12 +147,6 @@ class CONTENT_EXPORT BackForwardCache {
DISALLOW_COPY_AND_ASSIGN(BackForwardCache); DISALLOW_COPY_AND_ASSIGN(BackForwardCache);
}; };
// TODO(crbug.com/991082): We need to implement frozen frame enumeration
// before we can properly support pages with ServiceWorker in back-forward
// cache. This flag allows to bypass this restriction for local testing.
// Remove after ServiceWorker support is implemented.
CONTENT_EXPORT extern const base::Feature kBackForwardCacheWithServiceWorker;
} // namespace content } // namespace content
#endif // CONTENT_BROWSER_FRAME_HOST_BACK_FORWARD_CACHE_H_ #endif // CONTENT_BROWSER_FRAME_HOST_BACK_FORWARD_CACHE_H_
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