1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-06-14 12:11:02 +02: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){ if (changedFunction.getStatus(undefined, siteStatus).active){
Object.defineProperty( Object.defineProperty(
window.wrappedJSObject[changedFunction.object].prototype, window.wrappedJSObject[changedFunction.object].prototype,
name, name,
{ {
enumerable: true, enumerable: true,
configureable: false, configureable: false,
get: function(){ get: function(){
if (!window.location.href){ if (!window.location.href){
return undef; return undef;
} }
var error = new Error(); var error = new Error();
if (checkStack(error.stack)){ if (checkStack(error.stack)){
return original; return original;
} }
var funcStatus = changedFunction.getStatus(this, siteStatus); var funcStatus = changedFunction.getStatus(this, siteStatus);
if (funcStatus.active){ if (funcStatus.active){
if (funcStatus.mode === "ask"){ if (funcStatus.mode === "ask"){
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack}); funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
}
switch (funcStatus.mode){
case "allow":
return original;
case "fake":
setRandomSupplyByType(prefs("rng"));
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
notify({url: window.location.href, errorStack: error.stack, messageId});
});
switch (fake){
case true:
return original;
case false:
return undef;
default:
return exportFunction(fake, window.wrappedJSObject);
}
//case "block":
default:
return undef;
}
} }
switch (funcStatus.mode){ else {
case "allow": return original;
return original;
case "fake":
setRandomSupplyByType(prefs("rng"));
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
notify({url: window.location.href, errorStack: error.stack, messageId});
});
switch (fake){
case true:
return original;
case false:
return undef;
default:
return exportFunction(fake, window.wrappedJSObject);
}
//case "block":
default:
return undef;
} }
} }
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;
}, },