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 {loadImageAsCanvas, | 20 let {startIconAnimation, stopIconAnimation} = require("icon"); |
21 startIconAnimation, stopIconAnimation} = require("icon"); | |
22 let {Utils} = require("utils"); | 21 let {Utils} = require("utils"); |
23 let {Notification: NotificationStorage} = require("notification"); | 22 let {Notification: NotificationStorage} = require("notification"); |
24 let {stringifyURL} = require("url"); | 23 let {stringifyURL} = require("url"); |
25 let {initAntiAdblockNotification} = require("antiadblockInit"); | 24 let {initAntiAdblockNotification} = require("antiadblockInit"); |
26 | 25 |
27 let activeNotification = null; | 26 let activeNotification = null; |
28 let activeButtons = null; | 27 let activeButtons = null; |
29 let defaultDisplayMethods = ["popup"]; | 28 let defaultDisplayMethods = ["popup"]; |
30 let displayMethods = Object.create(null); | 29 let displayMethods = Object.create(null); |
31 displayMethods.critical = ["icon", "notification", "popup"]; | 30 displayMethods.critical = ["icon", "notification", "popup"]; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 { | 186 { |
188 let texts = NotificationStorage.getLocalizedTexts(notification); | 187 let texts = NotificationStorage.getLocalizedTexts(notification); |
189 let title = texts.title || ""; | 188 let title = texts.title || ""; |
190 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; | 189 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; |
191 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 190 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
192 let linkCount = (activeNotification.links || []).length; | 191 let linkCount = (activeNotification.links || []).length; |
193 | 192 |
194 if (canUseChromeNotifications) | 193 if (canUseChromeNotifications) |
195 { | 194 { |
196 activeButtons = getNotificationButtons(activeNotification.type, texts.mess
age); | 195 activeButtons = getNotificationButtons(activeNotification.type, texts.mess
age); |
197 let opts = { | 196 chrome.notifications.create("", { |
198 type: "basic", | 197 type: "basic", |
199 title: title, | 198 title: title, |
| 199 iconUrl: iconUrl, |
200 message: message, | 200 message: message, |
201 buttons: activeButtons.map(button => ({title: button.title})), | 201 buttons: activeButtons.map(button => ({title: button.title})), |
202 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically | 202 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically |
203 }; | |
204 | |
205 loadImageAsCanvas(iconUrl).then(canvas => | |
206 { | |
207 opts.iconUrl = canvas.toDataURL("image/png"); | |
208 chrome.notifications.create("", opts, function() {}); | |
209 }); | 203 }); |
210 } | 204 } |
211 else if ("Notification" in window && activeNotification.type != "question") | 205 else if ("Notification" in window && activeNotification.type != "question") |
212 { | 206 { |
213 if (linkCount > 0) | 207 if (linkCount > 0) |
214 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 208 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
215 | 209 |
216 loadImageAsCanvas(iconUrl).then(canvas => | 210 let notification = new Notification( |
217 { | 211 title, |
218 let notification = new Notification( | 212 { |
219 title, | 213 lang: Utils.appLocale, |
220 { | 214 dir: ext.i18n.getMessage("@@bidi_dir"), |
221 lang: Utils.appLocale, | 215 body: message, |
222 dir: ext.i18n.getMessage("@@bidi_dir"), | 216 icon: iconUrl |
223 body: message, | 217 } |
224 icon: canvas.toDataURL("image/png") | 218 ); |
225 } | 219 |
226 ); | 220 notification.addEventListener("click", openNotificationLinks); |
227 | 221 notification.addEventListener("close", notificationClosed); |
228 notification.addEventListener("click", openNotificationLinks); | |
229 notification.addEventListener("close", notificationClosed); | |
230 }); | |
231 } | 222 } |
232 else | 223 else |
233 { | 224 { |
234 let message = title + "\n" + message; | 225 let message = title + "\n" + message; |
235 if (linkCount > 0) | 226 if (linkCount > 0) |
236 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | 227 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
237 | 228 |
238 let approved = confirm(message); | 229 let approved = confirm(message); |
239 if (activeNotification.type == "question") | 230 if (activeNotification.type == "question") |
240 notificationButtonClick(approved ? 0 : 1); | 231 notificationButtonClick(approved ? 0 : 1); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 * @param {string} notificationType | 275 * @param {string} notificationType |
285 * @return {boolean} | 276 * @return {boolean} |
286 */ | 277 */ |
287 exports.shouldDisplay = function(method, notificationType) | 278 exports.shouldDisplay = function(method, notificationType) |
288 { | 279 { |
289 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 280 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
290 return methods.indexOf(method) > -1; | 281 return methods.indexOf(method) > -1; |
291 }; | 282 }; |
292 | 283 |
293 NotificationStorage.addShowListener(showNotification); | 284 NotificationStorage.addShowListener(showNotification); |
LEFT | RIGHT |