OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 18 matching lines...) Expand all Loading... |
29 "@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest"); | 29 "@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest"); |
30 | 30 |
31 function require(module) | 31 function require(module) |
32 { | 32 { |
33 let result = {}; | 33 let result = {}; |
34 result.wrappedJSObject = result; | 34 result.wrappedJSObject = result; |
35 Services.obs.notifyObservers(result, "adblockplus-require", module); | 35 Services.obs.notifyObservers(result, "adblockplus-require", module); |
36 return result.exports; | 36 return result.exports; |
37 } | 37 } |
38 | 38 |
| 39 let {Filter} = require("filterClasses"); |
39 let {FilterStorage} = require("filterStorage"); | 40 let {FilterStorage} = require("filterStorage"); |
| 41 let {defaultMatcher} = require("matcher"); |
40 let {Prefs} = require("prefs"); | 42 let {Prefs} = require("prefs"); |
41 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri
ption, ExternalSubscription} = require("subscriptionClasses"); | 43 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri
ption, ExternalSubscription} = require("subscriptionClasses"); |
42 let {Synchronizer} = require("synchronizer"); | 44 let {Synchronizer} = require("synchronizer"); |
43 let {UI} = require("ui"); | 45 let {UI} = require("ui"); |
44 | 46 |
| 47 function getWhitelistingFilter(url) |
| 48 { |
| 49 let uriObject = Services.io.newURI(url, null, null); |
| 50 try |
| 51 { |
| 52 return defaultMatcher.whitelist.matchesAny( |
| 53 uriObject.spec, "DOCUMENT", uriObject.host, false, null); |
| 54 } |
| 55 catch (e) |
| 56 { |
| 57 return null; |
| 58 } |
| 59 } |
| 60 |
45 var AdblockPlusApi = | 61 var AdblockPlusApi = |
46 { | 62 { |
47 get filtersLoaded() | 63 get filtersLoaded() |
48 { | 64 { |
49 return !FilterStorage._loading; | 65 return !FilterStorage._loading; |
50 }, | 66 }, |
51 get acceptableAdsEnabled() | 67 get acceptableAdsEnabled() |
52 { | 68 { |
53 return FilterStorage.subscriptions.some( | 69 return FilterStorage.subscriptions.some( |
54 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); | 70 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); |
(...skipping 28 matching lines...) Expand all Loading... |
83 if (!subscription.lastDownload) | 99 if (!subscription.lastDownload) |
84 { | 100 { |
85 Synchronizer.execute(subscription); | 101 Synchronizer.execute(subscription); |
86 } | 102 } |
87 }, | 103 }, |
88 removeSubscription: function(url) | 104 removeSubscription: function(url) |
89 { | 105 { |
90 FilterStorage.removeSubscription( | 106 FilterStorage.removeSubscription( |
91 FilterStorage.knownSubscriptions[url]); | 107 FilterStorage.knownSubscriptions[url]); |
92 }, | 108 }, |
| 109 isLocal: function(url) |
| 110 { |
| 111 let uriObject = Services.io.newURI(url, null, null); |
| 112 return !uriObject.schemeIs("http") && !uriObject.schemeIs("https"); |
| 113 }, |
| 114 isPageWhitelisted: function(url) |
| 115 { |
| 116 return AdblockPlusApi.isLocal(url) || !!getWhitelistingFilter(url); |
| 117 }, |
| 118 whitelistSite: function(url, whitelisted) |
| 119 { |
| 120 let uriObject = Services.io.newURI(url, null, null); |
| 121 if (whitelisted) |
| 122 { |
| 123 var host = uriObject.host.replace(/^www\./, ""); |
| 124 var filter = Filter.fromText("@@||" + host + "^$document"); |
| 125 if (filter.subscriptions.length && filter.disabled) |
| 126 filter.disabled = false; |
| 127 else |
| 128 { |
| 129 filter.disabled = false; |
| 130 FilterStorage.addFilter(filter); |
| 131 } |
| 132 } |
| 133 else |
| 134 { |
| 135 // Remove any exception rules applying to this URL |
| 136 var filter = getWhitelistingFilter(url); |
| 137 while (filter) |
| 138 { |
| 139 FilterStorage.removeFilter(filter); |
| 140 if (filter.subscriptions.length) |
| 141 filter.disabled = true; |
| 142 filter = getWhitelistingFilter(url); |
| 143 } |
| 144 } |
| 145 }, |
93 initCommunication: function() | 146 initCommunication: function() |
94 { | 147 { |
95 RequestService.addListener((function(data) | 148 RequestService.addListener((function(data) |
96 { | 149 { |
97 if (!data) | 150 if (!data) |
98 return {"success": false, "error": "malformed request"}; | 151 return {"success": false, "error": "malformed request"}; |
99 | 152 |
100 if (data["action"] == "getFiltersLoaded") | 153 if (data["action"] == "getFiltersLoaded") |
101 return {"success": true, "value": this.filtersLoaded}; | 154 return {"success": true, "value": this.filtersLoaded}; |
102 | 155 |
(...skipping 27 matching lines...) Expand all Loading... |
130 return {"success": true}; | 183 return {"success": true}; |
131 } | 184 } |
132 break; | 185 break; |
133 case "removeSubscription": | 186 case "removeSubscription": |
134 if ("url" in data) | 187 if ("url" in data) |
135 { | 188 { |
136 this.removeSubscription(data["url"]); | 189 this.removeSubscription(data["url"]); |
137 return {"success": true}; | 190 return {"success": true}; |
138 } | 191 } |
139 break; | 192 break; |
| 193 case "isLocal": |
| 194 if ("url" in data) |
| 195 return {"success": true, |
| 196 "value": this.isLocal(data["url"])}; |
| 197 break; |
| 198 case "isPageWhitelisted": |
| 199 if ("url" in data) |
| 200 return {"success": true, |
| 201 "value": this.isPageWhitelisted(data["url"])}; |
| 202 break; |
| 203 case "whitelistSite": |
| 204 if ("url" in data && "whitelisted" in data) |
| 205 { |
| 206 this.whitelistSite(data["url"], data["whitelisted"]); |
| 207 return {"success": true}; |
| 208 } |
| 209 break; |
140 } | 210 } |
141 return {"success": false, "error": "malformed request"}; | 211 return {"success": false, "error": "malformed request"}; |
142 }).bind(this), "AdblockPlus:Api"); | 212 }).bind(this), "AdblockPlus:Api"); |
143 } | 213 } |
144 }; | 214 }; |
145 | |
OLD | NEW |