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 var args = Array.prototype.slice.call(arguments, 1).map(function(arg) |
| 46 { |
| 47 if (arg instanceof Subscription) |
| 48 return convertSubscription(arg); |
| 49 else |
| 50 return arg; |
| 51 }); |
| 52 |
| 53 for (var i = 0; i < changeListeners.length; i++) |
| 54 { |
| 55 if (changeListeners[i].type == type && changeListeners[i].filter.indexOf(a
ction) >= 0) |
| 56 { |
| 57 changeListeners[i].page.sendMessage({ |
| 58 type: changeListeners[i].messageType, |
| 59 action: action, |
| 60 args: args |
| 61 }); |
| 62 } |
| 63 } |
| 64 }; |
| 65 |
| 66 ext.onMessage.addListener(function(message, sender, callback) |
| 67 { |
| 68 switch (message.type) |
| 69 { |
| 70 case "app.doclink": |
| 71 callback(Utils.getDocLink(message.args[0])); |
| 72 break; |
| 73 case "app.info": |
| 74 callback(require("info")); |
| 75 break; |
| 76 case "app.issues": |
| 77 callback({ |
| 78 seenDataCorruption: "seenDataCorruption" in global ? global.seenDataCo
rruption : false, |
| 79 filterlistsReinitialized: "filterlistsReinitialized" in global ? globa
l.filterlistsReinitialized : false |
| 80 }); |
| 81 break; |
| 82 case "app.options": |
| 83 if (typeof UI != "undefined") |
| 84 UI.openFiltersDialog(); |
| 85 else |
| 86 global.openOptions(); |
| 87 break; |
| 88 case "subscriptions.get": |
| 89 callback(FilterStorage.subscriptions.map(convertSubscription)); |
| 90 break; |
| 91 case "filters.blocked": |
| 92 var filter = defaultMatcher.matchesAny(message.url, message.requestType,
message.docDomain, message.thirdParty); |
| 93 callback(filter instanceof BlockingFilter); |
| 94 break; |
| 95 case "subscriptions.toggle": |
| 96 var subscription = Subscription.fromURL(message.url); |
| 97 if (subscription.url in FilterStorage.knownSubscriptions && !subscriptio
n.disabled) |
| 98 FilterStorage.removeSubscription(subscription); |
| 99 else |
| 100 { |
| 101 subscription.disabled = false; |
| 102 subscription.title = message.title; |
| 103 subscription.homepage = message.homepage; |
| 104 FilterStorage.addSubscription(subscription); |
| 105 if (!subscription.lastDownload) |
| 106 Synchronizer.execute(subscription); |
| 107 } |
| 108 break; |
| 109 case "subscriptions.listen": |
| 110 if (!changeListeners) |
| 111 { |
| 112 changeListeners = []; |
| 113 FilterNotifier.addListener(onFilterChange); |
| 114 } |
| 115 changeListeners.push({ |
| 116 type: "subscription", |
| 117 filter: message.filter, |
| 118 messageType: message.type, |
| 119 page: sender.page |
| 120 }); |
| 121 break; |
| 122 case "removePage": |
| 123 if (!changeListeners) |
| 124 return; |
| 125 |
| 126 for (var i = 0; i < changeListeners.length; i++) |
| 127 if (changeListeners[i].page.equals(sender.page)) |
| 128 changeListeners.splice(i--, 1); |
| 129 |
| 130 if (!changeListeners.length) |
| 131 { |
| 132 changeListeners = null; |
| 133 FilterNotifier.removeListener(onFilterChange); |
| 134 } |
| 135 break; |
| 136 } |
| 137 }); |
| 138 })(this); |
OLD | NEW |