OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 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 (function(global) |
| 19 { |
| 20 var subscriptionKeys = ["disabled", "homepage", "lastSuccess", "title", "url",
"downloadStatus"]; |
| 21 function convertSubscription(subscription) |
| 22 { |
| 23 var result = {}; |
| 24 for (var i = 0; i < subscriptionKeys.length; i++) |
| 25 result[subscriptionKeys[i]] = subscription[subscriptionKeys[i]] |
| 26 return result; |
| 27 } |
| 28 |
| 29 var changeListeners = null; |
| 30 function onFilterChange(action) |
| 31 { |
| 32 var parts = action.split(".", 2); |
| 33 var type; |
| 34 if (parts.length == 1) |
| 35 { |
| 36 type = "app"; |
| 37 action = parts[0]; |
| 38 } |
| 39 else |
| 40 { |
| 41 type = parts[0]; |
| 42 action = parts[1]; |
| 43 } |
| 44 |
| 45 for (var i = 0; i < changeListeners.length; i++) |
| 46 { |
| 47 if (changeListeners[i].type == type && changeListeners[i].filter.indexOf(a
ction) >= 0) |
| 48 { |
| 49 changeListeners[i].sender.sendMessage({ |
| 50 type: changeListeners[i].messageType, |
| 51 action: action, |
| 52 args: Array.prototype.slice.call(arguments, 1) |
| 53 }); |
| 54 } |
| 55 } |
| 56 }; |
| 57 |
| 58 ext.onMessage.addListener(function(message, sender, callback) |
| 59 { |
| 60 switch (message.type) |
| 61 { |
| 62 case "app.doclink": |
| 63 callback(Utils.getDocLink(message.args[0])); |
| 64 break; |
| 65 case "app.info": |
| 66 callback(require("info")); |
| 67 break; |
| 68 case "app.issues": |
| 69 callback({ |
| 70 seenDataCorruption: "seenDataCorruption" in global ? global.seenDataCo
rruption : false, |
| 71 filterlistsReinitialized: "filterlistsReinitialized" in global ? globa
l.filterlistsReinitialized : false |
| 72 }); |
| 73 break; |
| 74 case "app.options": |
| 75 if (typeof UI != "undefined") |
| 76 UI.openFiltersDialog(); |
| 77 else |
| 78 global.openOptions(); |
| 79 break; |
| 80 case "subscriptions.get": |
| 81 callback(FilterStorage.subscriptions.map(convertSubscription)); |
| 82 break; |
| 83 case "filters.blocked": |
| 84 var filter = defaultMatcher.matchesAny(message.url, message.requestType,
message.docDomain, message.thirdParty); |
| 85 callback(filter instanceof BlockingFilter); |
| 86 break; |
| 87 case "subscriptions.toggle": |
| 88 var subscription = Subscription.fromURL(message.url); |
| 89 if (subscription.url in FilterStorage.knownSubscriptions && !subscriptio
n.disabled) |
| 90 FilterStorage.removeSubscription(subscription); |
| 91 else |
| 92 { |
| 93 subscription.disabled = false; |
| 94 subscription.title = message.title; |
| 95 subscription.homepage = message.homepage; |
| 96 FilterStorage.addSubscription(subscription); |
| 97 if (!subscription.lastDownload) |
| 98 Synchronizer.execute(subscription); |
| 99 } |
| 100 break; |
| 101 case "subscriptions.listen": |
| 102 if (!changeListeners) |
| 103 { |
| 104 changeListeners = []; |
| 105 FilterNotifier.addListener(onFilterChange); |
| 106 } |
| 107 changeListeners.push({ |
| 108 type: "subscription", |
| 109 filter: message.filter, |
| 110 messageType: message.type, |
| 111 sender: sender |
| 112 }); |
| 113 break; |
| 114 } |
| 115 }); |
| 116 })(this); |
OLD | NEW |