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

Delta Between Two Patch Sets: include.preload.js

Issue 29350213: Issue 4364 - Drop support for Chrome 29-40 and remove legacy code (Closed)
Left Patch Set: Got rid of init(), refactored element hiding code into a class Created Aug. 25, 2016, 3:10 p.m.
Right Patch Set: Rephrased comment Created Sept. 13, 2016, 3:20 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') | metadata.chrome » ('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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 }, 328 },
329 329
330 disconnect: function() 330 disconnect: function()
331 { 331 {
332 document.removeEventListener("DOMContentLoaded", this.trace); 332 document.removeEventListener("DOMContentLoaded", this.trace);
333 this.observer.disconnect(); 333 this.observer.disconnect();
334 clearTimeout(this.timeout); 334 clearTimeout(this.timeout);
335 } 335 }
336 }; 336 };
337 337
338 function runInDocument(fn, arg) 338 function runInPageContext(fn, arg)
339 { 339 {
340 var script = document.createElement("script"); 340 var script = document.createElement("script");
341 script.type = "application/javascript"; 341 script.type = "application/javascript";
342 script.async = false; 342 script.async = false;
343 script.textContent = "(" + fn + ")(" + JSON.stringify(arg) + ");"; 343 script.textContent = "(" + fn + ")(" + JSON.stringify(arg) + ");";
344 document.documentElement.appendChild(script); 344 document.documentElement.appendChild(script);
345 document.documentElement.removeChild(script); 345 document.documentElement.removeChild(script);
346 } 346 }
347 347
348 // Neither Chrome[1] nor Safari allow us to intercept WebSockets, and therefore 348 // Neither Chrome[1] nor Safari allow us to intercept WebSockets, and therefore
(...skipping 14 matching lines...) Expand all
363 type: "request.websocket", 363 type: "request.websocket",
364 url: event.detail.url 364 url: event.detail.url
365 }, function (block) 365 }, function (block)
366 { 366 {
367 document.dispatchEvent( 367 document.dispatchEvent(
368 new CustomEvent(eventName + "-" + event.detail.url, {detail: block}) 368 new CustomEvent(eventName + "-" + event.detail.url, {detail: block})
369 ); 369 );
370 }); 370 });
371 }); 371 });
372 372
373 runInDocument(function(eventName) 373 runInPageContext(function(eventName)
374 { 374 {
375 // As far as possible we must track everything we use that could be 375 // As far as possible we must track everything we use that could be
376 // sabotaged by the website later in order to circumvent us. 376 // sabotaged by the website later in order to circumvent us.
377 var RealWebSocket = WebSocket; 377 var RealWebSocket = WebSocket;
378 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose); 378 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose);
379 var addEventListener = document.addEventListener.bind(document); 379 var addEventListener = document.addEventListener.bind(document);
380 var removeEventListener = document.removeEventListener.bind(document); 380 var removeEventListener = document.removeEventListener.bind(document);
381 var dispatchEvent = document.dispatchEvent.bind(document); 381 var dispatchEvent = document.dispatchEvent.bind(document);
382 var CustomEvent = window.CustomEvent; 382 var CustomEvent = window.CustomEvent;
383 383
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 }, callback); 446 }, callback);
447 }, 447 },
448 this.addSelectors.bind(this) 448 this.addSelectors.bind(this)
449 ); 449 );
450 } 450 }
451 ElemHide.prototype = { 451 ElemHide.prototype = {
452 selectorGroupSize: 200, 452 selectorGroupSize: 200,
453 453
454 createShadowTree: function() 454 createShadowTree: function()
455 { 455 {
456 // Use Shadow DOM if available to don't mess with web pages that rely 456 // Use Shadow DOM if available as to not mess with with web pages that
457 // on the order of their own <style> tags (#309). However, creating a 457 // rely on the order of their own <style> tags (#309). However, creating
458 // shadow root breaks running CSS transitions. So we have to create 458 // a shadow root breaks running CSS transitions. So we have to create
459 // the shadow root before transistions might start (#452). 459 // the shadow root before transistions might start (#452).
460 if (!("createShadowRoot" in document.documentElement)) 460 if (!("createShadowRoot" in document.documentElement))
461 return null; 461 return null;
462 462
463 // Using shadow DOM causes issues on some Google websites, 463 // Using shadow DOM causes issues on some Google websites,
464 // including Google Docs, Gmail and Blogger (#1770, #2602, #2687). 464 // including Google Docs, Gmail and Blogger (#1770, #2602, #2687).
465 if (/\.(?:google|blogger)\.com$/.test(document.domain)) 465 if (/\.(?:google|blogger)\.com$/.test(document.domain))
466 return null; 466 return null;
467 467
468 var shadow = document.documentElement.createShadowRoot(); 468 var shadow = document.documentElement.createShadowRoot();
469 shadow.appendChild(document.createElement("shadow")); 469 shadow.appendChild(document.createElement("shadow"));
470 470
471 // Stop the website from messing with our shadow root (#4191, #4298). 471 // Stop the website from messing with our shadow root (#4191, #4298).
472 if ("shadowRoot" in Element.prototype) 472 if ("shadowRoot" in Element.prototype)
473 { 473 {
474 runInDocument(function() 474 runInPageContext(function()
475 { 475 {
476 var ourShadowRoot = document.documentElement.shadowRoot; 476 var ourShadowRoot = document.documentElement.shadowRoot;
477 var desc = Object.getOwnPropertyDescriptor(Element.prototype, "shadowRoo t"); 477 var desc = Object.getOwnPropertyDescriptor(Element.prototype, "shadowRoo t");
478 var shadowRoot = Function.prototype.call.bind(desc.get); 478 var shadowRoot = Function.prototype.call.bind(desc.get);
479 479
480 Object.defineProperty(Element.prototype, "shadowRoot", { 480 Object.defineProperty(Element.prototype, "shadowRoot", {
481 configurable: true, enumerable: true, get: function() 481 configurable: true, enumerable: true, get: function()
482 { 482 {
483 var shadow = shadowRoot(this); 483 var shadow = shadowRoot(this);
484 return shadow == ourShadowRoot ? null : shadow; 484 return shadow == ourShadowRoot ? null : shadow;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 checkCollapse(event.target); 592 checkCollapse(event.target);
593 }, true); 593 }, true);
594 594
595 document.addEventListener("load", function(event) 595 document.addEventListener("load", function(event)
596 { 596 {
597 var element = event.target; 597 var element = event.target;
598 if (/^i?frame$/.test(element.localName)) 598 if (/^i?frame$/.test(element.localName))
599 checkCollapse(element); 599 checkCollapse(element);
600 }, true); 600 }, true);
601 } 601 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld