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

Delta Between Two Patch Sets: include.preload.js

Issue 29349816: Fixes 4331, 4332 - WebSocket.length and instanceof WebSocket (Closed)
Left Patch Set: Created Aug. 15, 2016, 7:22 p.m.
Right Patch Set: Assign WrappedWebSocket.prototype more simply Created Aug. 15, 2016, 8:35 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 | lib/requestBlocker.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-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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 function WrappedWebSocket(url) 401 function WrappedWebSocket(url)
kzar 2016/08/15 19:29:00 For some reason if I did this in one step I no lon
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, arguments[1]); 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 } 420 }
421 Object.defineProperty(WrappedWebSocket, "prototype", 421 WrappedWebSocket.prototype = RealWebSocket.prototype;
422 {value: RealWebSocket.prototype});
kzar 2016/08/15 19:29:00 We have to define the prototype here so that `...
Wladimir Palant 2016/08/15 20:20:35 Since the website cannot access WrappedWebSocket,
kzar 2016/08/15 20:36:21 Done.
423 WebSocket = WrappedWebSocket.bind(); 422 WebSocket = WrappedWebSocket.bind();
424 Object.defineProperties(WebSocket, { 423 Object.defineProperties(WebSocket, {
425 CONNECTING: {value: RealWebSocket.CONNECTING, enumerable: true}, 424 CONNECTING: {value: RealWebSocket.CONNECTING, enumerable: true},
426 OPEN: {value: RealWebSocket.OPEN, enumerable: true}, 425 OPEN: {value: RealWebSocket.OPEN, enumerable: true},
427 CLOSING: {value: RealWebSocket.CLOSING, enumerable: true}, 426 CLOSING: {value: RealWebSocket.CLOSING, enumerable: true},
428 CLOSED: {value: RealWebSocket.CLOSED, enumerable: true}, 427 CLOSED: {value: RealWebSocket.CLOSED, enumerable: true},
429 prototype: {value: RealWebSocket.prototype} 428 prototype: {value: RealWebSocket.prototype}
kzar 2016/08/15 19:29:00 We have to define the prototype here so that `WebS
430 }); 429 });
431 430
432 RealWebSocket.prototype.constructor = WebSocket; 431 RealWebSocket.prototype.constructor = WebSocket;
433 }, eventName); 432 }, eventName);
434 } 433 }
435 434
436 function init(document) 435 function init(document)
437 { 436 {
438 var shadow = null; 437 var shadow = null;
439 var style = null; 438 var style = null;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 }, true); 611 }, true);
613 612
614 return updateStylesheet; 613 return updateStylesheet;
615 } 614 }
616 615
617 if (document instanceof HTMLDocument) 616 if (document instanceof HTMLDocument)
618 { 617 {
619 checkSitekey(); 618 checkSitekey();
620 window.updateStylesheet = init(document); 619 window.updateStylesheet = init(document);
621 } 620 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld