| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 let {splitSelector} = require("./adblockpluscore/lib/common"); | 20 let {splitSelector} = require("./adblockpluscore/lib/common"); |
| 21 let {ElemHideEmulation} = | 21 let {ElemHideEmulation} = |
| 22 require("./adblockpluscore/lib/content/elemHideEmulation"); | 22 require("./adblockpluscore/lib/content/elemHideEmulation"); |
| 23 | 23 |
| 24 // This variable is also used by our other content scripts. | 24 // This variable is also used by our other content scripts. |
| 25 let elemhide; | 25 let contentFiltering; |
| 26 | 26 |
| 27 const typeMap = new Map([ | 27 const typeMap = new Map([ |
| 28 ["img", "IMAGE"], | 28 ["img", "IMAGE"], |
| 29 ["input", "IMAGE"], | 29 ["input", "IMAGE"], |
| 30 ["picture", "IMAGE"], | 30 ["picture", "IMAGE"], |
| 31 ["audio", "MEDIA"], | 31 ["audio", "MEDIA"], |
| 32 ["video", "MEDIA"], | 32 ["video", "MEDIA"], |
| 33 ["frame", "SUBDOCUMENT"], | 33 ["frame", "SUBDOCUMENT"], |
| 34 ["iframe", "SUBDOCUMENT"], | 34 ["iframe", "SUBDOCUMENT"], |
| 35 ["object", "OBJECT"], | 35 ["object", "OBJECT"], |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 }, | 219 }, |
| 220 collapse => | 220 collapse => |
| 221 { | 221 { |
| 222 if (collapse) | 222 if (collapse) |
| 223 { | 223 { |
| 224 if (selector) | 224 if (selector) |
| 225 { | 225 { |
| 226 if (!collapsingSelectors.has(selector)) | 226 if (!collapsingSelectors.has(selector)) |
| 227 { | 227 { |
| 228 collapsingSelectors.add(selector); | 228 collapsingSelectors.add(selector); |
| 229 elemhide.addSelectors([selector], null, "collapsing", true); | 229 contentFiltering.addSelectors([selector], null, "collapsing", true); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 else | 232 else |
| 233 { | 233 { |
| 234 hideElement(element); | 234 hideElement(element); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 ); | 238 ); |
| 239 } | 239 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 }, | 387 }, |
| 388 | 388 |
| 389 disconnect() | 389 disconnect() |
| 390 { | 390 { |
| 391 document.removeEventListener("DOMContentLoaded", this.trace); | 391 document.removeEventListener("DOMContentLoaded", this.trace); |
| 392 this.observer.disconnect(); | 392 this.observer.disconnect(); |
| 393 clearTimeout(this.timeout); | 393 clearTimeout(this.timeout); |
| 394 } | 394 } |
| 395 }; | 395 }; |
| 396 | 396 |
| 397 function ElemHide() | 397 function ContentFiltering() |
| 398 { | 398 { |
| 399 this.shadow = this.createShadowTree(); | 399 this.shadow = this.createShadowTree(); |
| 400 this.styles = new Map(); | 400 this.styles = new Map(); |
| 401 this.tracer = null; | 401 this.tracer = null; |
| 402 this.inline = true; | 402 this.inline = true; |
| 403 this.inlineEmulated = true; | 403 this.inlineEmulated = true; |
| 404 | 404 |
| 405 this.elemHideEmulation = new ElemHideEmulation( | 405 this.elemHideEmulation = new ElemHideEmulation( |
| 406 this.addSelectors.bind(this), | 406 this.addSelectors.bind(this), |
| 407 this.hideElements.bind(this) | 407 this.hideElements.bind(this) |
| 408 ); | 408 ); |
| 409 } | 409 } |
| 410 ElemHide.prototype = { | 410 ContentFiltering.prototype = { |
| 411 selectorGroupSize: 1024, | 411 selectorGroupSize: 1024, |
| 412 | 412 |
| 413 createShadowTree() | 413 createShadowTree() |
| 414 { | 414 { |
| 415 // Use Shadow DOM if available as to not mess with with web pages that | 415 // Use Shadow DOM if available as to not mess with with web pages that |
| 416 // rely on the order of their own <style> tags (#309). However, creating | 416 // rely on the order of their own <style> tags (#309). However, creating |
| 417 // a shadow root breaks running CSS transitions. So we have to create | 417 // a shadow root breaks running CSS transitions. So we have to create |
| 418 // the shadow root before transistions might start (#452). | 418 // the shadow root before transistions might start (#452). |
| 419 if (!("createShadowRoot" in document.documentElement)) | 419 if (!("createShadowRoot" in document.documentElement)) |
| 420 return null; | 420 return null; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 if (this.tracer) | 551 if (this.tracer) |
| 552 { | 552 { |
| 553 browser.runtime.sendMessage({ | 553 browser.runtime.sendMessage({ |
| 554 type: "hitLogger.traceElemHide", | 554 type: "hitLogger.traceElemHide", |
| 555 selectors: [], | 555 selectors: [], |
| 556 filters | 556 filters |
| 557 }); | 557 }); |
| 558 } | 558 } |
| 559 }, | 559 }, |
| 560 | 560 |
| 561 apply() | 561 apply(filterTypes) |
| 562 { | 562 { |
| 563 browser.runtime.sendMessage({type: "elemhide.getSelectors"}, response => | 563 browser.runtime.sendMessage({ |
| 564 type: "content.applyFilters", |
| 565 filterTypes |
| 566 }, |
| 567 response => |
| 564 { | 568 { |
| 565 if (this.tracer) | 569 if (this.tracer) |
| 566 this.tracer.disconnect(); | 570 this.tracer.disconnect(); |
| 567 this.tracer = null; | 571 this.tracer = null; |
| 568 | 572 |
| 569 if (response.trace) | 573 if (response.trace) |
| 570 this.tracer = new ElementHidingTracer(); | 574 this.tracer = new ElementHidingTracer(); |
| 571 | 575 |
| 572 this.inline = response.inline; | 576 this.inline = response.inline; |
| 573 this.inlineEmulated = !!response.inlineEmulated; | 577 this.inlineEmulated = !!response.inlineEmulated; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 585 | 589 |
| 586 this.elemHideEmulation.apply(response.emulatedPatterns); | 590 this.elemHideEmulation.apply(response.emulatedPatterns); |
| 587 }); | 591 }); |
| 588 } | 592 } |
| 589 }; | 593 }; |
| 590 | 594 |
| 591 if (document instanceof HTMLDocument) | 595 if (document instanceof HTMLDocument) |
| 592 { | 596 { |
| 593 checkSitekey(); | 597 checkSitekey(); |
| 594 | 598 |
| 595 elemhide = new ElemHide(); | 599 contentFiltering = new ContentFiltering(); |
| 596 elemhide.apply(); | 600 contentFiltering.apply(); |
| 597 | 601 |
| 598 document.addEventListener("error", event => | 602 document.addEventListener("error", event => |
| 599 { | 603 { |
| 600 checkCollapse(event.target); | 604 checkCollapse(event.target); |
| 601 }, true); | 605 }, true); |
| 602 | 606 |
| 603 document.addEventListener("load", event => | 607 document.addEventListener("load", event => |
| 604 { | 608 { |
| 605 let element = event.target; | 609 let element = event.target; |
| 606 if (/^i?frame$/.test(element.localName)) | 610 if (/^i?frame$/.test(element.localName)) |
| 607 checkCollapse(element); | 611 checkCollapse(element); |
| 608 }, true); | 612 }, true); |
| 609 } | 613 } |
| 610 | 614 |
| 611 window.checkCollapse = checkCollapse; | 615 window.checkCollapse = checkCollapse; |
| 612 window.elemhide = elemhide; | 616 window.contentFiltering = contentFiltering; |
| 613 window.typeMap = typeMap; | 617 window.typeMap = typeMap; |
| 614 window.getURLsFromElement = getURLsFromElement; | 618 window.getURLsFromElement = getURLsFromElement; |
| OLD | NEW |