Index: lib/ui.js |
=================================================================== |
--- a/lib/ui.js |
+++ b/lib/ui.js |
@@ -25,11 +25,12 @@ |
let {FilterStorage} = require("filterStorage"); |
let {FilterNotifier} = require("filterNotifier"); |
let {RequestNotifier} = require("requestNotifier"); |
-let {Filter, ActiveFilter} = require("filterClasses"); |
+let {Filter} = require("filterClasses"); |
let {Subscription, SpecialSubscription, DownloadableSubscription} = require("subscriptionClasses"); |
let {Synchronizer} = require("synchronizer"); |
let {KeySelector} = require("keySelector"); |
let {Notification} = require("notification"); |
+let {setupAntiAdblockNotification} = require("antiadblock-setup"); |
let CustomizableUI; |
try |
@@ -398,73 +399,6 @@ |
} |
}, |
- _initAntiAdblockNotification: function() |
- { |
- 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(); |
- }); |
- |
- var documentCreationObserver = { |
- observe: function(subject, topic, data) |
- { |
- if (!(subject instanceof Ci.nsIDOMWindow)) |
- return; |
- |
- this._showNextNotification(subject.location.href); |
- }.bind(this) |
- }; |
- Services.obs.addObserver(documentCreationObserver, "content-document-global-created", false); |
- onShutdown.add(function() |
- { |
- Services.obs.removeObserver(documentCreationObserver, "content-document-global-created", false); |
- }); |
- }, |
- |
/** |
* Gets called once the initialization is finished and Adblock Plus elements |
* can be added to the UI. |
@@ -522,7 +456,7 @@ |
}.bind(this)); |
notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
- notificationTimer.initWithCallback(this._showNextNotification.bind(this), |
+ notificationTimer.initWithCallback(this.showNextNotification.bind(this), |
3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT); |
onShutdown.add(function() notificationTimer.cancel()); |
}, |
@@ -598,7 +532,22 @@ |
}, false); |
// Add "anti-adblock messages" notification |
- this._initAntiAdblockNotification(); |
+ setupAntiAdblockNotification(); |
+ |
+ let documentCreationObserver = { |
+ observe: function(subject, topic, data) |
+ { |
+ if (!(subject instanceof Ci.nsIDOMWindow)) |
+ return; |
+ |
+ this.showNextNotification(subject.location.href); |
+ }.bind(UI) |
+ }; |
+ Services.obs.addObserver(documentCreationObserver, "content-document-global-created", false); |
+ onShutdown.add(function() |
+ { |
+ Services.obs.removeObserver(documentCreationObserver, "content-document-global-created", false); |
+ }); |
// First-run actions? |
if (!this.firstRunDone) |
@@ -1850,7 +1799,7 @@ |
} |
}, |
- _showNextNotification: function(url) |
+ showNextNotification: function(url) |
{ |
let window = this.currentWindow; |
if (!window) |