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

Side by Side Diff: include.preload.js

Issue 29894564: Issue 6999 - Remove inlineEmulated flag in content.applyFilters (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Sept. 28, 2018, 11:44 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 | « no previous file | lib/contentFiltering.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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 this.observer.disconnect(); 392 this.observer.disconnect();
393 clearTimeout(this.timeout); 393 clearTimeout(this.timeout);
394 } 394 }
395 }; 395 };
396 396
397 function ContentFiltering() 397 function ContentFiltering()
398 { 398 {
399 this.styles = new Map(); 399 this.styles = new Map();
400 this.tracer = null; 400 this.tracer = null;
401 this.inline = true; 401 this.inline = true;
402 this.inlineEmulated = true;
403 402
404 this.elemHideEmulation = new ElemHideEmulation( 403 this.elemHideEmulation = new ElemHideEmulation(
405 this.addSelectors.bind(this), 404 () => {},
406 this.hideElements.bind(this) 405 this.hideElements.bind(this)
407 ); 406 );
408 } 407 }
409 ContentFiltering.prototype = { 408 ContentFiltering.prototype = {
410 selectorGroupSize: 1024, 409 selectorGroupSize: 1024,
411 410
412 addSelectorsInline(selectors, groupName, appendOnly = false) 411 addSelectorsInline(selectors, groupName, appendOnly = false)
413 { 412 {
414 let style = this.styles.get(groupName); 413 let style = this.styles.get(groupName);
415 414
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 for (let i = 0; i < selectors.length; i += this.selectorGroupSize) 454 for (let i = 0; i < selectors.length; i += this.selectorGroupSize)
456 { 455 {
457 let selector = selectors.slice(i, i + this.selectorGroupSize).join(", "); 456 let selector = selectors.slice(i, i + this.selectorGroupSize).join(", ");
458 style.sheet.insertRule(selector + "{display: none !important;}", 457 style.sheet.insertRule(selector + "{display: none !important;}",
459 style.sheet.cssRules.length); 458 style.sheet.cssRules.length);
460 } 459 }
461 }, 460 },
462 461
463 addSelectors(selectors, filters, groupName = "emulated", appendOnly = false) 462 addSelectors(selectors, filters, groupName = "emulated", appendOnly = false)
464 { 463 {
465 if (this.inline || this.inlineEmulated) 464 if (this.inline)
466 { 465 {
467 // Insert the style rules inline if we have been instructed by the 466 // Insert the style rules inline if we have been instructed by the
468 // background page to do so. This is usually the case, except on platforms 467 // background page to do so. This is usually the case, except on platforms
469 // that do support user stylesheets via the browser.tabs.insertCSS API 468 // that do support user stylesheets via the browser.tabs.insertCSS API
470 // (Firefox 53 onwards for now and possibly Chrome in the near future). 469 // (Firefox 53 onwards for now and possibly Chrome in the near future).
471 // Once all supported platforms have implemented this API, we can remove 470 // Once all supported platforms have implemented this API, we can remove
472 // the code below. See issue #5090. 471 // the code below. See issue #5090.
473 // Related Chrome and Firefox issues: 472 // Related Chrome and Firefox issues:
474 // https://bugs.chromium.org/p/chromium/issues/detail?id=632009 473 // https://bugs.chromium.org/p/chromium/issues/detail?id=632009
475 // https://bugzilla.mozilla.org/show_bug.cgi?id=1310026 474 // https://bugzilla.mozilla.org/show_bug.cgi?id=1310026
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 response => 514 response =>
516 { 515 {
517 if (this.tracer) 516 if (this.tracer)
518 this.tracer.disconnect(); 517 this.tracer.disconnect();
519 this.tracer = null; 518 this.tracer = null;
520 519
521 if (response.trace) 520 if (response.trace)
522 this.tracer = new ElementHidingTracer(); 521 this.tracer = new ElementHidingTracer();
523 522
524 this.inline = response.inline; 523 this.inline = response.inline;
525 this.inlineEmulated = !!response.inlineEmulated;
526 524
527 if (this.inline) 525 if (this.inline)
528 this.addSelectorsInline(response.selectors, "standard"); 526 this.addSelectorsInline(response.selectors, "standard");
529 527
530 if (this.tracer) 528 if (this.tracer)
531 this.tracer.addSelectors(response.selectors); 529 this.tracer.addSelectors(response.selectors);
532 530
533 // Prefer CSS selectors for -abp-has and -abp-contains unless the
534 // background page has asked us to use inline styles.
535 this.elemHideEmulation.useInlineStyles = this.inline ||
536 this.inlineEmulated;
537
538 this.elemHideEmulation.apply(response.emulatedPatterns); 531 this.elemHideEmulation.apply(response.emulatedPatterns);
539 }); 532 });
540 } 533 }
541 }; 534 };
542 535
543 if (document instanceof HTMLDocument) 536 if (document instanceof HTMLDocument)
544 { 537 {
545 checkSitekey(); 538 checkSitekey();
546 539
547 contentFiltering = new ContentFiltering(); 540 contentFiltering = new ContentFiltering();
548 contentFiltering.apply(); 541 contentFiltering.apply();
549 542
550 document.addEventListener("error", event => 543 document.addEventListener("error", event =>
551 { 544 {
552 checkCollapse(event.target); 545 checkCollapse(event.target);
553 }, true); 546 }, true);
554 547
555 document.addEventListener("load", event => 548 document.addEventListener("load", event =>
556 { 549 {
557 let element = event.target; 550 let element = event.target;
558 if (/^i?frame$/.test(element.localName)) 551 if (/^i?frame$/.test(element.localName))
559 checkCollapse(element); 552 checkCollapse(element);
560 }, true); 553 }, true);
561 } 554 }
562 555
563 window.checkCollapse = checkCollapse; 556 window.checkCollapse = checkCollapse;
564 window.contentFiltering = contentFiltering; 557 window.contentFiltering = contentFiltering;
565 window.typeMap = typeMap; 558 window.typeMap = typeMap;
566 window.getURLsFromElement = getURLsFromElement; 559 window.getURLsFromElement = getURLsFromElement;
OLDNEW
« no previous file with comments | « no previous file | lib/contentFiltering.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld