LeOSium_webview/LeOS/patches/Add-flag-for-save-data-head...

113 lines
5.3 KiB
Diff

From: Wengling Chen <feiyu2817@gmail.com>
Date: Mon, 1 Feb 2021 19:18:55 +0200
Subject: Add flag for save-data-header
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
chrome/browser/about_flags.cc | 5 ++++-
chrome/browser/flag_descriptions.cc | 4 ++++
chrome/browser/flag_descriptions.h | 3 +++
.../browser/loader/browser_initiated_resource_request.cc | 8 ++++++++
services/network/public/cpp/features.cc | 5 +++++
services/network/public/cpp/features.h | 2 ++
6 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -5597,7 +5597,10 @@ const FeatureEntry kFeatureEntries[] = {
{"force-text-direction", flag_descriptions::kForceTextDirectionName,
flag_descriptions::kForceTextDirectionDescription, kOsAll,
MULTI_VALUE_TYPE(kForceTextDirectionChoices)},
-#if BUILDFLAG(IS_ANDROID)
+#if BUILDFLAG(IS_ANDROID) // Bromite save data header
+ {"enable-save-data-header", flag_descriptions::kEnableSaveDataHeaderName,
+ flag_descriptions::kEnableSaveDataHeaderDescription, kOsAndroid,
+ FEATURE_VALUE_TYPE(network::features::kEnableSaveDataHeader)},
{"force-update-menu-type", flag_descriptions::kUpdateMenuTypeName,
flag_descriptions::kUpdateMenuTypeDescription, kOsAndroid,
MULTI_VALUE_TYPE(kForceUpdateMenuTypeChoices)},
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -1401,6 +1401,10 @@ const char kDeprecateAltBasedSixPackDescription[] =
"Show deprecation notifications and disable functionality for Alt based "
"six pack deprecations. The Search based versions continue to work.";
+const char kEnableSaveDataHeaderName[] = "Enable save-data header";
+const char kEnableSaveDataHeaderDescription[] =
+ "Enable save-data header without enabling Data Saver.";
+
const char kDeprecateOldKeyboardShortcutsAcceleratorName[] =
"Enable deprecation notifications for Ctrl+Alt+/ to open Keyboard "
"shortcuts app";
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -726,6 +726,9 @@ extern const char kDeprecateAltBasedSixPackDescription[];
extern const char kDeprecateOldKeyboardShortcutsAcceleratorName[];
extern const char kDeprecateOldKeyboardShortcutsAcceleratorDescription[];
+extern const char kEnableSaveDataHeaderName[];
+extern const char kEnableSaveDataHeaderDescription[];
+
extern const char kMemlogName[];
extern const char kMemlogDescription[];
extern const char kMemlogModeMinimal[];
diff --git a/content/browser/loader/browser_initiated_resource_request.cc b/content/browser/loader/browser_initiated_resource_request.cc
--- a/content/browser/loader/browser_initiated_resource_request.cc
+++ b/content/browser/loader/browser_initiated_resource_request.cc
@@ -4,6 +4,9 @@
#include "content/browser/loader/browser_initiated_resource_request.h"
+#include "base/feature_list.h"
+#include "services/network/public/cpp/features.h"
+
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
@@ -37,8 +40,13 @@ void UpdateAdditionalHeadersForBrowserInitiatedRequest(
// Save-Data was previously included in hints for workers, thus we cannot
// remove it for the time being. If you're reading this, consider building
// permissions policies for workers and/or deprecating this inclusion.
+ bool setHeader = false;
if (is_for_worker_script &&
GetContentClient()->browser()->IsDataSaverEnabled(browser_context)) {
+ setHeader = true;
+ }
+ setHeader |= base::FeatureList::IsEnabled(network::features::kEnableSaveDataHeader);
+ if (setHeader) {
if (should_update_existing_headers) {
headers->RemoveHeader("Save-Data");
}
diff --git a/services/network/public/cpp/features.cc b/services/network/public/cpp/features.cc
--- a/services/network/public/cpp/features.cc
+++ b/services/network/public/cpp/features.cc
@@ -14,6 +14,11 @@
namespace network::features {
+// Enable save-data header separately (without enabled data reduction service).
+BASE_FEATURE(kEnableSaveDataHeader,
+ "EnableSaveDataHeader",
+ base::FEATURE_DISABLED_BY_DEFAULT);
+
BASE_FEATURE(kNetworkErrorLogging,
"NetworkErrorLogging", // disabled by default
base::FEATURE_DISABLED_BY_DEFAULT); // in bromite
diff --git a/services/network/public/cpp/features.h b/services/network/public/cpp/features.h
--- a/services/network/public/cpp/features.h
+++ b/services/network/public/cpp/features.h
@@ -91,6 +91,8 @@ extern uint32_t GetLoaderChunkSize();
COMPONENT_EXPORT(NETWORK_CPP)
BASE_DECLARE_FEATURE(kCorsNonWildcardRequestHeadersSupport);
+COMPONENT_EXPORT(NETWORK_CPP) BASE_DECLARE_FEATURE(kEnableSaveDataHeader);
+
COMPONENT_EXPORT(NETWORK_CPP) BASE_DECLARE_FEATURE(kNetworkServiceMemoryCache);
COMPONENT_EXPORT(NETWORK_CPP) BASE_DECLARE_FEATURE(kOmitCorsClientCert);
--
2.25.1