1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-01 16:49:39 +02:00
gorhill 2017-01-02 10:50:03 -05:00
parent c196bf5f53
commit 1a92fff641
2 changed files with 41 additions and 22 deletions

View File

@ -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,26 +2393,24 @@ 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; }
shouldLoadPopupListenerMap = new Map();
shouldLoadPopupListenerMapToD = Date.now() + 10000;
shouldLoadPopupListenerMap.set(popupURL, openerTabId);
vAPI.tabs.onPopupCreated(popupTabId, openerTabId); vAPI.tabs.onPopupCreated(popupTabId, openerTabId);
break; break;
} }
}
}; };
var shouldLoadPopupListenerAsync = function(e) { var shouldLoadPopupListenerAsync = function(e) {
if ( typeof vAPI.tabs.onPopupCreated !== 'function' ) { if ( typeof vAPI.tabs.onPopupCreated !== '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(

View File

@ -568,23 +568,26 @@ 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) &&
µb.hnSwitches.evaluateZ('no-popups', openerHostname)
) {
return 'ub:no-popups: ' + µb.hnSwitches.z + ' true'; return 'ub:no-popups: ' + µb.hnSwitches.z + ' true';
} }
}
// 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