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

Delta Between Two Patch Sets: include.preload.js

Issue 29713631: Issue 5760 - Use relative require paths (Closed)
Left Patch Set: Created March 3, 2018, 4:09 a.m.
Right Patch Set: Address PS4 comments, rebase Created April 5, 2018, 11:09 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/csp.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} = require( 21 let {ElemHideEmulation} =
kzar 2018/03/19 21:50:07 Please indent this like let {ElemHideEmulation}
Jon Sonesen 2018/03/20 23:25:18 Acknowledged.
22 "./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 elemhide;
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"],
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 }; 341 };
342 342
343 function ElemHide() 343 function ElemHide()
344 { 344 {
345 this.shadow = this.createShadowTree(); 345 this.shadow = this.createShadowTree();
346 this.styles = new Map(); 346 this.styles = new Map();
347 this.tracer = null; 347 this.tracer = null;
348 this.inline = true; 348 this.inline = true;
349 this.inlineEmulated = true; 349 this.inlineEmulated = true;
350 this.emulatedPatterns = null;
351 350
352 this.elemHideEmulation = new ElemHideEmulation( 351 this.elemHideEmulation = new ElemHideEmulation(
353 this.addSelectors.bind(this), 352 this.addSelectors.bind(this),
354 this.hideElements.bind(this) 353 this.hideElements.bind(this)
355 ); 354 );
356 } 355 }
357 ElemHide.prototype = { 356 ElemHide.prototype = {
358 selectorGroupSize: 1024, 357 selectorGroupSize: 1024,
359 358
360 createShadowTree() 359 createShadowTree()
361 { 360 {
362 // Use Shadow DOM if available as to not mess with with web pages that 361 // Use Shadow DOM if available as to not mess with with web pages that
363 // rely on the order of their own <style> tags (#309). However, creating 362 // rely on the order of their own <style> tags (#309). However, creating
364 // a shadow root breaks running CSS transitions. So we have to create 363 // a shadow root breaks running CSS transitions. So we have to create
365 // the shadow root before transistions might start (#452). 364 // the shadow root before transistions might start (#452).
366 if (!("createShadowRoot" in document.documentElement)) 365 if (!("createShadowRoot" in document.documentElement))
367 return null; 366 return null;
368 367
368 // Both Firefox and Chrome 66+ support user style sheets, so we can avoid
369 // creating an unnecessary shadow root on these platforms.
370 let match = /\bChrome\/(\d+)/.exec(navigator.userAgent);
371 if (!match || match[1] >= 66)
372 return null;
373
369 // Using shadow DOM causes issues on some Google websites, 374 // Using shadow DOM causes issues on some Google websites,
370 // including Google Docs, Gmail and Blogger (#1770, #2602, #2687). 375 // including Google Docs, Gmail and Blogger (#1770, #2602, #2687).
371 if (/\.(?:google|blogger)\.com$/.test(document.domain)) 376 if (/\.(?:google|blogger)\.com$/.test(document.domain))
372 return null; 377 return null;
373 378
374 // Finally since some users have both AdBlock and Adblock Plus installed we 379 // Finally since some users have both AdBlock and Adblock Plus installed we
375 // have to consider how the two extensions interact. For example we want to 380 // have to consider how the two extensions interact. For example we want to
376 // avoid creating the shadowRoot twice. 381 // avoid creating the shadowRoot twice.
377 let shadow = document.documentElement.shadowRoot || 382 let shadow = document.documentElement.shadowRoot ||
378 document.documentElement.createShadowRoot(); 383 document.documentElement.createShadowRoot();
379 shadow.appendChild(document.createElement("shadow")); 384 shadow.appendChild(document.createElement("content"));
380 385
381 return shadow; 386 return shadow;
382 }, 387 },
383 388
384 addSelectorsInline(selectors, groupName) 389 addSelectorsInline(selectors, groupName)
385 { 390 {
386 let style = this.styles.get(groupName); 391 let style = this.styles.get(groupName);
387 392
388 if (style) 393 if (style)
389 { 394 {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 514
510 this.inline = response.inline; 515 this.inline = response.inline;
511 this.inlineEmulated = !!response.inlineEmulated; 516 this.inlineEmulated = !!response.inlineEmulated;
512 517
513 if (this.inline) 518 if (this.inline)
514 this.addSelectorsInline(response.selectors, "standard"); 519 this.addSelectorsInline(response.selectors, "standard");
515 520
516 if (this.tracer) 521 if (this.tracer)
517 this.tracer.addSelectors(response.selectors); 522 this.tracer.addSelectors(response.selectors);
518 523
524 // Prefer CSS selectors for -abp-has and -abp-contains unless the
525 // background page has asked us to use inline styles.
526 this.elemHideEmulation.useInlineStyles = this.inline ||
527 this.inlineEmulated;
528
519 this.elemHideEmulation.apply(response.emulatedPatterns); 529 this.elemHideEmulation.apply(response.emulatedPatterns);
520 }); 530 });
521 } 531 }
522 }; 532 };
523 533
524 if (document instanceof HTMLDocument) 534 if (document instanceof HTMLDocument)
525 { 535 {
526 checkSitekey(); 536 checkSitekey();
527 537
528 elemhide = new ElemHide(); 538 elemhide = new ElemHide();
529 elemhide.apply(); 539 elemhide.apply();
530 540
531 document.addEventListener("error", event => 541 document.addEventListener("error", event =>
532 { 542 {
533 checkCollapse(event.target); 543 checkCollapse(event.target);
534 }, true); 544 }, true);
535 545
536 document.addEventListener("load", event => 546 document.addEventListener("load", event =>
537 { 547 {
538 let element = event.target; 548 let element = event.target;
539 if (/^i?frame$/.test(element.localName)) 549 if (/^i?frame$/.test(element.localName))
540 checkCollapse(element); 550 checkCollapse(element);
541 }, true); 551 }, true);
542 } 552 }
543 553
544 window.checkCollapse = checkCollapse; 554 window.checkCollapse = checkCollapse;
545 window.elemhide = elemhide; 555 window.elemhide = elemhide;
546 window.typeMap = typeMap; 556 window.typeMap = typeMap;
547 window.getURLsFromElement = getURLsFromElement; 557 window.getURLsFromElement = getURLsFromElement;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld