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

Delta Between Two Patch Sets: include.preload.js

Issue 29349737: Issue 1727 - Fix WebSocket constructor without second argument in Chrome 47 (Closed)
Left Patch Set: Rebased Created Aug. 11, 2016, 2:25 p.m.
Right Patch Set: Omit the second argument if absent Created Aug. 11, 2016, 3:38 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 new CustomEvent(eventName + "-" + event.detail.url, {detail: block}) 372 new CustomEvent(eventName + "-" + event.detail.url, {detail: block})
373 ); 373 );
374 }); 374 });
375 }); 375 });
376 376
377 runInDocument(document, function(eventName) 377 runInDocument(document, function(eventName)
378 { 378 {
379 // As far as possible we must track everything we use that could be 379 // As far as possible we must track everything we use that could be
380 // sabotaged by the website later in order to circumvent us. 380 // sabotaged by the website later in order to circumvent us.
381 var RealWebSocket = WebSocket; 381 var RealWebSocket = WebSocket;
382 var bindWebSocket = Function.prototype.bind.apply.bind(Function.prototype.bi nd, RealWebSocket);
383 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose); 382 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose);
384 var addEventListener = document.addEventListener.bind(document); 383 var addEventListener = document.addEventListener.bind(document);
385 var removeEventListener = document.removeEventListener.bind(document); 384 var removeEventListener = document.removeEventListener.bind(document);
386 var dispatchEvent = document.dispatchEvent.bind(document); 385 var dispatchEvent = document.dispatchEvent.bind(document);
387 var CustomEvent = window.CustomEvent; 386 var CustomEvent = window.CustomEvent;
388 387
389 function checkRequest(url, callback) 388 function checkRequest(url, callback)
390 { 389 {
391 var incomingEventName = eventName + "-" + url; 390 var incomingEventName = eventName + "-" + url;
392 function listener(event) 391 function listener(event)
393 { 392 {
394 callback(event.detail); 393 callback(event.detail);
395 removeEventListener(incomingEventName, listener); 394 removeEventListener(incomingEventName, listener);
396 } 395 }
397 addEventListener(incomingEventName, listener); 396 addEventListener(incomingEventName, listener);
398 397
399 dispatchEvent(new CustomEvent(eventName, { 398 dispatchEvent(new CustomEvent(eventName, {
400 detail: {url: url} 399 detail: {url: url}
401 })); 400 }));
402 } 401 }
403 402
404 WebSocket = function WrappedWebSocket() 403 WebSocket = function WrappedWebSocket(url, protocols)
405 { 404 {
406 var args = [this]; 405 // Throw correct exceptions if the constructor is used improperly.
407 for (var i = 0; i < arguments.length; i++) 406 if (!(this instanceof WrappedWebSocket)) return RealWebSocket();
408 args.push(arguments[i]); 407 if (arguments.length < 1) return new RealWebSocket();
409 408
410 var ctor = bindWebSocket(args); 409 var websocket;
411 var websocket = this instanceof WrappedWebSocket ? new ctor : ctor(); 410 if (arguments.length == 1)
411 websocket = new RealWebSocket(url);
412 else
413 websocket = new RealWebSocket(url, protocols);
Wladimir Palant 2016/08/15 12:33:24 Why make assumptions about the arguments in the fi
Wladimir Palant 2016/08/15 12:45:36 This will also allow dropping protocols parameter
Wladimir Palant 2016/08/15 13:01:24 Never mind, calling RealWebSocket.apply() won't wo
Sebastian Noack 2016/08/15 13:06:10 See patchset #2 (and the related discussin) for a
412 414
413 checkRequest(websocket.url, function(blocked) 415 checkRequest(websocket.url, function(blocked)
414 { 416 {
415 if (blocked) 417 if (blocked)
416 closeWebSocket(websocket); 418 closeWebSocket(websocket);
417 }); 419 });
418 420
419 return websocket; 421 return websocket;
420 }.bind(); 422 }.bind();
421 423
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 }, true); 618 }, true);
617 619
618 return updateStylesheet; 620 return updateStylesheet;
619 } 621 }
620 622
621 if (document instanceof HTMLDocument) 623 if (document instanceof HTMLDocument)
622 { 624 {
623 checkSitekey(); 625 checkSitekey();
624 window.updateStylesheet = init(document); 626 window.updateStylesheet = init(document);
625 } 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