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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 fileProperties: Object.create(null), | 79 fileProperties: Object.create(null), |
80 | 80 |
81 /** | 81 /** |
82 * List of filter subscriptions containing all filters | 82 * List of filter subscriptions containing all filters |
83 * @type {Subscription[]} | 83 * @type {Subscription[]} |
84 */ | 84 */ |
85 subscriptions: [], | 85 subscriptions: [], |
86 | 86 |
87 /** | 87 /** |
88 * Map of subscriptions already on the list, by their URL/identifier | 88 * Map of subscriptions already on the list, by their URL/identifier |
89 * @type {Object} | 89 * @type {Map.<string,Subscription>} |
90 */ | 90 */ |
91 knownSubscriptions: Object.create(null), | 91 knownSubscriptions: new Map(), |
92 | 92 |
93 /** | 93 /** |
94 * Finds the filter group that a filter should be added to by default. Will | 94 * Finds the filter group that a filter should be added to by default. Will |
95 * return null if this group doesn't exist yet. | 95 * return null if this group doesn't exist yet. |
96 * @param {Filter} filter | 96 * @param {Filter} filter |
97 * @return {?SpecialSubscription} | 97 * @return {?SpecialSubscription} |
98 */ | 98 */ |
99 getGroupForFilter(filter) | 99 getGroupForFilter(filter) |
100 { | 100 { |
101 let generalSubscription = null; | 101 let generalSubscription = null; |
(...skipping 15 matching lines...) Expand all Loading... |
117 } | 117 } |
118 return generalSubscription; | 118 return generalSubscription; |
119 }, | 119 }, |
120 | 120 |
121 /** | 121 /** |
122 * Adds a filter subscription to the list | 122 * Adds a filter subscription to the list |
123 * @param {Subscription} subscription filter subscription to be added | 123 * @param {Subscription} subscription filter subscription to be added |
124 */ | 124 */ |
125 addSubscription(subscription) | 125 addSubscription(subscription) |
126 { | 126 { |
127 if (subscription.url in FilterStorage.knownSubscriptions) | 127 if (FilterStorage.knownSubscriptions.has(subscription.url)) |
128 return; | 128 return; |
129 | 129 |
130 FilterStorage.subscriptions.push(subscription); | 130 FilterStorage.subscriptions.push(subscription); |
131 FilterStorage.knownSubscriptions[subscription.url] = subscription; | 131 FilterStorage.knownSubscriptions.set(subscription.url, subscription); |
132 addSubscriptionFilters(subscription); | 132 addSubscriptionFilters(subscription); |
133 | 133 |
134 FilterNotifier.triggerListeners("subscription.added", subscription); | 134 FilterNotifier.triggerListeners("subscription.added", subscription); |
135 }, | 135 }, |
136 | 136 |
137 /** | 137 /** |
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 | 148 |
149 FilterStorage.subscriptions.splice(i--, 1); | 149 FilterStorage.subscriptions.splice(i--, 1); |
150 delete FilterStorage.knownSubscriptions[subscription.url]; | 150 FilterStorage.knownSubscriptions.delete(subscription.url); |
151 FilterNotifier.triggerListeners("subscription.removed", subscription); | 151 FilterNotifier.triggerListeners("subscription.removed", subscription); |
152 return; | 152 return; |
153 } | 153 } |
154 } | 154 } |
155 }, | 155 }, |
156 | 156 |
157 /** | 157 /** |
158 * Moves a subscription in the list to a new position. | 158 * Moves a subscription in the list to a new position. |
159 * @param {Subscription} subscription filter subscription to be moved | 159 * @param {Subscription} subscription filter subscription to be moved |
160 * @param {Subscription} [insertBefore] filter subscription to insert before | 160 * @param {Subscription} [insertBefore] filter subscription to insert before |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 * forgetting this callback. | 361 * forgetting this callback. |
362 */ | 362 */ |
363 importData(silent) | 363 importData(silent) |
364 { | 364 { |
365 let parser = new INIParser(); | 365 let parser = new INIParser(); |
366 return line => | 366 return line => |
367 { | 367 { |
368 parser.process(line); | 368 parser.process(line); |
369 if (line === null) | 369 if (line === null) |
370 { | 370 { |
371 let knownSubscriptions = Object.create(null); | 371 let knownSubscriptions = new Map(); |
372 for (let subscription of parser.subscriptions) | 372 for (let subscription of parser.subscriptions) |
373 knownSubscriptions[subscription.url] = subscription; | 373 knownSubscriptions.set(subscription.url, subscription); |
374 | 374 |
375 this.fileProperties = parser.fileProperties; | 375 this.fileProperties = parser.fileProperties; |
376 this.subscriptions = parser.subscriptions; | 376 this.subscriptions = parser.subscriptions; |
377 this.knownSubscriptions = knownSubscriptions; | 377 this.knownSubscriptions = knownSubscriptions; |
378 Filter.knownFilters = parser.knownFilters; | 378 Filter.knownFilters = parser.knownFilters; |
379 Subscription.knownSubscriptions = parser.knownSubscriptions; | 379 Subscription.knownSubscriptions = parser.knownSubscriptions; |
380 | 380 |
381 if (!silent) | 381 if (!silent) |
382 FilterNotifier.triggerListeners("load"); | 382 FilterNotifier.triggerListeners("load"); |
383 } | 383 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 } | 651 } |
652 }; | 652 }; |
653 | 653 |
654 /** | 654 /** |
655 * Joins subscription's filters to the subscription without any notifications. | 655 * Joins subscription's filters to the subscription without any notifications. |
656 * @param {Subscription} subscription | 656 * @param {Subscription} subscription |
657 * filter subscription that should be connected to its filters | 657 * filter subscription that should be connected to its filters |
658 */ | 658 */ |
659 function addSubscriptionFilters(subscription) | 659 function addSubscriptionFilters(subscription) |
660 { | 660 { |
661 if (!(subscription.url in FilterStorage.knownSubscriptions)) | 661 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
662 return; | 662 return; |
663 | 663 |
664 for (let filter of subscription.filters) | 664 for (let filter of subscription.filters) |
665 filter.subscriptions.push(subscription); | 665 filter.subscriptions.push(subscription); |
666 } | 666 } |
667 | 667 |
668 /** | 668 /** |
669 * Removes subscription's filters from the subscription without any | 669 * Removes subscription's filters from the subscription without any |
670 * notifications. | 670 * notifications. |
671 * @param {Subscription} subscription filter subscription to be removed | 671 * @param {Subscription} subscription filter subscription to be removed |
672 */ | 672 */ |
673 function removeSubscriptionFilters(subscription) | 673 function removeSubscriptionFilters(subscription) |
674 { | 674 { |
675 if (!(subscription.url in FilterStorage.knownSubscriptions)) | 675 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
676 return; | 676 return; |
677 | 677 |
678 for (let filter of subscription.filters) | 678 for (let filter of subscription.filters) |
679 { | 679 { |
680 let i = filter.subscriptions.indexOf(subscription); | 680 let i = filter.subscriptions.indexOf(subscription); |
681 if (i >= 0) | 681 if (i >= 0) |
682 filter.subscriptions.splice(i, 1); | 682 filter.subscriptions.splice(i, 1); |
683 } | 683 } |
684 } | 684 } |
685 | 685 |
686 /** | 686 /** |
687 * Listener returned by FilterStorage.importData(), parses filter data. | 687 * Listener returned by FilterStorage.importData(), parses filter data. |
688 * @constructor | 688 * @constructor |
689 */ | 689 */ |
690 function INIParser() | 690 function INIParser() |
691 { | 691 { |
692 this.fileProperties = this.curObj = {}; | 692 this.fileProperties = this.curObj = {}; |
693 this.subscriptions = []; | 693 this.subscriptions = []; |
694 this.knownFilters = new Map(); | 694 this.knownFilters = new Map(); |
695 this.knownSubscriptions = Object.create(null); | 695 this.knownSubscriptions = new Map(); |
696 } | 696 } |
697 INIParser.prototype = | 697 INIParser.prototype = |
698 { | 698 { |
699 linesProcessed: 0, | 699 linesProcessed: 0, |
700 subscriptions: null, | 700 subscriptions: null, |
701 knownFilters: null, | 701 knownFilters: null, |
702 knownSubscriptions: null, | 702 knownSubscriptions: null, |
703 wantObj: true, | 703 wantObj: true, |
704 fileProperties: null, | 704 fileProperties: null, |
705 curObj: null, | 705 curObj: null, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 else if (this.wantObj === false && val) | 773 else if (this.wantObj === false && val) |
774 this.curObj.push(val.replace(/\\\[/g, "[")); | 774 this.curObj.push(val.replace(/\\\[/g, "[")); |
775 } | 775 } |
776 finally | 776 finally |
777 { | 777 { |
778 Filter.knownFilters = origKnownFilters; | 778 Filter.knownFilters = origKnownFilters; |
779 Subscription.knownSubscriptions = origKnownSubscriptions; | 779 Subscription.knownSubscriptions = origKnownSubscriptions; |
780 } | 780 } |
781 } | 781 } |
782 }; | 782 }; |
OLD | NEW |