 Issue 29570614:
  Issue 5028 - Use browser namespace  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockpluschrome/
    
  
    Issue 29570614:
  Issue 5028 - Use browser namespace  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockpluschrome/| Index: lib/notificationHelper.js | 
| =================================================================== | 
| --- a/lib/notificationHelper.js | 
| +++ b/lib/notificationHelper.js | 
| @@ -52,21 +52,21 @@ | 
| function getNotificationButtons(notificationType, message) | 
| { | 
| let buttons = []; | 
| if (notificationType == "question") | 
| { | 
| buttons.push({ | 
| type: "question", | 
| - title: chrome.i18n.getMessage("overlay_notification_button_yes") | 
| + title: browser.i18n.getMessage("overlay_notification_button_yes") | 
| }); | 
| buttons.push({ | 
| type: "question", | 
| - title: chrome.i18n.getMessage("overlay_notification_button_no") | 
| + title: browser.i18n.getMessage("overlay_notification_button_no") | 
| }); | 
| } | 
| else | 
| { | 
| let regex = /<a>(.*?)<\/a>/g; | 
| let match; | 
| while (match = regex.exec(message)) | 
| { | 
| @@ -79,50 +79,50 @@ | 
| // Chrome only allows two notification buttons so we need to fall back | 
| // to a single button to open all links if there are more than two. | 
| let maxButtons = (notificationType == "critical") ? 2 : 1; | 
| if (buttons.length > maxButtons) | 
| { | 
| buttons = [ | 
| { | 
| type: "open-all", | 
| - title: chrome.i18n.getMessage("notification_open_all") | 
| + title: browser.i18n.getMessage("notification_open_all") | 
| } | 
| ]; | 
| } | 
| if (!["critical", "relentless"].includes(notificationType)) | 
| { | 
| buttons.push({ | 
| type: "configure", | 
| - title: chrome.i18n.getMessage("notification_configure") | 
| + title: browser.i18n.getMessage("notification_configure") | 
| }); | 
| } | 
| } | 
| return buttons; | 
| } | 
| function openNotificationLinks() | 
| { | 
| if (activeNotification.links) | 
| { | 
| for (let link of activeNotification.links) | 
| - chrome.tabs.create({url: Utils.getDocLink(link)}); | 
| + browser.tabs.create({url: Utils.getDocLink(link)}); | 
| } | 
| } | 
| function notificationButtonClick(buttonIndex) | 
| { | 
| if (!(activeButtons && buttonIndex in activeButtons)) | 
| return; | 
| switch (activeButtons[buttonIndex].type) | 
| { | 
| case "link": | 
| - chrome.tabs.create({ | 
| + browser.tabs.create({ | 
| url: Utils.getDocLink(activeNotification.links[buttonIndex]) | 
| }); | 
| break; | 
| case "open-all": | 
| openNotificationLinks(); | 
| break; | 
| case "configure": | 
| Prefs.notifications_showui = true; | 
| @@ -155,67 +155,70 @@ | 
| // we need to clear them. | 
| function clearActiveNotification(notificationId) | 
| { | 
| if (activeNotification && | 
| activeNotification.type != "question" && | 
| !("links" in activeNotification)) | 
| return; | 
| - chrome.notifications.clear(notificationId, wasCleared => | 
| + browser.notifications.clear(notificationId, wasCleared => | 
| { | 
| if (wasCleared) | 
| notificationClosed(); | 
| }); | 
| } | 
| - chrome.notifications.onButtonClicked.addListener( | 
| + browser.notifications.onButtonClicked.addListener( | 
| (notificationId, buttonIndex) => | 
| { | 
| notificationButtonClick(buttonIndex); | 
| clearActiveNotification(notificationId); | 
| } | 
| ); | 
| - chrome.notifications.onClicked.addListener(clearActiveNotification); | 
| - chrome.notifications.onClosed.addListener(notificationClosed); | 
| + browser.notifications.onClicked.addListener(clearActiveNotification); | 
| + browser.notifications.onClosed.addListener(notificationClosed); | 
| } | 
| function showNotification(notification) | 
| { | 
| if (activeNotification && activeNotification.id == notification.id) | 
| return; | 
| activeNotification = notification; | 
| if (shouldDisplay("notification", activeNotification.type)) | 
| { | 
| let texts = NotificationStorage.getLocalizedTexts(notification); | 
| let title = texts.title || ""; | 
| let message = (texts.message || "").replace(/<\/?(a|strong)>/g, ""); | 
| - let iconUrl = chrome.extension.getURL("icons/detailed/abp-128.png"); | 
| + let iconUrl = browser.extension.getURL("icons/detailed/abp-128.png"); | 
| let linkCount = (activeNotification.links || []).length; | 
| - if ("notifications" in chrome) | 
| + if ("notifications" in browser) | 
| { | 
| activeButtons = getNotificationButtons(activeNotification.type, | 
| texts.message); | 
| - chrome.notifications.create("", { | 
| + browser.notifications.create("", { | 
| type: "basic", | 
| title, | 
| iconUrl, | 
| message, | 
| buttons: activeButtons.map(button => ({title: button.title})), | 
| // We use the highest priority to prevent the notification | 
| // from closing automatically. | 
| priority: 2 | 
| }); | 
| } | 
| else if ("Notification" in window && activeNotification.type != "question") | 
| { | 
| if (linkCount > 0) | 
| - message += " " + chrome.i18n.getMessage("notification_without_buttons"); | 
| + { | 
| + message += " " + browser.i18n.getMessage( | 
| + "notification_without_buttons"); | 
| 
kzar
2017/10/16 10:35:51
Nit: IMO it looks weird having the indentation lik
 
Manish Jethani
2017/10/16 12:17:35
Done.
 | 
| + } | 
| let widget = new Notification( | 
| title, | 
| { | 
| lang: Utils.appLocale, | 
| dir: Utils.readingDirection, | 
| body: message, | 
| icon: iconUrl | 
| @@ -224,17 +227,20 @@ | 
| widget.addEventListener("click", openNotificationLinks); | 
| widget.addEventListener("close", notificationClosed); | 
| } | 
| else | 
| { | 
| message = title + "\n" + message; | 
| if (linkCount > 0) | 
| - message += "\n\n" + chrome.i18n.getMessage("notification_with_buttons"); | 
| + { | 
| + message += "\n\n" + browser.i18n.getMessage( | 
| + "notification_with_buttons"); | 
| + } | 
| let approved = confirm(message); | 
| if (activeNotification.type == "question") | 
| notificationButtonClick(approved ? 0 : 1); | 
| else if (approved) | 
| openNotificationLinks(); | 
| } | 
| } | 
| @@ -244,17 +250,17 @@ | 
| NotificationStorage.markAsShown(notification.id); | 
| } | 
| /** | 
| * Initializes the notification system. | 
| */ | 
| exports.initNotifications = () => | 
| { | 
| - if ("notifications" in chrome) | 
| + if ("notifications" in browser) | 
| initChromeNotifications(); | 
| initAntiAdblockNotification(); | 
| }; | 
| /** | 
| * Gets the active notification to be shown if any. | 
| * | 
| * @return {?object} |