From c0bfb00be86c1bd6d3517f140baff45486aa2857 Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 20 Apr 2015 00:42:49 -0400 Subject: [PATCH] code review --- platform/firefox/vapi-background.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 38350e4..ccc70a3 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1121,9 +1121,8 @@ var httpObserver = { }; var onBeforeRequest = vAPI.net.onBeforeRequest; - if ( onBeforeRequest.types.size === 0 || onBeforeRequest.types.has(type) ) { + if ( !onBeforeRequest.types || onBeforeRequest.types.has(type) ) { result = onBeforeRequest.callback(callbackDetails); - if ( typeof result === 'object' && result.cancel === true ) { channel.cancel(this.ABORT); return true; @@ -1139,7 +1138,7 @@ var httpObserver = { } var onBeforeSendHeaders = vAPI.net.onBeforeSendHeaders; - if ( onBeforeSendHeaders.types.size === 0 || onBeforeSendHeaders.types.has(type) ) { + if ( !onBeforeSendHeaders.types || onBeforeSendHeaders.types.has(type) ) { callbackDetails.requestHeaders = httpRequestHeadersFactory(channel); result = onBeforeSendHeaders.callback(callbackDetails); callbackDetails.requestHeaders.dispose(); @@ -1148,7 +1147,6 @@ var httpObserver = { channel.cancel(this.ABORT); return true; } - } return false; @@ -1317,8 +1315,12 @@ vAPI.net = {}; /******************************************************************************/ vAPI.net.registerListeners = function() { - this.onBeforeRequest.types = new Set(this.onBeforeRequest.types); - this.onBeforeSendHeaders.types = new Set(this.onBeforeSendHeaders.types); + this.onBeforeRequest.types = this.onBeforeRequest.types ? + new Set(this.onBeforeRequest.types) : + null; + this.onBeforeSendHeaders.types = this.onBeforeSendHeaders.types ? + new Set(this.onBeforeSendHeaders.types) : + null; var shouldLoadListenerMessageName = location.host + ':shouldLoad'; var shouldLoadListener = function(e) {