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