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

Unified Diff: background.js

Issue 6098518317989888: Fix: Notification popup is broken (Closed)
Patch Set: moved code from /extcommon to ext/background Created Feb. 19, 2014, 1:09 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/ext/background.js » ('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
@@ -292,16 +292,83 @@
iconAnimation.update(activeNotification.severity);
}
+function openNotificationLinks()
+{
+ if (activeNotification.links)
+ {
+ activeNotification.links.forEach(function(link)
+ {
+ ext.windows.getLastFocused(function(win)
+ {
+ win.openTab(Utils.getDocLink(link));
+ });
+ });
+ }
+ prepareNotificationIconAndPopup();
+}
+
+function notificationButtonClick(id, index)
+{
+ if (activeNotification.links && activeNotification.links[index])
+ {
+ ext.windows.getLastFocused(function(win)
+ {
+ win.openTab(Utils.getDocLink(activeNotification.links[index]));
+ });
+ }
+ prepareNotificationIconAndPopup();
+}
+
function showNotification(notification)
{
activeNotification = notification;
-
- if (activeNotification.severity === "critical"
- && typeof webkitNotifications !== "undefined")
+ if (activeNotification.severity === "critical")
{
- var notification = webkitNotifications.createHTMLNotification("notification.html");
- notification.show();
- notification.addEventListener("close", prepareNotificationIconAndPopup);
+ var hasWebkitNotifications = typeof webkitNotifications !== "undefined";
+ if (hasWebkitNotifications && "createHTMLNotification" in webkitNotifications)
+ {
+ var notification = webkitNotifications.createHTMLNotification("notification.html");
+ notification.show();
+ notification.addEventListener("close", prepareNotificationIconAndPopup, false);
+ return;
+ }
+
+ var texts = Notification.getLocalizedTexts(notification);
+ var title = texts.title ? texts.title : "";
Felix Dahlke 2014/02/21 09:48:49 How about: var title = texts.title || "";
saroyanm 2014/02/21 13:39:22 Looks cool :)
+ var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
+ var iconUrl = ext.getURL("icons/abp-128.png");
+ if ("notifications" in ext)
Felix Dahlke 2014/02/21 09:48:49 I personally find it a bit confusing to have ext.n
Thomas Greiner 2014/02/21 09:53:43 Since we want to look into a Safari specific imple
Felix Dahlke 2014/02/21 09:56:22 My point is basically that, in the current stage,
Felix Dahlke 2014/02/21 10:04:01 Well, I don't have that strong feelings about this
saroyanm 2014/02/21 13:39:22 This looks a bit tricky, Anyway if we could move a
Thomas Greiner 2014/02/21 13:59:55 Large parts of the notifications code is also shar
saroyanm 2014/02/21 15:11:52 Thanks for pointing this, maybe I'll have some que
+ {
+ var opt = {
Felix Dahlke 2014/02/21 09:48:49 Shouldn't it be plural "opts"?
saroyanm 2014/02/21 13:39:22 Done.
+ type: "basic",
+ title: title,
+ message: message,
+ iconUrl: iconUrl,
+ buttons: []
+ };
+ var regex = /<a>(.*?)<\/a>/g;
+ var plainMessage = texts.message ? texts.message : "";
+ while (regex.test(plainMessage))
+ opt.buttons.push({title: RegExp.$1});
Felix Dahlke 2014/02/21 09:48:49 RegExp.$n is deprecated (https://developer.mozilla
saroyanm 2014/02/21 13:39:22 Good point. I've made performance test between th
Felix Dahlke 2014/02/21 13:48:20 A single match call would suffice in the first exa
+
+ var notification = ext.notifications;
+ notification.create("", opt, function() {});
+ notification.onClosed.addListener(prepareNotificationIconAndPopup);
+ notification.onButtonClicked.addListener(notificationButtonClick);
+ }
+ else if (hasWebkitNotifications && "createNotification" in webkitNotifications)
+ {
+ var notification = webkitNotifications.createNotification(iconUrl, title, message);
+ notification.show();
+ notification.addEventListener("close", prepareNotificationIconAndPopup, false);
+ notification.addEventListener("click", openNotificationLinks, false);
+ }
+ else
+ {
+ var notification = confirm(title + "\n" + message);
Felix Dahlke 2014/02/21 09:48:49 I think we should add some explanatory text here f
saroyanm 2014/02/21 13:39:22 Good point.
+ if (notification == true)
+ openNotificationLinks();
+ }
}
else
prepareNotificationIconAndPopup();
« no previous file with comments | « no previous file | chrome/ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld