| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) | 155 function imgToBase64(url, callback) |
| 156 { | 156 { |
| 157 let canvas = document.createElement("canvas"), | 157 return Utils.loadImage(url).then(function(image) |
| 158 ctx = canvas.getContext("2d"), | |
| 159 img = new Image; | |
| 160 img.src = url; | |
| 161 img.onload = function() | |
| 162 { | 158 { |
| 163 canvas.height = img.height; | 159 let canvas = document.createElement("canvas"); |
| 164 canvas.width = img.width; | 160 let ctx = canvas.getContext("2d"); |
| 165 ctx.drawImage(img, 0, 0); | 161 canvas.height = image.height; |
| 166 callback(canvas.toDataURL("image/png")); | 162 canvas.width = image.width; |
| 167 canvas = null; | 163 ctx.drawImage(image, 0, 0); |
| 168 }; | 164 return canvas.toDataURL("image/png"); |
| 165 }); |
| 169 } | 166 } |
| 170 | 167 |
| 171 function initChromeNotifications() | 168 function initChromeNotifications() |
| 172 { | 169 { |
| 173 // Chrome hides notifications in notification center when clicked so we need t
o clear them | 170 // Chrome hides notifications in notification center when clicked so we need t
o clear them |
| 174 function clearActiveNotification(notificationId) | 171 function clearActiveNotification(notificationId) |
| 175 { | 172 { |
| 176 if (activeNotification && activeNotification.type != "question" && !("links"
in activeNotification)) | 173 if (activeNotification && activeNotification.type != "question" && !("links"
in activeNotification)) |
| 177 return; | 174 return; |
| 178 | 175 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 { | 207 { |
| 211 activeButtons = getNotificationButtons(activeNotification.type, texts.mess
age); | 208 activeButtons = getNotificationButtons(activeNotification.type, texts.mess
age); |
| 212 let opts = { | 209 let opts = { |
| 213 type: "basic", | 210 type: "basic", |
| 214 title: title, | 211 title: title, |
| 215 message: message, | 212 message: message, |
| 216 buttons: activeButtons.map(button => ({title: button.title})), | 213 buttons: activeButtons.map(button => ({title: button.title})), |
| 217 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically | 214 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically |
| 218 }; | 215 }; |
| 219 | 216 |
| 220 imgToBase64(iconUrl, function(iconData) | 217 imgToBase64(iconUrl).then(function(iconData) |
| 221 { | 218 { |
| 222 opts.iconUrl = iconData; | 219 opts.iconUrl = iconData; |
| 223 chrome.notifications.create("", opts, function() {}); | 220 chrome.notifications.create("", opts, function() {}); |
| 224 }); | 221 }); |
| 225 } | 222 } |
| 226 else if ("Notification" in window && activeNotification.type != "question") | 223 else if ("Notification" in window && activeNotification.type != "question") |
| 227 { | 224 { |
| 228 if (linkCount > 0) | 225 if (linkCount > 0) |
| 229 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 226 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
| 230 | 227 |
| 231 imgToBase64(iconUrl, function(iconData) | 228 imgToBase64(iconUrl).then(function(iconData) |
| 232 { | 229 { |
| 233 let notification = new Notification( | 230 let notification = new Notification( |
| 234 title, | 231 title, |
| 235 { | 232 { |
| 236 lang: Utils.appLocale, | 233 lang: Utils.appLocale, |
| 237 dir: ext.i18n.getMessage("@@bidi_dir"), | 234 dir: ext.i18n.getMessage("@@bidi_dir"), |
| 238 body: message, | 235 body: message, |
| 239 icon: iconData | 236 icon: iconData |
| 240 } | 237 } |
| 241 ); | 238 ); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 * @param {string} notificationType | 296 * @param {string} notificationType |
| 300 * @return {boolean} | 297 * @return {boolean} |
| 301 */ | 298 */ |
| 302 exports.shouldDisplay = function(method, notificationType) | 299 exports.shouldDisplay = function(method, notificationType) |
| 303 { | 300 { |
| 304 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 301 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
| 305 return methods.indexOf(method) > -1; | 302 return methods.indexOf(method) > -1; |
| 306 } | 303 } |
| 307 | 304 |
| 308 NotificationStorage.addShowListener(showNotification); | 305 NotificationStorage.addShowListener(showNotification); |
| OLD | NEW |