mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 03:56:26 +02:00
parent
9711c67c3f
commit
26529a3653
6 changed files with 375 additions and 281 deletions
|
@ -17,6 +17,7 @@
|
|||
const logging = require("./logging");
|
||||
const {copyCanvasToWebgl} = require("./webgl");
|
||||
const getWrapped = require("sdk/getWrapped");
|
||||
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
|
||||
const modifiedAudioAPI = require("./modifiedAudioAPI");
|
||||
|
||||
var randomSupply = null;
|
||||
|
@ -151,10 +152,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
function hasType(status, type){
|
||||
return status.type.indexOf(type) !== -1;
|
||||
}
|
||||
|
||||
scope.setRandomSupply = function(supply){
|
||||
randomSupply = supply;
|
||||
modifiedAudioAPI.setRandomSupply(supply);
|
||||
|
@ -186,10 +183,13 @@
|
|||
}
|
||||
},
|
||||
object: "HTMLCanvasElement",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function(context, contextAttributes){
|
||||
canvasContextType.set(this, context);
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
canvasContextType.set(this, context);
|
||||
return original.apply(this, window.Array.from(args));
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -205,18 +205,21 @@
|
|||
return status;
|
||||
},
|
||||
object: "HTMLCanvasElement",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function toDataURL(){
|
||||
if (canvasSizeShouldBeFaked(this, prefs)){
|
||||
var fakeCanvas = getFakeCanvas(window, this, prefs);
|
||||
if (fakeCanvas !== this){
|
||||
notify.call(this, "fakedReadout");
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
if (canvasSizeShouldBeFaked(this, prefs)){
|
||||
var fakeCanvas = getFakeCanvas(window, this, prefs);
|
||||
if (fakeCanvas !== this){
|
||||
notify.call(this, "fakedReadout");
|
||||
}
|
||||
return original.apply(fakeCanvas, window.Array.from(args));
|
||||
}
|
||||
return original.apply(fakeCanvas, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(args));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -232,18 +235,21 @@
|
|||
return status;
|
||||
},
|
||||
object: "HTMLCanvasElement",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function toBlob(callback){
|
||||
if (canvasSizeShouldBeFaked(this, prefs)){
|
||||
var fakeCanvas = getFakeCanvas(window, this, prefs);
|
||||
if (fakeCanvas !== this){
|
||||
notify.call(this, "fakedReadout");
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
if (canvasSizeShouldBeFaked(this, prefs)){
|
||||
var fakeCanvas = getFakeCanvas(window, this, prefs);
|
||||
if (fakeCanvas !== this){
|
||||
notify.call(this, "fakedReadout");
|
||||
}
|
||||
return original.apply(fakeCanvas, window.Array.from(args));
|
||||
}
|
||||
return original.apply(fakeCanvas, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(args));
|
||||
}
|
||||
});
|
||||
};
|
||||
},
|
||||
exportOptions: {allowCallbacks: true}
|
||||
|
@ -260,18 +266,21 @@
|
|||
return status;
|
||||
},
|
||||
object: "HTMLCanvasElement",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function mozGetAsFile(callback){
|
||||
if (canvasSizeShouldBeFaked(this, prefs)){
|
||||
var fakeCanvas = getFakeCanvas(window, this, prefs);
|
||||
if (fakeCanvas !== this){
|
||||
notify.call(this, "fakedReadout");
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
if (canvasSizeShouldBeFaked(this, prefs)){
|
||||
var fakeCanvas = getFakeCanvas(window, this, prefs);
|
||||
if (fakeCanvas !== this){
|
||||
notify.call(this, "fakedReadout");
|
||||
}
|
||||
return original.apply(fakeCanvas, window.Array.from(args));
|
||||
}
|
||||
return original.apply(fakeCanvas, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(args));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -283,26 +292,29 @@
|
|||
return status;
|
||||
},
|
||||
object: "CanvasRenderingContext2D",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function getImageData(sx, sy, sw, sh){
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
var fakeCanvas;
|
||||
var context = this;
|
||||
if (this && this.canvas) {
|
||||
fakeCanvas = getFakeCanvas(window, this.canvas, prefs);
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
var fakeCanvas;
|
||||
var context = this;
|
||||
if (this && this.canvas) {
|
||||
fakeCanvas = getFakeCanvas(window, this.canvas, prefs);
|
||||
}
|
||||
if (fakeCanvas && fakeCanvas !== this.canvas){
|
||||
notify.call(this, "fakedReadout");
|
||||
context = window.HTMLCanvasElement.prototype.getContext.call(
|
||||
fakeCanvas,
|
||||
"2d"
|
||||
);
|
||||
}
|
||||
return original.apply(context, window.Array.from(args));
|
||||
}
|
||||
if (fakeCanvas && fakeCanvas !== this.canvas){
|
||||
notify.call(this, "fakedReadout");
|
||||
context = window.HTMLCanvasElement.prototype.getContext.call(
|
||||
fakeCanvas,
|
||||
"2d"
|
||||
);
|
||||
else {
|
||||
return original.apply(this, window.Array.from(args));
|
||||
}
|
||||
return original.apply(context, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -314,18 +326,21 @@
|
|||
return status;
|
||||
},
|
||||
object: "CanvasRenderingContext2D",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function isPointInPath(x, y){
|
||||
var rng = randomSupply.getValueRng(1, window);
|
||||
var originalValue = original.apply(this, window.Array.from(arguments));
|
||||
if ((typeof originalValue) === "boolean"){
|
||||
notify.call(this, "fakedReadout");
|
||||
var index = x + this.width * y;
|
||||
return original.call(this, rng(x, index), rng(y, index));
|
||||
}
|
||||
else {
|
||||
return originalValue;
|
||||
}
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
var rng = randomSupply.getValueRng(1, window);
|
||||
var originalValue = original.apply(this, window.Array.from(args));
|
||||
if ((typeof originalValue) === "boolean"){
|
||||
notify.call(this, "fakedReadout");
|
||||
var index = x + this.width * y;
|
||||
return original.call(this, rng(x, index), rng(y, index));
|
||||
}
|
||||
else {
|
||||
return originalValue;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -337,18 +352,21 @@
|
|||
return status;
|
||||
},
|
||||
object: "CanvasRenderingContext2D",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function isPointInStroke(x, y){
|
||||
var rng = randomSupply.getValueRng(1, window);
|
||||
var originalValue = original.apply(this, window.Array.from(arguments));
|
||||
if ((typeof originalValue) === "boolean"){
|
||||
notify.call(this, "fakedReadout");
|
||||
var index = x + this.width * y;
|
||||
return original.call(this, rng(x, index), rng(y, index));
|
||||
}
|
||||
else {
|
||||
return originalValue;
|
||||
}
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
var rng = randomSupply.getValueRng(1, window);
|
||||
var originalValue = original.apply(this, window.Array.from(args));
|
||||
if ((typeof originalValue) === "boolean"){
|
||||
notify.call(this, "fakedReadout");
|
||||
var index = x + this.width * y;
|
||||
return original.call(this, rng(x, index), rng(y, index));
|
||||
}
|
||||
else {
|
||||
return originalValue;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -360,27 +378,30 @@
|
|||
return status;
|
||||
},
|
||||
object: "CanvasRenderingContext2D",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function fillText(str, x, y){
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
notify.call(this, "fakedInput");
|
||||
var oldImageData;
|
||||
try {
|
||||
// "this" is not trustable - it may be not a context
|
||||
oldImageData = getImageData(window, this).imageData;
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
notify.call(this, "fakedInput");
|
||||
var oldImageData;
|
||||
try {
|
||||
// "this" is not trustable - it may be not a context
|
||||
oldImageData = getImageData(window, this).imageData;
|
||||
}
|
||||
catch (e){
|
||||
// nothing to do here
|
||||
}
|
||||
// if "this" is not a correct context the next line will throw an error
|
||||
var ret = original.apply(this, window.Array.from(args));
|
||||
var newImageData = getImageData(window, this).imageData;
|
||||
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
|
||||
return ret;
|
||||
}
|
||||
catch (e){
|
||||
// nothing to do here
|
||||
else {
|
||||
return original.apply(this, window.Array.from(args));
|
||||
}
|
||||
// if "this" is not a correct context the next line will throw an error
|
||||
var ret = original.apply(this, window.Array.from(arguments));
|
||||
var newImageData = getImageData(window, this).imageData;
|
||||
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -392,27 +413,30 @@
|
|||
return status;
|
||||
},
|
||||
object: "CanvasRenderingContext2D",
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function strokeText(str, x, y){
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
notify.call(this, "fakedInput");
|
||||
var oldImageData;
|
||||
try {
|
||||
// "this" is not trustable - it may be not a context
|
||||
oldImageData = getImageData(window, this).imageData;
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
notify.call(this, "fakedInput");
|
||||
var oldImageData;
|
||||
try {
|
||||
// "this" is not trustable - it may be not a context
|
||||
oldImageData = getImageData(window, this).imageData;
|
||||
}
|
||||
catch (e){
|
||||
// nothing to do here
|
||||
}
|
||||
// if "this" is not a correct context the next line will throw an error
|
||||
var ret = original.apply(this, window.Array.from(args));
|
||||
var newImageData = getImageData(window, this).imageData;
|
||||
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
|
||||
return ret;
|
||||
}
|
||||
catch (e){
|
||||
// nothing to do here
|
||||
else {
|
||||
return original.apply(this, window.Array.from(args));
|
||||
}
|
||||
// if "this" is not a correct context the next line will throw an error
|
||||
var ret = original.apply(this, window.Array.from(arguments));
|
||||
var newImageData = getImageData(window, this).imageData;
|
||||
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -424,21 +448,24 @@
|
|||
return status;
|
||||
},
|
||||
object: ["WebGLRenderingContext", "WebGL2RenderingContext"],
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
fakeGenerator: function(checker){
|
||||
return function readPixels(x, y, width, height, format, type, pixels){ // eslint-disable-line max-params
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
notify.call(this, "fakedReadout");
|
||||
var fakeCanvas = getFakeCanvas(window, this.canvas, prefs);
|
||||
var {context} = copyCanvasToWebgl(
|
||||
window,
|
||||
fakeCanvas,
|
||||
this instanceof window.WebGLRenderingContext? "webgl": "webgl2"
|
||||
);
|
||||
return original.apply(context, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(arguments));
|
||||
}
|
||||
return checkerWrapper(checker, this, arguments, function(args, check){
|
||||
var {prefs, notify, window, original} = check;
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
notify.call(this, "fakedReadout");
|
||||
var fakeCanvas = getFakeCanvas(window, this.canvas, prefs);
|
||||
var {context} = copyCanvasToWebgl(
|
||||
window,
|
||||
fakeCanvas,
|
||||
this instanceof window.WebGLRenderingContext? "webgl": "webgl2"
|
||||
);
|
||||
return original.apply(context, window.Array.from(args));
|
||||
}
|
||||
else {
|
||||
return original.apply(this, window.Array.from(args));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -446,7 +473,17 @@
|
|||
Object.keys(scope.changedFunctions).forEach(function(key){
|
||||
scope.changedFunctions[key].api = "canvas";
|
||||
});
|
||||
Object.keys(modifiedAudioAPI.changedFunctions).forEach(function(key){
|
||||
scope.changedFunctions[key] = modifiedAudioAPI.changedFunctions[key];
|
||||
});
|
||||
|
||||
scope.changedGetters = {};
|
||||
|
||||
function appendModified(collection){
|
||||
Object.keys(collection.changedFunctions || {}).forEach(function(key){
|
||||
scope.changedFunctions[key] = collection.changedFunctions[key];
|
||||
});
|
||||
|
||||
Object.keys(collection.changedGetters || {}).forEach(function(key){
|
||||
scope.changedGetters[key] = collection.changedGetters[key];
|
||||
});
|
||||
}
|
||||
appendModified(modifiedAudioAPI);
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue