From 2660bee0d20e8355380b1b8c64973601514526cd Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 5 Sep 2017 19:49:48 -0400 Subject: [PATCH] fix #2919 --- src/js/background.js | 11 ++++++++--- src/js/commands.js | 6 ++---- src/js/contentscript.js | 2 +- src/js/messaging.js | 21 ++++++++++++--------- src/js/tab.js | 42 ++++++++++++++++++++--------------------- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 39faa13be..c2b6a8cfe 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -153,9 +153,14 @@ var µBlock = (function() { // jshint ignore:line noopFunc: function(){}, apiErrorCount: 0, - mouseX: -1, - mouseY: -1, - mouseURL: '', + + mouseEventRegister: { + tabId: '', + x: -1, + y: -1, + url: '' + }, + epickerTarget: '', epickerZap: false, epickerEprom: null, diff --git a/src/js/commands.js b/src/js/commands.js index 09a684384..71b03fb58 100644 --- a/src/js/commands.js +++ b/src/js/commands.js @@ -35,10 +35,8 @@ case 'launch-element-zapper': case 'launch-element-picker': vAPI.tabs.get(null, function(tab) { - if ( tab instanceof Object === false ) { - return; - } - µb.mouseX = µb.mouseY = -1; + if ( tab instanceof Object === false ) { return; } + µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1; µb.elementPickerExec(tab.id, undefined, command === 'launch-element-zapper'); }); break; diff --git a/src/js/contentscript.js b/src/js/contentscript.js index acf63176a..8a22379e9 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -1659,7 +1659,7 @@ vAPI.domIsLoaded = function(ev) { what: 'mouseClick', x: ev.clientX, y: ev.clientY, - url: elem !== null ? elem.href : '' + url: elem !== null && ev.isTrusted !== false ? elem.href : '' } ); }; diff --git a/src/js/messaging.js b/src/js/messaging.js index 265e3ef86..a5bde04bf 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -88,7 +88,10 @@ var onMessage = function(request, sender, callback) { break; } - var tabId = sender && sender.tab ? sender.tab.id : 0; + // The concatenation with the empty string ensure that the resulting value + // is a string. This is important since tab id values are assumed to be + // of string type. + var tabId = sender && sender.tab ? '' + sender.tab.id : 0; // Sync var response; @@ -137,7 +140,7 @@ var onMessage = function(request, sender, callback) { case 'launchElementPicker': // Launched from some auxiliary pages, clear context menu coords. - µb.mouseX = µb.mouseY = -1; + µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1; µb.elementPickerExec(request.tabId, request.targetURL, request.zap); break; @@ -146,9 +149,10 @@ var onMessage = function(request, sender, callback) { break; case 'mouseClick': - µb.mouseX = request.x; - µb.mouseY = request.y; - µb.mouseURL = request.url; + µb.mouseEventRegister.tabId = tabId; + µb.mouseEventRegister.x = request.x; + µb.mouseEventRegister.y = request.y; + µb.mouseEventRegister.url = request.url; break; case 'reloadTab': @@ -560,15 +564,14 @@ var onMessage = function(request, sender, callback) { callback({ frameContent: this.responseText.replace(reStrings, replacer), target: µb.epickerTarget, - clientX: µb.mouseX, - clientY: µb.mouseY, + clientX: µb.mouseEventRegister.x, + clientY: µb.mouseEventRegister.y, zap: µb.epickerZap, eprom: µb.epickerEprom }); µb.epickerTarget = ''; - µb.mouseX = -1; - µb.mouseY = -1; + µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1; }; xhr.send(); return; diff --git a/src/js/tab.js b/src/js/tab.js index 7c1f04e82..e329c9fe2 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -1,7 +1,7 @@ /******************************************************************************* uBlock Origin - a browser extension to block requests. - Copyright (C) 2014-2016 Raymond Hill + Copyright (C) 2014-2017 Raymond Hill This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -536,22 +536,16 @@ vAPI.tabs.onPopupUpdated = (function() { var areDifferentURLs = function(a, b) { // https://github.com/gorhill/uBlock/issues/1378 // Maybe no link element was clicked. - if ( b === '' ) { - return true; - } + if ( b === '' ) { return true; } var pos = a.indexOf('://'); - if ( pos === -1 ) { - return false; - } + if ( pos === -1 ) { return false; } a = a.slice(pos); pos = b.indexOf('://'); - if ( pos === -1 ) { - return false; - } + if ( pos === -1 ) { return false; } return b.slice(pos) !== a; }; - var popupMatch = function(openerURL, targetURL, clickedURL, popupType) { + var popupMatch = function(openerURL, targetURL, popupType) { var openerHostname = µb.URI.hostnameFromURI(openerURL), openerDomain = µb.URI.domainFromHostname(openerHostname), result; @@ -584,16 +578,11 @@ vAPI.tabs.onPopupUpdated = (function() { if ( openerHostname !== '' && targetURL !== 'about:blank' ) { // Check per-site switch first if ( µb.hnSwitches.evaluateZ('no-popups', openerHostname) === true ) { - if ( - typeof clickedURL === 'string' && - areDifferentURLs(targetURL, clickedURL) - ) { - logData = { - source: 'switch', - raw: 'no-popups: ' + µb.hnSwitches.z + ' true' - }; - return 1; - } + logData = { + source: 'switch', + raw: 'no-popups: ' + µb.hnSwitches.z + ' true' + }; + return 1; } // https://github.com/gorhill/uBlock/issues/581 @@ -736,9 +725,18 @@ vAPI.tabs.onPopupUpdated = (function() { } } + // https://github.com/gorhill/uBlock/issues/2919 + // - The target tab matches a clicked link, assume it's legit. + if ( + openerTabId === µb.mouseEventRegister.tabId && + areDifferentURLs(targetURL, µb.mouseEventRegister.url) === false + ) { + return; + } + // Popup test. var popupType = 'popup', - result = popupMatch(openerURL, targetURL, µb.mouseURL, 'popup'); + result = popupMatch(openerURL, targetURL, 'popup'); // Popunder test. if ( result === 0 ) {