Commit b2f82902 authored by Minggang Wang's avatar Minggang Wang Committed by Commit Bot

[OnionSoup] Move

SetForceLegacyDefaultReferrerPolicy()/ShouldForceLegacyDefaultReferrerPolicy()
into Blink

This patch moves SetForceLegacyDefaultReferrerPolicy() and
ShouldForceLegacyDefaultReferrerPolicy() methods into Blink, so we could
call them directly from Blink.

Bug: 860403
Change-Id: I07eaf51344132dc7b2e6137e9929d3f9be9f1ccc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2355581Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Minggang Wang <minggang.wang@intel.com>
Cr-Commit-Position: refs/heads/master@{#801398}
parent 6f1e42dd
...@@ -353,6 +353,7 @@ ...@@ -353,6 +353,7 @@
#include "storage/browser/file_system/external_mount_points.h" #include "storage/browser/file_system/external_mount_points.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h" #include "third_party/blink/public/common/loader/url_loader_throttle.h"
#include "third_party/blink/public/common/switches.h" #include "third_party/blink/public/common/switches.h"
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h" #include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
...@@ -2168,7 +2169,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( ...@@ -2168,7 +2169,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
kDinosaurEasterEggSwitches, kDinosaurEasterEggSwitches,
base::size(kDinosaurEasterEggSwitches)); base::size(kDinosaurEasterEggSwitches));
if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()) if (blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy())
command_line->AppendSwitch( command_line->AppendSwitch(
blink::switches::kForceLegacyDefaultReferrerPolicy); blink::switches::kForceLegacyDefaultReferrerPolicy);
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
#include "components/policy/core/common/policy_map.h" #include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h" #include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "content/public/common/referrer.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
namespace policy { namespace policy {
...@@ -37,7 +37,7 @@ class ForceLegacyDefaultReferrerPolicy : public InProcessBrowserTest { ...@@ -37,7 +37,7 @@ class ForceLegacyDefaultReferrerPolicy : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(ForceLegacyDefaultReferrerPolicy, UpdatesDynamically) { IN_PROC_BROWSER_TEST_F(ForceLegacyDefaultReferrerPolicy, UpdatesDynamically) {
// When the policy's unset, we shouldn't be forcing the legacy default // When the policy's unset, we shouldn't be forcing the legacy default
// referrer policy. // referrer policy.
EXPECT_FALSE(content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()); EXPECT_FALSE(blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
policy::PolicyMap values; policy::PolicyMap values;
values.Set(key::kForceLegacyDefaultReferrerPolicy, POLICY_LEVEL_RECOMMENDED, values.Set(key::kForceLegacyDefaultReferrerPolicy, POLICY_LEVEL_RECOMMENDED,
...@@ -46,7 +46,7 @@ IN_PROC_BROWSER_TEST_F(ForceLegacyDefaultReferrerPolicy, UpdatesDynamically) { ...@@ -46,7 +46,7 @@ IN_PROC_BROWSER_TEST_F(ForceLegacyDefaultReferrerPolicy, UpdatesDynamically) {
policy_provider_.UpdateChromePolicy(values); policy_provider_.UpdateChromePolicy(values);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// When the policy's true, we should have flipped the global to true. // When the policy's true, we should have flipped the global to true.
EXPECT_TRUE(content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()); EXPECT_TRUE(blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
values.Set(key::kForceLegacyDefaultReferrerPolicy, POLICY_LEVEL_RECOMMENDED, values.Set(key::kForceLegacyDefaultReferrerPolicy, POLICY_LEVEL_RECOMMENDED,
POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, base::Value(false), POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, base::Value(false),
...@@ -54,7 +54,7 @@ IN_PROC_BROWSER_TEST_F(ForceLegacyDefaultReferrerPolicy, UpdatesDynamically) { ...@@ -54,7 +54,7 @@ IN_PROC_BROWSER_TEST_F(ForceLegacyDefaultReferrerPolicy, UpdatesDynamically) {
policy_provider_.UpdateChromePolicy(values); policy_provider_.UpdateChromePolicy(values);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// When the policy's false, we should have flipped the global back to false. // When the policy's false, we should have flipped the global back to false.
EXPECT_FALSE(content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()); EXPECT_FALSE(blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
} }
} // namespace policy } // namespace policy
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "components/policy/core/common/policy_map.h" #include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h" #include "components/prefs/pref_value_map.h"
#include "content/public/common/referrer.h" #include "third_party/blink/public/common/loader/referrer_utils.h"
namespace policy { namespace policy {
...@@ -24,7 +24,7 @@ void ReferrerPolicyPolicyHandler::ApplyPolicySettings(const PolicyMap& policies, ...@@ -24,7 +24,7 @@ void ReferrerPolicyPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
policies.GetValue(key::kForceLegacyDefaultReferrerPolicy); policies.GetValue(key::kForceLegacyDefaultReferrerPolicy);
if (value) { if (value) {
DCHECK(value->is_bool()); DCHECK(value->is_bool());
content::Referrer::SetForceLegacyDefaultReferrerPolicy(value->GetBool()); blink::ReferrerUtils::SetForceLegacyDefaultReferrerPolicy(value->GetBool());
} }
} }
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include "components/policy/core/common/policy_types.h" #include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h" #include "components/prefs/pref_value_map.h"
#include "content/public/common/referrer.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
namespace policy { namespace policy {
...@@ -69,13 +69,13 @@ TEST_F(ReferrerPolicyPolicyHandlerTest, ValueTrue) { ...@@ -69,13 +69,13 @@ TEST_F(ReferrerPolicyPolicyHandlerTest, ValueTrue) {
SetPolicyValue(key::kForceLegacyDefaultReferrerPolicy, base::Value(true)); SetPolicyValue(key::kForceLegacyDefaultReferrerPolicy, base::Value(true));
CheckAndApplyPolicySettings(); CheckAndApplyPolicySettings();
EXPECT_TRUE(content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()); EXPECT_TRUE(blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
} }
TEST_F(ReferrerPolicyPolicyHandlerTest, ValueFalse) { TEST_F(ReferrerPolicyPolicyHandlerTest, ValueFalse) {
SetPolicyValue(key::kForceLegacyDefaultReferrerPolicy, base::Value(false)); SetPolicyValue(key::kForceLegacyDefaultReferrerPolicy, base::Value(false));
CheckAndApplyPolicySettings(); CheckAndApplyPolicySettings();
EXPECT_FALSE(content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()); EXPECT_FALSE(blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
} }
} // namespace policy } // namespace policy
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/input/web_input_event.h" #include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h" #include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h" #include "ui/base/window_open_disposition.h"
...@@ -736,7 +737,7 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, ...@@ -736,7 +737,7 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest,
// These tests assume a default policy of no-referrer-when-downgrade. // These tests assume a default policy of no-referrer-when-downgrade.
struct ReferrerOverrideParams { struct ReferrerOverrideParams {
base::Optional<base::Feature> feature_to_enable; base::Optional<base::Feature> feature_to_enable;
// If true, calls content::Referrer::SetForceLegacyDefaultReferrerPolicy() // If true, calls blink::ReferrerUtils::SetForceLegacyDefaultReferrerPolicy()
// to pin the default policy to no-referrer-when-downgrade. // to pin the default policy to no-referrer-when-downgrade.
bool force_no_referrer_when_downgrade_default; bool force_no_referrer_when_downgrade_default;
network::mojom::ReferrerPolicy baseline_policy; network::mojom::ReferrerPolicy baseline_policy;
...@@ -832,7 +833,7 @@ class ReferrerOverrideTest ...@@ -832,7 +833,7 @@ class ReferrerOverrideTest
ReferrerOverrideTest() { ReferrerOverrideTest() {
if (GetParam().feature_to_enable) if (GetParam().feature_to_enable)
scoped_feature_list_.InitAndEnableFeature(*GetParam().feature_to_enable); scoped_feature_list_.InitAndEnableFeature(*GetParam().feature_to_enable);
content::Referrer::SetForceLegacyDefaultReferrerPolicy( blink::ReferrerUtils::SetForceLegacyDefaultReferrerPolicy(
GetParam().force_no_referrer_when_downgrade_default); GetParam().force_no_referrer_when_downgrade_default);
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "content/common/content_switches_internal.h" #include "content/common/content_switches_internal.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/referrer.h"
#include "device/fido/features.h" #include "device/fido/features.h"
#include "device/gamepad/public/cpp/gamepad_features.h" #include "device/gamepad/public/cpp/gamepad_features.h"
#include "gpu/config/gpu_switches.h" #include "gpu/config/gpu_switches.h"
...@@ -28,6 +27,7 @@ ...@@ -28,6 +27,7 @@
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_switches.h" #include "services/network/public/cpp/network_switches.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
#include "third_party/blink/public/common/switches.h" #include "third_party/blink/public/common/switches.h"
#include "third_party/blink/public/platform/web_runtime_features.h" #include "third_party/blink/public/platform/web_runtime_features.h"
#include "ui/accessibility/accessibility_features.h" #include "ui/accessibility/accessibility_features.h"
...@@ -626,7 +626,7 @@ void SetCustomizedRuntimeFeaturesFromCombinedArgs( ...@@ -626,7 +626,7 @@ void SetCustomizedRuntimeFeaturesFromCombinedArgs(
WebRuntimeFeatures::EnableReducedReferrerGranularity( WebRuntimeFeatures::EnableReducedReferrerGranularity(
base::FeatureList::IsEnabled( base::FeatureList::IsEnabled(
blink::features::kReducedReferrerGranularity) && blink::features::kReducedReferrerGranularity) &&
!content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()); !blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
blink::features::kAppCacheRequireOriginTrial)) { blink::features::kAppCacheRequireOriginTrial)) {
......
...@@ -71,17 +71,6 @@ net::ReferrerPolicy Referrer::ReferrerPolicyForUrlRequest( ...@@ -71,17 +71,6 @@ net::ReferrerPolicy Referrer::ReferrerPolicyForUrlRequest(
return network::ReferrerPolicyForUrlRequest(referrer_policy); return network::ReferrerPolicyForUrlRequest(referrer_policy);
} }
// static
void Referrer::SetForceLegacyDefaultReferrerPolicy(bool force) {
blink::ReferrerUtils::ReadModifyWriteForceLegacyPolicyFlag(force);
}
// static
bool Referrer::ShouldForceLegacyDefaultReferrerPolicy() {
return blink::ReferrerUtils::ReadModifyWriteForceLegacyPolicyFlag(
base::nullopt);
}
// static // static
network::mojom::ReferrerPolicy Referrer::ConvertToPolicy(int32_t policy) { network::mojom::ReferrerPolicy Referrer::ConvertToPolicy(int32_t policy) {
return mojo::ConvertIntToMojoEnum<network::mojom::ReferrerPolicy>(policy) return mojo::ConvertIntToMojoEnum<network::mojom::ReferrerPolicy>(policy)
......
...@@ -110,24 +110,4 @@ TEST(ReferrerTest, BlinkNetRoundTripConversion) { ...@@ -110,24 +110,4 @@ TEST(ReferrerTest, BlinkNetRoundTripConversion) {
} }
} }
TEST(DefaultReferrerPolicyTest, SetAndGetForceLegacy) {
EXPECT_FALSE(content::Referrer::ShouldForceLegacyDefaultReferrerPolicy());
content::Referrer::SetForceLegacyDefaultReferrerPolicy(true);
EXPECT_TRUE(content::Referrer::ShouldForceLegacyDefaultReferrerPolicy());
}
TEST(DefaultReferrerPolicyTest, ForceLegacyOnly) {
content::Referrer::SetForceLegacyDefaultReferrerPolicy(true);
EXPECT_EQ(blink::ReferrerUtils::GetDefaultNetReferrerPolicy(),
net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE);
}
TEST(DefaultReferrerPolicyTest, FeatureAndForceLegacy) {
base::test::ScopedFeatureList f;
f.InitAndEnableFeature(blink::features::kReducedReferrerGranularity);
content::Referrer::SetForceLegacyDefaultReferrerPolicy(true);
EXPECT_EQ(blink::ReferrerUtils::GetDefaultNetReferrerPolicy(),
net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE);
}
} // namespace content } // namespace content
...@@ -10,6 +10,28 @@ ...@@ -10,6 +10,28 @@
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/switches.h" #include "third_party/blink/public/common/switches.h"
namespace {
// Using an atomic is necessary because this code is called from both the
// browser and the renderer (so that access is not on a single sequence when in
// single-process mode), and because it is called from multiple threads within
// the renderer.
bool ReadModifyWriteForceLegacyPolicyFlag(
base::Optional<bool> maybe_new_value) {
// Default to false in the browser process (it is not expected
// that the browser will be provided this switch).
// The value is propagated to other processes through the command line.
DCHECK(base::CommandLine::InitializedForCurrentProcess());
static std::atomic<bool> value(
base::CommandLine::ForCurrentProcess()->HasSwitch(
blink::switches::kForceLegacyDefaultReferrerPolicy));
if (!maybe_new_value.has_value())
return value;
return value.exchange(*maybe_new_value);
}
} // namespace
namespace blink { namespace blink {
network::mojom::ReferrerPolicy ReferrerUtils::NetToMojoReferrerPolicy( network::mojom::ReferrerPolicy ReferrerUtils::NetToMojoReferrerPolicy(
...@@ -48,30 +70,18 @@ net::ReferrerPolicy ReferrerUtils::GetDefaultNetReferrerPolicy() { ...@@ -48,30 +70,18 @@ net::ReferrerPolicy ReferrerUtils::GetDefaultNetReferrerPolicy() {
if (!base::FeatureList::IsEnabled(features::kReducedReferrerGranularity)) if (!base::FeatureList::IsEnabled(features::kReducedReferrerGranularity))
return net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE; return net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
bool should_force_legacy_default_referrer_policy = return ShouldForceLegacyDefaultReferrerPolicy()
ReadModifyWriteForceLegacyPolicyFlag(base::nullopt);
return should_force_legacy_default_referrer_policy
? net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE ? net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE
: net::ReferrerPolicy:: : net::ReferrerPolicy::
REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN; REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN;
} }
// Using an atomic is necessary because this code is called from both the void ReferrerUtils::SetForceLegacyDefaultReferrerPolicy(bool force) {
// browser and the renderer (so that access is not on a single sequence when in ReadModifyWriteForceLegacyPolicyFlag(force);
// single-process mode), and because it is called from multiple threads within }
// the renderer.
bool ReferrerUtils::ReadModifyWriteForceLegacyPolicyFlag( bool ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy() {
base::Optional<bool> maybe_new_value) { return ReadModifyWriteForceLegacyPolicyFlag(base::nullopt);
// Default to false in the browser process (it is not expected
// that the browser will be provided this switch).
// The value is propagated to other processes through the command line.
DCHECK(base::CommandLine::InitializedForCurrentProcess());
static std::atomic<bool> value(
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceLegacyDefaultReferrerPolicy));
if (!maybe_new_value.has_value())
return value;
return value.exchange(*maybe_new_value);
} }
} // namespace blink } // namespace blink
...@@ -22,4 +22,24 @@ TEST(DefaultNetReferrerPolicyTest, FeatureOnly) { ...@@ -22,4 +22,24 @@ TEST(DefaultNetReferrerPolicyTest, FeatureOnly) {
net::ReferrerPolicy::REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN); net::ReferrerPolicy::REDUCE_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN);
} }
TEST(DefaultReferrerPolicyTest, SetAndGetForceLegacy) {
EXPECT_FALSE(blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
blink::ReferrerUtils::SetForceLegacyDefaultReferrerPolicy(true);
EXPECT_TRUE(blink::ReferrerUtils::ShouldForceLegacyDefaultReferrerPolicy());
}
TEST(DefaultReferrerPolicyTest, ForceLegacyOnly) {
blink::ReferrerUtils::SetForceLegacyDefaultReferrerPolicy(true);
EXPECT_EQ(blink::ReferrerUtils::GetDefaultNetReferrerPolicy(),
net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE);
}
TEST(DefaultReferrerPolicyTest, FeatureAndForceLegacy) {
base::test::ScopedFeatureList f;
f.InitAndEnableFeature(blink::features::kReducedReferrerGranularity);
blink::ReferrerUtils::SetForceLegacyDefaultReferrerPolicy(true);
EXPECT_EQ(blink::ReferrerUtils::GetDefaultNetReferrerPolicy(),
net::ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE);
}
} // namespace blink } // namespace blink
...@@ -19,8 +19,13 @@ class ReferrerUtils { ...@@ -19,8 +19,13 @@ class ReferrerUtils {
static BLINK_COMMON_EXPORT net::ReferrerPolicy GetDefaultNetReferrerPolicy(); static BLINK_COMMON_EXPORT net::ReferrerPolicy GetDefaultNetReferrerPolicy();
static BLINK_COMMON_EXPORT bool ReadModifyWriteForceLegacyPolicyFlag( // Configures retaining the pre-M80 default referrer
base::Optional<bool> maybe_new_value); // policy of no-referrer-when-downgrade.
// TODO(crbug.com/1016541): After M88, remove when the corresponding
// enterprise policy has been deleted.
static BLINK_COMMON_EXPORT void SetForceLegacyDefaultReferrerPolicy(
bool force);
static BLINK_COMMON_EXPORT bool ShouldForceLegacyDefaultReferrerPolicy();
}; };
} // namespace blink } // namespace blink
......
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