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

Delta Between Two Patch Sets: lib/notificationHelper.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Fix indentation Created Oct. 9, 2017, 3:50 p.m.
Right Patch Set: Update adblockplusui dependency Created Oct. 17, 2017, 1:02 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/io.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
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 { 182 {
183 if (activeNotification && activeNotification.id == notification.id) 183 if (activeNotification && activeNotification.id == notification.id)
184 return; 184 return;
185 185
186 activeNotification = notification; 186 activeNotification = notification;
187 if (shouldDisplay("notification", activeNotification.type)) 187 if (shouldDisplay("notification", activeNotification.type))
188 { 188 {
189 let texts = NotificationStorage.getLocalizedTexts(notification); 189 let texts = NotificationStorage.getLocalizedTexts(notification);
190 let title = texts.title || ""; 190 let title = texts.title || "";
191 let message = (texts.message || "").replace(/<\/?(a|strong)>/g, ""); 191 let message = (texts.message || "").replace(/<\/?(a|strong)>/g, "");
192 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); 192 let iconUrl = browser.extension.getURL("icons/detailed/abp-128.png");
193 let linkCount = (activeNotification.links || []).length; 193 let linkCount = (activeNotification.links || []).length;
194 194
195 if ("notifications" in browser) 195 if ("notifications" in browser)
196 { 196 {
197 activeButtons = getNotificationButtons(activeNotification.type, 197 activeButtons = getNotificationButtons(activeNotification.type,
198 texts.message); 198 texts.message);
199 browser.notifications.create("", { 199 browser.notifications.create("", {
200 type: "basic", 200 type: "basic",
201 title, 201 title,
202 iconUrl, 202 iconUrl,
203 message, 203 message,
204 buttons: activeButtons.map(button => ({title: button.title})), 204 buttons: activeButtons.map(button => ({title: button.title})),
205 // We use the highest priority to prevent the notification 205 // We use the highest priority to prevent the notification
206 // from closing automatically. 206 // from closing automatically.
207 priority: 2 207 priority: 2
208 }); 208 });
209 } 209 }
210 else if ("Notification" in window && activeNotification.type != "question") 210 else if ("Notification" in window && activeNotification.type != "question")
211 { 211 {
212 if (linkCount > 0) 212 if (linkCount > 0)
213 { 213 {
214 message += " " + browser.i18n.getMessage( 214 message += " " + browser.i18n.getMessage(
215 "notification_without_buttons"); 215 "notification_without_buttons"
216 );
216 } 217 }
217 218
218 let widget = new Notification( 219 let widget = new Notification(
219 title, 220 title,
220 { 221 {
221 lang: Utils.appLocale, 222 lang: Utils.appLocale,
222 dir: Utils.readingDirection, 223 dir: Utils.readingDirection,
223 body: message, 224 body: message,
224 icon: iconUrl 225 icon: iconUrl
225 } 226 }
226 ); 227 );
227 228
228 widget.addEventListener("click", openNotificationLinks); 229 widget.addEventListener("click", openNotificationLinks);
229 widget.addEventListener("close", notificationClosed); 230 widget.addEventListener("close", notificationClosed);
230 } 231 }
231 else 232 else
232 { 233 {
233 message = title + "\n" + message; 234 message = title + "\n" + message;
234 if (linkCount > 0) 235 if (linkCount > 0)
235 { 236 {
236 message += "\n\n" + browser.i18n.getMessage( 237 message += "\n\n" + browser.i18n.getMessage(
237 "notification_with_buttons"); 238 "notification_with_buttons"
239 );
238 } 240 }
239 241
240 let approved = confirm(message); 242 let approved = confirm(message);
241 if (activeNotification.type == "question") 243 if (activeNotification.type == "question")
242 notificationButtonClick(approved ? 0 : 1); 244 notificationButtonClick(approved ? 0 : 1);
243 else if (approved) 245 else if (approved)
244 openNotificationLinks(); 246 openNotificationLinks();
245 } 247 }
246 } 248 }
247 prepareNotificationIconAndPopup(); 249 prepareNotificationIconAndPopup();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 let methods = displayMethods[notificationType] || defaultDisplayMethods; 283 let methods = displayMethods[notificationType] || defaultDisplayMethods;
282 return methods.includes(method); 284 return methods.includes(method);
283 }; 285 };
284 286
285 ext.pages.onLoading.addListener(page => 287 ext.pages.onLoading.addListener(page =>
286 { 288 {
287 NotificationStorage.showNext(stringifyURL(page.url)); 289 NotificationStorage.showNext(stringifyURL(page.url));
288 }); 290 });
289 291
290 NotificationStorage.addShowListener(showNotification); 292 NotificationStorage.addShowListener(showNotification);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld