1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00
CanvasBlocker/lib/frame.js
2017-01-31 21:51:08 +01:00

67 lines
1.5 KiB
JavaScript

/* jslint moz: true */
/* 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 {process, frames} = require("sdk/remote/child");
const {intercept} = require("./intercept.js");
const {ask} = require("./askForPermission.js");
const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js");
// Variable to "unload" the script
var enabled = true;
function check(message){
if (enabled){
return originalCheck(message);
}
else {
return {type: [], mode: "allow"};
}
}
function checkStack(stack){
if (enabled){
return originalCheckStack(stack);
}
else {
return true;
}
}
const _ = require("sdk/l10n").get;
function askWrapper(data){
return ask(data, {
_,
prefs
});
}
function notify(data){
process.port.emit("canvasBlocker-notify", data);
}
const preferences = require("sdk/simple-prefs");
function prefs(name){
return preferences.prefs[name];
}
frames.forEvery(function(frame){
frame.addEventListener("DOMWindowCreated", function(ev){
if (enabled){
var subject = ev.target.defaultView;
function notify(data){
frame.port.emit("canvasBlocker-notify", data);
}
intercept(
{subject},
{check, checkStack, ask: askWrapper, notify, prefs}
);
}
});
});
process.port.on("canvasBlocker-unload", function unload(){
enabled = false;
});
}());