Skip to content
This repository was archived by the owner on Feb 29, 2020. It is now read-only.

Commit 05c9346

Browse files
committed
Bug 1539470 - Prevent tabs opened in the background from affecting the CFR Pin Tab visits counter
1 parent 9808476 commit 05c9346

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/ASRouterTriggerListeners.jsm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ async function checkStartupFinished(win) {
3030
}
3131
}
3232

33+
function isFocusedTab(aBrowser, aLocationURI) {
34+
try {
35+
if (aBrowser.ownerGlobal.gBrowser.currentURI.spec === aLocationURI.aLocationURI.spec) {
36+
return true;
37+
}
38+
} catch (e) {} // nsIURI.host can throw for non-nsStandardURL nsIURIs
39+
40+
return false;
41+
}
42+
3343
function isPrivateWindow(win) {
3444
return !(win instanceof Ci.nsIDOMWindow) || win.closed || PrivateBrowsingUtils.isWindowPrivate(win);
3545
}
@@ -179,6 +189,12 @@ this.ASRouterTriggerListeners = new Map([
179189
},
180190

181191
onLocationChange(aBrowser, aWebProgress, aRequest, aLocationURI, aFlags) {
192+
// If a new tab was opened in the background we don't want it to increment
193+
// the visits count. That will happen anyway because of the `onTabSwitch`
194+
// listener that fires when the tab is selected.
195+
if (!isFocusedTab(aBrowser, aLocationURI)) {
196+
return;
197+
}
182198
// Some websites trigger redirect events after they finish loading even
183199
// though the location remains the same. This results in onLocationChange
184200
// events to be fired twice.

0 commit comments

Comments
 (0)