Skip to content

Commit

Permalink
Added Shields settings sections
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Oct 14, 2022
1 parent e163516 commit b83cc84
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 27 deletions.
18 changes: 15 additions & 3 deletions app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@
</if>

<!-- Settings / Shields -->
<message name="IDS_SETTINGS_SITE_SETTINGS_SHIELDS" desc="Label for shields site settings.">
Shields settings
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SHIELDS_STATUS" desc="Label for shields status site settings.">
Shields status
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SHIELDS_DESCRIPTION" desc="Label for shields status on site settings.">
Sites can block trackers, ads, and fingerprinting using Shields
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SHIELDS_UP" desc="Label for shields status up site settings.">
Shields Up
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SHIELDS_DOWN" desc="Label for shields status down site settings.">
Shields Down
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_TITLE" desc="The title for Brave shields section in settings">
Shields
</message>
Expand Down Expand Up @@ -196,9 +211,6 @@
<message name="IDS_SETTINGS_ALLOW_ADS_TRACKERS" desc="Select value">
Disabled
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_HTTPS_EVERYWHERE_CONTROL_LABEL" desc="Default Brave upgrade connections to HTTPS control setting label">
Upgrade connections to HTTPS
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_NO_SCRIPT_CONTROL_LABEL" desc="Default Brave script blocking control setting label">
Block scripts
</message>
Expand Down
2 changes: 0 additions & 2 deletions browser/brave_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, DownloadPromptDefault) {
}

IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
EXPECT_TRUE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean(
kHTTPSEVerywhereControlType));
EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean(
kNoScriptControlType));
EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean(
Expand Down
1 change: 0 additions & 1 deletion browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kAskWidevineInstall, true);

// Default Brave shields
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
registry->RegisterBooleanPref(kNoScriptControlType, false);
registry->RegisterBooleanPref(kAdControlType, true);
registry->RegisterBooleanPref(kShieldsAdvancedViewEnabled, false);
Expand Down
2 changes: 0 additions & 2 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kAdControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kHTTPSEVerywhereControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kNoScriptControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[kGoogleLoginControlType] =
Expand Down
11 changes: 11 additions & 0 deletions browser/resources/settings/brave_overrides/privacy_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ RegisterPolymerTemplateModifications({
</template>
`)
}
pages.insertAdjacentHTML('beforeend', `
<template is="dom-if" route-path="/content/braveShields" no-search>
<settings-subpage page-title="${I18nBehavior.i18n('siteSettingsShieldsStatus')}">
<category-setting-exceptions
category="[[contentSettingsTypesEnum_.BRAVE_SHIELDS]]"
block-header="${I18nBehavior.i18n('siteSettingsShieldsDown')}"
allow-header="${I18nBehavior.i18n('siteSettingsShieldsUp')}">
</category-setting-exceptions>
</settings-subpage>
</template>
`)
}

if (!loadTimeData.getBoolean('isPrivacySandboxRestricted')) {
Expand Down
18 changes: 18 additions & 0 deletions browser/resources/settings/brave_overrides/site_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,23 @@ RegisterPolymerTemplateModifications({
`)
}
}
const usageSection = templateContent.querySelector('div#usage')
if (!usageSection) {
console.error(`[Brave Settings Overrides] Couldn't find usageSection item`)
} else {
usageSection.insertAdjacentHTML('afterend', `
<div id="shields">
<div id="shieldsHeader" style="padding: 0 var(--cr-section-padding);">
<h2 class="first">${I18nBehavior.i18n('siteSettingsShields')}</h2>
</div>
<div class="list-frame">
<site-details-permission
category="[[contentSettingsTypesEnum_.BRAVE_SHIELDS]]"
icon="brave_settings:shields" label="${I18nBehavior.i18n('siteSettingsShieldsStatus')}">
</site-details-permission>
</div>
</div>
`)
}
},
})
33 changes: 31 additions & 2 deletions browser/resources/settings/brave_overrides/site_settings_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

// @ts-nocheck TODO(petemill): Define types and remove ts-nocheck

import {RegisterPolymerComponentReplacement} from 'chrome://resources/polymer_overriding.js'
import {RegisterPolymerComponentReplacement, RegisterPolymerTemplateModifications} from 'chrome://resources/polymer_overriding.js'
import {ContentSettingsTypes} from '../site_settings/constants.js'
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {I18nBehavior} from 'chrome://resources/cr_elements/i18n_behavior.js';
import {SettingsSiteSettingsPageElement} from '../site_settings_page/site_settings_page.js'
import {routes} from '../route.js'
import './config.js'
Expand All @@ -19,6 +20,23 @@ const CONTENT_ADVANCED_REMOVE_IDS = [
ContentSettingsTypes.ADS,
]

RegisterPolymerTemplateModifications({
'settings-site-settings-page': (templateContent) => {
const allSites = templateContent.querySelector('#allSites')
if (!allSites) {
console.error('[Brave Settings Overrides] Could not find all sites list')
return
}
allSites.insertAdjacentHTML('afterend', `
<div class="cr-row first line-only"><h2>${I18nBehavior.i18n('siteSettingsShields')}</h2></div>
<settings-site-settings-list id="basicShieldsList"
category-list="[[lists_.shieldsBasic]]"
focus-config="[[focusConfig]]">
</settings-site-settings-list>
`)
}
})

RegisterPolymerComponentReplacement(
'settings-site-settings-page',
class BraveComponent extends SettingsSiteSettingsPageElement {
Expand All @@ -30,7 +48,7 @@ RegisterPolymerComponentReplacement(
}
const oldListsGetter = properties.lists_.value
properties.lists_.value = function () {
const lists_ = oldListsGetter()
let lists_ = oldListsGetter()
if (!lists_) {
console.error('[Brave Settings Overrides] did not get lists_ data')
return
Expand Down Expand Up @@ -95,6 +113,17 @@ RegisterPolymerComponentReplacement(
}
}
}
lists_.shieldsBasic = [
{
route: routes.SITE_SETTINGS_SHIELDS_STATUS,
id: 'braveShields',
label: 'siteSettingsShieldsStatus',
icon: 'brave_settings:shields',
enabledLabel: 'siteSettingsShieldsDescription',
disabledLabel: 'siteSettingsShieldsDown'
}
]

return lists_
}
return properties
Expand Down
1 change: 1 addition & 0 deletions browser/resources/settings/brave_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function addBraveRoutes(r) {
r.SITE_SETTINGS_ETHEREUM = r.SITE_SETTINGS.createChild('ethereum')
r.SITE_SETTINGS_SOLANA = r.SITE_SETTINGS.createChild('solana')
}
r.SITE_SETTINGS_SHIELDS_STATUS = r.SITE_SETTINGS.createChild('braveShields')
if (r.SITE_SETTINGS_ADS) {
delete r.SITE_SETTINGS_ADS
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@
</template>
</select>
</div>
<settings-toggle-button id="httpsEverywhereControlType"
class="cr-row"
pref="{{prefs.brave.https_everywhere_default}}"
label="$i18n{httpsEverywhereControlLabel}"
on-settings-boolean-control-change="onHTTPSEverywhereControlChange_">
</settings-toggle-button>
<settings-toggle-button id="noScriptControlType"
class="cr-row"
pref="{{prefs.brave.no_script_default}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class BraveShieldsPage extends BraveShieldsPageBase {
}
})

}

refreshState() {
this.browserProxy_.getHTTPSEverywhereEnabled().then(value => {
this.httpsEverywhereEnabled_ = value
})

this.browserProxy_.getCookieControlType().then(value => {
this.cookieControlType_ = value
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
{"siteSettingsSolanaAsk", IDS_SETTINGS_SITE_SETTINGS_SOLANA_ASK},
{"siteSettingsSolanaBlock", IDS_SETTINGS_SITE_SETTINGS_SOLANA_BLOCK},
{"braveGetStartedTitle", IDS_SETTINGS_BRAVE_GET_STARTED_TITLE},
{"siteSettingsShields", IDS_SETTINGS_SITE_SETTINGS_SHIELDS},
{"siteSettingsShieldsStatus", IDS_SETTINGS_SITE_SETTINGS_SHIELDS_STATUS},
{"siteSettingsShieldsUp", IDS_SETTINGS_SITE_SETTINGS_SHIELDS_UP},
{"siteSettingsShieldsDown", IDS_SETTINGS_SITE_SETTINGS_SHIELDS_DOWN},
{"siteSettingsShieldsDescription",
IDS_SETTINGS_SITE_SETTINGS_SHIELDS_DESCRIPTION},
{"appearanceSettingsBraveTheme",
IDS_SETTINGS_APPEARANCE_SETTINGS_BRAVE_THEMES},
{"appearanceSettingsShowBookmarksButton",
Expand Down Expand Up @@ -163,8 +169,6 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
{"reduceLanguageControlLabel",
IDS_SETTINGS_BRAVE_SHIELDS_REDUCE_LANGUAGE_CONTROL_LABEL},
{"reduceLanguageDesc", IDS_SETTINGS_BRAVE_SHIELDS_REDUCE_LANGUAGE_SUBITEM},
{"httpsEverywhereControlLabel",
IDS_SETTINGS_BRAVE_SHIELDS_HTTPS_EVERYWHERE_CONTROL_LABEL},
{"noScriptControlLabel",
IDS_SETTINGS_BRAVE_SHIELDS_NO_SCRIPT_CONTROL_LABEL},
{"showStatsBlockedBadgeLabel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "chrome/browser/ui/webui/settings/site_settings_helper.h"

#include "brave/components/brave_shields/common/brave_shield_constants.h"

#define HasRegisteredGroupName HasRegisteredGroupName_ChromiumImpl
#define ContentSettingsTypeToGroupName \
ContentSettingsTypeToGroupName_ChromiumImpl
Expand Down Expand Up @@ -32,7 +34,9 @@
if (name == "ethereum") \
return ContentSettingsType::BRAVE_ETHEREUM; \
if (name == "solana") \
return ContentSettingsType::BRAVE_SOLANA;
return ContentSettingsType::BRAVE_SOLANA; \
if (name == brave_shields::kBraveShields) \
return ContentSettingsType::BRAVE_SHIELDS;

#include "src/chrome/browser/ui/webui/settings/site_settings_helper.cc"

Expand All @@ -51,6 +55,8 @@ bool HasRegisteredGroupName(ContentSettingsType type) {
return true;
if (type == ContentSettingsType::BRAVE_SOLANA)
return true;
if (type == ContentSettingsType::BRAVE_SHIELDS)
return true;
return HasRegisteredGroupName_ChromiumImpl(type);
}

Expand All @@ -61,15 +67,15 @@ base::StringPiece ContentSettingsTypeToGroupName(ContentSettingsType type) {
return "ethereum";
if (type == ContentSettingsType::BRAVE_SOLANA)
return "solana";
if (type == ContentSettingsType::BRAVE_SHIELDS)
return brave_shields::kBraveShields;
return ContentSettingsTypeToGroupName_ChromiumImpl(type);
}

const std::vector<ContentSettingsType>& GetVisiblePermissionCategories() {
static base::NoDestructor<std::vector<ContentSettingsType>> types{{
ContentSettingsType::AUTOPLAY,
ContentSettingsType::BRAVE_ETHEREUM,
ContentSettingsType::BRAVE_SOLANA,
}};
static base::NoDestructor<std::vector<ContentSettingsType>> types{
{ContentSettingsType::AUTOPLAY, ContentSettingsType::BRAVE_ETHEREUM,
ContentSettingsType::BRAVE_SOLANA}};
static bool initialized = false;
if (!initialized) {
auto& base_types = GetVisiblePermissionCategories_ChromiumImpl();
Expand Down
1 change: 0 additions & 1 deletion components/constants/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const char kReferralAttemptCount[] = "brave.referral.referral_attempt_count";
const char kReferralHeaders[] = "brave.referral.headers";
const char kReferralAndroidFirstRunTimestamp[] =
"brave.referral_android_first_run_timestamp";
const char kHTTPSEVerywhereControlType[] = "brave.https_everywhere_default";
const char kNoScriptControlType[] = "brave.no_script_default";
const char kShieldsAdvancedViewEnabled[] =
"brave.shields.advanced_view_enabled";
Expand Down
1 change: 0 additions & 1 deletion components/constants/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern const char kReferralAttemptTimestamp[];
extern const char kReferralAttemptCount[];
extern const char kReferralHeaders[];
extern const char kReferralAndroidFirstRunTimestamp[];
extern const char kHTTPSEVerywhereControlType[];
extern const char kNoScriptControlType[];
extern const char kShieldsAdvancedViewEnabled[];
extern const char kShieldsStatsBadgeVisible[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ index b51c1d25ae44512d0218030436feed867a1c216a..988a30c89868e4b15997ed1d95554c16
// The following item is not in the C++ kContentSettingsTypeGroupNames, but it
// is used everywhere where ContentSettingsTypes is used in JS.
PDF_DOCUMENTS = 'pdfDocuments',
+ AUTOPLAY = 'autoplay', ETHEREUM = 'ethereum', SOLANA = 'solana',
+ AUTOPLAY = 'autoplay', ETHEREUM = 'ethereum', SOLANA = 'solana', BRAVE_SHIELDS = 'braveShields',
}

/**

0 comments on commit b83cc84

Please sign in to comment.