Left: | ||
Right: |
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) |
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, 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 Object.defineProperty(WrappedWebSocket, "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 Object.defineProperties(WebSocket, { | 424 Object.defineProperties(WebSocket, { |
423 CONNECTING: {value: RealWebSocket.CONNECTING, enumerable: true}, | 425 CONNECTING: {value: RealWebSocket.CONNECTING, enumerable: true}, |
424 OPEN: {value: RealWebSocket.OPEN, enumerable: true}, | 426 OPEN: {value: RealWebSocket.OPEN, enumerable: true}, |
425 CLOSING: {value: RealWebSocket.CLOSING, enumerable: true}, | 427 CLOSING: {value: RealWebSocket.CLOSING, enumerable: true}, |
426 CLOSED: {value: RealWebSocket.CLOSED, enumerable: true}, | 428 CLOSED: {value: RealWebSocket.CLOSED, enumerable: true}, |
427 prototype: {value: RealWebSocket.prototype} | 429 prototype: {value: RealWebSocket.prototype} |
kzar
2016/08/15 19:29:00
We have to define the prototype here so that `WebS
| |
428 }); | 430 }); |
429 | 431 |
430 RealWebSocket.prototype.constructor = WebSocket; | 432 RealWebSocket.prototype.constructor = WebSocket; |
431 }, eventName); | 433 }, eventName); |
432 } | 434 } |
433 | 435 |
434 function init(document) | 436 function init(document) |
435 { | 437 { |
436 var shadow = null; | 438 var shadow = null; |
437 var style = null; | 439 var style = null; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 }, true); | 612 }, true); |
611 | 613 |
612 return updateStylesheet; | 614 return updateStylesheet; |
613 } | 615 } |
614 | 616 |
615 if (document instanceof HTMLDocument) | 617 if (document instanceof HTMLDocument) |
616 { | 618 { |
617 checkSitekey(); | 619 checkSitekey(); |
618 window.updateStylesheet = init(document); | 620 window.updateStylesheet = init(document); |
619 } | 621 } |
OLD | NEW |