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 28, 2014, 3: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 | webrequest.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
@@ -18,7 +18,6 @@
with(require("filterClasses"))
{
this.Filter = Filter;
- this.ActiveFilter = ActiveFilter;
this.RegExpFilter = RegExpFilter;
this.BlockingFilter = BlockingFilter;
this.WhitelistFilter = WhitelistFilter;
@@ -47,6 +46,12 @@
RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OTHER;
+// Chrome on Linux does not fully support chrome.notifications until version 35
+// 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);
+
var isFirstRun = false;
var seenDataCorruption = false;
require("filterNotifier").FilterNotifier.addListener(function(action)
@@ -65,6 +70,8 @@
addSubscription(prevVersion);
}
+ if (canUseChromeNotifications)
+ initChromeNotifications();
initAntiAdblockNotification();
}
@@ -314,7 +321,7 @@
{
if (animateIcon)
iconAnimation.stop();
- activeNotification = null;
+ notificationClosed();
};
if (animateIcon)
iconAnimation.update(activeNotification.type);
@@ -334,23 +341,52 @@
}
}
-function notificationButtonClick(id, index)
+function notificationButtonClick(buttonIndex)
{
if (activeNotification.type === "question")
{
- Notification.triggerQuestionListeners(activeNotification.id, index === 0);
+ Notification.triggerQuestionListeners(activeNotification.id, buttonIndex === 0);
Notification.markAsShown(activeNotification.id);
activeNotification.onClicked();
}
- else if (activeNotification.links && activeNotification.links[index])
+ else if (activeNotification.links && activeNotification.links[buttonIndex])
{
ext.windows.getLastFocused(function(win)
{
- win.openTab(Utils.getDocLink(activeNotification.links[index]));
+ win.openTab(Utils.getDocLink(activeNotification.links[buttonIndex]));
});
}
}
+function notificationClosed()
+{
+ activeNotification = null;
+}
+
+function initChromeNotifications()
+{
+ // Chrome hides notifications in notification center when clicked so we need to close them
+ function clearActiveNotification(notificationId)
+ {
+ if (activeNotification && activeNotification.type != "question")
Felix Dahlke 2014/03/28 16:16:39 Why check for the notification type here? Seems to
Thomas Greiner 2014/03/28 17:26:51 What this function does is remove the notification
Felix Dahlke 2014/03/28 17:33:46 Ah, no I get it. No it's fine let's go with 2 if y
Thomas Greiner 2014/03/28 18:23:17 For completeness' sake, what I meant for (2) was:
+ return;
+
+ chrome.notifications.clear(notificationId, function(wasCleared)
+ {
+ if (wasCleared)
+ notificationClosed();
+ });
+ }
+
+ chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex)
+ {
+ notificationButtonClick(buttonIndex);
+ clearActiveNotification(notificationId);
Thomas Greiner 2014/03/28 15:57:08 I noticed that even notifications that were dismis
+ });
+ chrome.notifications.onClicked.addListener(clearActiveNotification);
+ chrome.notifications.onClosed.addListener(notificationClosed);
+}
+
function showNotification(notification)
{
if (activeNotification && activeNotification.id === notification.id)
@@ -374,9 +410,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 +435,6 @@
}
chrome.notifications.create("", opts, function() {});
- chrome.notifications.onButtonClicked.addListener(notificationButtonClick);
}
else if (hasWebkitNotifications && "createNotification" in webkitNotifications && activeNotification.type !== "question")
{
@@ -411,6 +444,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld