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