From 49441de2b6176bc129e9e4cc30942300d1e59be4 Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 28 Oct 2014 23:21:06 -0400 Subject: [PATCH] bring back `doc` req type; many little fixes --- src/info.html | 10 +++++----- src/js/httpsb.js | 1 + src/js/info.js | 29 +++++++++++------------------ src/js/matrix.js | 17 +++++++++-------- src/js/popup.js | 16 ++++++---------- src/js/reqstats.js | 10 +++++----- src/js/storage.js | 6 ++++++ src/js/tab.js | 4 ++-- src/js/traffic.js | 4 ++-- src/js/types.js | 10 +++++----- 10 files changed, 52 insertions(+), 55 deletions(-) diff --git a/src/info.html b/src/info.html index c08a9a7..36bebf5 100644 --- a/src/info.html +++ b/src/info.html @@ -143,16 +143,16 @@ tr.unused {

 Show: - + - - + + - - + +

diff --git a/src/js/httpsb.js b/src/js/httpsb.js index 50179fd..25439d2 100644 --- a/src/js/httpsb.js +++ b/src/js/httpsb.js @@ -32,6 +32,7 @@ µm.pMatrix.setSwitch(µm.behindTheSceneScope, false); µm.pMatrix.setSwitch('opera-scheme', false); µm.pMatrix.setCell('*', '*', '*', µm.Matrix.Red); + µm.pMatrix.setCell('*', '*', 'doc', µm.Matrix.Green); µm.pMatrix.setCell('*', '*', 'css', µm.Matrix.Green); µm.pMatrix.setCell('*', '*', 'image', µm.Matrix.Green); µm.pMatrix.setCell('*', '*', 'frame', µm.Matrix.Red); diff --git a/src/js/info.js b/src/js/info.js index 4821d7b..9ae393c 100644 --- a/src/js/info.js +++ b/src/js/info.js @@ -30,12 +30,6 @@ messaging.start('info.js'); var targetUrl = 'all'; var maxRequests = 500; var cachedUserSettings = {}; -var tableFriendlyTypeNames = { - 'main_frame': 'page', - 'stylesheet': 'css', - 'sub_frame': 'frame', - 'xmlhttprequest': 'xhr' -}; /******************************************************************************/ @@ -162,24 +156,24 @@ function renderStats() { renderNumbers({ '#blockedAllCount': requestStats.blocked.all, - '#blockedMainFrameCount': blockedStats.main_frame, + '#blockedMainFrameCount': blockedStats.doc, '#blockedCookieCount': blockedStats.cookie, - '#blockedStylesheetCount': blockedStats.stylesheet, + '#blockedStylesheetCount': blockedStats.css, '#blockedImageCount': blockedStats.image, - '#blockedObjectCount': blockedStats.object, + '#blockedObjectCount': blockedStats.plugin, '#blockedScriptCount': blockedStats.script, - '#blockedXHRCount': blockedStats.xmlhttprequest, - '#blockedSubFrameCount': blockedStats.sub_frame, + '#blockedXHRCount': blockedStats.xhr, + '#blockedSubFrameCount': blockedStats.frame, '#blockedOtherCount': blockedStats.other, '#allowedAllCount': allowedStats.all, - '#allowedMainFrameCount': allowedStats.main_frame, + '#allowedMainFrameCount': allowedStats.doc, '#allowedCookieCount': allowedStats.cookie, - '#allowedStylesheetCount': allowedStats.stylesheet, + '#allowedStylesheetCount': allowedStats.css, '#allowedImageCount': allowedStats.image, - '#allowedObjectCount': allowedStats.object, + '#allowedObjectCount': allowedStats.plugin, '#allowedScriptCount': allowedStats.script, - '#allowedXHRCount': allowedStats.xmlhttprequest, - '#allowedSubFrameCount': allowedStats.sub_frame, + '#allowedXHRCount': allowedStats.xhr, + '#allowedSubFrameCount': allowedStats.frame, '#allowedOtherCount': allowedStats.other }); @@ -216,8 +210,7 @@ function renderRequestRow(row, request) { $(cells[0]).text(when.toLocaleTimeString()); // request type - var text = tableFriendlyTypeNames[request.type] || request.type; - $(cells[1]).text(text); + $(cells[1]).text(request.type); // Well I got back full control since not using Tempo.js, I can now // generate smarter hyperlinks, that is, not hyperlinking fake diff --git a/src/js/matrix.js b/src/js/matrix.js index 64ed450..004f98a 100644 --- a/src/js/matrix.js +++ b/src/js/matrix.js @@ -58,14 +58,15 @@ Matrix.GrayIndirect = Matrix.Gray | Matrix.Indirect; var typeBitOffsets = { '*': 0, - 'cookie': 2, - 'css': 4, - 'image': 6, - 'plugin': 8, - 'script': 10, - 'xhr': 12, - 'frame': 14, - 'other': 16 + 'doc': 2, + 'cookie': 4, + 'css': 6, + 'image': 8, + 'plugin': 10, + 'script': 12, + 'xhr': 14, + 'frame': 16, + 'other': 18 }; var stateToNameMap = { diff --git a/src/js/popup.js b/src/js/popup.js index 2832b8f..cbeb57b 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -633,8 +633,9 @@ function makeMatrixMetaRow(totals) { function computeMatrixGroupMetaStats(group) { var headers = matrixSnapshot.headers; - var i = Object.keys(headers).length - var totals = new Array(i); + var n = Object.keys(headers).length + var totals = new Array(n); + var i = n; while ( i-- ) { totals[i] = 0; } @@ -651,14 +652,9 @@ function computeMatrixGroupMetaStats(group) { continue; } totals[0] += 1; - totals[1] += row.counts[headers.cookie]; - totals[2] += row.counts[headers.css]; - totals[3] += row.counts[headers.image]; - totals[4] += row.counts[headers.plugin]; - totals[5] += row.counts[headers.script]; - totals[6] += row.counts[headers.xhr]; - totals[7] += row.counts[headers.frame]; - totals[8] += row.counts[headers.other]; + for ( i = 1; i < n; i++ ) { + totals[i] += row.counts[i]; + } } return totals; } diff --git a/src/js/reqstats.js b/src/js/reqstats.js index 3e0ce8a..829884f 100644 --- a/src/js/reqstats.js +++ b/src/js/reqstats.js @@ -23,13 +23,13 @@ _WebRequestStats.prototype.reset = function() { this.all = - this.main_frame = - this.sub_frame = + this.doc = + this.frame = this.script = - this.stylesheet = + this.css = this.image = - this.object = - this.xmlhttprequest = + this.plugin = + this.xhr = this.other = this.cookie = 0; }; diff --git a/src/js/storage.js b/src/js/storage.js index a139836..aae40bc 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -85,6 +85,12 @@ var onLoaded = function(bin) { if ( bin.hasOwnProperty('userMatrix') ) { µm.pMatrix.fromString(bin.userMatrix); + // Bring back the `doc` type, should not have removed it, it is + // quite useful. + // TODO: remove this before offical release, as everybody + // should have it in their rules at this point. + µm.pMatrix.setCell('*', '*', 'doc', µm.Matrix.Green); + µm.saveMatrix(); µm.tMatrix.assign(µm.pMatrix); } }; diff --git a/src/js/tab.js b/src/js/tab.js index 140e2f7..f88faaf 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -249,9 +249,9 @@ // https://github.com/gorhill/httpswitchboard/issues/141 if ( !mustReload ) { var reloadNewlyBlockedTypes = { - 'main_frame': true, + 'doc': true, 'script' : true, - 'sub_frame': true + 'frame': true }; var blockRuleType; for ( blockRule in newState ) { diff --git a/src/js/traffic.js b/src/js/traffic.js index 35a6037..fdc77ff 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -177,7 +177,7 @@ var onBeforeChromeExtensionRequestHandler = function(details) { // Is the target page still blacklisted? var pageURL = decodeURIComponent(matches[1]); var hostname = decodeURIComponent(matches[2]); - if ( µm.mustBlock(µm.scopeFromURL(pageURL), hostname, '*') ) { + if ( µm.mustBlock(µm.scopeFromURL(pageURL), hostname, 'doc') ) { return; } @@ -216,7 +216,7 @@ var onBeforeRootFrameRequestHandler = function(details) { var requestHostname = uri.hostname; var pageStats = µm.pageStatsFromTabId(tabId); var pageURL = µm.pageUrlFromPageStats(pageStats); - var block = µm.evaluateURL(pageURL, requestHostname, '*') === µm.Matrix.RedDirect; + var block = µm.mustBlock(pageStats.pageHostname, requestHostname, 'doc'); // console.debug('onBeforeRequestHandler()> block=%s "%s": %o', block, details.url, details); diff --git a/src/js/types.js b/src/js/types.js index 0946eec..0d84984 100644 --- a/src/js/types.js +++ b/src/js/types.js @@ -23,13 +23,13 @@ function _WebRequestStats() { this.all = - this.main_frame = - this.stylesheet = - this.sub_frame = + this.doc = + this.css = + this.frame = this.script = this.image = - this.object = - this.xmlhttprequest = + this.plugin = + this.xhr = this.other = this.cookie = 0; }