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

Clear per-tab browserAction data when navigation happens #5339

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/common/state/extensionState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const tabState = require('./tabState')
const {makeImmutable} = require('./immutableUtil')
const Immutable = require('immutable')
const WindowConstants = require('../../../js/constants/windowConstants')

let transientFields = []

Expand Down Expand Up @@ -56,6 +57,20 @@ const extensionState = {
browserActionUpdated: (state, action) => {
action = makeImmutable(action)
state = makeImmutable(state)
if (action.get('actionType') === WindowConstants.WINDOW_SET_NAVIGATED &&
action.get('tabId')) {
let tabId = action.get('tabId')
let extensions = extensionState.getEnabledExtensions(state)
extensions && extensions.forEach((extension) => {
let tabs = extension.getIn(['browserAction', 'tabs'])
if (tabs && tabs.get(tabId)) {
tabs = tabs.set(tabId, Immutable.Map())
extension = extension.setIn(['browserAction', 'tabs'], tabs)
state = state.setIn(['extensions', extension.get('id')], extension)
}
})
return state
}
let extensionId = action.get('extensionId').toString()
let extension = extensionState.getExtensionById(state, extensionId)
if (extension && extension.get('browserAction')) {
Expand Down
4 changes: 3 additions & 1 deletion docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Dispatches a message to the store to set the new URL.



### setNavigated(location, key, isNavigatedInPage)
### setNavigated(location, key, isNavigatedInPage, tabId)

Dispatches a message to the store to let it know a page has been navigated.

Expand All @@ -60,6 +60,8 @@ Dispatches a message to the store to let it know a page has been navigated.

**isNavigatedInPage**: `boolean`, true if it was a navigation within the same page.

**tabId**: `number`, the tab id



### setSecurityState(frameProps, securityState)
Expand Down
6 changes: 4 additions & 2 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ const windowActions = {
* @param {string} location - The URL of the page that was navigated to.
* @param {number} key - The frame key to modify.
* @param {boolean} isNavigatedInPage - true if it was a navigation within the same page.
* @param {number} tabId - the tab id
*/
setNavigated: function (location, key, isNavigatedInPage) {
setNavigated: function (location, key, isNavigatedInPage, tabId) {
dispatch({
actionType: WindowConstants.WINDOW_SET_NAVIGATED,
location,
key,
isNavigatedInPage
isNavigatedInPage,
tabId
})
},

Expand Down
6 changes: 3 additions & 3 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ class Frame extends ImmutableComponent {
windowActions.loadUrl(this.frame, 'about:error')
appActions.removeSite(siteUtil.getDetailFromFrame(this.frame))
} else if (provisionLoadFailure) {
windowActions.setNavigated(this.webview.getURL(), this.props.frameKey, true)
windowActions.setNavigated(this.webview.getURL(), this.props.frameKey, true, this.frame.get('tabId'))
}
}
this.webview.addEventListener('load-commit', (e) => {
Expand All @@ -1018,7 +1018,7 @@ class Frame extends ImmutableComponent {
if (this.props.isActive && this.webview.canGoBack() && document.activeElement !== this.webview) {
this.webview.focus()
}
windowActions.setNavigated(e.url, this.props.frameKey, false)
windowActions.setNavigated(e.url, this.props.frameKey, false, this.frame.get('tabId'))
// force temporary url display for tabnapping protection
windowActions.setMouseInTitlebar(true)

Expand Down Expand Up @@ -1059,7 +1059,7 @@ class Frame extends ImmutableComponent {
})
this.webview.addEventListener('did-navigate-in-page', (e) => {
if (e.isMainFrame) {
windowActions.setNavigated(e.url, this.props.frameKey, true)
windowActions.setNavigated(e.url, this.props.frameKey, true, this.frame.get('tabId'))
loadEnd(true)
}
})
Expand Down
5 changes: 5 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,11 @@ const handleAppAction = (action) => {
case WindowConstants.WINDOW_SET_FAVICON:
appState = appState.set('sites', siteUtil.updateSiteFavicon(appState.get('sites'), action.frameProps.get('location'), action.favicon))
break
case WindowConstants.WINDOW_SET_NAVIGATED:
if (!action.isNavigatedInPage) {
appState = extensionState.browserActionUpdated(appState, action)
}
break
default:
}

Expand Down