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

Side by Side Diff: include.preload.js

Issue 29349737: Issue 1727 - Fix WebSocket constructor without second argument in Chrome 47 (Closed)
Patch Set: Created Aug. 11, 2016, 2:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 new CustomEvent(eventName + "-" + event.detail.url, {detail: block}) 366 new CustomEvent(eventName + "-" + event.detail.url, {detail: block})
367 ); 367 );
368 }); 368 });
369 }); 369 });
370 370
371 runInDocument(document, function(eventName) 371 runInDocument(document, function(eventName)
372 { 372 {
373 // As far as possible we must track everything we use that could be 373 // As far as possible we must track everything we use that could be
374 // sabotaged by the website later in order to circumvent us. 374 // sabotaged by the website later in order to circumvent us.
375 var RealWebSocket = WebSocket; 375 var RealWebSocket = WebSocket;
376 var bindWebSocket = Function.prototype.bind.apply.bind(Function.prototype.bi nd, RealWebSocket);
376 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose); 377 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose);
377 var addEventListener = document.addEventListener.bind(document); 378 var addEventListener = document.addEventListener.bind(document);
378 var removeEventListener = document.removeEventListener.bind(document); 379 var removeEventListener = document.removeEventListener.bind(document);
379 var dispatchEvent = document.dispatchEvent.bind(document); 380 var dispatchEvent = document.dispatchEvent.bind(document);
380 var CustomEvent = window.CustomEvent; 381 var CustomEvent = window.CustomEvent;
381 382
382 function checkRequest(url, callback) 383 function checkRequest(url, callback)
383 { 384 {
384 var incomingEventName = eventName + "-" + url; 385 var incomingEventName = eventName + "-" + url;
385 function listener(event) 386 function listener(event)
386 { 387 {
387 callback(event.detail); 388 callback(event.detail);
388 removeEventListener(incomingEventName, listener); 389 removeEventListener(incomingEventName, listener);
389 } 390 }
390 addEventListener(incomingEventName, listener); 391 addEventListener(incomingEventName, listener);
391 392
392 dispatchEvent(new CustomEvent(eventName, { 393 dispatchEvent(new CustomEvent(eventName, {
393 detail: {url: url} 394 detail: {url: url}
394 })); 395 }));
395 } 396 }
396 397
397 WebSocket = function WrappedWebSocket(url, protocols) 398 WebSocket = function WrappedWebSocket()
398 { 399 {
399 // Throw correct exceptions if the constructor is used improperly. 400 var args = [null];
kzar 2016/08/11 14:25:05 I think this approach is extremely hard to follow,
Sebastian Noack 2016/08/11 14:38:46 Well, if you'd write your logic compliant to our c
kzar 2016/08/11 14:54:16 I didn't say anything about the code being shorter
Sebastian Noack 2016/08/11 15:11:35 I don't think that I agree. But there you go.
400 if (!(this instanceof WrappedWebSocket)) return RealWebSocket(); 401 for (var i = 0; i < arguments.length; i++)
401 if (arguments.length < 1) return new RealWebSocket(); 402 args.push(arguments[i]);
kzar 2016/08/11 14:25:05 This would allow for circumvention since we didn't
Sebastian Noack 2016/08/11 14:38:46 Well spotted, fixed.
402 403
403 var websocket = new RealWebSocket(url, protocols); 404 var ctor = bindWebSocket(args);
405 var websocket = this instanceof WrappedWebSocket ? new ctor : ctor();
404 406
405 checkRequest(websocket.url, function(blocked) 407 checkRequest(websocket.url, function(blocked)
406 { 408 {
407 if (blocked) 409 if (blocked)
408 closeWebSocket(websocket); 410 closeWebSocket(websocket);
409 }); 411 });
410 412
411 return websocket; 413 return websocket;
412 }.bind(); 414 }.bind();
413 415
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 }, true); 610 }, true);
609 611
610 return updateStylesheet; 612 return updateStylesheet;
611 } 613 }
612 614
613 if (document instanceof HTMLDocument) 615 if (document instanceof HTMLDocument)
614 { 616 {
615 checkSitekey(); 617 checkSitekey();
616 window.updateStylesheet = init(document); 618 window.updateStylesheet = init(document);
617 } 619 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld