From 0c418988d589387d1da087e127e12e56d5fbcb53 Mon Sep 17 00:00:00 2001 From: Deep Date: Wed, 27 Jul 2022 04:33:11 -0400 Subject: [PATCH 01/12] Set fp BLOCK_THIRD_PARTY to DEFAULT --- .../browser/shields/BraveShieldsHandler.java | 14 +++++++++++--- .../res/layout/brave_shields_option_layout.xml | 3 +-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java index 0506ab93527..e0d3e551ee0 100644 --- a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java +++ b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java @@ -670,8 +670,11 @@ public class BraveShieldsHandler implements BraveRewardsHelper.LargeIconReadyCal BraveShieldsContentSettings.getShieldsValue(mProfile, mHost, layout); if (settingOption.equals(BraveShieldsContentSettings.BLOCK_RESOURCE)) { mBlockShieldsOption1.setChecked(true); - } else if (settingOption.equals( - BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE)) { + } else if (settingOption.equals(layout + == BraveShieldsContentSettings + .RESOURCE_IDENTIFIER_FINGERPRINTING + ? BraveShieldsContentSettings.DEFAULT + : BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE)) { mBlockShieldsOption2.setChecked(true); } else if (settingOption.equals(BraveShieldsContentSettings.ALLOW_RESOURCE)) { mBlockShieldsOption3.setChecked(true); @@ -694,7 +697,12 @@ public class BraveShieldsHandler implements BraveRewardsHelper.LargeIconReadyCal } else if (checkedId == R.id.option2) { BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, layout, - BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE, + layout + == BraveShieldsContentSettings + .RESOURCE_IDENTIFIER_FINGERPRINTING + ? BraveShieldsContentSettings.DEFAULT + : BraveShieldsContentSettings + .BLOCK_THIRDPARTY_RESOURCE, false); } else if (checkedId == R.id.option3) { BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, diff --git a/android/java/res/layout/brave_shields_option_layout.xml b/android/java/res/layout/brave_shields_option_layout.xml index 41282a8a4ea..688f729a159 100644 --- a/android/java/res/layout/brave_shields_option_layout.xml +++ b/android/java/res/layout/brave_shields_option_layout.xml @@ -86,8 +86,7 @@ android:layout_height="wrap_content" android:textSize="16sp" android:padding="8dp" - android:textColor="@color/shield_text_color" - android:checked="true"/> + android:textColor="@color/shield_text_color"/> Date: Thu, 28 Jul 2022 15:54:02 -0400 Subject: [PATCH 02/12] Reafctor set FP controlTYpe --- .../core/browser/content_settings_registry.cc | 2 +- .../browser/brave_shields_util.cc | 25 +++++-------------- .../common/brave_shield_utils.cc | 9 ------- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc index e78d76b8868..6972a8bd3ef 100644 --- a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc +++ b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc @@ -82,7 +82,7 @@ void ContentSettingsRegistry::BraveInit() { brave_shields::kFingerprintingV2, CONTENT_SETTING_DEFAULT, WebsiteSettingsInfo::SYNCABLE, AllowlistedSchemes(), ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK), - WebsiteSettingsInfo::COOKIES_SCOPE, + WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE, WebsiteSettingsRegistry::DESKTOP | WebsiteSettingsRegistry::PLATFORM_ANDROID, ContentSettingsInfo::INHERIT_IN_INCOGNITO, diff --git a/components/brave_shields/browser/brave_shields_util.cc b/components/brave_shields/browser/brave_shields_util.cc index 923574c215d..57cbc65b723 100644 --- a/components/brave_shields/browser/brave_shields_util.cc +++ b/components/brave_shields/browser/brave_shields_util.cc @@ -523,34 +523,22 @@ void SetFingerprintingControlType(HostContentSettingsMap* map, return; ControlType prev_setting = GetFingerprintingControlType(map, url); - content_settings::SettingInfo setting_info; - base::Value web_setting = map->GetWebsiteSetting( - url, GURL("https://balanced/*"), - ContentSettingsType::BRAVE_FINGERPRINTING_V2, &setting_info); - bool was_default = - web_setting.is_none() || setting_info.primary_pattern.MatchesAllHosts(); // Clear previous value to have only one rule for one pattern. - map->SetContentSettingCustomScope( - primary_pattern, ContentSettingsPattern::FromString("https://balanced/*"), - ContentSettingsType::BRAVE_FINGERPRINTING_V2, CONTENT_SETTING_DEFAULT); map->SetContentSettingCustomScope( primary_pattern, ContentSettingsPattern::Wildcard(), ContentSettingsType::BRAVE_FINGERPRINTING_V2, CONTENT_SETTING_DEFAULT); - auto content_setting = CONTENT_SETTING_BLOCK; - auto secondary_pattern = - ContentSettingsPattern::FromString("https://balanced/*"); - - if (type != ControlType::DEFAULT) { + ContentSetting content_setting; + if (type == ControlType::DEFAULT || type == ControlType::BLOCK_THIRD_PARTY) { + content_setting = CONTENT_SETTING_DEFAULT; + } else { content_setting = GetDefaultBlockFromControlType(type); - secondary_pattern = ContentSettingsPattern::Wildcard(); } map->SetContentSettingCustomScope( - primary_pattern, secondary_pattern, + primary_pattern, ContentSettingsPattern::Wildcard(), ContentSettingsType::BRAVE_FINGERPRINTING_V2, content_setting); - if (!map->IsOffTheRecord()) { // Only report to P3A if not a guest/incognito profile RecordShieldsSettingChanged(local_state); @@ -563,8 +551,7 @@ void SetFingerprintingControlType(HostContentSettingsMap* map, // If domain specific setting changed, recalculate counts ControlType global_setting = GetFingerprintingControlType(map, GURL()); RecordShieldsDomainSettingCountsWithChange( - profile_state, true, global_setting, - was_default ? nullptr : &prev_setting, type); + profile_state, true, global_setting, &prev_setting, type); } } } diff --git a/components/brave_shields/common/brave_shield_utils.cc b/components/brave_shields/common/brave_shield_utils.cc index 7d5cec7c1d8..d1422638081 100644 --- a/components/brave_shields/common/brave_shield_utils.cc +++ b/components/brave_shields/common/brave_shield_utils.cc @@ -23,20 +23,11 @@ ContentSetting GetBraveFPContentSettingFromRules( for (const auto& rule : fp_rules) { if (rule.primary_pattern != ContentSettingsPattern::Wildcard() && rule.primary_pattern.Matches(primary_url)) { - if (rule.secondary_pattern == - ContentSettingsPattern::FromString("https://balanced")) { - return CONTENT_SETTING_DEFAULT; - } if (rule.secondary_pattern == ContentSettingsPattern::Wildcard()) return rule.GetContentSetting(); } if (rule.primary_pattern == ContentSettingsPattern::Wildcard()) { - if (rule.secondary_pattern == - ContentSettingsPattern::FromString("https://balanced")) { - DCHECK(!global_fp_rule); - global_fp_balanced_rule = rule; - } if (rule.secondary_pattern == ContentSettingsPattern::Wildcard()) { DCHECK(!global_fp_balanced_rule); global_fp_rule = rule; From 55f3b77a7f241e403c6e06ca27296ea909c1222f Mon Sep 17 00:00:00 2001 From: Deep Date: Fri, 29 Jul 2022 13:24:43 -0400 Subject: [PATCH 03/12] Remove clearing previous pattern --- components/brave_shields/browser/brave_shields_util.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/brave_shields/browser/brave_shields_util.cc b/components/brave_shields/browser/brave_shields_util.cc index 57cbc65b723..80acaeaa635 100644 --- a/components/brave_shields/browser/brave_shields_util.cc +++ b/components/brave_shields/browser/brave_shields_util.cc @@ -524,11 +524,6 @@ void SetFingerprintingControlType(HostContentSettingsMap* map, ControlType prev_setting = GetFingerprintingControlType(map, url); - // Clear previous value to have only one rule for one pattern. - map->SetContentSettingCustomScope( - primary_pattern, ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_FINGERPRINTING_V2, CONTENT_SETTING_DEFAULT); - ContentSetting content_setting; if (type == ControlType::DEFAULT || type == ControlType::BLOCK_THIRD_PARTY) { content_setting = CONTENT_SETTING_DEFAULT; From d7db72f5e25e6a8a78f2b677175938e147ce8324 Mon Sep 17 00:00:00 2001 From: Deep Date: Fri, 29 Jul 2022 17:29:50 -0400 Subject: [PATCH 04/12] Update GetBraveFPContentSettingFromRules to remove balanced --- .../brave_shields/common/brave_shield_utils.cc | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/components/brave_shields/common/brave_shield_utils.cc b/components/brave_shields/common/brave_shield_utils.cc index d1422638081..051d92277ea 100644 --- a/components/brave_shields/common/brave_shield_utils.cc +++ b/components/brave_shields/common/brave_shield_utils.cc @@ -18,26 +18,17 @@ ContentSetting GetBraveFPContentSettingFromRules( const ContentSettingsForOneType& fp_rules, const GURL& primary_url) { absl::optional global_fp_rule; - absl::optional global_fp_balanced_rule; for (const auto& rule : fp_rules) { - if (rule.primary_pattern != ContentSettingsPattern::Wildcard() && - rule.primary_pattern.Matches(primary_url)) { - if (rule.secondary_pattern == ContentSettingsPattern::Wildcard()) - return rule.GetContentSetting(); - } - if (rule.primary_pattern == ContentSettingsPattern::Wildcard()) { if (rule.secondary_pattern == ContentSettingsPattern::Wildcard()) { - DCHECK(!global_fp_balanced_rule); global_fp_rule = rule; } + } else if (rule.primary_pattern.Matches(primary_url)) { + return rule.GetContentSetting(); } } - if (global_fp_balanced_rule) - return CONTENT_SETTING_DEFAULT; - if (global_fp_rule) return global_fp_rule->GetContentSetting(); From 5b7d0694b998b238a620c1a4cc97ce3f3fdf36e1 Mon Sep 17 00:00:00 2001 From: Deep Date: Wed, 3 Aug 2022 15:40:17 -0400 Subject: [PATCH 05/12] Add migration for FP settings --- components/constants/pref_names.cc | 2 ++ components/constants/pref_names.h | 1 + .../brave_content_settings_pref_provider.cc | 31 +++++++++++++++++++ .../brave_content_settings_pref_provider.h | 1 + 4 files changed, 35 insertions(+) diff --git a/components/constants/pref_names.cc b/components/constants/pref_names.cc index 9c198b7e46c..4a2055e22fc 100644 --- a/components/constants/pref_names.cc +++ b/components/constants/pref_names.cc @@ -90,6 +90,8 @@ const char kBackgroundVideoPlaybackEnabled[] = "brave.background_video_playback"; const char kSafetynetCheckFailed[] = "safetynetcheck.failed"; const char kSafetynetStatus[] = "safetynet.status"; +const char kBraveShieldsFPSettingsMigration[] = + "brave.shields_fp_settings_migration"; #endif #if !BUILDFLAG(IS_ANDROID) diff --git a/components/constants/pref_names.h b/components/constants/pref_names.h index 3d188db6dcb..ee8871eb939 100644 --- a/components/constants/pref_names.h +++ b/components/constants/pref_names.h @@ -77,6 +77,7 @@ extern const char kPlayYTVideoInBrowserEnabled[]; extern const char kBackgroundVideoPlaybackEnabled[]; extern const char kSafetynetCheckFailed[]; extern const char kSafetynetStatus[]; +extern const char kBraveShieldsFPSettingsMigration[]; #endif #if !BUILDFLAG(IS_ANDROID) diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc index d77634db27c..db736bd3978 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc @@ -206,6 +206,10 @@ void BravePrefProvider::MigrateShieldsSettings(bool incognito) { MigrateShieldsSettingsV2ToV3(); MigrateShieldsSettingsV3ToV4(version); + +#if BUILDFLAG(IS_ANDROID) + MigrateFPShieldsSettingsAndroid(); +#endif } void BravePrefProvider::EnsureNoWildcardEntries( @@ -455,6 +459,33 @@ void BravePrefProvider::MigrateShieldsSettingsV1ToV2ForOneType( } } +void BravePrefProvider::MigrateFPShieldsSettingsAndroid() { + if (prefs_->GetBoolean(kBraveShieldsFPSettingsMigration)) + return; + auto rule_iterator = PrefProvider::GetRuleIterator( + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + /*off_the_record*/ false); + while (rule_iterator && rule_iterator->HasNext()) { + auto rule = rule_iterator->Next(); + + if (rule.secondary_pattern == ContentSettingsPattern::Wildcard() && + rule.value == CONTENT_SETTING_BLOCK) { + SetWebsiteSettingInternal(rule.primary_pattern, rule.secondary_pattern, + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + ContentSettingToValue(CONTENT_SETTING_DEFAULT), + {rule.expiration, rule.session_model}); + } else if (rule.secondary_pattern == + ContentSettingsPattern::FromString("https://balanced/*")) { + SetWebsiteSettingInternal(rule.primary_pattern, rule.secondary_pattern, + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + ContentSettingToValue(CONTENT_SETTING_DEFAULT), + {}); + } + } + rule_iterator.reset(); + prefs_->SetBoolean(kBraveShieldsFPSettingsMigration, true); +} + bool BravePrefProvider::SetWebsiteSetting( const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& secondary_pattern, diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.h b/components/content_settings/core/browser/brave_content_settings_pref_provider.h index 783633f6489..1a91e34cf5a 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.h +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.h @@ -73,6 +73,7 @@ class BravePrefProvider : public PrefProvider, void MigrateShieldsSettingsV1ToV2ForOneType(ContentSettingsType content_type); void MigrateShieldsSettingsV2ToV3(); void MigrateShieldsSettingsV3ToV4(int start_version); + void MigrateFPShieldsSettingsAndroid(); void UpdateCookieRules(ContentSettingsType content_type, bool incognito); void OnCookieSettingsChanged(ContentSettingsType content_type); void NotifyChanges(const std::vector& rules, bool incognito); From 1945ca1fdac16e658cfcc5d77b73b3d7f020428b Mon Sep 17 00:00:00 2001 From: deep Date: Mon, 8 Aug 2022 18:11:29 -0400 Subject: [PATCH 06/12] Remove code to set value in iterators --- .../brave_content_settings_pref_provider.cc | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc index db736bd3978..6ab7f04db10 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc @@ -462,27 +462,36 @@ void BravePrefProvider::MigrateShieldsSettingsV1ToV2ForOneType( void BravePrefProvider::MigrateFPShieldsSettingsAndroid() { if (prefs_->GetBoolean(kBraveShieldsFPSettingsMigration)) return; + + // Find rules that can be migrated and create replacement rules for them. + std::vector rules; auto rule_iterator = PrefProvider::GetRuleIterator( ContentSettingsType::BRAVE_FINGERPRINTING_V2, /*off_the_record*/ false); while (rule_iterator && rule_iterator->HasNext()) { auto rule = rule_iterator->Next(); - - if (rule.secondary_pattern == ContentSettingsPattern::Wildcard() && - rule.value == CONTENT_SETTING_BLOCK) { - SetWebsiteSettingInternal(rule.primary_pattern, rule.secondary_pattern, - ContentSettingsType::BRAVE_FINGERPRINTING_V2, - ContentSettingToValue(CONTENT_SETTING_DEFAULT), - {rule.expiration, rule.session_model}); - } else if (rule.secondary_pattern == - ContentSettingsPattern::FromString("https://balanced/*")) { - SetWebsiteSettingInternal(rule.primary_pattern, rule.secondary_pattern, - ContentSettingsType::BRAVE_FINGERPRINTING_V2, - ContentSettingToValue(CONTENT_SETTING_DEFAULT), - {}); - } + rules.emplace_back(CloneRule(rule)); } rule_iterator.reset(); + + // Migrate. + for (const auto& fp_rule : rules) { + if (fp_rule.secondary_pattern == ContentSettingsPattern::Wildcard() && + fp_rule.value == CONTENT_SETTING_BLOCK) { + SetWebsiteSettingInternal(fp_rule.primary_pattern, + fp_rule.secondary_pattern, + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + ContentSettingToValue(CONTENT_SETTING_DEFAULT), + {fp_rule.expiration, fp_rule.session_model}); + } else if (fp_rule.secondary_pattern == + ContentSettingsPattern::FromString("https://balanced/*")) { + SetWebsiteSettingInternal( + fp_rule.primary_pattern, fp_rule.secondary_pattern, + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + ContentSettingToValue(CONTENT_SETTING_DEFAULT), {}); + } + } + prefs_->SetBoolean(kBraveShieldsFPSettingsMigration, true); } From bc79c17fe9d74fc02671fc63bd67a81b9a073a28 Mon Sep 17 00:00:00 2001 From: Deep Date: Fri, 12 Aug 2022 02:58:14 -0400 Subject: [PATCH 07/12] Update comparison for content settings --- .../chrome/browser/shields/BraveShieldsHandler.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java index e0d3e551ee0..a717d939185 100644 --- a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java +++ b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java @@ -670,9 +670,9 @@ public class BraveShieldsHandler implements BraveRewardsHelper.LargeIconReadyCal BraveShieldsContentSettings.getShieldsValue(mProfile, mHost, layout); if (settingOption.equals(BraveShieldsContentSettings.BLOCK_RESOURCE)) { mBlockShieldsOption1.setChecked(true); - } else if (settingOption.equals(layout - == BraveShieldsContentSettings - .RESOURCE_IDENTIFIER_FINGERPRINTING + } else if (settingOption.equals( + layout.equals(BraveShieldsContentSettings + .RESOURCE_IDENTIFIER_FINGERPRINTING) ? BraveShieldsContentSettings.DEFAULT : BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE)) { mBlockShieldsOption2.setChecked(true); @@ -697,9 +697,9 @@ public class BraveShieldsHandler implements BraveRewardsHelper.LargeIconReadyCal } else if (checkedId == R.id.option2) { BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, layout, - layout - == BraveShieldsContentSettings - .RESOURCE_IDENTIFIER_FINGERPRINTING + layout.equals( + BraveShieldsContentSettings + .RESOURCE_IDENTIFIER_FINGERPRINTING) ? BraveShieldsContentSettings.DEFAULT : BraveShieldsContentSettings .BLOCK_THIRDPARTY_RESOURCE, From 70a5e1aef51dfbef8eb96dd69b92d6789e2d509f Mon Sep 17 00:00:00 2001 From: Deep Date: Fri, 12 Aug 2022 03:46:15 -0400 Subject: [PATCH 08/12] Add tests for migration --- browser/brave_profile_prefs.cc | 1 + .../brave_content_settings_pref_provider.cc | 6 ++- .../brave_content_settings_pref_provider.h | 4 ++ ...content_settings_pref_provider_unittest.cc | 43 +++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index e0f72bee202..053aba57cc6 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -268,6 +268,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(kPlayYTVideoInBrowserEnabled, true); registry->RegisterBooleanPref(kBackgroundVideoPlaybackEnabled, false); registry->RegisterBooleanPref(kSafetynetCheckFailed, false); + registry->RegisterBooleanPref(kBraveShieldsFPSettingsMigration, false); // clear default popular sites registry->SetDefaultPrefValue(ntp_tiles::prefs::kPopularSitesJsonPref, base::Value(base::Value::Type::LIST)); diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc index 6ab7f04db10..4807930e76a 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc @@ -207,9 +207,13 @@ void BravePrefProvider::MigrateShieldsSettings(bool incognito) { MigrateShieldsSettingsV3ToV4(version); + bool run_fp_migration = run_fp_migration_for_testing_; #if BUILDFLAG(IS_ANDROID) - MigrateFPShieldsSettingsAndroid(); + run_fp_migration = true; #endif + if (run_fp_migration) { + MigrateFPShieldsSettingsAndroid(); + } } void BravePrefProvider::EnsureNoWildcardEntries( diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.h b/components/content_settings/core/browser/brave_content_settings_pref_provider.h index 1a91e34cf5a..211f4547483 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.h +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.h @@ -33,6 +33,8 @@ class BravePrefProvider : public PrefProvider, BravePrefProvider& operator=(const BravePrefProvider&) = delete; ~BravePrefProvider() override; + bool run_fp_migration_for_testing_ = false; + static void CopyPluginSettingsForMigration(PrefService* prefs); static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); @@ -59,6 +61,8 @@ class BravePrefProvider : public PrefProvider, FRIEND_TEST_ALL_PREFIXES(BravePrefProviderTest, TestShieldsSettingsMigrationFromUnknownSettings); FRIEND_TEST_ALL_PREFIXES(BravePrefProviderTest, EnsureNoWildcardEntries); + FRIEND_TEST_ALL_PREFIXES(BravePrefProviderTest, + MigrateFPShieldsSettingsAndroid); void MigrateShieldsSettings(bool incognito); void EnsureNoWildcardEntries(ContentSettingsType content_type); void MigrateShieldsSettingsFromResourceIds(); diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc index fee644dcd28..2a1cc5ebc01 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc @@ -216,6 +216,24 @@ class ShieldsFingerprintingSetting : public ShieldsSetting { {{GURL(), ContentSettingsType::BRAVE_FINGERPRINTING_V2}, {GURL("https://firstParty/*"), ContentSettingsType::BRAVE_FINGERPRINTING_V2}}) {} + + void SetPreMigrationSettingsAndroid( + const ContentSettingsPattern& pattern, + const ContentSettingsPattern& secondary_pattern, + ContentSetting setting) { + provider_->SetWebsiteSetting(pattern, secondary_pattern, + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + ContentSettingToValue(setting), {}); + } + + void CheckSettingsAndroid(const GURL& url, ContentSetting setting) { + for (const auto& url_source : urls_) { + EXPECT_EQ(setting, + TestUtils::GetContentSetting( + provider_, url_source.first, url, + ContentSettingsType::BRAVE_FINGERPRINTING_V2, false)); + } + } }; class ShieldsHTTPSESetting : public ShieldsSetting { @@ -441,6 +459,31 @@ TEST_F(BravePrefProviderTest, TestShieldsSettingsMigrationVersion) { provider.ShutdownOnUIThread(); } +TEST_F(BravePrefProviderTest, MigrateFPShieldsSettingsAndroid) { + BravePrefProvider provider( + testing_profile()->GetPrefs(), false /* incognito */, + true /* store_last_modified */, false /* restore_session */); + provider.run_fp_migration_for_testing_ = true; + ShieldsFingerprintingSetting fp_settings(&provider); + + GURL url("http://brave.com:8080/"); + ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); + + GURL url2("http://brave.com:3030"); + ContentSettingsPattern pattern2 = ContentSettingsPattern::FromURL(url2); + + fp_settings.SetPreMigrationSettingsAndroid( + pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTING_BLOCK); + fp_settings.SetPreMigrationSettingsAndroid( + pattern2, ContentSettingsPattern::FromString("https://balanced/*"), + CONTENT_SETTING_BLOCK); + provider.MigrateFPShieldsSettingsAndroid(); + fp_settings.CheckSettingsAndroid(url, CONTENT_SETTING_DEFAULT); + fp_settings.CheckSettingsAndroid(url2, CONTENT_SETTING_DEFAULT); + + provider.ShutdownOnUIThread(); +} + TEST_F(BravePrefProviderTest, TestShieldsSettingsMigrationFromResourceIDs) { PrefService* pref_service = testing_profile()->GetPrefs(); BravePrefProvider provider(pref_service, false /* incognito */, From dea149e95e9f8e8b284899ab993b9bfa25117499 Mon Sep 17 00:00:00 2001 From: Deep Date: Tue, 16 Aug 2022 04:02:08 -0400 Subject: [PATCH 09/12] Update migration variable --- browser/brave_profile_prefs.cc | 1 - components/constants/pref_names.cc | 2 -- components/constants/pref_names.h | 1 - .../core/browser/brave_content_settings_pref_provider.cc | 4 +++- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 053aba57cc6..e0f72bee202 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -268,7 +268,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(kPlayYTVideoInBrowserEnabled, true); registry->RegisterBooleanPref(kBackgroundVideoPlaybackEnabled, false); registry->RegisterBooleanPref(kSafetynetCheckFailed, false); - registry->RegisterBooleanPref(kBraveShieldsFPSettingsMigration, false); // clear default popular sites registry->SetDefaultPrefValue(ntp_tiles::prefs::kPopularSitesJsonPref, base::Value(base::Value::Type::LIST)); diff --git a/components/constants/pref_names.cc b/components/constants/pref_names.cc index 4a2055e22fc..9c198b7e46c 100644 --- a/components/constants/pref_names.cc +++ b/components/constants/pref_names.cc @@ -90,8 +90,6 @@ const char kBackgroundVideoPlaybackEnabled[] = "brave.background_video_playback"; const char kSafetynetCheckFailed[] = "safetynetcheck.failed"; const char kSafetynetStatus[] = "safetynet.status"; -const char kBraveShieldsFPSettingsMigration[] = - "brave.shields_fp_settings_migration"; #endif #if !BUILDFLAG(IS_ANDROID) diff --git a/components/constants/pref_names.h b/components/constants/pref_names.h index ee8871eb939..3d188db6dcb 100644 --- a/components/constants/pref_names.h +++ b/components/constants/pref_names.h @@ -77,7 +77,6 @@ extern const char kPlayYTVideoInBrowserEnabled[]; extern const char kBackgroundVideoPlaybackEnabled[]; extern const char kSafetynetCheckFailed[]; extern const char kSafetynetStatus[]; -extern const char kBraveShieldsFPSettingsMigration[]; #endif #if !BUILDFLAG(IS_ANDROID) diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc index 4807930e76a..4e5a764632b 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc @@ -45,6 +45,8 @@ namespace { constexpr char kObsoleteShieldCookies[] = "profile.content_settings.exceptions.shieldsCookies"; +constexpr char kBraveShieldsFPSettingsMigration[] = + "brave.shields_fp_settings_migration"; constexpr char kGoogleAuthPattern[] = "https://accounts.google.com/*"; constexpr char kFirebasePattern[] = "https://[*.]firebaseapp.com/*"; @@ -148,7 +150,7 @@ void BravePrefProvider::RegisterProfilePrefs( "profile.content_settings.exceptions.plugins"); } #endif - + registry->RegisterBooleanPref(kBraveShieldsFPSettingsMigration, false); registry->RegisterDictionaryPref(kObsoleteShieldCookies); } From f33016240dee5bae12877a31955ca3018d106abf Mon Sep 17 00:00:00 2001 From: bridiver Date: Wed, 31 Aug 2022 13:55:36 -0700 Subject: [PATCH 10/12] remove incorrect "aggressive" setting --- components/brave_shields/browser/brave_shields_util.cc | 4 ---- components/brave_shields/browser/brave_shields_util.h | 9 +-------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/components/brave_shields/browser/brave_shields_util.cc b/components/brave_shields/browser/brave_shields_util.cc index 80acaeaa635..03cb35aaed6 100644 --- a/components/brave_shields/browser/brave_shields_util.cc +++ b/components/brave_shields/browser/brave_shields_util.cc @@ -147,8 +147,6 @@ std::string ControlTypeToString(ControlType type) { return "allow"; case ControlType::BLOCK: return "block"; - case ControlType::AGGRESSIVE: - return "aggressive"; case ControlType::BLOCK_THIRD_PARTY: return "block_third_party"; case ControlType::DEFAULT: @@ -164,8 +162,6 @@ ControlType ControlTypeFromString(const std::string& string) { return ControlType::ALLOW; } else if (string == "block") { return ControlType::BLOCK; - } else if (string == "aggressive") { - return ControlType::AGGRESSIVE; } else if (string == "block_third_party") { return ControlType::BLOCK_THIRD_PARTY; } else if (string == "default") { diff --git a/components/brave_shields/browser/brave_shields_util.h b/components/brave_shields/browser/brave_shields_util.h index a1825191c21..8408cfac438 100644 --- a/components/brave_shields/browser/brave_shields_util.h +++ b/components/brave_shields/browser/brave_shields_util.h @@ -27,14 +27,7 @@ class PrefService; namespace brave_shields { -enum ControlType { - ALLOW = 0, - BLOCK, - BLOCK_THIRD_PARTY, - DEFAULT, - INVALID, - AGGRESSIVE -}; +enum ControlType { ALLOW = 0, BLOCK, BLOCK_THIRD_PARTY, DEFAULT, INVALID }; // List of possible blocking modes when accessing blocked websites. enum class DomainBlockingType { From 8ee874cdc1c24a510f42a3744a49ba9b150fb689 Mon Sep 17 00:00:00 2001 From: bridiver Date: Wed, 31 Aug 2022 14:06:00 -0700 Subject: [PATCH 11/12] fix migration --- .../worker_content_settings_client.cc | 4 +- .../core/browser/content_settings_registry.cc | 6 +- .../browser/brave_shields_util.cc | 9 ++- .../common/brave_shield_utils.cc | 27 +++------ .../brave_content_settings_pref_provider.cc | 20 ++++--- .../brave_content_settings_pref_provider.h | 7 +-- ...content_settings_pref_provider_unittest.cc | 57 +++++++++++-------- 7 files changed, 67 insertions(+), 63 deletions(-) diff --git a/chromium_src/chrome/renderer/worker_content_settings_client.cc b/chromium_src/chrome/renderer/worker_content_settings_client.cc index 140c94dec3f..f22398690c0 100644 --- a/chromium_src/chrome/renderer/worker_content_settings_client.cc +++ b/chromium_src/chrome/renderer/worker_content_settings_client.cc @@ -14,10 +14,8 @@ BraveFarblingLevel WorkerContentSettingsClient::GetBraveFarblingLevel() { ContentSetting setting = CONTENT_SETTING_DEFAULT; if (content_setting_rules_) { const GURL& primary_url = top_frame_origin_.GetURL(); - const GURL& secondary_url = document_origin_.GetURL(); for (const auto& rule : content_setting_rules_->brave_shields_rules) { - if (rule.primary_pattern.Matches(primary_url) && - rule.secondary_pattern.Matches(secondary_url)) { + if (rule.primary_pattern.Matches(primary_url)) { setting = rule.GetContentSetting(); break; } diff --git a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc index 6972a8bd3ef..b8fade915fa 100644 --- a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc +++ b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc @@ -8,6 +8,7 @@ #undef BRAVE_INIT #include "brave/components/brave_shields/common/brave_shield_constants.h" +#include "components/content_settings/core/common/content_settings.h" namespace content_settings { @@ -79,9 +80,10 @@ void ContentSettingsRegistry::BraveInit() { ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); Register(ContentSettingsType::BRAVE_FINGERPRINTING_V2, - brave_shields::kFingerprintingV2, CONTENT_SETTING_DEFAULT, + brave_shields::kFingerprintingV2, CONTENT_SETTING_ASK, WebsiteSettingsInfo::SYNCABLE, AllowlistedSchemes(), - ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK), + ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, + CONTENT_SETTING_ASK), WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE, WebsiteSettingsRegistry::DESKTOP | WebsiteSettingsRegistry::PLATFORM_ANDROID, diff --git a/components/brave_shields/browser/brave_shields_util.cc b/components/brave_shields/browser/brave_shields_util.cc index 03cb35aaed6..0a23226c0fe 100644 --- a/components/brave_shields/browser/brave_shields_util.cc +++ b/components/brave_shields/browser/brave_shields_util.cc @@ -522,7 +522,8 @@ void SetFingerprintingControlType(HostContentSettingsMap* map, ContentSetting content_setting; if (type == ControlType::DEFAULT || type == ControlType::BLOCK_THIRD_PARTY) { - content_setting = CONTENT_SETTING_DEFAULT; + type = ControlType::DEFAULT; + content_setting = CONTENT_SETTING_ASK; } else { content_setting = GetDefaultBlockFromControlType(type); } @@ -555,8 +556,12 @@ ControlType GetFingerprintingControlType(HostContentSettingsMap* map, ContentSetting fp_setting = GetBraveFPContentSettingFromRules(fingerprinting_rules, url); - if (fp_setting == CONTENT_SETTING_DEFAULT) + + if (fp_setting == CONTENT_SETTING_ASK || + fp_setting == CONTENT_SETTING_DEFAULT) { return ControlType::DEFAULT; + } + return fp_setting == CONTENT_SETTING_ALLOW ? ControlType::ALLOW : ControlType::BLOCK; } diff --git a/components/brave_shields/common/brave_shield_utils.cc b/components/brave_shields/common/brave_shield_utils.cc index 051d92277ea..2d1a7b8b414 100644 --- a/components/brave_shields/common/brave_shield_utils.cc +++ b/components/brave_shields/common/brave_shield_utils.cc @@ -8,6 +8,7 @@ #include #include +#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_pattern.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "url/gurl.h" @@ -17,21 +18,13 @@ namespace brave_shields { ContentSetting GetBraveFPContentSettingFromRules( const ContentSettingsForOneType& fp_rules, const GURL& primary_url) { - absl::optional global_fp_rule; - + ContentSettingPatternSource fp_rule; for (const auto& rule : fp_rules) { - if (rule.primary_pattern == ContentSettingsPattern::Wildcard()) { - if (rule.secondary_pattern == ContentSettingsPattern::Wildcard()) { - global_fp_rule = rule; - } - } else if (rule.primary_pattern.Matches(primary_url)) { + if (rule.primary_pattern.Matches(primary_url)) { return rule.GetContentSetting(); } } - if (global_fp_rule) - return global_fp_rule->GetContentSetting(); - return CONTENT_SETTING_DEFAULT; } @@ -43,16 +36,12 @@ ShieldsSettingCounts GetFPSettingCountFromRules( if (rule.primary_pattern.MatchesAllHosts()) { continue; } - if (rule.secondary_pattern.MatchesAllHosts()) { - if (rule.GetContentSetting() == CONTENT_SETTING_ALLOW) { - result.allow++; - } else { - result.aggressive++; - } + if (rule.GetContentSetting() == CONTENT_SETTING_ALLOW) { + result.allow++; + } else if (rule.GetContentSetting() == CONTENT_SETTING_BLOCK) { + result.aggressive++; } else { - if (rule.GetContentSetting() == CONTENT_SETTING_BLOCK) { - result.standard++; - } + result.standard++; } } diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc index 4e5a764632b..6ff26167e66 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc @@ -209,13 +209,7 @@ void BravePrefProvider::MigrateShieldsSettings(bool incognito) { MigrateShieldsSettingsV3ToV4(version); - bool run_fp_migration = run_fp_migration_for_testing_; -#if BUILDFLAG(IS_ANDROID) - run_fp_migration = true; -#endif - if (run_fp_migration) { - MigrateFPShieldsSettingsAndroid(); - } + MigrateFPShieldsSettings(); } void BravePrefProvider::EnsureNoWildcardEntries( @@ -465,7 +459,7 @@ void BravePrefProvider::MigrateShieldsSettingsV1ToV2ForOneType( } } -void BravePrefProvider::MigrateFPShieldsSettingsAndroid() { +void BravePrefProvider::MigrateFPShieldsSettings() { if (prefs_->GetBoolean(kBraveShieldsFPSettingsMigration)) return; @@ -484,17 +478,25 @@ void BravePrefProvider::MigrateFPShieldsSettingsAndroid() { for (const auto& fp_rule : rules) { if (fp_rule.secondary_pattern == ContentSettingsPattern::Wildcard() && fp_rule.value == CONTENT_SETTING_BLOCK) { +#if BUILDFLAG(IS_ANDROID) SetWebsiteSettingInternal(fp_rule.primary_pattern, fp_rule.secondary_pattern, ContentSettingsType::BRAVE_FINGERPRINTING_V2, - ContentSettingToValue(CONTENT_SETTING_DEFAULT), + ContentSettingToValue(CONTENT_SETTING_ASK), {fp_rule.expiration, fp_rule.session_model}); +#endif } else if (fp_rule.secondary_pattern == ContentSettingsPattern::FromString("https://balanced/*")) { + // delete the "balanced" override SetWebsiteSettingInternal( fp_rule.primary_pattern, fp_rule.secondary_pattern, ContentSettingsType::BRAVE_FINGERPRINTING_V2, ContentSettingToValue(CONTENT_SETTING_DEFAULT), {}); + // replace with ask + SetWebsiteSettingInternal(fp_rule.primary_pattern, + ContentSettingsPattern::Wildcard(), + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + ContentSettingToValue(CONTENT_SETTING_ASK), {}); } } diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.h b/components/content_settings/core/browser/brave_content_settings_pref_provider.h index 211f4547483..c454db8f650 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.h +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.h @@ -33,8 +33,6 @@ class BravePrefProvider : public PrefProvider, BravePrefProvider& operator=(const BravePrefProvider&) = delete; ~BravePrefProvider() override; - bool run_fp_migration_for_testing_ = false; - static void CopyPluginSettingsForMigration(PrefService* prefs); static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); @@ -61,8 +59,7 @@ class BravePrefProvider : public PrefProvider, FRIEND_TEST_ALL_PREFIXES(BravePrefProviderTest, TestShieldsSettingsMigrationFromUnknownSettings); FRIEND_TEST_ALL_PREFIXES(BravePrefProviderTest, EnsureNoWildcardEntries); - FRIEND_TEST_ALL_PREFIXES(BravePrefProviderTest, - MigrateFPShieldsSettingsAndroid); + FRIEND_TEST_ALL_PREFIXES(BravePrefProviderTest, MigrateFPShieldsSettings); void MigrateShieldsSettings(bool incognito); void EnsureNoWildcardEntries(ContentSettingsType content_type); void MigrateShieldsSettingsFromResourceIds(); @@ -77,7 +74,7 @@ class BravePrefProvider : public PrefProvider, void MigrateShieldsSettingsV1ToV2ForOneType(ContentSettingsType content_type); void MigrateShieldsSettingsV2ToV3(); void MigrateShieldsSettingsV3ToV4(int start_version); - void MigrateFPShieldsSettingsAndroid(); + void MigrateFPShieldsSettings(); void UpdateCookieRules(ContentSettingsType content_type, bool incognito); void OnCookieSettingsChanged(ContentSettingsType content_type); void NotifyChanges(const std::vector& rules, bool incognito); diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc index 2a1cc5ebc01..730db61941c 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider_unittest.cc @@ -149,6 +149,10 @@ class ShieldsSetting { CheckSettings(url, CONTENT_SETTING_ALLOW); } + void CheckSettingsWouldAsk(const GURL& url) const { + CheckSettings(url, CONTENT_SETTING_ASK); + } + protected: virtual void CheckSettings(const GURL& url, ContentSetting setting) const { for (const auto& url_source : urls_) { @@ -212,12 +216,16 @@ class CookieSettings : public ShieldsSetting { class ShieldsFingerprintingSetting : public ShieldsSetting { public: explicit ShieldsFingerprintingSetting(BravePrefProvider* provider) - : ShieldsSetting(provider, - {{GURL(), ContentSettingsType::BRAVE_FINGERPRINTING_V2}, - {GURL("https://firstParty/*"), - ContentSettingsType::BRAVE_FINGERPRINTING_V2}}) {} + : ShieldsSetting(provider, {}) {} - void SetPreMigrationSettingsAndroid( + void SetPreMigrationSettings(const ContentSettingsPattern& pattern, + ContentSetting setting) override { + provider_->SetWebsiteSetting(pattern, ContentSettingsPattern::Wildcard(), + ContentSettingsType::BRAVE_FINGERPRINTING_V2, + ContentSettingToValue(setting), {}); + } + + void SetPreMigrationSettingsWithSecondary( const ContentSettingsPattern& pattern, const ContentSettingsPattern& secondary_pattern, ContentSetting setting) { @@ -225,15 +233,6 @@ class ShieldsFingerprintingSetting : public ShieldsSetting { ContentSettingsType::BRAVE_FINGERPRINTING_V2, ContentSettingToValue(setting), {}); } - - void CheckSettingsAndroid(const GURL& url, ContentSetting setting) { - for (const auto& url_source : urls_) { - EXPECT_EQ(setting, - TestUtils::GetContentSetting( - provider_, url_source.first, url, - ContentSettingsType::BRAVE_FINGERPRINTING_V2, false)); - } - } }; class ShieldsHTTPSESetting : public ShieldsSetting { @@ -459,27 +458,39 @@ TEST_F(BravePrefProviderTest, TestShieldsSettingsMigrationVersion) { provider.ShutdownOnUIThread(); } -TEST_F(BravePrefProviderTest, MigrateFPShieldsSettingsAndroid) { +TEST_F(BravePrefProviderTest, MigrateFPShieldsSettings) { BravePrefProvider provider( testing_profile()->GetPrefs(), false /* incognito */, true /* store_last_modified */, false /* restore_session */); - provider.run_fp_migration_for_testing_ = true; ShieldsFingerprintingSetting fp_settings(&provider); GURL url("http://brave.com:8080/"); ContentSettingsPattern pattern = ContentSettingsPattern::FromURL(url); + fp_settings.SetPreMigrationSettings(pattern, CONTENT_SETTING_BLOCK); GURL url2("http://brave.com:3030"); ContentSettingsPattern pattern2 = ContentSettingsPattern::FromURL(url2); - - fp_settings.SetPreMigrationSettingsAndroid( - pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTING_BLOCK); - fp_settings.SetPreMigrationSettingsAndroid( + fp_settings.SetPreMigrationSettingsWithSecondary( pattern2, ContentSettingsPattern::FromString("https://balanced/*"), CONTENT_SETTING_BLOCK); - provider.MigrateFPShieldsSettingsAndroid(); - fp_settings.CheckSettingsAndroid(url, CONTENT_SETTING_DEFAULT); - fp_settings.CheckSettingsAndroid(url2, CONTENT_SETTING_DEFAULT); + + GURL url3("http://brave.com:8181/"); + ContentSettingsPattern pattern3 = ContentSettingsPattern::FromURL(url3); + fp_settings.SetPreMigrationSettings(pattern3, CONTENT_SETTING_ALLOW); + + GURL url4("http://brave.com:8282/"); + ContentSettingsPattern pattern4 = ContentSettingsPattern::FromURL(url4); + fp_settings.SetPreMigrationSettings(pattern4, CONTENT_SETTING_ASK); + + provider.MigrateFPShieldsSettings(); +#if BUILDFLAG(IS_ANDROID) + fp_settings.CheckSettingsWouldAsk(url); +#else + fp_settings.CheckSettingsWouldBlock(url); +#endif + fp_settings.CheckSettingsWouldAsk(url2); + fp_settings.CheckSettingsWouldAllow(url3); + fp_settings.CheckSettingsWouldAsk(url4); provider.ShutdownOnUIThread(); } From d889db6f23eae09f4ce617fee335f88bba381ac6 Mon Sep 17 00:00:00 2001 From: bridiver Date: Wed, 31 Aug 2022 14:16:00 -0700 Subject: [PATCH 12/12] restore was_default value for p3a --- components/brave_shields/browser/brave_shields_util.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/brave_shields/browser/brave_shields_util.cc b/components/brave_shields/browser/brave_shields_util.cc index 0a23226c0fe..cff4aa8ebba 100644 --- a/components/brave_shields/browser/brave_shields_util.cc +++ b/components/brave_shields/browser/brave_shields_util.cc @@ -519,6 +519,11 @@ void SetFingerprintingControlType(HostContentSettingsMap* map, return; ControlType prev_setting = GetFingerprintingControlType(map, url); + content_settings::SettingInfo setting_info; + base::Value web_setting = map->GetWebsiteSetting( + url, GURL(), ContentSettingsType::BRAVE_FINGERPRINTING_V2, &setting_info); + bool was_default = + web_setting.is_none() || setting_info.primary_pattern.MatchesAllHosts(); ContentSetting content_setting; if (type == ControlType::DEFAULT || type == ControlType::BLOCK_THIRD_PARTY) { @@ -543,7 +548,8 @@ void SetFingerprintingControlType(HostContentSettingsMap* map, // If domain specific setting changed, recalculate counts ControlType global_setting = GetFingerprintingControlType(map, GURL()); RecordShieldsDomainSettingCountsWithChange( - profile_state, true, global_setting, &prev_setting, type); + profile_state, true, global_setting, + was_default ? nullptr : &prev_setting, type); } } }