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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 activeNotification.onClicked(); | 145 activeNotification.onClicked(); |
146 break; | 146 break; |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 function notificationClosed() | 150 function notificationClosed() |
151 { | 151 { |
152 activeNotification = null; | 152 activeNotification = null; |
153 } | 153 } |
154 | 154 |
155 function imgToBase64(url, callback) | |
156 { | |
157 let canvas = document.createElement("canvas"), | |
158 ctx = canvas.getContext("2d"), | |
159 img = new Image; | |
160 img.src = url; | |
161 img.onload = function() | |
162 { | |
163 canvas.height = img.height; | |
164 canvas.width = img.width; | |
165 ctx.drawImage(img, 0, 0); | |
166 callback(canvas.toDataURL("image/png")); | |
167 canvas = null; | |
168 }; | |
169 } | |
170 | |
171 function initChromeNotifications() | 155 function initChromeNotifications() |
172 { | 156 { |
173 // Chrome hides notifications in notification center when clicked so we need t o clear them | 157 // Chrome hides notifications in notification center when clicked so we need t o clear them |
174 function clearActiveNotification(notificationId) | 158 function clearActiveNotification(notificationId) |
175 { | 159 { |
176 if (activeNotification && activeNotification.type != "question" && !("links" in activeNotification)) | 160 if (activeNotification && activeNotification.type != "question" && !("links" in activeNotification)) |
177 return; | 161 return; |
178 | 162 |
179 chrome.notifications.clear(notificationId, function(wasCleared) | 163 chrome.notifications.clear(notificationId, function(wasCleared) |
180 { | 164 { |
(...skipping 21 matching lines...) Expand all Loading... | |
202 { | 186 { |
203 let texts = NotificationStorage.getLocalizedTexts(notification); | 187 let texts = NotificationStorage.getLocalizedTexts(notification); |
204 let title = texts.title || ""; | 188 let title = texts.title || ""; |
205 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | 189 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
206 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 190 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
207 let linkCount = (activeNotification.links || []).length; | 191 let linkCount = (activeNotification.links || []).length; |
208 | 192 |
209 if (canUseChromeNotifications) | 193 if (canUseChromeNotifications) |
210 { | 194 { |
211 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); | 195 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); |
212 let opts = { | 196 chrome.notifications.create("", { |
213 type: "basic", | 197 type: "basic", |
214 title: title, | 198 title: title, |
199 iconUrl: iconUrl, | |
215 message: message, | 200 message: message, |
216 buttons: activeButtons.map(button => ({title: button.title})), | 201 buttons: activeButtons.map(button => ({title: button.title})), |
217 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 202 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically |
218 }; | 203 }, function() {}); |
Sebastian Noack
2016/01/26 17:23:14
While changing this code, note that the callback i
kzar
2016/01/26 17:35:10
Done.
| |
219 | |
220 imgToBase64(iconUrl, function(iconData) | |
221 { | |
222 opts.iconUrl = iconData; | |
223 chrome.notifications.create("", opts, function() {}); | |
224 }); | |
225 } | 204 } |
226 else if ("Notification" in window && activeNotification.type != "question") | 205 else if ("Notification" in window && activeNotification.type != "question") |
227 { | 206 { |
228 if (linkCount > 0) | 207 if (linkCount > 0) |
229 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 208 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
230 | 209 |
231 imgToBase64(iconUrl, function(iconData) | 210 let notification = new Notification( |
232 { | 211 title, |
233 let notification = new Notification( | 212 { |
234 title, | 213 lang: Utils.appLocale, |
235 { | 214 dir: ext.i18n.getMessage("@@bidi_dir"), |
236 lang: Utils.appLocale, | 215 body: message, |
237 dir: ext.i18n.getMessage("@@bidi_dir"), | 216 icon: iconUrl |
238 body: message, | 217 } |
239 icon: iconData | 218 ); |
240 } | |
241 ); | |
242 | 219 |
243 notification.addEventListener("click", openNotificationLinks); | 220 notification.addEventListener("click", openNotificationLinks); |
244 notification.addEventListener("close", notificationClosed); | 221 notification.addEventListener("close", notificationClosed); |
245 }); | |
246 } | 222 } |
247 else | 223 else |
248 { | 224 { |
249 let message = title + "\n" + message; | 225 let message = title + "\n" + message; |
250 if (linkCount > 0) | 226 if (linkCount > 0) |
251 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | 227 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
252 | 228 |
253 let approved = confirm(message); | 229 let approved = confirm(message); |
254 if (activeNotification.type == "question") | 230 if (activeNotification.type == "question") |
255 notificationButtonClick(approved ? 0 : 1); | 231 notificationButtonClick(approved ? 0 : 1); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 * @param {string} notificationType | 275 * @param {string} notificationType |
300 * @return {boolean} | 276 * @return {boolean} |
301 */ | 277 */ |
302 exports.shouldDisplay = function(method, notificationType) | 278 exports.shouldDisplay = function(method, notificationType) |
303 { | 279 { |
304 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 280 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
305 return methods.indexOf(method) > -1; | 281 return methods.indexOf(method) > -1; |
306 }; | 282 }; |
307 | 283 |
308 NotificationStorage.addShowListener(showNotification); | 284 NotificationStorage.addShowListener(showNotification); |
OLD | NEW |