1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 04:26:35 +02: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

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