OLD | NEW |
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 Loading... |
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); |
382 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl
ose); | 383 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl
ose); |
383 var addEventListener = document.addEventListener.bind(document); | 384 var addEventListener = document.addEventListener.bind(document); |
384 var removeEventListener = document.removeEventListener.bind(document); | 385 var removeEventListener = document.removeEventListener.bind(document); |
385 var dispatchEvent = document.dispatchEvent.bind(document); | 386 var dispatchEvent = document.dispatchEvent.bind(document); |
386 var CustomEvent = window.CustomEvent; | 387 var CustomEvent = window.CustomEvent; |
387 | 388 |
388 function checkRequest(url, callback) | 389 function checkRequest(url, callback) |
389 { | 390 { |
390 var incomingEventName = eventName + "-" + url; | 391 var incomingEventName = eventName + "-" + url; |
391 function listener(event) | 392 function listener(event) |
392 { | 393 { |
393 callback(event.detail); | 394 callback(event.detail); |
394 removeEventListener(incomingEventName, listener); | 395 removeEventListener(incomingEventName, listener); |
395 } | 396 } |
396 addEventListener(incomingEventName, listener); | 397 addEventListener(incomingEventName, listener); |
397 | 398 |
398 dispatchEvent(new CustomEvent(eventName, { | 399 dispatchEvent(new CustomEvent(eventName, { |
399 detail: {url: url} | 400 detail: {url: url} |
400 })); | 401 })); |
401 } | 402 } |
402 | 403 |
403 WebSocket = function WrappedWebSocket(url, protocols) | 404 WebSocket = function WrappedWebSocket() |
404 { | 405 { |
405 // Throw correct exceptions if the constructor is used improperly. | 406 var args = [this]; |
406 if (!(this instanceof WrappedWebSocket)) return RealWebSocket(); | 407 for (var i = 0; i < arguments.length; i++) |
407 if (arguments.length < 1) return new RealWebSocket(); | 408 args[i + 1] = arguments[i]; |
408 | 409 |
409 var websocket = new RealWebSocket(url, protocols); | 410 var ctor = bindWebSocket(args); |
| 411 var websocket = this instanceof WrappedWebSocket ? new ctor : ctor(); |
410 | 412 |
411 checkRequest(websocket.url, function(blocked) | 413 checkRequest(websocket.url, function(blocked) |
412 { | 414 { |
413 if (blocked) | 415 if (blocked) |
414 closeWebSocket(websocket); | 416 closeWebSocket(websocket); |
415 }); | 417 }); |
416 | 418 |
417 return websocket; | 419 return websocket; |
418 }.bind(); | 420 }.bind(); |
419 | 421 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 }, true); | 616 }, true); |
615 | 617 |
616 return updateStylesheet; | 618 return updateStylesheet; |
617 } | 619 } |
618 | 620 |
619 if (document instanceof HTMLDocument) | 621 if (document instanceof HTMLDocument) |
620 { | 622 { |
621 checkSitekey(); | 623 checkSitekey(); |
622 window.updateStylesheet = init(document); | 624 window.updateStylesheet = init(document); |
623 } | 625 } |
OLD | NEW |