From aea695bf8b4543842cc139194a5663135435f280 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 13 May 2015 14:32:16 -0400 Subject: [PATCH] code review --- src/background.html | 2 -- src/js/background.js | 52 +++++++++++++++++++++++++++++++++++++++- src/js/pagestats.js | 2 +- src/js/reqstats.js | 56 -------------------------------------------- src/js/types.js | 40 ------------------------------- 5 files changed, 52 insertions(+), 100 deletions(-) delete mode 100644 src/js/reqstats.js delete mode 100644 src/js/types.js diff --git a/src/background.html b/src/background.html index ad7d259..9770a60 100644 --- a/src/background.html +++ b/src/background.html @@ -10,7 +10,6 @@ - @@ -20,7 +19,6 @@ - diff --git a/src/js/background.js b/src/js/background.js index 8c8f1c6..15ef63e 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -32,6 +32,7 @@ var oneMinute = 60 * oneSecond; var oneHour = 60 * oneMinute; var oneDay = 24 * oneHour; +/******************************************************************************/ /******************************************************************************/ var defaultUserAgentStrings = [ @@ -48,6 +49,54 @@ var defaultUserAgentStrings = [ '' ].join('\n').trim(); +/******************************************************************************/ +/******************************************************************************/ + +var _RequestStats = function() { + this.reset(); +}; + +_RequestStats.prototype.reset = function() { + this.all = + this.doc = + this.frame = + this.script = + this.css = + this.image = + this.plugin = + this.xhr = + this.other = + this.cookie = 0; +}; + +/******************************************************************************/ + +var RequestStats = function() { + this.allowed = new _RequestStats(); + this.blocked = new _RequestStats(); +}; + +RequestStats.prototype.reset = function() { + this.blocked.reset(); + this.allowed.reset(); +}; + +RequestStats.prototype.record = function(type, blocked) { + // Remember: always test against **false** + if ( blocked !== false ) { + this.blocked[type] += 1; + this.blocked.all += 1; + } else { + this.allowed[type] += 1; + this.allowed.all += 1; + } +}; + +var requestStatsFactory = function() { + return new RequestStats(); +}; + +/******************************************************************************/ /******************************************************************************/ return { @@ -100,7 +149,8 @@ return { ubiquitousBlacklist: null, // various stats - requestStats: new WebRequestStats(), + requestStatsFactory: requestStatsFactory, + requestStats: requestStatsFactory(), cookieRemovedCounter: 0, localStorageRemovedCounter: 0, cookieHeaderFoiledCounter: 0, diff --git a/src/js/pagestats.js b/src/js/pagestats.js index d195c35..779128d 100644 --- a/src/js/pagestats.js +++ b/src/js/pagestats.js @@ -321,7 +321,7 @@ var pageStoreFactory = function(tabContext) { /******************************************************************************/ function PageStore(tabContext) { - this.requestStats = new WebRequestStats(); + this.requestStats = µm.requestStatsFactory(); this.off = false; this.init(tabContext); } diff --git a/src/js/reqstats.js b/src/js/reqstats.js deleted file mode 100644 index 829884f..0000000 --- a/src/js/reqstats.js +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - - µMatrix - a Chromium browser extension to black/white list requests. - Copyright (C) 2014 Raymond Hill - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see {http://www.gnu.org/licenses/}. - - Home: https://github.com/gorhill/uMatrix -*/ - -/******************************************************************************/ - -_WebRequestStats.prototype.reset = function() { - this.all = - this.doc = - this.frame = - this.script = - this.css = - this.image = - this.plugin = - this.xhr = - this.other = - this.cookie = 0; -}; - -/******************************************************************************/ - -WebRequestStats.prototype.record = function(type, blocked) { - // Remember: always test against **false** - if ( blocked !== false ) { - this.blocked[type] += 1; - this.blocked.all += 1; - } else { - this.allowed[type] += 1; - this.allowed.all += 1; - } -}; - -/******************************************************************************/ - -WebRequestStats.prototype.reset = function() { - this.blocked.reset(); - this.allowed.reset(); -}; - diff --git a/src/js/types.js b/src/js/types.js deleted file mode 100644 index 0d84984..0000000 --- a/src/js/types.js +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - - µMatrix - a Chromium browser extension to black/white list requests. - Copyright (C) 2014 Raymond Hill - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see {http://www.gnu.org/licenses/}. - - Home: https://github.com/gorhill/uMatrix -*/ - -/******************************************************************************/ - -function _WebRequestStats() { - this.all = - this.doc = - this.css = - this.frame = - this.script = - this.image = - this.plugin = - this.xhr = - this.other = - this.cookie = 0; -} - -function WebRequestStats() { - this.allowed = new _WebRequestStats(); - this.blocked = new _WebRequestStats(); -}