mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-01 16:49:39 +02:00
code review re. https://github.com/gorhill/uMatrix/issues/554: use channel data when available
This commit is contained in:
parent
f43e51bac9
commit
84b81f751c
@ -2016,6 +2016,15 @@ 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.
|
// Try to synthesize a pending request from a behind-the-scene request.
|
||||||
synthesizePendingRequest: function(channel, rawtype) {
|
synthesizePendingRequest: function(channel, rawtype) {
|
||||||
|
var data = this.channelDataFromChannel(channel);
|
||||||
|
if ( data !== null ) {
|
||||||
|
return {
|
||||||
|
frameId: data[0],
|
||||||
|
parentFrameId: data[1],
|
||||||
|
tabId: data[2],
|
||||||
|
rawtype: data[3]
|
||||||
|
};
|
||||||
|
}
|
||||||
var tabId = this.tabIdFromChannel(channel);
|
var tabId = this.tabIdFromChannel(channel);
|
||||||
if ( tabId === vAPI.noTabId ) {
|
if ( tabId === vAPI.noTabId ) {
|
||||||
return null;
|
return null;
|
||||||
@ -2116,34 +2125,45 @@ var httpObserver = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
channelDataFromChannel: function(channel) {
|
||||||
|
if ( channel instanceof Ci.nsIWritablePropertyBag ) {
|
||||||
|
try {
|
||||||
|
return channel.getProperty(this.REQDATAKEY) || null;
|
||||||
|
} catch (ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
observe: function(channel, topic) {
|
observe: function(channel, topic) {
|
||||||
if ( channel instanceof Ci.nsIHttpChannel === false ) {
|
if ( channel instanceof Ci.nsIHttpChannel === false ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var URI = channel.URI;
|
var URI = channel.URI;
|
||||||
|
var channelData = this.channelDataFromChannel(channel);
|
||||||
|
|
||||||
if ( topic === 'http-on-examine-response' ) {
|
if ( topic === 'http-on-examine-response' ) {
|
||||||
if ( channel instanceof Ci.nsIWritablePropertyBag === false ) {
|
if ( channelData !== null ) {
|
||||||
return;
|
this.handleResponseHeaders(channel, URI, channelData);
|
||||||
}
|
}
|
||||||
|
|
||||||
var channelData;
|
|
||||||
try {
|
|
||||||
channelData = channel.getProperty(this.REQDATAKEY);
|
|
||||||
} catch (ex) {
|
|
||||||
}
|
|
||||||
if ( !channelData ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handleResponseHeaders(channel, URI, channelData);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// http-on-modify-request
|
// http-on-modify-request
|
||||||
|
|
||||||
|
// The channel was previously serviced.
|
||||||
|
if ( channelData !== null ) {
|
||||||
|
this.handleRequest(channel, URI, {
|
||||||
|
frameId: channelData[0],
|
||||||
|
parentFrameId: channelData[1],
|
||||||
|
tabId: channelData[2],
|
||||||
|
rawtype: channelData[3]
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The channel was never serviced.
|
||||||
var pendingRequest = this.lookupPendingRequest(URI.spec);
|
var pendingRequest = this.lookupPendingRequest(URI.spec);
|
||||||
|
|
||||||
// https://github.com/gorhill/uMatrix/issues/390#issuecomment-155759004
|
// https://github.com/gorhill/uMatrix/issues/390#issuecomment-155759004
|
||||||
|
Loading…
Reference in New Issue
Block a user