Left: | ||
Right: |
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 * Removes a filter subscription from the list | 138 * Removes a filter subscription from the list |
139 * @param {Subscription} subscription filter subscription to be removed | 139 * @param {Subscription} subscription filter subscription to be removed |
140 */ | 140 */ |
141 removeSubscription(subscription) | 141 removeSubscription(subscription) |
142 { | 142 { |
143 for (let i = 0; i < FilterStorage.subscriptions.length; i++) | 143 for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
144 { | 144 { |
145 if (FilterStorage.subscriptions[i].url == subscription.url) | 145 if (FilterStorage.subscriptions[i].url == subscription.url) |
146 { | 146 { |
147 removeSubscriptionFilters(subscription); | 147 removeSubscriptionFilters(subscription); |
148 for (let filter of subscription.filters) | |
149 { | |
150 if (filter.subscriptions.size == 0) | |
151 Filter.knownFilters.delete(filter.text); | |
152 } | |
148 | 153 |
Manish Jethani
2018/08/25 15:03:38
We should delete the filters here.
Jon Sonesen
2018/08/27 16:28:03
Hm, because of the update function calling removSu
| |
149 FilterStorage.subscriptions.splice(i--, 1); | 154 FilterStorage.subscriptions.splice(i--, 1); |
150 FilterStorage.knownSubscriptions.delete(subscription.url); | 155 FilterStorage.knownSubscriptions.delete(subscription.url); |
151 | |
152 // This should be the last remaining reference to the Subscription | |
153 // object. | |
154 Subscription.knownSubscriptions.delete(subscription.url); | |
155 | |
156 FilterNotifier.triggerListeners("subscription.removed", subscription); | 156 FilterNotifier.triggerListeners("subscription.removed", subscription); |
157 return; | 157 return; |
158 } | 158 } |
159 } | 159 } |
160 }, | 160 }, |
161 | 161 |
162 /** | 162 /** |
163 * Moves a subscription in the list to a new position. | 163 * Moves a subscription in the list to a new position. |
164 * @param {Subscription} subscription filter subscription to be moved | 164 * @param {Subscription} subscription filter subscription to be moved |
165 * @param {Subscription} [insertBefore] filter subscription to insert before | 165 * @param {Subscription} [insertBefore] filter subscription to insert before |
(...skipping 25 matching lines...) Expand all Loading... | |
191 /** | 191 /** |
192 * Replaces the list of filters in a subscription by a new list | 192 * Replaces the list of filters in a subscription by a new list |
193 * @param {Subscription} subscription filter subscription to be updated | 193 * @param {Subscription} subscription filter subscription to be updated |
194 * @param {Filter[]} filters new filter list | 194 * @param {Filter[]} filters new filter list |
195 */ | 195 */ |
196 updateSubscriptionFilters(subscription, filters) | 196 updateSubscriptionFilters(subscription, filters) |
197 { | 197 { |
198 removeSubscriptionFilters(subscription); | 198 removeSubscriptionFilters(subscription); |
199 subscription.oldFilters = subscription.filters; | 199 subscription.oldFilters = subscription.filters; |
200 subscription.filters = filters; | 200 subscription.filters = filters; |
201 addSubscriptionFilters(subscription); | 201 addSubscriptionFilters(subscription); |
Manish Jethani
2018/08/25 15:03:38
After calling addSubscriptionFilters, we should de
Jon Sonesen
2018/08/27 16:28:02
See comment above
| |
202 FilterNotifier.triggerListeners("subscription.updated", subscription); | 202 FilterNotifier.triggerListeners("subscription.updated", subscription); |
203 delete subscription.oldFilters; | 203 delete subscription.oldFilters; |
204 }, | 204 }, |
205 | 205 |
206 /** | 206 /** |
207 * Adds a user-defined filter to the list | 207 * Adds a user-defined filter to the list |
208 * @param {Filter} filter | 208 * @param {Filter} filter |
209 * @param {SpecialSubscription} [subscription] | 209 * @param {SpecialSubscription} [subscription] |
210 * particular group that the filter should be added to | 210 * particular group that the filter should be added to |
211 * @param {number} [position] | 211 * @param {number} [position] |
212 * position within the subscription at which the filter should be added | 212 * position within the subscription at which the filter should be added |
213 */ | 213 */ |
214 addFilter(filter, subscription, position) | 214 addFilter(filter, subscription, position) |
215 { | 215 { |
216 if (!subscription) | 216 if (!subscription) |
217 { | 217 { |
218 for (let currentSubscription of filter.subscriptions) | 218 if (filter.subscriptions.some(s => s instanceof SpecialSubscription && |
219 { | 219 !s.disabled)) |
220 if (currentSubscription instanceof SpecialSubscription && | 220 { |
221 !currentSubscription.disabled) | 221 return; // No need to add |
222 { | |
223 return; // No need to add | |
224 } | |
225 } | 222 } |
226 subscription = FilterStorage.getGroupForFilter(filter); | 223 subscription = FilterStorage.getGroupForFilter(filter); |
227 } | 224 } |
228 if (!subscription) | 225 if (!subscription) |
229 { | 226 { |
230 // No group for this filter exists, create one | 227 // No group for this filter exists, create one |
231 subscription = SpecialSubscription.createForFilter(filter); | 228 subscription = SpecialSubscription.createForFilter(filter); |
232 this.addSubscription(subscription); | 229 this.addSubscription(subscription); |
233 return; | 230 return; |
234 } | 231 } |
235 | 232 |
236 if (typeof position == "undefined") | 233 if (typeof position == "undefined") |
237 position = subscription.filters.length; | 234 position = subscription.filters.length; |
238 | 235 |
239 filter.subscriptions.add(subscription); | 236 if (filter.subscriptions.indexOf(subscription) < 0) |
237 filter.subscriptions.push(subscription); | |
240 subscription.filters.splice(position, 0, filter); | 238 subscription.filters.splice(position, 0, filter); |
241 FilterNotifier.triggerListeners("filter.added", filter, subscription, | 239 FilterNotifier.triggerListeners("filter.added", filter, subscription, |
242 position); | 240 position); |
243 }, | 241 }, |
244 | 242 |
245 /** | 243 /** |
246 * Removes a user-defined filter from the list | 244 * Removes a user-defined filter from the list |
247 * @param {Filter} filter | 245 * @param {Filter} filter |
248 * @param {SpecialSubscription} [subscription] a particular filter group that | 246 * @param {SpecialSubscription} [subscription] a particular filter group that |
249 * the filter should be removed from (if ommited will be removed from all | 247 * the filter should be removed from (if ommited will be removed from all |
250 * subscriptions) | 248 * subscriptions) |
251 * @param {number} [position] position inside the filter group at which the | 249 * @param {number} [position] position inside the filter group at which the |
252 * filter should be removed (if ommited all instances will be removed) | 250 * filter should be removed (if ommited all instances will be removed) |
253 */ | 251 */ |
254 removeFilter(filter, subscription, position) | 252 removeFilter(filter, subscription, position) |
255 { | 253 { |
256 let subscriptions = ( | 254 let subscriptions = ( |
257 subscription ? [subscription] : filter.subscriptions | 255 subscription ? [subscription] : filter.subscriptions.slice() |
258 ); | 256 ); |
259 for (let currentSubscription of subscriptions) | 257 for (let i = 0; i < subscriptions.length; i++) |
260 { | 258 { |
259 let currentSubscription = subscriptions[i]; | |
261 if (currentSubscription instanceof SpecialSubscription) | 260 if (currentSubscription instanceof SpecialSubscription) |
262 { | 261 { |
263 let positions = []; | 262 let positions = []; |
264 if (typeof position == "undefined") | 263 if (typeof position == "undefined") |
265 { | 264 { |
266 let index = -1; | 265 let index = -1; |
267 do | 266 do |
268 { | 267 { |
269 index = currentSubscription.filters.indexOf(filter, index + 1); | 268 index = currentSubscription.filters.indexOf(filter, index + 1); |
270 if (index >= 0) | 269 if (index >= 0) |
271 positions.push(index); | 270 positions.push(index); |
272 } while (index >= 0); | 271 } while (index >= 0); |
273 } | 272 } |
274 else | 273 else |
275 positions.push(position); | 274 positions.push(position); |
276 | 275 |
277 for (let j = positions.length - 1; j >= 0; j--) | 276 for (let j = positions.length - 1; j >= 0; j--) |
278 { | 277 { |
279 let currentPosition = positions[j]; | 278 let currentPosition = positions[j]; |
280 if (currentSubscription.filters[currentPosition] == filter) | 279 if (currentSubscription.filters[currentPosition] == filter) |
281 { | 280 { |
282 currentSubscription.filters.splice(currentPosition, 1); | 281 currentSubscription.filters.splice(currentPosition, 1); |
283 if (currentSubscription.filters.indexOf(filter) < 0) | 282 if (currentSubscription.filters.indexOf(filter) < 0) |
284 filter.subscriptions.delete(currentSubscription); | 283 { |
284 let index = filter.subscriptions.indexOf(currentSubscription); | |
285 if (index >= 0) | |
286 filter.subscriptions.splice(index, 1); | |
287 } | |
285 FilterNotifier.triggerListeners( | 288 FilterNotifier.triggerListeners( |
286 "filter.removed", filter, currentSubscription, currentPosition | 289 "filter.removed", filter, currentSubscription, currentPosition |
287 ); | 290 ); |
288 } | 291 } |
289 } | 292 } |
290 } | 293 } |
291 } | 294 } |
292 }, | 295 }, |
293 | 296 |
294 /** | 297 /** |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 * Joins subscription's filters to the subscription without any notifications. | 660 * Joins subscription's filters to the subscription without any notifications. |
658 * @param {Subscription} subscription | 661 * @param {Subscription} subscription |
659 * filter subscription that should be connected to its filters | 662 * filter subscription that should be connected to its filters |
660 */ | 663 */ |
661 function addSubscriptionFilters(subscription) | 664 function addSubscriptionFilters(subscription) |
662 { | 665 { |
663 if (!FilterStorage.knownSubscriptions.has(subscription.url)) | 666 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
664 return; | 667 return; |
665 | 668 |
666 for (let filter of subscription.filters) | 669 for (let filter of subscription.filters) |
667 filter.subscriptions.add(subscription); | 670 filter.subscriptions.push(subscription); |
668 } | 671 } |
669 | 672 |
670 /** | 673 /** |
671 * Removes subscription's filters from the subscription without any | 674 * Removes subscription's filters from the subscription without any |
672 * notifications. | 675 * notifications. |
673 * @param {Subscription} subscription filter subscription to be removed | 676 * @param {Subscription} subscription filter subscription to be removed |
674 */ | 677 */ |
675 function removeSubscriptionFilters(subscription) | 678 function removeSubscriptionFilters(subscription) |
676 { | 679 { |
677 if (!FilterStorage.knownSubscriptions.has(subscription.url)) | 680 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
678 return; | 681 return; |
679 | 682 |
680 for (let filter of subscription.filters) | 683 for (let filter of subscription.filters) |
681 { | 684 { |
682 filter.subscriptions.delete(subscription); | 685 let i = filter.subscriptions.indexOf(subscription); |
683 if (filter.subscriptions.size == 0) | 686 if (i >= 0) |
Manish Jethani
2018/08/25 15:03:38
removeSubscriptionFilters is also called from upda
jsonesen
2018/08/25 15:18:46
The deletion should I ly occur if there are no sub
jsonesen
2018/08/25 15:32:08
Oh shoot nevermind, since it removes first then ad
Manish Jethani
2018/08/26 15:56:19
Yes, exactly. If a filter is also in a different s
| |
684 Filter.knownFilters.delete(filter.text); | 687 filter.subscriptions.splice(i, 1); |
Jon Sonesen
2018/08/21 21:50:41
I found that there is a pretty good reduction in t
| |
685 } | 688 } |
686 } | 689 } |
687 | 690 |
688 /** | 691 /** |
689 * Listener returned by FilterStorage.importData(), parses filter data. | 692 * Listener returned by FilterStorage.importData(), parses filter data. |
690 * @constructor | 693 * @constructor |
691 */ | 694 */ |
692 function INIParser() | 695 function INIParser() |
693 { | 696 { |
694 this.fileProperties = this.curObj = {}; | 697 this.fileProperties = this.curObj = {}; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 case "subscription filters": | 741 case "subscription filters": |
739 if (this.subscriptions.length) | 742 if (this.subscriptions.length) |
740 { | 743 { |
741 let subscription = this.subscriptions[ | 744 let subscription = this.subscriptions[ |
742 this.subscriptions.length - 1 | 745 this.subscriptions.length - 1 |
743 ]; | 746 ]; |
744 for (let text of this.curObj) | 747 for (let text of this.curObj) |
745 { | 748 { |
746 let filter = Filter.fromText(text); | 749 let filter = Filter.fromText(text); |
747 subscription.filters.push(filter); | 750 subscription.filters.push(filter); |
748 filter.subscriptions.add(subscription); | 751 filter.subscriptions.push(subscription); |
749 } | 752 } |
750 } | 753 } |
751 break; | 754 break; |
752 } | 755 } |
753 } | 756 } |
754 | 757 |
755 if (val === null) | 758 if (val === null) |
756 return; | 759 return; |
757 | 760 |
758 this.curSection = match[1].toLowerCase(); | 761 this.curSection = match[1].toLowerCase(); |
(...skipping 16 matching lines...) Expand all Loading... | |
775 else if (this.wantObj === false && val) | 778 else if (this.wantObj === false && val) |
776 this.curObj.push(val.replace(/\\\[/g, "[")); | 779 this.curObj.push(val.replace(/\\\[/g, "[")); |
777 } | 780 } |
778 finally | 781 finally |
779 { | 782 { |
780 Filter.knownFilters = origKnownFilters; | 783 Filter.knownFilters = origKnownFilters; |
781 Subscription.knownSubscriptions = origKnownSubscriptions; | 784 Subscription.knownSubscriptions = origKnownSubscriptions; |
782 } | 785 } |
783 } | 786 } |
784 }; | 787 }; |
LEFT | RIGHT |