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

Delta Between Two Patch Sets: include.preload.js

Issue 29737561: Issue 6539, 6782 - Implement support for snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Clean up messaging for content.applyFilters Created July 19, 2018, 1:50 p.m.
Right Patch Set: Add explanatory comment in catch block Created July 19, 2018, 3:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « composer.postload.js ('k') | lib/contentFiltering.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 content; 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 content.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 Content() 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 Content.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 applyFilters(filterTypes) 561 apply(filterTypes)
562 { 562 {
563 browser.runtime.sendMessage({ 563 browser.runtime.sendMessage({
564 type: "content.applyFilters", filterTypes 564 type: "content.applyFilters",
565 filterTypes
565 }, 566 },
566 response => 567 response =>
567 { 568 {
568 if (this.tracer) 569 if (this.tracer)
569 this.tracer.disconnect(); 570 this.tracer.disconnect();
570 this.tracer = null; 571 this.tracer = null;
571 572
572 if (response.trace) 573 if (response.trace)
573 this.tracer = new ElementHidingTracer(); 574 this.tracer = new ElementHidingTracer();
574 575
(...skipping 13 matching lines...) Expand all
588 589
589 this.elemHideEmulation.apply(response.emulatedPatterns); 590 this.elemHideEmulation.apply(response.emulatedPatterns);
590 }); 591 });
591 } 592 }
592 }; 593 };
593 594
594 if (document instanceof HTMLDocument) 595 if (document instanceof HTMLDocument)
595 { 596 {
596 checkSitekey(); 597 checkSitekey();
597 598
598 content = new Content(); 599 contentFiltering = new ContentFiltering();
599 content.applyFilters(); 600 contentFiltering.apply();
600 601
601 document.addEventListener("error", event => 602 document.addEventListener("error", event =>
602 { 603 {
603 checkCollapse(event.target); 604 checkCollapse(event.target);
604 }, true); 605 }, true);
605 606
606 document.addEventListener("load", event => 607 document.addEventListener("load", event =>
607 { 608 {
608 let element = event.target; 609 let element = event.target;
609 if (/^i?frame$/.test(element.localName)) 610 if (/^i?frame$/.test(element.localName))
610 checkCollapse(element); 611 checkCollapse(element);
611 }, true); 612 }, true);
612 } 613 }
613 614
614 window.checkCollapse = checkCollapse; 615 window.checkCollapse = checkCollapse;
615 window.content = content; 616 window.contentFiltering = contentFiltering;
616 window.typeMap = typeMap; 617 window.typeMap = typeMap;
617 window.getURLsFromElement = getURLsFromElement; 618 window.getURLsFromElement = getURLsFromElement;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld