2015-09-06 12:26:50 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
2017-06-25 22:33:12 +02:00
|
|
|
var scope;
|
|
|
|
if ((typeof exports) !== "undefined"){
|
|
|
|
scope = exports;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
window.scope.modifiedAPI = {};
|
|
|
|
scope = window.scope.modifiedAPI;
|
|
|
|
}
|
|
|
|
|
2017-08-07 21:03:34 +02:00
|
|
|
const colorStatistics = require("./colorStatistics");
|
2017-08-13 23:41:57 +02:00
|
|
|
const logging = require("./logging");
|
|
|
|
const {copyCanvasToWebgl} = require("./webgl");
|
2017-10-07 23:26:04 +02:00
|
|
|
const getWrapped = require("sdk/getWrapped");
|
2018-07-13 16:58:13 +02:00
|
|
|
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
|
2018-06-16 00:22:31 +02:00
|
|
|
const modifiedAudioAPI = require("./modifiedAudioAPI");
|
2018-09-04 23:29:58 +02:00
|
|
|
const modifiedDOMRectAPI = require("./modifiedDOMRectAPI");
|
2017-08-07 21:03:34 +02:00
|
|
|
|
2016-08-06 19:17:36 +02:00
|
|
|
var randomSupply = null;
|
|
|
|
|
2016-10-23 22:12:12 +02:00
|
|
|
function getContext(window, canvas){
|
|
|
|
return window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d") ||
|
|
|
|
window.HTMLCanvasElement.prototype.getContext.call(canvas, "webgl") ||
|
|
|
|
window.HTMLCanvasElement.prototype.getContext.call(canvas, "experimental-webgl") ||
|
|
|
|
window.HTMLCanvasElement.prototype.getContext.call(canvas, "webgl2") ||
|
|
|
|
window.HTMLCanvasElement.prototype.getContext.call(canvas, "experimental-webgl2");
|
|
|
|
}
|
|
|
|
function getImageData(window, context){
|
2016-12-26 14:36:01 +01:00
|
|
|
var imageData;
|
|
|
|
var source;
|
2017-04-19 19:32:37 +02:00
|
|
|
if ((context.canvas.width || 0) * (context.canvas.height || 0) === 0){
|
2017-10-10 21:09:26 +02:00
|
|
|
imageData = new (getWrapped(window).ImageData)(0, 0);
|
|
|
|
source = new (getWrapped(window).ImageData)(0, 0);
|
2017-04-19 19:32:37 +02:00
|
|
|
}
|
|
|
|
else if (context instanceof window.CanvasRenderingContext2D){
|
2017-10-06 16:06:31 +02:00
|
|
|
imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(
|
|
|
|
context,
|
|
|
|
0, 0,
|
|
|
|
context.canvas.width, context.canvas.height
|
|
|
|
);
|
2016-12-26 14:36:01 +01:00
|
|
|
source = imageData.data;
|
2015-09-10 01:35:49 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-10-10 21:09:26 +02:00
|
|
|
imageData = new (getWrapped(window).ImageData)(context.canvas.width, context.canvas.height);
|
2017-04-19 19:32:37 +02:00
|
|
|
source = new Uint8Array(imageData.data.length);
|
2017-10-10 21:09:26 +02:00
|
|
|
(
|
|
|
|
context instanceof window.WebGLRenderingContext?
|
|
|
|
window.WebGLRenderingContext:
|
|
|
|
window.WebGL2RenderingContext
|
|
|
|
).prototype.readPixels.call(
|
2015-09-10 01:35:49 +02:00
|
|
|
context,
|
2016-10-23 22:12:12 +02:00
|
|
|
0, 0, context.canvas.width, context.canvas.height,
|
2015-09-10 01:35:49 +02:00
|
|
|
context.RGBA, context.UNSIGNED_BYTE,
|
2016-12-26 14:36:01 +01:00
|
|
|
source
|
2015-09-10 01:35:49 +02:00
|
|
|
);
|
|
|
|
}
|
2016-12-26 14:36:01 +01:00
|
|
|
return {
|
|
|
|
imageData,
|
|
|
|
source
|
|
|
|
};
|
2016-10-23 22:12:12 +02:00
|
|
|
}
|
|
|
|
|
2017-08-08 18:08:18 +02:00
|
|
|
var canvasCache = Object.create(null);
|
2017-08-07 21:03:34 +02:00
|
|
|
function getFakeCanvas(window, original, prefs){
|
2017-05-05 09:18:11 +02:00
|
|
|
try {
|
2017-08-08 18:08:18 +02:00
|
|
|
if (prefs("useCanvasCache")){
|
|
|
|
var originalDataURL = original.toDataURL();
|
|
|
|
var cached = canvasCache[originalDataURL];
|
|
|
|
if (cached){
|
|
|
|
return cached;
|
|
|
|
}
|
|
|
|
}
|
2017-05-05 09:18:11 +02:00
|
|
|
// original may not be a canvas -> we must not leak an error
|
|
|
|
var context = getContext(window, original);
|
|
|
|
var {imageData, source} = getImageData(window, context);
|
|
|
|
var desc = imageData.data;
|
|
|
|
var l = desc.length;
|
|
|
|
|
2017-08-07 08:49:49 +02:00
|
|
|
var ignoredColors = {};
|
2017-12-11 12:47:43 +01:00
|
|
|
var statistic;
|
2017-08-07 21:03:34 +02:00
|
|
|
if (prefs("ignoreFrequentColors")){
|
2017-12-11 12:47:43 +01:00
|
|
|
statistic = colorStatistics.compute(source);
|
2017-08-07 21:03:34 +02:00
|
|
|
ignoredColors = statistic.getMaxColors(prefs("ignoreFrequentColors"));
|
|
|
|
}
|
2017-12-11 12:47:43 +01:00
|
|
|
if (prefs("minColors")){
|
|
|
|
if (!colorStatistics.hasMoreColors(source, prefs("minColors"), statistic)){
|
|
|
|
return original;
|
|
|
|
}
|
|
|
|
}
|
2017-08-07 21:03:34 +02:00
|
|
|
|
2017-08-07 08:49:49 +02:00
|
|
|
var rng = randomSupply.getPixelRng(l, window, ignoredColors);
|
2017-08-11 16:26:24 +02:00
|
|
|
var fakeAlphaChannel = prefs("fakeAlphaChannel");
|
2017-08-07 08:49:49 +02:00
|
|
|
for (var i = 0; i < l; i += 4){
|
|
|
|
var [r, g, b, a] = rng(
|
2017-10-03 15:35:31 +02:00
|
|
|
source[i + 0],
|
|
|
|
source[i + 1],
|
|
|
|
source[i + 2],
|
2017-08-07 08:49:49 +02:00
|
|
|
source[i + 3],
|
|
|
|
i / 4
|
|
|
|
);
|
|
|
|
desc[i + 0] = r;
|
|
|
|
desc[i + 1] = g;
|
|
|
|
desc[i + 2] = b;
|
2017-08-11 16:26:24 +02:00
|
|
|
desc[i + 3] = fakeAlphaChannel? a: source[i + 3];
|
2017-05-05 09:18:11 +02:00
|
|
|
}
|
|
|
|
var canvas = original.cloneNode(true);
|
|
|
|
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
|
|
|
context.putImageData(imageData, 0, 0);
|
2017-08-08 18:08:18 +02:00
|
|
|
if (prefs("useCanvasCache")){
|
|
|
|
canvasCache[originalDataURL] = canvas;
|
2017-08-11 16:26:24 +02:00
|
|
|
canvasCache[canvas.toDataURL()] = canvas;
|
2017-08-08 18:08:18 +02:00
|
|
|
}
|
2017-05-05 09:18:11 +02:00
|
|
|
return canvas;
|
|
|
|
}
|
|
|
|
catch (e){
|
2017-08-13 23:41:57 +02:00
|
|
|
logging.warning("Error while faking:", e);
|
2017-05-05 09:18:11 +02:00
|
|
|
return original;
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-23 22:12:12 +02:00
|
|
|
function randomMixImageData(window, imageData1, imageData2){
|
|
|
|
var data1 = imageData1.data;
|
|
|
|
var data2 = imageData2.data;
|
|
|
|
var l = data1.length;
|
|
|
|
if (l === data2.length){
|
2018-06-16 00:09:06 +02:00
|
|
|
var rng = randomSupply.getValueRng(l, window);
|
2016-10-23 22:12:12 +02:00
|
|
|
|
|
|
|
for (var i = 0; i < l; i += 1){
|
|
|
|
if (data1[i] > data2[i]){
|
|
|
|
data2[i] = data1[i] - rng(data1[i] - data2[i], i);
|
|
|
|
}
|
|
|
|
else if (data1[i] < data2[i]){
|
|
|
|
data2[i] = data1[i] + rng(data2[i] - data1[i], i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return imageData2;
|
|
|
|
}
|
|
|
|
|
2017-07-18 16:11:12 +02:00
|
|
|
function canvasSizeShouldBeFaked(canvas, prefs){
|
|
|
|
if (canvas){
|
|
|
|
var size = canvas.height * canvas.width;
|
|
|
|
var maxSize = prefs("maxFakeSize") || Number.POSITIVE_INFINITY;
|
|
|
|
var minSize = prefs("minFakeSize") || 0;
|
|
|
|
return size > minSize & size <= maxSize;
|
|
|
|
}
|
|
|
|
else {
|
2017-10-03 15:35:31 +02:00
|
|
|
return true;
|
2017-07-18 16:11:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-25 22:33:12 +02:00
|
|
|
scope.setRandomSupply = function(supply){
|
2016-08-06 19:17:36 +02:00
|
|
|
randomSupply = supply;
|
2018-06-16 00:22:31 +02:00
|
|
|
modifiedAudioAPI.setRandomSupply(supply);
|
2018-09-04 23:29:58 +02:00
|
|
|
modifiedDOMRectAPI.setRandomSupply(supply);
|
2016-08-06 19:17:36 +02:00
|
|
|
};
|
2016-10-23 22:12:12 +02:00
|
|
|
var canvasContextType = new WeakMap();
|
2015-09-06 12:26:50 +02:00
|
|
|
// changed functions and their fakes
|
2017-06-25 22:33:12 +02:00
|
|
|
scope.changedFunctions = {
|
2015-09-06 12:26:50 +02:00
|
|
|
getContext: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "context",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2016-11-13 14:55:42 +01:00
|
|
|
if (hasType(status, "internal")){
|
|
|
|
return {
|
|
|
|
mode: "allow",
|
|
|
|
type: status.type,
|
|
|
|
active: false
|
2017-10-03 15:35:31 +02:00
|
|
|
};
|
2016-11-13 14:55:42 +01:00
|
|
|
}
|
|
|
|
else if (hasType(status, "context") || hasType(status, "input")){
|
|
|
|
return {
|
2017-11-09 00:53:52 +01:00
|
|
|
mode: status.mode,
|
2016-11-13 14:55:42 +01:00
|
|
|
type: status.type,
|
|
|
|
active: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2016-11-13 14:55:42 +01:00
|
|
|
status.active = false;
|
|
|
|
return status;
|
|
|
|
}
|
2016-10-23 22:12:12 +02:00
|
|
|
},
|
|
|
|
object: "HTMLCanvasElement",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2016-10-23 22:12:12 +02:00
|
|
|
return function(context, contextAttributes){
|
2018-07-13 16:58:13 +02:00
|
|
|
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));
|
|
|
|
});
|
2016-10-23 22:12:12 +02:00
|
|
|
};
|
|
|
|
}
|
2015-09-06 12:26:50 +02:00
|
|
|
},
|
|
|
|
toDataURL: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "readout",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2017-11-09 00:53:52 +01:00
|
|
|
status.active = hasType(status, "readout");
|
|
|
|
if (!status.active && hasType(status, "input")){
|
2016-10-23 22:12:12 +02:00
|
|
|
var contextType = canvasContextType.get(obj);
|
2016-11-13 15:09:03 +01:00
|
|
|
status.active = contextType !== "2d";
|
2016-10-23 22:12:12 +02:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
},
|
2015-09-06 12:26:50 +02:00
|
|
|
object: "HTMLCanvasElement",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2016-10-23 22:12:12 +02:00
|
|
|
return function toDataURL(){
|
2018-07-13 16:58:13 +02:00
|
|
|
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){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedReadout");
|
2018-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
return original.apply(fakeCanvas, window.Array.from(args));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return original.apply(this, window.Array.from(args));
|
2017-12-11 12:48:08 +01:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
});
|
2016-10-23 22:12:12 +02:00
|
|
|
};
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
toBlob: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "readout",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2017-11-09 00:53:52 +01:00
|
|
|
status.active = hasType(status, "readout");
|
|
|
|
if (!status.active && hasType(status, "input")){
|
2016-10-23 22:12:12 +02:00
|
|
|
var contextType = canvasContextType.get(obj);
|
2016-11-13 15:09:03 +01:00
|
|
|
status.active = contextType !== "2d";
|
2016-10-23 22:12:12 +02:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
},
|
2015-09-06 12:26:50 +02:00
|
|
|
object: "HTMLCanvasElement",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2016-10-23 22:12:12 +02:00
|
|
|
return function toBlob(callback){
|
2018-07-13 16:58:13 +02:00
|
|
|
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){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedReadout");
|
2018-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
return original.apply(fakeCanvas, window.Array.from(args));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return original.apply(this, window.Array.from(args));
|
2017-12-11 12:48:08 +01:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
});
|
2016-10-23 22:12:12 +02:00
|
|
|
};
|
2015-09-06 12:26:50 +02:00
|
|
|
},
|
|
|
|
exportOptions: {allowCallbacks: true}
|
|
|
|
},
|
|
|
|
mozGetAsFile: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "readout",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2017-11-09 00:53:52 +01:00
|
|
|
status.active = hasType(status, "readout");
|
|
|
|
if (!status.active && hasType(status, "input")){
|
2016-10-23 22:12:12 +02:00
|
|
|
var contextType = canvasContextType.get(obj);
|
2016-11-13 15:09:03 +01:00
|
|
|
status.active = contextType !== "2d";
|
2016-10-23 22:12:12 +02:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
},
|
2015-09-06 12:26:50 +02:00
|
|
|
object: "HTMLCanvasElement",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2016-10-23 22:12:12 +02:00
|
|
|
return function mozGetAsFile(callback){
|
2018-07-13 16:58:13 +02:00
|
|
|
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){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedReadout");
|
2018-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
return original.apply(fakeCanvas, window.Array.from(args));
|
2017-12-11 12:48:08 +01:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
else {
|
|
|
|
return original.apply(this, window.Array.from(args));
|
|
|
|
}
|
|
|
|
});
|
2016-10-23 22:12:12 +02:00
|
|
|
};
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
getImageData: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "readout",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2017-10-12 00:25:12 +02:00
|
|
|
status.active = hasType(status, "readout");
|
2016-10-23 22:12:12 +02:00
|
|
|
return status;
|
|
|
|
},
|
2015-09-06 12:26:50 +02:00
|
|
|
object: "CanvasRenderingContext2D",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2016-05-10 08:01:21 +02:00
|
|
|
return function getImageData(sx, sy, sw, sh){
|
2018-07-13 16:58:13 +02:00
|
|
|
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){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedReadout");
|
2018-07-13 16:58:13 +02:00
|
|
|
context = window.HTMLCanvasElement.prototype.getContext.call(
|
|
|
|
fakeCanvas,
|
|
|
|
"2d"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return original.apply(context, window.Array.from(args));
|
2017-05-05 09:18:11 +02:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
else {
|
|
|
|
return original.apply(this, window.Array.from(args));
|
2017-05-05 09:18:11 +02:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
});
|
2016-08-06 19:17:36 +02:00
|
|
|
};
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
},
|
2018-04-01 22:47:57 +02:00
|
|
|
isPointInPath: {
|
|
|
|
type: "readout",
|
|
|
|
getStatus: function(obj, status){
|
|
|
|
status = Object.create(status);
|
|
|
|
status.active = hasType(status, "readout");
|
|
|
|
return status;
|
|
|
|
},
|
|
|
|
object: "CanvasRenderingContext2D",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2018-04-01 22:47:57 +02:00
|
|
|
return function isPointInPath(x, y){
|
2018-07-13 16:58:13 +02:00
|
|
|
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"){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedReadout");
|
2018-07-13 16:58:13 +02:00
|
|
|
var index = x + this.width * y;
|
|
|
|
return original.call(this, rng(x, index), rng(y, index));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return originalValue;
|
|
|
|
}
|
|
|
|
});
|
2018-04-01 22:47:57 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isPointInStroke: {
|
|
|
|
type: "readout",
|
|
|
|
getStatus: function(obj, status){
|
|
|
|
status = Object.create(status);
|
|
|
|
status.active = hasType(status, "readout");
|
|
|
|
return status;
|
|
|
|
},
|
|
|
|
object: "CanvasRenderingContext2D",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2018-04-01 22:47:57 +02:00
|
|
|
return function isPointInStroke(x, y){
|
2018-07-13 16:58:13 +02:00
|
|
|
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"){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedReadout");
|
2018-07-13 16:58:13 +02:00
|
|
|
var index = x + this.width * y;
|
|
|
|
return original.call(this, rng(x, index), rng(y, index));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return originalValue;
|
|
|
|
}
|
|
|
|
});
|
2018-04-01 22:47:57 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
2016-10-23 22:12:12 +02:00
|
|
|
fillText: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "input",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2016-10-23 22:12:12 +02:00
|
|
|
status.active = hasType(status, "input");
|
|
|
|
return status;
|
|
|
|
},
|
|
|
|
object: "CanvasRenderingContext2D",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2016-10-23 22:12:12 +02:00
|
|
|
return function fillText(str, x, y){
|
2018-07-13 16:58:13 +02:00
|
|
|
return checkerWrapper(checker, this, arguments, function(args, check){
|
|
|
|
var {prefs, notify, window, original} = check;
|
|
|
|
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedInput");
|
2018-07-13 16:58:13 +02:00
|
|
|
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;
|
2017-07-18 16:11:12 +02:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
else {
|
|
|
|
return original.apply(this, window.Array.from(args));
|
2017-10-03 15:35:31 +02:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
});
|
2016-10-23 22:12:12 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
strokeText: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "input",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2016-10-23 22:12:12 +02:00
|
|
|
status.active = hasType(status, "input");
|
|
|
|
return status;
|
|
|
|
},
|
|
|
|
object: "CanvasRenderingContext2D",
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2016-10-23 22:12:12 +02:00
|
|
|
return function strokeText(str, x, y){
|
2018-07-13 16:58:13 +02:00
|
|
|
return checkerWrapper(checker, this, arguments, function(args, check){
|
|
|
|
var {prefs, notify, window, original} = check;
|
|
|
|
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedInput");
|
2018-07-13 16:58:13 +02:00
|
|
|
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;
|
2017-07-18 16:11:12 +02:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
else {
|
|
|
|
return original.apply(this, window.Array.from(args));
|
2017-10-03 15:35:31 +02:00
|
|
|
}
|
2018-07-13 16:58:13 +02:00
|
|
|
});
|
2016-10-23 22:12:12 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
2015-09-06 12:26:50 +02:00
|
|
|
readPixels: {
|
2017-03-03 00:55:32 +01:00
|
|
|
type: "readout",
|
2016-10-23 22:12:12 +02:00
|
|
|
getStatus: function(obj, status){
|
2017-10-03 15:35:31 +02:00
|
|
|
status = Object.create(status);
|
2016-10-23 22:12:12 +02:00
|
|
|
status.active = hasType(status, "readout") || hasType(status, "input");
|
|
|
|
return status;
|
|
|
|
},
|
2016-12-26 14:36:01 +01:00
|
|
|
object: ["WebGLRenderingContext", "WebGL2RenderingContext"],
|
2018-07-13 16:58:13 +02:00
|
|
|
fakeGenerator: function(checker){
|
2017-10-06 16:06:31 +02:00
|
|
|
return function readPixels(x, y, width, height, format, type, pixels){ // eslint-disable-line max-params
|
2018-07-13 16:58:13 +02:00
|
|
|
return checkerWrapper(checker, this, arguments, function(args, check){
|
|
|
|
var {prefs, notify, window, original} = check;
|
|
|
|
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
2018-09-21 16:42:58 +02:00
|
|
|
notify("fakedReadout");
|
2018-07-13 16:58:13 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
});
|
2016-10-23 22:12:12 +02:00
|
|
|
};
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-06-21 00:09:07 +02:00
|
|
|
Object.keys(scope.changedFunctions).forEach(function(key){
|
|
|
|
scope.changedFunctions[key].api = "canvas";
|
|
|
|
});
|
2018-07-13 16:58:13 +02:00
|
|
|
|
2018-08-27 00:23:19 +02:00
|
|
|
scope.changedGetters = [];
|
2018-07-13 16:58:13 +02:00
|
|
|
|
|
|
|
function appendModified(collection){
|
|
|
|
Object.keys(collection.changedFunctions || {}).forEach(function(key){
|
|
|
|
scope.changedFunctions[key] = collection.changedFunctions[key];
|
|
|
|
});
|
|
|
|
|
2018-08-27 00:23:19 +02:00
|
|
|
(collection.changedGetters || []).forEach(function(changedGetter){
|
|
|
|
scope.changedGetters.push(changedGetter);
|
2018-07-13 16:58:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
appendModified(modifiedAudioAPI);
|
2018-08-27 00:30:48 +02:00
|
|
|
appendModified(require("./modifiedHistoryAPI"));
|
2018-08-27 00:33:39 +02:00
|
|
|
appendModified(require("./modifiedWindowAPI"));
|
2018-09-04 23:29:58 +02:00
|
|
|
appendModified(modifiedDOMRectAPI);
|
2015-09-06 12:26:50 +02:00
|
|
|
}());
|