From a465303fffc03b8aba6545d7f96945c1b1da41bc Mon Sep 17 00:00:00 2001 From: kkapsner Date: Fri, 10 Nov 2017 23:45:09 +0100 Subject: [PATCH] askOnly once extended API-types can now be combined in "askOnlyOnce". Needed new storage version -> added settings migration --- _locales/de/messages.json | 20 ++++++++-- _locales/en/messages.json | 20 ++++++++-- lib/askForPermission.js | 17 ++++++-- lib/main.js | 7 ---- lib/settingDefinitions.js | 6 ++- lib/settings.js | 81 +++++++++++++++++++++++++++++++-------- releaseNotes.txt | 3 +- 7 files changed, 116 insertions(+), 38 deletions(-) diff --git a/_locales/de/messages.json b/_locales/de/messages.json index d7956cf..681b2b2 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -70,14 +70,26 @@ "message": "Wollen Sie das Auslesen des rot umrandeten erlauben?", "description": "" }, - "askOnlyOnce_description": { - "message": "Wenn der Blockiermodus des Canvas Blockers auf \"um Erlaubnis fragen\" oder \"bei Auslese-API um Erlaubnis fragen\" gesetzt ist, erscheint jedes Mal ein Abfragedialog, wenn eine Seite versucht, die (Auslese-)API aufzurufen. Diese Einstellung versucht diese Abfrage nur einmal pro Seite anzuzeigen, unabhängig davon wie oft die API aufgerufen wird. Es können trotzdem mehrere Dialoge pro Seite erscheinen.", - "description": "" - }, "askOnlyOnce_title": { "message": "Nur einmal nachfragen", "description": "" }, + "askOnlyOnce_description": { + "message": "Wenn der Blockiermodus des Canvas Blockers auf \"um Erlaubnis fragen\" oder \"bei Auslese-API um Erlaubnis fragen\" gesetzt ist, erscheint jedes Mal ein Abfragedialog wenn eine Seite versucht, die (Auslese-)API aufzurufen. Diese Einstellung versucht diese Abfrage nur einmal pro Seite anzuzeigen, unabhängig davon wie oft die API aufgerufen wird. Es können trotzdem mehrere Dialoge pro Seite erscheinen.\nNein: es wird jedes mal gefragt\nIndividuell: jeder API-Typ (Context, Eingabe, Auslese) wird separat abgefragt\nKombiniert: alle API-Typen werden zusammen abgefragt", + "description": "" + }, + "askOnlyOnce_options.no": { + "message": "nein", + "description": "" + }, + "askOnlyOnce_options.individual": { + "message": "individuell", + "description": "" + }, + "askOnlyOnce_options.combined": { + "message": "kombiniert", + "description": "" + }, "askDenyMode_title":{ "message": "Nachfrageverweigerungsmodus", "description": "" diff --git a/_locales/en/messages.json b/_locales/en/messages.json index bd507e5..7db245a 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -70,14 +70,26 @@ "message": "Do you want to allow the readout of the red bordered ?", "description": "" }, - "askOnlyOnce_description": { - "message": "When Canvas Blocker's Block mode is set to 'ask permission' or 'ask permission for readout API', a confirm message will appear every time a page tries to access the API or readout API. This setting tries to display the confirm message only once for each page regardless of how many times the page tries to access the API. Nevertheless, multiple confirm messages may still be displayed on some pages.", - "description": "" - }, "askOnlyOnce_title": { "message": "Ask only once", "description": "" }, + "askOnlyOnce_description": { + "message": "When Canvas Blocker's Block mode is set to 'ask permission' or 'ask permission for readout API', a confirm message will appear every time a page tries to access the API or readout API. This setting tries to display the confirm message only once for each page regardless of how many times the page tries to access the API. Nevertheless, multiple confirm messages may still be displayed on some pages.\nNo: asking every time\nIndividual: each API-type (context, input, readout) has to be confirmed seperately\ncombined: all API-types get confirmed together", + "description": "" + }, + "askOnlyOnce_options.no": { + "message": "no", + "description": "" + }, + "askOnlyOnce_options.individual": { + "message": "individual", + "description": "" + }, + "askOnlyOnce_options.combined": { + "message": "combined", + "description": "" + }, "askDenyMode_title":{ "message": "Ask deny mode", "description": "" diff --git a/lib/askForPermission.js b/lib/askForPermission.js index 3a913c7..c4624cb 100644 --- a/lib/askForPermission.js +++ b/lib/askForPermission.js @@ -125,7 +125,7 @@ var askMode = getAskMode(window, type, _); var askStatus = askMode.askStatus; var appearance = canvasAppearance(window, canvas); - if (prefs("askOnlyOnce") && askStatus.alreadyAsked[appearance.askCategory]){ + if (prefs("askOnlyOnce") !== "no" && askStatus.alreadyAsked[appearance.askCategory]){ // already asked appearance.reset(); return askStatus.answer[appearance.askCategory]; @@ -137,8 +137,19 @@ msg += parseErrorStack(errorStack).toString(_); } answer = window.confirm(msg)? "allow": prefs("askDenyMode"); - askStatus.alreadyAsked[appearance.text] = true; - askStatus.answer[appearance.text] = answer; + + if (prefs("askOnlyOnce") === "combined"){ + ["context", "readout", "input"].forEach(function(type){ + var askMode = getAskMode(window, type, _); + var askStatus = askMode.askStatus; + askStatus.alreadyAsked[appearance.text] = true; + askStatus.answer[appearance.text] = answer; + }); + } + else { + askStatus.alreadyAsked[appearance.text] = true; + askStatus.answer[appearance.text] = answer; + } appearance.reset(); return answer; } diff --git a/lib/main.js b/lib/main.js index 5e3f6e5..ac184dc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -91,13 +91,6 @@ browser.runtime.onInstalled.addListener(function(){ message("CanvasBlocker installed"); - browser.storage.local.get("storageVersion").then(function(data){ - if (data.storageVersion !== 0.1){ - browser.storage.local.set({ - storageVersion: 0.1 - }); - } - }); }); message("end"); diff --git a/lib/settingDefinitions.js b/lib/settingDefinitions.js index ff4cc1c..4f9fa43 100644 --- a/lib/settingDefinitions.js +++ b/lib/settingDefinitions.js @@ -74,7 +74,8 @@ }, { name: "askOnlyOnce", - defaultValue: true + defaultValue: "individual", + options: ["no", "individual", "combined"] }, { name: "askDenyMode", @@ -123,7 +124,8 @@ }, { name: "storageVersion", - defaultValue: 0.1 + defaultValue: 0.2, + fixed: true } ]; diff --git a/lib/settings.js b/lib/settings.js index d451fde..104c33a 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -48,25 +48,26 @@ return settings[name]; }; settingDefinition.set = function setValue(newValue){ - if ((typeof newValue) === (typeof settingDefinition.defaultValue)){ - if ( - !settingDefinition.options || - settingDefinition.options.includes(newValue) - ){ - settings[name] = newValue; - if (!settingDefinition.transient){ - var storeObject = {}; - storeObject[name] = newValue; - browser.storage.local.set(storeObject); - } - - } - else { - logging.warning("Provided value outside specified options for ", name, ":", newValue); - } + if (settingDefinition.fixed){ + logging.warning("Trying to set the fixed setting", name, ":", newValue); + } + else if ((typeof newValue) !== (typeof settingDefinition.defaultValue)){ + logging.warning("Wrong type provided for setting", name, ":", newValue); + } + else if ( + settingDefinition.options && + !settingDefinition.options.includes(newValue) + ){ + logging.warning("Provided value outside specified options for ", name, ":", newValue); } else { - logging.warning("Wrong type provided for setting", name, ":", newValue); + settings[name] = newValue; + if (!settingDefinition.transient){ + var storeObject = {}; + storeObject[name] = newValue; + browser.storage.local.set(storeObject); + } + } }; Object.defineProperty( @@ -134,10 +135,56 @@ }); } }); + + const settingsMigration = { + validVersions: [undefined, 0.1, 0.2], + transitions: { + "": function(oldStorage){ + return { + storageVersion: 0.2 + }; + }, + 0.1: function(oldStorage){ + var newStorage = { + storageVersion: 0.2 + }; + if (oldStorage.hasOwnProperty("askOnlyOnce")){ + newStorage.askOnlyOnce = oldStorage.askOnlyOnce? "individual": "no"; + } + return newStorage; + } + } + }; logging.verbose("loading settings"); scope.loaded = browser.storage.local.get().then(function(storage){ logging.message("settings loaded"); + if (!storage.storageVersion){ + logging.message("No storage version found. Initializing storage."); + browser.storage.local.remove(Object.keys(storage)); + storage = settingsMigration.transitions[""]({}); + browser.storage.local.set(storage); + } + else if (storage.storageVersion !== settings.storageVersion){ + var toChange = {}; + while (storage.storageVersion !== settings.storageVersion){ + logging.message("Old storage found. Storage version", storage.storageVersion); + if (settingsMigration.transitions[storage.storageVersion]){ + var changes = settingsMigration.transitions[storage.storageVersion](storage); + Object.entries(changes).forEach(function(entry){ + const [name, value] = entry; + toChange[name] = value; + storage[name] = value; + }); + } + else { + logging.warning("Unable to migrate storage."); + break; + } + } + logging.notice("Changed settings:", toChange); + browser.storage.local.set(toChange); + } Object.entries(storage).forEach(function(entry){ const [name, value] = entry; changeValue(name, value); diff --git a/releaseNotes.txt b/releaseNotes.txt index e3cbe48..55da5c2 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -2,11 +2,12 @@ Version 0.4.1: changes: - improved design of the page action display - Enabled Firefox ESR - - persistent random generator data is always stored in the settings but cleared on restart if the store flag is not set + - persistent random generator data is always stored in the settings but cleared on restart if the store flag is not set new features: - setting to set an interval to clear the persistent random generator data - setting for the ask deny mode + - ask only once can now also combine the API-types fixes: - unnecessary check for context type in getImageData broke websites