Skip to content

Commit

Permalink
Merge pull request #12583 from brave/shields-p3a-multiple-domains
Browse files Browse the repository at this point in the history
Added Shields domain-specific ad/fingerprint block setting questions
  • Loading branch information
DJAndries authored Apr 12, 2022
2 parents 48743b4 + 066a3dd commit 2af3710
Show file tree
Hide file tree
Showing 23 changed files with 645 additions and 140 deletions.
6 changes: 4 additions & 2 deletions browser/android/brave_shields_content_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ void JNI_BraveShieldsContentSettings_SetCosmeticFilteringControlType(
brave_shields::ControlTypeFromString(
base::android::ConvertJavaStringToUTF8(env, type)),
GURL(base::android::ConvertJavaStringToUTF8(env, url)),
g_browser_process->local_state());
g_browser_process->local_state(),
ProfileAndroid::FromProfileAndroid(j_profile)->GetPrefs());
}

base::android::ScopedJavaLocalRef<jstring>
Expand All @@ -182,7 +183,8 @@ void JNI_BraveShieldsContentSettings_SetFingerprintingControlType(JNIEnv* env,
brave_shields::ControlTypeFromString(
base::android::ConvertJavaStringToUTF8(env, type)),
GURL(base::android::ConvertJavaStringToUTF8(env, url)),
g_browser_process->local_state());
g_browser_process->local_state(),
ProfileAndroid::FromProfileAndroid(j_profile)->GetPrefs());
}

base::android::ScopedJavaLocalRef<jstring>
Expand Down
15 changes: 10 additions & 5 deletions browser/android/preferences/brave_pref_service_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void JNI_BravePrefServiceBridge_SetCosmeticFilteringControlType(JNIEnv* env,
// aggressive
brave_shields::SetCosmeticFilteringControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
ControlType::BLOCK, GURL(), g_browser_process->local_state());
ControlType::BLOCK, GURL(), g_browser_process->local_state(),
GetOriginalProfile()->GetPrefs());
brave_shields::SetAdControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
ControlType::BLOCK, GURL(), g_browser_process->local_state());
Expand All @@ -163,7 +164,8 @@ void JNI_BravePrefServiceBridge_SetCosmeticFilteringControlType(JNIEnv* env,
// standard
brave_shields::SetCosmeticFilteringControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
ControlType::DEFAULT, GURL(), g_browser_process->local_state());
ControlType::DEFAULT, GURL(), g_browser_process->local_state(),
GetOriginalProfile()->GetPrefs());
brave_shields::SetAdControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
ControlType::BLOCK, GURL(), g_browser_process->local_state());
Expand All @@ -172,7 +174,8 @@ void JNI_BravePrefServiceBridge_SetCosmeticFilteringControlType(JNIEnv* env,
// allow all
brave_shields::SetCosmeticFilteringControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
ControlType::ALLOW, GURL(), g_browser_process->local_state());
ControlType::ALLOW, GURL(), g_browser_process->local_state(),
GetOriginalProfile()->GetPrefs());
brave_shields::SetAdControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
ControlType::ALLOW, GURL(), g_browser_process->local_state());
Expand All @@ -185,7 +188,8 @@ void JNI_BravePrefServiceBridge_SetCosmeticFilteringControlType(JNIEnv* env,
ControlType::BLOCK, GURL(), g_browser_process->local_state());
brave_shields::SetCosmeticFilteringControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
ControlType::DEFAULT, GURL(), g_browser_process->local_state());
ControlType::DEFAULT, GURL(), g_browser_process->local_state(),
GetOriginalProfile()->GetPrefs());
break;
}
}
Expand Down Expand Up @@ -240,7 +244,8 @@ void JNI_BravePrefServiceBridge_SetFingerprintingControlType(
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile()),
brave_shields::ControlTypeFromString(
base::android::ConvertJavaStringToUTF8(env, type)),
GURL(), g_browser_process->local_state());
GURL(), g_browser_process->local_state(),
GetOriginalProfile()->GetPrefs());
}

base::android::ScopedJavaLocalRef<jstring>
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {

#endif // BUILDFLAG(BRAVE_P3A_ENABLED)

brave_shields::RegisterShieldsP3APrefs(registry);
brave_shields::RegisterShieldsP3ALocalPrefs(registry);
#if !BUILDFLAG(IS_ANDROID)
BraveNewTabMessageHandler::RegisterLocalStatePrefs(registry);
BraveWindowTracker::RegisterPrefs(registry);
Expand Down
3 changes: 3 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "brave/components/brave_search/browser/brave_search_default_host.h"
#include "brave/components/brave_search/common/brave_search_utils.h"
#include "brave/components/brave_shields/browser/brave_farbling_service.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/brave_shields/common/pref_names.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
#include "brave/components/brave_today/browser/brave_news_controller.h"
Expand Down Expand Up @@ -183,6 +184,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {

brave_sync::Prefs::RegisterProfilePrefs(registry);

brave_shields::RegisterShieldsP3AProfilePrefs(registry);

#if BUILDFLAG(ENABLE_BRAVE_VPN) && !BUILDFLAG(IS_ANDROID)
brave_vpn::prefs::RegisterProfilePrefs(registry);
#endif
Expand Down
6 changes: 3 additions & 3 deletions browser/brave_shields/ad_block_pref_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ AdBlockPrefServiceFactory::~AdBlockPrefServiceFactory() {}

KeyedService* AdBlockPrefServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new AdBlockPrefService(
g_brave_browser_process->ad_block_service(),
Profile::FromBrowserContext(context)->GetPrefs());
Profile* profile = Profile::FromBrowserContext(context);
return new AdBlockPrefService(g_brave_browser_process->ad_block_service(),
profile->GetPrefs());
}

content::BrowserContext* AdBlockPrefServiceFactory::GetBrowserContextToUse(
Expand Down
12 changes: 4 additions & 8 deletions browser/extensions/api/brave_shields_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ BraveShieldsSetCosmeticFilteringControlTypeFunction::Run() {

Profile* profile = Profile::FromBrowserContext(browser_context());
::brave_shields::SetCosmeticFilteringControlType(
HostContentSettingsMapFactory::GetForProfile(profile),
control_type,
url,
g_browser_process->local_state());
HostContentSettingsMapFactory::GetForProfile(profile), control_type, url,
g_browser_process->local_state(), profile->GetPrefs());

return RespondNow(NoArguments());
}
Expand Down Expand Up @@ -312,10 +310,8 @@ BraveShieldsSetFingerprintingControlTypeFunction::Run() {

Profile* profile = Profile::FromBrowserContext(browser_context());
::brave_shields::SetFingerprintingControlType(
HostContentSettingsMapFactory::GetForProfile(profile),
control_type,
url,
g_browser_process->local_state());
HostContentSettingsMapFactory::GetForProfile(profile), control_type, url,
g_browser_process->local_state(), profile->GetPrefs());

return RespondNow(NoArguments());
}
Expand Down
7 changes: 7 additions & 0 deletions browser/profiles/profile_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include "base/no_destructor.h"
#include "brave/common/brave_constants.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/ntp_background_images/common/pref_names.h"
#include "brave/components/search_engines/brave_prepopulated_engines.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/profiles/profile_manager.h"
Expand Down Expand Up @@ -223,6 +225,11 @@ void RecordInitialP3AValues(Profile* profile) {
return;
}
RecordSponsoredImagesEnabledP3A(profile);
if (profile->IsRegularProfile()) {
brave_shields::MaybeRecordInitialShieldsSettings(
profile->GetPrefs(),
HostContentSettingsMapFactory::GetForProfile(profile));
}
}

void SetDefaultSearchVersion(Profile* profile, bool is_new_profile) {
Expand Down
15 changes: 12 additions & 3 deletions browser/ui/brave_shields_data_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,21 @@ void BraveShieldsDataController::SetAdBlockMode(AdBlockMode mode) {

if (mode == AdBlockMode::AGGRESSIVE) {
control_type_cosmetic = ControlType::BLOCK; // aggressive
} else {
} else if (mode == AdBlockMode::STANDARD) {
control_type_cosmetic = ControlType::BLOCK_THIRD_PARTY; // standard
} else {
control_type_cosmetic = ControlType::ALLOW; // allow
}

brave_shields::SetAdControlType(map, control_type_ad, GetCurrentSiteURL(),
g_browser_process->local_state());

PrefService* profile_prefs =
Profile::FromBrowserContext(web_contents()->GetBrowserContext())
->GetPrefs();
brave_shields::SetCosmeticFilteringControlType(
map, control_type_cosmetic, GetCurrentSiteURL(),
g_browser_process->local_state());
g_browser_process->local_state(), profile_prefs);

ReloadWebContents();
}
Expand All @@ -267,8 +272,12 @@ void BraveShieldsDataController::SetFingerprintMode(FingerprintMode mode) {
control_type = ControlType::DEFAULT; // STANDARD
}

PrefService* profile_prefs =
Profile::FromBrowserContext(web_contents()->GetBrowserContext())
->GetPrefs();
brave_shields::SetFingerprintingControlType(
map, control_type, GetCurrentSiteURL(), g_browser_process->local_state());
map, control_type, GetCurrentSiteURL(), g_browser_process->local_state(),
profile_prefs);

ReloadWebContents();
}
Expand Down
10 changes: 5 additions & 5 deletions browser/ui/brave_shields_data_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ TEST_F(BraveShieldsDataControllerTest, SetAdBlockMode_ForOrigin_1) {
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_ADS),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING),
CONTENT_SETTING_BLOCK);
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING,
GURL("https://firstParty/")),
CONTENT_SETTING_ALLOW);
Expand All @@ -145,7 +145,7 @@ TEST_F(BraveShieldsDataControllerTest, SetAdBlockMode_ForOrigin_1) {
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_ADS),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING),
CONTENT_SETTING_BLOCK);
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING,
GURL("https://firstParty/")),
CONTENT_SETTING_ALLOW);
Expand All @@ -165,7 +165,7 @@ TEST_F(BraveShieldsDataControllerTest, SetAdBlockMode_ForOrigin_1) {
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_ADS),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING),
CONTENT_SETTING_BLOCK);
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING,
GURL("https://firstParty/")),
CONTENT_SETTING_ALLOW);
Expand Down Expand Up @@ -199,7 +199,7 @@ TEST_F(BraveShieldsDataControllerTest, SetAdBlockMode_ForOrigin_2) {
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_ADS),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING),
CONTENT_SETTING_BLOCK);
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING,
GURL("https://firstParty/")),
CONTENT_SETTING_ALLOW);
Expand Down Expand Up @@ -263,7 +263,7 @@ TEST_F(BraveShieldsDataControllerTest, SetAdBlockMode_ForOrigin_3) {
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_ADS),
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING),
CONTENT_SETTING_BLOCK);
CONTENT_SETTING_ALLOW);
EXPECT_EQ(GetContentSettingFor(ContentSettingsType::BRAVE_COSMETIC_FILTERING,
GURL("https://firstParty/")),
CONTENT_SETTING_ALLOW);
Expand Down
6 changes: 4 additions & 2 deletions browser/ui/webui/settings/default_brave_shields_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void DefaultBraveShieldsHandler::SetCosmeticFilteringControlType(

brave_shields::SetCosmeticFilteringControlType(
HostContentSettingsMapFactory::GetForProfile(profile_),
ControlTypeFromString(value), GURL(), g_browser_process->local_state());
ControlTypeFromString(value), GURL(), g_browser_process->local_state(),
profile_->GetPrefs());
}

void DefaultBraveShieldsHandler::GetCookieControlType(
Expand Down Expand Up @@ -162,7 +163,8 @@ void DefaultBraveShieldsHandler::SetFingerprintingControlType(

brave_shields::SetFingerprintingControlType(
HostContentSettingsMapFactory::GetForProfile(profile_),
ControlTypeFromString(value), GURL(), g_browser_process->local_state());
ControlTypeFromString(value), GURL(), g_browser_process->local_state(),
profile_->GetPrefs());
}

void DefaultBraveShieldsHandler::SetHTTPSEverywhereEnabled(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BraveFarblingLevel WorkerContentSettingsClient::GetBraveFarblingLevel() {
setting = CONTENT_SETTING_ALLOW;
} else {
// Brave Shields is up, so check fingerprinting rules
setting = GetBraveFPContentSettingFromRules(
setting = brave_shields::GetBraveFPContentSettingFromRules(
content_setting_rules_->fingerprinting_rules, primary_url);
}
}
Expand Down
4 changes: 0 additions & 4 deletions components/brave_shields/browser/ad_block_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service_helper.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/brave_shields/common/adblock_domain_resolver.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_shields/common/features.h"
Expand Down Expand Up @@ -314,9 +313,6 @@ bool AdBlockService::Start() {
regional_service_manager();
subscription_service_manager();

MaybeRecordDefaultShieldsAdsSetting(local_state_);
MaybeRecordDefaultShieldsFingerprintSetting(local_state_);

return true;
}

Expand Down
Loading

0 comments on commit 2af3710

Please sign in to comment.