2015-09-06 12:26:50 +02: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/. */
|
|
|
|
|
|
|
|
var _ = require("sdk/l10n").get;
|
|
|
|
var preferences = require("sdk/simple-prefs");
|
|
|
|
var prefService = require("sdk/preferences/service");
|
|
|
|
var prefs = preferences.prefs;
|
|
|
|
var tabUtils = require("sdk/tabs/utils");
|
|
|
|
var lists = require("./lists");
|
|
|
|
var URL = require("sdk/url").URL;
|
|
|
|
|
|
|
|
exports.notify = function(window, callingStackMsg){
|
2015-09-08 11:42:32 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
var contentURL = new URL(window.location);
|
|
|
|
if (prefs.showNotifications && !lists.get("ignore").match(contentURL)){
|
|
|
|
var url = contentURL.href;
|
|
|
|
var domain = contentURL.hostname;
|
|
|
|
var message = _("fakedReadout").replace(/\{url\}/g, domain);
|
|
|
|
|
2015-09-06 15:40:34 +02:00
|
|
|
var tab = tabUtils.getTabForContentWindow(window);
|
|
|
|
var tabBrowser = tabUtils.getTabBrowserForTab(tab);
|
|
|
|
var browser = tabUtils.getBrowserForTab(tab);
|
2015-09-06 12:26:50 +02:00
|
|
|
|
|
|
|
var notifyBox = tabBrowser.getNotificationBox(browser);
|
|
|
|
var notification = notifyBox.getNotificationWithValue("fake-readout");
|
|
|
|
if (notification){
|
|
|
|
notification.label = message;
|
|
|
|
notification.url = url;
|
|
|
|
notification.domain = domain;
|
|
|
|
notification.callingStackMsg = callingStackMsg;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: _("displayFullURL"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
|
|
|
browser.contentWindow.alert(notification.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.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("displayCallingStack"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
|
|
|
browser.contentWindow.alert(notification.callingStackMsg);
|
|
|
|
// 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.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("ignorelistDomain"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2015-10-11 13:56:28 +02:00
|
|
|
var domain = browser.contentWindow.prompt(
|
2015-10-24 10:44:51 +02:00
|
|
|
_("inputIgnoreDomain"),
|
2015-10-11 13:56:28 +02:00
|
|
|
notification.domain
|
|
|
|
);
|
|
|
|
if (domain){
|
|
|
|
lists.appendTo("ignore", domain);
|
|
|
|
}
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("whitelistURL"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2015-10-08 17:17:02 +02:00
|
|
|
var url = browser.contentWindow.prompt(
|
2015-10-24 10:44:51 +02:00
|
|
|
_("inputWhitelistDomain"),
|
2015-10-08 17:17:02 +02:00
|
|
|
"^" + notification.url.replace(/([\\\+\*\?\[\^\]\$\(\)\{\}\=\!\|\.])/g, "\\$1") + "$"
|
|
|
|
);
|
|
|
|
if (url){
|
|
|
|
lists.appendTo("white", url);
|
|
|
|
}
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("whitelistDomain"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2015-10-08 17:17:02 +02:00
|
|
|
var domain = browser.contentWindow.prompt(
|
2015-10-24 10:44:51 +02:00
|
|
|
_("inputWhitelistURL"),
|
2015-10-08 17:17:02 +02:00
|
|
|
notification.domain
|
|
|
|
);
|
|
|
|
if (domain){
|
|
|
|
lists.appendTo("white", domain);
|
|
|
|
}
|
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("disableNotifications"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
|
|
|
prefs.showNotifications = false;
|
|
|
|
prefService.set("extensions.CanvasBlocker@kkapsner.de.showNotifications", prefs.showNotifications);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var priority = notifyBox.PRIORITY_WARNING_MEDIUM;
|
|
|
|
notification = notifyBox.appendNotification(
|
|
|
|
message,
|
|
|
|
"fake-readout",
|
|
|
|
"chrome://browser/skin/Info.png",
|
|
|
|
priority,
|
|
|
|
buttons
|
|
|
|
);
|
|
|
|
notification.url = url;
|
|
|
|
notification.domain = domain;
|
|
|
|
notification.callingStackMsg = callingStackMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|