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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 * Map containing domains that this filter should match on/not match | 450 * Map containing domains that this filter should match on/not match |
451 * on or null if the filter should match on all domains | 451 * on or null if the filter should match on all domains |
452 * @type {?Map.<string,boolean>} | 452 * @type {?Map.<string,boolean>} |
453 */ | 453 */ |
454 get domains() | 454 get domains() |
455 { | 455 { |
456 let domains = null; | 456 let domains = null; |
457 | 457 |
458 if (this.domainSource) | 458 if (this.domainSource) |
459 { | 459 { |
| 460 // For some filter types this property is accessed only rarely, |
| 461 // especially when the subscriptions are initially loaded. We defer any |
| 462 // caching for such filters. |
| 463 let cacheValue = this.shouldCacheDomains(); |
| 464 |
460 let source = this.domainSource.toLowerCase(); | 465 let source = this.domainSource.toLowerCase(); |
461 | 466 |
462 let knownMap = knownDomainMaps.get(source); | 467 let knownMap = knownDomainMaps.get(source); |
463 if (knownMap) | 468 if (knownMap) |
464 { | 469 { |
465 domains = knownMap; | 470 domains = knownMap; |
466 } | 471 } |
467 else | 472 else |
468 { | 473 { |
469 let list = source.split(this.domainSeparator); | 474 let list = source.split(this.domainSeparator); |
(...skipping 26 matching lines...) Expand all Loading... |
496 if (!domains) | 501 if (!domains) |
497 domains = new Map(); | 502 domains = new Map(); |
498 | 503 |
499 domains.set(domain, include); | 504 domains.set(domain, include); |
500 } | 505 } |
501 | 506 |
502 if (domains) | 507 if (domains) |
503 domains.set("", !hasIncludes); | 508 domains.set("", !hasIncludes); |
504 } | 509 } |
505 | 510 |
506 if (domains) | 511 if (!domains || cacheValue) |
507 knownDomainMaps.set(source, domains); | 512 knownDomainMaps.set(source, domains); |
508 } | 513 } |
509 | 514 |
510 this.domainSource = null; | 515 if (!domains || cacheValue) |
| 516 { |
| 517 this.domainSource = null; |
| 518 Object.defineProperty(this, "domains", {value: domains}); |
| 519 } |
511 } | 520 } |
512 | 521 |
513 Object.defineProperty(this, "domains", {value: domains}); | 522 return domains; |
514 return this.domains; | 523 }, |
| 524 |
| 525 /** |
| 526 * Whether the value of {@link ActiveFilter#domains} should be cached. This |
| 527 * is meant to be overridden by subclasses that don't want the value to be |
| 528 * cached (for better memory usage). |
| 529 * @return {boolean} Always <code>true</code>, but may be overriden by |
| 530 * subclasses. |
| 531 * @protected |
| 532 */ |
| 533 shouldCacheDomains() |
| 534 { |
| 535 return true; |
515 }, | 536 }, |
516 | 537 |
517 /** | 538 /** |
518 * Array containing public keys of websites that this filter should apply to | 539 * Array containing public keys of websites that this filter should apply to |
519 * @type {?string[]} | 540 * @type {?string[]} |
520 */ | 541 */ |
521 sitekeys: null, | 542 sitekeys: null, |
522 | 543 |
523 /** | 544 /** |
524 * Checks whether this filter is active on a domain. | 545 * Checks whether this filter is active on a domain. |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 * @augments ContentFilter | 1168 * @augments ContentFilter |
1148 */ | 1169 */ |
1149 function ElemHideBase(text, domains, selector) | 1170 function ElemHideBase(text, domains, selector) |
1150 { | 1171 { |
1151 ContentFilter.call(this, text, domains, selector); | 1172 ContentFilter.call(this, text, domains, selector); |
1152 } | 1173 } |
1153 exports.ElemHideBase = ElemHideBase; | 1174 exports.ElemHideBase = ElemHideBase; |
1154 | 1175 |
1155 ElemHideBase.prototype = extend(ContentFilter, { | 1176 ElemHideBase.prototype = extend(ContentFilter, { |
1156 /** | 1177 /** |
| 1178 * Whether {@link ActiveFilter#domains} has been accessed at least once. |
| 1179 * @type {boolean} |
| 1180 * @private |
| 1181 */ |
| 1182 _domainsAccessed: false, |
| 1183 |
| 1184 /** |
| 1185 * See ActiveFilter.domains |
| 1186 * @inheritdoc |
| 1187 */ |
| 1188 get domains() |
| 1189 { |
| 1190 let {get} = Object.getOwnPropertyDescriptor(ActiveFilter.prototype, |
| 1191 "domains"); |
| 1192 let value = get.call(this); |
| 1193 this._domainsAccessed = true; |
| 1194 return value; |
| 1195 }, |
| 1196 |
| 1197 /** |
| 1198 * See ActiveFilter.shouldCacheDomains() |
| 1199 * @inheritdoc |
| 1200 */ |
| 1201 shouldCacheDomains() |
| 1202 { |
| 1203 return this._domainsAccessed; |
| 1204 }, |
| 1205 |
| 1206 /** |
1157 * CSS selector for the HTML elements that should be hidden | 1207 * CSS selector for the HTML elements that should be hidden |
1158 * @type {string} | 1208 * @type {string} |
1159 */ | 1209 */ |
1160 get selector() | 1210 get selector() |
1161 { | 1211 { |
1162 // Braces are being escaped to prevent CSS rule injection. | 1212 // Braces are being escaped to prevent CSS rule injection. |
1163 return this.body.replace("{", "\\7B ").replace("}", "\\7D "); | 1213 return this.body.replace("{", "\\7B ").replace("}", "\\7D "); |
1164 } | 1214 } |
1165 }); | 1215 }); |
1166 | 1216 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1287 |
1238 /** | 1288 /** |
1239 * Script that should be executed | 1289 * Script that should be executed |
1240 * @type {string} | 1290 * @type {string} |
1241 */ | 1291 */ |
1242 get script() | 1292 get script() |
1243 { | 1293 { |
1244 return this.body; | 1294 return this.body; |
1245 } | 1295 } |
1246 }); | 1296 }); |
OLD | NEW |