diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 926d3f0d996a..59f9e1c7d09e 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -306,6 +306,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { // Disable Chromium's privacy sandbox registry->SetDefaultPrefValue(prefs::kPrivacySandboxApisEnabled, base::Value(false)); + registry->SetDefaultPrefValue(prefs::kPrivacySandboxApisEnabledV2, + base::Value(false)); // Disable Chromium's privacy sandbox registry->SetDefaultPrefValue(prefs::kPrivacySandboxFlocEnabled, diff --git a/chromium_src/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc b/chromium_src/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc index b26dc794fde9..3cc4eeb8867f 100644 --- a/chromium_src/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc +++ b/chromium_src/chrome/browser/privacy_sandbox/privacy_sandbox_service_unittest.cc @@ -153,3 +153,43 @@ TEST_F(PrivacySandboxServiceTest, OnPrivacySandboxPrefChanged) { prefs::kPrivacySandboxApisEnabled, true); testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer); } + +TEST_F(PrivacySandboxServiceTest, OnPrivacySandboxPrefV2Changed) { + // When either the main Privacy Sandbox pref, or the FLoC pref, are changed + // the FLoC ID should be reset. This will be propagated to the settings + // instance, which should then notify observers. + privacy_sandbox_test_util::MockPrivacySandboxObserver + mock_privacy_sandbox_observer; + PrivacySandboxSettingsFactory::GetForProfile(profile())->AddObserver( + &mock_privacy_sandbox_observer); + EXPECT_CALL(mock_privacy_sandbox_observer, + OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true)); + + profile()->GetTestingPrefService()->SetBoolean( + prefs::kPrivacySandboxApisEnabledV2, false); + testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer); + + EXPECT_CALL(mock_privacy_sandbox_observer, + OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true)); + profile()->GetTestingPrefService()->SetBoolean( + prefs::kPrivacySandboxFlocEnabled, false); + testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer); + + // OnFlocDataAccessibleSinceUpdated() will be called twice because the attempt + // to enable the pref will be immediately followed by setting it to false. + EXPECT_CALL(mock_privacy_sandbox_observer, + OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true)) + .Times(2); + profile()->GetTestingPrefService()->SetBoolean( + prefs::kPrivacySandboxFlocEnabled, true); + testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer); + + // OnFlocDataAccessibleSinceUpdated() will be called twice because the attempt + // to enable the pref will be immediately followed by setting it to false. + EXPECT_CALL(mock_privacy_sandbox_observer, + OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true)) + .Times(2); + profile()->GetTestingPrefService()->SetBoolean( + prefs::kPrivacySandboxApisEnabledV2, true); + testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer); +} diff --git a/chromium_src/components/privacy_sandbox/privacy_sandbox_settings_unittest.cc b/chromium_src/components/privacy_sandbox/privacy_sandbox_settings_unittest.cc index 07899390b8d7..53b5e11507a8 100644 --- a/chromium_src/components/privacy_sandbox/privacy_sandbox_settings_unittest.cc +++ b/chromium_src/components/privacy_sandbox/privacy_sandbox_settings_unittest.cc @@ -479,9 +479,11 @@ TEST_F(PrivacySandboxSettingsTest, IsPrivacySandboxEnabled) { EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled()); // Check that even bypassing PrivacySandboxSettings::SetPrivacySandboxEnabled, - // and manually updating the preference, we still don't get this enabled. + // and manually updating the preferences, we still don't get this enabled. profile()->GetTestingPrefService()->SetBoolean( prefs::kPrivacySandboxApisEnabled, true); + profile()->GetTestingPrefService()->SetBoolean( + prefs::kPrivacySandboxApisEnabledV2, true); EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled()); } @@ -503,6 +505,8 @@ TEST_F(PrivacySandboxSettingsTest, IsFlocAllowed) { // and manually updating the preferences, we still don't get this enabled. profile()->GetTestingPrefService()->SetBoolean( prefs::kPrivacySandboxApisEnabled, true); + profile()->GetTestingPrefService()->SetBoolean( + prefs::kPrivacySandboxApisEnabledV2, true); profile()->GetTestingPrefService()->SetBoolean( prefs::kPrivacySandboxFlocEnabled, true); EXPECT_FALSE(privacy_sandbox_settings()->IsFlocAllowed()); diff --git a/components/privacy_sandbox/brave_privacy_sandbox_settings.cc b/components/privacy_sandbox/brave_privacy_sandbox_settings.cc index 5e4337710f97..c9c3e2b2afaf 100644 --- a/components/privacy_sandbox/brave_privacy_sandbox_settings.cc +++ b/components/privacy_sandbox/brave_privacy_sandbox_settings.cc @@ -27,6 +27,11 @@ BravePrivacySandboxSettings::BravePrivacySandboxSettings( base::BindRepeating( &BravePrivacySandboxSettings::OnPrivacySandboxPrefChanged, base::Unretained(this))); + user_prefs_registrar_.Add( + prefs::kPrivacySandboxApisEnabledV2, + base::BindRepeating( + &BravePrivacySandboxSettings::OnPrivacySandboxPrefChanged, + base::Unretained(this))); user_prefs_registrar_.Add( prefs::kPrivacySandboxFlocEnabled, base::BindRepeating( @@ -38,10 +43,13 @@ BravePrivacySandboxSettings::~BravePrivacySandboxSettings() = default; void BravePrivacySandboxSettings::OnPrivacySandboxPrefChanged() { // Make sure that Private Sandbox features remain disabled even if we manually - // access the Pref service and try to change the preference from there. + // access the Pref service and try to change the preferences from there. if (pref_service_->GetBoolean(prefs::kPrivacySandboxApisEnabled)) { pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, false); } + if (pref_service_->GetBoolean(prefs::kPrivacySandboxApisEnabledV2)) { + pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabledV2, false); + } if (pref_service_->GetBoolean(prefs::kPrivacySandboxFlocEnabled)) { pref_service_->SetBoolean(prefs::kPrivacySandboxFlocEnabled, false); }