Left: | ||
Right: |
OLD | NEW |
---|---|
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 ext.showOptions(page => | 126 ext.showOptions(page => |
127 { | 127 { |
128 page.sendMessage({ | 128 page.sendMessage({ |
129 type: "app.respond", | 129 type: "app.respond", |
130 action: "focusSection", | 130 action: "focusSection", |
131 args: ["notifications"] | 131 args: ["notifications"] |
132 }); | 132 }); |
133 }); | 133 }); |
134 break; | 134 break; |
135 case "question": | 135 case "question": |
136 NotificationStorage.triggerQuestionListeners(activeNotification.id, button Index == 0); | 136 NotificationStorage.triggerQuestionListeners(activeNotification.id, |
137 buttonIndex == 0); | |
137 NotificationStorage.markAsShown(activeNotification.id); | 138 NotificationStorage.markAsShown(activeNotification.id); |
138 activeNotification.onClicked(); | 139 activeNotification.onClicked(); |
139 break; | 140 break; |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 function notificationClosed() | 144 function notificationClosed() |
144 { | 145 { |
145 activeNotification = null; | 146 activeNotification = null; |
146 } | 147 } |
147 | 148 |
148 function initChromeNotifications() | 149 function initChromeNotifications() |
149 { | 150 { |
150 // Chrome hides notifications in notification center when clicked so we need t o clear them | 151 // Chrome hides notifications in notification center when clicked so |
152 // we need to clear them. | |
151 function clearActiveNotification(notificationId) | 153 function clearActiveNotification(notificationId) |
152 { | 154 { |
153 if (activeNotification && activeNotification.type != "question" && !("links" in activeNotification)) | 155 if (activeNotification && |
156 activeNotification.type != "question" && | |
157 !("links" in activeNotification)) | |
154 return; | 158 return; |
155 | 159 |
156 chrome.notifications.clear(notificationId, wasCleared => | 160 chrome.notifications.clear(notificationId, wasCleared => |
157 { | 161 { |
158 if (wasCleared) | 162 if (wasCleared) |
159 notificationClosed(); | 163 notificationClosed(); |
160 }); | 164 }); |
161 } | 165 } |
162 | 166 |
163 chrome.notifications.onButtonClicked.addListener((notificationId, buttonIndex) => | 167 chrome.notifications.onButtonClicked.addListener( |
164 { | 168 (notificationId, buttonIndex) => |
165 notificationButtonClick(buttonIndex); | 169 { |
166 clearActiveNotification(notificationId); | 170 notificationButtonClick(buttonIndex); |
167 }); | 171 clearActiveNotification(notificationId); |
172 } | |
173 ); | |
168 chrome.notifications.onClicked.addListener(clearActiveNotification); | 174 chrome.notifications.onClicked.addListener(clearActiveNotification); |
169 chrome.notifications.onClosed.addListener(notificationClosed); | 175 chrome.notifications.onClosed.addListener(notificationClosed); |
170 } | 176 } |
171 | 177 |
172 function showNotification(notification) | 178 function showNotification(notification) |
173 { | 179 { |
174 if (activeNotification && activeNotification.id == notification.id) | 180 if (activeNotification && activeNotification.id == notification.id) |
175 return; | 181 return; |
176 | 182 |
177 activeNotification = notification; | 183 activeNotification = notification; |
178 if (shouldDisplay("notification", activeNotification.type)) | 184 if (shouldDisplay("notification", activeNotification.type)) |
179 { | 185 { |
180 let texts = NotificationStorage.getLocalizedTexts(notification); | 186 let texts = NotificationStorage.getLocalizedTexts(notification); |
181 let title = texts.title || ""; | 187 let title = texts.title || ""; |
182 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | 188 let message = (texts.message || "").replace(/<\/?(a|strong)>/g, ""); |
183 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 189 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
184 let linkCount = (activeNotification.links || []).length; | 190 let linkCount = (activeNotification.links || []).length; |
185 | 191 |
186 if ("notifications" in chrome) | 192 if ("notifications" in chrome) |
187 { | 193 { |
188 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); | 194 activeButtons = getNotificationButtons(activeNotification.type, |
195 texts.message); | |
189 chrome.notifications.create("", { | 196 chrome.notifications.create("", { |
190 type: "basic", | 197 type: "basic", |
191 title: title, | 198 title, |
192 iconUrl: iconUrl, | 199 iconUrl, |
193 message: message, | 200 message, |
194 buttons: activeButtons.map(button => ({title: button.title})), | 201 buttons: activeButtons.map(button => ({title: button.title})), |
195 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 202 // We use the highest priority to prevent the notification |
203 // from closing automatically. | |
204 priority: 2 | |
196 }); | 205 }); |
197 } | 206 } |
198 else if ("Notification" in window && activeNotification.type != "question") | 207 else if ("Notification" in window && activeNotification.type != "question") |
199 { | 208 { |
200 if (linkCount > 0) | 209 if (linkCount > 0) |
201 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 210 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
202 | 211 |
203 let notification = new Notification( | 212 let notif = new Notification( |
Wladimir Palant
2017/03/14 13:03:28
I understand that the point here is to avoid maski
kzar
2017/03/15 04:57:51
Done.
| |
204 title, | 213 title, |
205 { | 214 { |
206 lang: Utils.appLocale, | 215 lang: Utils.appLocale, |
207 dir: ext.i18n.getMessage("@@bidi_dir"), | 216 dir: ext.i18n.getMessage("@@bidi_dir"), |
208 body: message, | 217 body: message, |
209 icon: iconUrl | 218 icon: iconUrl |
210 } | 219 } |
211 ); | 220 ); |
212 | 221 |
213 notification.addEventListener("click", openNotificationLinks); | 222 notif.addEventListener("click", openNotificationLinks); |
214 notification.addEventListener("close", notificationClosed); | 223 notif.addEventListener("close", notificationClosed); |
215 } | 224 } |
216 else | 225 else |
217 { | 226 { |
218 let message = title + "\n" + message; | 227 message = title + "\n" + message; |
219 if (linkCount > 0) | 228 if (linkCount > 0) |
220 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | 229 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
221 | 230 |
222 let approved = confirm(message); | 231 let approved = confirm(message); |
223 if (activeNotification.type == "question") | 232 if (activeNotification.type == "question") |
224 notificationButtonClick(approved ? 0 : 1); | 233 notificationButtonClick(approved ? 0 : 1); |
225 else if (approved) | 234 else if (approved) |
226 openNotificationLinks(); | 235 openNotificationLinks(); |
227 } | 236 } |
228 } | 237 } |
229 prepareNotificationIconAndPopup(); | 238 prepareNotificationIconAndPopup(); |
230 | 239 |
231 if (notification.type !== "question") | 240 if (notification.type !== "question") |
232 NotificationStorage.markAsShown(notification.id); | 241 NotificationStorage.markAsShown(notification.id); |
233 }; | 242 } |
234 | 243 |
235 /** | 244 /** |
236 * Initializes the notification system. | 245 * Initializes the notification system. |
237 */ | 246 */ |
238 exports.initNotifications = () => | 247 exports.initNotifications = () => |
239 { | 248 { |
240 if ("notifications" in chrome) | 249 if ("notifications" in chrome) |
241 initChromeNotifications(); | 250 initChromeNotifications(); |
242 initAntiAdblockNotification(); | 251 initAntiAdblockNotification(); |
243 }; | 252 }; |
(...skipping 19 matching lines...) Expand all Loading... | |
263 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 272 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
264 return methods.indexOf(method) > -1; | 273 return methods.indexOf(method) > -1; |
265 }; | 274 }; |
266 | 275 |
267 ext.pages.onLoading.addListener(page => | 276 ext.pages.onLoading.addListener(page => |
268 { | 277 { |
269 NotificationStorage.showNext(stringifyURL(page.url)); | 278 NotificationStorage.showNext(stringifyURL(page.url)); |
270 }); | 279 }); |
271 | 280 |
272 NotificationStorage.addShowListener(showNotification); | 281 NotificationStorage.addShowListener(showNotification); |
OLD | NEW |