| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 activeNotification.onClicked = function() | 53 activeNotification.onClicked = function() |
| 54 { | 54 { |
| 55 if (animateIcon) | 55 if (animateIcon) |
| 56 stopIconAnimation(); | 56 stopIconAnimation(); |
| 57 notificationClosed(); | 57 notificationClosed(); |
| 58 }; | 58 }; |
| 59 if (animateIcon) | 59 if (animateIcon) |
| 60 startIconAnimation(activeNotification.type); | 60 startIconAnimation(activeNotification.type); |
| 61 } | 61 } |
| 62 | 62 |
| 63 function getNotificationButtons(message) | 63 function getNotificationButtons(notificationType, message) |
| 64 { | 64 { |
| 65 activeButtons = []; | 65 let buttons = []; |
| 66 if (activeNotification.type == "question") | 66 if (notificationType == "question") |
| 67 { | 67 { |
| 68 activeButtons.push({ | 68 buttons.push({ |
| 69 type: "question", | 69 type: "question", |
| 70 title: ext.i18n.getMessage("overlay_notification_button_yes") | 70 title: ext.i18n.getMessage("overlay_notification_button_yes") |
| 71 }); | 71 }); |
| 72 activeButtons.push({ | 72 buttons.push({ |
| 73 type: "question", | 73 type: "question", |
| 74 title: ext.i18n.getMessage("overlay_notification_button_no") | 74 title: ext.i18n.getMessage("overlay_notification_button_no") |
| 75 }); | 75 }); |
| 76 } | 76 } |
| 77 else | 77 else |
| 78 { | 78 { |
| 79 let regex = /<a>(.*?)<\/a>/g; | 79 let regex = /<a>(.*?)<\/a>/g; |
| 80 let match; | 80 let match; |
| 81 while (match = regex.exec(message)) | 81 while (match = regex.exec(message)) |
| 82 { | 82 { |
| 83 activeButtons.push({ | 83 buttons.push({ |
| 84 type: "link", | 84 type: "link", |
| 85 title: match[1] | 85 title: match[1] |
| 86 }); | 86 }); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Chrome only allows two notification buttons so we need to fall back | 89 // Chrome only allows two notification buttons so we need to fall back |
| 90 // to a single button to open all links if there are more than two. | 90 // to a single button to open all links if there are more than two. |
| 91 let maxButtons = (activeNotification.type == "critical") ? 2 : 1; | 91 let maxButtons = (notificationType == "critical") ? 2 : 1; |
| 92 if (activeButtons.length > maxButtons) | 92 if (buttons.length > maxButtons) |
| 93 { | 93 { |
| 94 activeButtons = [ | 94 buttons = [ |
| 95 { | 95 { |
| 96 type: "open-all", | 96 type: "open-all", |
| 97 title: ext.i18n.getMessage("notification_open_all") | 97 title: ext.i18n.getMessage("notification_open_all") |
| 98 } | 98 } |
| 99 ]; | 99 ]; |
| 100 } | 100 } |
| 101 if (activeNotification.type != "critical") | 101 if (notificationType != "critical") |
| 102 { | 102 { |
| 103 activeButtons.push({ | 103 buttons.push({ |
| 104 type: "configure", | 104 type: "configure", |
| 105 title: ext.i18n.getMessage("notification_configure") | 105 title: ext.i18n.getMessage("notification_configure") |
| 106 }); | 106 }); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 return activeButtons.map(button => ({title: button.title})); | 110 return buttons; |
| 111 } | 111 } |
| 112 | 112 |
| 113 function openNotificationLinks() | 113 function openNotificationLinks() |
| 114 { | 114 { |
| 115 if (activeNotification.links) | 115 if (activeNotification.links) |
| 116 { | 116 { |
| 117 for (let link of activeNotification.links) | 117 for (let link of activeNotification.links) |
|
Sebastian Noack
2015/09/11 14:51:00
This one is unrelated.
| |
| 118 ext.pages.open(Utils.getDocLink(link)); | 118 ext.pages.open(Utils.getDocLink(link)); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 function notificationButtonClick(buttonIndex) | 122 function notificationButtonClick(buttonIndex) |
| 123 { | 123 { |
| 124 switch (activeButtons[buttonIndex].type) | 124 switch (activeButtons[buttonIndex].type) |
| 125 { | 125 { |
| 126 case "link": | 126 case "link": |
| 127 ext.pages.open(Utils.getDocLink(activeNotification.links[buttonIndex])); | 127 ext.pages.open(Utils.getDocLink(activeNotification.links[buttonIndex])); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 if (shouldDisplay("notification", activeNotification.type)) | 201 if (shouldDisplay("notification", activeNotification.type)) |
| 202 { | 202 { |
| 203 let texts = NotificationStorage.getLocalizedTexts(notification); | 203 let texts = NotificationStorage.getLocalizedTexts(notification); |
| 204 let title = texts.title || ""; | 204 let title = texts.title || ""; |
| 205 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | 205 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
| 206 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 206 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
| 207 let linkCount = (activeNotification.links || []).length; | 207 let linkCount = (activeNotification.links || []).length; |
| 208 | 208 |
| 209 if (canUseChromeNotifications) | 209 if (canUseChromeNotifications) |
| 210 { | 210 { |
| 211 activeButtons = getNotificationButtons(activeNotification.type, texts.mess age); | |
| 211 let opts = { | 212 let opts = { |
| 212 type: "basic", | 213 type: "basic", |
| 213 title: title, | 214 title: title, |
| 214 message: message, | 215 message: message, |
| 215 buttons: getNotificationButtons(texts.message), | 216 buttons: activeButtons.map(button => ({title: button.title})), |
| 216 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 217 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically |
| 217 }; | 218 }; |
| 218 | 219 |
| 219 imgToBase64(iconUrl, function(iconData) | 220 imgToBase64(iconUrl, function(iconData) |
| 220 { | 221 { |
| 221 opts.iconUrl = iconData; | 222 opts.iconUrl = iconData; |
| 222 chrome.notifications.create("", opts, function() {}); | 223 chrome.notifications.create("", opts, function() {}); |
| 223 }); | 224 }); |
| 224 } | 225 } |
| 225 else if ("Notification" in window && activeNotification.type != "question") | 226 else if ("Notification" in window && activeNotification.type != "question") |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 /** | 283 /** |
| 283 * Gets the active notification to be shown if any. | 284 * Gets the active notification to be shown if any. |
| 284 * | 285 * |
| 285 * @return {?object} | 286 * @return {?object} |
| 286 */ | 287 */ |
| 287 exports.getActiveNotification = function() | 288 exports.getActiveNotification = function() |
| 288 { | 289 { |
| 289 return activeNotification; | 290 return activeNotification; |
| 290 }; | 291 }; |
| 291 | 292 |
| 293 let shouldDisplay = | |
|
Sebastian Noack
2015/09/11 14:51:00
This one is unrelated.
| |
| 292 /** | 294 /** |
| 293 * Determines whether a given display method should be used for a | 295 * Determines whether a given display method should be used for a |
| 294 * specified notification type. | 296 * specified notification type. |
| 295 * | 297 * |
| 296 * @param {string} method Display method: icon, notification or popup | 298 * @param {string} method Display method: icon, notification or popup |
| 297 * @param {string} notificationType | 299 * @param {string} notificationType |
| 298 * @return {boolean} | 300 * @return {boolean} |
| 299 */ | 301 */ |
| 300 exports.shouldDisplay = shouldDisplay; | 302 exports.shouldDisplay = function(method, notificationType) |
| 301 function shouldDisplay(method, notificationType) | |
| 302 { | 303 { |
| 303 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 304 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
| 304 return methods.indexOf(method) > -1; | 305 return methods.indexOf(method) > -1; |
| 305 } | 306 } |
| 306 | 307 |
| 307 NotificationStorage.addShowListener(showNotification); | 308 NotificationStorage.addShowListener(showNotification); |
| LEFT | RIGHT |