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

Commit

Permalink
fix methods that used api calls removed in brave/muon@aed5f65
Browse files Browse the repository at this point in the history
ensure settings are updated for all partitions
auditors @bbondy
  • Loading branch information
bridiver committed Dec 18, 2016
1 parent fbb1647 commit daa7743
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions app/extensions/brave/content/scripts/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ chrome.webFrame.setGlobal("navigator.credentials.store", function () {
chrome.webFrame.setGlobal("navigator.getBattery", function () {
return new Promise((resolve, reject) => { reject(new Error('navigator.getBattery not supported.')) })
})

if (chrome.contentSettings.doNotTrack == 'allow') {
executeScript("window.Navigator.prototype.__defineGetter__('doNotTrack', () => { return 1 })")
}
2 changes: 1 addition & 1 deletion app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ showBookmarkMatches=Show bookmark matches
showOpenedTabMatches=Show tab matches
offerSearchSuggestions=Autocomplete search term as you type
doNotTrackTitle=Do Not Track
doNotTrack=Send a 'Do Not Track' header with browsing requests (requires browser restart)
doNotTrack=Send a 'Do Not Track' header with browsing requests
blockCanvasFingerprinting=Fingerprinting Protection (may break some sites)
advancedSettings=Advanced Settings...
advancedSettingsTitle=Advanced Settings for Brave Payments
Expand Down
2 changes: 1 addition & 1 deletion js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ class AboutPreferences extends React.Component {
settings: this.state.settings.set(key, value)
})
aboutActions.changeSetting(key, value)
if (key === settings.DO_NOT_TRACK || key === settings.HARDWARE_ACCELERATION_ENABLED ||
if (key === settings.HARDWARE_ACCELERATION_ENABLED ||
key === settings.PDFJS_ENABLED || key === settings.TORRENT_VIEWER_ENABLED ||
key === settings.SMOOTH_SCROLL_ENABLED || key === settings.SEND_CRASH_REPORTS) {
ipc.send(messages.PREFS_RESTART, key, value)
Expand Down
5 changes: 0 additions & 5 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class Frame extends ImmutableComponent {
this.onFocus = this.onFocus.bind(this)
// Maps notification message to its callback
this.notificationCallbacks = {}
// Change to DNT requires restart
this.doNotTrack = getSetting(settings.DO_NOT_TRACK)
// Counter for detecting PDF URL redirect loops
this.reloadCounter = {}
}
Expand Down Expand Up @@ -744,9 +742,6 @@ class Frame extends ImmutableComponent {
runInsecureContent: false
})
}
if (this.doNotTrack) {
this.webview.executeJavaScript('Navigator.prototype.__defineGetter__("doNotTrack", () => {return 1});')
}
}

const loadEnd = (savePage) => {
Expand Down
20 changes: 15 additions & 5 deletions js/state/contentSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {cookieExceptions, localStorageExceptions} = require('../data/siteHacks')
const {defaultPasswordManager} = require('../constants/passwordManagers')
const urlParse = require('url').parse
const siteSettings = require('./siteSettings')
const { setUserPref } = require('./userPrefs')
const { registerUserPrefs } = require('./userPrefs')
const { getSetting } = require('../settings')

// backward compatibility with appState siteSettings
Expand Down Expand Up @@ -65,6 +65,10 @@ const getDefaultUserPrefContentSettings = (braveryDefaults, appSettings, appConf
setting: braveryDefaults.adControl === 'showBraveAds' ? 'allow' : 'block',
primaryPattern: '*'
}],
doNotTrack: [{
setting: getSetting(settings.DO_NOT_TRACK, appSettings) ? 'allow' : 'block',
primaryPattern: '*'
}],
passwordManager: getDefaultPasswordManagerSettings(braveryDefaults, appSettings, appConfig),
javascript: [{
setting: braveryDefaults.noScript ? 'block' : 'allow',
Expand Down Expand Up @@ -235,35 +239,41 @@ const updateContentSettings = (appState, appConfig, isPrivate = false) => {
const defaultUserPrefs = getDefaultUserPrefContentSettings(braveryDefaults, appState, appConfig)
const defaultHostContentSettings = getDefaultHostContentSettings(braveryDefaults, appState, appConfig)

setUserPref('content_settings', getSettingsFromSiteSettings(defaultUserPrefs, appState, appConfig, isPrivate), isPrivate)
hostContentSettings.setContentSettings(getSettingsFromSiteSettings(defaultHostContentSettings, appState, appConfig, isPrivate), isPrivate)
return { 'content_settings': getSettingsFromSiteSettings(defaultUserPrefs, appState, appConfig, isPrivate) }
}

let updateTrigger

// Register callback to handle all updates
const doAction = (action) => {
switch (action.actionType) {
case appConstants.APP_REMOVE_SITE_SETTING:
case appConstants.APP_CHANGE_SITE_SETTING:
AppDispatcher.waitFor([AppStore.dispatchToken], () => {
updateContentSettings(AppStore.getState(), appConfig, action.temporary)
updateTrigger(action.temporary)
})
break
case appConstants.APP_CHANGE_SETTING:
case appConstants.APP_SET_RESOURCE_ENABLED:
AppDispatcher.waitFor([AppStore.dispatchToken], () => {
updateContentSettings(AppStore.getState(), appConfig)
updateTrigger()
})
break
case appConstants.APP_ALLOW_FLASH_ONCE:
case appConstants.APP_ALLOW_FLASH_ALWAYS:
AppDispatcher.waitFor([AppStore.dispatchToken], () => {
updateContentSettings(AppStore.getState(), appConfig, action.isPrivate)
updateTrigger(action.isPrivate)
})
break
default:
}
}

module.exports.init = () => {
updateTrigger = registerUserPrefs((incognito) =>
updateContentSettings(AppStore.getState(), appConfig, incognito)
)

AppDispatcher.register(doAction)
}
4 changes: 2 additions & 2 deletions js/state/userPrefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const setUserPrefType = (ses, path, value) => {
}

const runCallback = (cb, name, incognito) => {
let prefs = cb()
let prefs = cb(incognito)

if (typeof prefs !== 'object') {
console.warn('userPrefs callback did not return an object:', prefs)
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports.init = (ses, partition, isPrivate) => {
registeredPrivateSessions[partition] = ses
}
registeredSessions[partition] = ses
registeredCallbacks.forEach((fn) => fn())
registeredCallbacks.forEach((fn) => fn(null, isPrivate))
}

module.exports.registerUserPrefs = (cb) => {
Expand Down

0 comments on commit daa7743

Please sign in to comment.