Skip to content

Commit

Permalink
fix #3129, #3112, #2277
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Oct 13, 2017
1 parent 01fe37c commit 7713597
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ housekeep itself.

var PopupCandidate = function(targetTabId, openerTabId) {
this.targetTabId = targetTabId;
this.openerTabId = openerTabId;
this.opener = {
tabId: openerTabId,
popunder: false,
trustedURL: openerTabId === µb.mouseEventRegister.tabId ?
µb.mouseEventRegister.url :
''
};
this.selfDestructionTimer = null;
this.launchSelfDestruction();
};
Expand All @@ -160,13 +166,20 @@ housekeep itself.
};

var popupCandidateTest = function(targetTabId) {
var candidates = popupCandidates, entry;
var candidates = popupCandidates,
entry;
for ( var tabId in candidates ) {
entry = candidates[tabId];
if ( targetTabId !== tabId && targetTabId !== entry.openerTabId ) {
if ( targetTabId !== tabId && targetTabId !== entry.opener.tabId ) {
continue;
}
if ( vAPI.tabs.onPopupUpdated(tabId, entry.openerTabId) === true ) {
// https://github.com/gorhill/uBlock/issues/3129
// If the trigger is a change in the opener's URL, mark the entry
// as candidate for popunder filtering.
if ( targetTabId === entry.opener.tabId ) {
entry.popunder = true;
}
if ( vAPI.tabs.onPopupUpdated(tabId, entry.opener) === true ) {
entry.destroy();
} else {
entry.launchSelfDestruction();
Expand Down Expand Up @@ -706,8 +719,9 @@ vAPI.tabs.onPopupUpdated = (function() {
);
};

return function(targetTabId, openerTabId) {
return function(targetTabId, openerDetails) {
// Opener details.
var openerTabId = openerDetails.tabId;
var tabContext = µb.tabContextManager.lookup(openerTabId);
if ( tabContext === null ) { return; }
var openerURL = tabContext.rawURL;
Expand Down Expand Up @@ -744,15 +758,12 @@ vAPI.tabs.onPopupUpdated = (function() {
result = 0;
// https://github.com/gorhill/uBlock/issues/2919
// - If the target tab matches a clicked link, assume it's legit.
if (
openerTabId !== µb.mouseEventRegister.tabId ||
areDifferentURLs(targetURL, µb.mouseEventRegister.url)
) {
if ( areDifferentURLs(targetURL, openerDetails.trustedURL) ) {
result = popupMatch(openerURL, targetURL, 'popup');
}

// Popunder test.
if ( result === 0 ) {
if ( result === 0 && openerDetails.popunder ) {
result = popunderMatch(openerURL, targetURL);
if ( result === 1 ) {
popupType = 'popunder';
Expand Down

0 comments on commit 7713597

Please sign in to comment.