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

Side by Side Diff: include.preload.js

Issue 29367475: Issue 4659 - Incorporate element hiding emulation filters (Closed) Base URL: https://bitbucket.org/fhd/adblockpluschrome
Patch Set: Update adblockplusui dependency and combine common.js and elemHideEmulation.js content scripts Created Dec. 20, 2016, 2:30 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 | « dependencies ('k') | metadata.common » ('j') | metadata.common » ('J')
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 RealWebSocket.prototype.constructor = WebSocket; 423 RealWebSocket.prototype.constructor = WebSocket;
424 }, eventName); 424 }, eventName);
425 } 425 }
426 426
427 function ElemHide() 427 function ElemHide()
428 { 428 {
429 this.shadow = this.createShadowTree(); 429 this.shadow = this.createShadowTree();
430 this.style = null; 430 this.style = null;
431 this.tracer = null; 431 this.tracer = null;
432 432
433 this.propertyFilters = new CSSPropertyFilters( 433 this.elemHideEmulation = new ElemHideEmulation(
434 window, 434 window,
435 function(callback) 435 function(callback)
436 { 436 {
437 ext.backgroundPage.sendMessage({ 437 ext.backgroundPage.sendMessage({
438 type: "filters.get", 438 type: "filters.get",
439 what: "cssproperties" 439 what: "elemhideemulation"
440 }, callback); 440 }, callback);
441 }, 441 },
442 this.addSelectors.bind(this) 442 this.addSelectors.bind(this)
443 ); 443 );
444 } 444 }
445 ElemHide.prototype = { 445 ElemHide.prototype = {
446 selectorGroupSize: 200, 446 selectorGroupSize: 200,
447 447
448 createShadowTree: function() 448 createShadowTree: function()
449 { 449 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 { 537 {
538 var selector = selectors.slice(i, i + this.selectorGroupSize).join(", "); 538 var selector = selectors.slice(i, i + this.selectorGroupSize).join(", ");
539 this.style.sheet.insertRule(selector + "{display: none !important;}", 539 this.style.sheet.insertRule(selector + "{display: none !important;}",
540 this.style.sheet.cssRules.length); 540 this.style.sheet.cssRules.length);
541 } 541 }
542 }, 542 },
543 543
544 apply: function() 544 apply: function()
545 { 545 {
546 var selectors = null; 546 var selectors = null;
547 var propertyFiltersLoaded = false; 547 var elemHideEmulationLoaded = false;
548 548
549 var checkLoaded = function() 549 var checkLoaded = function()
550 { 550 {
551 if (!selectors || !propertyFiltersLoaded) 551 if (!selectors || !elemHideEmulationLoaded)
552 return; 552 return;
553 553
554 if (this.tracer) 554 if (this.tracer)
555 this.tracer.disconnect(); 555 this.tracer.disconnect();
556 this.tracer = null; 556 this.tracer = null;
557 557
558 if (this.style && this.style.parentElement) 558 if (this.style && this.style.parentElement)
559 this.style.parentElement.removeChild(this.style); 559 this.style.parentElement.removeChild(this.style);
560 this.style = null; 560 this.style = null;
561 561
562 this.addSelectors(selectors.selectors); 562 this.addSelectors(selectors.selectors);
563 this.propertyFilters.apply(); 563 this.elemHideEmulation.apply();
564 564
565 if (selectors.trace) 565 if (selectors.trace)
566 this.tracer = new ElementHidingTracer(selectors.selectors); 566 this.tracer = new ElementHidingTracer(selectors.selectors);
567 }.bind(this); 567 }.bind(this);
568 568
569 ext.backgroundPage.sendMessage({type: "get-selectors"}, function(response) 569 ext.backgroundPage.sendMessage({type: "get-selectors"}, function(response)
570 { 570 {
571 selectors = response; 571 selectors = response;
572 checkLoaded(); 572 checkLoaded();
573 }); 573 });
574 574
575 this.propertyFilters.load(function() 575 this.elemHideEmulation.load(function()
576 { 576 {
577 propertyFiltersLoaded = true; 577 elemHideEmulationLoaded = true;
578 checkLoaded(); 578 checkLoaded();
579 }); 579 });
580 } 580 }
581 }; 581 };
582 582
583 if (document instanceof HTMLDocument) 583 if (document instanceof HTMLDocument)
584 { 584 {
585 checkSitekey(); 585 checkSitekey();
586 wrapWebSocket(); 586 wrapWebSocket();
587 587
588 var elemhide = new ElemHide(); 588 var elemhide = new ElemHide();
589 elemhide.apply(); 589 elemhide.apply();
590 590
591 document.addEventListener("error", function(event) 591 document.addEventListener("error", function(event)
592 { 592 {
593 checkCollapse(event.target); 593 checkCollapse(event.target);
594 }, true); 594 }, true);
595 595
596 document.addEventListener("load", function(event) 596 document.addEventListener("load", function(event)
597 { 597 {
598 var element = event.target; 598 var element = event.target;
599 if (/^i?frame$/.test(element.localName)) 599 if (/^i?frame$/.test(element.localName))
600 checkCollapse(element); 600 checkCollapse(element);
601 }, true); 601 }, true);
602 } 602 }
OLDNEW
« no previous file with comments | « dependencies ('k') | metadata.common » ('j') | metadata.common » ('J')

Powered by Google App Engine
This is Rietveld