This commit is contained in:
gorhill 2017-09-05 19:49:48 -04:00
parent 162d612317
commit 2660bee0d2
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 43 additions and 39 deletions

View File

@ -153,9 +153,14 @@ var µBlock = (function() { // jshint ignore:line
noopFunc: function(){}, noopFunc: function(){},
apiErrorCount: 0, apiErrorCount: 0,
mouseX: -1,
mouseY: -1, mouseEventRegister: {
mouseURL: '', tabId: '',
x: -1,
y: -1,
url: ''
},
epickerTarget: '', epickerTarget: '',
epickerZap: false, epickerZap: false,
epickerEprom: null, epickerEprom: null,

View File

@ -35,10 +35,8 @@
case 'launch-element-zapper': case 'launch-element-zapper':
case 'launch-element-picker': case 'launch-element-picker':
vAPI.tabs.get(null, function(tab) { vAPI.tabs.get(null, function(tab) {
if ( tab instanceof Object === false ) { if ( tab instanceof Object === false ) { return; }
return; µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1;
}
µb.mouseX = µb.mouseY = -1;
µb.elementPickerExec(tab.id, undefined, command === 'launch-element-zapper'); µb.elementPickerExec(tab.id, undefined, command === 'launch-element-zapper');
}); });
break; break;

View File

@ -1659,7 +1659,7 @@ vAPI.domIsLoaded = function(ev) {
what: 'mouseClick', what: 'mouseClick',
x: ev.clientX, x: ev.clientX,
y: ev.clientY, y: ev.clientY,
url: elem !== null ? elem.href : '' url: elem !== null && ev.isTrusted !== false ? elem.href : ''
} }
); );
}; };

View File

@ -88,7 +88,10 @@ var onMessage = function(request, sender, callback) {
break; 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 // Sync
var response; var response;
@ -137,7 +140,7 @@ var onMessage = function(request, sender, callback) {
case 'launchElementPicker': case 'launchElementPicker':
// Launched from some auxiliary pages, clear context menu coords. // 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); µb.elementPickerExec(request.tabId, request.targetURL, request.zap);
break; break;
@ -146,9 +149,10 @@ var onMessage = function(request, sender, callback) {
break; break;
case 'mouseClick': case 'mouseClick':
µb.mouseX = request.x; µb.mouseEventRegister.tabId = tabId;
µb.mouseY = request.y; µb.mouseEventRegister.x = request.x;
µb.mouseURL = request.url; µb.mouseEventRegister.y = request.y;
µb.mouseEventRegister.url = request.url;
break; break;
case 'reloadTab': case 'reloadTab':
@ -560,15 +564,14 @@ var onMessage = function(request, sender, callback) {
callback({ callback({
frameContent: this.responseText.replace(reStrings, replacer), frameContent: this.responseText.replace(reStrings, replacer),
target: µb.epickerTarget, target: µb.epickerTarget,
clientX: µb.mouseX, clientX: µb.mouseEventRegister.x,
clientY: µb.mouseY, clientY: µb.mouseEventRegister.y,
zap: µb.epickerZap, zap: µb.epickerZap,
eprom: µb.epickerEprom eprom: µb.epickerEprom
}); });
µb.epickerTarget = ''; µb.epickerTarget = '';
µb.mouseX = -1; µb.mouseEventRegister.x = µb.mouseEventRegister.y = -1;
µb.mouseY = -1;
}; };
xhr.send(); xhr.send();
return; return;

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock Origin - a browser extension to block requests. 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 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 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) { var areDifferentURLs = function(a, b) {
// https://github.com/gorhill/uBlock/issues/1378 // https://github.com/gorhill/uBlock/issues/1378
// Maybe no link element was clicked. // Maybe no link element was clicked.
if ( b === '' ) { if ( b === '' ) { return true; }
return true;
}
var pos = a.indexOf('://'); var pos = a.indexOf('://');
if ( pos === -1 ) { if ( pos === -1 ) { return false; }
return false;
}
a = a.slice(pos); a = a.slice(pos);
pos = b.indexOf('://'); pos = b.indexOf('://');
if ( pos === -1 ) { if ( pos === -1 ) { return false; }
return false;
}
return b.slice(pos) !== a; return b.slice(pos) !== a;
}; };
var popupMatch = function(openerURL, targetURL, clickedURL, popupType) { var popupMatch = function(openerURL, targetURL, popupType) {
var openerHostname = µb.URI.hostnameFromURI(openerURL), var openerHostname = µb.URI.hostnameFromURI(openerURL),
openerDomain = µb.URI.domainFromHostname(openerHostname), openerDomain = µb.URI.domainFromHostname(openerHostname),
result; result;
@ -584,17 +578,12 @@ vAPI.tabs.onPopupUpdated = (function() {
if ( openerHostname !== '' && targetURL !== 'about:blank' ) { if ( openerHostname !== '' && targetURL !== 'about:blank' ) {
// Check per-site switch first // Check per-site switch first
if ( µb.hnSwitches.evaluateZ('no-popups', openerHostname) === true ) { if ( µb.hnSwitches.evaluateZ('no-popups', openerHostname) === true ) {
if (
typeof clickedURL === 'string' &&
areDifferentURLs(targetURL, clickedURL)
) {
logData = { logData = {
source: 'switch', source: 'switch',
raw: 'no-popups: ' + µb.hnSwitches.z + ' true' raw: 'no-popups: ' + µb.hnSwitches.z + ' true'
}; };
return 1; return 1;
} }
}
// https://github.com/gorhill/uBlock/issues/581 // https://github.com/gorhill/uBlock/issues/581
// Take into account popup-specific rules in dynamic URL filtering, OR // Take into account popup-specific rules in dynamic URL filtering, OR
@ -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. // Popup test.
var popupType = 'popup', var popupType = 'popup',
result = popupMatch(openerURL, targetURL, µb.mouseURL, 'popup'); result = popupMatch(openerURL, targetURL, 'popup');
// Popunder test. // Popunder test.
if ( result === 0 ) { if ( result === 0 ) {