From fc07961c6bb01a76fa89e0e04bf6bef9a3a3e38d Mon Sep 17 00:00:00 2001 From: kkapsner Date: Sat, 19 Nov 2016 15:35:00 +0100 Subject: [PATCH] Completely remove function monitoring for white listed sites. Fixes #84. --- lib/intercept.js | 102 +++++++++++++++++++++++---------------------- lib/modifiedAPI.js | 8 ++++ 2 files changed, 60 insertions(+), 50 deletions(-) diff --git a/lib/intercept.js b/lib/intercept.js index a2427ff..a20d754 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -23,59 +23,61 @@ exports.setRandomSupplyByType = setRandomSupplyByType; exports.intercept = function intercept({subject: window}, {check, checkStack, ask, notify, prefs}){ var siteStatus = check({url: window.location.href}); - apiNames.forEach(function(name){ - var changedFunction = changedFunctions[name]; - var original = window.wrappedJSObject[changedFunction.object].prototype[name]; - - if (changedFunction.getStatus(undefined, siteStatus).active){ - Object.defineProperty( - window.wrappedJSObject[changedFunction.object].prototype, - name, - { - enumerable: true, - configureable: false, - get: function(){ - 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}); + if (siteStatus.mode !== "allow"){ + apiNames.forEach(function(name){ + var changedFunction = changedFunctions[name]; + var original = window.wrappedJSObject[changedFunction.object].prototype[name]; + + if (changedFunction.getStatus(undefined, siteStatus).active){ + Object.defineProperty( + window.wrappedJSObject[changedFunction.object].prototype, + name, + { + enumerable: true, + configureable: false, + get: function(){ + if (!window.location.href){ + return undef; } - 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; + 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){ + 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; + } + } + else { + return original; } - } - else { - return original; } } - } - ); - } - }); + ); + } + }); + } }; }()); \ No newline at end of file diff --git a/lib/modifiedAPI.js b/lib/modifiedAPI.js index 27e974e..a5f0aeb 100644 --- a/lib/modifiedAPI.js +++ b/lib/modifiedAPI.js @@ -94,6 +94,7 @@ }; } else { + var status = Object.create(status); status.active = false; return status; } @@ -109,6 +110,7 @@ }, toDataURL: { getStatus: function(obj, status){ + var status = Object.create(status); if (hasType(status, "input")){ var contextType = canvasContextType.get(obj); status.active = contextType !== "2d"; @@ -129,6 +131,7 @@ }, toBlob: { getStatus: function(obj, status){ + var status = Object.create(status); if (hasType(status, "input")){ var contextType = canvasContextType.get(obj); status.active = contextType !== "2d"; @@ -150,6 +153,7 @@ }, mozGetAsFile: { getStatus: function(obj, status){ + var status = Object.create(status); if (hasType(status, "input")){ var contextType = canvasContextType.get(obj); status.active = contextType !== "2d"; @@ -170,6 +174,7 @@ }, getImageData: { getStatus: function(obj, status){ + var status = Object.create(status); if (hasType(status, "input")){ var contextType = canvasContextType.get(obj); status.active = contextType !== "2d"; @@ -207,6 +212,7 @@ }, fillText: { getStatus: function(obj, status){ + var status = Object.create(status); status.active = hasType(status, "input"); return status; }, @@ -225,6 +231,7 @@ }, strokeText: { getStatus: function(obj, status){ + var status = Object.create(status); status.active = hasType(status, "input"); return status; }, @@ -243,6 +250,7 @@ }, readPixels: { getStatus: function(obj, status){ + var status = Object.create(status); status.active = hasType(status, "readout") || hasType(status, "input"); return status; },