From d6516f7ac6a16c415fdf56c9e9f5d2769b67cd31 Mon Sep 17 00:00:00 2001 From: yan Date: Wed, 10 May 2017 00:19:16 +0000 Subject: [PATCH] noscript exceptions from private tabs should not apply to regular tabs fix https://github.com/brave/browser-laptop/issues/8779 Test Plan: 1. disable scripts on twitter.com 2. open twitter.com in a private tab. scripts should be disabled. 3. click the noscript icon to allow scripts in the private tab. 4. load twitter again in a regular tab. scripts should still be disabled. --- docs/appActions.md | 4 +++- js/actions/appActions.js | 6 ++++-- js/components/noScriptInfo.js | 2 +- js/stores/appStore.js | 21 ++++++++++++--------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/docs/appActions.md b/docs/appActions.md index 00f97f732c6..55876824dd0 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -766,7 +766,7 @@ Dispatches a message when a tab is being cloned -### noScriptExceptionsAdded(hostPattern, origins) +### noScriptExceptionsAdded(hostPattern, origins, temporary) Dispatches a message when noscript exceptions are added for an origin @@ -776,6 +776,8 @@ Dispatches a message when noscript exceptions are added for an origin **origins**: `Object.<string, (boolean|number)>`, Dispatches a message when noscript exceptions are added for an origin +**temporary**: `boolean`, Dispatches a message when noscript exceptions are added for an origin + ### setObjectId(objectId, objectPath) diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 93b8a96201f..db3fbe61d0a 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -943,12 +943,14 @@ const appActions = { * Dispatches a message when noscript exceptions are added for an origin * @param {string} hostPattern * @param {Object.} origins + * @param {boolean} temporary */ - noScriptExceptionsAdded: function (hostPattern, origins) { + noScriptExceptionsAdded: function (hostPattern, origins, temporary) { AppDispatcher.dispatch({ actionType: appConstants.APP_ADD_NOSCRIPT_EXCEPTIONS, hostPattern, - origins + origins, + temporary }) }, diff --git a/js/components/noScriptInfo.js b/js/components/noScriptInfo.js index 11a3adfb1ac..db26fc0271e 100644 --- a/js/components/noScriptInfo.js +++ b/js/components/noScriptInfo.js @@ -84,7 +84,7 @@ class NoScriptInfo extends ImmutableComponent { } }) if (checkedOrigins.filter((value) => value !== false).size) { - appActions.noScriptExceptionsAdded(this.origin, checkedOrigins) + appActions.noScriptExceptionsAdded(this.origin, checkedOrigins, this.isPrivate) this.reload() this.props.onHide() } diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 93f051c2e61..51840518c58 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -562,15 +562,18 @@ const handleAppAction = (action) => { break } case appConstants.APP_ADD_NOSCRIPT_EXCEPTIONS: - // Note that this is always cleared on restart or reload, so should not - // be synced or persisted. - let key = 'noScriptExceptions' - if (!action.origins || !action.origins.size) { - // Clear the exceptions - appState = appState.setIn(['siteSettings', action.hostPattern, key], new Immutable.Map()) - } else { - const currentExceptions = appState.getIn(['siteSettings', action.hostPattern, key]) || new Immutable.Map() - appState = appState.setIn(['siteSettings', action.hostPattern, key], currentExceptions.merge(action.origins)) + { + const propertyName = action.temporary ? 'temporarySiteSettings' : 'siteSettings' + // Note that this is always cleared on restart or reload, so should not + // be synced or persisted. + const key = 'noScriptExceptions' + if (!action.origins || !action.origins.size) { + // Clear the exceptions + appState = appState.setIn([propertyName, action.hostPattern, key], new Immutable.Map()) + } else { + const currentExceptions = appState.getIn([propertyName, action.hostPattern, key]) || new Immutable.Map() + appState = appState.setIn([propertyName, action.hostPattern, key], currentExceptions.merge(action.origins)) + } } break case appConstants.APP_UPDATE_LEDGER_INFO: