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

Side by Side Diff: chrome/content/elemHideEmulation.js

Issue 29490698: Issue 5422 - Properly build props selector (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased on master Created July 19, 2017, 2:35 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 | « no previous file | 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 else if (sep == "") 42 else if (sep == "")
43 { 43 {
44 if (chr == '"' || chr == "'") 44 if (chr == '"' || chr == "'")
45 sep = chr; 45 sep = chr;
46 else if (chr == "(") // don't split between parentheses 46 else if (chr == "(") // don't split between parentheses
47 level++; // e.g. :matches(div,span) 47 level++; // e.g. :matches(div,span)
48 else if (chr == ")") 48 else if (chr == ")")
49 level = Math.max(0, level - 1); 49 level = Math.max(0, level - 1);
50 else if (chr == "," && level == 0) 50 else if (chr == "," && level == 0)
51 { 51 {
52 selectors.push(selector.substring(start, i)); 52 selectors.push(selector.substring(start, i).trim());
53 start = i + 1; 53 start = i + 1;
54 } 54 }
55 } 55 }
56 } 56 }
57 57
58 selectors.push(selector.substring(start)); 58 selectors.push(selector.substring(start).trim());
59 return selectors; 59 return selectors;
60 } 60 }
61 61
62 /** Return position of node from parent. 62 /** Return position of node from parent.
63 * @param {Node} node the node to find the position of. 63 * @param {Node} node the node to find the position of.
64 * @return {number} One-based index like for :nth-child(), or 0 on error. 64 * @return {number} One-based index like for :nth-child(), or 0 on error.
65 */ 65 */
66 function positionInParent(node) 66 function positionInParent(node)
67 { 67 {
68 let {children} = node.parentNode; 68 let {children} = node.parentNode;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 regexpString = filterToRegExp(propertyExpression); 266 regexpString = filterToRegExp(propertyExpression);
267 267
268 this._regexp = new RegExp(regexpString, "i"); 268 this._regexp = new RegExp(regexpString, "i");
269 } 269 }
270 270
271 PropsSelector.prototype = { 271 PropsSelector.prototype = {
272 preferHideWithSelector: true, 272 preferHideWithSelector: true,
273 273
274 *findPropsSelectors(styles, prefix, regexp) 274 *findPropsSelectors(styles, prefix, regexp)
275 { 275 {
276 let actualPrefix = (prefix && !incompletePrefixRegexp.test(prefix)) ?
277 prefix + " " : prefix;
Wladimir Palant 2017/08/16 08:37:02 No, this is not what we want. Consider .abp-testsu
hub 2017/08/16 19:50:32 Acknowledged.
276 for (let style of styles) 278 for (let style of styles)
277 if (regexp.test(style.style)) 279 if (regexp.test(style.style))
278 for (let subSelector of style.subSelectors) 280 for (let subSelector of style.subSelectors)
279 yield prefix + subSelector; 281 {
282 if (subSelector == "*")
283 subSelector = "";
Wladimir Palant 2017/08/16 08:37:02 What if we have a filter like `:-abp-properties(fo
hub 2017/08/16 19:50:32 Done.
284 yield actualPrefix + subSelector;
285 }
280 }, 286 },
281 287
282 *getSelectors(prefix, subtree, styles) 288 *getSelectors(prefix, subtree, styles)
283 { 289 {
284 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp)) 290 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp))
285 yield [selector, subtree]; 291 yield [selector, subtree];
286 } 292 }
287 }; 293 };
288 294
289 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc, 295 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 462
457 if (this.patterns.length > 0) 463 if (this.patterns.length > 0)
458 { 464 {
459 let {document} = this.window; 465 let {document} = this.window;
460 this.addSelectors(document.styleSheets); 466 this.addSelectors(document.styleSheets);
461 document.addEventListener("load", this.onLoad.bind(this), true); 467 document.addEventListener("load", this.onLoad.bind(this), true);
462 } 468 }
463 }); 469 });
464 } 470 }
465 }; 471 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld