1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

separate persistent random numbers for incognito windows

This commit is contained in:
kkapsner 2018-07-28 14:13:14 +02:00
parent 7f1fe0ed1c
commit 9b18631768
6 changed files with 61 additions and 18 deletions

View file

@ -12,12 +12,13 @@
scope = {};
window.scope.persistentRndStorage = scope;
}
const settings = require("./settings");
const logging = require("./logging");
scope.persistentRnd = Object.create(null);
scope.persistentIncognitoRnd = Object.create(null);
scope.init = function init(){
logging.message("initializing persistent rng storage");
@ -74,6 +75,16 @@
return settings.persistentRndClearIntervalValue * units[settings.persistentRndClearIntervalUnit] || 0;
};
}();
browser.windows.onRemoved.addListener(function(){
browser.windows.getAll().then(function(windows){
if (windows.every(function(window){
return !window.incognito;
})){
clearIncognito();
}
});
});
let clearTimeout;
function registerTimeout(){
@ -98,19 +109,30 @@
});
});
}
function clearIncognito(){
scope.persistentIncognitoRnd = Object.create(null);
settings.persistentIncognitoRndStorage = JSON.stringify(scope.persistentIncognitoRnd);
}
function clear(){
logging.verbose("domain rnd cleared");
scope.persistentRnd = Object.create(null);
settings.persistentRndStorage = JSON.stringify(scope.persistentRnd);
settings.lastPersistentRndClearing = Date.now();
clearIncognito();
registerTimeout();
broadcast({"canvasBlocker-clear-domain-rnd": true});
}
function setDomainData(domain, rnd){
logging.verbose("got new domain rnd for ", domain, ":", rnd);
scope.persistentRnd[domain] = rnd;
settings.persistentRndStorage = JSON.stringify(scope.persistentRnd);
broadcast({"canvasBlocker-set-domain-rnd": {domain, rnd}});
function setDomainData(domain, incognito, rnd){
logging.verbose("got new domain rnd for ", domain, " (incognito:", incognito, "):", rnd);
if (incognito){
scope.persistentIncognitoRnd[domain] = rnd;
settings.persistentIncognitoRndStorage = JSON.stringify(scope.persistentIncognitoRnd);
}
else {
scope.persistentRnd[domain] = rnd;
settings.persistentRndStorage = JSON.stringify(scope.persistentRnd);
}
broadcast({"canvasBlocker-set-domain-rnd": {domain, incognito, rnd}});
}
scope.clear = clear;