This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Using temporarySiteSettings to store private tab preferences #4469
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ const {cookieExceptions, localStorageExceptions} = require('../data/siteHacks') | |
const {passwordManagers, defaultPasswordManager} = require('../constants/passwordManagers') | ||
const urlParse = require('url').parse | ||
const siteSettings = require('./siteSettings') | ||
const { registerUserPrefs } = require('./userPrefs') | ||
const { setUserPref } = require('./userPrefs') | ||
const { getSetting } = require('../settings') | ||
|
||
// backward compatibility with appState siteSettings | ||
|
@@ -79,10 +79,59 @@ const getBlock3rdPartyStorage = (braveryDefaults) => { | |
} | ||
} | ||
|
||
const getContentSettingsFromSiteSettings = (appState) => { | ||
const hostSettingsToContentSettings = (hostSettings, contentSettingsSource) => { | ||
let contentSettings = contentSettingsSource | ||
// We do 2 passes for setting content settings. On the first pass we consider all shield types. | ||
for (let hostPattern in hostSettings) { | ||
let hostSetting = hostSettings[hostPattern] | ||
if (['number', 'boolean'].includes(typeof hostSetting.noScript)) { | ||
addContentSettings(contentSettings.javascript, hostPattern, '*', | ||
hostSetting.noScript === true ? 'block' : 'allow') | ||
} | ||
if (typeof hostSetting.runInsecureContent === 'boolean') { | ||
addContentSettings(contentSettings.runInsecureContent, hostPattern, '*', | ||
hostSetting.runInsecureContent ? 'allow' : 'block') | ||
} | ||
if (hostSetting.cookieControl) { | ||
if (hostSetting.cookieControl === 'block3rdPartyCookie') { | ||
addContentSettings(contentSettings.cookies, hostPattern, '*', 'block') | ||
addContentSettings(contentSettings.cookies, hostPattern, parseSiteSettingsPattern(hostPattern), 'allow') | ||
addContentSettings(contentSettings.referer, hostPattern, '*', 'block') | ||
cookieExceptions.forEach((exceptionPair) => | ||
addContentSettings(contentSettings.cookies, exceptionPair[0], exceptionPair[1], 'allow')) | ||
} else { | ||
addContentSettings(contentSettings.cookies, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.referer, hostPattern, '*', 'allow') | ||
} | ||
} | ||
if (typeof hostSetting.fingerprintingProtection === 'boolean') { | ||
addContentSettings(contentSettings.canvasFingerprinting, hostPattern, '*', hostSetting.fingerprintingProtection ? 'block' : 'allow') | ||
} | ||
if (hostSetting.adControl) { | ||
addContentSettings(contentSettings.adInsertion, hostPattern, '*', hostSetting.adControl === 'showBraveAds' ? 'allow' : 'block') | ||
} | ||
if (typeof hostSetting.flash === 'number') { | ||
addContentSettings(contentSettings.flashActive, hostPattern, '*', 'allow') | ||
} | ||
} | ||
// On the second pass we consider only shieldsUp === false settings since we want those to take precedence. | ||
for (let hostPattern in hostSettings) { | ||
let hostSetting = hostSettings[hostPattern] | ||
if (hostSetting.shieldsUp === false) { | ||
addContentSettings(contentSettings.cookies, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.canvasFingerprinting, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.adInsertion, hostPattern, '*', 'block') | ||
addContentSettings(contentSettings.javascript, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.referer, hostPattern, '*', 'allow') | ||
} | ||
} | ||
return contentSettings | ||
} | ||
|
||
const getContentSettingsFromSiteSettings = (appState, isPrivate = false) => { | ||
let braveryDefaults = siteSettings.braveryDefaults(appState, appConfig) | ||
|
||
let contentSettings = { | ||
const contentSettings = { | ||
cookies: getBlock3rdPartyStorage(braveryDefaults), | ||
referer: [{ | ||
setting: braveryDefaults.cookieControl === 'block3rdPartyCookie' ? 'block' : 'allow', | ||
|
@@ -126,85 +175,51 @@ const getContentSettingsFromSiteSettings = (appState) => { | |
}] | ||
} | ||
|
||
let hostSettings = appState.get('siteSettings').toJS() | ||
// We do 2 passes for setting content settings. On the first pass we consider all shield types. | ||
for (let hostPattern in hostSettings) { | ||
let hostSetting = hostSettings[hostPattern] | ||
if (['number', 'boolean'].includes(typeof hostSetting.noScript)) { | ||
addContentSettings(contentSettings.javascript, hostPattern, '*', | ||
hostSetting.noScript === true ? 'block' : 'allow') | ||
} | ||
if (typeof hostSetting.runInsecureContent === 'boolean') { | ||
addContentSettings(contentSettings.runInsecureContent, hostPattern, '*', | ||
hostSetting.runInsecureContent ? 'allow' : 'block') | ||
} | ||
if (hostSetting.cookieControl) { | ||
if (hostSetting.cookieControl === 'block3rdPartyCookie') { | ||
addContentSettings(contentSettings.cookies, hostPattern, '*', 'block') | ||
addContentSettings(contentSettings.cookies, hostPattern, parseSiteSettingsPattern(hostPattern), 'allow') | ||
addContentSettings(contentSettings.referer, hostPattern, '*', 'block') | ||
cookieExceptions.forEach((exceptionPair) => | ||
addContentSettings(contentSettings.cookies, exceptionPair[0], exceptionPair[1], 'allow')) | ||
} else { | ||
addContentSettings(contentSettings.cookies, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.referer, hostPattern, '*', 'allow') | ||
} | ||
} | ||
if (typeof hostSetting.fingerprintingProtection === 'boolean') { | ||
addContentSettings(contentSettings.canvasFingerprinting, hostPattern, '*', hostSetting.fingerprintingProtection ? 'block' : 'allow') | ||
} | ||
if (hostSetting.adControl) { | ||
addContentSettings(contentSettings.adInsertion, hostPattern, '*', hostSetting.adControl === 'showBraveAds' ? 'allow' : 'block') | ||
} | ||
if (typeof hostSetting.flash === 'number') { | ||
addContentSettings(contentSettings.flashActive, hostPattern, '*', 'allow') | ||
} | ||
} | ||
// On the second pass we consider only shieldsUp === false settings since we want those to take precedence. | ||
for (let hostPattern in hostSettings) { | ||
let hostSetting = hostSettings[hostPattern] | ||
if (hostSetting.shieldsUp === false) { | ||
addContentSettings(contentSettings.cookies, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.canvasFingerprinting, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.adInsertion, hostPattern, '*', 'block') | ||
addContentSettings(contentSettings.javascript, hostPattern, '*', 'allow') | ||
addContentSettings(contentSettings.referer, hostPattern, '*', 'allow') | ||
} | ||
const regularSettings = hostSettingsToContentSettings(appState.get('siteSettings').toJS(), contentSettings) | ||
if (isPrivate) { | ||
const privateSettings = | ||
hostSettingsToContentSettings(appState.get('siteSettings').merge(appState.get('temporarySiteSettings')).toJS(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/merge/mergeDeep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry I missed this earlier, but the deep merge is not required or desirable. The overlay pref store already handles this correctly if you set the regular settings for the regular profile and only the private settings for the private profile There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
contentSettings) | ||
return { content_settings: privateSettings } | ||
} | ||
|
||
return { content_settings: contentSettings } | ||
return { content_settings: regularSettings } | ||
} | ||
|
||
let updateTrigger | ||
|
||
// Register callback to handle all updates | ||
const doAction = (action) => { | ||
switch (action.actionType) { | ||
case AppConstants.APP_CHANGE_SITE_SETTING: | ||
AppDispatcher.waitFor([AppStore.dispatchToken], () => { | ||
updateTrigger('content_settings', action.temporary) | ||
if (action.temporary) { | ||
setUserPref('content_settings', getContentSettingsFromSiteSettings(AppStore.getState(), true).content_settings, true) | ||
} else { | ||
setUserPref('content_settings', getContentSettingsFromSiteSettings(AppStore.getState()).content_settings) | ||
} | ||
}) | ||
break | ||
case AppConstants.APP_REMOVE_SITE_SETTING: | ||
AppDispatcher.waitFor([AppStore.dispatchToken], () => { | ||
updateTrigger('content_settings', action.temporary) | ||
if (action.temporary) { | ||
setUserPref('content_settings', getContentSettingsFromSiteSettings(AppStore.getState(), true).content_settings, true) | ||
} else { | ||
setUserPref('content_settings', getContentSettingsFromSiteSettings(AppStore.getState()).content_settings) | ||
} | ||
}) | ||
break | ||
case AppConstants.APP_SET_RESOURCE_ENABLED: | ||
AppDispatcher.waitFor([AppStore.dispatchToken], () => { | ||
updateTrigger() | ||
setUserPref('content_settings', getContentSettingsFromSiteSettings(AppStore.getState()).content_settings) | ||
}) | ||
break | ||
case AppConstants.APP_CHANGE_SETTING: | ||
AppDispatcher.waitFor([AppStore.dispatchToken], () => { | ||
updateTrigger() | ||
setUserPref('content_settings', getContentSettingsFromSiteSettings(AppStore.getState()).content_settings) | ||
}) | ||
break | ||
default: | ||
} | ||
} | ||
|
||
module.exports.init = () => { | ||
updateTrigger = registerUserPrefs(() => getContentSettingsFromSiteSettings(AppStore.getState())) | ||
AppDispatcher.register(doAction) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to be careful here that the
allSiteSettings
frame property is consistent with what is being sent injs/state/contentSettings.js
and alsoregisterPermissionHandler
inapp/filtering.js
. the expected behavior is that private context inheirit settings from regular contexts but not vice-versa, so I think what you want here is a merge oftemporarySiteSettings
andsiteSettings
for private frames.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address in 7de0c05.