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

Decoupled block mode from protected part

Fixes #287
This commit is contained in:
kkapsner 2018-10-23 08:26:23 +02:00
parent 5932ac2292
commit 8b9197a68a
17 changed files with 356 additions and 211 deletions

View file

@ -21,21 +21,19 @@
scope.check = function check({url, errorStack}){
url = new URL(url || "about:blank");
var match = checkBoth(errorStack, url, settings.get("blockMode", url)).match(
/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/
/^(block|allow|fake|ask)(|Everything|Internal)$/
);
if (match){
return {
url: url,
type: (match[2] === "Everything" || match[2] === "")?
["context", "readout", "input"]:
[match[2].toLowerCase()],
internal: match[2] === "Internal",
mode: match[1]
};
}
else {
return {
url: url,
type: ["context", "readout", "input"],
internal: false,
mode: "block"
};
}
@ -72,21 +70,9 @@
mode = "block";
break;
case "block":
case "blockContext":
case "blockReadout":
case "blockInput":
case "ask":
case "askContext":
case "askReadout":
case "askInput":
case "fake":
case "fakeContext":
case "fakeReadout":
case "fakeInput":
case "allow":
case "allowContext":
case "allowReadout":
case "allowInput":
if (url && lists.get("white").match(url)){
mode = "allow";
}

View file

@ -17,7 +17,7 @@
const logging = require("./logging");
const {copyCanvasToWebgl} = require("./webgl");
const getWrapped = require("sdk/getWrapped");
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
const {checkerWrapper} = require("./modifiedAPIFunctions");
const modifiedAudioAPI = require("./modifiedAudioAPI");
const modifiedDOMRectAPI = require("./modifiedDOMRectAPI");
@ -153,6 +153,27 @@
}
}
function getProtectedPartChecker(pref, url){
const protectedPart = pref("protectedCanvasPart", url);
if (protectedPart === "everything"){
return function(){
return true;
};
}
else {
return function(parts){
if (Array.isArray(parts)){
return parts.some(function(part){
return part === protectedPart;
});
}
else {
return parts === protectedPart;
}
};
}
}
scope.setRandomSupply = function(supply){
randomSupply = supply;
modifiedAudioAPI.setRandomSupply(supply);
@ -163,15 +184,15 @@
scope.changedFunctions = {
getContext: {
type: "context",
getStatus: function(obj, status){
if (hasType(status, "internal")){
getStatus: function(obj, status, prefs){
if (status.internal){
return {
mode: "allow",
type: status.type,
active: false
};
}
else if (hasType(status, "context") || hasType(status, "input")){
else if (getProtectedPartChecker(prefs, status.url)("input")){
return {
mode: status.mode,
type: status.type,
@ -197,10 +218,11 @@
},
toDataURL: {
type: "readout",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "readout");
if (!status.active && hasType(status, "input")){
status.active = protectedPartChecker("readout");
if (!status.active && protectedPartChecker("input")){
var contextType = canvasContextType.get(obj);
status.active = contextType !== "2d";
}
@ -227,10 +249,11 @@
},
toBlob: {
type: "readout",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "readout");
if (!status.active && hasType(status, "input")){
status.active = protectedPartChecker("readout");
if (!status.active && protectedPartChecker("input")){
var contextType = canvasContextType.get(obj);
status.active = contextType !== "2d";
}
@ -258,10 +281,11 @@
},
mozGetAsFile: {
type: "readout",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "readout");
if (!status.active && hasType(status, "input")){
status.active = protectedPartChecker("readout");
if (!status.active && protectedPartChecker("input")){
var contextType = canvasContextType.get(obj);
status.active = contextType !== "2d";
}
@ -288,9 +312,10 @@
},
getImageData: {
type: "readout",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "readout");
status.active = protectedPartChecker("readout");
return status;
},
object: "CanvasRenderingContext2D",
@ -322,9 +347,10 @@
},
isPointInPath: {
type: "readout",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "readout");
status.active = protectedPartChecker("readout");
return status;
},
object: "CanvasRenderingContext2D",
@ -348,9 +374,10 @@
},
isPointInStroke: {
type: "readout",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "readout");
status.active = protectedPartChecker("readout");
return status;
},
object: "CanvasRenderingContext2D",
@ -374,9 +401,10 @@
},
fillText: {
type: "input",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "input");
status.active = protectedPartChecker("input");
return status;
},
object: "CanvasRenderingContext2D",
@ -409,9 +437,10 @@
},
strokeText: {
type: "input",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "input");
status.active = protectedPartChecker("input");
return status;
},
object: "CanvasRenderingContext2D",
@ -444,9 +473,10 @@
},
readPixels: {
type: "readout",
getStatus: function(obj, status){
getStatus: function(obj, status, prefs){
const protectedPartChecker = getProtectedPartChecker(prefs, status.url);
status = Object.create(status);
status.active = hasType(status, "readout") || hasType(status, "input");
status.active = protectedPartChecker(["readout", "input"]);
return status;
},
object: ["WebGLRenderingContext", "WebGL2RenderingContext"],

View file

@ -13,12 +13,6 @@
scope = window.scope.modifiedAPIFunctions;
}
scope.hasType = function hasType(status, type){
return status.type.indexOf(type) !== -1;
};
scope.checkerWrapper = function checkerWrapper(checker, object, args, callback){
const check = checker.call(object);
if (check.allow){

View file

@ -16,7 +16,7 @@
const logging = require("./logging");
const {sha256String: hashing} = require("./hash");
const getWrapped = require("sdk/getWrapped");
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
const {checkerWrapper} = require("./modifiedAPIFunctions");
var randomSupply = null;
@ -150,7 +150,7 @@
function getStatus(obj, status, prefs){
status = Object.create(status);
status.active = prefs("protectAudio", status.url) && hasType(status, "readout");
status.active = prefs("protectAudio", status.url);
return status;
}

View file

@ -13,7 +13,7 @@
scope = window.scope.modifiedDOMRectAPI;
}
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
const {checkerWrapper} = require("./modifiedAPIFunctions");
const {byteArrayToString: hash} = require("./hash");
const getWrapped = require("sdk/getWrapped");
@ -424,7 +424,7 @@
function getStatus(obj, status, prefs){
status = Object.create(status);
status.active = prefs("protectDOMRect", status.url) && hasType(status, "readout");
status.active = prefs("protectDOMRect", status.url);
return status;
}

View file

@ -13,7 +13,7 @@
scope = window.scope.modifiedHistoryAPI;
}
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
const {checkerWrapper} = require("./modifiedAPIFunctions");
scope.changedGetters = [
{
@ -43,9 +43,7 @@
function getStatus(obj, status){
status = Object.create(status);
status.active = hasType(status, "readout");
return status;
return Object.create(status);
}
scope.changedGetters.forEach(function(changedGetter){

View file

@ -13,7 +13,7 @@
scope = window.scope.modifiedWindowAPI;
}
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
const {checkerWrapper} = require("./modifiedAPIFunctions");
const windowNames = new WeakMap();
scope.changedGetters = [
@ -75,7 +75,7 @@
function getStatus(obj, status, prefs){
status = Object.create(status);
status.active = prefs("protectWindow", status.url) && hasType(status, "readout");
status.active = prefs("protectWindow", status.url);
return status;
}

View file

@ -58,11 +58,19 @@
},
{
name: "blockMode",
defaultValue: "fakeReadout",
defaultValue: "fake",
urlSpecific: true,
options: [
"blockReadout", "fakeReadout", "fakeInput", "askReadout", null,
"blockEverything", "block", "ask", "allow", "allowEverything"
"fake", "ask", null,
"blockEverything", "block", "allow", "allowEverything"
]
},
{
name: "protectedCanvasPart",
defaultValue: "readout",
urlSpecific: true,
options: [
"readout", "input", "everything"
]
},
{

View file

@ -17,7 +17,7 @@
scope.transitions = {
"": function(oldStorage){
return {
storageVersion: 0.4
storageVersion: 0.5
};
},
0.1: function(oldStorage){
@ -97,6 +97,40 @@
}
return newStorage;
},
0.4: function(oldStorage){
var newStorage = {
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;
}
};
scope.check = function(storage, {settings, logging, changeValue, urlContainer}){