2014-10-14 01:06:11 +02:00
|
|
|
/* global console */
|
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";
|
2015-06-23 13:14:50 +02:00
|
|
|
require("./stylePreferencePane");
|
2015-08-26 18:12:12 +02:00
|
|
|
require("./disableWithoutDocumentElement");
|
2015-04-22 11:18:26 +02:00
|
|
|
|
2014-08-20 10:21:38 +02:00
|
|
|
var self = require("sdk/self");
|
|
|
|
var pageMod = require("sdk/page-mod");
|
2014-10-09 00:26:36 +02:00
|
|
|
var array = require("sdk/util/array");
|
2014-08-20 10:21:38 +02:00
|
|
|
var preferences = require("sdk/simple-prefs");
|
2015-04-14 01:26:04 +02:00
|
|
|
var prefService = require("sdk/preferences/service");
|
2014-08-20 10:21:38 +02:00
|
|
|
var prefs = preferences.prefs;
|
2014-10-14 01:06:11 +02:00
|
|
|
var URL = require("sdk/url").URL;
|
2014-08-20 10:21:38 +02:00
|
|
|
var _ = require("sdk/l10n").get;
|
2015-04-15 10:08:01 +02:00
|
|
|
var tabUtils = require("sdk/tabs/utils");
|
2014-08-01 12:03:23 +02:00
|
|
|
|
2015-06-23 13:14:50 +02:00
|
|
|
var sharedFunctions = require("./sharedFunctions");
|
2015-04-22 11:18:26 +02:00
|
|
|
var getDomainRegExpList = sharedFunctions.getDomainRegExpList;
|
2014-08-20 10:21:38 +02:00
|
|
|
// preferences
|
2014-10-09 00:26:36 +02:00
|
|
|
Object.keys(prefs).forEach(function(pref){
|
|
|
|
preferences.on(pref, function(){
|
|
|
|
workers.forEach(checkWorker);
|
|
|
|
});
|
|
|
|
});
|
2014-08-20 10:21:38 +02:00
|
|
|
var whiteList;
|
|
|
|
function updateWhiteList(){
|
|
|
|
whiteList = getDomainRegExpList(prefs.whiteList);
|
|
|
|
}
|
2014-08-01 12:03:23 +02:00
|
|
|
updateWhiteList();
|
2014-08-20 10:21:38 +02:00
|
|
|
preferences.on("whiteList", function(){
|
|
|
|
updateWhiteList();
|
|
|
|
});
|
2014-07-31 03:05:51 +02:00
|
|
|
|
2014-08-20 10:21:38 +02:00
|
|
|
var blackList;
|
|
|
|
function updateBlackList(){
|
|
|
|
blackList = getDomainRegExpList(prefs.blackList);
|
|
|
|
}
|
2014-08-11 18:05:56 +02:00
|
|
|
updateBlackList();
|
2014-08-20 10:21:38 +02:00
|
|
|
preferences.on("blackList", function(){
|
|
|
|
updateBlackList();
|
|
|
|
});
|
2015-04-23 10:04:20 +02:00
|
|
|
|
|
|
|
var ignoreList;
|
|
|
|
function updateIgnoreList(){
|
|
|
|
ignoreList = getDomainRegExpList(prefs.ignoreList);
|
|
|
|
}
|
|
|
|
updateIgnoreList();
|
|
|
|
preferences.on("ignoreList", function(){
|
|
|
|
updateIgnoreList();
|
|
|
|
});
|
2014-10-11 00:07:51 +02:00
|
|
|
|
2014-12-15 18:43:47 +01:00
|
|
|
// preferences for injected file
|
|
|
|
var preferencesForInjected = ["showCallingFile", "showCompleteCallingStack"];
|
|
|
|
preferencesForInjected.forEach(function(name){
|
|
|
|
preferences.on(name, function(){
|
|
|
|
workers.forEach(function(worker){
|
|
|
|
worker.port.emit("set", name, prefs[name]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-11 00:07:51 +02:00
|
|
|
function checkURL(url){
|
2015-04-22 11:18:26 +02:00
|
|
|
return sharedFunctions.checkURL(url, prefs.blockMode, whiteList, blackList);
|
2014-10-11 00:07:51 +02:00
|
|
|
}
|
|
|
|
function checkWorker(worker){
|
|
|
|
try {
|
2015-04-15 11:39:35 +02:00
|
|
|
var mode;
|
2015-04-22 11:55:31 +02:00
|
|
|
var url = new URL(worker.url);
|
2015-04-15 11:39:35 +02:00
|
|
|
if (
|
|
|
|
(url.protocol === "about:") ||
|
2015-08-26 18:12:12 +02:00
|
|
|
(prefs.allowPDFCanvas && worker.tab && worker.tab.contentType.match(/\/pdf$/i))
|
2015-04-15 11:39:35 +02:00
|
|
|
){
|
|
|
|
mode = "unblock";
|
|
|
|
}
|
|
|
|
else {
|
2015-04-22 11:55:31 +02:00
|
|
|
mode = checkURL(url);
|
2015-04-15 11:39:35 +02:00
|
|
|
}
|
|
|
|
worker.port.emit(mode, prefs.askOnlyOnce);
|
2014-10-09 00:26:36 +02:00
|
|
|
}
|
|
|
|
catch (e){
|
2015-09-03 00:05:43 +02:00
|
|
|
// console.log("Error updating " + worker.url + ": " + e.message);
|
2014-08-01 12:03:23 +02:00
|
|
|
}
|
2014-07-31 03:05:51 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 00:26:36 +02:00
|
|
|
var workers = [];
|
2015-04-24 01:04:14 +02:00
|
|
|
var workerTranslations = {
|
|
|
|
sourceOutput: _("sourceOutput"),
|
|
|
|
stackEntryOutput: _("stackEntryOutput")
|
|
|
|
};
|
|
|
|
|
|
|
|
["", "Readout"].forEach(function(type){
|
|
|
|
["", "Visible", "Invisible"].forEach(function(visibility){
|
|
|
|
var text = "askFor" + visibility + type + "Permission";
|
|
|
|
workerTranslations[text] = _(text);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-04-22 11:18:26 +02:00
|
|
|
var workerOptions = {
|
|
|
|
blockMode: checkURL(),
|
|
|
|
whiteList: prefs.whiteList,
|
|
|
|
blackList: prefs.blackList,
|
2015-04-24 01:04:14 +02:00
|
|
|
askOnce: prefs.askOnce,
|
|
|
|
translations: workerTranslations
|
2015-04-22 11:18:26 +02:00
|
|
|
};
|
|
|
|
preferences.on("blockMode", function(){
|
|
|
|
workerOptions.blockMode = checkURL();
|
|
|
|
});
|
|
|
|
["whiteList", "blackList", "askOnce"].forEach(function(prefName){
|
|
|
|
preferences.on(prefName, function(){
|
|
|
|
workerOptions[prefName] = prefs[prefName];
|
|
|
|
});
|
|
|
|
});
|
2014-08-20 10:21:38 +02:00
|
|
|
pageMod.PageMod({
|
|
|
|
include: "*",
|
|
|
|
contentScriptWhen: "start",
|
2015-04-22 11:18:26 +02:00
|
|
|
contentScriptFile: [
|
|
|
|
self.data.url("sharedFunctions.js").replace("/data/", "/lib/"),
|
|
|
|
self.data.url("inject.js"),
|
|
|
|
],
|
|
|
|
contentScriptOptions: workerOptions,
|
2014-08-20 10:21:38 +02:00
|
|
|
onAttach: function(worker){
|
|
|
|
|
2014-10-09 00:26:36 +02:00
|
|
|
array.add(workers, worker);
|
|
|
|
worker.on("pageshow", function(){
|
|
|
|
array.add(workers, this);
|
|
|
|
});
|
|
|
|
worker.on("pagehide", function(){
|
|
|
|
array.remove(workers, this);
|
|
|
|
});
|
|
|
|
worker.on("detach", function(){
|
|
|
|
array.remove(workers, this);
|
|
|
|
});
|
2014-12-15 18:43:47 +01:00
|
|
|
|
|
|
|
preferencesForInjected.forEach(function(name){
|
|
|
|
worker.port.emit("set", name, prefs[name]);
|
|
|
|
});
|
2014-12-04 23:34:41 +01:00
|
|
|
|
2014-08-20 10:21:38 +02:00
|
|
|
checkWorker(worker);
|
2015-04-14 01:26:04 +02:00
|
|
|
|
|
|
|
// display notifications
|
2015-04-15 12:02:21 +02:00
|
|
|
worker.port.on("accessed readAPI", function(status, callingStackMsg){
|
2015-04-14 01:26:04 +02:00
|
|
|
switch (status){
|
|
|
|
case "fake":
|
2015-04-15 10:08:01 +02:00
|
|
|
|
2015-04-14 01:26:04 +02:00
|
|
|
var contentURL = new URL(worker.contentURL);
|
2015-05-03 13:39:27 +02:00
|
|
|
if (prefs.showNotifications && !ignoreList.match(contentURL)){
|
2015-04-23 10:04:20 +02:00
|
|
|
var url = contentURL.href;
|
|
|
|
var domain = contentURL.hostname;
|
2015-09-01 21:40:30 +02:00
|
|
|
var message = _("fakedReadout").replace(/\{url\}/g, domain);
|
2015-04-23 10:04:20 +02:00
|
|
|
|
|
|
|
var tab = tabUtils.getTabForId(worker.tab.id);
|
|
|
|
var tabBrowser = tabUtils.getTabBrowserForTab(tab);
|
|
|
|
var browser = tabUtils.getBrowserForTab(tab);
|
|
|
|
|
|
|
|
var notifyBox = tabBrowser.getNotificationBox(browser);
|
|
|
|
var notification = notifyBox.getNotificationWithValue("fake-readout");
|
|
|
|
if (notification){
|
|
|
|
notification.label = message;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var buttons = [
|
2015-09-01 21:40:30 +02:00
|
|
|
{
|
|
|
|
label: _("displayFullURL"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
|
|
|
browser.contentWindow.alert(url);
|
|
|
|
// only way to prevent closing... see https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Method/appendNotification#Notification_box_events
|
|
|
|
throw new Error("Do not close notification.");
|
|
|
|
}
|
|
|
|
},
|
2015-04-23 10:04:20 +02:00
|
|
|
{
|
|
|
|
label: _("displayCallingStack"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
|
|
|
browser.contentWindow.alert(callingStackMsg);
|
2015-04-24 01:04:14 +02:00
|
|
|
// only way to prevent closing... see https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Method/appendNotification#Notification_box_events
|
|
|
|
throw new Error("Do not close notification.");
|
2015-04-23 10:04:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("ignorelistDomain"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2015-05-11 10:45:04 +02:00
|
|
|
prefs.ignoreList += (prefs.ignoreList? ",": "") + domain;
|
2015-04-23 10:04:20 +02:00
|
|
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.ignoreList", prefs.ignoreList);
|
|
|
|
updateIgnoreList();
|
|
|
|
}
|
|
|
|
},
|
2015-05-11 10:55:12 +02:00
|
|
|
{
|
|
|
|
label: _("whitelistURL"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
|
|
|
prefs.whiteList += (prefs.whiteList? ",": "") + "^" + url.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "$";
|
|
|
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.whiteList", prefs.whiteList);
|
|
|
|
updateWhiteList();
|
|
|
|
workers.forEach(checkWorker);
|
|
|
|
}
|
|
|
|
},
|
2015-04-23 10:04:20 +02:00
|
|
|
{
|
|
|
|
label: _("whitelistDomain"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2015-05-11 10:45:04 +02:00
|
|
|
prefs.whiteList += (prefs.whiteList? ",": "") + domain;
|
2015-04-23 10:04:20 +02:00
|
|
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.whiteList", prefs.whiteList);
|
|
|
|
updateWhiteList();
|
|
|
|
workers.forEach(checkWorker);
|
|
|
|
}
|
2015-05-06 23:59:36 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("disableNotifications"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
|
|
|
prefs.showNotifications = false;
|
|
|
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.showNotifications", prefs.showNotifications);
|
|
|
|
}
|
2015-04-14 01:26:04 +02:00
|
|
|
}
|
2015-04-23 10:04:20 +02:00
|
|
|
];
|
2015-04-14 01:26:04 +02:00
|
|
|
|
2015-04-23 10:04:20 +02:00
|
|
|
var priority = notifyBox.PRIORITY_WARNING_MEDIUM;
|
2015-04-24 01:04:14 +02:00
|
|
|
notification = notifyBox.appendNotification(
|
2015-04-23 10:04:20 +02:00
|
|
|
message,
|
|
|
|
"fake-readout",
|
|
|
|
"chrome://browser/skin/Info.png",
|
|
|
|
priority,
|
|
|
|
buttons
|
|
|
|
);
|
2015-04-24 01:04:14 +02:00
|
|
|
}
|
2015-04-14 01:26:04 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2014-08-20 10:21:38 +02:00
|
|
|
},
|
|
|
|
});
|
2014-07-31 03:05:51 +02:00
|
|
|
|
2014-08-20 10:21:38 +02:00
|
|
|
}());
|