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

Commit

Permalink
Add option to clear site settings
Browse files Browse the repository at this point in the history
Fix #4174

Auditors: @bbondy

Test plan:
1. go to apple.com, turn on block scripts
2. go to about:preferences#security, select 'Clear saved site settings'
3. restart brave, verify that scripts are allowed on apple.com
  • Loading branch information
diracdeltas committed Oct 3, 2016
1 parent b27f6ad commit 8ea8ff0
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ savedPasswords=Saved passwords
allSiteCookies=All site cookies
autofillData=Autofill data
autocompleteData=Autocomplete data
savedSiteSettings=Saved site settings and permissions
clear=Clear
clearDataWarning=Warning: Selected data, back to the day you installed Brave will be cleared and cannot be undone.
clearBrowsingData=Clear browsing data
Expand Down
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ cachedImagesAndFiles=Cached images and files
allSiteCookies=All site cookies
autofillData=Autofill data
autocompleteData=Autocomplete data
savedSiteSettings=Saved site settings and permissions
passwordsAndForms=Passwords and Forms
tabSettings=Tab Settings
clearBrowsingDataNow=Clear Browsing Data Now…
Expand Down
20 changes: 12 additions & 8 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,6 @@ module.exports.cleanPerWindowData = (perWindowData, isShutdown) => {
if (clearHistory) {
perWindowData.closedFrames = []
}
const clearAutocompleteData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA) === true
if (clearAutocompleteData) {
filtering.clearAutocompleteData()
}
const clearAutofillData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOFILL_DATA) === true
if (clearAutofillData) {
filtering.clearAutofillData()
}

// Clean closed frame data before frames because the keys are re-ordered
// and the new next key is calculated in windowStore.js based on
Expand Down Expand Up @@ -248,6 +240,18 @@ module.exports.cleanAppData = (data, isShutdown) => {
data.perWindowState.forEach((perWindowState) =>
module.exports.cleanPerWindowData(perWindowState, isShutdown))
}
const clearAutocompleteData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA) === true
if (clearAutocompleteData) {
filtering.clearAutocompleteData()
}
const clearAutofillData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOFILL_DATA) === true
if (clearAutofillData) {
filtering.clearAutofillData()
}
const clearSiteSettings = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_SITE_SETTINGS) === true
if (clearSiteSettings) {
data.siteSettings = {}
}
// Delete expired Flash and NoScript allow-once approvals
let now = Date.now()
for (var host in data.siteSettings) {
Expand Down
1 change: 1 addition & 0 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ class SecurityTab extends ImmutableComponent {
<SettingCheckbox dataL10nId='allSiteCookies' prefKey={settings.SHUTDOWN_CLEAR_ALL_SITE_COOKIES} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='autocompleteData' prefKey={settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='autofillData' prefKey={settings.SHUTDOWN_CLEAR_AUTOFILL_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='savedSiteSettings' prefKey={settings.SHUTDOWN_CLEAR_SITE_SETTINGS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<Button l10nId='clearBrowsingDataNow' className='primaryButton clearBrowsingDataButton' onClick={this.clearBrowsingDataNow} />
</SettingsList>
<div className='sectionTitle' data-l10n-id='passwordsAndForms' />
Expand Down
2 changes: 2 additions & 0 deletions js/components/clearBrowsingDataPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
this.onToggleAllSiteCookies = this.onToggleSetting.bind(this, 'allSiteCookies')
this.onToggleAutocompleteData = this.onToggleSetting.bind(this, 'autocompleteData')
this.onToggleAutofillData = this.onToggleSetting.bind(this, 'autofillData')
this.onToggleSavedSiteSettings = this.onToggleSetting.bind(this, 'savedSiteSettings')
this.onClear = this.onClear.bind(this)
}
onToggleSetting (setting, e) {
Expand All @@ -48,6 +49,7 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
<SwitchControl rightl10nId='allSiteCookies' checkedOn={this.props.clearBrowsingDataDetail.get('allSiteCookies')} onClick={this.onToggleAllSiteCookies} />
<SwitchControl className='autocompleteDataSwitch' rightl10nId='autocompleteData' checkedOn={this.props.clearBrowsingDataDetail.get('autocompleteData')} onClick={this.onToggleAutocompleteData} />
<SwitchControl className='autofillDataSwitch' rightl10nId='autofillData' checkedOn={this.props.clearBrowsingDataDetail.get('autofillData')} onClick={this.onToggleAutofillData} />
<SwitchControl className='siteSettingsSwitch' rightl10nId='savedSiteSettings' checkedOn={this.props.clearBrowsingDataDetail.get('savedSiteSettings')} onClick={this.onToggleSavedSiteSettings} />
</div>
<div className='formSection clearBrowsingDataButtons'>
<Button l10nId='cancel' className='secondaryAltButton' onClick={this.props.onHide} />
Expand Down
1 change: 1 addition & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const settings = {
SHUTDOWN_CLEAR_ALL_SITE_COOKIES: 'shutdown.clear-all-site-cookies',
SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA: 'shutdown.clear-autocomplete-data',
SHUTDOWN_CLEAR_AUTOFILL_DATA: 'shutdown.clear-autofill-data',
SHUTDOWN_CLEAR_SITE_SETTINGS: 'shutdown.clear-site-settings',
// Autofill
AUTOFILL_ENABLED: 'privacy.autofill-enabled',
// Security Tab: DEPRECATED but still required (for now)
Expand Down
4 changes: 4 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ const handleAppAction = (action) => {
const Filtering = require('../../app/filtering')
Filtering.clearAutofillData()
}
if (action.clearDataDetail.get('savedSiteSettings')) {
appState = appState.set('siteSettings', Immutable.Map())
appState = appState.set('temporarySiteSettings', Immutable.Map())
}
break
case AppConstants.APP_IMPORT_BROWSER_DATA:
{
Expand Down
58 changes: 57 additions & 1 deletion test/components/clearBrowsingDataPanelTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, it, beforeEach */

const Brave = require('../lib/brave')
const {urlInput, clearBrowsingDataButton, securityTab} = require('../lib/selectors')
const {urlInput, braveMenu, noScriptSwitch, braveryPanel, notificationBar, clearBrowsingDataButton, securityTab} = require('../lib/selectors')
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
const messages = require('../../js/constants/messages')

Expand All @@ -15,6 +15,14 @@ describe('Clear Browsing Panel', function () {
.waitForVisible(urlInput)
}

function * openBraveMenu (client) {
return client
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(braveMenu)
.click(braveMenu)
.waitForVisible(braveryPanel)
}

describe('with history', function () {
Brave.beforeEach(this)
beforeEach(function * () {
Expand Down Expand Up @@ -101,4 +109,52 @@ describe('Clear Browsing Panel', function () {
})
})
})

describe('with site settings', function () {
Brave.beforeEach(this)
beforeEach(function * () {
this.notificationUrl = Brave.server.url('notification.html')
yield setup(this.app.client)
yield this.app.client
.tabByIndex(0)
.loadUrl(this.notificationUrl)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitForExist('[data-l10n-id=rememberDecision]')
.click('[data-l10n-id=rememberDecision]')
.waitForExist('button=Allow')
.click('button=Allow')
yield this.app.client
.tabByIndex(0)
.url('https://example.com')
yield openBraveMenu(this.app.client)
yield this.app.client
.click(noScriptSwitch)
.waitUntil(function () {
return this.getAppState().then((val) => {
return Object.keys(val.value.siteSettings).length === 2
})
})
})

it('clears site settings and permissions', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(getTargetAboutUrl('about:preferences'))
.waitForVisible(securityTab)
.click(securityTab)
.waitForVisible(clearBrowsingDataButton)
.click(clearBrowsingDataButton)
.waitForBrowserWindow()
.waitForVisible('.siteSettingsSwitch')
.click('.siteSettingsSwitch .switchBackground')
.waitForVisible('.clearDataButton')
.click('.clearDataButton')
.waitUntil(function () {
return this.getAppState().then((val) => {
return Object.keys(val.value.siteSettings).length === 0
})
})
})
})
})

1 comment on commit 8ea8ff0

@bbondy
Copy link
Member

@bbondy bbondy commented on 8ea8ff0 Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ very helpful

Please sign in to comment.