1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-01 16:49:39 +02:00
This commit is contained in:
gorhill 2016-08-06 10:20:11 -04:00
parent 5704a90cf0
commit 16acbca1fa
3 changed files with 35 additions and 55 deletions

View File

@ -248,26 +248,27 @@ var contentObserver = {
return this.ACCEPT; return this.ACCEPT;
} }
let details = { let rpcData = this.rpcData;
frameId: this.getFrameId(context), rpcData.frameId = this.getFrameId(context);
parentFrameId: context.parent === context.top ? 0 : this.getFrameId(context.parent), rpcData.pFrameId = context.parent === context.top ? 0 : this.getFrameId(context.parent);
rawtype: type, rpcData.type = type;
tabId: '', rpcData.url = location.spec;
url: location.spec
};
//console.log('shouldLoad: type=' + type + ' url=' + location.spec); //console.log('shouldLoad: type=' + type + ' url=' + location.spec);
if ( typeof messageManager.sendRpcMessage === 'function' ) { if ( typeof messageManager.sendRpcMessage === 'function' ) {
// https://bugzil.la/1092216 // https://bugzil.la/1092216
messageManager.sendRpcMessage(this.cpMessageName, details); messageManager.sendRpcMessage(this.cpMessageName, rpcData);
} else { } else {
// Compatibility for older versions // Compatibility for older versions
messageManager.sendSyncMessage(this.cpMessageName, details); messageManager.sendSyncMessage(this.cpMessageName, rpcData);
} }
return this.ACCEPT; return this.ACCEPT;
}, },
// Reuse object to avoid repeated memory allocation.
rpcData: { frameId: 0, pFrameId: -1, type: 0, url: '' },
initContentScripts: function(win, create) { initContentScripts: function(win, create) {
let messager = getMessageManager(win); let messager = getMessageManager(win);
let sandboxId = hostName + ':sb:' + this.uniqueSandboxId++; let sandboxId = hostName + ':sb:' + this.uniqueSandboxId++;

View File

@ -2089,19 +2089,7 @@ var httpObserver = {
}, },
// https://github.com/gorhill/uBlock/issues/959 // https://github.com/gorhill/uBlock/issues/959
// Try to synthesize a pending request from a behind-the-scene request. syntheticPendingRequest: { frameId: 0, parentFrameId: -1, tabId: '', rawtype: 1 },
synthesizePendingRequest: function(channel, rawtype) {
var tabId = this.tabIdFromChannel(channel);
if ( tabId === vAPI.noTabId ) {
return null;
}
return {
frameId: 0,
parentFrameId: -1,
tabId: tabId,
rawtype: rawtype
};
},
handleRequest: function(channel, URI, details) { handleRequest: function(channel, URI, details) {
var type = this.typeMap[details.rawtype] || 'other'; var type = this.typeMap[details.rawtype] || 'other';
@ -2244,37 +2232,28 @@ var httpObserver = {
} }
} }
if ( pendingRequest !== null ) {
// https://github.com/gorhill/uBlock/issues/654
// Use the request type from the HTTP observer point of view.
if ( rawtype !== 1 ) {
pendingRequest.rawtype = rawtype;
}
// IMPORTANT: // IMPORTANT:
// If this is a main frame, ensure that the proper tab id is being // If this is a main frame, ensure that the proper tab id is being
// used: it can happen that the wrong tab id was looked up at // used: it can happen that the wrong tab id was looked up at
// `shouldLoadListener` time. Without this, the popup blocker may // `shouldLoadListener` time. Without this, the popup blocker may
// not work properly, and also a tab opened from a link may end up // not work properly, and also a tab opened from a link may end up
// being wrongly reported as an embedded element. // being wrongly reported as an embedded element.
if ( pendingRequest !== null && pendingRequest.rawtype === 6 ) { if ( pendingRequest.rawtype === 6 ) {
var tabId = this.tabIdFromChannel(channel); var tabId = this.tabIdFromChannel(channel);
if ( tabId !== vAPI.noTabId ) { if ( tabId !== vAPI.noTabId ) {
pendingRequest.tabId = tabId; pendingRequest.tabId = tabId;
} }
} }
} else { // pendingRequest === null
// Behind-the-scene request... Really? // No matching pending request found, synthetize one.
if ( pendingRequest === null ) { pendingRequest = this.syntheticPendingRequest;
pendingRequest = this.synthesizePendingRequest(channel, rawtype); pendingRequest.tabId = this.tabIdFromChannel(channel);
}
// Behind-the-scene request... Yes, really.
if ( pendingRequest === null ) {
pendingRequest = {
frameId: 0,
parentFrameId: -1,
tabId: vAPI.noTabId,
rawtype: rawtype
};
}
// https://github.com/gorhill/uBlock/issues/654
// Use the request type from the HTTP observer point of view.
if ( rawtype !== 1 ) {
pendingRequest.rawtype = rawtype; pendingRequest.rawtype = rawtype;
} }
@ -2401,8 +2380,8 @@ vAPI.net.registerListeners = function() {
// request into a ring buffer for later retrieval by the HTTP observer. // request into a ring buffer for later retrieval by the HTTP observer.
var pendingReq = httpObserver.createPendingRequest(details.url); var pendingReq = httpObserver.createPendingRequest(details.url);
pendingReq.frameId = details.frameId; pendingReq.frameId = details.frameId;
pendingReq.parentFrameId = details.parentFrameId; pendingReq.parentFrameId = details.pFrameId;
pendingReq.rawtype = details.rawtype; pendingReq.rawtype = details.type;
pendingReq.tabId = tabWatcher.tabIdFromTarget(e.target); pendingReq.tabId = tabWatcher.tabIdFromTarget(e.target);
}; };

View File

@ -1516,7 +1516,7 @@ vAPI.executionCost.stop('domIsLoaded');
/******************************************************************************/ /******************************************************************************/
if ( document.readyState !== 'loading' ) { if ( document.readyState !== 'loading' ) {
domIsLoaded(); window.requestAnimationFrame(domIsLoaded);
} else { } else {
document.addEventListener('DOMContentLoaded', domIsLoaded); document.addEventListener('DOMContentLoaded', domIsLoaded);
} }