mirror of https://github.com/gorhill/uBlock.git
Merge branch 'next'
This commit is contained in:
commit
523f9f479d
|
@ -68,6 +68,7 @@ var contentObserver = {
|
||||||
classID: Components.ID('{7afbd130-cbaf-46c2-b944-f5d24305f484}'),
|
classID: Components.ID('{7afbd130-cbaf-46c2-b944-f5d24305f484}'),
|
||||||
contractID: '@' + hostName + '/content-policy;1',
|
contractID: '@' + hostName + '/content-policy;1',
|
||||||
ACCEPT: Ci.nsIContentPolicy.ACCEPT,
|
ACCEPT: Ci.nsIContentPolicy.ACCEPT,
|
||||||
|
REJECT: Ci.nsIContentPolicy.REJECT_REQUEST,
|
||||||
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||||
SUB_FRAME: Ci.nsIContentPolicy.TYPE_SUBDOCUMENT,
|
SUB_FRAME: Ci.nsIContentPolicy.TYPE_SUBDOCUMENT,
|
||||||
contentBaseURI: 'chrome://' + hostName + '/content/js/',
|
contentBaseURI: 'chrome://' + hostName + '/content/js/',
|
||||||
|
@ -204,17 +205,23 @@ var contentObserver = {
|
||||||
openerURL: openerURL,
|
openerURL: openerURL,
|
||||||
parentFrameId: parentFrameId,
|
parentFrameId: parentFrameId,
|
||||||
rawtype: type,
|
rawtype: type,
|
||||||
|
tabId: '',
|
||||||
url: location.spec
|
url: location.spec
|
||||||
};
|
};
|
||||||
|
|
||||||
//console.log('shouldLoad: type=' + type' ' + 'url=' + location.spec);
|
//console.log('shouldLoad: type=' + type' ' + 'url=' + location.spec);
|
||||||
|
var r;
|
||||||
if ( typeof messageManager.sendRpcMessage === 'function' ) {
|
if ( typeof messageManager.sendRpcMessage === 'function' ) {
|
||||||
// https://bugzil.la/1092216
|
// https://bugzil.la/1092216
|
||||||
messageManager.sendRpcMessage(this.cpMessageName, details);
|
r = messageManager.sendRpcMessage(this.cpMessageName, details);
|
||||||
} else {
|
} else {
|
||||||
// Compatibility for older versions
|
// Compatibility for older versions
|
||||||
messageManager.sendSyncMessage(this.cpMessageName, details);
|
r = messageManager.sendSyncMessage(this.cpMessageName, details);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Important: hard test against `false`.
|
||||||
|
if ( Array.isArray(r) && r.length !== 0 && r[0] === false ) {
|
||||||
|
return this.REJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.ACCEPT;
|
return this.ACCEPT;
|
||||||
|
|
|
@ -2104,24 +2104,12 @@ vAPI.net.registerListeners = function() {
|
||||||
new Set(this.onBeforeRequest.types) :
|
new Set(this.onBeforeRequest.types) :
|
||||||
null;
|
null;
|
||||||
|
|
||||||
var shouldLoadListenerMessageName = location.host + ':shouldLoad';
|
var shouldBlockPopup = function(details) {
|
||||||
var shouldLoadListener = function(e) {
|
|
||||||
// Non blocking: it is assumed that the http observer is fired after
|
|
||||||
// shouldLoad recorded the pending requests. If this is not the case,
|
|
||||||
// a request would end up being categorized as a behind-the-scene
|
|
||||||
// requests.
|
|
||||||
var details = e.data;
|
|
||||||
var tabId = tabWatcher.tabIdFromTarget(e.target);
|
|
||||||
var sourceTabId = null;
|
var sourceTabId = null;
|
||||||
|
var uri;
|
||||||
|
|
||||||
// Popup candidate: this code path is taken only for when a new top
|
|
||||||
// document loads, i.e. only once per document load. TODO: evaluate for
|
|
||||||
// popup filtering in an asynchrous manner -- it's not really required
|
|
||||||
// to evaluate on the spot. Still, there is currently no harm given
|
|
||||||
// this code path is typically taken only once per page load.
|
|
||||||
if ( details.openerURL ) {
|
|
||||||
for ( var browser of tabWatcher.browsers() ) {
|
for ( var browser of tabWatcher.browsers() ) {
|
||||||
var URI = browser.currentURI;
|
uri = browser.currentURI;
|
||||||
|
|
||||||
// Probably isn't the best method to identify the source tab.
|
// Probably isn't the best method to identify the source tab.
|
||||||
|
|
||||||
|
@ -2131,25 +2119,66 @@ 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 !== details.openerURL ) {
|
if ( !uri || uri.spec !== details.openerURL ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceTabId = tabWatcher.tabIdFromTarget(browser);
|
sourceTabId = tabWatcher.tabIdFromTarget(browser);
|
||||||
|
if ( sourceTabId === details.tabId ) {
|
||||||
if ( sourceTabId === tabId ) {
|
|
||||||
sourceTabId = null;
|
sourceTabId = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
URI = Services.io.newURI(details.url, null, null);
|
uri = Services.io.newURI(details.url, null, null);
|
||||||
|
|
||||||
if ( httpObserver.handlePopup(URI, tabId, sourceTabId) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
httpObserver.handlePopup(uri, details.tabId, sourceTabId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sourceTabId;
|
||||||
|
};
|
||||||
|
|
||||||
|
var shouldLoadMedia = function(details) {
|
||||||
|
var uri = Services.io.newURI(details.url, null, null);
|
||||||
|
|
||||||
|
var r = vAPI.net.onBeforeRequest.callback({
|
||||||
|
frameId: details.frameId,
|
||||||
|
hostname: uri.asciiHost,
|
||||||
|
parentFrameId: details.parentFrameId,
|
||||||
|
tabId: details.tabId,
|
||||||
|
type: 'media',
|
||||||
|
url: uri.asciiSpec
|
||||||
|
});
|
||||||
|
|
||||||
|
return typeof r !== 'object' || r === null;
|
||||||
|
};
|
||||||
|
|
||||||
|
var shouldLoadListenerMessageName = location.host + ':shouldLoad';
|
||||||
|
var shouldLoadListener = function(e) {
|
||||||
|
// Non blocking: it is assumed that the http observer is fired after
|
||||||
|
// shouldLoad recorded the pending requests. If this is not the case,
|
||||||
|
// a request would end up being categorized as a behind-the-scene
|
||||||
|
// requests.
|
||||||
|
var details = e.data;
|
||||||
|
var sourceTabId = null;
|
||||||
|
var mustLoad;
|
||||||
|
|
||||||
|
details.tabId = tabWatcher.tabIdFromTarget(e.target);
|
||||||
|
|
||||||
|
// Popup candidate: this code path is taken only for when a new top
|
||||||
|
// document loads, i.e. only once per document load. TODO: evaluate for
|
||||||
|
// popup filtering in an asynchrous manner -- it's not really required
|
||||||
|
// to evaluate on the spot. Still, there is currently no harm given
|
||||||
|
// this code path is typically taken only once per page load.
|
||||||
|
if ( details.openerURL ) {
|
||||||
|
sourceTabId = shouldBlockPopup(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/868
|
||||||
|
// Firefox quirk: for some reasons, there are instances of resources
|
||||||
|
// for `video` tag not being reported to HTTP observers.
|
||||||
|
if ( details.rawtype === 15 ) {
|
||||||
|
mustLoad = shouldLoadMedia(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are being called synchronously from the content process, so we
|
// We are being called synchronously from the content process, so we
|
||||||
|
@ -2160,7 +2189,9 @@ vAPI.net.registerListeners = function() {
|
||||||
pendingReq.parentFrameId = details.parentFrameId;
|
pendingReq.parentFrameId = details.parentFrameId;
|
||||||
pendingReq.rawtype = details.rawtype;
|
pendingReq.rawtype = details.rawtype;
|
||||||
pendingReq.sourceTabId = sourceTabId;
|
pendingReq.sourceTabId = sourceTabId;
|
||||||
pendingReq.tabId = tabId;
|
pendingReq.tabId = details.tabId;
|
||||||
|
|
||||||
|
return mustLoad;
|
||||||
};
|
};
|
||||||
|
|
||||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||||
|
|
Loading…
Reference in New Issue