Skip to content

Commit 7713597

Browse files
committed
fix #3129, #3112, #2277
1 parent 01fe37c commit 7713597

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/js/tab.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ housekeep itself.
140140

141141
var PopupCandidate = function(targetTabId, openerTabId) {
142142
this.targetTabId = targetTabId;
143-
this.openerTabId = openerTabId;
143+
this.opener = {
144+
tabId: openerTabId,
145+
popunder: false,
146+
trustedURL: openerTabId === µb.mouseEventRegister.tabId ?
147+
µb.mouseEventRegister.url :
148+
''
149+
};
144150
this.selfDestructionTimer = null;
145151
this.launchSelfDestruction();
146152
};
@@ -160,13 +166,20 @@ housekeep itself.
160166
};
161167

162168
var popupCandidateTest = function(targetTabId) {
163-
var candidates = popupCandidates, entry;
169+
var candidates = popupCandidates,
170+
entry;
164171
for ( var tabId in candidates ) {
165172
entry = candidates[tabId];
166-
if ( targetTabId !== tabId && targetTabId !== entry.openerTabId ) {
173+
if ( targetTabId !== tabId && targetTabId !== entry.opener.tabId ) {
167174
continue;
168175
}
169-
if ( vAPI.tabs.onPopupUpdated(tabId, entry.openerTabId) === true ) {
176+
// https://github.com/gorhill/uBlock/issues/3129
177+
// If the trigger is a change in the opener's URL, mark the entry
178+
// as candidate for popunder filtering.
179+
if ( targetTabId === entry.opener.tabId ) {
180+
entry.popunder = true;
181+
}
182+
if ( vAPI.tabs.onPopupUpdated(tabId, entry.opener) === true ) {
170183
entry.destroy();
171184
} else {
172185
entry.launchSelfDestruction();
@@ -706,8 +719,9 @@ vAPI.tabs.onPopupUpdated = (function() {
706719
);
707720
};
708721

709-
return function(targetTabId, openerTabId) {
722+
return function(targetTabId, openerDetails) {
710723
// Opener details.
724+
var openerTabId = openerDetails.tabId;
711725
var tabContext = µb.tabContextManager.lookup(openerTabId);
712726
if ( tabContext === null ) { return; }
713727
var openerURL = tabContext.rawURL;
@@ -744,15 +758,12 @@ vAPI.tabs.onPopupUpdated = (function() {
744758
result = 0;
745759
// https://github.com/gorhill/uBlock/issues/2919
746760
// - If the target tab matches a clicked link, assume it's legit.
747-
if (
748-
openerTabId !== µb.mouseEventRegister.tabId ||
749-
areDifferentURLs(targetURL, µb.mouseEventRegister.url)
750-
) {
761+
if ( areDifferentURLs(targetURL, openerDetails.trustedURL) ) {
751762
result = popupMatch(openerURL, targetURL, 'popup');
752763
}
753764

754765
// Popunder test.
755-
if ( result === 0 ) {
766+
if ( result === 0 && openerDetails.popunder ) {
756767
result = popunderMatch(openerURL, targetURL);
757768
if ( result === 1 ) {
758769
popupType = 'popunder';

0 commit comments

Comments
 (0)