From 7310ec3c0419de220876a0e1bfce14a3ac2ab0dc Mon Sep 17 00:00:00 2001 From: Maaz Syed Adeeb Date: Mon, 5 Dec 2016 21:55:17 +0530 Subject: [PATCH] =?UTF-8?q?Making=20the=20Clear=20Browsing=20Data=20panel?= =?UTF-8?q?=20stateful=20Majorly,=20the=20change=20affects=202=20places=20?= =?UTF-8?q?in=20the=20UI.=20The=20Clear=20Browsing=20Data=E2=80=A6=20optio?= =?UTF-8?q?n=20in=20the=20History=20menu=20and=20the=20Clear=20Browsing=20?= =?UTF-8?q?Data=20Now=E2=80=A6=20button=20in=20the=20Security=20tab=20in?= =?UTF-8?q?=20Preferences.=20We=20store=20the=20state=20of=20the=20toggled?= =?UTF-8?q?=20options=20when=20the=20user=20clears=20anytime,=20so=20that?= =?UTF-8?q?=20the=20next=20time=20he/she=20opens=20this=20dialog,=20the=20?= =?UTF-8?q?options=20are=20pre-populated=20as=20per=20the=20last=20selecte?= =?UTF-8?q?d=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From a technical perspective, we have moved away from saving the current state of the SwitchControls in the windowState. We only save the visibility on the windowState. The whole state is managed by the panel itself and just updates the appState on clicking clear. Fixes #4082 --- app/browser/menu.js | 2 +- app/sessionStore.js | 5 +- docs/appActions.md | 8 +- docs/state.md | 20 +++-- docs/windowActions.md | 8 +- js/about/aboutActions.js | 4 +- js/about/preferences.js | 2 +- js/actions/appActions.js | 10 +-- js/actions/windowActions.js | 9 ++- js/components/clearBrowsingDataPanel.js | 36 +++++---- js/components/frame.js | 4 +- js/components/main.js | 6 +- js/constants/appConstants.js | 2 +- js/constants/windowConstants.js | 2 +- js/stores/appStore.js | 4 +- js/stores/windowStore.js | 14 ++-- test/about/newTabTest.js | 10 +-- test/app/sessionStoreTest.js | 2 +- test/components/clearBrowsingDataPanelTest.js | 74 +++++++++++++++++-- test/components/urlBarTest.js | 4 +- test/lib/brave.js | 4 +- test/lib/selectors.js | 1 + 22 files changed, 150 insertions(+), 81 deletions(-) diff --git a/app/browser/menu.js b/app/browser/menu.js index b5a9656cf25..e64ed164835 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -316,7 +316,7 @@ const createHistorySubmenu = () => { label: locale.translation('clearBrowsingData'), accelerator: 'Shift+CmdOrCtrl+Delete', click: function (item, focusedWindow) { - CommonMenu.sendToFocusedWindow(focusedWindow, [messages.SHORTCUT_OPEN_CLEAR_BROWSING_DATA_PANEL, {browserHistory: true}]) + CommonMenu.sendToFocusedWindow(focusedWindow, [messages.SHORTCUT_OPEN_CLEAR_BROWSING_DATA_PANEL]) } } ] diff --git a/app/sessionStore.js b/app/sessionStore.js index 6144f7a67e7..331c7f21c57 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -114,11 +114,10 @@ module.exports.cleanPerWindowData = (perWindowData, isShutdown) => { delete perWindowData.bookmarkDetail // Don't restore bravery panel delete perWindowData.braveryPanelDetail - // Don't restore cache clearing popup - delete perWindowData.clearBrowsingDataDetail - // Don't restore drag data + // Don't restore drag data and clearBrowsingDataPanel's visibility if (perWindowData.ui) { delete perWindowData.ui.dragging + delete perWindowData.ui.isClearBrowsingDataPanelVisible } perWindowData.frames = perWindowData.frames || [] let newKey = 0 diff --git a/docs/appActions.md b/docs/appActions.md index 8a9a7378b0d..f202b40ea5c 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -92,7 +92,7 @@ Adds a site to the site list ### clearHistory() -Clears history (all sites without tags). Indirectly called by appActions.clearAppData(). +Clears history (all sites without tags). Indirectly called by appActions.onClearBrowsingData(). @@ -403,13 +403,13 @@ Adds information about pending basic auth login requests -### clearAppData(clearDataDetail) +### onClearBrowsingData(clearDataDetail) -Clears the data specified in dataDetail +Clears the data specified in clearDataDetail **Parameters** -**clearDataDetail**: `object`, the app data to clear as per doc/state.md's clearBrowsingDataDetail +**clearDataDetail**: `object`, the app data to clear as per doc/state.md's clearBrowsingDataDefaults diff --git a/docs/state.md b/docs/state.md index 6c9c4025991..d3d38a2f051 100644 --- a/docs/state.md +++ b/docs/state.md @@ -266,7 +266,17 @@ AppStore menu: { template: object // used on Windows and by our tests: template object with Menubar control }, - defaultBrowserCheckComplete: boolean // true to indicate default browser check is complete + defaultBrowserCheckComplete: boolean, // true to indicate default browser check is complete + clearBrowsingDataDefaults: { + browserHistory: boolean, + downloadHistory: boolean, + cachedImagesAndFiles: boolean, + savedPasswords: boolean, + allSiteCookies: boolean, + autocompleteData: boolean, + autofillData: boolean, + savedSiteSettings: booleanß + } } ``` @@ -392,6 +402,7 @@ WindowStore position: array, // last known window position [x, y] size: array, // last known window size [x, y] isFullScreen: boolean, // true if window is fullscreen + isClearBrowsingDataPanelVisible: boolean, // true if the Clear Browsing Data panel is visible mouseInTitlebar: boolean, //Whether or not the mouse is in the titlebar dragging: { dragType: string, // tab, bookmark @@ -444,13 +455,6 @@ WindowStore expandNoScript: boolean, // Whether noscript section should be expanded expandFp: boolean // Whether fingerprinting protection should be expanded }, - clearBrowsingDataDetail: { - browserHistory: boolean, - downloadHistory: boolean, - cachedImagesAndFiles: boolean, - savedPasswords: boolean, - allSiteCookies: boolean - }, contextMenuDetail: { left: number, // the left position of the context menu right: number, // the right position of the context menu diff --git a/docs/windowActions.md b/docs/windowActions.md index 4aea42ff0d0..80190af86fa 100644 --- a/docs/windowActions.md +++ b/docs/windowActions.md @@ -765,9 +765,13 @@ Adds a history entry -### setClearBrowsingDataDetail() +### setClearBrowsingDataPanelVisible(isVisible) -Sets the clear browsing data popup detail +Sets whether the clear browsing data popup is visible + +**Parameters** + +**isVisible**: `boolean`, Sets whether the clear browsing data popup is visible diff --git a/js/about/aboutActions.js b/js/about/aboutActions.js index 77d4cc08234..05f537470ed 100644 --- a/js/about/aboutActions.js +++ b/js/about/aboutActions.js @@ -206,8 +206,8 @@ const aboutActions = { }) }, - clearBrowsingDataNow: function (clearBrowsingDataDetail) { - ipc.sendToHost(messages.CLEAR_BROWSING_DATA_NOW, clearBrowsingDataDetail) + clearBrowsingDataNow: function () { + ipc.sendToHost(messages.CLEAR_BROWSING_DATA_NOW) }, importBrowserDataNow: function () { diff --git a/js/about/preferences.js b/js/about/preferences.js index 15d9d7d074b..2d4d09cdd8d 100644 --- a/js/about/preferences.js +++ b/js/about/preferences.js @@ -1549,7 +1549,7 @@ class SecurityTab extends ImmutableComponent { this.clearBrowsingDataNow = this.clearBrowsingDataNow.bind(this) } clearBrowsingDataNow () { - aboutActions.clearBrowsingDataNow({browserHistory: true}) + aboutActions.clearBrowsingDataNow() } onToggleFlash (e) { aboutActions.setResourceEnabled(flash, e.target.value) diff --git a/js/actions/appActions.js b/js/actions/appActions.js index c39f9da6abb..5c8e8045aef 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -128,7 +128,7 @@ const appActions = { }, /** - * Clears history (all sites without tags). Indirectly called by appActions.clearAppData(). + * Clears history (all sites without tags). Indirectly called by appActions.onClearBrowsingData(). */ clearHistory: function () { AppDispatcher.dispatch({ @@ -492,12 +492,12 @@ const appActions = { }, /** - * Clears the data specified in dataDetail - * @param {object} clearDataDetail - the app data to clear as per doc/state.md's clearBrowsingDataDetail + * Clears the data specified in clearDataDetail + * @param {object} clearDataDetail - the app data to clear as per doc/state.md's clearBrowsingDataDefaults */ - clearAppData: function (clearDataDetail) { + onClearBrowsingData: function (clearDataDetail) { AppDispatcher.dispatch({ - actionType: appConstants.APP_CLEAR_DATA, + actionType: appConstants.APP_ON_CLEAR_BROWSING_DATA, clearDataDetail }) }, diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 141768a6ec1..5b4602d731b 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -980,12 +980,13 @@ const windowActions = { }, /** - * Sets the clear browsing data popup detail + * Sets whether the clear browsing data popup is visible + * @param {boolean} isVisible */ - setClearBrowsingDataDetail: function (clearBrowsingDataDetail) { + setClearBrowsingDataPanelVisible: function (isVisible) { dispatch({ - actionType: windowConstants.WINDOW_SET_CLEAR_BROWSING_DATA_DETAIL, - clearBrowsingDataDetail + actionType: windowConstants.WINDOW_SET_CLEAR_BROWSING_DATA_VISIBLE, + isVisible }) }, diff --git a/js/components/clearBrowsingDataPanel.js b/js/components/clearBrowsingDataPanel.js index 1d91d113025..9ed61871053 100644 --- a/js/components/clearBrowsingDataPanel.js +++ b/js/components/clearBrowsingDataPanel.js @@ -3,17 +3,16 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ const React = require('react') -const ImmutableComponent = require('./immutableComponent') +const Immutable = require('immutable') const Dialog = require('./dialog') const Button = require('./button') const SwitchControl = require('./switchControl') -const windowActions = require('../actions/windowActions') const appActions = require('../actions/appActions') const ipc = require('electron').ipcRenderer const messages = require('../constants/messages') -class ClearBrowsingDataPanel extends ImmutableComponent { - constructor () { +class ClearBrowsingDataPanel extends React.Component { + constructor (props) { super() this.onToggleBrowserHistory = this.onToggleSetting.bind(this, 'browserHistory') this.onToggleDownloadHistory = this.onToggleSetting.bind(this, 'downloadHistory') @@ -24,14 +23,19 @@ class ClearBrowsingDataPanel extends ImmutableComponent { this.onToggleAutofillData = this.onToggleSetting.bind(this, 'autofillData') this.onToggleSavedSiteSettings = this.onToggleSetting.bind(this, 'savedSiteSettings') this.onClear = this.onClear.bind(this) + this.state = { + clearBrowsingDataDetail: props.clearBrowsingDataDefaults ? props.clearBrowsingDataDefaults : Immutable.Map() + } } - onToggleSetting (setting, e) { - windowActions.setClearBrowsingDataDetail(this.props.clearBrowsingDataDetail.set(setting, e.target.value)) + onToggleSetting (setting) { + this.setState(({clearBrowsingDataDetail}) => ({ + clearBrowsingDataDetail: clearBrowsingDataDetail.update(setting, isChecked => !isChecked) + })) } onClear () { - appActions.clearAppData(this.props.clearBrowsingDataDetail) + appActions.onClearBrowsingData(this.state.clearBrowsingDataDetail) this.props.onHide() - let detail = this.props.clearBrowsingDataDetail + let detail = this.state.clearBrowsingDataDetail if (detail.get('allSiteCookies') && detail.get('browserHistory') && detail.get('cachedImagesAndFiles')) { ipc.send(messages.PREFS_RESTART) @@ -42,14 +46,14 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
e.stopPropagation()}>
- - - - - - - - + + + + + + + +