| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 /* |  | 
| 2  * This file is part of Adblock Plus <https://adblockplus.org/>, |  | 
| 3  * Copyright (C) 2006-2016 Eyeo GmbH |  | 
| 4  * |  | 
| 5  * Adblock Plus is free software: you can redistribute it and/or modify |  | 
| 6  * it under the terms of the GNU General Public License version 3 as |  | 
| 7  * published by the Free Software Foundation. |  | 
| 8  * |  | 
| 9  * Adblock Plus is distributed in the hope that it will be useful, |  | 
| 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of |  | 
| 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | 
| 12  * GNU General Public License for more details. |  | 
| 13  * |  | 
| 14  * You should have received a copy of the GNU General Public License |  | 
| 15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. |  | 
| 16  */ |  | 
| 17 |  | 
| 18 Cu.import("resource://gre/modules/Services.jsm"); |  | 
| 19 |  | 
| 20 let {Utils} = require("utils"); |  | 
| 21 let {Prefs} = require("prefs"); |  | 
| 22 let {ActiveFilter} = require("filterClasses"); |  | 
| 23 let {FilterStorage} = require("filterStorage"); |  | 
| 24 let {FilterNotifier} = require("filterNotifier"); |  | 
| 25 let {Subscription} = require("subscriptionClasses"); |  | 
| 26 let {Notification} = require("notification"); |  | 
| 27 |  | 
| 28 exports.initAntiAdblockNotification = function initAntiAdblockNotification() |  | 
| 29 { |  | 
| 30   let notification = { |  | 
| 31     id: "antiadblock", |  | 
| 32     type: "question", |  | 
| 33     title: Utils.getString("notification_antiadblock_title"), |  | 
| 34     message: Utils.getString("notification_antiadblock_message"), |  | 
| 35     urlFilters: [] |  | 
| 36   }; |  | 
| 37 |  | 
| 38   function notificationListener(approved) |  | 
| 39   { |  | 
| 40     let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); |  | 
| 41     if (subscription.url in FilterStorage.knownSubscriptions) |  | 
| 42       subscription.disabled = !approved; |  | 
| 43   } |  | 
| 44 |  | 
| 45   function addAntiAdblockNotification(subscription) |  | 
| 46   { |  | 
| 47     let urlFilters = []; |  | 
| 48     for (let filter of subscription.filters) |  | 
| 49     { |  | 
| 50       if (filter instanceof ActiveFilter) |  | 
| 51       { |  | 
| 52         for (let domain in filter.domains) |  | 
| 53         { |  | 
| 54           let urlFilter = "||" + domain + "^$document"; |  | 
| 55           if (domain && filter.domains[domain] && urlFilters.indexOf(urlFilter) 
    == -1) |  | 
| 56             urlFilters.push(urlFilter); |  | 
| 57         } |  | 
| 58       } |  | 
| 59     } |  | 
| 60     notification.urlFilters = urlFilters; |  | 
| 61     Notification.addNotification(notification); |  | 
| 62     Notification.addQuestionListener(notification.id, notificationListener); |  | 
| 63   } |  | 
| 64 |  | 
| 65   function removeAntiAdblockNotification() |  | 
| 66   { |  | 
| 67     Notification.removeNotification(notification); |  | 
| 68     Notification.removeQuestionListener(notification.id, notificationListener); |  | 
| 69   } |  | 
| 70 |  | 
| 71   let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); |  | 
| 72   if (subscription.lastDownload && subscription.disabled) |  | 
| 73     addAntiAdblockNotification(subscription); |  | 
| 74 |  | 
| 75   FilterNotifier.addListener(function(action, value, newItem, oldItem) |  | 
| 76   { |  | 
| 77     if (!/^subscription\.(updated|removed|disabled)$/.test(action) || value.url 
    != Prefs.subscriptions_antiadblockurl) |  | 
| 78       return; |  | 
| 79 |  | 
| 80     if (action == "subscription.updated") |  | 
| 81       addAntiAdblockNotification(value); |  | 
| 82     else if (action == "subscription.removed" || (action == "subscription.disabl
    ed" && !value.disabled)) |  | 
| 83       removeAntiAdblockNotification(); |  | 
| 84   }); |  | 
| 85 } |  | 
| OLD | NEW | 
|---|