2015-09-08 11:41:33 +02:00
|
|
|
/* jslint moz: true */
|
2015-01-16 13:01:01 +01:00
|
|
|
/* 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/. */
|
2014-08-20 10:21:38 +02:00
|
|
|
(function(){
|
2014-10-14 01:06:11 +02:00
|
|
|
"use strict";
|
2017-06-25 22:33:12 +02:00
|
|
|
|
|
|
|
console.log("start main script");
|
|
|
|
browser.runtime.onMessage.addListener(function(data){
|
|
|
|
console.log("got data", data);
|
|
|
|
});
|
|
|
|
browser.runtime.onConnect.addListener(function(port){
|
2017-06-29 07:21:36 +02:00
|
|
|
console.log("got port", port);
|
|
|
|
port.postMessage({tabId: port.sender.tab.id});
|
|
|
|
port.onMessage.addListener(function(data){
|
|
|
|
browser.pageAction.show(port.sender.tab.id);
|
|
|
|
console.log("got data", data, "from port", port);
|
|
|
|
});
|
2017-06-25 22:33:12 +02:00
|
|
|
});
|
2017-06-29 07:21:36 +02:00
|
|
|
|
2017-06-25 22:33:12 +02:00
|
|
|
console.log("end main script");
|
|
|
|
return null;
|
2015-06-23 13:14:50 +02:00
|
|
|
require("./stylePreferencePane");
|
2014-10-11 00:07:51 +02:00
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
|
2016-02-13 12:28:36 +01:00
|
|
|
const {when: unload} = require("sdk/system/unload");
|
|
|
|
const {notify} = require("./notifications");
|
|
|
|
|
|
|
|
const _ = require("sdk/l10n").get;
|
|
|
|
const lists = require("./lists");
|
2015-09-06 12:26:50 +02:00
|
|
|
const preferences = require("sdk/simple-prefs");
|
|
|
|
const prefs = preferences.prefs;
|
2014-12-15 18:43:47 +01:00
|
|
|
|
2017-05-21 13:17:35 +02:00
|
|
|
require("./webExtension");
|
|
|
|
|
2016-02-13 12:28:36 +01:00
|
|
|
const notificationPref = {
|
|
|
|
doShow: function(){
|
|
|
|
return prefs.showNotifications;
|
|
|
|
},
|
|
|
|
setShow: function(value){
|
|
|
|
prefs.showNotifications = value;
|
|
|
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.showNotifications", prefs.showNotifications);
|
2016-11-11 00:19:25 +01:00
|
|
|
},
|
|
|
|
displayTime: function(){
|
|
|
|
return prefs.notificationDisplayTime;
|
2015-09-06 15:40:34 +02:00
|
|
|
}
|
2016-02-13 12:28:36 +01:00
|
|
|
};
|
2015-04-24 01:04:14 +02:00
|
|
|
|
2017-01-31 21:31:55 +01:00
|
|
|
const {processes, frames, remoteRequire} = require("sdk/remote/parent");
|
2017-04-23 00:27:40 +02:00
|
|
|
// remoteRequire("./frame.js", module); // currently not working due to a regression in the SDK
|
|
|
|
var framePath = require("sdk/self").data.url("").replace(/data\/$/, "") + "lib/frame.js";
|
|
|
|
remoteRequire(framePath);
|
2015-09-06 12:26:50 +02:00
|
|
|
|
2017-01-31 21:31:55 +01:00
|
|
|
frames.port.on("canvasBlocker-notify", function(frame, data){
|
|
|
|
notify(data, {lists, _, notificationPref, browser: frame.frameElement});
|
2016-02-13 12:28:36 +01:00
|
|
|
});
|
2017-01-31 21:31:55 +01:00
|
|
|
unload(function(){
|
|
|
|
processes.port.emit("canvasBlocker-unload");
|
2016-02-13 12:28:36 +01:00
|
|
|
});
|
|
|
|
|
2017-02-01 10:49:33 +01:00
|
|
|
// persistent rng
|
2017-02-10 17:37:35 +01:00
|
|
|
var persistentRnd = Object.create(null);
|
|
|
|
try {
|
|
|
|
let storedData = JSON.parse(prefs.persistentRndStorage);
|
|
|
|
for (var domain in storedData){
|
|
|
|
var value = storedData[domain];
|
|
|
|
if (
|
|
|
|
Array.isArray(value) &&
|
|
|
|
value.length === 128 &&
|
|
|
|
value.every(function(value){return typeof value === "number" && value >= 0 && value < 256;})
|
|
|
|
){
|
|
|
|
persistentRnd[domain] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e){}
|
|
|
|
|
2017-02-01 10:49:33 +01:00
|
|
|
processes.port.on("canvasBlocker-new-domain-rnd", function(process, data){
|
|
|
|
processes.port.emit("canvasBlocker-set-domain-rnd", data);
|
|
|
|
persistentRnd[data.domain] = data.rnd;
|
2017-02-10 17:37:35 +01:00
|
|
|
if (prefs.storePersistentRnd){
|
|
|
|
prefs.persistentRndStorage = JSON.stringify(persistentRnd);
|
|
|
|
}
|
2017-02-01 10:49:33 +01:00
|
|
|
});
|
2017-02-10 17:37:35 +01:00
|
|
|
processes.forEvery(function(process){
|
2017-02-01 10:49:33 +01:00
|
|
|
if (process.isRemote){
|
2017-02-10 17:37:35 +01:00
|
|
|
for (var domain in persistentRnd){
|
|
|
|
process.port.emit("canvasBlocker-set-domain-rnd", {domain, rnd: persistentRnd[domain]});
|
2017-02-01 10:49:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-02-10 17:37:35 +01:00
|
|
|
preferences.on("storePersistentRnd", function(){
|
|
|
|
if (prefs.storePersistentRnd){
|
|
|
|
prefs.persistentRndStorage = JSON.stringify(persistentRnd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prefs.persistentRndStorage = "";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
preferences.on("clearPersistentRnd", function(){
|
|
|
|
persistentRnd = Object.create(null);
|
|
|
|
prefs.persistentRndStorage = "";
|
|
|
|
processes.port.emit("canvasBlocker-clear-domain-rnd");
|
|
|
|
});
|
2017-02-01 10:49:33 +01:00
|
|
|
|
2017-01-31 21:31:55 +01:00
|
|
|
// show release notes
|
2016-11-13 15:34:33 +01:00
|
|
|
var data = require("sdk/self").data;
|
|
|
|
preferences.on("showReleaseNotes", function(){
|
|
|
|
var url = data.url("releaseNotes.txt").replace("/data/", "/");
|
|
|
|
require("sdk/tabs").open(url);
|
|
|
|
});
|
2014-08-20 10:21:38 +02:00
|
|
|
}());
|