diff --git a/app/filtering.js b/app/filtering.js index 3e4ab069738..63474d46002 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -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 @@ -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 @@ -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) } }) } @@ -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 } @@ -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) @@ -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) { diff --git a/app/httpsEverywhere.js b/app/httpsEverywhere.js index ecba6d22d26..02119e81c98 100644 --- a/app/httpsEverywhere.js +++ b/app/httpsEverywhere.js @@ -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 @@ -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 diff --git a/app/siteHacks.js b/app/siteHacks.js index 7dc46b76a92..24a0aa57305 100644 --- a/app/siteHacks.js +++ b/app/siteHacks.js @@ -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 @@ -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 @@ -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] @@ -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 diff --git a/js/components/braveryPanel.js b/js/components/braveryPanel.js index 94864e627c8..78cbd21c97c 100644 --- a/js/components/braveryPanel.js +++ b/js/components/braveryPanel.js @@ -287,7 +287,7 @@ class BraveryPanel extends ImmutableComponent { braverySelectTitle: true, disabled: !shieldsUp })} data-l10n-id='adControl' /> -