2016-02-13 12:28:36 +01:00
|
|
|
/* 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 {utils: Cu} = Components;
|
|
|
|
const COMMONJS_URI = "resource://gre/modules/commonjs";
|
|
|
|
const {require} = Cu.import(COMMONJS_URI + "/toolkit/require.js", {});
|
2016-10-24 22:30:57 +02:00
|
|
|
const {intercept} = require("../lib/intercept.js");
|
2016-02-13 12:28:36 +01:00
|
|
|
const {ask} = require("../lib/askForPermission.js");
|
|
|
|
|
|
|
|
// Variable to "unload" the script
|
|
|
|
var enabled = true;
|
|
|
|
|
|
|
|
function check(message){
|
|
|
|
if (enabled){
|
|
|
|
var status = sendSyncMessage(
|
|
|
|
"canvasBlocker-check",
|
|
|
|
message
|
|
|
|
);
|
|
|
|
return status[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return {type: [], mode: "allow"};
|
|
|
|
}
|
|
|
|
}
|
2016-11-13 14:51:58 +01:00
|
|
|
function checkStack(stack){
|
|
|
|
if (enabled){
|
|
|
|
var status = sendSyncMessage(
|
|
|
|
"canvasBlocker-checkStack",
|
|
|
|
stack
|
|
|
|
);
|
|
|
|
return status[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 12:28:36 +01:00
|
|
|
function askWrapper(data){
|
|
|
|
return ask(data, {
|
|
|
|
_: function(token){
|
|
|
|
return sendSyncMessage(
|
|
|
|
"canvasBlocker-translate",
|
|
|
|
token
|
|
|
|
)[0];
|
|
|
|
},
|
2016-05-10 08:01:21 +02:00
|
|
|
prefs
|
2016-02-13 12:28:36 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function notify(data){
|
|
|
|
sendAsyncMessage("canvasBlocker-notify", data);
|
|
|
|
}
|
2016-05-10 08:01:21 +02:00
|
|
|
function prefs(name){
|
|
|
|
return sendSyncMessage(
|
|
|
|
"canvasBlocker-pref-get",
|
|
|
|
name
|
|
|
|
)[0];
|
|
|
|
}
|
2016-02-13 12:28:36 +01:00
|
|
|
|
|
|
|
function interceptWrapper(ev){
|
|
|
|
if (enabled){
|
|
|
|
// window is only equal to content for the top window. For susequent
|
|
|
|
// calls (e.g. iframe windows) the new generated window has to be
|
|
|
|
// used.
|
|
|
|
|
|
|
|
var window = ev.target.defaultView;
|
|
|
|
intercept(
|
|
|
|
{subject: window},
|
2016-11-13 14:51:58 +01:00
|
|
|
{check, checkStack, ask: askWrapper, notify, prefs}
|
2016-02-13 12:28:36 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addEventListener("DOMWindowCreated", interceptWrapper);
|
|
|
|
var context = this;
|
|
|
|
addEventListener("unload", function(ev){
|
|
|
|
if (ev.target === context){
|
|
|
|
removeEventListener("DOMWindowCreated", interceptWrapper);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addMessageListener("canvasBlocker-unload", function unload(){
|
|
|
|
enabled = false;
|
|
|
|
removeEventListener("DOMWindowCreated", interceptWrapper);
|
|
|
|
removeMessageListener("canvasBlocker-unload", unload);
|
|
|
|
});
|
|
|
|
}());
|