| 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 canUseChromeNotifications = typeof chrome != "undefined" && "notifications" 
     in chrome; |  | 
| 37 | 35 | 
| 38 function prepareNotificationIconAndPopup() | 36 function prepareNotificationIconAndPopup() | 
| 39 { | 37 { | 
| 40   let animateIcon = shouldDisplay("icon", activeNotification.type); | 38   let animateIcon = shouldDisplay("icon", activeNotification.type); | 
| 41   activeNotification.onClicked = function() | 39   activeNotification.onClicked = function() | 
| 42   { | 40   { | 
| 43     if (animateIcon) | 41     if (animateIcon) | 
| 44       stopIconAnimation(); | 42       stopIconAnimation(); | 
| 45     notificationClosed(); | 43     notificationClosed(); | 
| 46   }; | 44   }; | 
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 175 | 173 | 
| 176   activeNotification = notification; | 174   activeNotification = notification; | 
| 177   if (shouldDisplay("notification", activeNotification.type)) | 175   if (shouldDisplay("notification", activeNotification.type)) | 
| 178   { | 176   { | 
| 179     let texts = NotificationStorage.getLocalizedTexts(notification); | 177     let texts = NotificationStorage.getLocalizedTexts(notification); | 
| 180     let title = texts.title || ""; | 178     let title = texts.title || ""; | 
| 181     let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") 
     : ""; | 179     let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") 
     : ""; | 
| 182     let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 180     let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 
| 183     let linkCount = (activeNotification.links || []).length; | 181     let linkCount = (activeNotification.links || []).length; | 
| 184 | 182 | 
| 185     if (canUseChromeNotifications) | 183     if ("notifications" in chrome) | 
| 186     { | 184     { | 
| 187       activeButtons = getNotificationButtons(activeNotification.type, texts.mess
     age); | 185       activeButtons = getNotificationButtons(activeNotification.type, texts.mess
     age); | 
| 188       chrome.notifications.create("", { | 186       chrome.notifications.create("", { | 
| 189         type: "basic", | 187         type: "basic", | 
| 190         title: title, | 188         title: title, | 
| 191         iconUrl: iconUrl, | 189         iconUrl: iconUrl, | 
| 192         message: message, | 190         message: message, | 
| 193         buttons: activeButtons.map(button => ({title: button.title})), | 191         buttons: activeButtons.map(button => ({title: button.title})), | 
| 194         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 | 
| 195       }); | 193       }); | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 226     } | 224     } | 
| 227   } | 225   } | 
| 228   prepareNotificationIconAndPopup(); | 226   prepareNotificationIconAndPopup(); | 
| 229 }; | 227 }; | 
| 230 | 228 | 
| 231 /** | 229 /** | 
| 232  * Initializes the notification system. | 230  * Initializes the notification system. | 
| 233  */ | 231  */ | 
| 234 exports.initNotifications = function() | 232 exports.initNotifications = function() | 
| 235 { | 233 { | 
| 236   if (canUseChromeNotifications) | 234   if ("notifications" in chrome) | 
| 237     initChromeNotifications(); | 235     initChromeNotifications(); | 
| 238   initAntiAdblockNotification(); | 236   initAntiAdblockNotification(); | 
| 239 }; | 237 }; | 
| 240 | 238 | 
| 241 /** | 239 /** | 
| 242  * Gets the active notification to be shown if any. | 240  * Gets the active notification to be shown if any. | 
| 243  * | 241  * | 
| 244  * @return {?object} | 242  * @return {?object} | 
| 245  */ | 243  */ | 
| 246 exports.getActiveNotification = function() | 244 exports.getActiveNotification = function() | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 262   let methods = displayMethods[notificationType] || defaultDisplayMethods; | 260   let methods = displayMethods[notificationType] || defaultDisplayMethods; | 
| 263   return methods.indexOf(method) > -1; | 261   return methods.indexOf(method) > -1; | 
| 264 }; | 262 }; | 
| 265 | 263 | 
| 266 ext.pages.onLoading.addListener(page => | 264 ext.pages.onLoading.addListener(page => | 
| 267 { | 265 { | 
| 268   NotificationStorage.showNext(stringifyURL(page.url)); | 266   NotificationStorage.showNext(stringifyURL(page.url)); | 
| 269 }); | 267 }); | 
| 270 | 268 | 
| 271 NotificationStorage.addShowListener(showNotification); | 269 NotificationStorage.addShowListener(showNotification); | 
| LEFT | RIGHT | 
|---|