1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 04:49:12 +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;
}
let details = {
frameId: this.getFrameId(context),
parentFrameId: context.parent === context.top ? 0 : this.getFrameId(context.parent),
rawtype: type,
tabId: '',
url: location.spec
};
let rpcData = this.rpcData;
rpcData.frameId = this.getFrameId(context);
rpcData.pFrameId = context.parent === context.top ? 0 : this.getFrameId(context.parent);
rpcData.type = type;
rpcData.url = location.spec;
//console.log('shouldLoad: type=' + type + ' url=' + location.spec);
if ( typeof messageManager.sendRpcMessage === 'function' ) {
// https://bugzil.la/1092216
messageManager.sendRpcMessage(this.cpMessageName, details);
messageManager.sendRpcMessage(this.cpMessageName, rpcData);
} else {
// Compatibility for older versions
messageManager.sendSyncMessage(this.cpMessageName, details);
messageManager.sendSyncMessage(this.cpMessageName, rpcData);
}
return this.ACCEPT;
},
// Reuse object to avoid repeated memory allocation.
rpcData: { frameId: 0, pFrameId: -1, type: 0, url: '' },
initContentScripts: function(win, create) {
let messager = getMessageManager(win);
let sandboxId = hostName + ':sb:' + this.uniqueSandboxId++;

View File

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

View File

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