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

Side by Side Diff: lib/notificationHelper.js

Issue 29569649: Issue 4580 - Replace ext.i18n with i18n (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update adblockplusui dependency again Created Oct. 10, 2017, 4:31 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 | « lib/filterValidation.js ('k') | lib/utils.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-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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 startIconAnimation(activeNotification.type); 50 startIconAnimation(activeNotification.type);
51 } 51 }
52 52
53 function getNotificationButtons(notificationType, message) 53 function getNotificationButtons(notificationType, message)
54 { 54 {
55 let buttons = []; 55 let buttons = [];
56 if (notificationType == "question") 56 if (notificationType == "question")
57 { 57 {
58 buttons.push({ 58 buttons.push({
59 type: "question", 59 type: "question",
60 title: ext.i18n.getMessage("overlay_notification_button_yes") 60 title: chrome.i18n.getMessage("overlay_notification_button_yes")
61 }); 61 });
62 buttons.push({ 62 buttons.push({
63 type: "question", 63 type: "question",
64 title: ext.i18n.getMessage("overlay_notification_button_no") 64 title: chrome.i18n.getMessage("overlay_notification_button_no")
65 }); 65 });
66 } 66 }
67 else 67 else
68 { 68 {
69 let regex = /<a>(.*?)<\/a>/g; 69 let regex = /<a>(.*?)<\/a>/g;
70 let match; 70 let match;
71 while (match = regex.exec(message)) 71 while (match = regex.exec(message))
72 { 72 {
73 buttons.push({ 73 buttons.push({
74 type: "link", 74 type: "link",
75 title: match[1] 75 title: match[1]
76 }); 76 });
77 } 77 }
78 78
79 // Chrome only allows two notification buttons so we need to fall back 79 // Chrome only allows two notification buttons so we need to fall back
80 // to a single button to open all links if there are more than two. 80 // to a single button to open all links if there are more than two.
81 let maxButtons = (notificationType == "critical") ? 2 : 1; 81 let maxButtons = (notificationType == "critical") ? 2 : 1;
82 if (buttons.length > maxButtons) 82 if (buttons.length > maxButtons)
83 { 83 {
84 buttons = [ 84 buttons = [
85 { 85 {
86 type: "open-all", 86 type: "open-all",
87 title: ext.i18n.getMessage("notification_open_all") 87 title: chrome.i18n.getMessage("notification_open_all")
88 } 88 }
89 ]; 89 ];
90 } 90 }
91 if (!["critical", "relentless"].includes(notificationType)) 91 if (!["critical", "relentless"].includes(notificationType))
92 { 92 {
93 buttons.push({ 93 buttons.push({
94 type: "configure", 94 type: "configure",
95 title: ext.i18n.getMessage("notification_configure") 95 title: chrome.i18n.getMessage("notification_configure")
96 }); 96 });
97 } 97 }
98 } 98 }
99 99
100 return buttons; 100 return buttons;
101 } 101 }
102 102
103 function openNotificationLinks() 103 function openNotificationLinks()
104 { 104 {
105 if (activeNotification.links) 105 if (activeNotification.links)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 message += " " + ext.i18n.getMessage("notification_without_buttons"); 213 message += " " + chrome.i18n.getMessage("notification_without_buttons");
214 214
215 let widget = new Notification( 215 let widget = new Notification(
216 title, 216 title,
217 { 217 {
218 lang: Utils.appLocale, 218 lang: Utils.appLocale,
219 dir: Utils.readingDirection, 219 dir: Utils.readingDirection,
220 body: message, 220 body: message,
221 icon: iconUrl 221 icon: iconUrl
222 } 222 }
223 ); 223 );
224 224
225 widget.addEventListener("click", openNotificationLinks); 225 widget.addEventListener("click", openNotificationLinks);
226 widget.addEventListener("close", notificationClosed); 226 widget.addEventListener("close", notificationClosed);
227 } 227 }
228 else 228 else
229 { 229 {
230 message = title + "\n" + message; 230 message = title + "\n" + message;
231 if (linkCount > 0) 231 if (linkCount > 0)
232 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); 232 message += "\n\n" + chrome.i18n.getMessage("notification_with_buttons");
233 233
234 let approved = confirm(message); 234 let approved = confirm(message);
235 if (activeNotification.type == "question") 235 if (activeNotification.type == "question")
236 notificationButtonClick(approved ? 0 : 1); 236 notificationButtonClick(approved ? 0 : 1);
237 else if (approved) 237 else if (approved)
238 openNotificationLinks(); 238 openNotificationLinks();
239 } 239 }
240 } 240 }
241 prepareNotificationIconAndPopup(); 241 prepareNotificationIconAndPopup();
242 242
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 let methods = displayMethods[notificationType] || defaultDisplayMethods; 275 let methods = displayMethods[notificationType] || defaultDisplayMethods;
276 return methods.includes(method); 276 return methods.includes(method);
277 }; 277 };
278 278
279 ext.pages.onLoading.addListener(page => 279 ext.pages.onLoading.addListener(page =>
280 { 280 {
281 NotificationStorage.showNext(stringifyURL(page.url)); 281 NotificationStorage.showNext(stringifyURL(page.url));
282 }); 282 });
283 283
284 NotificationStorage.addShowListener(showNotification); 284 NotificationStorage.addShowListener(showNotification);
OLDNEW
« no previous file with comments | « lib/filterValidation.js ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld