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

Commit

Permalink
Clear recently closed when clearing browsing history
Browse files Browse the repository at this point in the history
Auditors: @aekeus

Fix #3287
  • Loading branch information
bbondy committed Aug 22, 2016
1 parent ca88fc8 commit 6a87879
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports.saveAppState = (payload, isShutdown) => {
/**
* Cleans session data from unwanted values.
*/
module.exports.cleanPerWindowData = (perWindowData) => {
module.exports.cleanPerWindowData = (perWindowData, isShutdown) => {
if (!perWindowData) {
perWindowData = {}
}
Expand Down Expand Up @@ -195,6 +195,10 @@ module.exports.cleanPerWindowData = (perWindowData) => {
}
}
}
const clearHistory = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_HISTORY) === true
if (clearHistory) {
perWindowData.closedFrames = []
}

// 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 @@ -233,7 +237,8 @@ module.exports.cleanAppData = (data, isShutdown) => {
// Get rid of them here.
delete data.windows
if (data.perWindowState) {
data.perWindowState.forEach(module.exports.cleanPerWindowData)
data.perWindowState.forEach((perWindowState) =>
module.exports.cleanPerWindowData(perWindowState, isShutdown))
}
// Delete expired Flash approvals
let now = Date.now()
Expand Down
9 changes: 9 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ const windowActions = {
})
},

/**
* Dispatches a message to the store to clear closed frames
*/
clearClosedFrames: function () {
dispatch({
actionType: WindowConstants.WINDOW_CLEAR_CLOSED_FRAMES
})
},

/**
* Dispatches a message to the store to set a new frame as the active frame.
*
Expand Down
1 change: 1 addition & 0 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const messages = {
RESPONSE_WINDOW_STATE: _,
LAST_WINDOW_STATE: _,
UNDO_CLOSED_WINDOW: _,
CLEAR_CLOSED_FRAMES: _,
// Menu rebuilding
REQUEST_MENU_DATA_FOR_WINDOW: _,
RESPONSE_MENU_DATA_FOR_WINDOW: _,
Expand Down
1 change: 1 addition & 0 deletions js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const windowConstants = {
WINDOW_SET_NAVIGATED: _,
WINDOW_SET_URL_BAR_ACTIVE: _, // whether the URL bar is being typed in
WINDOW_UNDO_CLOSED_FRAME: _,
WINDOW_CLEAR_CLOSED_FRAMES: _,
WINDOW_SET_ACTIVE_FRAME_SHORTCUT: _,
WINDOW_SET_URL_BAR_SELECTED: _,
WINDOW_SET_SEARCH_DETAIL: _,
Expand Down
8 changes: 7 additions & 1 deletion js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const ipc = electron.ipcRenderer
const webFrame = electron.webFrame
const windowStore = require('./stores/windowStore')
const appStoreRenderer = require('./stores/appStoreRenderer')
const windowActions = require('./actions/windowActions')
const messages = require('./constants/messages')
const Immutable = require('immutable')
const patch = require('immutablepatch')
Expand Down Expand Up @@ -66,7 +67,8 @@ ipc.on(messages.REQUEST_MENU_DATA_FOR_WINDOW, () => {

if (process.env.NODE_ENV === 'test') {
window.appStoreRenderer = appStoreRenderer
window.windowActions = require('./actions/windowActions')
window.windowActions = windowActions
window.windowStore = windowStore
}

ipc.on(messages.APP_STATE_CHANGE, (e, action) => {
Expand All @@ -75,6 +77,10 @@ ipc.on(messages.APP_STATE_CHANGE, (e, action) => {
: appStoreRenderer.state = Immutable.fromJS(action.state)
})

ipc.on(messages.CLEAR_CLOSED_FRAMES, () => {
windowActions.clearClosedFrames()
})

window.addEventListener('beforeunload', function () {
ipc.send(messages.LAST_WINDOW_STATE, windowStore.getState().toJS())
})
Expand Down
2 changes: 2 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ const handleAppAction = (action) => {
case AppConstants.APP_CLEAR_DATA:
if (action.clearDataDetail.get('browserHistory')) {
handleAppAction({actionType: AppConstants.APP_CLEAR_SITES_WITHOUT_TAGS})
BrowserWindow.getAllWindows().forEach((wnd) => wnd.webContents.send(messages.CLEAR_CLOSED_FRAMES))
BrowserWindow.getAllWindows().forEach((wnd) => wnd.webContents.send(messages.REQUEST_MENU_DATA_FOR_WINDOW))
}
if (action.clearDataDetail.get('downloadHistory')) {
handleAppAction({actionType: AppConstants.APP_CLEAR_COMPLETED_DOWNLOADS})
Expand Down
3 changes: 3 additions & 0 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ const doAction = (action) => {
windowState = windowState.merge(FrameStateUtil.undoCloseFrame(windowState, windowState.get('closedFrames')))
focusWebview(activeFrameStatePath())
break
case WindowConstants.WINDOW_CLEAR_CLOSED_FRAMES:
windowState = windowState.set('closedFrames', new Immutable.List())
break
case WindowConstants.WINDOW_SET_ACTIVE_FRAME:
if (!action.frameProps) {
break
Expand Down
27 changes: 27 additions & 0 deletions test/components/clearBrowsingDataPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Brave = require('../lib/brave')
const {urlInput, clearBrowsingDataPanel} = require('../lib/selectors')
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
const messages = require('../../js/constants/messages')

describe('Clear Browsing Panel', function () {
function * setup (client) {
Expand Down Expand Up @@ -56,5 +57,31 @@ describe('Clear Browsing Panel', function () {
})
})
})
it('Clearing browsing history clears closedFrames', function * () {
const page1Url = Brave.server.url('page1.html')
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.tabByIndex(0)
.url(page1Url)
.windowByUrl(Brave.browserWindowUrl)
.ipcSend(messages.SHORTCUT_NEW_FRAME, page1Url)
.waitUntil(function () {
return this.getWindowState().then((val) => {
return val.value.frames.length === 2
})
})
.ipcSend(messages.SHORTCUT_CLOSE_FRAME)
.waitUntil(function () {
return this.getWindowState().then((val) => {
return val.value.closedFrames.length === 1
})
})
.clearAppData({browserHistory: true})
.waitUntil(function () {
return this.getWindowState().then((val) => {
return val.value.closedFrames.length === 0
})
})
})
})
})
17 changes: 17 additions & 0 deletions test/lib/brave.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ var exports = {
})
})

this.app.client.addCommand('getWindowState', function () {
return this.execute(function () {
return window.windowStore.state.toJS()
})
})

this.app.client.addCommand('showFindbar', function (show) {
return this.execute(function (show) {
window.windowActions.setFindbarShown(Object.assign({
Expand Down Expand Up @@ -269,6 +275,17 @@ var exports = {
}, key, value).then((response) => response.value)
})

/**
* Clears application data
*
* @param {object} clearDataDetail - the options to use for clearing
*/
this.app.client.addCommand('clearAppData', function (clearDataDetail) {
return this.execute(function (clearDataDetail) {
return require('../../../js/actions/appActions').clearAppData(clearDataDetail)
}, clearDataDetail).then((response) => response.value)
})

this.app.client.addCommand('getDefaultWindowHeight', function () {
return this.execute(function () {
let screen = require('electron').screen
Expand Down

0 comments on commit 6a87879

Please sign in to comment.