1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Switch from frameScript to require("sdk/remote/...").

Fixes #98. Fixes #100.
This commit is contained in:
kkapsner 2017-01-31 21:31:55 +01:00
parent c0c16b6546
commit 602d5a6bfd
3 changed files with 74 additions and 142 deletions

67
lib/frame.js Normal file
View file

@ -0,0 +1,67 @@
/* 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;
});
}());