| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 "use strict"; |
| 21 let {Utils} = require("utils"); | 21 |
| 22 let {Notification: NotificationStorage} = require("notification"); | 22 const {startIconAnimation, stopIconAnimation} = require("icon"); |
| 23 let {stringifyURL} = require("url"); | 23 const {Utils} = require("utils"); |
| 24 let {initAntiAdblockNotification} = require("antiadblockInit"); | 24 const {Notification: NotificationStorage} = require("notification"); |
| 25 let {Prefs} = require("prefs"); | 25 const {stringifyURL} = require("url"); |
| 26 const {initAntiAdblockNotification} = require("antiadblockInit"); |
| 27 const {Prefs} = require("prefs"); |
| 26 | 28 |
| 27 let activeNotification = null; | 29 let activeNotification = null; |
| 28 let activeButtons = null; | 30 let activeButtons = null; |
| 29 let defaultDisplayMethods = ["popup"]; | 31 let defaultDisplayMethods = ["popup"]; |
| 30 let displayMethods = Object.create(null); | 32 let displayMethods = Object.create(null); |
| 31 displayMethods.critical = ["icon", "notification", "popup"]; | 33 displayMethods.critical = ["icon", "notification", "popup"]; |
| 32 displayMethods.question = ["notification"]; | 34 displayMethods.question = ["notification"]; |
| 33 displayMethods.normal = ["notification"]; | 35 displayMethods.normal = ["notification"]; |
| 34 displayMethods.information = ["icon", "popup"]; | 36 displayMethods.information = ["icon", "popup"]; |
| 35 | |
| 36 let platform = require("info").platform; | |
| 37 let canUseChromeNotifications = platform == "chromium" && "notifications" in chr
ome; | |
| 38 | 37 |
| 39 function prepareNotificationIconAndPopup() | 38 function prepareNotificationIconAndPopup() |
| 40 { | 39 { |
| 41 let animateIcon = shouldDisplay("icon", activeNotification.type); | 40 let animateIcon = shouldDisplay("icon", activeNotification.type); |
| 42 activeNotification.onClicked = () => | 41 activeNotification.onClicked = () => |
| 43 { | 42 { |
| 44 if (animateIcon) | 43 if (animateIcon) |
| 45 stopIconAnimation(); | 44 stopIconAnimation(); |
| 46 notificationClosed(); | 45 notificationClosed(); |
| 47 }; | 46 }; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 175 |
| 177 activeNotification = notification; | 176 activeNotification = notification; |
| 178 if (shouldDisplay("notification", activeNotification.type)) | 177 if (shouldDisplay("notification", activeNotification.type)) |
| 179 { | 178 { |
| 180 let texts = NotificationStorage.getLocalizedTexts(notification); | 179 let texts = NotificationStorage.getLocalizedTexts(notification); |
| 181 let title = texts.title || ""; | 180 let title = texts.title || ""; |
| 182 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; | 181 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; |
| 183 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 182 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
| 184 let linkCount = (activeNotification.links || []).length; | 183 let linkCount = (activeNotification.links || []).length; |
| 185 | 184 |
| 186 if (canUseChromeNotifications) | 185 if ("notifications" in chrome) |
| 187 { | 186 { |
| 188 activeButtons = getNotificationButtons(activeNotification.type, texts.mess
age); | 187 activeButtons = getNotificationButtons(activeNotification.type, texts.mess
age); |
| 189 chrome.notifications.create("", { | 188 chrome.notifications.create("", { |
| 190 type: "basic", | 189 type: "basic", |
| 191 title: title, | 190 title: title, |
| 192 iconUrl: iconUrl, | 191 iconUrl: iconUrl, |
| 193 message: message, | 192 message: message, |
| 194 buttons: activeButtons.map(button => ({title: button.title})), | 193 buttons: activeButtons.map(button => ({title: button.title})), |
| 195 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically | 194 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically |
| 196 }); | 195 }); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 227 } | 226 } |
| 228 } | 227 } |
| 229 prepareNotificationIconAndPopup(); | 228 prepareNotificationIconAndPopup(); |
| 230 }; | 229 }; |
| 231 | 230 |
| 232 /** | 231 /** |
| 233 * Initializes the notification system. | 232 * Initializes the notification system. |
| 234 */ | 233 */ |
| 235 exports.initNotifications = () => | 234 exports.initNotifications = () => |
| 236 { | 235 { |
| 237 if (canUseChromeNotifications) | 236 if ("notifications" in chrome) |
| 238 initChromeNotifications(); | 237 initChromeNotifications(); |
| 239 initAntiAdblockNotification(); | 238 initAntiAdblockNotification(); |
| 240 }; | 239 }; |
| 241 | 240 |
| 242 /** | 241 /** |
| 243 * Gets the active notification to be shown if any. | 242 * Gets the active notification to be shown if any. |
| 244 * | 243 * |
| 245 * @return {?object} | 244 * @return {?object} |
| 246 */ | 245 */ |
| 247 exports.getActiveNotification = () => activeNotification; | 246 exports.getActiveNotification = () => activeNotification; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 260 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 259 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
| 261 return methods.indexOf(method) > -1; | 260 return methods.indexOf(method) > -1; |
| 262 }; | 261 }; |
| 263 | 262 |
| 264 ext.pages.onLoading.addListener(page => | 263 ext.pages.onLoading.addListener(page => |
| 265 { | 264 { |
| 266 NotificationStorage.showNext(stringifyURL(page.url)); | 265 NotificationStorage.showNext(stringifyURL(page.url)); |
| 267 }); | 266 }); |
| 268 | 267 |
| 269 NotificationStorage.addShowListener(showNotification); | 268 NotificationStorage.addShowListener(showNotification); |
| LEFT | RIGHT |