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

Unified Diff: lib/antiadblockInit.js

Issue 6020195227271168: Moved initAntiAdblockNotification function from ui.js to its own file (Closed)
Patch Set: Created March 19, 2014, 2:10 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 | lib/ui.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/antiadblockInit.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/antiadblockInit.js
@@ -0,0 +1,77 @@
+/*
+ * This file is part of Adblock Plus <http://adblockplus.org/>,
+ * Copyright (C) 2006-2014 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+let {Utils} = require("utils");
+let {Prefs} = require("prefs");
+let {FilterStorage} = require("filterStorage");
+let {FilterNotifier} = require("filterNotifier");
+let {Subscription} = require("subscriptionClasses");
+let {Notification} = require("notification");
+
+exports.initAntiAdblockNotification = function initAntiAdblockNotification()
+{
+ let notification = {
+ id: "antiadblock",
+ type: "question",
+ title: Utils.getString("notification_antiadblock_title"),
+ message: Utils.getString("notification_antiadblock_message"),
+ urlFilters: []
+ };
+
+ function notificationListener(approved)
+ {
+ let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl);
+ if (subscription.url in FilterStorage.knownSubscriptions)
+ subscription.disabled = !approved;
+ }
+
+ function addAntiAdblockNotification(subscription)
+ {
+ let urlFilters = [];
+ for each (let filter in subscription.filters)
+ if (filter instanceof ActiveFilter)
+ for (let domain in filter.domains)
+ if (domain && urlFilters.indexOf(domain) == -1)
+ urlFilters.push(domain);
+ notification.urlFilters = urlFilters;
+ Notification.addNotification(notification);
+ Notification.addQuestionListener(notification.id, notificationListener);
+ }
+
+ function removeAntiAdblockNotification()
+ {
+ Notification.removeNotification(notification);
+ Notification.removeQuestionListener(notification.id, notificationListener);
+ }
+
+ let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl);
+ if (subscription.lastDownload && subscription.disabled)
+ addAntiAdblockNotification(subscription);
+
+ FilterNotifier.addListener(function(action, value, newItem, oldItem)
+ {
+ if (!/^subscription\.(updated|removed|disabled)$/.test(action) || value.url != Prefs.subscriptions_antiadblockurl)
+ return;
+
+ if (action == "subscription.updated")
+ addAntiAdblockNotification(value);
+ else if (action == "subscription.removed" || (action == "subscription.disabled" && !value.disabled))
+ removeAntiAdblockNotification();
+ });
+}
« no previous file with comments | « no previous file | lib/ui.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld