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

Removed bypass option with non content windos.

This commit is contained in:
kkapsner 2015-08-26 18:12:12 +02:00
parent 01ea10fe79
commit f6e09a9b1a
4 changed files with 55 additions and 5 deletions

Binary file not shown.

View File

@ -147,7 +147,7 @@
toDataURL: { toDataURL: {
mode: blockMode.readAPI, mode: blockMode.readAPI,
object: unsafeWindow.HTMLCanvasElement, object: unsafeWindow.HTMLCanvasElement,
fake: function(){ fake: function toDataURL(){
var type = arguments[0] || "image/png"; var type = arguments[0] || "image/png";
return "data:" + type + ";base64," + btoa(randomImage); return "data:" + type + ";base64," + btoa(randomImage);
} }
@ -155,7 +155,7 @@
toBlob: { toBlob: {
mode: blockMode.readAPI, mode: blockMode.readAPI,
object: unsafeWindow.HTMLCanvasElement, object: unsafeWindow.HTMLCanvasElement,
fake: function(callback){ fake: function toBlob(callback){
var type = arguments[0] || "image/png"; var type = arguments[0] || "image/png";
var blob = new window.Blob(randomImage, {type: type}); var blob = new window.Blob(randomImage, {type: type});
callback(blob); callback(blob);
@ -169,7 +169,7 @@
getImageData: { getImageData: {
mode: blockMode.readAPI, mode: blockMode.readAPI,
object: unsafeWindow.CanvasRenderingContext2D, object: unsafeWindow.CanvasRenderingContext2D,
fake: function(sx, sy, sw, sh){ fake: function getImageData(sx, sy, sw, sh){
var l = sw * sh * 4; var l = sw * sh * 4;
var data = new Uint8ClampedArray(l); var data = new Uint8ClampedArray(l);
for (var i = 0; i < l; i += 1){ for (var i = 0; i < l; i += 1){
@ -185,7 +185,7 @@
readPixels: { readPixels: {
mode: blockMode.readAPI, mode: blockMode.readAPI,
object: unsafeWindow.WebGLRenderingContext, object: unsafeWindow.WebGLRenderingContext,
fake: function(x, y, width, height, format, type, pixels){ fake: function readPixels(x, y, width, height, format, type, pixels){
// fake not working due to XRay copy restrictions... // fake not working due to XRay copy restrictions...
// for (var i = 0; i < pixels.length; i += 1){ // for (var i = 0; i < pixels.length; i += 1){
// pixels[i] = Math.floor( // pixels[i] = Math.floor(

View File

@ -0,0 +1,49 @@
/* 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";
const observers = require("sdk/system/events");
const { when: unload } = require("sdk/system/unload");
var classes = {
HTMLCanvasElement: ["getContext", "toDataURL", "toBlob", "mozGetAsFile"],
CanvasRenderingContext2D: ["getImageData"],
WebGLRenderingContext: ["readPixels"]
};
var classNames = Object.keys(classes);
var originalProperties = new WeakMap();
function disable({subject: window}){
var oldProperties = {};
classNames.forEach(function(className){
oldProperties[className] = {};
classes[className].forEach(function(funcName){
oldProperties[className][funcName] = window.wrappedJSObject[className].prototype[funcName];
window.wrappedJSObject[className].prototype[funcName] = function(){};
});
});
originalProperties.set(window, oldProperties);
}
function reset({subject: document}){
var window = document.defaultView;
var oldProperties = originalProperties.get(window);
if (oldProperties){
originalProperties.delete(window);
classNames.forEach(function(className){
classes[className].forEach(function(funcName){
window.wrappedJSObject[className].prototype[funcName] = oldProperties[className][funcName];
});
});
}
}
observers.on("content-document-global-created", disable);
unload(() => observers.off("content-document-global-created", disable));
observers.on("document-element-inserted", reset);
unload(() => observers.off("document-element-inserted", reset));
}());

View File

@ -5,6 +5,7 @@
(function(){ (function(){
"use strict"; "use strict";
require("./stylePreferencePane"); require("./stylePreferencePane");
require("./disableWithoutDocumentElement");
var self = require("sdk/self"); var self = require("sdk/self");
var pageMod = require("sdk/page-mod"); var pageMod = require("sdk/page-mod");
@ -70,7 +71,7 @@
var url = new URL(worker.url); var url = new URL(worker.url);
if ( if (
(url.protocol === "about:") || (url.protocol === "about:") ||
(prefs.allowPDFCanvas && worker.tab.contentType.match(/\/pdf$/i)) (prefs.allowPDFCanvas && worker.tab && worker.tab.contentType.match(/\/pdf$/i))
){ ){
mode = "unblock"; mode = "unblock";
} }