From 77e079e5cc40fa0a4bcc1d0e79318373fb485af1 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Thu, 4 Jan 2018 13:36:18 +0100 Subject: [PATCH] Added showCanvasWhileAsking Fixes #175 --- _locales/de/messages.json | 14 +++++++++++++ _locales/en/messages.json | 14 +++++++++++++ lib/askForPermission.js | 41 ++++++++++++++++++++++++++++++++++++++ lib/intercept.js | 8 +++++++- lib/settingDefinitions.js | 4 ++++ options/settingsDisplay.js | 7 +++++++ releaseNotes.txt | 2 +- 7 files changed, 88 insertions(+), 2 deletions(-) diff --git a/_locales/de/messages.json b/_locales/de/messages.json index 4d6c529..c65b5b1 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -153,6 +153,20 @@ "message": "vortäuschen", "description": "" }, + + "showCanvasWhileAsking_title":{ + "message": "Canvas-Inhalt anzeigen", + "description": "" + }, + "showCanvasWhileAsking_description":{ + "message": "Wenn möglich wird der Inhalt des Canvas angezeigt, bei dem um Erlaubnis gefragt wird.", + "description": "" + }, + "showCanvasWhileAsking_message":{ + "message": "Die Webseite will den Inhalt des folgenden Canvas auslesen:", + "description": "" + }, + "blackList_description": { "message": "Domänen oder URLs, die die -API niemals verwenden dürfen. Mehrere Einträge müssen durch ein Komma getrennt werden.", "description": "" diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 5fb3784..3a503e4 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -153,6 +153,20 @@ "message": "fake", "description": "" }, + + "showCanvasWhileAsking_title":{ + "message": "Show canvas content", + "description": "" + }, + "showCanvasWhileAsking_description":{ + "message": "Shows the content of the canvas for which the permission is asked if possible.", + "description": "" + }, + "showCanvasWhileAsking_message":{ + "message": "The web page wants to read the content of the following canvas:", + "description": "" + }, + "blackList_description": { "message": "Domains or URLs where the -API should always be blocked. To add multiple entries, separate them by commas.", "description": "" diff --git a/lib/askForPermission.js b/lib/askForPermission.js index 03ec567..34f01ec 100644 --- a/lib/askForPermission.js +++ b/lib/askForPermission.js @@ -131,12 +131,53 @@ return askStatus.answer[appearance.askCategory]; } else { + let imgContainer = null; + if (type === "readout" && prefs("showCanvasWhileAsking") && canvas){ + try { + let content = canvas.toDataURL(); + let document = window.top.document; + imgContainer = document.createElement("div"); + imgContainer.style.cssText = ` + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(0, 0, 0, 0.7); + color: white; + text-align: center; + z-index: 100000000000000; + padding: 1em;`; + + let heading = document.createElement("h1"); + heading.textContent = "CanvasBlocker"; + imgContainer.appendChild(heading); + + let text = document.createElement("div"); + text.style.margin = "0.5em auto"; + text.textContent = browser.i18n.getMessage("showCanvasWhileAsking_message"); + imgContainer.appendChild(text); + + let img = document.createElement("img"); + img.style.backgroundColor = "white"; + img.style.border = "2px solid lightgray"; + img.src = HTMLCanvasElement.prototype.toDataURL.call(canvas); + imgContainer.appendChild(img); + document.body.appendChild(imgContainer); + } + catch (e){ + // unable to read the canvas + } + } // asking var msg = askMode.askText[appearance.text]; if (prefs("showCallingFile")){ msg += parseErrorStack(errorStack).toString(_); } answer = window.top.confirm(msg)? "allow": prefs("askDenyMode"); + if (imgContainer && imgContainer.parentNode){ + imgContainer.parentNode.removeChild(imgContainer); + } if (prefs("askOnlyOnce") === "combined"){ ["context", "readout", "input"].forEach(function(type){ diff --git a/lib/intercept.js b/lib/intercept.js index 5629740..4cd9084 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -232,7 +232,13 @@ funcStatus.mode = ask({ window: window, type: changedFunction.type, - canvas: this, + canvas: this instanceof HTMLCanvasElement? + this: + ( + this.canvas instanceof HTMLCanvasElement? + this.canvas: + false + ), errorStack: error.stack }); } diff --git a/lib/settingDefinitions.js b/lib/settingDefinitions.js index b045acd..33a08d2 100644 --- a/lib/settingDefinitions.js +++ b/lib/settingDefinitions.js @@ -106,6 +106,10 @@ defaultValue: "block", options: ["block", "fake"] }, + { + name: "showCanvasWhileAsking", + defaultValue: true + }, { name: "showNotifications", defaultValue: true, diff --git a/options/settingsDisplay.js b/options/settingsDisplay.js index 32d17a9..83ff2b2 100644 --- a/options/settingsDisplay.js +++ b/options/settingsDisplay.js @@ -27,6 +27,13 @@ "displayAdvancedSettings": [true] } }, + { + "name": "showCanvasWhileAsking", + "displayDependencies": { + "blockMode": ["askReadout", "ask"], + "displayAdvancedSettings": [true] + } + }, "faking", { "name": "minFakeSize", diff --git a/releaseNotes.txt b/releaseNotes.txt index 78dc76d..9141ca1 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -3,7 +3,7 @@ Version 0.4.5: - new features: - - + - Added way to inspect canvas content in ask mode while being asked fixes: - prevent possible double faking