Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: background.js

Issue 6182748523855872: Issue 1518 - Got rid of deprecated code using webkitNotifications (Closed)
Patch Set: Use addEventListener() Created Jan. 13, 2015, 12:29 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/notification.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -41,7 +41,7 @@
var Prefs = require("prefs").Prefs;
var Synchronizer = require("synchronizer").Synchronizer;
var Utils = require("utils").Utils;
-var Notification = require("notification").Notification;
+var NotificationStorage = require("notification").Notification;
var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNotification;
var parseFilters = require("filterValidation").parseFilters;
@@ -299,8 +299,8 @@
{
if (activeNotification.type === "question")
{
- Notification.triggerQuestionListeners(activeNotification.id, buttonIndex === 0);
- Notification.markAsShown(activeNotification.id);
+ NotificationStorage.triggerQuestionListeners(activeNotification.id, buttonIndex === 0);
+ NotificationStorage.markAsShown(activeNotification.id);
activeNotification.onClicked();
}
else if (activeNotification.links && activeNotification.links[buttonIndex])
@@ -365,16 +365,7 @@
activeNotification = notification;
if (activeNotification.type === "critical" || activeNotification.type === "question")
{
- var hasWebkitNotifications = typeof webkitNotifications !== "undefined";
- if (hasWebkitNotifications && "createHTMLNotification" in webkitNotifications)
- {
- var notification = webkitNotifications.createHTMLNotification("notification.html");
- notification.show();
- prepareNotificationIconAndPopup();
- return;
- }
-
- var texts = Notification.getLocalizedTexts(notification);
+ var texts = NotificationStorage.getLocalizedTexts(notification);
var title = texts.title || "";
var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
var iconUrl = ext.getURL("icons/abp-128.png");
@@ -409,17 +400,25 @@
chrome.notifications.create("", opts, function() {});
});
}
- else if (hasWebkitNotifications && "createNotification" in webkitNotifications && activeNotification.type !== "question")
+ else if ("Notification" in window && activeNotification.type !== "question")
{
if (hasLinks)
message += " " + ext.i18n.getMessage("notification_without_buttons");
imgToBase64(iconUrl, function(iconData)
{
- var notification = webkitNotifications.createNotification(iconData, title, message);
- notification.show();
- notification.addEventListener("click", openNotificationLinks, false);
- notification.addEventListener("close", notificationClosed, false);
+ var notification = new Notification(
+ title,
+ {
+ lang: Utils.appLocale,
+ dir: ext.i18n.getMessage("@@bidi_dir"),
+ body: message,
+ icon: iconData
+ }
+ );
+
+ notification.addEventListener("click", openNotificationLinks);
+ notification.addEventListener("close", notificationClosed);
});
}
else
@@ -582,7 +581,7 @@
setTimeout(function()
{
- var notificationToShow = Notification.getNextToShow();
+ var notificationToShow = NotificationStorage.getNextToShow();
if (notificationToShow)
showNotification(notificationToShow);
}, 3 * 60 * 1000);
« no previous file with comments | « no previous file | chrome/notification.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld