mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
minor code review re. https://bugzilla.mozilla.org/show_bug.cgi?id=1232354
This commit is contained in:
parent
5704a90cf0
commit
16acbca1fa
@ -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++;
|
||||||
|
@ -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 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMPORTANT:
|
if ( pendingRequest !== null ) {
|
||||||
// If this is a main frame, ensure that the proper tab id is being
|
// https://github.com/gorhill/uBlock/issues/654
|
||||||
// used: it can happen that the wrong tab id was looked up at
|
// Use the request type from the HTTP observer point of view.
|
||||||
// `shouldLoadListener` time. Without this, the popup blocker may
|
if ( rawtype !== 1 ) {
|
||||||
// not work properly, and also a tab opened from a link may end up
|
pendingRequest.rawtype = rawtype;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
}
|
// IMPORTANT:
|
||||||
|
// If this is a main frame, ensure that the proper tab id is being
|
||||||
// Behind-the-scene request... Really?
|
// used: it can happen that the wrong tab id was looked up at
|
||||||
if ( pendingRequest === null ) {
|
// `shouldLoadListener` time. Without this, the popup blocker may
|
||||||
pendingRequest = this.synthesizePendingRequest(channel, rawtype);
|
// 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 ) {
|
||||||
// Behind-the-scene request... Yes, really.
|
var tabId = this.tabIdFromChannel(channel);
|
||||||
if ( pendingRequest === null ) {
|
if ( tabId !== vAPI.noTabId ) {
|
||||||
pendingRequest = {
|
pendingRequest.tabId = tabId;
|
||||||
frameId: 0,
|
}
|
||||||
parentFrameId: -1,
|
}
|
||||||
tabId: vAPI.noTabId,
|
} else { // pendingRequest === null
|
||||||
rawtype: rawtype
|
// No matching pending request found, synthetize one.
|
||||||
};
|
pendingRequest = this.syntheticPendingRequest;
|
||||||
}
|
pendingRequest.tabId = this.tabIdFromChannel(channel);
|
||||||
|
|
||||||
// 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user