LEFT | RIGHT |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 12 matching lines...) Expand all Loading... |
23 */ | 23 */ |
24 | 24 |
25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
27 | 27 |
28 const {FilterStorage} = require("./filterStorage"); | 28 const {FilterStorage} = require("./filterStorage"); |
29 const {FilterNotifier} = require("./filterNotifier"); | 29 const {FilterNotifier} = require("./filterNotifier"); |
30 const {ElemHide} = require("./elemHide"); | 30 const {ElemHide} = require("./elemHide"); |
31 const {ElemHideEmulation} = require("./elemHideEmulation"); | 31 const {ElemHideEmulation} = require("./elemHideEmulation"); |
32 const {ElemHideExceptions} = require("./elemHideExceptions"); | 32 const {ElemHideExceptions} = require("./elemHideExceptions"); |
| 33 const {Snippets} = require("./snippets"); |
33 const {defaultMatcher} = require("./matcher"); | 34 const {defaultMatcher} = require("./matcher"); |
34 const {ActiveFilter, RegExpFilter, | 35 const {ActiveFilter, RegExpFilter, |
35 ElemHideBase, ElemHideEmulationFilter, | 36 ElemHideBase, ElemHideFilter, ElemHideEmulationFilter, |
36 ElemHideException} = require("./filterClasses"); | 37 SnippetFilter} = require("./filterClasses"); |
| 38 const {SpecialSubscription} = require("./subscriptionClasses"); |
37 const {Prefs} = require("prefs"); | 39 const {Prefs} = require("prefs"); |
38 | 40 |
39 /** | 41 /** |
40 * Increases on filter changes, filters will be saved if it exceeds 1. | 42 * Increases on filter changes, filters will be saved if it exceeds 1. |
41 * @type {number} | 43 * @type {number} |
42 */ | 44 */ |
43 let isDirty = 0; | 45 let isDirty = 0; |
44 | 46 |
45 /** | 47 /** |
46 * This object can be used to change properties of the filter change listeners. | 48 * This object can be used to change properties of the filter change listeners. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 * Notifies Matcher instances or ElemHide object about a new filter | 135 * Notifies Matcher instances or ElemHide object about a new filter |
134 * if necessary. | 136 * if necessary. |
135 * @param {Filter} filter filter that has been added | 137 * @param {Filter} filter filter that has been added |
136 */ | 138 */ |
137 function addFilter(filter) | 139 function addFilter(filter) |
138 { | 140 { |
139 if (!(filter instanceof ActiveFilter) || filter.disabled) | 141 if (!(filter instanceof ActiveFilter) || filter.disabled) |
140 return; | 142 return; |
141 | 143 |
142 let hasEnabled = false; | 144 let hasEnabled = false; |
| 145 let allowSnippets = false; |
143 for (let i = 0; i < filter.subscriptions.length; i++) | 146 for (let i = 0; i < filter.subscriptions.length; i++) |
144 { | 147 { |
145 if (!filter.subscriptions[i].disabled) | 148 let subscription = filter.subscriptions[i]; |
| 149 |
| 150 if (!subscription.disabled) |
| 151 { |
146 hasEnabled = true; | 152 hasEnabled = true; |
| 153 |
| 154 // Allow snippets to be executed only by the circumvention lists or the |
| 155 // user's own filters. |
| 156 if (subscription.type == "circumvention" || |
| 157 subscription instanceof SpecialSubscription) |
| 158 { |
| 159 allowSnippets = true; |
| 160 break; |
| 161 } |
| 162 } |
147 } | 163 } |
148 if (!hasEnabled) | 164 if (!hasEnabled) |
149 return; | 165 return; |
150 | 166 |
151 if (filter instanceof RegExpFilter) | 167 if (filter instanceof RegExpFilter) |
152 defaultMatcher.add(filter); | 168 defaultMatcher.add(filter); |
153 else if (filter instanceof ElemHideBase) | 169 else if (filter instanceof ElemHideBase) |
154 { | 170 { |
155 if (filter instanceof ElemHideException) | 171 if (filter instanceof ElemHideFilter) |
156 ElemHideExceptions.add(filter); | 172 ElemHide.add(filter); |
157 if (filter instanceof ElemHideEmulationFilter) | 173 else if (filter instanceof ElemHideEmulationFilter) |
158 ElemHideEmulation.add(filter); | 174 ElemHideEmulation.add(filter); |
159 else | 175 else |
160 ElemHide.add(filter); | 176 ElemHideExceptions.add(filter); |
161 } | 177 } |
| 178 else if (allowSnippets && filter instanceof SnippetFilter) |
| 179 Snippets.add(filter); |
162 } | 180 } |
163 | 181 |
164 /** | 182 /** |
165 * Notifies Matcher instances or ElemHide object about removal of a filter | 183 * Notifies Matcher instances or ElemHide object about removal of a filter |
166 * if necessary. | 184 * if necessary. |
167 * @param {Filter} filter filter that has been removed | 185 * @param {Filter} filter filter that has been removed |
168 */ | 186 */ |
169 function removeFilter(filter) | 187 function removeFilter(filter) |
170 { | 188 { |
171 if (!(filter instanceof ActiveFilter)) | 189 if (!(filter instanceof ActiveFilter)) |
172 return; | 190 return; |
173 | 191 |
174 if (!filter.disabled) | 192 if (!filter.disabled) |
175 { | 193 { |
176 let hasEnabled = false; | 194 let hasEnabled = false; |
177 for (let i = 0; i < filter.subscriptions.length; i++) | 195 for (let i = 0; i < filter.subscriptions.length; i++) |
178 { | 196 { |
179 if (!filter.subscriptions[i].disabled) | 197 if (!filter.subscriptions[i].disabled) |
| 198 { |
180 hasEnabled = true; | 199 hasEnabled = true; |
| 200 break; |
| 201 } |
181 } | 202 } |
182 if (hasEnabled) | 203 if (hasEnabled) |
183 return; | 204 return; |
184 } | 205 } |
185 | 206 |
186 if (filter instanceof RegExpFilter) | 207 if (filter instanceof RegExpFilter) |
187 defaultMatcher.remove(filter); | 208 defaultMatcher.remove(filter); |
188 else if (filter instanceof ElemHideBase) | 209 else if (filter instanceof ElemHideBase) |
189 { | 210 { |
190 if (filter instanceof ElemHideException) | 211 if (filter instanceof ElemHideFilter) |
191 ElemHideExceptions.remove(filter); | 212 ElemHide.remove(filter); |
192 if (filter instanceof ElemHideEmulationFilter) | 213 else if (filter instanceof ElemHideEmulationFilter) |
193 ElemHideEmulation.remove(filter); | 214 ElemHideEmulation.remove(filter); |
194 else | 215 else |
195 ElemHide.remove(filter); | 216 ElemHideExceptions.remove(filter); |
196 } | 217 } |
| 218 else if (filter instanceof SnippetFilter) |
| 219 Snippets.remove(filter); |
197 } | 220 } |
198 | 221 |
199 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; | 222 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; |
200 | 223 |
201 function addFilters(filters) | 224 function addFilters(filters) |
202 { | 225 { |
203 // We add filters using pseudo-random ordering. Reason is that ElemHide will | 226 // We add filters using pseudo-random ordering. Reason is that ElemHide will |
204 // assign consecutive filter IDs that might be visible to the website. The | 227 // assign consecutive filter IDs that might be visible to the website. The |
205 // randomization makes sure that no conclusion can be made about the actual | 228 // randomization makes sure that no conclusion can be made about the actual |
206 // filters applying there. We have ten prime numbers to use as iteration step, | 229 // filters applying there. We have ten prime numbers to use as iteration step, |
(...skipping 27 matching lines...) Expand all Loading... |
234 FilterListener.setDirty(1); | 257 FilterListener.setDirty(1); |
235 | 258 |
236 if (!subscription.disabled) | 259 if (!subscription.disabled) |
237 subscription.filters.forEach(removeFilter); | 260 subscription.filters.forEach(removeFilter); |
238 } | 261 } |
239 | 262 |
240 function onSubscriptionDisabled(subscription, newValue) | 263 function onSubscriptionDisabled(subscription, newValue) |
241 { | 264 { |
242 FilterListener.setDirty(1); | 265 FilterListener.setDirty(1); |
243 | 266 |
244 if (subscription.url in FilterStorage.knownSubscriptions) | 267 if (FilterStorage.knownSubscriptions.has(subscription.url)) |
245 { | 268 { |
246 if (newValue == false) | 269 if (newValue == false) |
247 addFilters(subscription.filters); | 270 addFilters(subscription.filters); |
248 else | 271 else |
249 subscription.filters.forEach(removeFilter); | 272 subscription.filters.forEach(removeFilter); |
250 } | 273 } |
251 } | 274 } |
252 | 275 |
253 function onSubscriptionUpdated(subscription) | 276 function onSubscriptionUpdated(subscription) |
254 { | 277 { |
255 FilterListener.setDirty(1); | 278 FilterListener.setDirty(1); |
256 | 279 |
257 if (subscription.url in FilterStorage.knownSubscriptions && | 280 if (!subscription.disabled && |
258 !subscription.disabled) | 281 FilterStorage.knownSubscriptions.has(subscription.url)) |
259 { | 282 { |
260 subscription.oldFilters.forEach(removeFilter); | 283 subscription.oldFilters.forEach(removeFilter); |
261 addFilters(subscription.filters); | 284 addFilters(subscription.filters); |
262 } | 285 } |
263 } | 286 } |
264 | 287 |
265 function onFilterHitCount(filter, newValue) | 288 function onFilterHitCount(filter, newValue) |
266 { | 289 { |
267 if (newValue == 0) | 290 if (newValue == 0) |
268 FilterListener.setDirty(0); | 291 FilterListener.setDirty(0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 330 } |
308 | 331 |
309 function onLoad() | 332 function onLoad() |
310 { | 333 { |
311 isDirty = 0; | 334 isDirty = 0; |
312 | 335 |
313 defaultMatcher.clear(); | 336 defaultMatcher.clear(); |
314 ElemHide.clear(); | 337 ElemHide.clear(); |
315 ElemHideEmulation.clear(); | 338 ElemHideEmulation.clear(); |
316 ElemHideExceptions.clear(); | 339 ElemHideExceptions.clear(); |
| 340 Snippets.clear(); |
317 for (let subscription of FilterStorage.subscriptions) | 341 for (let subscription of FilterStorage.subscriptions) |
318 { | 342 { |
319 if (!subscription.disabled) | 343 if (!subscription.disabled) |
320 addFilters(subscription.filters); | 344 addFilters(subscription.filters); |
321 } | 345 } |
322 } | 346 } |
323 | 347 |
324 function onSave() | 348 function onSave() |
325 { | 349 { |
326 isDirty = 0; | 350 isDirty = 0; |
327 } | 351 } |
LEFT | RIGHT |