Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 /** @module notificationHelper */ | 18 /** @module notificationHelper */ |
19 | 19 |
20 let {startIconAnimation, stopIconAnimation} = require("icon"); | 20 let {startIconAnimation, stopIconAnimation} = require("icon"); |
21 let {Utils} = require("utils"); | 21 let {Utils} = require("utils"); |
22 let {Notification: NotificationStorage} = require("notification"); | 22 let {Notification: NotificationStorage} = require("notification"); |
23 let {stringifyURL} = require("url"); | 23 let {stringifyURL} = require("url"); |
24 let {initAntiAdblockNotification} = require("antiadblockInit"); | 24 let {initAntiAdblockNotification} = require("antiadblockInit"); |
25 | 25 |
26 let activeNotification = null; | 26 let activeNotification = null; |
27 let displayMethods = { | 27 let defaultDisplayMethods = ["popup"]; |
Sebastian Noack
2015/09/09 17:38:57
Please use Object.create(null) for objects used as
| |
28 _default: ["popup"], | 28 let displayMethods = Object.create(null); |
Sebastian Noack
2015/09/09 17:38:57
There is no reason why this is a prefixed property
| |
29 critical: ["icon", "notification", "popup"], | 29 displayMethods.critical = ["icon", "notification", "popup"]; |
30 question: ["notification"], | 30 displayMethods.question = ["notification"]; |
31 normal: ["notification"], | 31 displayMethods.normal = ["notification"]; |
32 information: ["icon", "popup"] | 32 displayMethods.information = ["icon", "popup"]; |
33 }; | |
34 | 33 |
35 // Chrome on Linux does not fully support chrome.notifications until version 35 | 34 // Chrome on Linux does not fully support chrome.notifications until version 35 |
36 // https://code.google.com/p/chromium/issues/detail?id=291485 | 35 // https://code.google.com/p/chromium/issues/detail?id=291485 |
37 let canUseChromeNotifications = (function() | 36 let canUseChromeNotifications = (function() |
38 { | 37 { |
39 let info = require("info"); | 38 let info = require("info"); |
40 if (info.platform == "chromium" && "notifications" in chrome) | 39 if (info.platform == "chromium" && "notifications" in chrome) |
41 { | 40 { |
42 if (navigator.platform.indexOf("Linux") == -1) | 41 if (navigator.platform.indexOf("Linux") == -1) |
43 return true; | 42 return true; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 }; | 246 }; |
248 | 247 |
249 /** | 248 /** |
250 * Determines whether a given display method should be used for a | 249 * Determines whether a given display method should be used for a |
251 * specified notification type. | 250 * specified notification type. |
252 * | 251 * |
253 * @param {string} method Display method: icon, notification or popup | 252 * @param {string} method Display method: icon, notification or popup |
254 * @param {string} notificationType | 253 * @param {string} notificationType |
255 * @return {boolean} | 254 * @return {boolean} |
256 */ | 255 */ |
257 exports.shouldDisplay = shouldDisplay; | 256 exports.shouldDisplay = shouldDisplay; |
Sebastian Noack
2015/09/11 13:15:46
I just realized that this way shouldDisplay is doc
| |
258 function shouldDisplay(method, notificationType) | 257 function shouldDisplay(method, notificationType) |
259 { | 258 { |
260 let methods = displayMethods[notificationType] || displayMethods._default; | 259 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
261 return methods.indexOf(method) > -1; | 260 return methods.indexOf(method) > -1; |
Sebastian Noack
2015/09/09 17:38:57
If you use objects for these "lists", you can use
| |
262 } | 261 } |
263 | 262 |
264 NotificationStorage.addShowListener(showNotification); | 263 NotificationStorage.addShowListener(showNotification); |
LEFT | RIGHT |