| Index: inject.preload.js |
| =================================================================== |
| --- a/inject.preload.js |
| +++ b/inject.preload.js |
| @@ -18,26 +18,25 @@ |
| "use strict"; |
| let randomEventName = "abp-request-" + Math.random().toString(36).substr(2); |
| // Proxy "should we block?" messages from checkRequest inside the injected |
| // code to the background page and back again. |
| document.addEventListener(randomEventName, event => |
| { |
| - let {url, requestType} = event.detail; |
| + let {url} = event.detail; |
| browser.runtime.sendMessage({ |
| - type: "request.blockedByWrapper", |
| - requestType, |
| + type: "request.blockedByRTCWrapper", |
| url |
| }, block => |
| { |
| document.dispatchEvent(new CustomEvent( |
| - randomEventName + "-" + requestType + "-" + url, {detail: block} |
| + randomEventName + "-" + url, {detail: block} |
| )); |
| }); |
| }); |
| function injected(eventName, injectedIntoContentWindow) |
| { |
| let checkRequest; |
| @@ -133,103 +132,64 @@ |
| let thisShadow = shadowRoot(this); |
| return thisShadow == ourShadowRoot ? null : thisShadow; |
| } |
| }); |
| } |
| } |
| /* |
| - * Shared request checking code, used by both the WebSocket and |
| - * RTCPeerConnection wrappers. |
| + * RTCPeerConnection wrapper |
| + * |
| + * The webRequest API in Chrome does not yet allow the blocking of |
| + * WebRTC connections. |
| + * See https://bugs.chromium.org/p/chromium/issues/detail?id=707683 |
| */ |
| let RealCustomEvent = window.CustomEvent; |
| // If we've been injected into a frame via contentWindow then we can simply |
| // grab the copy of checkRequest left for us by the parent document. Otherwise |
| // we need to set it up now, along with the event handling functions. |
| if (injectedIntoContentWindow) |
| checkRequest = window[eventName]; |
| else |
| { |
| let addEventListener = document.addEventListener.bind(document); |
| let dispatchEvent = document.dispatchEvent.bind(document); |
| let removeEventListener = document.removeEventListener.bind(document); |
| - checkRequest = (requestType, url, callback) => |
| + checkRequest = (url, callback) => |
| { |
| - let incomingEventName = eventName + "-" + requestType + "-" + url; |
| + let incomingEventName = eventName + "-" + url; |
| function listener(event) |
| { |
| callback(event.detail); |
| removeEventListener(incomingEventName, listener); |
| } |
| addEventListener(incomingEventName, listener); |
| - dispatchEvent(new RealCustomEvent(eventName, |
| - {detail: {url, requestType}})); |
| + dispatchEvent(new RealCustomEvent(eventName, {detail: {url}})); |
| }; |
| } |
| // Only to be called before the page's code, not hardened. |
| function copyProperties(src, dest, properties) |
| { |
| for (let name of properties) |
| { |
| if (src.hasOwnProperty(name)) |
| { |
| Object.defineProperty(dest, name, |
| Object.getOwnPropertyDescriptor(src, name)); |
| } |
| } |
| } |
| - /* |
| - * WebSocket wrapper |
| - * |
| - * Required before Chrome 58, since the webRequest API didn't allow us to |
| - * intercept WebSockets. |
| - * See https://bugs.chromium.org/p/chromium/issues/detail?id=129353 |
| - */ |
| - let RealWebSocket = WebSocket; |
| - let closeWebSocket = Function.prototype.call.bind( |
| - RealWebSocket.prototype.close |
| - ); |
| - |
| - function WrappedWebSocket(url, ...args) |
| - { |
| - // Throw correct exceptions if the constructor is used improperly. |
| - if (!(this instanceof WrappedWebSocket)) return RealWebSocket(); |
| - if (arguments.length < 1) return new RealWebSocket(); |
| - |
| - let websocket = new RealWebSocket(url, ...args); |
| - |
| - checkRequest("websocket", websocket.url, blocked => |
| - { |
| - if (blocked) |
| - closeWebSocket(websocket); |
| - }); |
| - |
| - return websocket; |
| - } |
| - WrappedWebSocket.prototype = RealWebSocket.prototype; |
| - window.WebSocket = WrappedWebSocket.bind(); |
| - copyProperties(RealWebSocket, WebSocket, |
| - ["CONNECTING", "OPEN", "CLOSING", "CLOSED", "prototype"]); |
| - RealWebSocket.prototype.constructor = WebSocket; |
| - |
| - /* |
| - * RTCPeerConnection wrapper |
| - * |
| - * The webRequest API in Chrome does not yet allow the blocking of |
| - * WebRTC connections. |
| - * See https://bugs.chromium.org/p/chromium/issues/detail?id=707683 |
| - */ |
| let RealRTCPeerConnection = window.RTCPeerConnection || |
| - window.webkitRTCPeerConnection; |
| + window.webkitRTCPeerConnection; |
| // Firefox has the option (media.peerconnection.enabled) to disable WebRTC |
| // in which case RealRTCPeerConnection is undefined. |
| if (typeof RealRTCPeerConnection != "undefined") |
| { |
| let closeRTCPeerConnection = Function.prototype.call.bind( |
| RealRTCPeerConnection.prototype.close |
| ); |
| @@ -300,17 +260,17 @@ |
| configurable: false, enumerable: false, writable: false, |
| value: iceServers |
| } |
| }); |
| }; |
| let checkUrl = (peerconnection, url) => |
| { |
| - checkRequest("webrtc", url, blocked => |
| + checkRequest(url, blocked => |
| { |
| if (blocked) |
| { |
| // Calling .close() throws if already closed. |
| try |
| { |
| closeRTCPeerConnection(peerconnection); |
| } |