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

Side by Side Diff: lib/notificationHelper.js

Issue 29371739: Issue 4722 - Remove old check for Chrome notification API (Closed)
Patch Set: Inline chrome.notification check Created Jan. 16, 2017, 2:28 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 | 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 15 matching lines...) Expand all
26 26
27 let activeNotification = null; 27 let activeNotification = null;
28 let activeButtons = null; 28 let activeButtons = null;
29 let defaultDisplayMethods = ["popup"]; 29 let defaultDisplayMethods = ["popup"];
30 let displayMethods = Object.create(null); 30 let displayMethods = Object.create(null);
31 displayMethods.critical = ["icon", "notification", "popup"]; 31 displayMethods.critical = ["icon", "notification", "popup"];
32 displayMethods.question = ["notification"]; 32 displayMethods.question = ["notification"];
33 displayMethods.normal = ["notification"]; 33 displayMethods.normal = ["notification"];
34 displayMethods.information = ["icon", "popup"]; 34 displayMethods.information = ["icon", "popup"];
35 35
36 // Chrome on Linux does not fully support chrome.notifications until version 35
37 // https://code.google.com/p/chromium/issues/detail?id=291485
38 let canUseChromeNotifications = (function()
39 {
40 let info = require("info");
41 if (info.platform == "chromium" && "notifications" in chrome)
42 {
43 if (navigator.platform.indexOf("Linux") == -1)
44 return true;
45 if (Services.vc.compare(info.applicationVersion, "35") >= 0)
46 return true;
47 }
48 return false;
49 })();
50
51 function prepareNotificationIconAndPopup() 36 function prepareNotificationIconAndPopup()
52 { 37 {
53 let animateIcon = shouldDisplay("icon", activeNotification.type); 38 let animateIcon = shouldDisplay("icon", activeNotification.type);
54 activeNotification.onClicked = function() 39 activeNotification.onClicked = function()
55 { 40 {
56 if (animateIcon) 41 if (animateIcon)
57 stopIconAnimation(); 42 stopIconAnimation();
58 notificationClosed(); 43 notificationClosed();
59 }; 44 };
60 if (animateIcon) 45 if (animateIcon)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 173
189 activeNotification = notification; 174 activeNotification = notification;
190 if (shouldDisplay("notification", activeNotification.type)) 175 if (shouldDisplay("notification", activeNotification.type))
191 { 176 {
192 let texts = NotificationStorage.getLocalizedTexts(notification); 177 let texts = NotificationStorage.getLocalizedTexts(notification);
193 let title = texts.title || ""; 178 let title = texts.title || "";
194 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; 179 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
195 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); 180 let iconUrl = ext.getURL("icons/detailed/abp-128.png");
196 let linkCount = (activeNotification.links || []).length; 181 let linkCount = (activeNotification.links || []).length;
197 182
198 if (canUseChromeNotifications) 183 if ("notifications" in chrome)
199 { 184 {
200 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); 185 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age);
201 chrome.notifications.create("", { 186 chrome.notifications.create("", {
202 type: "basic", 187 type: "basic",
203 title: title, 188 title: title,
204 iconUrl: iconUrl, 189 iconUrl: iconUrl,
205 message: message, 190 message: message,
206 buttons: activeButtons.map(button => ({title: button.title})), 191 buttons: activeButtons.map(button => ({title: button.title})),
207 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically 192 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically
208 }); 193 });
(...skipping 30 matching lines...) Expand all
239 } 224 }
240 } 225 }
241 prepareNotificationIconAndPopup(); 226 prepareNotificationIconAndPopup();
242 }; 227 };
243 228
244 /** 229 /**
245 * Initializes the notification system. 230 * Initializes the notification system.
246 */ 231 */
247 exports.initNotifications = function() 232 exports.initNotifications = function()
248 { 233 {
249 if (canUseChromeNotifications) 234 if ("notifications" in chrome)
250 initChromeNotifications(); 235 initChromeNotifications();
251 initAntiAdblockNotification(); 236 initAntiAdblockNotification();
252 }; 237 };
253 238
254 /** 239 /**
255 * Gets the active notification to be shown if any. 240 * Gets the active notification to be shown if any.
256 * 241 *
257 * @return {?object} 242 * @return {?object}
258 */ 243 */
259 exports.getActiveNotification = function() 244 exports.getActiveNotification = function()
(...skipping 15 matching lines...) Expand all
275 let methods = displayMethods[notificationType] || defaultDisplayMethods; 260 let methods = displayMethods[notificationType] || defaultDisplayMethods;
276 return methods.indexOf(method) > -1; 261 return methods.indexOf(method) > -1;
277 }; 262 };
278 263
279 ext.pages.onLoading.addListener(page => 264 ext.pages.onLoading.addListener(page =>
280 { 265 {
281 NotificationStorage.showNext(stringifyURL(page.url)); 266 NotificationStorage.showNext(stringifyURL(page.url));
282 }); 267 });
283 268
284 NotificationStorage.addShowListener(showNotification); 269 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