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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 if (domains) | 126 if (domains) |
127 domains.set("", !hasIncludes); | 127 domains.set("", !hasIncludes); |
128 } | 128 } |
129 | 129 |
130 return domains; | 130 return domains; |
131 } | 131 } |
132 | 132 |
133 /** | 133 /** |
| 134 * Checks whether the given filter object should be cached in |
| 135 * <code>{@link Filter.knownFilters}</code> based on properties of the object. |
| 136 * @param {Filter} filter |
| 137 * @returns {boolean} |
| 138 */ |
| 139 function shouldCacheFilter(filter) |
| 140 { |
| 141 return !(filter instanceof ElemHideFilter); |
| 142 } |
| 143 |
| 144 /** |
134 * Abstract base class for filters | 145 * Abstract base class for filters |
135 * | 146 * |
136 * @param {string} text string representation of the filter | 147 * @param {string} text string representation of the filter |
137 * @constructor | 148 * @constructor |
138 */ | 149 */ |
139 function Filter(text) | 150 function Filter(text) |
140 { | 151 { |
141 this.text = text; | 152 this.text = text; |
142 | 153 |
143 /** | 154 /** |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 * Regular expression that matches an invalid Content Security Policy | 215 * Regular expression that matches an invalid Content Security Policy |
205 * @type {RegExp} | 216 * @type {RegExp} |
206 */ | 217 */ |
207 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad
e-insecure-requests)\b/i; | 218 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad
e-insecure-requests)\b/i; |
208 | 219 |
209 /** | 220 /** |
210 * Creates a filter of correct type from its text representation - does the | 221 * Creates a filter of correct type from its text representation - does the |
211 * basic parsing and calls the right constructor then. | 222 * basic parsing and calls the right constructor then. |
212 * | 223 * |
213 * @param {string} text as in Filter() | 224 * @param {string} text as in Filter() |
| 225 * @param {boolean} [forceCache] Whether to force-cache the filter object. |
| 226 * <em>For internal use only.<em> |
214 * @return {Filter} | 227 * @return {Filter} |
215 */ | 228 */ |
216 Filter.fromText = function(text) | 229 Filter.fromText = function(text, forceCache = true) |
217 { | 230 { |
218 let filter = Filter.knownFilters.get(text); | 231 let filter = Filter.knownFilters.get(text); |
219 if (filter) | 232 if (filter) |
220 return filter; | 233 return filter; |
221 | 234 |
222 if (text[0] == "!") | 235 if (text[0] == "!") |
223 { | 236 { |
224 filter = new CommentFilter(text); | 237 filter = new CommentFilter(text); |
225 } | 238 } |
226 else | 239 else |
227 { | 240 { |
228 let match = text.includes("#") ? Filter.contentRegExp.exec(text) : null; | 241 let match = text.includes("#") ? Filter.contentRegExp.exec(text) : null; |
229 if (match) | 242 if (match) |
230 filter = ContentFilter.fromText(text, match[1], match[2], match[3]); | 243 filter = ContentFilter.fromText(text, match[1], match[2], match[3]); |
231 else | 244 else |
232 filter = RegExpFilter.fromText(text); | 245 filter = RegExpFilter.fromText(text); |
233 } | 246 } |
234 | 247 |
235 Filter.knownFilters.set(filter.text, filter); | 248 if (forceCache || shouldCacheFilter(filter)) |
| 249 Filter.knownFilters.set(filter.text, filter); |
| 250 |
236 return filter; | 251 return filter; |
237 }; | 252 }; |
238 | 253 |
239 /** | 254 /** |
240 * Deserializes a filter | 255 * Deserializes a filter |
241 * | 256 * |
242 * @param {Object} obj map of serialized properties and their values | 257 * @param {Object} obj map of serialized properties and their values |
243 * @return {Filter} filter or null if the filter couldn't be created | 258 * @return {Filter} filter or null if the filter couldn't be created |
244 */ | 259 */ |
245 Filter.fromObject = function(obj) | 260 Filter.fromObject = function(obj) |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 | 1370 |
1356 /** | 1371 /** |
1357 * Script that should be executed | 1372 * Script that should be executed |
1358 * @type {string} | 1373 * @type {string} |
1359 */ | 1374 */ |
1360 get script() | 1375 get script() |
1361 { | 1376 { |
1362 return this.body; | 1377 return this.body; |
1363 } | 1378 } |
1364 }); | 1379 }); |
OLD | NEW |