Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Cleaning #1007

Merged
merged 5 commits into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -232,8 +185,6 @@ return {
ubiquitousBlacklist: null,

// various stats
requestStatsFactory: requestStatsFactory,
requestStats: requestStatsFactory(),
cookieRemovedCounter: 0,
localStorageRemovedCounter: 0,
cookieHeaderFoiledCounter: 0,
Expand Down
44 changes: 1 addition & 43 deletions src/js/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/******************************************************************************/

Expand Down Expand Up @@ -259,24 +257,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) {
Expand Down Expand Up @@ -328,17 +308,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() {
Expand Down Expand Up @@ -438,16 +407,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; }
Expand Down Expand Up @@ -577,8 +536,7 @@ vAPI.setTimeout(processClean, processCleanPeriod);
// Expose only what is necessary

return {
recordPageCookies: recordPageCookiesAsync,
removePageCookies: removePageCookiesAsync
recordPageCookies: recordPageCookiesAsync
};

/******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var matrixSnapshot = function(pageStore, details) {

var r = {
appVersion: vAPI.app.version,
blockedCount: pageStore.requestStats.blocked.all,
blockedCount: pageStore.perLoadBlockedRequestCount,
collapseAllDomains: µmuser.popupCollapseAllDomains,
collapseBlacklistedDomains: µmuser.popupCollapseBlacklistedDomains,
diff: [],
Expand Down
11 changes: 0 additions & 11 deletions src/js/pagestats.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,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);
};

Expand All @@ -119,8 +117,6 @@ PageStore.prototype = {
this.domains.clear();
this.allHostnamesString = ' ';
this.blockedCollapsibles.reset();
this.requestStats.reset();
this.distinctRequestCount = 0;
this.perLoadAllowedRequestCount = 0;
this.perLoadBlockedRequestCount = 0;
this.has3pReferrer = false;
Expand Down Expand Up @@ -227,15 +223,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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,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;
Expand Down