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-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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 Services.obs.removeObserver(HistoryPurgeObserver, | 127 Services.obs.removeObserver(HistoryPurgeObserver, |
128 "browser:purge-session-history"); | 128 "browser:purge-session-history"); |
129 }); | 129 }); |
130 } | 130 } |
131 init(); | 131 init(); |
132 | 132 |
133 /** | 133 /** |
134 * Notifies Matcher instances or ElemHide object about a new filter | 134 * Notifies Matcher instances or ElemHide object about a new filter |
135 * if necessary. | 135 * if necessary. |
136 * @param {Filter} filter filter that has been added | 136 * @param {Filter} filter filter that has been added |
| 137 * @param {?Array.<Subscription>} [subscriptions] subscriptions to which the |
| 138 * filter belongs |
137 */ | 139 */ |
138 function addFilter(filter) | 140 function addFilter(filter, subscriptions = null) |
139 { | 141 { |
140 if (!(filter instanceof ActiveFilter) || filter.disabled) | 142 if (!(filter instanceof ActiveFilter) || filter.disabled) |
141 return; | 143 return; |
142 | 144 |
143 let hasEnabled = false; | 145 let hasEnabled = false; |
144 let allowSnippets = false; | 146 let allowSnippets = false; |
145 for (let subscription of filter.subscriptions()) | 147 for (let subscription of subscriptions || |
| 148 filterStorage.subscriptions(filter.text)) |
146 { | 149 { |
147 if (!subscription.disabled) | 150 if (!subscription.disabled) |
148 { | 151 { |
149 hasEnabled = true; | 152 hasEnabled = true; |
150 | 153 |
151 // Allow snippets to be executed only by the circumvention lists or the | 154 // Allow snippets to be executed only by the circumvention lists or the |
152 // user's own filters. | 155 // user's own filters. |
153 if (subscription.type == "circumvention" || | 156 if (subscription.type == "circumvention" || |
154 subscription.url == "https://easylist-downloads.adblockplus.org/abp-fi
lters-anti-cv.txt" || | 157 subscription.url == "https://easylist-downloads.adblockplus.org/abp-fi
lters-anti-cv.txt" || |
155 subscription instanceof SpecialSubscription) | 158 subscription instanceof SpecialSubscription) |
(...skipping 27 matching lines...) Expand all Loading... |
183 * @param {Filter} filter filter that has been removed | 186 * @param {Filter} filter filter that has been removed |
184 */ | 187 */ |
185 function removeFilter(filter) | 188 function removeFilter(filter) |
186 { | 189 { |
187 if (!(filter instanceof ActiveFilter)) | 190 if (!(filter instanceof ActiveFilter)) |
188 return; | 191 return; |
189 | 192 |
190 if (!filter.disabled) | 193 if (!filter.disabled) |
191 { | 194 { |
192 let hasEnabled = false; | 195 let hasEnabled = false; |
193 for (let subscription of filter.subscriptions()) | 196 for (let subscription of filterStorage.subscriptions(filter.text)) |
194 { | 197 { |
195 if (!subscription.disabled) | 198 if (!subscription.disabled) |
196 { | 199 { |
197 hasEnabled = true; | 200 hasEnabled = true; |
198 break; | 201 break; |
199 } | 202 } |
200 } | 203 } |
201 if (hasEnabled) | 204 if (hasEnabled) |
202 return; | 205 return; |
203 } | 206 } |
(...skipping 13 matching lines...) Expand all Loading... |
217 Snippets.remove(filter); | 220 Snippets.remove(filter); |
218 } | 221 } |
219 | 222 |
220 function onSubscriptionAdded(subscription) | 223 function onSubscriptionAdded(subscription) |
221 { | 224 { |
222 FilterListener.setDirty(1); | 225 FilterListener.setDirty(1); |
223 | 226 |
224 if (!subscription.disabled) | 227 if (!subscription.disabled) |
225 { | 228 { |
226 for (let text of subscription.filterText()) | 229 for (let text of subscription.filterText()) |
227 addFilter(Filter.fromText(text)); | 230 addFilter(Filter.fromText(text), [subscription]); |
228 } | 231 } |
229 } | 232 } |
230 | 233 |
231 function onSubscriptionRemoved(subscription) | 234 function onSubscriptionRemoved(subscription) |
232 { | 235 { |
233 FilterListener.setDirty(1); | 236 FilterListener.setDirty(1); |
234 | 237 |
235 if (!subscription.disabled) | 238 if (!subscription.disabled) |
236 { | 239 { |
237 for (let text of subscription.filterText()) | 240 for (let text of subscription.filterText()) |
238 removeFilter(Filter.fromText(text)); | 241 removeFilter(Filter.fromText(text)); |
239 } | 242 } |
240 } | 243 } |
241 | 244 |
242 function onSubscriptionDisabled(subscription, newValue) | 245 function onSubscriptionDisabled(subscription, newValue) |
243 { | 246 { |
244 FilterListener.setDirty(1); | 247 FilterListener.setDirty(1); |
245 | 248 |
246 if (filterStorage.knownSubscriptions.has(subscription.url)) | 249 if (filterStorage.knownSubscriptions.has(subscription.url)) |
247 { | 250 { |
248 if (newValue == false) | 251 if (newValue == false) |
249 { | 252 { |
250 for (let text of subscription.filterText()) | 253 for (let text of subscription.filterText()) |
251 addFilter(Filter.fromText(text)); | 254 addFilter(Filter.fromText(text), [subscription]); |
252 } | 255 } |
253 else | 256 else |
254 { | 257 { |
255 for (let text of subscription.filterText()) | 258 for (let text of subscription.filterText()) |
256 removeFilter(Filter.fromText(text)); | 259 removeFilter(Filter.fromText(text)); |
257 } | 260 } |
258 } | 261 } |
259 } | 262 } |
260 | 263 |
261 function onSubscriptionUpdated(subscription, oldFilterText) | 264 function onSubscriptionUpdated(subscription, oldFilterText) |
262 { | 265 { |
263 FilterListener.setDirty(1); | 266 FilterListener.setDirty(1); |
264 | 267 |
265 if (!subscription.disabled && | 268 if (!subscription.disabled && |
266 filterStorage.knownSubscriptions.has(subscription.url)) | 269 filterStorage.knownSubscriptions.has(subscription.url)) |
267 { | 270 { |
268 for (let text of oldFilterText) | 271 for (let text of oldFilterText) |
269 removeFilter(Filter.fromText(text)); | 272 removeFilter(Filter.fromText(text)); |
270 | 273 |
271 for (let text of subscription.filterText()) | 274 for (let text of subscription.filterText()) |
272 addFilter(Filter.fromText(text)); | 275 addFilter(Filter.fromText(text), [subscription]); |
273 } | 276 } |
274 } | 277 } |
275 | 278 |
276 function onFilterHitCount(filter, newValue) | 279 function onFilterHitCount(filter, newValue) |
277 { | 280 { |
278 if (newValue == 0) | 281 if (newValue == 0) |
279 FilterListener.setDirty(0); | 282 FilterListener.setDirty(0); |
280 else | 283 else |
281 FilterListener.setDirty(0.002); | 284 FilterListener.setDirty(0.002); |
282 } | 285 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 ElemHide.clear(); | 328 ElemHide.clear(); |
326 ElemHideEmulation.clear(); | 329 ElemHideEmulation.clear(); |
327 ElemHideExceptions.clear(); | 330 ElemHideExceptions.clear(); |
328 Snippets.clear(); | 331 Snippets.clear(); |
329 | 332 |
330 for (let subscription of filterStorage.subscriptions()) | 333 for (let subscription of filterStorage.subscriptions()) |
331 { | 334 { |
332 if (!subscription.disabled) | 335 if (!subscription.disabled) |
333 { | 336 { |
334 for (let text of subscription.filterText()) | 337 for (let text of subscription.filterText()) |
335 addFilter(Filter.fromText(text)); | 338 addFilter(Filter.fromText(text), [subscription]); |
336 } | 339 } |
337 } | 340 } |
338 } | 341 } |
339 | 342 |
340 function onSave() | 343 function onSave() |
341 { | 344 { |
342 isDirty = 0; | 345 isDirty = 0; |
343 } | 346 } |
OLD | NEW |