| LEFT | RIGHT |
| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 this.tracer = null; | 346 this.tracer = null; |
| 347 this.inline = true; | 347 this.inline = true; |
| 348 this.emulatedPatterns = null; | 348 this.emulatedPatterns = null; |
| 349 | 349 |
| 350 this.elemHideEmulation = new ElemHideEmulation( | 350 this.elemHideEmulation = new ElemHideEmulation( |
| 351 this.addSelectors.bind(this), | 351 this.addSelectors.bind(this), |
| 352 this.hideElements.bind(this) | 352 this.hideElements.bind(this) |
| 353 ); | 353 ); |
| 354 } | 354 } |
| 355 ElemHide.prototype = { | 355 ElemHide.prototype = { |
| 356 selectorGroupSize: 200, | 356 selectorGroupSize: 1024, |
| 357 | 357 |
| 358 createShadowTree() | 358 createShadowTree() |
| 359 { | 359 { |
| 360 // Use Shadow DOM if available as to not mess with with web pages that | 360 // Use Shadow DOM if available as to not mess with with web pages that |
| 361 // rely on the order of their own <style> tags (#309). However, creating | 361 // rely on the order of their own <style> tags (#309). However, creating |
| 362 // a shadow root breaks running CSS transitions. So we have to create | 362 // a shadow root breaks running CSS transitions. So we have to create |
| 363 // the shadow root before transistions might start (#452). | 363 // the shadow root before transistions might start (#452). |
| 364 if (!("createShadowRoot" in document.documentElement)) | 364 if (!("createShadowRoot" in document.documentElement)) |
| 365 return null; | 365 return null; |
| 366 | 366 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 let subSelectors = splitSelector(selector); | 423 let subSelectors = splitSelector(selector); |
| 424 for (let subSelector of subSelectors) | 424 for (let subSelector of subSelectors) |
| 425 preparedSelectors.push("::content " + subSelector); | 425 preparedSelectors.push("::content " + subSelector); |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 else | 428 else |
| 429 { | 429 { |
| 430 preparedSelectors = selectors; | 430 preparedSelectors = selectors; |
| 431 } | 431 } |
| 432 | 432 |
| 433 // Chromium's Blink engine supports only up to 8,192 selectors; more | 433 // Chromium's Blink engine supports only up to 8,192 simple selectors, and |
| 434 // specifically, it ignores any selectors that start at index 8192 or | 434 // even fewer compound selectors, in a rule. The exact number of selectors |
| 435 // beyond in the list of plain selectors. In order to avoid spilling | 435 // that would work depends on their sizes (e.g. "#foo .bar" has a |
| 436 // outside of this range, we simply add multiple rules in groups of up to | 436 // size of 2). Since we don't know the sizes of the selectors here, we |
| 437 // 200 selectors each. | 437 // simply split them into groups of 1,024, based on the reasonable |
| 438 // assumption that the average selector won't have a size greater than 8. |
| 439 // The alternative would be to calculate the sizes of the selectors and |
| 440 // divide them up accordingly, but this approach is more efficient and has |
| 441 // worked well in practice. In theory this could still lead to some |
| 442 // selectors not working on Chromium, but it is highly unlikely. |
| 438 // See issue #6298 and https://crbug.com/804179 | 443 // See issue #6298 and https://crbug.com/804179 |
| 439 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize) | 444 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize) |
| 440 { | 445 { |
| 441 let selector = preparedSelectors.slice( | 446 let selector = preparedSelectors.slice( |
| 442 i, i + this.selectorGroupSize | 447 i, i + this.selectorGroupSize |
| 443 ).join(", "); | 448 ).join(", "); |
| 444 this.style.sheet.insertRule(selector + "{display: none !important;}", | 449 this.style.sheet.insertRule(selector + "{display: none !important;}", |
| 445 this.style.sheet.cssRules.length); | 450 this.style.sheet.cssRules.length); |
| 446 } | 451 } |
| 447 }, | 452 }, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 let element = event.target; | 535 let element = event.target; |
| 531 if (/^i?frame$/.test(element.localName)) | 536 if (/^i?frame$/.test(element.localName)) |
| 532 checkCollapse(element); | 537 checkCollapse(element); |
| 533 }, true); | 538 }, true); |
| 534 } | 539 } |
| 535 | 540 |
| 536 window.checkCollapse = checkCollapse; | 541 window.checkCollapse = checkCollapse; |
| 537 window.elemhide = elemhide; | 542 window.elemhide = elemhide; |
| 538 window.typeMap = typeMap; | 543 window.typeMap = typeMap; |
| 539 window.getURLsFromElement = getURLsFromElement; | 544 window.getURLsFromElement = getURLsFromElement; |
| LEFT | RIGHT |