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

Powered by Google App Engine
This is Rietveld