Browse Source

fix #554

pull/2/head
gorhill 9 years ago
parent
commit
73646ed7ce
  1. 44
      platform/firefox/vapi-background.js

44
platform/firefox/vapi-background.js

@ -1722,7 +1722,6 @@ var httpObserver = {
this.pendingRingBufferInit(); this.pendingRingBufferInit();
// https://developer.mozilla.org/en/docs/Observer_Notifications#HTTP_requests // https://developer.mozilla.org/en/docs/Observer_Notifications#HTTP_requests
Services.obs.addObserver(this, 'http-on-opening-request', true);
Services.obs.addObserver(this, 'http-on-modify-request', true); Services.obs.addObserver(this, 'http-on-modify-request', true);
Services.obs.addObserver(this, 'http-on-examine-response', true); Services.obs.addObserver(this, 'http-on-examine-response', true);
Services.obs.addObserver(this, 'http-on-examine-cached-response', true); Services.obs.addObserver(this, 'http-on-examine-cached-response', true);
@ -1752,7 +1751,6 @@ var httpObserver = {
}, },
unregister: function() { unregister: function() {
Services.obs.removeObserver(this, 'http-on-opening-request');
Services.obs.removeObserver(this, 'http-on-modify-request'); Services.obs.removeObserver(this, 'http-on-modify-request');
Services.obs.removeObserver(this, 'http-on-examine-response'); Services.obs.removeObserver(this, 'http-on-examine-response');
Services.obs.removeObserver(this, 'http-on-examine-cached-response'); Services.obs.removeObserver(this, 'http-on-examine-cached-response');
@ -1840,11 +1838,9 @@ var httpObserver = {
handleRequest: function(channel, URI, tabId, rawType) { handleRequest: function(channel, URI, tabId, rawType) {
var type = this.typeMap[rawType] || 'other'; var type = this.typeMap[rawType] || 'other';
var onBeforeRequest = vAPI.net.onBeforeRequest;
if ( onBeforeRequest.types && onBeforeRequest.types.has(type) === false ) {
return false;
}
var onBeforeRequest = vAPI.net.onBeforeRequest;
if ( onBeforeRequest.types === null || onBeforeRequest.types.has(type) ) {
var result = onBeforeRequest.callback({ var result = onBeforeRequest.callback({
hostname: URI.asciiHost, hostname: URI.asciiHost,
parentFrameId: type === 'main_frame' ? -1 : 0, parentFrameId: type === 'main_frame' ? -1 : 0,
@ -1852,21 +1848,14 @@ var httpObserver = {
type: type, type: type,
url: URI.asciiSpec url: URI.asciiSpec
}); });
if ( typeof result !== 'object' ) {
return false;
}
if ( typeof result === 'object' ) {
channel.cancel(this.ABORT); channel.cancel(this.ABORT);
return true; return true;
},
}
}
handleRequestHeaders: function(channel, URI, tabId, rawType) {
var type = this.typeMap[rawType] || 'other';
var onBeforeSendHeaders = vAPI.net.onBeforeSendHeaders; var onBeforeSendHeaders = vAPI.net.onBeforeSendHeaders;
if ( onBeforeSendHeaders.types && onBeforeSendHeaders.types.has(type) === false ) {
return;
}
if ( onBeforeSendHeaders.types === null || onBeforeSendHeaders.types.has(type) ) {
var requestHeaders = httpRequestHeadersFactory(channel); var requestHeaders = httpRequestHeadersFactory(channel);
onBeforeSendHeaders.callback({ onBeforeSendHeaders.callback({
hostname: URI.asciiHost, hostname: URI.asciiHost,
@ -1877,6 +1866,9 @@ var httpObserver = {
url: URI.asciiSpec url: URI.asciiSpec
}); });
requestHeaders.dispose(); requestHeaders.dispose();
}
return false;
}, },
channelDataFromChannel: function(channel) { channelDataFromChannel: function(channel) {
@ -1996,18 +1988,7 @@ var httpObserver = {
return; return;
} }
if ( topic === 'http-on-modify-request' ) {
channelData = this.channelDataFromChannel(channel);
if ( channelData === null ) {
return;
}
this.handleRequestHeaders(channel, URI, channelData[0], channelData[1]);
return;
}
// http-on-opening-request
// http-on-modify-request
var tabId; var tabId;
var pendingRequest = this.lookupPendingRequest(URI.asciiSpec); var pendingRequest = this.lookupPendingRequest(URI.asciiSpec);
var rawType = 1; var rawType = 1;
@ -2060,12 +2041,11 @@ var httpObserver = {
return; return;
} }
if ( !(oldChannel instanceof Ci.nsIWritablePropertyBag) ) {
var channelData = this.channelDataFromChannel(oldChannel);
if ( channelData === null ) {
return; return;
} }
var channelData = oldChannel.getProperty(this.REQDATAKEY);
if ( this.handleRequest(newChannel, URI, channelData[0], channelData[1]) ) { if ( this.handleRequest(newChannel, URI, channelData[0], channelData[1]) ) {
result = this.ABORT; result = this.ABORT;
return; return;

Loading…
Cancel
Save