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

Commit

Permalink
Clear per-tab browserAction data when navigation happens
Browse files Browse the repository at this point in the history
fix #5327

Auditors: @bridiver, @bbondy

Test Plan:
1. Go to about:preferences#advanced and enable pocket
2. Login pocket
3. Navigate to arbitrary page
4. Save page to pocket
5. Navigate to other page/refresh the page
6. The pocket icon should not be illuminated
  • Loading branch information
darkdh committed Nov 2, 2016
1 parent 3874b48 commit 8b2c828
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
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
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 @@ -983,7 +983,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 @@ -1007,7 +1007,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 @@ -1048,7 +1048,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 @@ -773,6 +773,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

0 comments on commit 8b2c828

Please sign in to comment.