1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-03 10:31:54 +01:00

Completely remove function monitoring for white listed sites.

Fixes #84.
This commit is contained in:
kkapsner 2016-11-19 15:35:00 +01:00
parent bda00e5741
commit fc07961c6b
2 changed files with 60 additions and 50 deletions

View File

@ -23,59 +23,61 @@
exports.setRandomSupplyByType = setRandomSupplyByType; exports.setRandomSupplyByType = setRandomSupplyByType;
exports.intercept = function intercept({subject: window}, {check, checkStack, ask, notify, prefs}){ exports.intercept = function intercept({subject: window}, {check, checkStack, ask, notify, prefs}){
var siteStatus = check({url: window.location.href}); var siteStatus = check({url: window.location.href});
apiNames.forEach(function(name){ if (siteStatus.mode !== "allow"){
var changedFunction = changedFunctions[name]; apiNames.forEach(function(name){
var original = window.wrappedJSObject[changedFunction.object].prototype[name]; var changedFunction = changedFunctions[name];
var original = window.wrappedJSObject[changedFunction.object].prototype[name];
if (changedFunction.getStatus(undefined, siteStatus).active){
Object.defineProperty( if (changedFunction.getStatus(undefined, siteStatus).active){
window.wrappedJSObject[changedFunction.object].prototype, Object.defineProperty(
name, window.wrappedJSObject[changedFunction.object].prototype,
{ name,
enumerable: true, {
configureable: false, enumerable: true,
get: function(){ configureable: false,
if (!window.location.href){ get: function(){
return undef; if (!window.location.href){
} return undef;
var error = new Error();
if (checkStack(error.stack)){
return original;
}
var funcStatus = changedFunction.getStatus(this, siteStatus);
if (funcStatus.active){
if (funcStatus.mode === "ask"){
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
} }
switch (funcStatus.mode){ var error = new Error();
case "allow": if (checkStack(error.stack)){
return original; return original;
case "fake": }
setRandomSupplyByType(prefs("rng")); var funcStatus = changedFunction.getStatus(this, siteStatus);
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
notify({url: window.location.href, errorStack: error.stack, messageId}); if (funcStatus.active){
}); if (funcStatus.mode === "ask"){
switch (fake){ funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
case true: }
return original; switch (funcStatus.mode){
case false: case "allow":
return undef; return original;
default: case "fake":
return exportFunction(fake, window.wrappedJSObject); setRandomSupplyByType(prefs("rng"));
} var fake = changedFunction.fakeGenerator(prefs, function(messageId){
//case "block": notify({url: window.location.href, errorStack: error.stack, messageId});
default: });
return undef; switch (fake){
case true:
return original;
case false:
return undef;
default:
return exportFunction(fake, window.wrappedJSObject);
}
//case "block":
default:
return undef;
}
}
else {
return original;
} }
}
else {
return original;
} }
} }
} );
); }
} });
}); }
}; };
}()); }());

View File

@ -94,6 +94,7 @@
}; };
} }
else { else {
var status = Object.create(status);
status.active = false; status.active = false;
return status; return status;
} }
@ -109,6 +110,7 @@
}, },
toDataURL: { toDataURL: {
getStatus: function(obj, status){ getStatus: function(obj, status){
var status = Object.create(status);
if (hasType(status, "input")){ if (hasType(status, "input")){
var contextType = canvasContextType.get(obj); var contextType = canvasContextType.get(obj);
status.active = contextType !== "2d"; status.active = contextType !== "2d";
@ -129,6 +131,7 @@
}, },
toBlob: { toBlob: {
getStatus: function(obj, status){ getStatus: function(obj, status){
var status = Object.create(status);
if (hasType(status, "input")){ if (hasType(status, "input")){
var contextType = canvasContextType.get(obj); var contextType = canvasContextType.get(obj);
status.active = contextType !== "2d"; status.active = contextType !== "2d";
@ -150,6 +153,7 @@
}, },
mozGetAsFile: { mozGetAsFile: {
getStatus: function(obj, status){ getStatus: function(obj, status){
var status = Object.create(status);
if (hasType(status, "input")){ if (hasType(status, "input")){
var contextType = canvasContextType.get(obj); var contextType = canvasContextType.get(obj);
status.active = contextType !== "2d"; status.active = contextType !== "2d";
@ -170,6 +174,7 @@
}, },
getImageData: { getImageData: {
getStatus: function(obj, status){ getStatus: function(obj, status){
var status = Object.create(status);
if (hasType(status, "input")){ if (hasType(status, "input")){
var contextType = canvasContextType.get(obj); var contextType = canvasContextType.get(obj);
status.active = contextType !== "2d"; status.active = contextType !== "2d";
@ -207,6 +212,7 @@
}, },
fillText: { fillText: {
getStatus: function(obj, status){ getStatus: function(obj, status){
var status = Object.create(status);
status.active = hasType(status, "input"); status.active = hasType(status, "input");
return status; return status;
}, },
@ -225,6 +231,7 @@
}, },
strokeText: { strokeText: {
getStatus: function(obj, status){ getStatus: function(obj, status){
var status = Object.create(status);
status.active = hasType(status, "input"); status.active = hasType(status, "input");
return status; return status;
}, },
@ -243,6 +250,7 @@
}, },
readPixels: { readPixels: {
getStatus: function(obj, status){ getStatus: function(obj, status){
var status = Object.create(status);
status.active = hasType(status, "readout") || hasType(status, "input"); status.active = hasType(status, "readout") || hasType(status, "input");
return status; return status;
}, },