mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
This commit is contained in:
parent
c196bf5f53
commit
1a92fff641
@ -2361,9 +2361,27 @@ vAPI.net.registerListeners = function() {
|
|||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var shouldLoadPopupListenerMessageName = location.host + ':shouldLoadPopup';
|
var shouldLoadPopupListenerMessageName = location.host + ':shouldLoadPopup',
|
||||||
var shouldLoadPopupListener = function(openerURL, popupTabId) {
|
shouldLoadPopupListenerMap = new Map(),
|
||||||
var uri, openerTabId;
|
shouldLoadPopupListenerMapToD = 0;
|
||||||
|
var shouldLoadPopupListener = function(openerURL, target) {
|
||||||
|
var popupTabId = tabWatcher.tabIdFromTarget(target),
|
||||||
|
popupURL = target.currentURI && target.currentURI.asciiSpec || '',
|
||||||
|
openerTabId,
|
||||||
|
uri;
|
||||||
|
if ( shouldLoadPopupListenerMapToD > Date.now() ) {
|
||||||
|
openerTabId = shouldLoadPopupListenerMap.get(popupURL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uAssets/issues/255
|
||||||
|
// Handle chained popups.
|
||||||
|
if ( openerTabId !== undefined ) {
|
||||||
|
shouldLoadPopupListenerMap.set(target.currentURI.asciiSpec, openerTabId);
|
||||||
|
shouldLoadPopupListenerMapToD = Date.now() + 10000;
|
||||||
|
vAPI.tabs.onPopupCreated(popupTabId, openerTabId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for ( var browser of tabWatcher.browsers() ) {
|
for ( var browser of tabWatcher.browsers() ) {
|
||||||
uri = browser.currentURI;
|
uri = browser.currentURI;
|
||||||
|
|
||||||
@ -2375,15 +2393,16 @@ vAPI.net.registerListeners = function() {
|
|||||||
// believe this may have to do with those very temporary
|
// believe this may have to do with those very temporary
|
||||||
// browser objects created when opening a new tab, i.e. related
|
// browser objects created when opening a new tab, i.e. related
|
||||||
// to https://github.com/gorhill/uBlock/issues/212
|
// to https://github.com/gorhill/uBlock/issues/212
|
||||||
if ( !uri || uri.spec !== openerURL ) {
|
if ( !uri || uri.spec !== openerURL ) { continue; }
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
openerTabId = tabWatcher.tabIdFromTarget(browser);
|
openerTabId = tabWatcher.tabIdFromTarget(browser);
|
||||||
if ( openerTabId !== popupTabId ) {
|
if ( openerTabId === popupTabId ) { continue; }
|
||||||
vAPI.tabs.onPopupCreated(popupTabId, openerTabId);
|
|
||||||
break;
|
shouldLoadPopupListenerMap = new Map();
|
||||||
}
|
shouldLoadPopupListenerMapToD = Date.now() + 10000;
|
||||||
|
shouldLoadPopupListenerMap.set(popupURL, openerTabId);
|
||||||
|
vAPI.tabs.onPopupCreated(popupTabId, openerTabId);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var shouldLoadPopupListenerAsync = function(e) {
|
var shouldLoadPopupListenerAsync = function(e) {
|
||||||
@ -2391,10 +2410,7 @@ vAPI.net.registerListeners = function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We are handling a synchronous message: do not block.
|
// We are handling a synchronous message: do not block.
|
||||||
vAPI.setTimeout(
|
vAPI.setTimeout(shouldLoadPopupListener.bind(null, e.data, e.target), 1);
|
||||||
shouldLoadPopupListener.bind(null, e.data, tabWatcher.tabIdFromTarget(e.target)),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||||
|
@ -568,22 +568,25 @@ vAPI.tabs.onPopupUpdated = (function() {
|
|||||||
// URL.
|
// URL.
|
||||||
// https://github.com/gorhill/uBlock/issues/1735
|
// https://github.com/gorhill/uBlock/issues/1735
|
||||||
// Do not bail out on `data:` URI, they are commonly used for popups.
|
// Do not bail out on `data:` URI, they are commonly used for popups.
|
||||||
|
// https://github.com/uBlockOrigin/uAssets/issues/255
|
||||||
|
// Do not bail out on `about:blank`: an `about:blank` popup can be
|
||||||
|
// opened, with the sole purpose to serve as an intermediary in
|
||||||
|
// a sequence of chained popups.
|
||||||
if (
|
if (
|
||||||
context.requestHostname === '' &&
|
context.requestHostname === '' &&
|
||||||
targetURL.startsWith('data:') === false
|
targetURL.startsWith('data:') === false &&
|
||||||
|
targetURL !== 'about:blank'
|
||||||
) {
|
) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dynamic filtering makes sense only when we have a valid hostname.
|
// Dynamic filtering makes sense only when we have a valid hostname.
|
||||||
if ( openerHostname !== '' ) {
|
if ( openerHostname !== '' ) {
|
||||||
// Check user switch first
|
// Check per-site switch first
|
||||||
if (
|
if ( µb.hnSwitches.evaluateZ('no-popups', openerHostname) ) {
|
||||||
typeof clickedURL === 'string' &&
|
if ( typeof clickedURL !== 'string' || areDifferentURLs(targetURL, clickedURL) ) {
|
||||||
areDifferentURLs(targetURL, clickedURL) &&
|
return 'ub:no-popups: ' + µb.hnSwitches.z + ' true';
|
||||||
µb.hnSwitches.evaluateZ('no-popups', openerHostname)
|
}
|
||||||
) {
|
|
||||||
return 'ub:no-popups: ' + µb.hnSwitches.z + ' true';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/581
|
// https://github.com/gorhill/uBlock/issues/581
|
||||||
|
Loading…
Reference in New Issue
Block a user