Skip to content

Commit

Permalink
add toggle for default cosmetic filtering behavior in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Nov 12, 2019
1 parent be5aa9e commit 6aa0f4c
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_ADVANCED_VIEW_LABEL" desc="Default Brave advanced view title label">
Advanced view
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_COSMETIC_FILTERING_CONTROL_LABEL" desc="Default Brave block first-party ads control setting label">
Block first-party ads
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_AD_CONTROL_LABEL" desc="Default Brave block cross-site trackers control setting label">
Block cross-site trackers
</message>
Expand Down
1 change: 1 addition & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// Default Brave shields
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
registry->RegisterBooleanPref(kNoScriptControlType, false);
registry->RegisterBooleanPref(kCosmeticFilteringControlType, true);
registry->RegisterBooleanPref(kAdControlType, true);
// > advanced view is defaulted to true for EXISTING users; false for new
bool is_new_user = false;
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
// Default Brave shields
(*s_brave_whitelist)[kShieldsAdvancedViewEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kCosmeticFilteringControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kAdControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kHTTPSEVerywhereControlType] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
cr.define('settings', function() {
/** @interface */
class DefaultBraveShieldsBrowserProxy {
/**
* @return {!Promise<string>}
*/
getCosmeticFilteringControlType() {}
/**
* @param {string} value name.
*/
setCosmeticFilteringControlType(value) {}

/**
* @return {!Promise<string>}
*/
Expand Down Expand Up @@ -47,6 +56,16 @@ cr.define('settings', function() {
* @implements {settings.DefaultBraveShieldsBrowserProxy}
*/
class DefaultBraveShieldsBrowserProxyImpl {
/** @override */
getCosmeticFilteringControlType() {
return cr.sendWithPromise('getCosmeticFilteringControlType');
}

/** @override */
setCosmeticFilteringControlType(value) {
chrome.send('setCosmeticFilteringControlType', [value]);
}

/** @override */
getAdControlType() {
return cr.sendWithPromise('getAdControlType');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
</settings-radio-group>
</div>
</div>
<settings-toggle-button id="cosmeticFilteringControlType"
pref="{{prefs.brave.cosmetic_filtering_default}}"
label="$i18n{cosmeticFilteringControlLabel}"
on-settings-boolean-control-change="onCosmeticFilteringControlChange_">
</settings-toggle-button>
<settings-toggle-button id="adControlType"
pref="{{prefs.brave.ad_default}}"
label="$i18n{adControlLabel}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Polymer({
return val1 === val2;
},

onCosmeticFilteringControlChange_: function() {
this.browserProxy_.setCosmeticFilteringControlType(this.$.cosmeticFilteringControlType.checked);
},
onAdControlChange_: function() {
this.browserProxy_.setAdControlType(this.$.adControlType.checked);
},
Expand Down
32 changes: 32 additions & 0 deletions browser/ui/webui/settings/default_brave_shields_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ using brave_shields::ControlTypeToString;

void DefaultBraveShieldsHandler::RegisterMessages() {
profile_ = Profile::FromWebUI(web_ui());
web_ui()->RegisterMessageCallback(
"getCosmeticFilteringControlType",
base::BindRepeating(&DefaultBraveShieldsHandler::GetCosmeticFilteringControlType,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"setCosmeticFilteringControlType",
base::BindRepeating(&DefaultBraveShieldsHandler::SetCosmeticFilteringControlType,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getAdControlType",
base::BindRepeating(&DefaultBraveShieldsHandler::GetAdControlType,
Expand Down Expand Up @@ -56,6 +64,30 @@ void DefaultBraveShieldsHandler::RegisterMessages() {
base::Unretained(this)));
}

void DefaultBraveShieldsHandler::GetCosmeticFilteringControlType(const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
CHECK(profile_);

ControlType setting = brave_shields::GetCosmeticFilteringControlType(profile_, GURL());

AllowJavascript();
ResolveJavascriptCallback(
args->GetList()[0].Clone(),
base::Value(setting == ControlType::ALLOW));
}

void DefaultBraveShieldsHandler::SetCosmeticFilteringControlType(const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
CHECK(profile_);
bool value;
args->GetBoolean(0, &value);

brave_shields::SetCosmeticFilteringControlType(profile_,
value ? ControlType::BLOCK
: ControlType::ALLOW,
GURL());
}

void DefaultBraveShieldsHandler::GetAdControlType(const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
CHECK(profile_);
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/webui/settings/default_brave_shields_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class DefaultBraveShieldsHandler : public settings::SettingsPageUIHandler {
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}

void SetCosmeticFilteringControlType(const base::ListValue* args);
void GetCosmeticFilteringControlType(const base::ListValue* args);
void SetAdControlType(const base::ListValue* args);
void GetAdControlType(const base::ListValue* args);
void SetCookieControlType(const base::ListValue* args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_SIMPLE_VIEW_LABEL},
{"advancedView",
IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_ADVANCED_VIEW_LABEL},
{"cosmeticFilteringControlLabel",
IDS_SETTINGS_BRAVE_SHIELDS_COSMETIC_FILTERING_CONTROL_LABEL},
{"adControlLabel",
IDS_SETTINGS_BRAVE_SHIELDS_AD_CONTROL_LABEL},
{"cookieControlLabel",
Expand Down
1 change: 1 addition & 0 deletions common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const char kHTTPSEVerywhereControlType[] = "brave.https_everywhere_default";
const char kNoScriptControlType[] = "brave.no_script_default";
const char kShieldsAdvancedViewEnabled[] =
"brave.shields.advanced_view_enabled";
const char kCosmeticFilteringControlType[] = "brave.cosmetic_filtering_default";
const char kAdControlType[] = "brave.ad_default";
const char kFBEmbedControlType[] = "brave.fb_embed_default";
const char kTwitterEmbedControlType[] = "brave.twitter_embed_default";
Expand Down
1 change: 1 addition & 0 deletions common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern const char kReferralAndroidFirstRunTimestamp[];
extern const char kHTTPSEVerywhereControlType[];
extern const char kNoScriptControlType[];
extern const char kShieldsAdvancedViewEnabled[];
extern const char kCosmeticFilteringControlType[];
extern const char kAdControlType[];
extern const char kFBEmbedControlType[];
extern const char kTwitterEmbedControlType[];
Expand Down

0 comments on commit 6aa0f4c

Please sign in to comment.