| Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 return element.contentDocument; | 187 return element.contentDocument; | 
| 188 } | 188 } | 
| 189 catch (e) | 189 catch (e) | 
| 190 { | 190 { | 
| 191 return null; | 191 return null; | 
| 192 } | 192 } | 
| 193 } | 193 } | 
| 194 | 194 | 
| 195 function ElementHidingTracer(selectors) | 195 function ElementHidingTracer(selectors) | 
| 196 { | 196 { | 
| 197 this.selectors = selectors; | 197 this.selectors = selectors || []; | 
| 
 
Sebastian Noack
2017/01/11 16:20:40
It seems you removed the only code that initialize
 
wspee
2017/01/12 13:39:58
No longer relevant.
 
wspee
2017/01/19 16:20:14
Done.
 
 | |
| 198 | 198 | 
| 199 this.changedNodes = []; | 199 this.changedNodes = []; | 
| 200 this.timeout = null; | 200 this.timeout = null; | 
| 201 | 201 | 
| 202 this.observer = new MutationObserver(this.observe.bind(this)); | 202 this.observer = new MutationObserver(this.observe.bind(this)); | 
| 203 this.trace = this.trace.bind(this); | 203 this.trace = this.trace.bind(this); | 
| 204 | 204 | 
| 205 if (document.readyState == "loading") | 205 if (document.readyState == "loading") | 
| 206 document.addEventListener("DOMContentLoaded", this.trace); | 206 document.addEventListener("DOMContentLoaded", this.trace); | 
| 207 else | 207 else | 
| 208 this.trace(); | 208 this.trace(); | 
| 209 } | 209 } | 
| 210 ElementHidingTracer.prototype = { | 210 ElementHidingTracer.prototype = { | 
| 211 checkNodes: function(nodes) | 211 checkNodes: function(nodes) | 
| 212 { | 212 { | 
| 213 var matchedSelectors = []; | 213 var matchedSelectors = []; | 
| 214 | 214 | 
| 215 // Find all selectors that match any hidden element inside the given nodes. | 215 // Find all selectors that match any hidden element inside the given nodes. | 
| 216 for (var i = 0; i < this.selectors.length; i++) | 216 for (var i = 0; i < this.selectors.length; i++) | 
| 217 { | 217 { | 
| 218 var selector = this.selectors[i]; | 218 var selector = this.selectors[i]; | 
| 219 | 219 | 
| 220 for (var j = 0; j < nodes.length; j++) | 220 for (var j = 0; j < nodes.length; j++) | 
| 221 { | 221 { | 
| 222 var elements = nodes[j].querySelectorAll(selector); | 222 var elements = nodes[j].querySelectorAll(selector.selector); | 
| 223 var matched = false; | 223 var matched = false; | 
| 224 | 224 | 
| 225 for (var k = 0; k < elements.length; k++) | 225 for (var k = 0; k < elements.length; k++) | 
| 226 { | 226 { | 
| 227 // Only consider selectors that actually have an effect on the | 227 // Only consider selectors that actually have an effect on the | 
| 228 // computed styles, and aren't overridden by rules with higher | 228 // computed styles, and aren't overridden by rules with higher | 
| 229 // priority, or haven't been circumvented in a different way. | 229 // priority, or haven't been circumvented in a different way. | 
| 230 if (getComputedStyle(elements[k]).display == "none") | 230 if (getComputedStyle(elements[k]).display == "none") | 
| 231 { | 231 { | 
| 232 matchedSelectors.push(selector); | 232 if (selector.filter) | 
| 233 matchedSelectors.push(selector.filter.replace(/^.*?##/, "")); | |
| 234 else | |
| 235 matchedSelectors.push(selector.selector); | |
| 233 matched = true; | 236 matched = true; | 
| 234 break; | 237 break; | 
| 235 } | 238 } | 
| 236 } | 239 } | 
| 237 | 240 | 
| 238 if (matched) | 241 if (matched) | 
| 239 break; | 242 break; | 
| 240 } | 243 } | 
| 241 } | 244 } | 
| 242 | 245 | 
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 var shadow = shadowRoot(this); | 486 var shadow = shadowRoot(this); | 
| 484 return shadow == ourShadowRoot ? null : shadow; | 487 return shadow == ourShadowRoot ? null : shadow; | 
| 485 } | 488 } | 
| 486 }); | 489 }); | 
| 487 }, null); | 490 }, null); | 
| 488 } | 491 } | 
| 489 | 492 | 
| 490 return shadow; | 493 return shadow; | 
| 491 }, | 494 }, | 
| 492 | 495 | 
| 493 addSelectors: function(selectors) | 496 addSelectors: function(selectors, filters) | 
| 494 { | 497 { | 
| 495 if (selectors.length == 0) | 498 if (selectors.length == 0) | 
| 496 return; | 499 return; | 
| 497 | 500 | 
| 501 if (this.tracer != null) | |
| 502 { | |
| 503 // The selector is beeing used to identify the filter that is responsible | |
| 504 // for hiding a particular element in the devtools panel. The | |
| 505 // ElementHidingTracer uses the selector to figure out if a filter is | |
| 506 // used on the current document. In case of an ElemHideEmulationFilter | |
| 507 // the selector doesn't match the selector of the filter | |
| 508 // ([-abp-properties=...] vs actual css selector depending on the sites | |
| 509 // css). The To still allow the devtools panel to find the correct filter | |
| 510 // we pass both the selector and the filter string to the | |
| 511 // ElementHidingTracer. | |
| 512 for (var i = 0; i < selectors.length; i++) | |
| 513 { | |
| 514 this.tracer.selectors.push({ | |
| 
 
Sebastian Noack
2017/01/11 16:20:40
Is it guaranteed that the order of selectors match
 
Sebastian Noack
2017/01/11 16:20:40
Creating a new object for each selector might pote
 
wspee
2017/01/12 13:39:58
Indeed ... if you look at findSelectors there can
 
wspee
2017/01/12 13:39:58
No longer relevant.
 
wspee
2017/01/19 16:20:14
According to the chrome profiler an array with 100
 
wspee
2017/01/19 16:20:14
Done.
 
 | |
| 515 selector: selectors[i], | |
| 516 filter: filters ? filters[i] : null | |
| 517 }); | |
| 518 } | |
| 519 } | |
| 520 | |
| 498 if (!this.style) | 521 if (!this.style) | 
| 499 { | 522 { | 
| 500 // Create <style> element lazily, only if we add styles. Add it to | 523 // Create <style> element lazily, only if we add styles. Add it to | 
| 501 // the shadow DOM if possible. Otherwise fallback to the <head> or | 524 // the shadow DOM if possible. Otherwise fallback to the <head> or | 
| 502 // <html> element. If we have injected a style element before that | 525 // <html> element. If we have injected a style element before that | 
| 503 // has been removed (the sheet property is null), create a new one. | 526 // has been removed (the sheet property is null), create a new one. | 
| 504 this.style = document.createElement("style"); | 527 this.style = document.createElement("style"); | 
| 505 (this.shadow || document.head | 528 (this.shadow || document.head | 
| 506 || document.documentElement).appendChild(this.style); | 529 || document.documentElement).appendChild(this.style); | 
| 507 | 530 | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 537 { | 560 { | 
| 538 var selector = selectors.slice(i, i + this.selectorGroupSize).join(", "); | 561 var selector = selectors.slice(i, i + this.selectorGroupSize).join(", "); | 
| 539 this.style.sheet.insertRule(selector + "{display: none !important;}", | 562 this.style.sheet.insertRule(selector + "{display: none !important;}", | 
| 540 this.style.sheet.cssRules.length); | 563 this.style.sheet.cssRules.length); | 
| 541 } | 564 } | 
| 542 }, | 565 }, | 
| 543 | 566 | 
| 544 apply: function() | 567 apply: function() | 
| 545 { | 568 { | 
| 546 var selectors = null; | 569 var selectors = null; | 
| 547 var elemHideEmulationLoaded = false; | |
| 548 | 570 | 
| 549 var checkLoaded = function() | 571 var checkLoaded = function() | 
| 550 { | 572 { | 
| 551 if (!selectors || !elemHideEmulationLoaded) | |
| 552 return; | |
| 553 | |
| 554 if (this.tracer) | 573 if (this.tracer) | 
| 555 this.tracer.disconnect(); | 574 this.tracer.disconnect(); | 
| 556 this.tracer = null; | 575 this.tracer = null; | 
| 557 | 576 | 
| 577 if (selectors.trace) | |
| 578 this.tracer = new ElementHidingTracer(); | |
| 579 | |
| 558 if (this.style && this.style.parentElement) | 580 if (this.style && this.style.parentElement) | 
| 559 this.style.parentElement.removeChild(this.style); | 581 this.style.parentElement.removeChild(this.style); | 
| 560 this.style = null; | 582 this.style = null; | 
| 561 | 583 | 
| 562 this.addSelectors(selectors.selectors); | 584 if (selectors.selectors) | 
| 585 this.addSelectors(selectors.selectors); | |
| 563 this.elemHideEmulation.apply(); | 586 this.elemHideEmulation.apply(); | 
| 564 | 587 | 
| 565 if (selectors.trace) | 588 if (this.tracer && this.tracer.selectors.length) | 
| 
 
Sebastian Noack
2017/01/11 16:20:40
Any particular reason (except for a hypothetical m
 
wspee
2017/01/12 13:39:58
No longer relevant.
 
wspee
2017/01/19 16:20:15
Done.
 
 | |
| 566 this.tracer = new ElementHidingTracer(selectors.selectors); | 589 this.tracer.checkNodes([document]); | 
| 567 }.bind(this); | 590 }.bind(this); | 
| 568 | 591 | 
| 569 ext.backgroundPage.sendMessage({type: "get-selectors"}, function(response) | 592 ext.backgroundPage.sendMessage({type: "get-selectors"}, (response) => | 
| 
 
Sebastian Noack
2017/01/11 16:20:40
The parentheses around the "response" argument are
 
wspee
2017/01/12 13:39:58
No longer relevant.
 
wspee
2017/01/19 16:20:14
Done.
 
 | |
| 570 { | 593 { | 
| 571 selectors = response; | 594 selectors = response; | 
| 572 checkLoaded(); | 595 this.elemHideEmulation.load(() => { checkLoaded(); }); | 
| 
 
Sebastian Noack
2017/01/11 16:20:40
The arrow function seems redundant. Why not just p
 
wspee
2017/01/12 13:39:58
No longer relevant.
 
wspee
2017/01/19 16:20:14
Done.
 
 | |
| 573 }); | |
| 574 | |
| 575 this.elemHideEmulation.load(function() | |
| 576 { | |
| 577 elemHideEmulationLoaded = true; | |
| 578 checkLoaded(); | |
| 579 }); | 596 }); | 
| 580 } | 597 } | 
| 581 }; | 598 }; | 
| 582 | 599 | 
| 583 if (document instanceof HTMLDocument) | 600 if (document instanceof HTMLDocument) | 
| 584 { | 601 { | 
| 585 checkSitekey(); | 602 checkSitekey(); | 
| 586 wrapWebSocket(); | 603 wrapWebSocket(); | 
| 587 | 604 | 
| 588 var elemhide = new ElemHide(); | 605 var elemhide = new ElemHide(); | 
| 589 elemhide.apply(); | 606 elemhide.apply(); | 
| 590 | 607 | 
| 591 document.addEventListener("error", function(event) | 608 document.addEventListener("error", function(event) | 
| 592 { | 609 { | 
| 593 checkCollapse(event.target); | 610 checkCollapse(event.target); | 
| 594 }, true); | 611 }, true); | 
| 595 | 612 | 
| 596 document.addEventListener("load", function(event) | 613 document.addEventListener("load", function(event) | 
| 597 { | 614 { | 
| 598 var element = event.target; | 615 var element = event.target; | 
| 599 if (/^i?frame$/.test(element.localName)) | 616 if (/^i?frame$/.test(element.localName)) | 
| 600 checkCollapse(element); | 617 checkCollapse(element); | 
| 601 }, true); | 618 }, true); | 
| 602 } | 619 } | 
| OLD | NEW |