diff --git a/components/brave_extension/extension/brave_extension/BUILD.gn b/components/brave_extension/extension/brave_extension/BUILD.gn index 571f11ec73cd..10f4e248c874 100644 --- a/components/brave_extension/extension/brave_extension/BUILD.gn +++ b/components/brave_extension/extension/brave_extension/BUILD.gn @@ -40,14 +40,18 @@ transpile_web_ui("brave_extension") { "background/reducers/shieldsPanelReducer.ts", "background/store.ts", "braveShieldsPanel.tsx", - "components/braveShields/braveShields.tsx", - "components/braveShields/footer.tsx", - "components/braveShields/header.tsx", - "components/braveShields/interfaceControls.tsx", - "components/braveShields/privacyControls.tsx", - "components/braveShields/blockedResources/blockedResources.tsx", - "components/braveShields/blockedResources/scriptsList.tsx", - "components/braveShields/blockedResources/staticList.tsx", + "components/braveShields.tsx", + "components/footer.tsx", + "components/header.tsx", + "components/interfaceControls.tsx", + "components/privacyControls.tsx", + "components/controls/adsTrackersControl.tsx", + "components/controls/cookiesControl.tsx", + "components/controls/deviceRecognitionControl.tsx", + "components/controls/httpsUpgradesControl.tsx", + "components/controls/scriptsControl.tsx", + "components/list/dynamic.tsx", + "components/list/static.tsx", "constants/cosmeticFilterTypes.ts", "constants/resourceIdentifiers.ts", "constants/runtimeActionTypes.ts", diff --git a/components/brave_extension/extension/brave_extension/_locales/en_US/messages.json b/components/brave_extension/extension/brave_extension/_locales/en_US/messages.json index eb925256842c..e1be70d452f8 100644 --- a/components/brave_extension/extension/brave_extension/_locales/en_US/messages.json +++ b/components/brave_extension/extension/brave_extension/_locales/en_US/messages.json @@ -15,10 +15,6 @@ "message": "down", "description": "Message for when shields is disabled" }, - "totalBlocked": { - "message": "Total blocked", - "description": "Message showing the amount of all blocked resources" - }, "forThisSite": { "message": "for this site", "description": "Partial string for the phrase `shields is up *for this site*`" @@ -31,69 +27,65 @@ "message": "You’re browsing this site without any privacy and security protections.", "description": "Message telling the user that shields are disabled" }, - "blockAds": { - "message": "Ads and trackers blocked", - "description": "Message indicating the number of ads and trackers blocked" + "itemsBlocked": { + "message": "Items blocked", + "description": "Message for the main blocked resources text when there is more than one ad/track/script blocked (plural)" }, - "blockPopups": { - "message": "Pop-ups blocked", - "description": "Message indicating the number of pop-ups blocked" + "itemBlocked": { + "message": "Item blocked", + "description": "Message for the main blocked resources text when there is one ad/track/script blocked (singular)" }, - "blockImages": { - "message": "Images blocked", - "description": "Message indicating the number of images blocked" + "and": { + "message": "and", + "description": "Message for the `and` conjunction. Used to connect grammatically the `item blocked and connection upgrades` and its variant phrases" }, - "block3partyCookies": { - "message": "3rd-party cookies blocked", - "description": "Message for the select option about cookies blocked, blocking 3rd party cookies" + "connectionsUpgraded": { + "message": "connections upgraded", + "description": "Message for the main blocked resources text when there is at least one ad/track/script blocked and more than one connection upgrade (plural)" }, - "allowAllCookies": { - "message": "All cookies allowed", - "description": "Message for the select option about cookies blocked, allowing all cookies" + "connectionUpgraded": { + "message": "connection upgraded", + "description": "Message for the main blocked resources text when there is at least one ad/track/script blocked and one connection upgrade (singular)" }, - "blockAllCookies": { - "message": "Cookies blocked", - "description": "Message for the select option about cookies blocked, blocking all cookies" + "thirdPartyTrackersBlocked": { + "message": "3rd-party trackers blocked", + "description": "Message for the scripts blocked row label" }, - "blockSomeScripts": { - "message": "Some scripts blocked", - "description": "Message for the select option about scripts blocked, blocking 3rd party scripts" + "connectionsUpgradedHTTPS": { + "message": "Connections upgraded to HTTPS", + "description": "Message for the connections upgraded row label and for the main blocked resources text when there is more than one connection upgraded (plural) and no other ads/trackers blocked" }, - "allowAllScripts": { - "message": "All scripts allowed", - "description": "Message for the select option about scripts blocked, allowing all scripts" + "connectionUpgradedHTTPS": { + "message": "Connection upgraded to HTTPS", + "description": "Message for the main blocked resources text when there is one connection upgraded (singular) and no other ads/trackers blocked" }, - "blockAllScriptsOrigins": { + "scriptsBlocked": { "message": "Scripts blocked", - "description": "Message for the select option about scripts blocked, blocking all scripts" - }, - "block3partyFingerprinting": { - "message": "3rd-party device recognition blocked", - "description": "Message for the select option about fingerprinting blocked, blocking 3rd party fingerprinting" + "description": "Message for the scripts blocked row label" }, - "allowAllFingerprinting": { - "message": "All device recognition allowed", - "description": "Message for the select option about fingerprinting blocked, allowing all fingerprinting" + "thirdPartyCookiesBlocked": { + "message": "3rd-party cookies blocked", + "description": "Message for the option in the cookies select field to block all 3rd party cookies" }, - "blockAllFingerprinting": { - "message": "Device recognition blocked", - "description": "Message for the select option about fingerprinting blocked, blocking all fingerprinting" + "allCookiesBlocked": { + "message": "Cookies blocked", + "description": "Message for the option in the cookies select field to block all cookies" }, - "blockPishing": { - "message": "Phishing/malware attempts blocked", - "description": "Message indicating the number of phishing/malware blocked" + "allCookiesAllowed": { + "message": "All cookies allowed", + "description": "Message for the option in the cookies select field to allow all cookies" }, - "connectionsEncrypted": { - "message": "Connections encrypted", - "description": "Message indicating the number of connections encrypted" + "thirdPartyFingerprintingBlocked": { + "message": "3rd-party device recognition blocked", + "description": "Message for the option in the device recognition select field to block all 3rd party recognition attempts" }, - "editDefaults": { - "message": "Global shield defaults", - "description": "Message linking shields to the global shield settings" + "allFingerprintingBlocked": { + "message": "Device recognition blocked", + "description": "Message for the option in the device recognition select field to block all device recognition attempts" }, - "cookiesOnThisSite": { - "message": "Cookies on this site", - "description": "Message for the cookie resources blocked panel" + "allFingerprintingAllowed": { + "message": "All device recognition allowed", + "description": "Message for the option in the device recognition select field to allow all device recognition attempts" }, "deviceRecognitionAttempts": { "message": "Device recognition attempts", @@ -111,49 +103,21 @@ "message": "Allowed scripts", "description": "Message for the script resources allowed" }, - "allowAll": { - "message": "Allow all", - "description": "Message for the resources blocked *allow all* option" - }, - "allow": { - "message": "Allow", - "description": "Message for the resources blocked *allow* option" - }, - "allowed": { - "message": "Allowed", - "description": "Message for the resources blocked *allowed* option" - }, "blockAll": { "message": "Block all", "description": "Message for the resources blocked *block all* option" }, + "allowAll": { + "message": "Allow all", + "description": "Message for the resources blocked *allow all* option" + }, "block": { "message": "Block", "description": "Message for the resources blocked *block* option" }, - "blocked": { - "message": "Blocked", - "description": "Message for the resources blocked *blocked* option" - }, - "apply": { - "message": "Apply", - "description": "Message for the button inside dynamic list of resources blocked" - }, - "applyOnce": { - "message": "Apply once", - "description": "Message for the dropdown option inside dynamic list of resources blocked to *apply once*" - }, - "applyUntilRestart": { - "message": "Apply until restart", - "description": "Message for the dropdown option inside dynamic list of resources blocked to *apply until restart*" - }, - "alwaysApply": { - "message": "Always apply", - "description": "Message for the dropdown option inside dynamic list of resources blocked to *always apply*" - }, - "undo": { - "message": "Undo", - "description": "Message for the resources blocked *undo* option" + "allow": { + "message": "Allow", + "description": "Message for the resources blocked *allow* option" }, "cancel": { "message": "Cancel", @@ -162,5 +126,13 @@ "goBack": { "message": "Go back", "description": "Message for the button inside the static list of resources blocked to go back from the current screen" + }, + "applyOnce": { + "message": "Apply once", + "description": "Message for action in dynamic list of resources blocked to *apply once*" + }, + "changeDefaults": { + "message": "Change global shield defaults", + "description": "Message for the button action linking to the settings page" } } diff --git a/components/brave_extension/extension/brave_extension/actions/shieldsPanelActions.ts b/components/brave_extension/extension/brave_extension/actions/shieldsPanelActions.ts index 99546feef9b2..c0305bce38f7 100644 --- a/components/brave_extension/extension/brave_extension/actions/shieldsPanelActions.ts +++ b/components/brave_extension/extension/brave_extension/actions/shieldsPanelActions.ts @@ -82,10 +82,9 @@ export const changeNoScriptSettings: actions.ChangeNoScriptSettings = (origin) = } } -export const changeAllNoScriptSettings: actions.ChangeAllNoScriptSettings = (origin, shouldBlock) => { +export const changeAllNoScriptSettings: actions.ChangeAllNoScriptSettings = (shouldBlock) => { return { type: types.CHANGE_ALL_NO_SCRIPT_SETTINGS, - origin, shouldBlock } } diff --git a/components/brave_extension/extension/brave_extension/background/api/cosmeticFilterAPI.ts b/components/brave_extension/extension/brave_extension/background/api/cosmeticFilterAPI.ts index a8905f6f4757..30dfd653893d 100644 --- a/components/brave_extension/extension/brave_extension/background/api/cosmeticFilterAPI.ts +++ b/components/brave_extension/extension/brave_extension/background/api/cosmeticFilterAPI.ts @@ -22,13 +22,15 @@ export const applySiteFilters = (hostname: string) => { chrome.storage.local.get('cosmeticFilterList', (storeData = {}) => { if (!storeData.cosmeticFilterList) { if (process.env.NODE_ENV === 'shields_development') { - console.info('applySiteFilters: no cosmetic filter store yet') + console.log('applySiteFilters: no cosmetic filter store yet') } return } if (storeData.cosmeticFilterList[hostname] !== undefined) { storeData.cosmeticFilterList[hostname].map((rule: string) => { - console.log('applying rule', rule) + if (process.env.NODE_ENV === 'shields_development') { + console.log('applying rule', rule) + } chrome.tabs.insertCSS({ code: `${rule} {display: none;}`, runAt: 'document_start' diff --git a/components/brave_extension/extension/brave_extension/background/api/localeAPI.ts b/components/brave_extension/extension/brave_extension/background/api/localeAPI.ts index 6f68f70a50ea..5d2cea906087 100644 --- a/components/brave_extension/extension/brave_extension/background/api/localeAPI.ts +++ b/components/brave_extension/extension/brave_extension/background/api/localeAPI.ts @@ -6,7 +6,7 @@ * Gets the locale message specified in messages.json * @param {string} message - The locale string */ -export const getMessage = (message: string): string => { +export const getLocale = (message: string): string => { if (chrome.i18n) { return chrome.i18n.getMessage(message) } diff --git a/components/brave_extension/extension/brave_extension/background/reducers/shieldsPanelReducer.ts b/components/brave_extension/extension/brave_extension/background/reducers/shieldsPanelReducer.ts index e28ff36373c3..76f13ba97317 100644 --- a/components/brave_extension/extension/brave_extension/background/reducers/shieldsPanelReducer.ts +++ b/components/brave_extension/extension/brave_extension/background/reducers/shieldsPanelReducer.ts @@ -305,7 +305,7 @@ export default function shieldsPanelReducer (state: State = { tabs: {}, windows: } case shieldsPanelTypes.CHANGE_ALL_NO_SCRIPT_SETTINGS: { const tabId: number = shieldsPanelState.getActiveTabId(state) - state = shieldsPanelState.changeAllNoScriptSettings(state, tabId, action.origin, action.shouldBlock) + state = shieldsPanelState.changeAllNoScriptSettings(state, tabId, action.shouldBlock) break } } diff --git a/components/brave_extension/extension/brave_extension/braveShieldsPanel.html b/components/brave_extension/extension/brave_extension/braveShieldsPanel.html index 1678474edb85..75beeec7aeaf 100644 --- a/components/brave_extension/extension/brave_extension/braveShieldsPanel.html +++ b/components/brave_extension/extension/brave_extension/braveShieldsPanel.html @@ -7,7 +7,7 @@ Brave Shields Panel diff --git a/components/brave_extension/extension/brave_extension/components/braveShields.tsx b/components/brave_extension/extension/brave_extension/components/braveShields.tsx new file mode 100644 index 000000000000..bc043f05fb40 --- /dev/null +++ b/components/brave_extension/extension/brave_extension/components/braveShields.tsx @@ -0,0 +1,149 @@ +/* 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/. */ + +import * as React from 'react' + +// CSS normalizer +import 'emptykit.css' + +// Feature-specific components +import { ShieldsPanel } from 'brave-ui/features/shields' + +// Components group +import Header from './header' +import InterfaceControls from './interfaceControls' +import PrivacyControls from './privacyControls' +import Footer from './footer' + +// Types +import { Tab } from '../types/state/shieldsPannelState' +import { isShieldsEnabled, getFavicon } from '../helpers/shieldsUtils' +import { + ShieldsToggled, + BlockAdsTrackers, + HttpsEverywhereToggled, + BlockJavaScript, + BlockFingerprinting, + BlockCookies, + AllowScriptOriginsOnce, + ChangeNoScriptSettings, + ChangeAllNoScriptSettings +} from '../types/actions/shieldsPanelActions' + +interface Props { + actions: { + shieldsToggled: ShieldsToggled + blockAdsTrackers: BlockAdsTrackers + httpsEverywhereToggled: HttpsEverywhereToggled + blockJavaScript: BlockJavaScript + blockFingerprinting: BlockFingerprinting + blockCookies: BlockCookies + allowScriptOriginsOnce: AllowScriptOriginsOnce + changeNoScriptSettings: ChangeNoScriptSettings + changeAllNoScriptSettings: ChangeAllNoScriptSettings + } + shieldsPanelTabData: Tab +} + +interface State { + isBlockedListOpen: boolean +} + +export default class Shields extends React.PureComponent { + constructor (props: Props) { + super(props) + this.state = { isBlockedListOpen: false } + } + + get favicon (): string { + const { url } = this.props.shieldsPanelTabData + return getFavicon(url) + } + + get isShieldsEnabled (): boolean { + const { braveShields } = this.props.shieldsPanelTabData + return isShieldsEnabled(braveShields) + } + + setBlockedListOpen = () => { + this.setState({ isBlockedListOpen: !this.state.isBlockedListOpen }) + } + + render () { + const { shieldsPanelTabData, actions } = this.props + const { isBlockedListOpen } = this.state + + if (!shieldsPanelTabData) { + return null + } + + return ( + +
+ { + this.isShieldsEnabled && ( + <> + + + + ) + } +