From e5dabe14dabe546ea3a29ac22d2cf9ec27aaee49 Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Tue, 3 Jul 2018 21:04:36 -0300 Subject: [PATCH] disable shields for any protocol other than http or https - fix https://github.com/brave/brave-browser/issues/169 --- app/background/api/browserActionAPI.ts | 5 +++-- app/background/api/shieldsAPI.ts | 4 +++- app/components/braveShields/braveShields.tsx | 1 + app/components/braveShields/braveShieldsControls.tsx | 3 --- app/components/braveShields/braveShieldsHeader.tsx | 6 ++++++ app/helpers/urlUtils.ts | 10 ++++++++++ 6 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 app/helpers/urlUtils.ts diff --git a/app/background/api/browserActionAPI.ts b/app/background/api/browserActionAPI.ts index 43f354b..4d05937 100644 --- a/app/background/api/browserActionAPI.ts +++ b/app/background/api/browserActionAPI.ts @@ -2,6 +2,8 @@ * 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 { isHttpOrHttps } from '../../helpers/urlUtils' + /** * Sets the badge text * @param {string} text - The text to put on the badge @@ -18,11 +20,10 @@ export const setBadgeText = (text: string) => { export const setIcon = (url: string, tabId: number, shieldsOn: boolean) => { const shieldsEnabledIcon = 'img/icon-16.png' const shieldsDisabledIcon = 'img/icon-16-disabled.png' - const isHttpOrHttps = url && /^http/.test(url) if (chrome.browserAction) { chrome.browserAction.setIcon({ - path: shieldsOn && isHttpOrHttps ? shieldsEnabledIcon : shieldsDisabledIcon, + path: shieldsOn && isHttpOrHttps(url) ? shieldsEnabledIcon : shieldsDisabledIcon, tabId }) } diff --git a/app/background/api/shieldsAPI.ts b/app/background/api/shieldsAPI.ts index d7845b6..86b1dbc 100644 --- a/app/background/api/shieldsAPI.ts +++ b/app/background/api/shieldsAPI.ts @@ -5,6 +5,7 @@ import { Tab } from '../../types/state/shieldsPannelState' import { BlockOptions } from '../../types/other/blockTypes' import * as resourceIdentifiers from '../../constants/resourceIdentifiers' +import { isHttpOrHttps } from '../../helpers/urlUtils' /** * Obtains the shields panel data for the specified tab data @@ -33,12 +34,13 @@ export const getShieldSettingsForTabData = (tabData?: chrome.tabs.Tab) => { ]).then((details) => { const fingerprinting = details[5].setting !== details[6].setting ? 'block_third_party' : details[5].setting const cookies = details[7].setting !== details[8].setting ? 'block_third_party' : details[7].setting + const braveShields = isHttpOrHttps(origin) ? details[0].setting : 'block' return { url: url.href, origin, hostname, id: tabData.id, - braveShields: details[0].setting, + braveShields, ads: details[1].setting, trackers: details[2].setting, httpUpgradableResources: details[3].setting, diff --git a/app/components/braveShields/braveShields.tsx b/app/components/braveShields/braveShields.tsx index 9073aaa..10add9e 100644 --- a/app/components/braveShields/braveShields.tsx +++ b/app/components/braveShields/braveShields.tsx @@ -39,6 +39,7 @@ export default class BraveShields extends React.Component braveShields={shieldsPanelTabData.braveShields} shieldsToggled={actions.shieldsToggled} hostname={shieldsPanelTabData.hostname} + origin={shieldsPanelTabData.origin} /> - {/* TODO @cezaraugusto */} - {/* TODO @cezaraugusto */} - {/* TODO @cezaraugusto */} { + if (!url) { + return false + } + return /^https?:/i.test(url) +}