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

Fix isResourceEnabled private tab overlay #5812

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function registerForBeforeRequest (session, partition) {
}

for (let i = 0; i < beforeRequestFilteringFns.length; i++) {
let results = beforeRequestFilteringFns[i](details)
let results = beforeRequestFilteringFns[i](details, isPrivate)
const isAdBlock = results.resourceName === appConfig.resourceNames.ADBLOCK || appConfig[results.resourceName] && appConfig[results.resourceName].resourceType === adBlockResourceName
const isHttpsEverywhere = results.resourceName === appConfig.resourceNames.HTTPS_EVERYWHERE
const isTracker = results.resourceName === appConfig.resourceNames.TRACKING_PROTECTION
Expand Down Expand Up @@ -185,7 +185,8 @@ function registerForBeforeRequest (session, partition) {
* session.
* @param {object} session Session to add webRequest filtering on
*/
function registerForBeforeRedirect (session) {
function registerForBeforeRedirect (session, partition) {
const isPrivate = !partition.startsWith('persist:')
// Note that onBeforeRedirect listener doesn't take a callback
session.webRequest.onBeforeRedirect(function (details) {
// Using an electron binary which isn't from Brave
Expand All @@ -196,7 +197,7 @@ function registerForBeforeRedirect (session) {
// Note that since this isn't supposed to have a return value, the
// redirect filtering function must check whether the resource is
// enabled and do nothing if it's not.
beforeRedirectFilteringFns[i](details)
beforeRedirectFilteringFns[i](details, isPrivate)
}
})
}
Expand Down Expand Up @@ -244,7 +245,7 @@ function registerForBeforeSendHeaders (session, partition) {
}

for (let i = 0; i < beforeSendHeadersFilteringFns.length; i++) {
let results = beforeSendHeadersFilteringFns[i](details)
let results = beforeSendHeadersFilteringFns[i](details, isPrivate)
if (!module.exports.isResourceEnabled(results.resourceName, firstPartyUrl, isPrivate)) {
continue
}
Expand Down Expand Up @@ -401,20 +402,17 @@ function registerPermissionHandler (session, partition) {
}

const permissionName = permission + 'Permission'
let isAllowed
if (settings) {
let isAllowed = settings.get(permissionName)
if (typeof isAllowed === 'boolean') {
cb(isAllowed)
return
}
isAllowed = settings.get(permissionName)
}
// Private tabs inherit settings from normal tabs, but not vice versa.
if (isPrivate && tempSettings) {
let isAllowed = tempSettings.get(permissionName)
if (typeof isAllowed === 'boolean') {
cb(isAllowed)
return
}
isAllowed = tempSettings.get(permissionName)
}
if (typeof isAllowed === 'boolean') {
cb(isAllowed)
return
}

const message = locale.translation('permissionMessage').replace(/{{\s*host\s*}}/, origin).replace(/{{\s*permission\s*}}/, permissions[permission].action)
Expand Down Expand Up @@ -605,13 +603,13 @@ module.exports.isResourceEnabled = (resourceName, url, isPrivate) => {
}

const appState = appStore.getState()
let settings
if (!isPrivate) {
settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), url)
} else {
settings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), url)
const settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), url)
const tempSettings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), url)

let braverySettings = siteSettings.activeSettings(settings, appState, appConfig)
if (isPrivate && tempSettings) {
braverySettings = siteSettings.activeSettings(tempSettings, appState, appConfig)
}
const braverySettings = siteSettings.activeSettings(settings, appState, appConfig)

// If full shields are down never enable extra protection
if (braverySettings.shieldsUp === false) {
Expand Down
8 changes: 4 additions & 4 deletions app/httpsEverywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ function startHttpsEverywhere () {
Filtering.registerBeforeRedirectFilteringCB(onBeforeRedirect)
}

function onBeforeHTTPRequest (details) {
function onBeforeHTTPRequest (details, isPrivate) {
let result = { resourceName: module.exports.resourceName }

const mainFrameUrl = Filtering.getMainFrameUrl(details)
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl)) {
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl, isPrivate)) {
return result
}
// Ignore URLs that are not HTTP
Expand All @@ -137,9 +137,9 @@ function onBeforeHTTPRequest (details) {
return result
}

function onBeforeRedirect (details) {
function onBeforeRedirect (details, isPrivate) {
const mainFrameUrl = Filtering.getMainFrameUrl(details)
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl)) {
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl, isPrivate)) {
return
}
// Ignore URLs that are not HTTP
Expand Down
10 changes: 5 additions & 5 deletions app/siteHacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports.init = () => {
if (!appConfig[resourceName].enabled) {
return
}
Filtering.registerBeforeSendHeadersFilteringCB((details) => {
Filtering.registerBeforeSendHeadersFilteringCB((details, isPrivate) => {
if (details.resourceType !== 'mainFrame') {
return {
resourceName
Expand All @@ -31,7 +31,7 @@ module.exports.init = () => {
const result = hack.onBeforeSendHeaders.call(this, details)
if (result && result.customCookie) {
customCookie = result.customCookie
} else if (Filtering.isResourceEnabled(appConfig.resourceNames.NOSCRIPT, 'https://twitter.com/') &&
} else if (Filtering.isResourceEnabled(appConfig.resourceNames.NOSCRIPT, 'https://twitter.com/', isPrivate) &&
result && result.cancel) {
// cancel is only called on Twitter where noscript is enabled
cancel = true
Expand All @@ -43,7 +43,7 @@ module.exports.init = () => {
cancel
}
})
Filtering.registerBeforeRequestFilteringCB((details) => {
Filtering.registerBeforeRequestFilteringCB((details, isPrivate) => {
let domain = URL.parse(details.url).hostname
let hack = siteHacks[domain]

Expand All @@ -58,8 +58,8 @@ module.exports.init = () => {
}
if (hack && hack.onBeforeRequest &&
(hack.enableForAll ||
hack.enableForAdblock && Filtering.isResourceEnabled(appConfig.resourceNames.ADBLOCK, mainFrameUrl) ||
hack.enableForTrackingProtection && Filtering.isResourceEnabled(appConfig.resourceNames.TRACKING_PROTECTION, mainFrameUrl))) {
hack.enableForAdblock && Filtering.isResourceEnabled(appConfig.resourceNames.ADBLOCK, mainFrameUrl, isPrivate) ||
hack.enableForTrackingProtection && Filtering.isResourceEnabled(appConfig.resourceNames.TRACKING_PROTECTION, mainFrameUrl, isPrivate))) {
const result = hack.onBeforeRequest.call(this, details)
if (result && result.redirectURL) {
redirectURL = result.redirectURL
Expand Down
2 changes: 1 addition & 1 deletion js/components/braveryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class BraveryPanel extends ImmutableComponent {
braverySelectTitle: true,
disabled: !shieldsUp
})} data-l10n-id='adControl' />
<select className='form-control' value={adControl} onChange={this.onToggleAdControl} disabled={!shieldsUp}>
<select className='adsBlockedControl form-control' value={adControl} onChange={this.onToggleAdControl} disabled={!shieldsUp}>
<option data-l10n-id='showBraveAds' value='showBraveAds' />
<option data-l10n-id='blockAds' value='blockAds' />
<option data-l10n-id='allowAdsAndTracking' value='allowAdsAndTracking' />
Expand Down
Loading