| 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 function runInPageContext(fn, arg) | 338 function runInPageContext(fn, arg) |
| 339 { | 339 { |
| 340 var script = document.createElement("script"); | 340 var script = document.createElement("script"); |
| 341 script.type = "application/javascript"; | 341 script.type = "application/javascript"; |
| 342 script.async = false; | 342 script.async = false; |
| 343 script.textContent = "(" + fn + ")(" + JSON.stringify(arg) + ");"; | 343 script.textContent = "(" + fn + ")(" + JSON.stringify(arg) + ");"; |
| 344 document.documentElement.appendChild(script); | 344 document.documentElement.appendChild(script); |
| 345 document.documentElement.removeChild(script); | 345 document.documentElement.removeChild(script); |
| 346 } | 346 } |
| 347 | 347 |
| 348 // Neither Chrome[1] nor Safari allow us to intercept WebSockets, and therefore | 348 // Chrome doesn't allow us to intercept WebSockets[1], and therefore |
| 349 // some ad networks are misusing them as a way to serve adverts and circumvent | 349 // some ad networks are misusing them as a way to serve adverts and circumvent |
| 350 // us. As a workaround we wrap WebSocket, preventing blocked WebSocket | 350 // us. As a workaround we wrap WebSocket, preventing blocked WebSocket |
| 351 // connections from being opened. | 351 // connections from being opened. |
| 352 // [1] - https://bugs.chromium.org/p/chromium/issues/detail?id=129353 | 352 // [1] - https://bugs.chromium.org/p/chromium/issues/detail?id=129353 |
| 353 function wrapWebSocket() | 353 function wrapWebSocket() |
| 354 { | 354 { |
| 355 if (typeof WebSocket == "undefined") | |
| 356 return; | |
| 357 | |
| 358 var eventName = "abpws-" + Math.random().toString(36).substr(2); | 355 var eventName = "abpws-" + Math.random().toString(36).substr(2); |
| 359 | 356 |
| 360 document.addEventListener(eventName, function(event) | 357 document.addEventListener(eventName, function(event) |
| 361 { | 358 { |
| 362 ext.backgroundPage.sendMessage({ | 359 ext.backgroundPage.sendMessage({ |
| 363 type: "request.websocket", | 360 type: "request.websocket", |
| 364 url: event.detail.url | 361 url: event.detail.url |
| 365 }, function (block) | 362 }, function (block) |
| 366 { | 363 { |
| 367 document.dispatchEvent( | 364 document.dispatchEvent( |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 checkCollapse(event.target); | 632 checkCollapse(event.target); |
| 636 }, true); | 633 }, true); |
| 637 | 634 |
| 638 document.addEventListener("load", function(event) | 635 document.addEventListener("load", function(event) |
| 639 { | 636 { |
| 640 var element = event.target; | 637 var element = event.target; |
| 641 if (/^i?frame$/.test(element.localName)) | 638 if (/^i?frame$/.test(element.localName)) |
| 642 checkCollapse(element); | 639 checkCollapse(element); |
| 643 }, true); | 640 }, true); |
| 644 } | 641 } |
| OLD | NEW |