Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/elemHideExceptions.js

Issue 29893618: Issue 6957 - Return common style sheet for unknown domains (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 27, 2018, 9:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 const {EventEmitter} = require("./events"); 24 const {EventEmitter} = require("./events");
25 const {filterNotifier} = require("./filterNotifier"); 25 const {filterNotifier} = require("./filterNotifier");
26 26
27 /** 27 /**
28 * Lookup table, lists of element hiding exceptions by selector 28 * Lookup table, lists of element hiding exceptions by selector
29 * @type {Map.<string,ElemHideException[]>} 29 * @type {Map.<string,ElemHideException[]>}
30 */ 30 */
31 let exceptions = new Map(); 31 let exceptions = new Map();
32 32
33 /** 33 /**
34 * Set containing all known domains
35 * @type {Set.<string>}
36 */
37 let knownDomains = new Set();
38
39 /**
34 * Set containing known element exceptions 40 * Set containing known element exceptions
35 * @type {Set.<ElemHideException>} 41 * @type {Set.<ElemHideException>}
36 */ 42 */
37 let knownExceptions = new Set(); 43 let knownExceptions = new Set();
38 44
39 /** 45 /**
40 * Container for element hiding exceptions 46 * Container for element hiding exceptions
41 * @class 47 * @class
42 */ 48 */
43 exports.ElemHideExceptions = Object.assign(Object.create(new EventEmitter()), { 49 exports.ElemHideExceptions = Object.assign(Object.create(new EventEmitter()), {
(...skipping 10 matching lines...) Expand all
54 60
55 /** 61 /**
56 * Add a new element hiding exception 62 * Add a new element hiding exception
57 * @param {ElemHideException} exception 63 * @param {ElemHideException} exception
58 */ 64 */
59 add(exception) 65 add(exception)
60 { 66 {
61 if (knownExceptions.has(exception)) 67 if (knownExceptions.has(exception))
62 return; 68 return;
63 69
64 let {selector} = exception; 70 let {domains, selector} = exception;
71
72 if (domains)
73 {
74 for (let domain of domains.keys())
75 {
76 // Note: Once a domain is known it never becomes unknown, even when all
77 // the filters containing that domain are removed. This is a best-case
78 // optimization.
79 if (domain != "")
80 knownDomains.add(domain);
81 }
82 }
83
65 let list = exceptions.get(selector); 84 let list = exceptions.get(selector);
66 if (list) 85 if (list)
67 list.push(exception); 86 list.push(exception);
68 else 87 else
69 exceptions.set(selector, [exception]); 88 exceptions.set(selector, [exception]);
70 89
71 knownExceptions.add(exception); 90 knownExceptions.add(exception);
72 91
73 this.emit("added", exception); 92 this.emit("added", exception);
74 93
(...skipping 15 matching lines...) Expand all
90 list.splice(index, 1); 109 list.splice(index, 1);
91 110
92 knownExceptions.delete(exception); 111 knownExceptions.delete(exception);
93 112
94 this.emit("removed", exception); 113 this.emit("removed", exception);
95 114
96 filterNotifier.emit("elemhideupdate"); 115 filterNotifier.emit("elemhideupdate");
97 }, 116 },
98 117
99 /** 118 /**
119 * Checks whether a given domain is known.
120 * @param {string} domain
121 * @returns {boolean}
122 */
123 isKnownDomain(domain)
124 {
125 return knownDomains.has(domain);
126 },
127
128 /**
100 * Checks whether any exception rules are registered for a selector 129 * Checks whether any exception rules are registered for a selector
101 * @param {string} selector 130 * @param {string} selector
102 * @returns {boolean} 131 * @returns {boolean}
103 */ 132 */
104 hasExceptions(selector) 133 hasExceptions(selector)
105 { 134 {
106 return exceptions.has(selector); 135 return exceptions.has(selector);
107 }, 136 },
108 137
109 /** 138 /**
(...skipping 11 matching lines...) Expand all
121 150
122 for (let i = list.length - 1; i >= 0; i--) 151 for (let i = list.length - 1; i >= 0; i--)
123 { 152 {
124 if (list[i].isActiveOnDomain(docDomain)) 153 if (list[i].isActiveOnDomain(docDomain))
125 return list[i]; 154 return list[i];
126 } 155 }
127 156
128 return null; 157 return null;
129 } 158 }
130 }); 159 });
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld