Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/notificationHelper.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Left Patch Set: Workaround limiation with iterating element collections in older versions of Chrome Created Jan. 16, 2017, 8:46 a.m.
Right Patch Set: Addressed some more feedback Created Jan. 18, 2017, 11:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/messaging.js ('k') | lib/popupBlocker.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 "use strict"; 20 "use strict";
21 21
22 let {startIconAnimation, stopIconAnimation} = require("icon"); 22 const {startIconAnimation, stopIconAnimation} = require("icon");
23 let {Utils} = require("utils"); 23 const {Utils} = require("utils");
24 let {Notification: NotificationStorage} = require("notification"); 24 const {Notification: NotificationStorage} = require("notification");
25 let {stringifyURL} = require("url"); 25 const {stringifyURL} = require("url");
26 let {initAntiAdblockNotification} = require("antiadblockInit"); 26 const {initAntiAdblockNotification} = require("antiadblockInit");
27 let {Prefs} = require("prefs"); 27 const {Prefs} = require("prefs");
28 28
29 let activeNotification = null; 29 let activeNotification = null;
30 let activeButtons = null; 30 let activeButtons = null;
31 let defaultDisplayMethods = ["popup"]; 31 let defaultDisplayMethods = ["popup"];
32 let displayMethods = Object.create(null); 32 let displayMethods = Object.create(null);
33 displayMethods.critical = ["icon", "notification", "popup"]; 33 displayMethods.critical = ["icon", "notification", "popup"];
34 displayMethods.question = ["notification"]; 34 displayMethods.question = ["notification"];
35 displayMethods.normal = ["notification"]; 35 displayMethods.normal = ["notification"];
36 displayMethods.information = ["icon", "popup"]; 36 displayMethods.information = ["icon", "popup"];
37
38 let canUseChromeNotifications = typeof chrome != "undefined" && "notifications" in chrome;
kzar 2017/01/16 08:48:09 (Due to rebase.)
39 37
40 function prepareNotificationIconAndPopup() 38 function prepareNotificationIconAndPopup()
41 { 39 {
42 let animateIcon = shouldDisplay("icon", activeNotification.type); 40 let animateIcon = shouldDisplay("icon", activeNotification.type);
43 activeNotification.onClicked = () => 41 activeNotification.onClicked = () =>
44 { 42 {
45 if (animateIcon) 43 if (animateIcon)
46 stopIconAnimation(); 44 stopIconAnimation();
47 notificationClosed(); 45 notificationClosed();
48 }; 46 };
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 175
178 activeNotification = notification; 176 activeNotification = notification;
179 if (shouldDisplay("notification", activeNotification.type)) 177 if (shouldDisplay("notification", activeNotification.type))
180 { 178 {
181 let texts = NotificationStorage.getLocalizedTexts(notification); 179 let texts = NotificationStorage.getLocalizedTexts(notification);
182 let title = texts.title || ""; 180 let title = texts.title || "";
183 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; 181 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
184 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); 182 let iconUrl = ext.getURL("icons/detailed/abp-128.png");
185 let linkCount = (activeNotification.links || []).length; 183 let linkCount = (activeNotification.links || []).length;
186 184
187 if (canUseChromeNotifications) 185 if ("notifications" in chrome)
188 { 186 {
189 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); 187 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age);
190 chrome.notifications.create("", { 188 chrome.notifications.create("", {
191 type: "basic", 189 type: "basic",
192 title: title, 190 title: title,
193 iconUrl: iconUrl, 191 iconUrl: iconUrl,
194 message: message, 192 message: message,
195 buttons: activeButtons.map(button => ({title: button.title})), 193 buttons: activeButtons.map(button => ({title: button.title})),
196 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
197 }); 195 });
(...skipping 30 matching lines...) Expand all
228 } 226 }
229 } 227 }
230 prepareNotificationIconAndPopup(); 228 prepareNotificationIconAndPopup();
231 }; 229 };
232 230
233 /** 231 /**
234 * Initializes the notification system. 232 * Initializes the notification system.
235 */ 233 */
236 exports.initNotifications = () => 234 exports.initNotifications = () =>
237 { 235 {
238 if (canUseChromeNotifications) 236 if ("notifications" in chrome)
239 initChromeNotifications(); 237 initChromeNotifications();
240 initAntiAdblockNotification(); 238 initAntiAdblockNotification();
241 }; 239 };
242 240
243 /** 241 /**
244 * Gets the active notification to be shown if any. 242 * Gets the active notification to be shown if any.
245 * 243 *
246 * @return {?object} 244 * @return {?object}
247 */ 245 */
248 exports.getActiveNotification = () => activeNotification; 246 exports.getActiveNotification = () => activeNotification;
(...skipping 12 matching lines...) Expand all
261 let methods = displayMethods[notificationType] || defaultDisplayMethods; 259 let methods = displayMethods[notificationType] || defaultDisplayMethods;
262 return methods.indexOf(method) > -1; 260 return methods.indexOf(method) > -1;
263 }; 261 };
264 262
265 ext.pages.onLoading.addListener(page => 263 ext.pages.onLoading.addListener(page =>
266 { 264 {
267 NotificationStorage.showNext(stringifyURL(page.url)); 265 NotificationStorage.showNext(stringifyURL(page.url));
268 }); 266 });
269 267
270 NotificationStorage.addShowListener(showNotification); 268 NotificationStorage.addShowListener(showNotification);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld