From 8ae33e9c125db5e020da8efcd87cd3e36036e4b6 Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 21 Apr 2015 17:38:54 -0400 Subject: [PATCH] FF: this fixes availability of response headers for when item pulled from cache --- platform/firefox/vapi-background.js | 14 +++++++++++--- src/js/traffic.js | 7 +++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 8ded8b3..5cfff68 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1054,6 +1054,7 @@ var httpObserver = { register: function() { Services.obs.addObserver(this, 'http-on-opening-request', true); Services.obs.addObserver(this, 'http-on-examine-response', true); + Services.obs.addObserver(this, 'http-on-examine-cached-response', true); // Guard against stale instances not having been unregistered if ( this.componentRegistrar.isCIDRegistered(this.classID) ) { @@ -1082,6 +1083,7 @@ var httpObserver = { unregister: function() { Services.obs.removeObserver(this, 'http-on-opening-request'); Services.obs.removeObserver(this, 'http-on-examine-response'); + Services.obs.removeObserver(this, 'http-on-examine-cached-response'); this.componentRegistrar.unregisterFactory(this.classID, this); this.categoryManager.deleteCategoryEntry( @@ -1155,6 +1157,8 @@ var httpObserver = { return false; }, + // https://developer.mozilla.org/en/docs/Observer_Notifications#HTTP_requests + // observe: function(channel, topic) { if ( channel instanceof Ci.nsIHttpChannel === false ) { return; @@ -1163,7 +1167,10 @@ var httpObserver = { var URI = channel.URI; var channelData, type, result; - if ( topic === 'http-on-examine-response' ) { + if ( + topic === 'http-on-examine-response' || + topic === 'http-on-examine-cached-response' + ) { if ( !(channel instanceof Ci.nsIWritablePropertyBag) ) { return; } @@ -1606,11 +1613,12 @@ vAPI.toolbarButton.onBeforeCreated = function(doc) { panel.parentNode.style.maxWidth = 'none'; // We set a limit for height var height = Math.min(body.clientHeight, 600); + var width = body.clientWidth; // https://github.com/chrisaljoudi/uBlock/issues/730 // Voodoo programming: this recipe works panel.style.height = iframe.style.height = height.toString() + 'px'; - panel.style.width = iframe.style.width = body.clientWidth.toString() + 'px'; - if ( iframe.clientHeight !== height || iframe.clientWidth !== body.clientWidth ) { + panel.style.width = iframe.style.width = width.toString() + 'px'; + if ( iframe.clientHeight !== height || iframe.clientWidth !== width ) { delayedResize(); } }; diff --git a/src/js/traffic.js b/src/js/traffic.js index 489d23d..33340bf 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -497,7 +497,7 @@ var onMainDocHeadersReceived = function(details) { // https://github.com/gorhill/httpswitchboard/issues/112 // rhill 2014-02-10: Handle all redirects. // https://github.com/gorhill/httpswitchboard/issues/188 - if ( /\b30[12378]\b/.test(details.statusLine) ) { + if ( reStatusRedirect.test(details.statusLine) ) { var i = headerIndexFromName('location', headers); if ( i >= 0 ) { // rhill 2014-01-20: Be ready to handle relative URLs. @@ -513,7 +513,7 @@ var onMainDocHeadersReceived = function(details) { // rhill 2014-01-15: Report redirects if any. // https://github.com/gorhill/httpswitchboard/issues/112 - if ( details.statusLine.indexOf(' 200') > 0 ) { + if ( reStatusOK.test(details.statusLine) ) { var mainFrameStack = [requestURL]; var destinationURL = requestURL; var sourceURL; @@ -555,6 +555,9 @@ var onMainDocHeadersReceived = function(details) { } }; +var reStatusOK = /\b(?:200|304)\b/; +var reStatusRedirect = /\b30[12378]\b/; + /******************************************************************************/ var onSubDocHeadersReceived = function(details) {