From 4d7109bf993534bc1833c74642d749cb8c8489c5 Mon Sep 17 00:00:00 2001 From: Ryan Hendrickson Date: Mon, 31 Dec 2018 19:24:15 +0000 Subject: [PATCH] Cleaning (#1007) * remove unused field distinctRequestCount * remove mostly unused RequestStats * write to pageStore.pageUrl, not pageStore.normalURL * remove unused cookie code * remove unused field off --- src/js/background.js | 49 -------------------------------------------- src/js/cookies.js | 44 +-------------------------------------- src/js/messaging.js | 2 +- src/js/pagestats.js | 11 ---------- src/js/tab.js | 2 +- 5 files changed, 3 insertions(+), 105 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 76a1980..3c81606 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -32,53 +32,6 @@ var oneMinute = 60 * oneSecond; var oneHour = 60 * oneMinute; var oneDay = 24 * oneHour; -/******************************************************************************/ -/******************************************************************************/ - -var _RequestStats = function() { - this.reset(); -}; - -_RequestStats.prototype.reset = function() { - this.all = - this.doc = - this.frame = - this.script = - this.css = - this.image = - this.media = - 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(); -}; - /******************************************************************************* SVG-based icons below were extracted from @@ -231,8 +184,6 @@ return { ubiquitousBlacklist: null, // various stats - requestStatsFactory: requestStatsFactory, - requestStats: requestStatsFactory(), cookieRemovedCounter: 0, localStorageRemovedCounter: 0, cookieHeaderFoiledCounter: 0, diff --git a/src/js/cookies.js b/src/js/cookies.js index 890bfb4..36029f8 100644 --- a/src/js/cookies.js +++ b/src/js/cookies.js @@ -40,14 +40,12 @@ var µm = µMatrix; var recordPageCookiesQueue = new Map(); -var removePageCookiesQueue = new Map(); var removeCookieQueue = new Set(); var cookieDict = new Map(); var cookieEntryJunkyard = []; var processRemoveQueuePeriod = 2 * 60 * 1000; var processCleanPeriod = 10 * 60 * 1000; var processPageRecordQueueTimer = null; -var processPageRemoveQueueTimer = null; /******************************************************************************/ @@ -260,24 +258,6 @@ var recordPageCookie = (function() { /******************************************************************************/ -// Look for cookies to potentially remove for a specific web page - -var removePageCookiesAsync = function(pageStats) { - // Hold onto pageStats objects so that it doesn't go away - // before we handle the job. - // rhill 2013-10-19: pageStats could be nil, for example, this can - // happens if a file:// ... makes an xmlHttpRequest - if ( !pageStats ) { - return; - } - removePageCookiesQueue.set(pageStats.pageUrl, pageStats); - if ( processPageRemoveQueueTimer === null ) { - processPageRemoveQueueTimer = vAPI.setTimeout(processPageRemoveQueue, 15 * 1000); - } -}; - -/******************************************************************************/ - // Candidate for removal var removeCookieAsync = function(cookieKey) { @@ -332,17 +312,6 @@ var processPageRecordQueue = function() { /******************************************************************************/ -var processPageRemoveQueue = function() { - processPageRemoveQueueTimer = null; - - for ( var pageStore of removePageCookiesQueue.values() ) { - findAndRemovePageCookies(pageStore); - } - removePageCookiesQueue.clear(); -}; - -/******************************************************************************/ - // Effectively remove cookies. var processRemoveQueue = function() { @@ -442,16 +411,6 @@ var findAndRecordPageCookies = function(pageStore) { /******************************************************************************/ -var findAndRemovePageCookies = function(pageStore) { - for ( var cookieKey of cookieDict.keys() ) { - if ( cookieMatchDomains(cookieKey, pageStore.allHostnamesString) ) { - removeCookieAsync(cookieKey); - } - } -}; - -/******************************************************************************/ - var canRemoveCookie = function(cookieKey, srcHostnames) { var cookieEntry = cookieDict.get(cookieKey); if ( cookieEntry === undefined ) { return false; } @@ -587,8 +546,7 @@ vAPI.setTimeout(processClean, processCleanPeriod); // Expose only what is necessary return { - recordPageCookies: recordPageCookiesAsync, - removePageCookies: removePageCookiesAsync + recordPageCookies: recordPageCookiesAsync }; /******************************************************************************/ diff --git a/src/js/messaging.js b/src/js/messaging.js index 8495702..6738ef1 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -226,7 +226,7 @@ var matrixSnapshot = function(pageStore, details) { let r = { appVersion: vAPI.app.version, - blockedCount: pageStore.requestStats.blocked.all, + blockedCount: pageStore.perLoadBlockedRequestCount, collapseAllDomains: µmuser.popupCollapseAllDomains, collapseBlacklistedDomains: µmuser.popupCollapseBlacklistedDomains, diff: [], diff --git a/src/js/pagestats.js b/src/js/pagestats.js index 2954da8..04a777b 100644 --- a/src/js/pagestats.js +++ b/src/js/pagestats.js @@ -104,8 +104,6 @@ var PageStore = function(tabContext) { this.hostnameTypeCells = new Map(); this.domains = new Set(); this.blockedCollapsibles = new BlockedCollapsibles(); - this.requestStats = µm.requestStatsFactory(); - this.off = false; this.init(tabContext); }; @@ -125,8 +123,6 @@ PageStore.prototype = { this.domains.clear(); this.allHostnamesString = ' '; this.blockedCollapsibles.reset(); - this.requestStats.reset(); - this.distinctRequestCount = 0; this.perLoadAllowedRequestCount = 0; this.perLoadBlockedRequestCount = 0; this.perLoadBlockedReferrerCount = 0; @@ -232,15 +228,8 @@ PageStore.prototype = { if ( uids.has(uid) ) { return; } uids.add(uid); - // Count blocked/allowed requests - this.requestStats.record(type, block); - - // https://github.com/gorhill/httpswitchboard/issues/306 - // If it is recorded locally, record globally - µm.requestStats.record(type, block); µm.updateBadgeAsync(this.tabId); - this.distinctRequestCount++; this.mtxCountModifiedTime = Date.now(); if ( this.domains.has(hostname) === false ) { diff --git a/src/js/tab.js b/src/js/tab.js index 34f1876..4581214 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -472,7 +472,7 @@ vAPI.tabs.registerListeners(); pageStore.pageHostname === tabContext.rootHostname ) { pageStore.rawURL = tabContext.rawURL; - pageStore.normalURL = normalURL; + pageStore.pageUrl = normalURL; this.updateTitle(tabId); this.pageStoresToken = Date.now(); return pageStore;