| 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 }, true); | 611 }, true); |
| 611 | 612 |
| 612 return updateStylesheet; | 613 return updateStylesheet; |
| 613 } | 614 } |
| 614 | 615 |
| 615 if (document instanceof HTMLDocument) | 616 if (document instanceof HTMLDocument) |
| 616 { | 617 { |
| 617 checkSitekey(); | 618 checkSitekey(); |
| 618 window.updateStylesheet = init(document); | 619 window.updateStylesheet = init(document); |
| 619 } | 620 } |
| OLD | NEW |