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

Commit

Permalink
fix data URL phishing warning appear on the wrong tab
Browse files Browse the repository at this point in the history
fix #10754

test plan
1. go to https://jsfiddle.net/y3uw6q1w/
2. right click the link and open in new tab
3. no siteInfo popup should appear
4. switch to the new tab
5. siteInfo popup should appear
6. switch to tab 1 and back to tab 2. the siteInfo popup should not appear.
  • Loading branch information
diracdeltas committed Sep 1, 2017
1 parent 32ef086 commit 04376e5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/renderer/reducers/frameReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,18 @@ const frameReducer = (state, action, immutableAction) => {
// see bug #8429
const isNewTab = changeInfo.isEmpty()
const activeTabHasUpdated = changeInfo.get('active') != null
const hasBeenActivated = frame.get('hasBeenActivated')

if (!isNewTab && activeTabHasUpdated) {
state = frameStateUtil.updateTabPageIndex(state, tabId)
state = state.set('previewFrameKey', null)
// Show the phishing warning if we are showing a data: tab
// for the first time
state = state.setIn(['ui', 'siteInfo', 'isVisible'],
!hasBeenActivated && isPotentialPhishingUrl(tab.get('url')))
}
if (!frame.get('hasBeenActivated')) {
state = state.setIn(['frames', index, 'hasBeenActivated'], true)
}
}
}
Expand Down Expand Up @@ -183,7 +191,8 @@ const frameReducer = (state, action, immutableAction) => {
})
}
// For potential phishing pages, show a warning
state = state.setIn(['ui', 'siteInfo', 'isVisible'], isPotentialPhishingUrl(action.location))
state = state.setIn(['ui', 'siteInfo', 'isVisible'],
isPotentialPhishingUrl(action.location) && frameStateUtil.isFrameKeyActive(state, action.key))
break
case windowConstants.WINDOW_CLOSE_FRAMES:
let closedFrames = new Immutable.List()
Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ WindowStore
internalFindStatePresent: boolean // true if a find-first (ie findNext: false) call has been made
}
guestInstanceId: string, // not persisted
hasBeenActivated: boolean, // whether this frame has ever been the active frame
history: array, // navigation history
hrefPreview: string, // show hovered link preview
httpsEverywhere: Object<string, Array<string>>, // map of XML rulesets name to redirected resources
Expand Down
21 changes: 21 additions & 0 deletions test/navbar-components/siteInfoTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,26 @@ describe('siteInfo component tests', function () {
.waitForElementCount(siteInfoDialog, 1)
.waitForElementCount(siteInfoDialog, 0)
})

it('shows siteInfo once when switching to a new tab', function * () {
const page1 = 'data:,Hello%2C%20World!'
yield this.app.client
.tabByIndex(0)
.url('https://example.com')
.windowByUrl(Brave.browserWindowUrl)
.newTab({
active: false,
url: page1
})
.windowByUrl(Brave.browserWindowUrl)
.waitForElementCount(siteInfoDialog, 0)
.activateTabByIndex(1)
.waitForElementCount(siteInfoDialog, 1)
.activateTabByIndex(0)
.waitForElementCount(siteInfoDialog, 0)
.activateTabByIndex(1)
.waitForExist('[data-test-active-tab][data-frame-key="2"]')
.waitForElementCount(siteInfoDialog, 0)
})
})
})

0 comments on commit 04376e5

Please sign in to comment.