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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 */ | 52 */ |
53 let exceptions = Object.create(null); | 53 let exceptions = Object.create(null); |
54 | 54 |
55 /** | 55 /** |
56 * Currently applied stylesheet URL | 56 * Currently applied stylesheet URL |
57 * @type nsIURI | 57 * @type nsIURI |
58 */ | 58 */ |
59 let styleURL = null; | 59 let styleURL = null; |
60 | 60 |
61 /** | 61 /** |
| 62 * Lookup table, blocking filters by domain which they are applied to |
| 63 * @type Object |
| 64 */ |
| 65 let filtersByDomain = Object.create(null); |
| 66 |
| 67 /** |
62 * Element hiding component | 68 * Element hiding component |
63 * @class | 69 * @class |
64 */ | 70 */ |
65 let ElemHide = exports.ElemHide = | 71 let ElemHide = exports.ElemHide = |
66 { | 72 { |
67 /** | 73 /** |
68 * Indicates whether filters have been added or removed since the last apply()
call. | 74 * Indicates whether filters have been added or removed since the last apply()
call. |
69 * @type Boolean | 75 * @type Boolean |
70 */ | 76 */ |
71 isDirty: false, | 77 isDirty: false, |
(...skipping 26 matching lines...) Expand all Loading... |
98 | 104 |
99 /** | 105 /** |
100 * Removes all known filters | 106 * Removes all known filters |
101 */ | 107 */ |
102 clear: function() | 108 clear: function() |
103 { | 109 { |
104 filterByKey = Object.create(null); | 110 filterByKey = Object.create(null); |
105 keyByFilter = Object.create(null); | 111 keyByFilter = Object.create(null); |
106 knownExceptions = Object.create(null); | 112 knownExceptions = Object.create(null); |
107 exceptions = Object.create(null); | 113 exceptions = Object.create(null); |
| 114 filtersByDomain = Object.create(null); |
108 ElemHide.isDirty = false; | 115 ElemHide.isDirty = false; |
109 ElemHide.unapply(); | 116 ElemHide.unapply(); |
110 }, | 117 }, |
111 | 118 |
112 /** | 119 /** |
113 * Add a new element hiding filter | 120 * Add a new element hiding filter |
114 * @param {ElemHideFilter} filter | 121 * @param {ElemHideFilter} filter |
115 */ | 122 */ |
116 add: function(filter) | 123 add: function(filter) |
117 { | 124 { |
118 if (filter instanceof ElemHideException) | 125 if (filter instanceof ElemHideException) |
119 { | 126 { |
120 if (filter.text in knownExceptions) | 127 if (filter.text in knownExceptions) |
121 return; | 128 return; |
122 | 129 |
123 let selector = filter.selector; | 130 let selector = filter.selector; |
124 if (!(selector in exceptions)) | 131 if (!(selector in exceptions)) |
125 exceptions[selector] = []; | 132 exceptions[selector] = []; |
126 exceptions[selector].push(filter); | 133 exceptions[selector].push(filter); |
127 knownExceptions[filter.text] = true; | 134 knownExceptions[filter.text] = true; |
128 } | 135 } |
129 else | 136 else |
130 { | 137 { |
131 if (filter.text in keyByFilter) | 138 if (filter.text in keyByFilter) |
132 return; | 139 return; |
133 | 140 |
| 141 if (!("nsIStyleSheetService" in Ci)) |
| 142 { |
| 143 let domains = filter.domains; |
| 144 if (domains === null) |
| 145 { |
| 146 domains = Object.create(null); |
| 147 domains[""] = undefined; |
| 148 } |
| 149 |
| 150 for (let domain in domains) |
| 151 { |
| 152 if (!(domain in filtersByDomain)) |
| 153 filtersByDomain[domain] = Object.create(null); |
| 154 |
| 155 filtersByDomain[domain][filter.text] = filter.isActiveOnDomain(domain)
; |
| 156 } |
| 157 } |
| 158 |
134 let key; | 159 let key; |
135 do { | 160 do { |
136 key = Math.random().toFixed(15).substr(5); | 161 key = Math.random().toFixed(15).substr(5); |
137 } while (key in filterByKey); | 162 } while (key in filterByKey); |
138 | 163 |
139 filterByKey[key] = filter; | 164 filterByKey[key] = filter; |
140 keyByFilter[filter.text] = key; | 165 keyByFilter[filter.text] = key; |
141 ElemHide.isDirty = true; | 166 ElemHide.isDirty = true; |
142 } | 167 } |
143 }, | 168 }, |
(...skipping 13 matching lines...) Expand all Loading... |
157 let index = list.indexOf(filter); | 182 let index = list.indexOf(filter); |
158 if (index >= 0) | 183 if (index >= 0) |
159 list.splice(index, 1); | 184 list.splice(index, 1); |
160 delete knownExceptions[filter.text]; | 185 delete knownExceptions[filter.text]; |
161 } | 186 } |
162 else | 187 else |
163 { | 188 { |
164 if (!(filter.text in keyByFilter)) | 189 if (!(filter.text in keyByFilter)) |
165 return; | 190 return; |
166 | 191 |
| 192 if (!("nsIStyleSheetService" in Ci)) |
| 193 { |
| 194 for (let domain in filter.domains) |
| 195 { |
| 196 if (domain in filtersByDomain && filter.text in filtersByDomain[domain
]) |
| 197 delete filtersByDomain[domain][filter.text]; |
| 198 |
| 199 if (!Object.keys(filtersByDomain[domain]).length) |
| 200 delete filtersByDomain[domain]; |
| 201 } |
| 202 } |
| 203 |
167 let key = keyByFilter[filter.text]; | 204 let key = keyByFilter[filter.text]; |
168 delete filterByKey[key]; | 205 delete filterByKey[key]; |
169 delete keyByFilter[filter.text]; | 206 delete keyByFilter[filter.text]; |
170 ElemHide.isDirty = true; | 207 ElemHide.isDirty = true; |
171 } | 208 } |
172 }, | 209 }, |
173 | 210 |
174 /** | 211 /** |
175 * Checks whether an exception rule is registered for a filter on a particular | 212 * Checks whether an exception rule is registered for a filter on a particular |
176 * domain. | 213 * domain. |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 { | 407 { |
371 return (key in filterByKey ? filterByKey[key] : null); | 408 return (key in filterByKey ? filterByKey[key] : null); |
372 }, | 409 }, |
373 | 410 |
374 /** | 411 /** |
375 * Returns a list of all selectors active on a particular domain (currently | 412 * Returns a list of all selectors active on a particular domain (currently |
376 * used only in Chrome, Opera and Safari). | 413 * used only in Chrome, Opera and Safari). |
377 */ | 414 */ |
378 getSelectorsForDomain: function(/**String*/ domain, /**Boolean*/ specificOnly) | 415 getSelectorsForDomain: function(/**String*/ domain, /**Boolean*/ specificOnly) |
379 { | 416 { |
380 let result = []; | 417 let selectors = []; |
381 for (let key in filterByKey) | 418 domain = domain.toUpperCase(); |
| 419 |
| 420 if (!specificOnly) |
382 { | 421 { |
383 let filter = filterByKey[key]; | 422 let filterTexts = filtersByDomain[""]; |
384 if (specificOnly && (!filter.domains || filter.domains[""])) | 423 if (filterTexts) |
385 continue; | 424 { |
| 425 for (let filterText in filterTexts) |
| 426 { |
| 427 if (filterTexts[filterText]) |
| 428 { |
| 429 let filter = filterByKey[keyByFilter[filterText]]; |
| 430 if (!filter) |
| 431 continue; |
| 432 |
| 433 let selector = filter.selector; |
| 434 if (filter.isActiveOnDomain(docDomain) && !this.getException(selecto
r, docDomain)) |
| 435 selectors[selectors.length] = selector; |
| 436 } |
| 437 } |
| 438 } |
| 439 } |
386 | 440 |
387 if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain)) | 441 while (true) |
388 result.push(filter.selector); | 442 { |
| 443 if (domain && domain in filtersByDomain) |
| 444 { |
| 445 let filterTexts = filtersByDomain[domain]; |
| 446 if (filterTexts) |
| 447 { |
| 448 for (let filterText in filterTexts) |
| 449 { |
| 450 if (filterTexts[filterText]) |
| 451 { |
| 452 let filter = filterByKey[keyByFilter[filterText]]; |
| 453 if (!filter) |
| 454 continue; |
| 455 |
| 456 let selector = filter.selector; |
| 457 if (!this.getException(selector, docDomain)) |
| 458 selectors[selectors.length] = selector; |
| 459 } |
| 460 } |
| 461 } |
| 462 } |
| 463 |
| 464 let nextDot = domain.indexOf("."); |
| 465 if (nextDot < 0) |
| 466 break; |
| 467 domain = domain.substr(nextDot + 1); |
389 } | 468 } |
390 return result; | 469 |
| 470 return selectors; |
391 } | 471 } |
392 }; | 472 }; |
OLD | NEW |