2018-09-14 16:29:30 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
let scope;
|
2018-09-14 16:29:30 +02:00
|
|
|
if ((typeof exports) !== "undefined"){
|
|
|
|
scope = exports;
|
|
|
|
}
|
|
|
|
else {
|
2019-03-12 22:24:23 +01:00
|
|
|
scope = require.register("./settingsMigration", {});
|
2018-09-14 16:29:30 +02:00
|
|
|
}
|
2019-11-11 15:30:11 +01:00
|
|
|
|
|
|
|
const settingDefinitions = require("./settingDefinitions");
|
|
|
|
|
2020-01-02 11:41:13 +01:00
|
|
|
scope.validVersions = [undefined, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 1.0];
|
2018-09-14 16:29:30 +02:00
|
|
|
scope.transitions = {
|
2019-12-10 15:07:22 +01:00
|
|
|
"": function(){
|
2018-09-14 16:29:30 +02:00
|
|
|
return {
|
2020-01-02 11:41:13 +01:00
|
|
|
storageVersion: 1.0
|
2018-09-14 16:29:30 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
0.1: function(oldStorage){
|
2019-11-28 01:26:35 +01:00
|
|
|
const newStorage = {
|
2018-09-14 16:29:30 +02:00
|
|
|
storageVersion: 0.2
|
|
|
|
};
|
|
|
|
if (oldStorage.hasOwnProperty("askOnlyOnce")){
|
|
|
|
newStorage.askOnlyOnce = oldStorage.askOnlyOnce? "individual": "no";
|
|
|
|
}
|
|
|
|
return newStorage;
|
|
|
|
},
|
|
|
|
0.2: function(oldStorage){
|
2019-11-28 01:26:35 +01:00
|
|
|
const newStorage = {
|
2018-09-14 16:29:30 +02:00
|
|
|
storageVersion: 0.3,
|
|
|
|
urlSettings: (
|
|
|
|
oldStorage.urlSettings &&
|
|
|
|
Array.isArray(oldStorage.urlSettings)
|
|
|
|
)? oldStorage.urlSettings: []
|
|
|
|
};
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const urlSettings = {};
|
2018-09-14 16:29:30 +02:00
|
|
|
|
|
|
|
(oldStorage.blackList || "").split(",")
|
|
|
|
.map(function(url){return url.trim();})
|
|
|
|
.filter(function(url){return !!url;})
|
|
|
|
.forEach(function(url){
|
2019-11-28 01:26:35 +01:00
|
|
|
let entry = urlSettings[url];
|
2018-09-14 16:29:30 +02:00
|
|
|
if (!entry){
|
|
|
|
entry = {url, blockMode: "block"};
|
|
|
|
urlSettings[url] = entry;
|
|
|
|
newStorage.urlSettings.push(entry);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
(oldStorage.whiteList || "").split(",")
|
|
|
|
.map(function(url){return url.trim();})
|
|
|
|
.filter(function(url){return !!url;})
|
|
|
|
.forEach(function(url){
|
2019-11-28 01:26:35 +01:00
|
|
|
let entry = urlSettings[url];
|
2018-09-14 16:29:30 +02:00
|
|
|
if (!entry){
|
|
|
|
entry = {url, blockMode: "allow"};
|
|
|
|
urlSettings[url] = entry;
|
|
|
|
newStorage.urlSettings.push(entry);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
(oldStorage.ignoreList || "").split(",")
|
|
|
|
.map(function(url){return url.trim();})
|
|
|
|
.filter(function(url){return !!url;})
|
|
|
|
.forEach(function(url){
|
2019-11-28 01:26:35 +01:00
|
|
|
let entry = urlSettings[url];
|
2018-09-14 16:29:30 +02:00
|
|
|
if (!entry){
|
|
|
|
entry = {url, showNotifications: false};
|
|
|
|
urlSettings[url] = entry;
|
|
|
|
newStorage.urlSettings.push(entry);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
entry.showNotifications = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
["whiteList", "blackList", "ignoreList"].forEach(function(list){
|
|
|
|
if (oldStorage.hasOwnProperty(list)){
|
|
|
|
newStorage[list] = "";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return newStorage;
|
|
|
|
},
|
|
|
|
0.3: function(oldStorage){
|
2019-11-28 01:26:35 +01:00
|
|
|
const newStorage = {
|
2018-09-14 16:29:30 +02:00
|
|
|
storageVersion: 0.4
|
|
|
|
};
|
|
|
|
if (oldStorage.hasOwnProperty("apiWhiteList")){
|
|
|
|
const protectedAPIFeatures = {};
|
|
|
|
Object.keys(oldStorage.apiWhiteList).forEach(function(key){
|
|
|
|
protectedAPIFeatures[key] = !oldStorage.apiWhiteList[key];
|
|
|
|
});
|
|
|
|
newStorage.protectedAPIFeatures = protectedAPIFeatures;
|
|
|
|
}
|
|
|
|
return newStorage;
|
|
|
|
},
|
2018-10-23 08:26:23 +02:00
|
|
|
0.4: function(oldStorage){
|
2019-11-28 01:26:35 +01:00
|
|
|
const newStorage = {
|
2018-10-23 08:26:23 +02:00
|
|
|
storageVersion: 0.5
|
|
|
|
};
|
|
|
|
|
|
|
|
if (oldStorage.hasOwnProperty("blockMode")){
|
|
|
|
switch (oldStorage.blockMode){
|
|
|
|
case "blockReadout":
|
|
|
|
newStorage.blockMode = "block";
|
|
|
|
newStorage.protectedCanvasPart = "readout";
|
|
|
|
break;
|
|
|
|
case "fakeReadout":
|
|
|
|
newStorage.blockMode = "fake";
|
|
|
|
newStorage.protectedCanvasPart = "readout";
|
|
|
|
break;
|
|
|
|
case "fakeInput":
|
|
|
|
newStorage.blockMode = "fake";
|
|
|
|
newStorage.protectedCanvasPart = "input";
|
|
|
|
break;
|
|
|
|
case "askReadout":
|
|
|
|
newStorage.blockMode = "ask";
|
|
|
|
newStorage.protectedCanvasPart = "readout";
|
|
|
|
break;
|
|
|
|
case "blockEverything":
|
|
|
|
case "block":
|
|
|
|
case "ask":
|
|
|
|
case "allow":
|
|
|
|
case "allowEverything":
|
|
|
|
newStorage.protectedCanvasPart = "everything";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newStorage;
|
2019-11-11 15:30:11 +01:00
|
|
|
},
|
|
|
|
0.5: function(oldStorage){
|
2019-11-28 01:26:35 +01:00
|
|
|
const newStorage = {
|
2019-11-11 15:30:11 +01:00
|
|
|
storageVersion: 0.6
|
|
|
|
};
|
|
|
|
|
|
|
|
if (oldStorage.hasOwnProperty("protectedAPIFeatures")){
|
|
|
|
const protectedAPIFeatures = {};
|
|
|
|
const protectedAPIFeaturesKeys = settingDefinitions.filter(function(definition){
|
|
|
|
return definition.name === "protectedAPIFeatures";
|
|
|
|
})[0].keys.filter(function(key){
|
|
|
|
return typeof key === "string";
|
|
|
|
});
|
|
|
|
Object.keys(oldStorage.protectedAPIFeatures).forEach(function(key){
|
|
|
|
const matchingKeys = protectedAPIFeaturesKeys.filter(function(definedKey){
|
|
|
|
return definedKey.startsWith(key);
|
|
|
|
});
|
|
|
|
if (matchingKeys.length){
|
|
|
|
protectedAPIFeatures[matchingKeys[0]] = oldStorage.protectedAPIFeatures[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
newStorage.protectedAPIFeatures = protectedAPIFeatures;
|
|
|
|
}
|
|
|
|
return newStorage;
|
|
|
|
},
|
2020-01-02 11:41:13 +01:00
|
|
|
0.6: function (oldStorage){
|
|
|
|
const newStorage = {
|
|
|
|
storageVersion: 1.0
|
|
|
|
};
|
|
|
|
if (
|
|
|
|
oldStorage.hasOwnProperty("protectWindow") &&
|
|
|
|
oldStorage.protectWindow &&
|
|
|
|
oldStorage.hasOwnProperty("urlSettings") &&
|
|
|
|
Array.isArray(oldStorage.urlSettings) &&
|
|
|
|
oldStorage.urlSettings.filter(function(entry){
|
|
|
|
return entry.url === "^https://www\\.google\\.com/recaptcha/api2/(?:b?frame|anchor).*$";
|
|
|
|
}).some(function(entry){
|
|
|
|
return entry.protectWindow === false;
|
|
|
|
})
|
|
|
|
){
|
|
|
|
newStorage.allowWindowNameInFrames = true;
|
|
|
|
}
|
|
|
|
return newStorage;
|
|
|
|
}
|
2018-09-14 16:29:30 +02:00
|
|
|
};
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
scope.check = function(storage, {settings, logging}){
|
2018-09-14 16:29:30 +02:00
|
|
|
|
|
|
|
if (!storage.storageVersion){
|
|
|
|
logging.message("No storage version found. Initializing storage.");
|
|
|
|
browser.storage.local.remove(Object.keys(storage));
|
|
|
|
storage = scope.transitions[""]({});
|
|
|
|
browser.storage.local.set(storage);
|
|
|
|
}
|
|
|
|
else if (storage.storageVersion !== settings.storageVersion){
|
2019-11-28 01:26:35 +01:00
|
|
|
const toChange = {};
|
2018-09-14 16:29:30 +02:00
|
|
|
while (storage.storageVersion !== settings.storageVersion){
|
|
|
|
logging.message("Old storage found (",
|
|
|
|
storage.storageVersion, "expected", settings.storageVersion,
|
|
|
|
")");
|
|
|
|
if (scope.transitions[storage.storageVersion]){
|
2019-11-28 01:26:35 +01:00
|
|
|
const changes = scope.transitions[storage.storageVersion](storage);
|
2018-09-14 16:29:30 +02:00
|
|
|
Object.entries(changes).forEach(function(entry){
|
|
|
|
const [name, value] = entry;
|
|
|
|
toChange[name] = value;
|
|
|
|
storage[name] = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2019-09-05 01:07:05 +02:00
|
|
|
logging.error("Unable to migrate storage.");
|
2018-09-14 16:29:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logging.notice("Changed settings:", toChange);
|
|
|
|
browser.storage.local.set(toChange);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}());
|