| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 configurable: true, enumerable: true, get() | 131 configurable: true, enumerable: true, get() |
| 132 { | 132 { |
| 133 let thisShadow = shadowRoot(this); | 133 let thisShadow = shadowRoot(this); |
| 134 return thisShadow == ourShadowRoot ? null : thisShadow; | 134 return thisShadow == ourShadowRoot ? null : thisShadow; |
| 135 } | 135 } |
| 136 }); | 136 }); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 /* | 140 /* |
| 141 * Shared request checking code, used by both the WebSocket and | 141 * Shared request checking code, used by the RTCPeerConnection wrapper. |
|
Sebastian Noack
2018/03/13 17:43:01
Well, it's no longer shared. We probably should ju
Manish Jethani
2018/03/13 18:05:11
Done.
| |
| 142 * RTCPeerConnection wrappers. | |
| 143 */ | 142 */ |
| 144 let RealCustomEvent = window.CustomEvent; | 143 let RealCustomEvent = window.CustomEvent; |
| 145 | 144 |
| 146 // If we've been injected into a frame via contentWindow then we can simply | 145 // If we've been injected into a frame via contentWindow then we can simply |
| 147 // grab the copy of checkRequest left for us by the parent document. Otherwise | 146 // grab the copy of checkRequest left for us by the parent document. Otherwise |
| 148 // we need to set it up now, along with the event handling functions. | 147 // we need to set it up now, along with the event handling functions. |
| 149 if (injectedIntoContentWindow) | 148 if (injectedIntoContentWindow) |
| 150 checkRequest = window[eventName]; | 149 checkRequest = window[eventName]; |
| 151 else | 150 else |
| 152 { | 151 { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 176 { | 175 { |
| 177 if (src.hasOwnProperty(name)) | 176 if (src.hasOwnProperty(name)) |
| 178 { | 177 { |
| 179 Object.defineProperty(dest, name, | 178 Object.defineProperty(dest, name, |
| 180 Object.getOwnPropertyDescriptor(src, name)); | 179 Object.getOwnPropertyDescriptor(src, name)); |
| 181 } | 180 } |
| 182 } | 181 } |
| 183 } | 182 } |
| 184 | 183 |
| 185 /* | 184 /* |
| 186 * WebSocket wrapper | |
| 187 * | |
| 188 * Required before Chrome 58, since the webRequest API didn't allow us to | |
| 189 * intercept WebSockets. | |
| 190 * See https://bugs.chromium.org/p/chromium/issues/detail?id=129353 | |
| 191 */ | |
| 192 let RealWebSocket = WebSocket; | |
| 193 let closeWebSocket = Function.prototype.call.bind( | |
| 194 RealWebSocket.prototype.close | |
| 195 ); | |
| 196 | |
| 197 function WrappedWebSocket(url, ...args) | |
| 198 { | |
| 199 // Throw correct exceptions if the constructor is used improperly. | |
| 200 if (!(this instanceof WrappedWebSocket)) return RealWebSocket(); | |
| 201 if (arguments.length < 1) return new RealWebSocket(); | |
| 202 | |
| 203 let websocket = new RealWebSocket(url, ...args); | |
| 204 | |
| 205 checkRequest("websocket", websocket.url, blocked => | |
| 206 { | |
| 207 if (blocked) | |
| 208 closeWebSocket(websocket); | |
| 209 }); | |
| 210 | |
| 211 return websocket; | |
| 212 } | |
| 213 WrappedWebSocket.prototype = RealWebSocket.prototype; | |
| 214 window.WebSocket = WrappedWebSocket.bind(); | |
| 215 copyProperties(RealWebSocket, WebSocket, | |
| 216 ["CONNECTING", "OPEN", "CLOSING", "CLOSED", "prototype"]); | |
| 217 RealWebSocket.prototype.constructor = WebSocket; | |
| 218 | |
| 219 /* | |
| 220 * RTCPeerConnection wrapper | 185 * RTCPeerConnection wrapper |
| 221 * | 186 * |
| 222 * The webRequest API in Chrome does not yet allow the blocking of | 187 * The webRequest API in Chrome does not yet allow the blocking of |
| 223 * WebRTC connections. | 188 * WebRTC connections. |
| 224 * See https://bugs.chromium.org/p/chromium/issues/detail?id=707683 | 189 * See https://bugs.chromium.org/p/chromium/issues/detail?id=707683 |
| 225 */ | 190 */ |
| 226 let RealRTCPeerConnection = window.RTCPeerConnection || | 191 let RealRTCPeerConnection = window.RTCPeerConnection || |
| 227 window.webkitRTCPeerConnection; | 192 window.webkitRTCPeerConnection; |
| 228 | 193 |
| 229 // Firefox has the option (media.peerconnection.enabled) to disable WebRTC | 194 // Firefox has the option (media.peerconnection.enabled) to disable WebRTC |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 // Firefox 58 only bypasses site CSPs when assigning to 'src'. | 373 // Firefox 58 only bypasses site CSPs when assigning to 'src'. |
| 409 let url = URL.createObjectURL(new Blob([ | 374 let url = URL.createObjectURL(new Blob([ |
| 410 "(" + injected + ")('" + randomEventName + "');" | 375 "(" + injected + ")('" + randomEventName + "');" |
| 411 ])); | 376 ])); |
| 412 script.src = url; | 377 script.src = url; |
| 413 document.documentElement.appendChild(script); | 378 document.documentElement.appendChild(script); |
| 414 document.documentElement.removeChild(script); | 379 document.documentElement.removeChild(script); |
| 415 URL.revokeObjectURL(url); | 380 URL.revokeObjectURL(url); |
| 416 } | 381 } |
| 417 } | 382 } |
| OLD | NEW |