Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include.preload.js

Issue 29737561: Issue 6539, 6782 - Implement support for snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rename lib/scriptInjection.js to lib/contentFiltering.js Created July 19, 2018, 1:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « composer.postload.js ('k') | lib/contentFiltering.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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", filterTypes
565 },
566 response =>
564 { 567 {
565 if (this.tracer) 568 if (this.tracer)
566 this.tracer.disconnect(); 569 this.tracer.disconnect();
567 this.tracer = null; 570 this.tracer = null;
568 571
569 if (response.trace) 572 if (response.trace)
570 this.tracer = new ElementHidingTracer(); 573 this.tracer = new ElementHidingTracer();
571 574
572 this.inline = response.inline; 575 this.inline = response.inline;
573 this.inlineEmulated = !!response.inlineEmulated; 576 this.inlineEmulated = !!response.inlineEmulated;
(...skipping 11 matching lines...) Expand all
585 588
586 this.elemHideEmulation.apply(response.emulatedPatterns); 589 this.elemHideEmulation.apply(response.emulatedPatterns);
587 }); 590 });
588 } 591 }
589 }; 592 };
590 593
591 if (document instanceof HTMLDocument) 594 if (document instanceof HTMLDocument)
592 { 595 {
593 checkSitekey(); 596 checkSitekey();
594 597
595 elemhide = new ElemHide(); 598 contentFiltering = new ContentFiltering();
596 elemhide.apply(); 599 contentFiltering.apply();
597 600
598 document.addEventListener("error", event => 601 document.addEventListener("error", event =>
599 { 602 {
600 checkCollapse(event.target); 603 checkCollapse(event.target);
601 }, true); 604 }, true);
602 605
603 document.addEventListener("load", event => 606 document.addEventListener("load", event =>
604 { 607 {
605 let element = event.target; 608 let element = event.target;
606 if (/^i?frame$/.test(element.localName)) 609 if (/^i?frame$/.test(element.localName))
607 checkCollapse(element); 610 checkCollapse(element);
608 }, true); 611 }, true);
609 } 612 }
610 613
611 window.checkCollapse = checkCollapse; 614 window.checkCollapse = checkCollapse;
612 window.elemhide = elemhide; 615 window.contentFiltering = contentFiltering;
613 window.typeMap = typeMap; 616 window.typeMap = typeMap;
614 window.getURLsFromElement = getURLsFromElement; 617 window.getURLsFromElement = getURLsFromElement;
OLDNEW
« no previous file with comments | « composer.postload.js ('k') | lib/contentFiltering.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld