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

Delta Between Two Patch Sets: lib/notificationHelper.js

Issue 6063199216467968: Issue 2642 - Moved notifications code to separate module (Closed)
Left Patch Set: Cleanup comparisons for consistency Created June 4, 2015, 9:34 p.m.
Right Patch Set: Fixed typo in comment Created June 5, 2015, 2:06 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 | « background.js ('k') | metadata.common » ('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-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 */
19
18 let {startIconAnimation, stopIconAnimation} = require("icon"); 20 let {startIconAnimation, stopIconAnimation} = require("icon");
19 let {Utils} = require("utils"); 21 let {Utils} = require("utils");
20 let {Notification: NotificationStorage} = require("notification"); 22 let {Notification: NotificationStorage} = require("notification");
23 let {stringifyURL} = require("url");
24 let {initAntiAdblockNotification} = require("antiadblockInit");
21 25
22 let activeNotification = null; 26 let activeNotification = null;
23 27
24 // Chrome on Linux does not fully support chrome.notifications until version 35 28 // Chrome on Linux does not fully support chrome.notifications until version 35
25 // https://code.google.com/p/chromium/issues/detail?id=291485 29 // https://code.google.com/p/chromium/issues/detail?id=291485
26 let canUseChromeNotifications = (function() 30 let canUseChromeNotifications = (function()
27 { 31 {
28 let info = require("info"); 32 let info = require("info");
29 if (info.platform == "chromium" && "notifications" in chrome) 33 if (info.platform == "chromium" && "notifications" in chrome)
30 { 34 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 122
119 chrome.notifications.onButtonClicked.addListener(function(notificationId, butt onIndex) 123 chrome.notifications.onButtonClicked.addListener(function(notificationId, butt onIndex)
120 { 124 {
121 notificationButtonClick(buttonIndex); 125 notificationButtonClick(buttonIndex);
122 clearActiveNotification(notificationId); 126 clearActiveNotification(notificationId);
123 }); 127 });
124 chrome.notifications.onClicked.addListener(clearActiveNotification); 128 chrome.notifications.onClicked.addListener(clearActiveNotification);
125 chrome.notifications.onClosed.addListener(notificationClosed); 129 chrome.notifications.onClosed.addListener(notificationClosed);
126 } 130 }
127 131
128 function showNotification(notification) 132 /**
129 { 133 * Initializes the notification system.
130 if (activeNotification && activeNotification.id == notification.id) 134 */
135 exports.initNotifications = function()
136 {
137 if (canUseChromeNotifications)
138 initChromeNotifications();
139 initAntiAdblockNotification();
140 };
141
142 let showNextNotification =
143 /**
144 * Shows the next notification from the queue if any.
145 *
146 * @param {URL} [url] URL to match notifications to
147 */
148 exports.showNextNotification = function(url)
149 {
150 let notification = NotificationStorage.getNextToShow(url && stringifyURL(url)) ;
151 if (!notification || activeNotification && activeNotification.id == notificati on.id)
131 return; 152 return;
132 153
133 activeNotification = notification; 154 activeNotification = notification;
134 if (activeNotification.type == "critical" || activeNotification.type == "quest ion") 155 if (activeNotification.type == "critical" || activeNotification.type == "quest ion")
135 { 156 {
136 let texts = NotificationStorage.getLocalizedTexts(notification); 157 let texts = NotificationStorage.getLocalizedTexts(notification);
137 let title = texts.title || ""; 158 let title = texts.title || "";
138 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; 159 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
139 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); 160 let iconUrl = ext.getURL("icons/detailed/abp-128.png");
140 let hasLinks = activeNotification.links && activeNotification.links.length > 0; 161 let hasLinks = activeNotification.links && activeNotification.links.length > 0;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); 217 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons");
197 218
198 let approved = confirm(message); 219 let approved = confirm(message);
199 if (activeNotification.type == "question") 220 if (activeNotification.type == "question")
200 notificationButtonClick(approved ? 0 : 1); 221 notificationButtonClick(approved ? 0 : 1);
201 else if (approved) 222 else if (approved)
202 openNotificationLinks(); 223 openNotificationLinks();
203 } 224 }
204 } 225 }
205 prepareNotificationIconAndPopup(); 226 prepareNotificationIconAndPopup();
206 } 227 };
207 228
208 setTimeout(function() 229 setTimeout(showNextNotification, 3 * 60 * 1000);
209 {
210 let notificationToShow = NotificationStorage.getNextToShow();
211 if (notificationToShow)
212 showNotification(notificationToShow);
213 }, 3 * 60 * 1000);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld