Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
disable shields for any protocol other than http or https
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jul 4, 2018
1 parent bdf4ea1 commit e5dabe1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/background/api/browserActionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})
}
Expand Down
4 changes: 3 additions & 1 deletion app/background/api/shieldsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions app/components/braveShields/braveShields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class BraveShields extends React.Component<BraveShieldsProps, {}>
braveShields={shieldsPanelTabData.braveShields}
shieldsToggled={actions.shieldsToggled}
hostname={shieldsPanelTabData.hostname}
origin={shieldsPanelTabData.origin}
/>
<BraveShieldsStats
braveShields={shieldsPanelTabData.braveShields}
Expand Down
3 changes: 0 additions & 3 deletions app/components/braveShields/braveShieldsControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export default class BraveShieldsControls extends React.Component<BraveShieldsCo

<Grid theme={theme.braveShieldsControlsSwitches}>
<Column>
{/* TODO @cezaraugusto */}
<SwitchButton
id='httpsEverywhere'
theme={theme.noUserSelect}
Expand All @@ -145,7 +144,6 @@ export default class BraveShieldsControls extends React.Component<BraveShieldsCo
/>
</Column>
<Column>
{/* TODO @cezaraugusto */}
<SwitchButton
id='blockScripts'
theme={theme.noUserSelect}
Expand All @@ -156,7 +154,6 @@ export default class BraveShieldsControls extends React.Component<BraveShieldsCo
/>
</Column>
<Column>
{/* TODO @cezaraugusto */}
<SwitchButton
id='blockPhishingMalware'
theme={theme.noUserSelect}
Expand Down
6 changes: 6 additions & 0 deletions app/components/braveShields/braveShieldsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import * as shieldActions from '../../types/actions/shieldsPanelActions'
import { BlockOptions } from '../../types/other/blockTypes'
import { getMessage } from '../../background/api/localeAPI'
import theme from '../../theme'
import { isHttpOrHttps } from '../../helpers/urlUtils'

export interface BraveShieldsHeaderProps {
shieldsToggled: shieldActions.ShieldsToggled
origin: string
hostname: string
braveShields: BlockOptions
}
Expand All @@ -27,6 +29,10 @@ export default class BraveShieldsHeader extends React.PureComponent<BraveShields
}

onToggleShields (e: HTMLSelectElement) {
const { origin } = this.props
if (!isHttpOrHttps(origin)) {
return
}
const shieldsOption: BlockOptions = e.target.checked ? 'allow' : 'block'
this.props.shieldsToggled(shieldsOption)
}
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/urlUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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/. */

export const isHttpOrHttps = (url?: string) => {
if (!url) {
return false
}
return /^https?:/i.test(url)
}

0 comments on commit e5dabe1

Please sign in to comment.