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: Remove elemhideWhitelisted temporary variable Created July 19, 2018, 1:13 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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 let message = {type: "content.applyFilters"};
564
565 if (filterTypes)
566 message.filterTypes = filterTypes;
567
568 browser.runtime.sendMessage(message, response =>
564 { 569 {
565 if (this.tracer) 570 if (this.tracer)
566 this.tracer.disconnect(); 571 this.tracer.disconnect();
567 this.tracer = null; 572 this.tracer = null;
568 573
569 if (response.trace) 574 if (response.trace)
570 this.tracer = new ElementHidingTracer(); 575 this.tracer = new ElementHidingTracer();
571 576
572 this.inline = response.inline; 577 this.inline = response.inline;
573 this.inlineEmulated = !!response.inlineEmulated; 578 this.inlineEmulated = !!response.inlineEmulated;
(...skipping 11 matching lines...) Expand all
585 590
586 this.elemHideEmulation.apply(response.emulatedPatterns); 591 this.elemHideEmulation.apply(response.emulatedPatterns);
587 }); 592 });
588 } 593 }
589 }; 594 };
590 595
591 if (document instanceof HTMLDocument) 596 if (document instanceof HTMLDocument)
592 { 597 {
593 checkSitekey(); 598 checkSitekey();
594 599
595 elemhide = new ElemHide(); 600 contentFiltering = new ContentFiltering();
596 elemhide.apply(); 601 contentFiltering.apply();
597 602
598 document.addEventListener("error", event => 603 document.addEventListener("error", event =>
599 { 604 {
600 checkCollapse(event.target); 605 checkCollapse(event.target);
601 }, true); 606 }, true);
602 607
603 document.addEventListener("load", event => 608 document.addEventListener("load", event =>
604 { 609 {
605 let element = event.target; 610 let element = event.target;
606 if (/^i?frame$/.test(element.localName)) 611 if (/^i?frame$/.test(element.localName))
607 checkCollapse(element); 612 checkCollapse(element);
608 }, true); 613 }, true);
609 } 614 }
610 615
611 window.checkCollapse = checkCollapse; 616 window.checkCollapse = checkCollapse;
612 window.elemhide = elemhide; 617 window.contentFiltering = contentFiltering;
613 window.typeMap = typeMap; 618 window.typeMap = typeMap;
614 window.getURLsFromElement = getURLsFromElement; 619 window.getURLsFromElement = getURLsFromElement;
OLDNEW
« composer.postload.js ('K') | « dependencies ('k') | lib/scriptInjection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld