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

Delta Between Two Patch Sets: lib/notificationHelper.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Left Patch Set: Use var for ext declarations again Created Feb. 8, 2017, 9:02 a.m.
Right Patch Set: Use .includes again Created March 31, 2017, 8:37 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-2017 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 *
(...skipping 12 matching lines...) Expand all
26 const {initAntiAdblockNotification} = require("antiadblockInit"); 26 const {initAntiAdblockNotification} = require("antiadblockInit");
27 const {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.relentless = ["notification"];
36 displayMethods.information = ["icon", "popup"]; 37 displayMethods.information = ["icon", "popup"];
37 38
38 function prepareNotificationIconAndPopup() 39 function prepareNotificationIconAndPopup()
39 { 40 {
40 let animateIcon = shouldDisplay("icon", activeNotification.type); 41 let animateIcon = shouldDisplay("icon", activeNotification.type);
41 activeNotification.onClicked = () => 42 activeNotification.onClicked = () =>
42 { 43 {
43 if (animateIcon) 44 if (animateIcon)
44 stopIconAnimation(); 45 stopIconAnimation();
45 notificationClosed(); 46 notificationClosed();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 let maxButtons = (notificationType == "critical") ? 2 : 1; 80 let maxButtons = (notificationType == "critical") ? 2 : 1;
80 if (buttons.length > maxButtons) 81 if (buttons.length > maxButtons)
81 { 82 {
82 buttons = [ 83 buttons = [
83 { 84 {
84 type: "open-all", 85 type: "open-all",
85 title: ext.i18n.getMessage("notification_open_all") 86 title: ext.i18n.getMessage("notification_open_all")
86 } 87 }
87 ]; 88 ];
88 } 89 }
89 if (notificationType != "critical") 90 if (["critical", "relentless"].indexOf(notificationType) == -1)
90 { 91 {
91 buttons.push({ 92 buttons.push({
92 type: "configure", 93 type: "configure",
93 title: ext.i18n.getMessage("notification_configure") 94 title: ext.i18n.getMessage("notification_configure")
94 }); 95 });
95 } 96 }
96 } 97 }
97 98
98 return buttons; 99 return buttons;
99 } 100 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // We use the highest priority to prevent the notification 202 // We use the highest priority to prevent the notification
202 // from closing automatically. 203 // from closing automatically.
203 priority: 2 204 priority: 2
204 }); 205 });
205 } 206 }
206 else if ("Notification" in window && activeNotification.type != "question") 207 else if ("Notification" in window && activeNotification.type != "question")
207 { 208 {
208 if (linkCount > 0) 209 if (linkCount > 0)
209 message += " " + ext.i18n.getMessage("notification_without_buttons"); 210 message += " " + ext.i18n.getMessage("notification_without_buttons");
210 211
211 let notif = new Notification( 212 let widget = new Notification(
212 title, 213 title,
213 { 214 {
214 lang: Utils.appLocale, 215 lang: Utils.appLocale,
215 dir: ext.i18n.getMessage("@@bidi_dir"), 216 dir: ext.i18n.getMessage("@@bidi_dir"),
216 body: message, 217 body: message,
217 icon: iconUrl 218 icon: iconUrl
218 } 219 }
219 ); 220 );
220 221
221 notif.addEventListener("click", openNotificationLinks); 222 widget.addEventListener("click", openNotificationLinks);
222 notif.addEventListener("close", notificationClosed); 223 widget.addEventListener("close", notificationClosed);
223 } 224 }
224 else 225 else
225 { 226 {
226 message = title + "\n" + message; 227 message = title + "\n" + message;
227 if (linkCount > 0) 228 if (linkCount > 0)
228 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); 229 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons");
229 230
230 let approved = confirm(message); 231 let approved = confirm(message);
231 if (activeNotification.type == "question") 232 if (activeNotification.type == "question")
232 notificationButtonClick(approved ? 0 : 1); 233 notificationButtonClick(approved ? 0 : 1);
233 else if (approved) 234 else if (approved)
234 openNotificationLinks(); 235 openNotificationLinks();
235 } 236 }
236 } 237 }
237 prepareNotificationIconAndPopup(); 238 prepareNotificationIconAndPopup();
239
240 if (notification.type !== "question")
241 NotificationStorage.markAsShown(notification.id);
238 } 242 }
239 243
240 /** 244 /**
241 * Initializes the notification system. 245 * Initializes the notification system.
242 */ 246 */
243 exports.initNotifications = () => 247 exports.initNotifications = () =>
244 { 248 {
245 if ("notifications" in chrome) 249 if ("notifications" in chrome)
246 initChromeNotifications(); 250 initChromeNotifications();
247 initAntiAdblockNotification(); 251 initAntiAdblockNotification();
(...skipping 20 matching lines...) Expand all
268 let methods = displayMethods[notificationType] || defaultDisplayMethods; 272 let methods = displayMethods[notificationType] || defaultDisplayMethods;
269 return methods.indexOf(method) > -1; 273 return methods.indexOf(method) > -1;
270 }; 274 };
271 275
272 ext.pages.onLoading.addListener(page => 276 ext.pages.onLoading.addListener(page =>
273 { 277 {
274 NotificationStorage.showNext(stringifyURL(page.url)); 278 NotificationStorage.showNext(stringifyURL(page.url));
275 }); 279 });
276 280
277 NotificationStorage.addShowListener(showNotification); 281 NotificationStorage.addShowListener(showNotification);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld