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

Delta Between Two Patch Sets: chrome/content/elemHideEmulation.js

Issue 29464708: Issue 5314 - Allow hide emulation filters to be with a plain selector (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created June 14, 2017, 3:18 a.m.
Right Patch Set: Updated the logic Created June 19, 2017, 1:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/filterClasses.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 }; 190 };
191 191
192 const incompletePrefixRegexp = /[\s>+~]$/; 192 const incompletePrefixRegexp = /[\s>+~]$/;
193 193
194 function HasSelector(selectors) 194 function HasSelector(selectors)
195 { 195 {
196 this._innerSelectors = selectors; 196 this._innerSelectors = selectors;
197 } 197 }
198 198
199 HasSelector.prototype = { 199 HasSelector.prototype = {
200 requiresHiding: true,
201
200 *getSelectors(prefix, subtree, styles) 202 *getSelectors(prefix, subtree, styles)
201 { 203 {
202 for (let element of this.getElements(prefix, subtree, styles)) 204 for (let element of this.getElements(prefix, subtree, styles))
203 yield [makeSelector(element, ""), element]; 205 yield [makeSelector(element, ""), element];
204 }, 206 },
205 207
206 /** 208 /**
207 * Generator function returning selected elements. 209 * Generator function returning selected elements.
208 * @param {string} prefix the prefix for the selector. 210 * @param {string} prefix the prefix for the selector.
209 * @param {Node} subtree the subtree we work on. 211 * @param {Node} subtree the subtree we work on.
(...skipping 27 matching lines...) Expand all
237 regexpString = propertyExpression.slice(1, -1) 239 regexpString = propertyExpression.slice(1, -1)
238 .replace("\\x7B ", "{").replace("\\x7D ", "}"); 240 .replace("\\x7B ", "{").replace("\\x7D ", "}");
239 } 241 }
240 else 242 else
241 regexpString = filterToRegExp(propertyExpression); 243 regexpString = filterToRegExp(propertyExpression);
242 244
243 this._regexp = new RegExp(regexpString, "i"); 245 this._regexp = new RegExp(regexpString, "i");
244 } 246 }
245 247
246 PropsSelector.prototype = { 248 PropsSelector.prototype = {
247 hideWithStyleSheet: true, 249 preferHideWithSelector: true,
248 250
249 *findPropsSelectors(styles, prefix, regexp) 251 *findPropsSelectors(styles, prefix, regexp)
250 { 252 {
251 for (let style of styles) 253 for (let style of styles)
252 if (regexp.test(style.style)) 254 if (regexp.test(style.style))
253 for (let subSelector of style.subSelectors) 255 for (let subSelector of style.subSelectors)
254 yield prefix + subSelector; 256 yield prefix + subSelector;
255 }, 257 },
256 258
257 *getSelectors(prefix, subtree, styles) 259 *getSelectors(prefix, subtree, styles)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 let selectors = []; 303 let selectors = [];
302 if (match.index > 0) 304 if (match.index > 0)
303 selectors.push(new PlainSelector(selector.substr(0, match.index))); 305 selectors.push(new PlainSelector(selector.substr(0, match.index)));
304 306
305 let startIndex = match.index + match[0].length; 307 let startIndex = match.index + match[0].length;
306 let content = parseSelectorContent(selector, startIndex); 308 let content = parseSelectorContent(selector, startIndex);
307 if (!content) 309 if (!content)
308 { 310 {
309 this.window.console.error( 311 this.window.console.error(
310 new SyntaxError("Failed to parse Adblock Plus " + 312 new SyntaxError("Failed to parse Adblock Plus " +
311 `selector ${selector}, ` + 313 `selector ${selector} ` +
312 "due to unmatched parentheses.")); 314 "due to unmatched parentheses."));
313 return null; 315 return null;
314 } 316 }
315 if (match[1] == "properties") 317 if (match[1] == "properties")
316 selectors.push(new PropsSelector(content.text)); 318 selectors.push(new PropsSelector(content.text));
317 else if (match[1] == "has") 319 else if (match[1] == "has")
318 { 320 {
319 let hasSelectors = this.parseSelector(content.text); 321 let hasSelectors = this.parseSelector(content.text);
320 if (hasSelectors == null) 322 if (hasSelectors == null)
321 return null; 323 return null;
322 let hasSelector = new HasSelector(hasSelectors); 324 selectors.push(new HasSelector(hasSelectors));
323 selectors.push(hasSelector);
324 } 325 }
325 else 326 else
326 { 327 {
327 // this is an error, can't parse selector. 328 // this is an error, can't parse selector.
328 this.window.console.error( 329 this.window.console.error(
329 new SyntaxError("Failed to parse Adblock Plus " + 330 new SyntaxError("Failed to parse Adblock Plus " +
330 `selector ${selector}, invalid ` + 331 `selector ${selector}, invalid ` +
331 `pseudo-class :-abp-${match[1]}().`)); 332 `pseudo-class :-abp-${match[1]}().`));
332 return null; 333 return null;
333 } 334 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 cssStyles.push(stringifyStyle(rule)); 371 cssStyles.push(stringifyStyle(rule));
371 } 372 }
372 } 373 }
373 374
374 let {document} = this.window; 375 let {document} = this.window;
375 for (let pattern of this.patterns) 376 for (let pattern of this.patterns)
376 { 377 {
377 for (let selector of evaluate(pattern.selectors, 378 for (let selector of evaluate(pattern.selectors,
378 0, "", document, cssStyles)) 379 0, "", document, cssStyles))
379 { 380 {
380 if (pattern.selectors.some(s => s.hideWithStyleSheet)) 381 if (pattern.selectors.some(s => s.preferHideWithSelector) &&
Wladimir Palant 2017/06/19 08:28:32 This logic reversal is wrong - any filter containi
hub 2017/06/19 13:37:15 Done.
382 !pattern.selectors.some(s => s.requiresHiding))
381 { 383 {
382 selectors.push(selector); 384 selectors.push(selector);
383 selectorFilters.push(pattern.text); 385 selectorFilters.push(pattern.text);
384 } 386 }
385 else 387 else
386 { 388 {
387 for (let element of document.querySelectorAll(selector)) 389 for (let element of document.querySelectorAll(selector))
388 { 390 {
389 elements.push(element); 391 elements.push(element);
390 elementFilters.push(pattern.text); 392 elementFilters.push(pattern.text);
(...skipping 27 matching lines...) Expand all
418 420
419 if (this.patterns.length > 0) 421 if (this.patterns.length > 0)
420 { 422 {
421 let {document} = this.window; 423 let {document} = this.window;
422 this.addSelectors(document.styleSheets); 424 this.addSelectors(document.styleSheets);
423 document.addEventListener("load", this.onLoad.bind(this), true); 425 document.addEventListener("load", this.onLoad.bind(this), true);
424 } 426 }
425 }); 427 });
426 } 428 }
427 }; 429 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld