| 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-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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 let {Prefs} = require("prefs"); | 25 let {Prefs} = require("prefs"); |
| 26 | 26 |
| 27 let activeNotification = null; | 27 let activeNotification = null; |
| 28 let activeButtons = null; | 28 let activeButtons = null; |
| 29 let defaultDisplayMethods = ["popup"]; | 29 let defaultDisplayMethods = ["popup"]; |
| 30 let displayMethods = Object.create(null); | 30 let displayMethods = Object.create(null); |
| 31 displayMethods.critical = ["icon", "notification", "popup"]; | 31 displayMethods.critical = ["icon", "notification", "popup"]; |
| 32 displayMethods.question = ["notification"]; | 32 displayMethods.question = ["notification"]; |
| 33 displayMethods.normal = ["notification"]; | 33 displayMethods.normal = ["notification"]; |
| 34 displayMethods.information = ["icon", "popup"]; | 34 displayMethods.information = ["icon", "popup"]; |
| 35 | |
| 36 let platform = require("info").platform; | |
| 37 let canUseChromeNotifications = platform == "chromium" && "notifications" in chr ome; | |
|
Sebastian Noack
2017/01/13 11:43:23
Any reason to still check for the platform? This w
kzar
2017/01/16 04:15:37
Not really but IMO that change is for when we swit
Sebastian Noack
2017/01/16 13:39:59
Well, when we switch to the browser.* API we would
kzar
2017/01/16 13:50:22
I guess not, Done.
| |
| 38 | 35 |
| 39 function prepareNotificationIconAndPopup() | 36 function prepareNotificationIconAndPopup() |
| 40 { | 37 { |
| 41 let animateIcon = shouldDisplay("icon", activeNotification.type); | 38 let animateIcon = shouldDisplay("icon", activeNotification.type); |
| 42 activeNotification.onClicked = function() | 39 activeNotification.onClicked = function() |
| 43 { | 40 { |
| 44 if (animateIcon) | 41 if (animateIcon) |
| 45 stopIconAnimation(); | 42 stopIconAnimation(); |
| 46 notificationClosed(); | 43 notificationClosed(); |
| 47 }; | 44 }; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 | 173 |
| 177 activeNotification = notification; | 174 activeNotification = notification; |
| 178 if (shouldDisplay("notification", activeNotification.type)) | 175 if (shouldDisplay("notification", activeNotification.type)) |
| 179 { | 176 { |
| 180 let texts = NotificationStorage.getLocalizedTexts(notification); | 177 let texts = NotificationStorage.getLocalizedTexts(notification); |
| 181 let title = texts.title || ""; | 178 let title = texts.title || ""; |
| 182 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | 179 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
| 183 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 180 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
| 184 let linkCount = (activeNotification.links || []).length; | 181 let linkCount = (activeNotification.links || []).length; |
| 185 | 182 |
| 186 if (canUseChromeNotifications) | 183 if ("notifications" in chrome) |
| 187 { | 184 { |
| 188 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); | 185 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); |
| 189 chrome.notifications.create("", { | 186 chrome.notifications.create("", { |
| 190 type: "basic", | 187 type: "basic", |
| 191 title: title, | 188 title: title, |
| 192 iconUrl: iconUrl, | 189 iconUrl: iconUrl, |
| 193 message: message, | 190 message: message, |
| 194 buttons: activeButtons.map(button => ({title: button.title})), | 191 buttons: activeButtons.map(button => ({title: button.title})), |
| 195 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 192 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically |
| 196 }); | 193 }); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 227 } | 224 } |
| 228 } | 225 } |
| 229 prepareNotificationIconAndPopup(); | 226 prepareNotificationIconAndPopup(); |
| 230 }; | 227 }; |
| 231 | 228 |
| 232 /** | 229 /** |
| 233 * Initializes the notification system. | 230 * Initializes the notification system. |
| 234 */ | 231 */ |
| 235 exports.initNotifications = function() | 232 exports.initNotifications = function() |
| 236 { | 233 { |
| 237 if (canUseChromeNotifications) | 234 if ("notifications" in chrome) |
| 238 initChromeNotifications(); | 235 initChromeNotifications(); |
| 239 initAntiAdblockNotification(); | 236 initAntiAdblockNotification(); |
| 240 }; | 237 }; |
| 241 | 238 |
| 242 /** | 239 /** |
| 243 * Gets the active notification to be shown if any. | 240 * Gets the active notification to be shown if any. |
| 244 * | 241 * |
| 245 * @return {?object} | 242 * @return {?object} |
| 246 */ | 243 */ |
| 247 exports.getActiveNotification = function() | 244 exports.getActiveNotification = function() |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 263 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 260 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
| 264 return methods.indexOf(method) > -1; | 261 return methods.indexOf(method) > -1; |
| 265 }; | 262 }; |
| 266 | 263 |
| 267 ext.pages.onLoading.addListener(page => | 264 ext.pages.onLoading.addListener(page => |
| 268 { | 265 { |
| 269 NotificationStorage.showNext(stringifyURL(page.url)); | 266 NotificationStorage.showNext(stringifyURL(page.url)); |
| 270 }); | 267 }); |
| 271 | 268 |
| 272 NotificationStorage.addShowListener(showNotification); | 269 NotificationStorage.addShowListener(showNotification); |
| LEFT | RIGHT |