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

Side by Side Diff: lib/notificationHelper.js

Issue 29370565: [adblockpluschrome] Issue 4764 - Added "relentless" notification that shows up in intervals (Closed)
Patch Set: Created Dec. 30, 2016, 9:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 let {stringifyURL} = require("url"); 23 let {stringifyURL} = require("url");
24 let {initAntiAdblockNotification} = require("antiadblockInit"); 24 let {initAntiAdblockNotification} = require("antiadblockInit");
25 25
26 let activeNotification = null; 26 let activeNotification = null;
27 let activeButtons = null; 27 let activeButtons = null;
28 let defaultDisplayMethods = ["popup"]; 28 let defaultDisplayMethods = ["popup"];
29 let displayMethods = Object.create(null); 29 let displayMethods = Object.create(null);
30 displayMethods.critical = ["icon", "notification", "popup"]; 30 displayMethods.critical = ["icon", "notification", "popup"];
31 displayMethods.question = ["notification"]; 31 displayMethods.question = ["notification"];
32 displayMethods.normal = ["notification"]; 32 displayMethods.normal = ["notification"];
33 displayMethods.relentless = ["notification"];
33 displayMethods.information = ["icon", "popup"]; 34 displayMethods.information = ["icon", "popup"];
34 35
35 // Chrome on Linux does not fully support chrome.notifications until version 35 36 // Chrome on Linux does not fully support chrome.notifications until version 35
36 // https://code.google.com/p/chromium/issues/detail?id=291485 37 // https://code.google.com/p/chromium/issues/detail?id=291485
37 let canUseChromeNotifications = (function() 38 let canUseChromeNotifications = (function()
38 { 39 {
39 let info = require("info"); 40 let info = require("info");
40 if (info.platform == "chromium" && "notifications" in chrome) 41 if (info.platform == "chromium" && "notifications" in chrome)
41 { 42 {
42 if (navigator.platform.indexOf("Linux") == -1) 43 if (navigator.platform.indexOf("Linux") == -1)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 let maxButtons = (notificationType == "critical") ? 2 : 1; 92 let maxButtons = (notificationType == "critical") ? 2 : 1;
92 if (buttons.length > maxButtons) 93 if (buttons.length > maxButtons)
93 { 94 {
94 buttons = [ 95 buttons = [
95 { 96 {
96 type: "open-all", 97 type: "open-all",
97 title: ext.i18n.getMessage("notification_open_all") 98 title: ext.i18n.getMessage("notification_open_all")
98 } 99 }
99 ]; 100 ];
100 } 101 }
101 if (notificationType != "critical") 102 if (["critical", "relentless"].indexOf(notificationType) == -1)
Sebastian Noack 2017/01/05 12:46:11 Using indexOf() for membership checks seems unnece
wspee 2017/01/05 15:19:27 Done.
102 { 103 {
103 buttons.push({ 104 buttons.push({
104 type: "configure", 105 type: "configure",
105 title: ext.i18n.getMessage("notification_configure") 106 title: ext.i18n.getMessage("notification_configure")
106 }); 107 });
107 } 108 }
108 } 109 }
109 110
110 return buttons; 111 return buttons;
111 } 112 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); 232 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons");
232 233
233 let approved = confirm(message); 234 let approved = confirm(message);
234 if (activeNotification.type == "question") 235 if (activeNotification.type == "question")
235 notificationButtonClick(approved ? 0 : 1); 236 notificationButtonClick(approved ? 0 : 1);
236 else if (approved) 237 else if (approved)
237 openNotificationLinks(); 238 openNotificationLinks();
238 } 239 }
239 } 240 }
240 prepareNotificationIconAndPopup(); 241 prepareNotificationIconAndPopup();
242
243 if (notification.type !== "question")
Sebastian Noack 2017/01/05 12:46:11 As per the Mozilla coding style guide (https://dev
wspee 2017/01/05 15:19:27 Done.
244 NotificationStorage.markAsShown(notification.id);
241 }; 245 };
242 246
243 /** 247 /**
244 * Initializes the notification system. 248 * Initializes the notification system.
245 */ 249 */
246 exports.initNotifications = function() 250 exports.initNotifications = function()
247 { 251 {
248 if (canUseChromeNotifications) 252 if (canUseChromeNotifications)
249 initChromeNotifications(); 253 initChromeNotifications();
250 initAntiAdblockNotification(); 254 initAntiAdblockNotification();
(...skipping 23 matching lines...) Expand all
274 let methods = displayMethods[notificationType] || defaultDisplayMethods; 278 let methods = displayMethods[notificationType] || defaultDisplayMethods;
275 return methods.indexOf(method) > -1; 279 return methods.indexOf(method) > -1;
276 }; 280 };
277 281
278 ext.pages.onLoading.addListener(page => 282 ext.pages.onLoading.addListener(page =>
279 { 283 {
280 NotificationStorage.showNext(stringifyURL(page.url)); 284 NotificationStorage.showNext(stringifyURL(page.url));
281 }); 285 });
282 286
283 NotificationStorage.addShowListener(showNotification); 287 NotificationStorage.addShowListener(showNotification);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld