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

Delta Between Two Patch Sets: include.preload.js

Issue 29349823: Fixes 4328 - Multiple shadowRoot deprecated warnings (Closed)
Left Patch Set: Created Aug. 15, 2016, 8:27 p.m.
Right Patch Set: Fixed indentation Created Nov. 17, 2016, 3:45 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 | « no previous file | no next file » | 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 function wrapWebSocket(document) 355 function wrapWebSocket(document)
356 { 356 {
357 if (typeof WebSocket == "undefined") 357 if (typeof WebSocket == "undefined")
358 return; 358 return;
359 359
360 var eventName = "abpws-" + Math.random().toString(36).substr(2); 360 var eventName = "abpws-" + Math.random().toString(36).substr(2);
361 361
362 document.addEventListener(eventName, function(event) 362 document.addEventListener(eventName, function(event)
363 { 363 {
364 ext.backgroundPage.sendMessage({ 364 ext.backgroundPage.sendMessage({
365 type: "websocket-request", 365 type: "request.websocket",
366 url: event.detail.url 366 url: event.detail.url
367 }, function (block) 367 }, function (block)
368 { 368 {
369 document.dispatchEvent( 369 document.dispatchEvent(
370 new CustomEvent(eventName + "-" + event.detail.url, {detail: block}) 370 new CustomEvent(eventName + "-" + event.detail.url, {detail: block})
371 ); 371 );
372 }); 372 });
373 }); 373 });
374 374
375 runInDocument(document, function(eventName) 375 runInDocument(document, function(eventName)
(...skipping 15 matching lines...) Expand all
391 callback(event.detail); 391 callback(event.detail);
392 removeEventListener(incomingEventName, listener); 392 removeEventListener(incomingEventName, listener);
393 } 393 }
394 addEventListener(incomingEventName, listener); 394 addEventListener(incomingEventName, listener);
395 395
396 dispatchEvent(new CustomEvent(eventName, { 396 dispatchEvent(new CustomEvent(eventName, {
397 detail: {url: url} 397 detail: {url: url}
398 })); 398 }));
399 } 399 }
400 400
401 WebSocket = function WrappedWebSocket(url, protocols) 401 function WrappedWebSocket(url)
402 { 402 {
403 // Throw correct exceptions if the constructor is used improperly. 403 // Throw correct exceptions if the constructor is used improperly.
404 if (!(this instanceof WrappedWebSocket)) return RealWebSocket(); 404 if (!(this instanceof WrappedWebSocket)) return RealWebSocket();
405 if (arguments.length < 1) return new RealWebSocket(); 405 if (arguments.length < 1) return new RealWebSocket();
406 406
407 var websocket; 407 var websocket;
408 if (arguments.length == 1) 408 if (arguments.length == 1)
409 websocket = new RealWebSocket(url); 409 websocket = new RealWebSocket(url);
410 else 410 else
411 websocket = new RealWebSocket(url, protocols); 411 websocket = new RealWebSocket(url, arguments[1]);
412 412
413 checkRequest(websocket.url, function(blocked) 413 checkRequest(websocket.url, function(blocked)
414 { 414 {
415 if (blocked) 415 if (blocked)
416 closeWebSocket(websocket); 416 closeWebSocket(websocket);
417 }); 417 });
418 418
419 return websocket; 419 return websocket;
420 }.bind(); 420 }
421 421 WrappedWebSocket.prototype = RealWebSocket.prototype;
422 WebSocket = WrappedWebSocket.bind();
422 Object.defineProperties(WebSocket, { 423 Object.defineProperties(WebSocket, {
423 CONNECTING: {value: RealWebSocket.CONNECTING, enumerable: true}, 424 CONNECTING: {value: RealWebSocket.CONNECTING, enumerable: true},
424 OPEN: {value: RealWebSocket.OPEN, enumerable: true}, 425 OPEN: {value: RealWebSocket.OPEN, enumerable: true},
425 CLOSING: {value: RealWebSocket.CLOSING, enumerable: true}, 426 CLOSING: {value: RealWebSocket.CLOSING, enumerable: true},
426 CLOSED: {value: RealWebSocket.CLOSED, enumerable: true}, 427 CLOSED: {value: RealWebSocket.CLOSED, enumerable: true},
427 prototype: {value: RealWebSocket.prototype} 428 prototype: {value: RealWebSocket.prototype}
428 }); 429 });
429 430
430 RealWebSocket.prototype.constructor = WebSocket; 431 RealWebSocket.prototype.constructor = WebSocket;
431 }, eventName); 432 }, eventName);
(...skipping 20 matching lines...) Expand all
452 453
453 // Use Shadow DOM if available to don't mess with web pages that rely on 454 // Use Shadow DOM if available to don't mess with web pages that rely on
454 // the order of their own <style> tags (#309). 455 // the order of their own <style> tags (#309).
455 // 456 //
456 // However, creating a shadow root breaks running CSS transitions. So we 457 // However, creating a shadow root breaks running CSS transitions. So we
457 // have to create the shadow root before transistions might start (#452). 458 // have to create the shadow root before transistions might start (#452).
458 // 459 //
459 // Also, using shadow DOM causes issues on some Google websites, 460 // Also, using shadow DOM causes issues on some Google websites,
460 // including Google Docs, Gmail and Blogger (#1770, #2602, #2687). 461 // including Google Docs, Gmail and Blogger (#1770, #2602, #2687).
461 // 462 //
462 // Finally since some users have both AdBlock and Adblock Plus installed at 463 // Finally since some users have both AdBlock and Adblock Plus installed we
463 // once we have to be careful not to create the shadowRoot twice! 464 // have to consider how the two extensions interact. For example we want to
465 // avoid creating the shadowRoot twice.
464 if ("createShadowRoot" in document.documentElement && 466 if ("createShadowRoot" in document.documentElement &&
465 !/\.(?:google|blogger)\.com$/.test(document.domain) && 467 !/\.(?:google|blogger)\.com$/.test(document.domain))
466 !document.documentElement.shadowRoot) 468 {
467 { 469 shadow = document.documentElement.shadowRoot ||
468 shadow = document.documentElement.createShadowRoot(); 470 document.documentElement.createShadowRoot();
469 shadow.appendChild(document.createElement("shadow")); 471 shadow.appendChild(document.createElement("shadow"));
470 472
471 // Stop the website from messing with our shadowRoot 473 // Stop the website from messing with our shadowRoot
472 if ("shadowRoot" in Element.prototype) 474 if ("shadowRoot" in Element.prototype)
473 { 475 {
474 runInDocument(document, function() 476 runInDocument(document, function()
475 { 477 {
476 var ourShadowRoot = document.documentElement.shadowRoot; 478 var ourShadowRoot = document.documentElement.shadowRoot;
479 if (!ourShadowRoot)
480 return;
477 var desc = Object.getOwnPropertyDescriptor(Element.prototype, "shadowRoo t"); 481 var desc = Object.getOwnPropertyDescriptor(Element.prototype, "shadowRoo t");
478 var shadowRoot = Function.prototype.call.bind(desc.get); 482 var shadowRoot = Function.prototype.call.bind(desc.get);
479 483
480 Object.defineProperty(Element.prototype, "shadowRoot", { 484 Object.defineProperty(Element.prototype, "shadowRoot", {
481 configurable: true, enumerable: true, get: function() 485 configurable: true, enumerable: true, get: function()
482 { 486 {
483 var shadow = shadowRoot(this); 487 var shadow = shadowRoot(this);
484 return shadow == ourShadowRoot ? null : shadow; 488 return shadow == ourShadowRoot ? null : shadow;
485 } 489 }
486 }); 490 });
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 }, true); 618 }, true);
615 619
616 return updateStylesheet; 620 return updateStylesheet;
617 } 621 }
618 622
619 if (document instanceof HTMLDocument) 623 if (document instanceof HTMLDocument)
620 { 624 {
621 checkSitekey(); 625 checkSitekey();
622 window.updateStylesheet = init(document); 626 window.updateStylesheet = init(document);
623 } 627 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld