Skip to content

Commit

Permalink
Merge pull request #436 from brave/default-brave-shields
Browse files Browse the repository at this point in the history
Add default Brave shields
  • Loading branch information
bbondy committed Sep 26, 2018
1 parent e2da479 commit a6d9cee
Show file tree
Hide file tree
Showing 20 changed files with 695 additions and 8 deletions.
43 changes: 43 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,49 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_UTILITY_PROCESS_TOR_LAUNCHER_NAME" desc="The utility process which launch Tor">
Tor Launcher
</message>
<!-- Brave Shields Defaults -->
<message name="IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_TITLE" desc="The title for Brave shields defaults in settings">
Brave shields defaults
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_AD_CONTROL_LABEL" desc="Default Brave ad control setting label">
Ad Control
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_COOKIE_CONTROL_LABEL" desc="Default Brave cookie control setting label">
Cookie Control
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_FINGERPRINTING_CONTROL_LABEL" desc="Default Brave fingerprinting control setting label">
Fingerprinting protection
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_HTTPS_EVERYWHERE_CONTROL_LABEL" desc="Default Brave HTTPS Everywhere control setting label">
HTTPS Everywhere
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_NO_SCRIPT_CONTROL_LABEL" desc="Default Brave script blocking control setting label">
Script blocking
</message>
<message name="IDS_SETTINGS_BLOCK_ADS" desc="Select value">
Block ads
</message>
<message name="IDS_SETTINGS_ALLOW_ADS_AND_TRACKING" desc="Select value">
Allow ads and tracking
</message>
<message name="IDS_SETTINGS_BLOCK_3RD_PARTY_COOKIES" desc="Select value">
Block 3rd party cookies
</message>
<message name="IDS_SETTINGS_ALLOW_ALL_COOKIES" desc="Select value">
Allow all cookies
</message>
<message name="IDS_SETTINGS_BLOCK_ALL_COOKIES" desc="Select value">
Block all cookies
</message>
<message name="IDS_SETTINGS_BLOCK_3RD_PARTY_FINGERPRINTING" desc="Select value">
Block 3rd party fingerprinting
</message>
<message name="IDS_SETTINGS_ALLOW_FINGERPRINTING" desc="Select value">
Allow fingerprinting
</message>
<message name="IDS_SETTINGS_BLOCK_FINGERPRINTING" desc="Select value">
Block all fingerprinting
</message>
</messages>
<includes>
<include name="IDR_BRAVE_TAG_SERVICES_POLYFILL" file="resources/js/tag_services_polyfill.js" type="BINDATA" />
Expand Down
4 changes: 4 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {

registry->RegisterBooleanPref(kWidevineOptedIn, false);

// Default Brave shields
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
registry->RegisterBooleanPref(kNoScriptControlType, false);

// No sign into Brave functionality
registry->SetDefaultPrefValue(prefs::kSigninAllowed, base::Value(false));

Expand Down
6 changes: 5 additions & 1 deletion browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, DownloadPromptDefault) {
browser()->profile()->GetPrefs()->GetBoolean(prefs::kPromptForDownload));
}

IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, WidevineOptInDisabledByDefault) {
IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kWidevineOptedIn));
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(kHTTPSEVerywhereControlType));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kNoScriptControlType));
}

IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, DisableGoogleServicesByDefault) {
Expand Down
7 changes: 5 additions & 2 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
const auto chromium_prefs = PrefsUtil::GetWhitelistedKeys();
s_brave_whitelist->insert(chromium_prefs.begin(), chromium_prefs.end());
// Add Brave values to the whitelist
#if !defined(OS_CHROMEOS)
// import data
(*s_brave_whitelist)[::prefs::kImportDialogCookies] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[::prefs::kImportDialogStats] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
#endif
// Default Brave shields
(*s_brave_whitelist)[kHTTPSEVerywhereControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNoScriptControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// appearance prefs
(*s_brave_whitelist)[kLocationBarIsWide] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
Expand Down
7 changes: 7 additions & 0 deletions browser/resources/settings/brave_page_visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ cr.define('settings', function() {
}
};

const braveShieldsDefaultsHandler = {
get: function(obj, prop) {
return true;
}
};

const privacyHandler = {
get: function(obj, prop) {
return true;
Expand All @@ -28,6 +34,7 @@ cr.define('settings', function() {
const handler = {
get: function(obj, prop) {
if (prop === 'appearance') return new Proxy({}, appearanceHandler);
if (prop === 'braveShieldsDefaults') return new Proxy({}, braveShieldsDefaultsHandler);
if (prop === 'privacy') return new Proxy({}, privacyHandler);
return prop === 'a11y' ? false : true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="href" src="chrome://resources/html/cr.html">
<script src="default_brave_shields_browser_proxy.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

cr.define('settings', function() {
/** @interface */
class DefaultBraveShieldsBrowserProxy {
/**
* @return {!Promise<string>}
*/
getAdControlType() {}
/**
* @param {string} value name.
*/
setAdControlType(value) {}

/**
* @return {!Promise<string>}
*/
getCookieControlType() {}
/**
* @param {string} value name.
*/
setCookieControlType(value) {}

/**
* @return {!Promise<string>}
*/
getFingerprintingControlType() {}
/**
* @param {string} value name.
*/
setFingerprintingControlType(value) {}

/**
* @param {string} value name.
*/
setHTTPSEverywhereControlType(value) {}

/**
* @param {string} value name.
*/
setNoScriptControlType(value) {}
}

/**
* @implements {settings.DefaultBraveShieldsBrowserProxy}
*/
class DefaultBraveShieldsBrowserProxyImpl {
/** @override */
getAdControlType() {
return cr.sendWithPromise('getAdControlType');
}

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

/** @override */
getCookieControlType() {
return cr.sendWithPromise('getCookieControlType');
}

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

/** @override */
getFingerprintingControlType() {
return cr.sendWithPromise('getFingerprintingControlType');
}

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

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

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

cr.addSingletonGetter(DefaultBraveShieldsBrowserProxyImpl);

return {
DefaultBraveShieldsBrowserProxy,
DefaultBraveShieldsBrowserProxyImpl
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<link rel="import" href="chrome://resources/html/polymer.html">

<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/html/md_select_css.html">
<link rel="import" href="default_brave_shields_browser_proxy.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html">

<dom-module id="settings-default-brave-shields-page">
<template>
<style include="settings-shared md-select iron-flex">
</style>
<div class="settings-box">
<div class="start">$i18n{adControlLabel}</div>
<select id="adControlType" class="md-select"
on-change="onAdControlChange_">
<template is="dom-repeat" items="[[adControlTypes_]]">
<option value="[[item.value]]"
selected="[[controlEqual(item.value, adControlType_)]]">
[[item.name]]
</option>
</template>
</select>
</div>
<div class="settings-box">
<div class="start">$i18n{cookieControlLabel}</div>
<select id="cookieControlType" class="md-select"
on-change="onCookieControlChange_">
<template is="dom-repeat" items="[[cookieControlTypes_]]">
<option value="[[item.value]]"
selected="[[controlEqual(item.value, cookieControlType_)]]">
[[item.name]]
</option>
</template>
</select>
</div>
<div class="settings-box">
<div class="start">$i18n{fingerprintingControlLabel}</div>
<select id="fingerprintingControlType" class="md-select"
on-change="onFingerprintingControlChange_">
<template is="dom-repeat" items="[[fingerprintingControlTypes_]]">
<option value="[[item.value]]"
selected="[[controlEqual(item.value, fingerprintingControlType_)]]">
[[item.name]]
</option>
</template>
</select>
</div>
<settings-toggle-button id="httpsEverywhereControlType"
pref="{{prefs.brave.https_everywhere_default}}"
label="$i18n{httpsEverywhereControlLabel}"
on-settings-boolean-control-change="onHTTPSEverywhereControlChange_">
</settings-toggle-button>
<settings-toggle-button id="noScriptControlType"
pref="{{prefs.brave.no_script_default}}"
label="$i18n{noScriptControlLabel}"
on-settings-boolean-control-change="onNoScriptControlChange_">
</settings-toggle-button>
</template>
<script src="default_brave_shields_page.js"></script>
</dom-module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

(function() {
'use strict';

/**
* 'settings-default-brave-shields-page' is the settings page containing brave's
* default shields.
*/
Polymer({
is: 'settings-default-brave-shields-page',

properties: {
adControlTypes_: {
readOnly: true,
type: Array,
value: function() {
return [
{value: 'block', name: loadTimeData.getString('blockAds')},
{value: 'allow', name: loadTimeData.getString('allowAdsAndTracking')}
]
}
},

cookieControlTypes_: {
readOnly: true,
type: Array,
value: function() {
return [
{value: '3p', name: loadTimeData.getString('block3rdPartyCookies')},
{value: 'block', name: loadTimeData.getString('blockAllCookies')},
{value: 'allow', name: loadTimeData.getString('allowAllCookies')}
]
}
},

fingerprintingControlTypes_: {
readOnly: true,
type: Array,
value: function() {
return [
{value: '3p', name: loadTimeData.getString('block3rdPartyFingerprinting')},
{value: 'block', name: loadTimeData.getString('blockAllFingerprinting')},
{value: 'allow', name: loadTimeData.getString('allowAllFingerprinting')}
]
}
},

adControlType_: String,
cookieControlType_: String,
fingerprintingControlType_: String,
},

/** @private {?settings.DefaultBraveShieldsBrowserProxy} */
browserProxy_: null,

/** @override */
created: function() {
this.browserProxy_ = settings.DefaultBraveShieldsBrowserProxyImpl.getInstance();
},

/** @override */
ready: function() {
this.onAdControlChange_= this.onAdControlChange_.bind(this)
this.onCookieControlChange_ = this.onCookieControlChange_.bind(this)
this.onFingerprintingControlChange_ = this.onFingerprintingControlChange_.bind(this)
this.onHTTPSEverywhereControlChange_ = this.onHTTPSEverywhereControlChange_.bind(this)
this.onNoScriptControlChange_ = this.onNoScriptControlChange_.bind(this)

this.browserProxy_.getAdControlType().then(value => {
this.adControlType_= value;
});
this.browserProxy_.getCookieControlType().then(value => {
this.cookieControlType_ = value;
});
this.browserProxy_.getFingerprintingControlType().then(value => {
this.fingerprintingControlType_ = value;
});
},

/**
* @param {string} value
* @param {string} value
* @return {boolean}
* @private
*/
controlEqual: function(val1, val2) {
return val1 === val2;
},

onAdControlChange_: function() {
this.browserProxy_.setAdControlType(this.$.adControlType.value);
},
onCookieControlChange_: function() {
this.browserProxy_.setCookieControlType(this.$.cookieControlType.value);
},
onFingerprintingControlChange_: function() {
this.browserProxy_.setFingerprintingControlType(this.$.fingerprintingControlType.value);
},
onHTTPSEverywhereControlChange_: function() {
this.browserProxy_.setHTTPSEverywhereControlType(this.$.httpsEverywhereControlType.checked);
},
onNoScriptControlChange_: function() {
this.browserProxy_.setNoScriptControlType(this.$.noScriptControlType.checked);
},
});
})();
2 changes: 1 addition & 1 deletion browser/resources/settings/settings_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<structure name="IDR_SETTINGS_APPEARANCE_FONTS_PAGE_HTML" file="appearance_page/appearance_fonts_page.html" type="chrome_html" allowexternalscript="true" preprocess="true" />
<structure name="IDR_SETTINGS_APPEARANCE_FONTS_PAGE_JS" file="appearance_page/appearance_fonts_page.js" type="chrome_html" />
<structure name="IDR_SETTINGS_APPEARANCE_PAGE_HTML" file="appearance_page/appearance_page.html" type="chrome_html" preprocess="true" allowexternalscript="true" />
<structure name="IDR_SETTINGS_APPEARANCE_PAGE_JS" file="appearance_page/appearance_page.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_BROWSER_PROXY_HTML" file="brave_appearance_page/brave_appearance_browser_proxy.html" type="chrome_html" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_BROWSER_PROXY_JS" file="brave_appearance_page/brave_appearance_browser_proxy.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_PAGE_JS" file="brave_appearance_page/brave_appearance_page.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_PAGE_HTML" file="brave_appearance_page/brave_appearance_page.html" type="chrome_html" preprocess="true" allowexternalscript="true" />
<structure name="IDR_SETTINGS_DEFAULT_BRAVE_SHIELDS_BROWSER_PROXY_HTML" file="default_brave_shields_page/default_brave_shields_browser_proxy.html" type="chrome_html" /><structure name="IDR_SETTINGS_DEFAULT_BRAVE_SHIELDS_BROWSER_PROXY_JS" file="default_brave_shields_page/default_brave_shields_browser_proxy.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_DEFAULT_BRAVE_SHIELDS_PAGE_JS" file="default_brave_shields_page/default_brave_shields_page.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_APPEARANCE_PAGE_JS" file="appearance_page/appearance_page.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_DEFAULT_BRAVE_SHIELDS_PAGE_HTML" file="default_brave_shields_page/default_brave_shields_page.html" type="chrome_html" preprocess="true" allowexternalscript="true" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_BROWSER_PROXY_HTML" file="brave_appearance_page/brave_appearance_browser_proxy.html" type="chrome_html" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_BROWSER_PROXY_JS" file="brave_appearance_page/brave_appearance_browser_proxy.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_PAGE_JS" file="brave_appearance_page/brave_appearance_page.js" type="chrome_html" preprocess="true" /><structure name="IDR_SETTINGS_BRAVE_APPEARANCE_PAGE_HTML" file="brave_appearance_page/brave_appearance_page.html" type="chrome_html" preprocess="true" allowexternalscript="true" />
<structure name="IDR_SETTINGS_APPEARANCE_HOME_URL_INPUT_HTML" file="appearance_page/home_url_input.html" type="chrome_html" />
<structure name="IDR_SETTINGS_APPEARANCE_HOME_URL_INPUT_JS" file="appearance_page/home_url_input.js" type="chrome_html" />
<structure name="IDR_SETTINGS_BASIC_PAGE_JS" file="basic_page/basic_page.js" preprocess="true" type="chrome_html" />
Expand Down
Loading

0 comments on commit a6d9cee

Please sign in to comment.