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

Side by Side Diff: lib/notificationHelper.js

Issue 29326181: Issue 3022 - Implemented new notification type for normal messages (Closed)
Patch Set: Created Sept. 10, 2015, 1:37 p.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 | notification.js » ('j') | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 let {startIconAnimation, stopIconAnimation} = require("icon"); 20 let {startIconAnimation, stopIconAnimation} = require("icon");
21 let {Utils} = require("utils"); 21 let {Utils} = require("utils");
22 let {Notification: NotificationStorage} = require("notification"); 22 let {Notification: NotificationStorage} = require("notification");
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 defaultDisplayMethods = ["popup"];
28 let displayMethods = Object.create(null);
29 displayMethods.critical = ["icon", "notification", "popup"];
30 displayMethods.question = ["notification"];
31 displayMethods.normal = ["notification"];
32 displayMethods.information = ["icon", "popup"];
27 33
28 // Chrome on Linux does not fully support chrome.notifications until version 35 34 // Chrome on Linux does not fully support chrome.notifications until version 35
29 // https://code.google.com/p/chromium/issues/detail?id=291485 35 // https://code.google.com/p/chromium/issues/detail?id=291485
30 let canUseChromeNotifications = (function() 36 let canUseChromeNotifications = (function()
31 { 37 {
32 let info = require("info"); 38 let info = require("info");
33 if (info.platform == "chromium" && "notifications" in chrome) 39 if (info.platform == "chromium" && "notifications" in chrome)
34 { 40 {
35 if (navigator.platform.indexOf("Linux") == -1) 41 if (navigator.platform.indexOf("Linux") == -1)
36 return true; 42 return true;
37 if (Services.vc.compare(info.applicationVersion, "35") >= 0) 43 if (Services.vc.compare(info.applicationVersion, "35") >= 0)
38 return true; 44 return true;
39 } 45 }
40 return false; 46 return false;
41 })(); 47 })();
42 48
43 function prepareNotificationIconAndPopup() 49 function prepareNotificationIconAndPopup()
44 { 50 {
45 let animateIcon = (activeNotification.type != "question"); 51 let animateIcon = shouldDisplay("icon", activeNotification.type);
46 activeNotification.onClicked = function() 52 activeNotification.onClicked = function()
47 { 53 {
48 if (animateIcon) 54 if (animateIcon)
49 stopIconAnimation(); 55 stopIconAnimation();
50 notificationClosed(); 56 notificationClosed();
51 }; 57 };
52 if (animateIcon) 58 if (animateIcon)
53 startIconAnimation(activeNotification.type); 59 startIconAnimation(activeNotification.type);
54 } 60 }
55 61
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 chrome.notifications.onClicked.addListener(clearActiveNotification); 134 chrome.notifications.onClicked.addListener(clearActiveNotification);
129 chrome.notifications.onClosed.addListener(notificationClosed); 135 chrome.notifications.onClosed.addListener(notificationClosed);
130 } 136 }
131 137
132 function showNotification(notification) 138 function showNotification(notification)
133 { 139 {
134 if (activeNotification && activeNotification.id == notification.id) 140 if (activeNotification && activeNotification.id == notification.id)
135 return; 141 return;
136 142
137 activeNotification = notification; 143 activeNotification = notification;
138 if (activeNotification.type == "critical" || activeNotification.type == "quest ion") 144 if (shouldDisplay("notification", activeNotification.type))
139 { 145 {
140 let texts = NotificationStorage.getLocalizedTexts(notification); 146 let texts = NotificationStorage.getLocalizedTexts(notification);
141 let title = texts.title || ""; 147 let title = texts.title || "";
142 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; 148 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
143 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); 149 let iconUrl = ext.getURL("icons/detailed/abp-128.png");
144 let hasLinks = activeNotification.links && activeNotification.links.length > 0; 150 let hasLinks = activeNotification.links && activeNotification.links.length > 0;
145 151
146 if (canUseChromeNotifications) 152 if (canUseChromeNotifications)
147 { 153 {
148 let opts = { 154 let opts = {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 /** 238 /**
233 * Gets the active notification to be shown if any. 239 * Gets the active notification to be shown if any.
234 * 240 *
235 * @return {?object} 241 * @return {?object}
236 */ 242 */
237 exports.getActiveNotification = function() 243 exports.getActiveNotification = function()
238 { 244 {
239 return activeNotification; 245 return activeNotification;
240 }; 246 };
241 247
248 /**
249 * Determines whether a given display method should be used for a
250 * specified notification type.
251 *
252 * @param {string} method Display method: icon, notification or popup
253 * @param {string} notificationType
254 * @return {boolean}
255 */
256 exports.shouldDisplay = shouldDisplay;
Sebastian Noack 2015/09/11 13:15:46 I just realized that this way shouldDisplay is doc
257 function shouldDisplay(method, notificationType)
258 {
259 let methods = displayMethods[notificationType] || defaultDisplayMethods;
260 return methods.indexOf(method) > -1;
261 }
262
242 NotificationStorage.addShowListener(showNotification); 263 NotificationStorage.addShowListener(showNotification);
OLDNEW
« no previous file with comments | « no previous file | notification.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld