diff --git a/_locales/de/messages.json b/_locales/de/messages.json index ec3b7a5..eeb234d 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -667,6 +667,18 @@ "message": "Geben Sie die URL \"RegExp\" ein, die für diese Sitzung erlaubt werden soll:", "description": "" }, + "selectWhitelistScope": { + "message": "Was soll erlaubt werden?", + "description": "" + }, + "whitelistOnlyAPI": { + "message": "Erlaube nur die \"{api}\" API.", + "description": "" + }, + "whitelistAllAPIs": { + "message": "Erlaube alle APIs.", + "description": "" + }, "settings": { "message": "Einstellungen", "description": "" diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 4ec10e9..d1238a5 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -701,6 +701,18 @@ "message": "Input URL \"RegExp\" to add to the session whitelist:", "description": "" }, + "selectWhitelistScope": { + "message": "What is the scope of the whitelisting?", + "description": "" + }, + "whitelistOnlyAPI": { + "message": "Whitelist only the API \"{api}\".", + "description": "" + }, + "whitelistAllAPIs": { + "message": "Whitelist all APIs.", + "description": "" + }, "settings": { "message": "settings", "description": "" diff --git a/lib/frame.js b/lib/frame.js index c8a1c1f..1282d25 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -76,7 +76,13 @@ if (settings.storeNotificationData){ notifications.push(data); } - notificationCounter[data.messageId] = (notificationCounter[data.messageId] || 0) + 1; + if (!notificationCounter[data.messageId]){ + notificationCounter[data.messageId] = { + count: 0, + api: data.api + }; + } + notificationCounter[data.messageId].count += 1; if (!sentAPIs[data.api]){ sentAPIs[data.api] = true; port.postMessage({"canvasBlocker-notify": data}); diff --git a/pageAction/domainNotification.js b/pageAction/domainNotification.js index 198deae..9a434da 100644 --- a/pageAction/domainNotification.js +++ b/pageAction/domainNotification.js @@ -26,7 +26,7 @@ }; }(); - const DomainNotification = function DomainNotification(domain, messageId, count = 0){ + const DomainNotification = function DomainNotification(domain, messageId, count = 0, api = ""){ if (domain instanceof URL){ this.urls().add(domain.href); domain = domain.hostname; @@ -34,6 +34,7 @@ this.domain = domain; this.messageId = messageId; this.count = count; + this.api = api; this.extraNotifications = 0; addToContainer(this); this.update(); @@ -148,7 +149,7 @@ DomainNotification.prototype.actionsNode = function actionsNode(){ const node = document.createElement("div"); node.className = "actions"; - createActionButtons(node, actions, {domain: this.domain, urls: this.urls()}); + createActionButtons(node, actions, {domain: this.domain, urls: this.urls(), api: this.api}); this.actionsNode = function(){ return node; }; @@ -165,11 +166,11 @@ }; const domains = new Map(); - const domainNotification = function(url, messageId, count = 0){ + const domainNotification = function(url, messageId, count = 0, api = ""){ const domain = url.hostname; var domainNotification = domains.get(domain + messageId); if (!domainNotification){ - domainNotification = new DomainNotification(url, messageId, count); + domainNotification = new DomainNotification(url, messageId, count, api); domains.set(domain + messageId, domainNotification); } else { diff --git a/pageAction/pageAction.js b/pageAction/pageAction.js index 0a9f7ae..659e363 100644 --- a/pageAction/pageAction.js +++ b/pageAction/pageAction.js @@ -120,15 +120,60 @@ { name: "whitelist", isIcon: true, - callback: function({domain, urls}){ + callback: function({domain, urls, api}){ + const whitelistingSettings = { + all: {name: "blockMode", value: "allow"}, + canvas: {name: "protectedCanvasPart", value: "nothing"}, + audio: {name: "protectAudio", value: false}, + domRect: {name: "protectDOMRect", value: false}, + history: {name: "historyLengthThreshold", value: 10000}, + navigator: {name: "protectNavigator", value: false}, + windows: {name: "protectWindow", value: false} + + }; domainOrUrlPicker( domain, urls, extension.getTranslation("selectWhitelist"), extension.getTranslation("inputWhitelistURL") ).then(function(choice){ + const allAPIs = { + choice, + setting: "blockMode", + settingValue: "allow" + }; + const onlyAPI = { + choice, + setting: whitelistingSettings[api], + settingValue: false + }; + if ( + api && + whitelistingSettings[api] + ){ + return modalChoice( + extension.getTranslation("selectWhitelistScope"), + [ + { + text: extension.getTranslation("whitelistOnlyAPI") + .replace(/\{api\}/g, api), + value: api + }, + { + text: extension.getTranslation("whitelistAllAPIs"), + value: "all" + } + ] + ).then(function(selection){ + return {choice, setting: whitelistingSettings[selection]}; + }); + } + else { + return {choice, setting: whitelistingSettings.all}; + } + }).then(function({choice, setting}){ if (choice){ - settings.set("blockMode", "allow", choice).then(function(){ + settings.set(setting.name, setting.value, choice).then(function(){ window.close(); }); } @@ -184,14 +229,15 @@ }); var tab = tabs[0]; - browser.runtime.onMessage.addListener(function(data){ + extension.message.on(function(data){ if (data["canvasBlocker-notificationCounter"]){ const url = new URL(data.url); Object.keys(data["canvasBlocker-notificationCounter"]).forEach(function(key){ const notification = domainNotification( url, key, - data["canvasBlocker-notificationCounter"][key] + data["canvasBlocker-notificationCounter"][key].count, + data["canvasBlocker-notificationCounter"][key].api ); }); } @@ -218,7 +264,9 @@ notification.url = new URL(notification.url); domainNotification( notification.url, - notification.messageId + notification.messageId, + 0, + notification.api ).addNotification(new Notification(notification)); } i += delta;