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

Side by Side Diff: lib/filterClasses.js

Issue 29945631: Issue 7097 - Make element hiding filter objects ephemeral Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Simplify Created Nov. 18, 2018, 6:12 a.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') | lib/iniParser.js » ('j') | 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 /** 74 /**
75 * Filter type as a string, e.g. "blocking". 75 * Filter type as a string, e.g. "blocking".
76 * @type {string} 76 * @type {string}
77 */ 77 */
78 get type() 78 get type()
79 { 79 {
80 throw new Error("Please define filter type in the subclass"); 80 throw new Error("Please define filter type in the subclass");
81 }, 81 },
82 82
83 /** 83 /**
84 * Whether this object is discarded after use. If <code>false</code>, the
85 * object is retained in memory once created and every call to
86 * {@link Filter#fromText} returns the same instance. Defaults to
87 * <code>false</code>.
88 * @type {boolean}
89 * @package
90 */
91 ephemeral: false,
92
93 /**
84 * Subscriptions to which this filter belongs. 94 * Subscriptions to which this filter belongs.
85 * @type {?(Subscription|Set.<Subscription>)} 95 * @type {?(Subscription|Set.<Subscription>)}
86 * @private 96 * @private
87 */ 97 */
88 _subscriptions: null, 98 _subscriptions: null,
89 99
90 /** 100 /**
91 * Whether the filter's subscriptions have already been added to the filter. 101 * Whether the filter's subscriptions have already been added to the filter.
92 * @type {boolean} 102 * @type {boolean}
93 * @package 103 * @package
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 * Regular expression that matches an invalid Content Security Policy 231 * Regular expression that matches an invalid Content Security Policy
222 * @type {RegExp} 232 * @type {RegExp}
223 */ 233 */
224 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i; 234 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i;
225 235
226 /** 236 /**
227 * Creates a filter of correct type from its text representation - does the 237 * Creates a filter of correct type from its text representation - does the
228 * basic parsing and calls the right constructor then. 238 * basic parsing and calls the right constructor then.
229 * 239 *
230 * @param {string} text as in Filter() 240 * @param {string} text as in Filter()
241 * @param {boolean} persistent Whether the filter object should be persisted in
242 * memory.
231 * @return {Filter} 243 * @return {Filter}
232 */ 244 */
233 Filter.fromText = function(text) 245 Filter.fromText = function(text, persistent = true)
Manish Jethani 2018/11/18 06:19:14 The idea here is that internally we'll always pass
234 { 246 {
235 let filter = Filter.knownFilters.get(text); 247 let filter = Filter.knownFilters.get(text);
236 if (filter) 248 if (filter)
237 return filter; 249 return filter;
238 250
239 if (text[0] == "!") 251 if (text[0] == "!")
240 { 252 {
241 filter = new CommentFilter(text); 253 filter = new CommentFilter(text);
242 } 254 }
243 else 255 else
244 { 256 {
245 let match = text.includes("#") ? Filter.contentRegExp.exec(text) : null; 257 let match = text.includes("#") ? Filter.contentRegExp.exec(text) : null;
246 if (match) 258 if (match)
247 filter = ContentFilter.fromText(text, match[1], match[2], match[3]); 259 filter = ContentFilter.fromText(text, match[1], match[2], match[3]);
248 else 260 else
249 filter = RegExpFilter.fromText(text); 261 filter = RegExpFilter.fromText(text);
250 } 262 }
251 263
252 Filter.knownFilters.set(filter.text, filter); 264 if (persistent)
265 filter.ephemeral = false;
266
267 if (!filter.ephemeral)
268 Filter.knownFilters.set(filter.text, filter);
269
253 return filter; 270 return filter;
254 }; 271 };
255 272
256 /** 273 /**
257 * Deserializes a filter 274 * Deserializes a filter
258 * 275 *
259 * @param {Object} obj map of serialized properties and their values 276 * @param {Object} obj map of serialized properties and their values
260 * @return {Filter} filter or null if the filter couldn't be created 277 * @return {Filter} filter or null if the filter couldn't be created
261 */ 278 */
262 Filter.fromObject = function(obj) 279 Filter.fromObject = function(obj)
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 * @constructor 1326 * @constructor
1310 * @augments ElemHideBase 1327 * @augments ElemHideBase
1311 */ 1328 */
1312 function ElemHideFilter(text, domains, selector) 1329 function ElemHideFilter(text, domains, selector)
1313 { 1330 {
1314 ElemHideBase.call(this, text, domains, selector); 1331 ElemHideBase.call(this, text, domains, selector);
1315 } 1332 }
1316 exports.ElemHideFilter = ElemHideFilter; 1333 exports.ElemHideFilter = ElemHideFilter;
1317 1334
1318 ElemHideFilter.prototype = extend(ElemHideBase, { 1335 ElemHideFilter.prototype = extend(ElemHideBase, {
1319 type: "elemhide" 1336 type: "elemhide",
1337
1338 /**
1339 * See Filter.ephemeral
1340 * @inheritdoc
1341 */
1342 ephemeral: true
1320 }); 1343 });
1321 1344
1322 /** 1345 /**
1323 * Class for element hiding exceptions 1346 * Class for element hiding exceptions
1324 * @param {string} text see {@link Filter Filter()} 1347 * @param {string} text see {@link Filter Filter()}
1325 * @param {string} [domains] see {@link ElemHideBase ElemHideBase()} 1348 * @param {string} [domains] see {@link ElemHideBase ElemHideBase()}
1326 * @param {string} selector see {@link ElemHideBase ElemHideBase()} 1349 * @param {string} selector see {@link ElemHideBase ElemHideBase()}
1327 * @constructor 1350 * @constructor
1328 * @augments ElemHideBase 1351 * @augments ElemHideBase
1329 */ 1352 */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 1397
1375 /** 1398 /**
1376 * Script that should be executed 1399 * Script that should be executed
1377 * @type {string} 1400 * @type {string}
1378 */ 1401 */
1379 get script() 1402 get script()
1380 { 1403 {
1381 return this.body; 1404 return this.body;
1382 } 1405 }
1383 }); 1406 });
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | lib/iniParser.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld