2016-02-13 12:48:22 +01:00
|
|
|
/* jslint moz: true */
|
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/. */
|
2016-10-31 16:43:49 +01:00
|
|
|
(function(){
|
|
|
|
"use strict";
|
2016-02-13 12:28:36 +01:00
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
var URL = require("sdk/url").URL;
|
2016-02-13 12:28:36 +01:00
|
|
|
const {parseErrorStack} = require("./callingStack");
|
2016-11-11 00:19:25 +01:00
|
|
|
const {setTimeout, clearTimeout} = require("sdk/timers");
|
2015-09-06 12:26:50 +02:00
|
|
|
|
2016-02-13 12:28:36 +01:00
|
|
|
var tabUtils = require("sdk/tabs/utils");
|
2016-10-23 22:12:12 +02:00
|
|
|
exports.notify = function({url, errorStack, messageId}, {lists, notificationPref, _, browser, window}){
|
2016-10-31 16:43:49 +01:00
|
|
|
|
2016-02-13 12:28:36 +01:00
|
|
|
var callingStackMsg = parseErrorStack(errorStack);
|
2015-09-08 11:42:32 +02:00
|
|
|
|
2016-02-13 12:28:36 +01:00
|
|
|
var contentURL = new URL(url);
|
|
|
|
if (notificationPref.doShow() && !lists.get("ignore").match(contentURL)){
|
2016-02-13 12:48:22 +01:00
|
|
|
url = contentURL.href;
|
2015-09-06 12:26:50 +02:00
|
|
|
var domain = contentURL.hostname;
|
2016-10-23 22:12:12 +02:00
|
|
|
var message = _(messageId).replace(/\{url\}/g, domain || url);
|
2015-09-06 12:26:50 +02:00
|
|
|
|
2016-02-13 12:28:36 +01:00
|
|
|
var tab, tabBrowser;
|
|
|
|
if (browser){
|
|
|
|
window = tabUtils.getOwnerWindow(browser);
|
2017-01-31 20:03:48 +01:00
|
|
|
if (!window){
|
|
|
|
return;
|
|
|
|
}
|
2016-02-13 12:28:36 +01:00
|
|
|
tab = tabUtils.getTabForBrowser(browser);
|
2017-01-31 20:03:48 +01:00
|
|
|
if (!tab){
|
|
|
|
// page ist displayed in preview
|
|
|
|
return;
|
|
|
|
}
|
2016-02-13 12:28:36 +01:00
|
|
|
tabBrowser = tabUtils.getTabBrowser(window);
|
|
|
|
}
|
2017-01-31 20:03:48 +01:00
|
|
|
else if (window){
|
2016-02-13 12:28:36 +01:00
|
|
|
tab = tabUtils.getTabForContentWindow(window);
|
|
|
|
tabBrowser = tabUtils.getTabBrowserForTab(tab);
|
|
|
|
browser = tabUtils.getBrowserForTab(tab);
|
|
|
|
}
|
2015-09-06 12:26:50 +02:00
|
|
|
|
|
|
|
var notifyBox = tabBrowser.getNotificationBox(browser);
|
2016-11-22 08:30:57 +01:00
|
|
|
var notification = notifyBox.getNotificationWithValue("CanvasBlocker-" + messageId);
|
2015-09-06 12:26:50 +02:00
|
|
|
if (notification){
|
|
|
|
notification.label = message;
|
2016-11-11 00:19:25 +01:00
|
|
|
clearTimeout(notification.hideTimeout);
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
label: _("displayFullURL"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2016-02-13 12:28:36 +01:00
|
|
|
window.alert(notification.url);
|
2015-09-06 12:26:50 +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.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("displayCallingStack"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2016-02-13 12:28:36 +01:00
|
|
|
window.alert(notification.callingStackMsg);
|
2015-09-06 12:26:50 +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.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: _("ignorelistDomain"),
|
|
|
|
accessKey: "",
|
|
|
|
callback: function(){
|
2016-02-13 12:28:36 +01:00
|
|
|
var domain = window.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(){
|
2016-02-13 12:28:36 +01:00
|
|
|
var url = window.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(){
|
2016-02-13 12:28:36 +01:00
|
|
|
var domain = window.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(){
|
2016-02-13 12:28:36 +01:00
|
|
|
notificationPref.setShow(false);
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var priority = notifyBox.PRIORITY_WARNING_MEDIUM;
|
|
|
|
notification = notifyBox.appendNotification(
|
|
|
|
message,
|
2016-11-22 08:30:57 +01:00
|
|
|
"CanvasBlocker-" + messageId,
|
2015-09-06 12:26:50 +02:00
|
|
|
"chrome://browser/skin/Info.png",
|
|
|
|
priority,
|
|
|
|
buttons
|
|
|
|
);
|
|
|
|
}
|
2016-11-11 00:19:25 +01:00
|
|
|
notification.url = url;
|
|
|
|
notification.domain = domain;
|
|
|
|
notification.callingStackMsg = callingStackMsg;
|
|
|
|
var displayTime = notificationPref.displayTime();
|
|
|
|
if (displayTime){
|
|
|
|
notification.hideTimeout = setTimeout(function(){
|
2017-01-30 11:31:04 +01:00
|
|
|
try {
|
|
|
|
notification.close();
|
|
|
|
}
|
|
|
|
catch(e){
|
|
|
|
// tab is not in focus
|
|
|
|
}
|
2016-11-11 00:19:25 +01:00
|
|
|
}, displayTime * 1000);
|
|
|
|
}
|
|
|
|
|
2016-05-11 08:58:45 +02:00
|
|
|
return notification;
|
2015-09-06 12:26:50 +02:00
|
|
|
}
|
2016-10-31 16:43:49 +01:00
|
|
|
};
|
|
|
|
}());
|