From: Wengling Chen 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 | 3 ++- 6 files changed, 26 insertions(+), 2 deletions(-) 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 @@ -4981,7 +4981,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 @@ -1261,6 +1261,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 kExperimentalAccessibilityLanguageDetectionName[] = "Experimental accessibility language detection"; const char kExperimentalAccessibilityLanguageDetectionDescription[] = 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 @@ -662,6 +662,9 @@ extern const char kDeprecateAltClickDescription[]; extern const char kDeprecateAltBasedSixPackName[]; extern const char kDeprecateAltBasedSixPackDescription[]; +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 @@ -20,6 +20,11 @@ BASE_FEATURE(kExpectCTReporting, "ExpectCTReporting", base::FEATURE_ENABLED_BY_DEFAULT); + +// Enable save-data header separately (without enabled data reduction service). +const base::Feature kEnableSaveDataHeader{"EnableSaveDataHeader", + base::FEATURE_DISABLED_BY_DEFAULT}; + BASE_FEATURE(kNetworkErrorLogging, "NetworkErrorLogging", base::FEATURE_ENABLED_BY_DEFAULT); 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 @@ -51,7 +51,8 @@ extern const base::FeatureParam kTrustTokenOperationsRequiringOriginTrial; COMPONENT_EXPORT(NETWORK_CPP) extern const base::FeatureParam kPlatformProvidedTrustTokenIssuance; - +COMPONENT_EXPORT(NETWORK_CPP) +extern const base::Feature kEnableSaveDataHeader; COMPONENT_EXPORT(NETWORK_CPP) BASE_DECLARE_FEATURE(kWebSocketReassembleShortMessages); -- 2.25.1