| 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 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
| 144 return; |
| 145 |
| 143 for (let i = 0; i < FilterStorage.subscriptions.length; i++) | 146 for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
| 144 { | 147 { |
| 145 if (FilterStorage.subscriptions[i].url == subscription.url) | 148 if (FilterStorage.subscriptions[i].url == subscription.url) |
| 146 { | 149 { |
| 147 removeSubscriptionFilters(subscription); | 150 removeSubscriptionFilters(subscription); |
| 148 | 151 |
| 149 FilterStorage.subscriptions.splice(i--, 1); | 152 FilterStorage.subscriptions.splice(i--, 1); |
| 150 delete FilterStorage.knownSubscriptions[subscription.url]; | 153 FilterStorage.knownSubscriptions.delete(subscription.url); |
| 151 FilterNotifier.triggerListeners("subscription.removed", subscription); | 154 FilterNotifier.triggerListeners("subscription.removed", subscription); |
| 152 return; | 155 return; |
| 153 } | 156 } |
| 154 } | 157 } |
| 155 }, | 158 }, |
| 156 | 159 |
| 157 /** | 160 /** |
| 158 * Moves a subscription in the list to a new position. | 161 * Moves a subscription in the list to a new position. |
| 159 * @param {Subscription} subscription filter subscription to be moved | 162 * @param {Subscription} subscription filter subscription to be moved |
| 160 * @param {Subscription} [insertBefore] filter subscription to insert before | 163 * @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. | 364 * forgetting this callback. |
| 362 */ | 365 */ |
| 363 importData(silent) | 366 importData(silent) |
| 364 { | 367 { |
| 365 let parser = new INIParser(); | 368 let parser = new INIParser(); |
| 366 return line => | 369 return line => |
| 367 { | 370 { |
| 368 parser.process(line); | 371 parser.process(line); |
| 369 if (line === null) | 372 if (line === null) |
| 370 { | 373 { |
| 371 let knownSubscriptions = Object.create(null); | 374 let knownSubscriptions = new Map(); |
| 372 for (let subscription of parser.subscriptions) | 375 for (let subscription of parser.subscriptions) |
| 373 knownSubscriptions[subscription.url] = subscription; | 376 knownSubscriptions.set(subscription.url, subscription); |
| 374 | 377 |
| 375 this.fileProperties = parser.fileProperties; | 378 this.fileProperties = parser.fileProperties; |
| 376 this.subscriptions = parser.subscriptions; | 379 this.subscriptions = parser.subscriptions; |
| 377 this.knownSubscriptions = knownSubscriptions; | 380 this.knownSubscriptions = knownSubscriptions; |
| 378 Filter.knownFilters = parser.knownFilters; | 381 Filter.knownFilters = parser.knownFilters; |
| 379 Subscription.knownSubscriptions = parser.knownSubscriptions; | 382 Subscription.knownSubscriptions = parser.knownSubscriptions; |
| 380 | 383 |
| 381 if (!silent) | 384 if (!silent) |
| 382 FilterNotifier.triggerListeners("load"); | 385 FilterNotifier.triggerListeners("load"); |
| 383 } | 386 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 } | 654 } |
| 652 }; | 655 }; |
| 653 | 656 |
| 654 /** | 657 /** |
| 655 * Joins subscription's filters to the subscription without any notifications. | 658 * Joins subscription's filters to the subscription without any notifications. |
| 656 * @param {Subscription} subscription | 659 * @param {Subscription} subscription |
| 657 * filter subscription that should be connected to its filters | 660 * filter subscription that should be connected to its filters |
| 658 */ | 661 */ |
| 659 function addSubscriptionFilters(subscription) | 662 function addSubscriptionFilters(subscription) |
| 660 { | 663 { |
| 661 if (!(subscription.url in FilterStorage.knownSubscriptions)) | 664 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
| 662 return; | 665 return; |
| 663 | 666 |
| 664 for (let filter of subscription.filters) | 667 for (let filter of subscription.filters) |
| 665 filter.subscriptions.push(subscription); | 668 filter.subscriptions.push(subscription); |
| 666 } | 669 } |
| 667 | 670 |
| 668 /** | 671 /** |
| 669 * Removes subscription's filters from the subscription without any | 672 * Removes subscription's filters from the subscription without any |
| 670 * notifications. | 673 * notifications. |
| 671 * @param {Subscription} subscription filter subscription to be removed | 674 * @param {Subscription} subscription filter subscription to be removed |
| 672 */ | 675 */ |
| 673 function removeSubscriptionFilters(subscription) | 676 function removeSubscriptionFilters(subscription) |
| 674 { | 677 { |
| 675 if (!(subscription.url in FilterStorage.knownSubscriptions)) | 678 if (!FilterStorage.knownSubscriptions.has(subscription.url)) |
| 676 return; | 679 return; |
| 677 | 680 |
| 678 for (let filter of subscription.filters) | 681 for (let filter of subscription.filters) |
| 679 { | 682 { |
| 680 let i = filter.subscriptions.indexOf(subscription); | 683 let i = filter.subscriptions.indexOf(subscription); |
| 681 if (i >= 0) | 684 if (i >= 0) |
| 682 filter.subscriptions.splice(i, 1); | 685 filter.subscriptions.splice(i, 1); |
| 683 } | 686 } |
| 684 } | 687 } |
| 685 | 688 |
| 686 /** | 689 /** |
| 687 * Listener returned by FilterStorage.importData(), parses filter data. | 690 * Listener returned by FilterStorage.importData(), parses filter data. |
| 688 * @constructor | 691 * @constructor |
| 689 */ | 692 */ |
| 690 function INIParser() | 693 function INIParser() |
| 691 { | 694 { |
| 692 this.fileProperties = this.curObj = {}; | 695 this.fileProperties = this.curObj = {}; |
| 693 this.subscriptions = []; | 696 this.subscriptions = []; |
| 694 this.knownFilters = new Map(); | 697 this.knownFilters = new Map(); |
| 695 this.knownSubscriptions = Object.create(null); | 698 this.knownSubscriptions = new Map(); |
| 696 } | 699 } |
| 697 INIParser.prototype = | 700 INIParser.prototype = |
| 698 { | 701 { |
| 699 linesProcessed: 0, | 702 linesProcessed: 0, |
| 700 subscriptions: null, | 703 subscriptions: null, |
| 701 knownFilters: null, | 704 knownFilters: null, |
| 702 knownSubscriptions: null, | 705 knownSubscriptions: null, |
| 703 wantObj: true, | 706 wantObj: true, |
| 704 fileProperties: null, | 707 fileProperties: null, |
| 705 curObj: null, | 708 curObj: null, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 else if (this.wantObj === false && val) | 776 else if (this.wantObj === false && val) |
| 774 this.curObj.push(val.replace(/\\\[/g, "[")); | 777 this.curObj.push(val.replace(/\\\[/g, "[")); |
| 775 } | 778 } |
| 776 finally | 779 finally |
| 777 { | 780 { |
| 778 Filter.knownFilters = origKnownFilters; | 781 Filter.knownFilters = origKnownFilters; |
| 779 Subscription.knownSubscriptions = origKnownSubscriptions; | 782 Subscription.knownSubscriptions = origKnownSubscriptions; |
| 780 } | 783 } |
| 781 } | 784 } |
| 782 }; | 785 }; |
| OLD | NEW |