From 42e81a13818f2c42314d794da5b830b9eee0f3f0 Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 26 May 2014 11:49:36 -0400 Subject: [PATCH] this fixes #306 --- js/contentscripthandlers.js | 38 ++++++++++++++++++++++--------------- js/cookies.js | 1 - js/tab.js | 4 ++++ js/traffic.js | 6 ------ manifest.json | 2 +- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/js/contentscripthandlers.js b/js/contentscripthandlers.js index 4252d31..22276ba 100644 --- a/js/contentscripthandlers.js +++ b/js/contentscripthandlers.js @@ -34,6 +34,7 @@ var contentScriptSummaryHandler = function(details, sender) { } var httpsb = HTTPSB; var pageURL = httpsb.pageUrlFromTabId(sender.tab.id); + var pageStats = httpsb.pageStatsFromPageUrl(pageURL); var httpsburi = httpsb.URI.set(details.locationURL); var frameURL = httpsburi.normalizedURI(); var urls, url, r; @@ -45,27 +46,34 @@ var contentScriptSummaryHandler = function(details, sender) { // scripts // https://github.com/gorhill/httpswitchboard/issues/25 - urls = details.scriptSources; - for ( url in urls ) { - if ( !urls.hasOwnProperty(url) ) { - continue; + if ( pageStats && pageStats.pageScriptBlocked ) { + urls = details.scriptSources; + for ( url in urls ) { + if ( !urls.hasOwnProperty(url) ) { + continue; + } + if ( url === '{inline_script}' ) { + url = frameURL + '{inline_script}'; + } + r = httpsb.filterRequest(pageURL, 'script', url); + pageStats.recordRequest('script', url, r !== false, r); } - if ( url === '{inline_script}' ) { - url = frameURL + '{inline_script}'; - } - r = httpsb.filterRequest(pageURL, 'script', url); - httpsb.recordFromPageUrl(pageURL, 'script', url, r !== false, r); } + // TODO: as of 2014-05-26, not sure this is needed anymore, since HTTPSB + // no longer uses chrome.contentSettings API (I think that was the reason + // this code was put in). // plugins // https://github.com/gorhill/httpswitchboard/issues/25 - urls = details.pluginSources; - for ( url in urls ) { - if ( !urls.hasOwnProperty(url) ) { - continue; + if ( pageStats ) { + urls = details.pluginSources; + for ( url in urls ) { + if ( !urls.hasOwnProperty(url) ) { + continue; + } + r = httpsb.filterRequest(pageURL, 'object', url); + pageStats.recordRequest('object', url, r !== false, r); } - r = httpsb.filterRequest(pageURL, 'object', url); - httpsb.recordFromPageUrl(pageURL, 'object', url, r !== false, r); } // https://github.com/gorhill/httpswitchboard/issues/181 diff --git a/js/cookies.js b/js/cookies.js index e736763..1edb372 100644 --- a/js/cookies.js +++ b/js/cookies.js @@ -229,7 +229,6 @@ var recordPageCookie = function(pageStats, cookieKey) { cookieLogEntryBuilder.join(''), block ); - httpsb.requestStats.record('cookie', block); // rhill 2013-11-21: // https://github.com/gorhill/httpswitchboard/issues/65 diff --git a/js/tab.js b/js/tab.js index e79f01a..756effa 100644 --- a/js/tab.js +++ b/js/tab.js @@ -91,6 +91,10 @@ PageStatsEntry.prototype.recordRequest = function(type, url, block, reason) { // Count blocked/allowed requests this.requestStats.record(type, block); + // https://github.com/gorhill/httpswitchboard/issues/306 + // If it is recorded locally, record globally + httpsb.requestStats.record(type, block); + if ( block !== false ) { this.perLoadBlockedRequestCount++; } else { diff --git a/js/traffic.js b/js/traffic.js index 7c9acc2..4f51a1d 100644 --- a/js/traffic.js +++ b/js/traffic.js @@ -220,9 +220,6 @@ var onBeforeRootFrameRequestHandler = function(details) { // console.debug('onBeforeRequestHandler()> block=%s "%s": %o', block, details.url, details); - // Collect global stats - httpsb.requestStats.record('main_frame', block); - // whitelisted? if ( !block ) { // rhill 2013-11-07: Senseless to do this for behind-the-scene requests. @@ -358,9 +355,6 @@ var onBeforeRequestHandler = function(details) { // Page stats pageStats.recordRequest(requestType, requestURL, block, reason); - // Global stats - httpsb.requestStats.record(requestType, block); - // whitelisted? if ( !block ) { // console.debug('onBeforeRequestHandler()> ALLOW "%s": %o', details.url, details); diff --git a/manifest.json b/manifest.json index ca5c453..efcff9e 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "__MSG_extName__", "short_name": "HTTPSB", - "version": "0.9.5.3", + "version": "0.9.5.4", "description": "__MSG_extShortDesc__", "icons": { "16": "icon_16.png",