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 ext.onPageRemoved.addListener(function(comparator) |
| 31 { |
| 32 if (!changeListeners) |
| 33 return; |
| 34 |
| 35 for (var i = 0; i < changeListeners.length; i++) |
| 36 if (comparator(changeListeners[i].page)) |
| 37 changeListeners.splice(i--, 1); |
| 38 |
| 39 if (!changeListeners.length) |
| 40 { |
| 41 changeListeners = null; |
| 42 FilterNotifier.removeListener(onFilterChange); |
| 43 } |
| 44 }); |
| 45 |
| 46 function onFilterChange(action) |
| 47 { |
| 48 var parts = action.split(".", 2); |
| 49 var type; |
| 50 if (parts.length == 1) |
| 51 { |
| 52 type = "app"; |
| 53 action = parts[0]; |
| 54 } |
| 55 else |
| 56 { |
| 57 type = parts[0]; |
| 58 action = parts[1]; |
| 59 } |
| 60 |
| 61 var args = Array.prototype.slice.call(arguments, 1).map(function(arg) |
| 62 { |
| 63 if (arg instanceof Subscription) |
| 64 return convertSubscription(arg); |
| 65 else |
| 66 return arg; |
| 67 }); |
| 68 |
| 69 for (var i = 0; i < changeListeners.length; i++) |
| 70 { |
| 71 if (changeListeners[i].type == type && changeListeners[i].filter.indexOf(a
ction) >= 0) |
| 72 { |
| 73 changeListeners[i].page.sendMessage({ |
| 74 type: changeListeners[i].messageType, |
| 75 action: action, |
| 76 args: args |
| 77 }); |
| 78 } |
| 79 } |
| 80 }; |
| 81 |
| 82 ext.onMessage.addListener(function(message, sender, callback) |
| 83 { |
| 84 switch (message.type) |
| 85 { |
| 86 case "app.get": |
| 87 if (message.what == "issues") |
| 88 { |
| 89 var info = require("info"); |
| 90 callback({ |
| 91 seenDataCorruption: "seenDataCorruption" in global ? global.seenData
Corruption : false, |
| 92 filterlistsReinitialized: "filterlistsReinitialized" in global ? glo
bal.filterlistsReinitialized : false, |
| 93 legacySafariVersion: (info.platform == "safari" && ( |
| 94 parseInt(info.platformVersion, 10) < 6 || // beforeload breaks w
ebsites in Safari 5 |
| 95 info.platformVersion == "6.1" || // extensions are brok
en in 6.1 and 7.0 |
| 96 info.platformVersion == "7.0")) |
| 97 }); |
| 98 } |
| 99 else if (message.what == "doclink") |
| 100 callback(Utils.getDocLink(message.link)); |
| 101 else |
| 102 callback(null); |
| 103 break; |
| 104 case "app.open": |
| 105 if (message.what == "options") |
| 106 { |
| 107 if (typeof UI != "undefined") |
| 108 UI.openFiltersDialog(); |
| 109 else |
| 110 global.openOptions(); |
| 111 } |
| 112 break; |
| 113 case "subscriptions.get": |
| 114 var subscriptions = FilterStorage.subscriptions.filter(function(s) |
| 115 { |
| 116 if (message.ignoreDisabled && s.disabled) |
| 117 return false; |
| 118 if (s instanceof DownloadableSubscription && message.downloadable) |
| 119 return true; |
| 120 if (s instanceof SpecialSubscription && message.special) |
| 121 return true; |
| 122 return false; |
| 123 }); |
| 124 callback(subscriptions.map(convertSubscription)); |
| 125 break; |
| 126 case "filters.blocked": |
| 127 var filter = defaultMatcher.matchesAny(message.url, message.requestType,
message.docDomain, message.thirdParty); |
| 128 callback(filter instanceof BlockingFilter); |
| 129 break; |
| 130 case "subscriptions.toggle": |
| 131 var subscription = Subscription.fromURL(message.url); |
| 132 if (subscription.url in FilterStorage.knownSubscriptions && !subscriptio
n.disabled) |
| 133 FilterStorage.removeSubscription(subscription); |
| 134 else |
| 135 { |
| 136 subscription.disabled = false; |
| 137 subscription.title = message.title; |
| 138 subscription.homepage = message.homepage; |
| 139 FilterStorage.addSubscription(subscription); |
| 140 if (!subscription.lastDownload) |
| 141 Synchronizer.execute(subscription); |
| 142 } |
| 143 break; |
| 144 case "subscriptions.listen": |
| 145 if (!changeListeners) |
| 146 { |
| 147 changeListeners = []; |
| 148 FilterNotifier.addListener(onFilterChange); |
| 149 } |
| 150 changeListeners.push({ |
| 151 type: "subscription", |
| 152 filter: message.filter, |
| 153 messageType: message.type, |
| 154 page: sender.page |
| 155 }); |
| 156 break; |
| 157 } |
| 158 }); |
| 159 })(this); |
OLD | NEW |