Skip to content

Commit

Permalink
set shields interface views as a global default in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jul 24, 2019
1 parent 9258a23 commit 6c471e3
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_SOCIAL_BLOCKING_DEFAULTS_TITLE" desc="The title the settings section which has options for blocking third-party embeds, commonly from social media sites">
Social media blocking
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_DEFAULT_VIEW_LABEL" desc="Default Brave view title label">
Default view
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_SIMPLE_VIEW_LABEL" desc="Default Brave simple view title label">
Simple view
</message>
<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_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) {
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
registry->RegisterBooleanPref(kNoScriptControlType, false);
registry->RegisterBooleanPref(kAdControlType, true);
registry->RegisterBooleanPref(kAdvancedViewControlType, false);
registry->RegisterBooleanPref(kGoogleLoginControlType, true);
registry->RegisterBooleanPref(kFBEmbedControlType, true);
registry->RegisterBooleanPref(kTwitterEmbedControlType, true);
Expand Down
2 changes: 2 additions & 0 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
kHTTPSEVerywhereControlType));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kNoScriptControlType));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kAdvancedViewControlType));
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(kAdControlType));
EXPECT_TRUE(
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 @@ -35,6 +35,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
(*s_brave_whitelist)[::prefs::kImportDialogWindows] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// Default Brave shields
(*s_brave_whitelist)[kAdvancedViewControlType] =
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,11 @@
cr.define('settings', function() {
/** @interface */
class DefaultBraveShieldsBrowserProxy {
/**
* @param {string} value name.
*/
setAdvancedViewControlType(value) {}

/**
* @return {!Promise<string>}
*/
Expand Down Expand Up @@ -47,6 +52,11 @@ cr.define('settings', function() {
* @implements {settings.DefaultBraveShieldsBrowserProxy}
*/
class DefaultBraveShieldsBrowserProxyImpl {
/** @override */
setAdvancedViewControlType(value) {
chrome.send('setAdvancedViewControlType', [value]);
}

/** @override */
getAdControlType() {
return cr.sendWithPromise('getAdControlType');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
.label.shields-secondary-title {
padding-bottom: 1em;
}
.shields-views {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 16px;
}
.shields-view-col {
margin: 16px 0 24px;
padding: 24px;
height: 100px;
border-radius: 6px;
border: 1px solid rgba(0,0,0,0.5);
display: flex;
align-items: center;
}
.shields-view-label {
margin: 0 20px;
}
</style>
<div class="settings-box first">
<div class="flex">
Expand All @@ -28,6 +45,35 @@
</div>
</div>
</div>
<settings-toggle-button id="advancedViewControlType"
pref="{{prefs.advanced_view_default}}"
label="$i18n{advancedView}"
on-settings-boolean-control-change="onAdvancedViewControlChange_">
</settings-toggle-button>
<!-- TODO: should be a radio input instead of checkbox
<settings-radio-group
id="advancedViewControlType"
class="settings-box"
pref="{{prefs.brave.advanced_view_default}}"
on-selected-changed="onAdvancedViewControlChange_">
<div class="label shields-primary-title">$i18n{defaultView}</div>
<div class="shields-views">
<div class="shields-view-col">
<controlled-radio-button
name="true" pref="[[prefs.brave.advanced_view_default]]">
<img src="images/stamp-simpleview.webp">
<label class="shields-view-label">$i18n{simpleView}</label>
</controlled-radio-button>
</div>
<div class="shields-view-col">
<controlled-radio-button
name="false" pref="[[prefs.brave.advanced_view_default]]">
<img src="images/stamp-simpleview.webp">
<label class="shields-view-label">$i18n{advancedView}</label>
</controlled-radio-button>
</div>
</div>
</settings-radio-group> -->
<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 @@ -51,6 +51,7 @@ Polymer({

/** @override */
ready: function() {
this.onAdvancedViewControlChange_ = this.onAdvancedViewControlChange_.bind(this)
this.onAdControlChange_= this.onAdControlChange_.bind(this)
this.onCookieControlChange_ = this.onCookieControlChange_.bind(this)
this.onFingerprintingControlChange_ = this.onFingerprintingControlChange_.bind(this)
Expand All @@ -75,6 +76,9 @@ Polymer({
return val1 === val2;
},

onAdvancedViewControlChange_: function() {
this.browserProxy_.setAdvancedViewControlType(this.$.advancedViewControlType.checked);
},
onAdControlChange_: function() {
this.browserProxy_.setAdControlType(this.$.adControlType.checked);
},
Expand Down
Binary file not shown.
Binary file not shown.
16 changes: 16 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,10 @@

void DefaultBraveShieldsHandler::RegisterMessages() {
profile_ = Profile::FromWebUI(web_ui());
web_ui()->RegisterMessageCallback(
"setAdvancedViewControlType",
base::BindRepeating(&DefaultBraveShieldsHandler::SetAdvancedViewControlType,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getAdControlType",
base::BindRepeating(&DefaultBraveShieldsHandler::GetAdControlType,
Expand Down Expand Up @@ -56,6 +60,18 @@ void DefaultBraveShieldsHandler::RegisterMessages() {
base::Unretained(this)));
}

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

// extensions::ExtensionService* service =
// extensions::ExtensionSystem::Get(profile_)->extension_service();
// extensions::ComponentLoader* loader = service->component_loader();
}

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

void SetAdvancedViewControlType(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 @@ -66,6 +66,12 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_DESCRIPTION_3},
{"socialBlocking",
IDS_SETTINGS_SOCIAL_BLOCKING_DEFAULTS_TITLE},
{"defaultView",
IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_DEFAULT_VIEW_LABEL},
{"simpleView",
IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_SIMPLE_VIEW_LABEL},
{"advancedView",
IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_ADVANCED_VIEW_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 @@ -40,6 +40,7 @@ const char kReferralCheckedForPromoCodeFile[] =
"brave.referral.checked_for_promo_code_file";
const char kHTTPSEVerywhereControlType[] = "brave.https_everywhere_default";
const char kNoScriptControlType[] = "brave.no_script_default";
const char kAdvancedViewControlType[] = "brave.advanced_view_default";
const char kAdControlType[] = "brave.ad_default";
const char kGoogleLoginControlType[] = "brave.google_login_default";
const char kFBEmbedControlType[] = "brave.fb_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 @@ -35,6 +35,7 @@ extern const char kReferralHeaders[];
extern const char kReferralCheckedForPromoCodeFile[];
extern const char kHTTPSEVerywhereControlType[];
extern const char kNoScriptControlType[];
extern const char kAdvancedViewControlType[];
extern const char kAdControlType[];
extern const char kGoogleLoginControlType[];
extern const char kFBEmbedControlType[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export default class Shields extends React.PureComponent<Props, State> {
this.setState({ isBlockedListOpen: !this.state.isBlockedListOpen })
}

onClickTestEnableAdvancedView = () => {
// chrome.send is not exposed to extensions
// TODO: find the correct method
// chrome.send('setAdvancedViewControlType', [true])
}

render () {
const { shieldsPanelTabData, persistentData, actions } = this.props
const { isBlockedListOpen } = this.state
Expand All @@ -90,6 +96,9 @@ export default class Shields extends React.PureComponent<Props, State> {

return (
<ShieldsPanel data-test-id='brave-shields-panel' style={{ width: '370px' }}>
<button onClick={this.onClickTestEnableAdvancedView}>
turn advanced view on
</button>
{
persistentData.isFirstAccess
&& <WebCompatWarning setAdvancedViewFirstAccess={actions.setAdvancedViewFirstAccess} />
Expand Down

0 comments on commit 6c471e3

Please sign in to comment.