 Issue 29349024:
  Issue 4298 - Enforce 'display: none' for ElemHide  (Closed)
    
  
    Issue 29349024:
  Issue 4298 - Enforce 'display: none' for ElemHide  (Closed) 
  | 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 }, | 327 }, | 
| 328 | 328 | 
| 329 disconnect: function() | 329 disconnect: function() | 
| 330 { | 330 { | 
| 331 this.document.removeEventListener("DOMContentLoaded", this.trace); | 331 this.document.removeEventListener("DOMContentLoaded", this.trace); | 
| 332 this.observer.disconnect(); | 332 this.observer.disconnect(); | 
| 333 clearTimeout(this.timeout); | 333 clearTimeout(this.timeout); | 
| 334 } | 334 } | 
| 335 }; | 335 }; | 
| 336 | 336 | 
| 337 function enforceStyleSheetRules(style) | |
| 338 { | |
| 339 style.id = id; | |
| 340 injectJS( | |
| 341 function(id) | |
| 342 { | |
| 343 var style = document.getElementById(id) || | |
| 344 document.documentElement.shadowRoot.getElementById(id); | |
| 345 style.removeAttribute("id"); | |
| 346 | |
| 347 Object.defineProperty(style.sheet, "disabled", | |
| 
Sebastian Noack
2016/08/04 20:44:23
Where did the code go, that addressed deleteRule a
 
kzar
2016/08/05 11:01:57
This review is based upon the changes in a couple
 | |
| 348 {value: false, enumerable: true}); | |
| 349 | |
| 350 for (var i = 0; i < style.sheet.rules.length; i += 1) | |
| 351 Object.defineProperty(style.sheet.rules[i].style, "display", | |
| 
Sebastian Noack
2016/08/04 20:44:23
How about overriding style.sheet.rules (and sheet.
 
kzar
2016/08/05 11:01:57
Cool idea, but I actually had to overwrite the get
 | |
| 352 {value: "none", enumerable: true}); | |
| 353 }, id | |
| 354 ); | |
| 355 } | |
| 356 | |
| 337 function reinjectStyleSheetWhenRemoved(document, style) | 357 function reinjectStyleSheetWhenRemoved(document, style) | 
| 338 { | 358 { | 
| 339 if (!MutationObserver) | 359 if (!MutationObserver) | 
| 340 return null; | 360 return null; | 
| 341 | 361 | 
| 342 var rules = style.sheet.rules; | 362 var rules = style.sheet.rules; | 
| 343 var parentNode = style.parentNode; | 363 var parentNode = style.parentNode; | 
| 344 var observer = new MutationObserver(function() | 364 var observer = new MutationObserver(function() | 
| 345 { | 365 { | 
| 346 if (style.parentNode != parentNode) | 366 if (style.parentNode != parentNode) | 
| 347 { | 367 { | 
| 348 parentNode.appendChild(style); | 368 parentNode.appendChild(style); | 
| 349 | 369 | 
| 350 if (style.sheet.rules.length == 0) | 370 if (style.sheet.rules.length == 0) | 
| 351 { | 371 { | 
| 352 for (var i = 0; i < rules.length; i += 1) | 372 for (var i = 0; i < rules.length; i += 1) | 
| 353 style.sheet.addRule(rules[i].selectorText, "display: none !important;" ); | 373 style.sheet.addRule(rules[i].selectorText); | 
| 354 | 374 | 
| 355 style.id = id; | 375 enforceStyleSheetRules(style); | 
| 356 injectJS( | |
| 357 function(id) | |
| 358 { | |
| 359 var style = document.getElementById(id) || | |
| 360 document.documentElement.shadowRoot.getElementById(id); | |
| 361 style.removeAttribute("id"); | |
| 362 Object.defineProperty(style.sheet, "disabled", | |
| 363 {value: false, enumerable: true}); | |
| 364 }, id | |
| 365 ); | |
| 366 } | 376 } | 
| 367 } | 377 } | 
| 368 }); | 378 }); | 
| 369 | 379 | 
| 370 observer.observe(parentNode, {childList: true}); | 380 observer.observe(parentNode, {childList: true}); | 
| 371 return observer; | 381 return observer; | 
| 372 } | 382 } | 
| 373 | 383 | 
| 374 function injectJS(f) | 384 function injectJS(f) | 
| 375 { | 385 { | 
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 } | 598 } | 
| 589 | 599 | 
| 590 // Safari only allows 8192 primitive selectors to be injected at once[1], we | 600 // Safari only allows 8192 primitive selectors to be injected at once[1], we | 
| 591 // therefore chunk the inserted selectors into groups of 200 to be safe. | 601 // therefore chunk the inserted selectors into groups of 200 to be safe. | 
| 592 // (Chrome also has a limit, larger... but we're not certain exactly what it | 602 // (Chrome also has a limit, larger... but we're not certain exactly what it | 
| 593 // is! Edge apparently has no such limit.) | 603 // is! Edge apparently has no such limit.) | 
| 594 // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69 debb75fc1de/Source/WebCore/css/RuleSet.h#L68 | 604 // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69 debb75fc1de/Source/WebCore/css/RuleSet.h#L68 | 
| 595 for (var i = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE) | 605 for (var i = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE) | 
| 596 { | 606 { | 
| 597 var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", "); | 607 var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", "); | 
| 598 style.sheet.addRule(selector, "display: none !important;"); | 608 style.sheet.addRule(selector); | 
| 599 } | 609 } | 
| 610 enforceStyleSheetRules(style); | |
| 600 }; | 611 }; | 
| 601 | 612 | 
| 602 var updateStylesheet = function() | 613 var updateStylesheet = function() | 
| 603 { | 614 { | 
| 604 var selectors = null; | 615 var selectors = null; | 
| 605 var CSSPropertyFiltersLoaded = false; | 616 var CSSPropertyFiltersLoaded = false; | 
| 606 | 617 | 
| 607 var checkLoaded = function() | 618 var checkLoaded = function() | 
| 608 { | 619 { | 
| 609 if (!selectors || !CSSPropertyFiltersLoaded) | 620 if (!selectors || !CSSPropertyFiltersLoaded) | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 }, true); | 696 }, true); | 
| 686 | 697 | 
| 687 return updateStylesheet; | 698 return updateStylesheet; | 
| 688 } | 699 } | 
| 689 | 700 | 
| 690 if (document instanceof HTMLDocument) | 701 if (document instanceof HTMLDocument) | 
| 691 { | 702 { | 
| 692 checkSitekey(); | 703 checkSitekey(); | 
| 693 window.updateStylesheet = init(document); | 704 window.updateStylesheet = init(document); | 
| 694 } | 705 } | 
| OLD | NEW |