1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Simplified require and further linting.

This commit is contained in:
kkapsner 2017-10-06 16:06:31 +02:00
parent 01c1145e28
commit dcb878392e
15 changed files with 86 additions and 78 deletions

View File

@ -21,8 +21,9 @@
"comma-spacing": ["error", { "before": false, "after": true }], "comma-spacing": ["error", { "before": false, "after": true }],
"constructor-super": "warn", "constructor-super": "warn",
"eqeqeq": "error", "eqeqeq": "error",
"max-len": ["warn", 120], "max-len": ["warn", {"code": 120, "tabWidth": 4}],
"max-lines": ["warn", 200], "max-lines": ["warn", {"max": 400, "skipBlankLines": true, "skipComments": true}],
"max-params": ["warn", 4],
"no-const-assign": "warn", "no-const-assign": "warn",
"no-this-before-super": "warn", "no-this-before-super": "warn",
"no-undef": "error", "no-undef": "error",

View File

@ -56,7 +56,10 @@
if (inDOM){ if (inDOM){
canvas.scrollIntoView(); canvas.scrollIntoView();
var rect = canvas.getBoundingClientRect(); var rect = canvas.getBoundingClientRect();
var foundEl = window.document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2); var foundEl = window.document.elementFromPoint(
rect.left + rect.width / 2,
rect.top + rect.height / 2
);
visible = (foundEl === canvas); visible = (foundEl === canvas);
} }
Object.defineProperty(this, "visible", {value: visible}); Object.defineProperty(this, "visible", {value: visible});

View File

@ -13,14 +13,10 @@
scope = window.scope.callingStack; scope = window.scope.callingStack;
} }
const preferences = require("sdk/simple-prefs");
const prefs = preferences.prefs;
// Translation // Translation
var translate = require("sdk/l10n").get;
var _ = function(name, replace, translateAPI){ var _ = function(name, replace, translateAPI){
if (!translateAPI){ if (!translateAPI){
translateAPI = translate; translateAPI = browser.i18n.getMessage;
} }
var str = translateAPI(name) || name; var str = translateAPI(name) || name;
@ -76,7 +72,7 @@
toString: function(translateAPI){ toString: function(translateAPI){
var msg = ""; var msg = "";
msg += "\n\n" + _("sourceOutput", undefined, translateAPI) + ": "; msg += "\n\n" + _("sourceOutput", undefined, translateAPI) + ": ";
if (prefs.showCompleteCallingStack){ if (settings.showCompleteCallingStack){
msg += callers.reduce(function(stack, c){ msg += callers.reduce(function(stack, c){
return stack + "\n\t" + _("stackEntryOutput", c, translateAPI); return stack + "\n\t" + _("stackEntryOutput", c, translateAPI);
}, ""); }, "");

View File

@ -14,13 +14,11 @@
} }
const lists = require("./lists"); const lists = require("./lists");
const preferences = require("sdk/simple-prefs");
const prefs = preferences.prefs;
const {parseErrorStack} = require("./callingStack"); const {parseErrorStack} = require("./callingStack");
const logging = require("./logging"); const logging = require("./logging");
scope.check = function check({url, errorStack}){ scope.check = function check({url, errorStack}){
var match = checkBoth(errorStack, url, prefs.blockMode).match( var match = checkBoth(errorStack, url, settings.blockMode).match(
/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/ /^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/
); );
if (match){ if (match){
@ -41,7 +39,7 @@
}; };
function checkBoth(errorStack, url, blockMode){ function checkBoth(errorStack, url, blockMode){
if (prefs.enableStackList && errorStack && checkStack(errorStack)){ if (settings.enableStackList && errorStack && checkStack(errorStack)){
return "allow"; return "allow";
} }
else { else {

View File

@ -27,7 +27,13 @@
var index = String.fromCharCode(r, g, b, a); var index = String.fromCharCode(r, g, b, a);
var color = this.colors[index]; var color = this.colors[index];
if (!color){ if (!color){
color = {index, color: [r, g, b, a], count: 0, previousColor: this.minBoundary, nextColor: this.minBoundary.nextColor}; color = {
index,
color: [r, g, b, a],
count: 0,
previousColor: this.minBoundary,
nextColor: this.minBoundary.nextColor
};
this.numberOfColors += 1; this.numberOfColors += 1;
this.minBoundary.nextColor = color; this.minBoundary.nextColor = color;
color.nextColor.previousColor = color; color.nextColor.previousColor = color;

View File

@ -34,10 +34,9 @@
return true; return true;
} }
} }
const _ = require("sdk/l10n").get;
function askWrapper(data){ function askWrapper(data){
return ask(data, { return ask(data, {
_, _: browser.i18n.getMessage,
prefs prefs
}); });
} }
@ -159,7 +158,10 @@
if (data["canvasBlocker-unload"]){ if (data["canvasBlocker-unload"]){
enabled = false; enabled = false;
} }
if (data.hasOwnProperty("canvasBlocker-sendNotifications") && data["canvasBlocker-sendNotifications"] === tabId){ if (
data.hasOwnProperty("canvasBlocker-sendNotifications") &&
data["canvasBlocker-sendNotifications"] === tabId
){
notice("sending notifications:", notifications); notice("sending notifications:", notifications);
browser.runtime.sendMessage({ browser.runtime.sendMessage({
sender: tabId, sender: tabId,

View File

@ -18,7 +18,6 @@
setRandomSupply(randomSupplies.nonPersistent); setRandomSupply(randomSupplies.nonPersistent);
var apiNames = Object.keys(changedFunctions); var apiNames = Object.keys(changedFunctions);
var undef; var undef;
var exportFunction = require("chrome").Cu.exportFunction;
function setRandomSupplyByType(type){ function setRandomSupplyByType(type){
switch (type){ switch (type){
case "persistent": case "persistent":
@ -86,6 +85,29 @@
} }
var funcStatus = changedFunction.getStatus(this, siteStatus); var funcStatus = changedFunction.getStatus(this, siteStatus);
function notifyCallback(messageId){
notify({
url,
errorStack: error.stack,
messageId,
timestamp: new Date(),
functionName: name,
dataURL:
prefs("storeImageForInspection") &&
prefs("showNotifications")?
(
this instanceof HTMLCanvasElement?
this.toDataURL():
(
this.canvas instanceof HTMLCanvasElement?
this.canvas.toDataURL():
false
)
):
false
});
}
if (funcStatus.active){ if (funcStatus.active){
if (funcStatus.mode === "ask"){ if (funcStatus.mode === "ask"){
funcStatus.mode = ask({ funcStatus.mode = ask({
@ -100,28 +122,12 @@
return original; return original;
case "fake": case "fake":
setRandomSupplyByType(prefs("rng")); setRandomSupplyByType(prefs("rng"));
var fake = changedFunction.fakeGenerator(prefs, function(messageId){ var fake = changedFunction.fakeGenerator(
notify({ prefs,
url, notifyCallback,
errorStack: error.stack, window,
messageId, original
timestamp: new Date(), );
functionName: name,
dataURL:
prefs("storeImageForInspection") &&
prefs("showNotifications")?
(
this instanceof HTMLCanvasElement?
this.toDataURL():
(
this.canvas instanceof HTMLCanvasElement?
this.canvas.toDataURL():
false
)
):
false
});
}, window, original);
switch (fake){ switch (fake){
case true: case true:
return original; return original;

View File

@ -143,13 +143,6 @@
}); });
}); });
// warning("TODO: register unload events - do not know how - there seems to be no way with a WebExtension");
// old code
// const {when: unload} = require("sdk/system/unload");
// unload(function(){
// processes.port.emit("canvasBlocker-unload");
// });
browser.runtime.onInstalled.addListener(function(){ browser.runtime.onInstalled.addListener(function(){
message("CanvasBlocker installed"); message("CanvasBlocker installed");
browser.storage.local.get("storageVersion").then(function(data){ browser.storage.local.get("storageVersion").then(function(data){

View File

@ -34,7 +34,11 @@
source = new window.wrappedJSObject.ImageData(0, 0); source = new window.wrappedJSObject.ImageData(0, 0);
} }
else if (context instanceof window.CanvasRenderingContext2D){ else if (context instanceof window.CanvasRenderingContext2D){
imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, context.canvas.width, context.canvas.height); imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(
context,
0, 0,
context.canvas.width, context.canvas.height
);
source = imageData.data; source = imageData.data;
} }
else { else {
@ -365,11 +369,15 @@
}, },
object: ["WebGLRenderingContext", "WebGL2RenderingContext"], object: ["WebGLRenderingContext", "WebGL2RenderingContext"],
fakeGenerator: function(prefs, notify, window, original){ fakeGenerator: function(prefs, notify, window, original){
return function readPixels(x, y, width, height, format, type, pixels){ return function readPixels(x, y, width, height, format, type, pixels){ // eslint-disable-line max-params
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){ if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
var fakeCanvas = getFakeCanvas(window, this.canvas, prefs); var fakeCanvas = getFakeCanvas(window, this.canvas, prefs);
var {context} = copyCanvasToWebgl(window, fakeCanvas, this instanceof window.WebGLRenderingContext? "webgl": "webgl2"); var {context} = copyCanvasToWebgl(
window,
fakeCanvas,
this instanceof window.WebGLRenderingContext? "webgl": "webgl2"
);
return original.apply(context, window.Array.from(arguments)); return original.apply(context, window.Array.from(arguments));
} }
else { else {

View File

@ -44,7 +44,9 @@
// create the (sub-)domains random numbers if not existing // create the (sub-)domains random numbers if not existing
persistentRnd[domain] = new Uint8Array(128); persistentRnd[domain] = new Uint8Array(128);
window.crypto.getRandomValues(persistentRnd[domain]); window.crypto.getRandomValues(persistentRnd[domain]);
browser.runtime.sendMessage({"canvasBlocker-new-domain-rnd": {domain, rnd: Array.from(persistentRnd[domain])}}); browser.runtime.sendMessage({
"canvasBlocker-new-domain-rnd": {domain, rnd: Array.from(persistentRnd[domain])}
});
} }
return persistentRnd[domain]; return persistentRnd[domain];
}; };
@ -75,7 +77,7 @@
}, },
getPixelRng: function(length, window, ignoredColors){ getPixelRng: function(length, window, ignoredColors){
var rng = this.getRng(length, window); var rng = this.getRng(length, window);
return function(r, g, b, a, i){ return function(r, g, b, a, i){ // eslint-disable-line max-params
var index = String.fromCharCode(r, g, b, a); var index = String.fromCharCode(r, g, b, a);
if (ignoredColors[index]){ if (ignoredColors[index]){
return [r, g, b, a]; return [r, g, b, a];
@ -101,7 +103,7 @@
return function getConstantPixelRng(length, window, ignoredColors){ return function getConstantPixelRng(length, window, ignoredColors){
var rng = scope.nonPersistent.getRng(1024, window); var rng = scope.nonPersistent.getRng(1024, window);
return function(r, g, b, a, i){ return function(r, g, b, a, i){ // eslint-disable-line max-params
var index = String.fromCharCode(r, g, b, a); var index = String.fromCharCode(r, g, b, a);
if (ignoredColors[index]){ if (ignoredColors[index]){
return [r, g, b, a]; return [r, g, b, a];
@ -147,7 +149,7 @@
}, },
getPixelRng: function(length, window, ignoredColors){ getPixelRng: function(length, window, ignoredColors){
var rng = this.getRng(length, window); var rng = this.getRng(length, window);
return function(r, g, b, a, i){ return function(r, g, b, a, i){ // eslint-disable-line max-params
var index = String.fromCharCode(r, g, b, a); var index = String.fromCharCode(r, g, b, a);
if (ignoredColors[index]){ if (ignoredColors[index]){
return [r, g, b, a]; return [r, g, b, a];

View File

@ -1,4 +1,3 @@
/* global settings exportFunction */
/* This Source Code Form is subject to the terms of the Mozilla Public /* 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -10,11 +9,6 @@ function require(module){
var scopeName = module.substr(2).replace(/\..+/, ""); var scopeName = module.substr(2).replace(/\..+/, "");
return window.scope[scopeName]; return window.scope[scopeName];
} }
else if (module === "chrome"){
return {
Cu: {exportFunction}
};
}
else if (module === "sdk/simple-prefs"){ else if (module === "sdk/simple-prefs"){
return { return {
prefs: settings, prefs: settings,
@ -29,18 +23,6 @@ function require(module){
} }
}; };
} }
else if (module === "sdk/l10n"){
return {
get: function(key){
return browser.i18n.getMessage(key);
}
};
}
else if (module === "sdk/url"){
return {
URL
};
}
throw new ReferenceError("Unable to get non relative module " + module + "!"); throw new ReferenceError("Unable to get non relative module " + module + "!");
} }

View File

@ -32,7 +32,8 @@
var program = context.createProgram(); var program = context.createProgram();
var shader = context.createShader(context.VERTEX_SHADER); var shader = context.createShader(context.VERTEX_SHADER);
var vertex = "attribute vec4 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_texCoord;\nvoid main(){\n\tgl_Position = a_position;\n\tv_texCoord = a_texCoord;\n}"; var vertex = "attribute vec4 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_texCoord;\n" +
"void main(){\n\tgl_Position = a_position;\n\tv_texCoord = a_texCoord;\n}";
context.shaderSource(shader, vertex); context.shaderSource(shader, vertex);
context.compileShader(shader); context.compileShader(shader);
success = context.getShaderParameter(shader, context.COMPILE_STATUS); success = context.getShaderParameter(shader, context.COMPILE_STATUS);
@ -44,7 +45,8 @@
context.attachShader(program, shader); context.attachShader(program, shader);
shader = context.createShader(context.FRAGMENT_SHADER); shader = context.createShader(context.FRAGMENT_SHADER);
var fragmenter = "precision mediump float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\nvoid main(){\n\tgl_FragColor = texture2D(u_image, v_texCoord);\n}"; var fragmenter = "precision mediump float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\n" +
"void main(){\n\tgl_FragColor = texture2D(u_image, v_texCoord);\n}";
context.shaderSource(shader, fragmenter); context.shaderSource(shader, fragmenter);
context.compileShader(shader); context.compileShader(shader);
success = context.getShaderParameter(shader, context.COMPILE_STATUS); success = context.getShaderParameter(shader, context.COMPILE_STATUS);

View File

@ -122,7 +122,10 @@ Promise.all([
data["canvasBlocker-notifications"].forEach(function(notification){ data["canvasBlocker-notifications"].forEach(function(notification){
verbose(notification); verbose(notification);
notification.url = new URL(notification.url); notification.url = new URL(notification.url);
domainNotification(notification.url.hostname, notification.messageId).addNotification(new Notification(notification)); domainNotification(
notification.url.hostname,
notification.messageId
).addNotification(new Notification(notification));
}); });
} }
}); });

View File

@ -53,7 +53,9 @@ addTest("function length", function(log){
addTest("function code", function(log){ addTest("function code", function(log){
"use strict"; "use strict";
if (!CanvasRenderingContext2D.prototype.getImageData.toString().match(/^\s*function getImageData\s*\(\)\s*\{\s*\[native code\]\s*\}\s*$/)){ if (!CanvasRenderingContext2D.prototype.getImageData.toString().match(
/^\s*function getImageData\s*\(\)\s*\{\s*\[native code\]\s*\}\s*$/
)){
log("unexpected function code:", CanvasRenderingContext2D.prototype.getImageData.toString()); log("unexpected function code:", CanvasRenderingContext2D.prototype.getImageData.toString());
return true; return true;
} }

View File

@ -20,8 +20,12 @@
show(document.getElementById("top"), topTest()); show(document.getElementById("top"), topTest());
show(document.getElementById("iframe"), iframeTest()); show(document.getElementById("iframe"), iframeTest());
} }
document.querySelector("#top button").addEventListener("click", function(){show(document.getElementById("top"), topTest());}); document.querySelector("#top button").addEventListener("click", function(){
document.querySelector("#iframe button").addEventListener("click", function(){show(document.getElementById("iframe"), iframeTest());}); show(document.getElementById("top"), topTest());
});
document.querySelector("#iframe button").addEventListener("click", function(){
show(document.getElementById("iframe"), iframeTest());
});
}()); }());
function draw(canvas){ function draw(canvas){