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

Unified Diff: background.js

Issue 5630329503088640: Fixed miscellaneous issues with anti-adblock notification port (Closed)
Patch Set: Created March 26, 2014, 10:30 a.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 | webrequest.js » ('j') | webrequest.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -18,7 +18,6 @@
with(require("filterClasses"))
{
this.Filter = Filter;
- this.ActiveFilter = ActiveFilter;
this.RegExpFilter = RegExpFilter;
this.BlockingFilter = BlockingFilter;
this.WhitelistFilter = WhitelistFilter;
@@ -351,6 +350,29 @@
}
}
+function notificationClosed()
+{
+ activeNotification = null;
+}
+
+// Chrome on Linux does not fully support chrome.notifications until version 35
Felix Dahlke 2014/03/28 13:10:41 Since this is executed immediately, I would have e
Thomas Greiner 2014/03/28 15:57:08 Done.
+// https://code.google.com/p/chromium/issues/detail?id=291485
+var canUseChromeNotifications = (require("info").platform == "chromium" && "notifications" in chrome && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").applicationVersion) > 34));
Felix Dahlke 2014/03/28 13:10:41 The outer parentheses are redundant here. And I'd
Thomas Greiner 2014/03/28 15:57:08 Done.
+if (canUseChromeNotifications)
+{
+ chrome.notifications.onButtonClicked.addListener(notificationButtonClick);
+ chrome.notifications.onClosed.addListener(notificationClosed);
+ // Chrome hides notifications in notification center when clicked so we need to close them
+ chrome.notifications.onClicked.addListener(function(id, callback)
+ {
+ chrome.notifications.clear(id, function(wasCleared)
+ {
+ if (wasCleared)
+ notificationClosed();
+ });
+ });
+}
+
function showNotification(notification)
{
if (activeNotification && activeNotification.id === notification.id)
@@ -374,9 +396,7 @@
var iconUrl = ext.getURL("icons/abp-128.png");
var hasLinks = activeNotification.links && activeNotification.links.length > 0;
- // Chrome on Linux does not fully support chrome.notifications yet
- // https://code.google.com/p/chromium/issues/detail?id=291485
- if (require("info").platform == "chromium" && "notifications" in chrome && navigator.platform.indexOf("Linux") == -1)
+ if (canUseChromeNotifications)
{
var opts = {
type: "basic",
@@ -401,7 +421,6 @@
}
chrome.notifications.create("", opts, function() {});
- chrome.notifications.onButtonClicked.addListener(notificationButtonClick);
}
else if (hasWebkitNotifications && "createNotification" in webkitNotifications && activeNotification.type !== "question")
{
@@ -411,6 +430,7 @@
var notification = webkitNotifications.createNotification(iconUrl, title, message);
notification.show();
notification.addEventListener("click", openNotificationLinks, false);
+ notification.addEventListener("close", notificationClosed, false);
}
else
{
« no previous file with comments | « no previous file | webrequest.js » ('j') | webrequest.js » ('J')

Powered by Google App Engine
This is Rietveld