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

Commit 04376e5

Browse files
committed
fix data URL phishing warning appear on the wrong tab
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.
1 parent 32ef086 commit 04376e5

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

app/renderer/reducers/frameReducer.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,18 @@ const frameReducer = (state, action, immutableAction) => {
146146
// see bug #8429
147147
const isNewTab = changeInfo.isEmpty()
148148
const activeTabHasUpdated = changeInfo.get('active') != null
149+
const hasBeenActivated = frame.get('hasBeenActivated')
149150

150151
if (!isNewTab && activeTabHasUpdated) {
151152
state = frameStateUtil.updateTabPageIndex(state, tabId)
152153
state = state.set('previewFrameKey', null)
154+
// Show the phishing warning if we are showing a data: tab
155+
// for the first time
156+
state = state.setIn(['ui', 'siteInfo', 'isVisible'],
157+
!hasBeenActivated && isPotentialPhishingUrl(tab.get('url')))
158+
}
159+
if (!frame.get('hasBeenActivated')) {
160+
state = state.setIn(['frames', index, 'hasBeenActivated'], true)
153161
}
154162
}
155163
}
@@ -183,7 +191,8 @@ const frameReducer = (state, action, immutableAction) => {
183191
})
184192
}
185193
// For potential phishing pages, show a warning
186-
state = state.setIn(['ui', 'siteInfo', 'isVisible'], isPotentialPhishingUrl(action.location))
194+
state = state.setIn(['ui', 'siteInfo', 'isVisible'],
195+
isPotentialPhishingUrl(action.location) && frameStateUtil.isFrameKeyActive(state, action.key))
187196
break
188197
case windowConstants.WINDOW_CLOSE_FRAMES:
189198
let closedFrames = new Immutable.List()

docs/state.md

+1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ WindowStore
490490
internalFindStatePresent: boolean // true if a find-first (ie findNext: false) call has been made
491491
}
492492
guestInstanceId: string, // not persisted
493+
hasBeenActivated: boolean, // whether this frame has ever been the active frame
493494
history: array, // navigation history
494495
hrefPreview: string, // show hovered link preview
495496
httpsEverywhere: Object<string, Array<string>>, // map of XML rulesets name to redirected resources

test/navbar-components/siteInfoTest.js

+21
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,26 @@ describe('siteInfo component tests', function () {
6969
.waitForElementCount(siteInfoDialog, 1)
7070
.waitForElementCount(siteInfoDialog, 0)
7171
})
72+
73+
it('shows siteInfo once when switching to a new tab', function * () {
74+
const page1 = 'data:,Hello%2C%20World!'
75+
yield this.app.client
76+
.tabByIndex(0)
77+
.url('https://example.com')
78+
.windowByUrl(Brave.browserWindowUrl)
79+
.newTab({
80+
active: false,
81+
url: page1
82+
})
83+
.windowByUrl(Brave.browserWindowUrl)
84+
.waitForElementCount(siteInfoDialog, 0)
85+
.activateTabByIndex(1)
86+
.waitForElementCount(siteInfoDialog, 1)
87+
.activateTabByIndex(0)
88+
.waitForElementCount(siteInfoDialog, 0)
89+
.activateTabByIndex(1)
90+
.waitForExist('[data-test-active-tab][data-frame-key="2"]')
91+
.waitForElementCount(siteInfoDialog, 0)
92+
})
7293
})
7394
})

0 commit comments

Comments
 (0)