Skip to content

Commit

Permalink
fix #2919
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 5, 2017
1 parent 162d612 commit 2660bee
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
11 changes: 8 additions & 3 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions src/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''
}
);
};
Expand Down
21 changes: 12 additions & 9 deletions src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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':
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 20 additions & 22 deletions src/js/tab.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 2660bee

Please sign in to comment.