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(){},
apiErrorCount: 0,
mouseX: -1,
mouseY: -1,
mouseURL: '',
mouseEventRegister: {
tabId: '',
x: -1,
y: -1,
url: ''
},
epickerTarget: '',
epickerZap: false,
epickerEprom: null,

View File

@ -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;

View File

@ -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 : ''
}
);
};

View File

@ -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;

View File

@ -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 ) {