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

Delta Between Two Patch Sets: lib/notificationHelper.js

Issue 29713631: Issue 5760 - Use relative require paths (Closed)
Left Patch Set: Created March 3, 2018, 4:09 a.m.
Right Patch Set: Address PS4 comments, rebase Created April 5, 2018, 11:09 p.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/options.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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 const {startIconAnimation, stopIconAnimation} = require("./icon"); 22 const {startIconAnimation, stopIconAnimation} = require("./icon");
23 const {Utils} = require("./utils"); 23 const {Utils} = require("./utils");
24 const {Notification: NotificationStorage} = require( 24 const {Notification: NotificationStorage} =
25 "../adblockpluscore/lib/notification"); 25 require("../adblockpluscore/lib/notification");
26 const {stringifyURL} = require("./url"); 26 const {stringifyURL} = require("./url");
27 const {initAntiAdblockNotification} = require( 27 const {initAntiAdblockNotification} =
28 "../adblockplusui/lib/antiadblockInit"); 28 require("../adblockplusui/lib/antiadblockInit");
29 const {Prefs} = require("./prefs"); 29 const {Prefs} = require("./prefs");
30 const {showOptions} = require("./options"); 30 const {showOptions} = require("./options");
31 31
32 let activeNotification = null; 32 let activeNotification = null;
33 let activeButtons = null; 33 let activeButtons = null;
34 let defaultDisplayMethods = ["popup"]; 34 let defaultDisplayMethods = ["popup"];
35 let displayMethods = Object.create(null); 35 let displayMethods = Object.create(null);
36 displayMethods.critical = ["icon", "notification", "popup"]; 36 displayMethods.critical = ["icon", "notification", "popup"];
37 displayMethods.question = ["notification"]; 37 displayMethods.question = ["notification"];
38 displayMethods.normal = ["notification"]; 38 displayMethods.normal = ["notification"];
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 case "link": 121 case "link":
122 browser.tabs.create({ 122 browser.tabs.create({
123 url: Utils.getDocLink(activeNotification.links[buttonIndex]) 123 url: Utils.getDocLink(activeNotification.links[buttonIndex])
124 }); 124 });
125 break; 125 break;
126 case "open-all": 126 case "open-all":
127 openNotificationLinks(); 127 openNotificationLinks();
128 break; 128 break;
129 case "configure": 129 case "configure":
130 Prefs.notifications_showui = true; 130 Prefs.notifications_showui = true;
131 showOptions(page => 131 showOptions((page, port) =>
132 { 132 {
133 page.sendMessage({ 133 port.postMessage({
134 type: "app.respond", 134 type: "app.respond",
135 action: "focusSection", 135 action: "focusSection",
136 args: ["notifications"] 136 args: ["notifications"]
137 }); 137 });
138 }); 138 });
139 break; 139 break;
140 case "question": 140 case "question":
141 NotificationStorage.triggerQuestionListeners(activeNotification.id, 141 NotificationStorage.triggerQuestionListeners(activeNotification.id,
142 buttonIndex == 0); 142 buttonIndex == 0);
143 NotificationStorage.markAsShown(activeNotification.id); 143 NotificationStorage.markAsShown(activeNotification.id);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 let notificationOptions = { 201 let notificationOptions = {
202 type: "basic", 202 type: "basic",
203 title, 203 title,
204 iconUrl, 204 iconUrl,
205 message, 205 message,
206 buttons: activeButtons.map(button => ({title: button.title})), 206 buttons: activeButtons.map(button => ({title: button.title})),
207 // We use the highest priority to prevent the notification 207 // We use the highest priority to prevent the notification
208 // from closing automatically. 208 // from closing automatically.
209 priority: 2 209 priority: 2
210 }; 210 };
211 browser.notifications.create("", notificationOptions, () => 211
212 { 212 // Firefox and Opera don't support buttons. Firefox throws synchronously,
213 // Opera does not support the addition of buttons to notifications. 213 // while Opera gives an asynchronous error. Wrapping the promise like
214 // Question type notfications always include buttons. 214 // this, turns the synchronous error on Firefox into a promise rejection.
215 if (browser.runtime.lastError && activeNotification.type != "question") 215 new Promise(resolve =>
216 {
217 resolve(browser.notifications.create(notificationOptions));
218 }).catch(() =>
219 {
220 // Without buttons, showing notifications of the type "question" is
221 // pointless. For other notifications, retry with the buttons removed.
222 if (activeNotification.type != "question")
216 { 223 {
217 delete notificationOptions.buttons; 224 delete notificationOptions.buttons;
218 browser.notifications.create("", notificationOptions); 225 browser.notifications.create(notificationOptions);
219 } 226 }
220 }); 227 });
221 } 228 }
222 else if ("Notification" in window && activeNotification.type != "question") 229 else if ("Notification" in window && activeNotification.type != "question")
223 { 230 {
224 if (linkCount > 0) 231 if (linkCount > 0)
225 { 232 {
226 message += " " + browser.i18n.getMessage( 233 message += " " + browser.i18n.getMessage(
227 "notification_without_buttons" 234 "notification_without_buttons"
228 ); 235 );
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 * @param {string} method Display method: icon, notification or popup 296 * @param {string} method Display method: icon, notification or popup
290 * @param {string} notificationType 297 * @param {string} notificationType
291 * @return {boolean} 298 * @return {boolean}
292 */ 299 */
293 exports.shouldDisplay = (method, notificationType) => 300 exports.shouldDisplay = (method, notificationType) =>
294 { 301 {
295 let methods = displayMethods[notificationType] || defaultDisplayMethods; 302 let methods = displayMethods[notificationType] || defaultDisplayMethods;
296 return methods.includes(method); 303 return methods.includes(method);
297 }; 304 };
298 305
306 /**
307 * Tidies up after a notification was clicked.
308 */
309 exports.notificationClicked = () =>
310 {
311 if (activeNotification)
312 activeNotification.onClicked();
313 };
314
299 ext.pages.onLoading.addListener(page => 315 ext.pages.onLoading.addListener(page =>
300 { 316 {
301 NotificationStorage.showNext(stringifyURL(page.url)); 317 NotificationStorage.showNext(stringifyURL(page.url));
302 }); 318 });
303 319
304 NotificationStorage.addShowListener(showNotification); 320 NotificationStorage.addShowListener(showNotification);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld