From d676864211a6992fd784e466b6cca777f65be29c Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 2 May 2016 14:30:24 -0400 Subject: [PATCH] #1604: remove now unreachable code --- platform/chromium/vapi-client.js | 216 ------------------------------- 1 file changed, 216 deletions(-) diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index b86c8e34e..34865ed07 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -338,222 +338,6 @@ vAPI.shutdown.add(function() { // https://www.youtube.com/watch?v=rT5zCHn0tsg // https://www.youtube.com/watch?v=E-jS4e3zacI -/******************************************************************************/ - -// https://bugs.chromium.org/p/chromium/issues/detail?id=129353 -// https://github.com/gorhill/uBlock/issues/956 -// https://github.com/gorhill/uBlock/issues/1497 -// Trap calls to WebSocket constructor, and expose websocket-based network -// requests to uBO's filtering engine, logger, etc. -// Counterpart of following block of code is found in "vapi-background.js" -- -// search for "https://github.com/gorhill/uBlock/issues/1497". - -/* jshint multistr: true */ - -(function() { - // https://github.com/gorhill/uBlock/issues/1604 - return; - - // Fix won't be applied on older versions of Chromium. - if ( - window.WebSocket instanceof Function === false || - window.WeakMap instanceof Function === false - ) { - return; - } - - // Only for http/https documents. - if ( /^https?:/.test(window.location.protocol) !== true ) { - return; - } - - var doc = document; - var parent = doc.head || doc.documentElement; - if ( parent === null ) { - return; - } - - // WebSocket reference: https://html.spec.whatwg.org/multipage/comms.html - // The script tag will remove itself from the DOM once it completes - // execution. - // Ideally, the `js/websocket.js` script would be declared as a - // `web_accessible_resources` in the manifest, but this unfortunately would - // open the door for web pages to identify *directly* that one is using - // uBlock Origin. Consequently, I have to inject the code as a literal - // string below :( - // For code review, the stringified code below is found in - // `js/websocket.js` (comments and empty lines were stripped). - var script = doc.createElement('script'); - script.textContent = "\ - (function() { \n\ - 'use strict'; \n\ - var Wrapped = window.WebSocket; \n\ - var toWrapped = new WeakMap(); \n\ - var onResponseReceived = function(wrapper, ok) { \n\ - this.onload = this.onerror = null; \n\ - var bag = toWrapped.get(wrapper); \n\ - if ( !ok ) { \n\ - if ( bag.properties.onerror ) { \n\ - bag.properties.onerror(new window.ErrorEvent('error')); \n\ - } \n\ - return; \n\ - } \n\ - var wrapped = new Wrapped(bag.args.url, bag.args.protocols); \n\ - for ( var prop in bag.properties ) { \n\ - wrapped[prop] = bag.properties[prop]; \n\ - } \n\ - toWrapped.set(wrapper, wrapped); \n\ - }; \n\ - var noopfn = function() {}; \n\ - var fallthruGet = function(wrapper, prop, value) { \n\ - var wrapped = toWrapped.get(wrapper); \n\ - if ( !wrapped ) { \n\ - return value; \n\ - } \n\ - if ( wrapped instanceof Wrapped ) { \n\ - return wrapped[prop]; \n\ - } \n\ - return wrapped.properties.hasOwnProperty(prop) ? \n\ - wrapped.properties[prop] : \n\ - value; \n\ - }; \n\ - var fallthruSet = function(wrapper, prop, value) { \n\ - if ( value instanceof Function ) { \n\ - value = value.bind(wrapper); \n\ - } \n\ - var wrapped = toWrapped.get(wrapper); \n\ - if ( !wrapped ) { \n\ - return; \n\ - } \n\ - if ( wrapped instanceof Wrapped ) { \n\ - wrapped[prop] = value; \n\ - } else { \n\ - wrapped.properties[prop] = value; \n\ - } \n\ - }; \n\ - var WebSocket = function(url, protocols) { \n\ - if ( \n\ - window.location.protocol === 'https:' && \n\ - url.lastIndexOf('ws:', 0) === 0 \n\ - ) { \n\ - var ws = new Wrapped(url, protocols); \n\ - if ( ws ) { \n\ - ws.close(); \n\ - } \n\ - } \n\ - Object.defineProperties(this, { \n\ - 'binaryType': { \n\ - get: function() { \n\ - return fallthruGet(this, 'binaryType', ''); \n\ - }, \n\ - set: function(value) { \n\ - fallthruSet(this, 'binaryType', value); \n\ - } \n\ - }, \n\ - 'bufferedAmount': { \n\ - get: function() { \n\ - return fallthruGet(this, 'bufferedAmount', 0); \n\ - }, \n\ - set: noopfn \n\ - }, \n\ - 'extensions': { \n\ - get: function() { \n\ - return fallthruGet(this, 'extensions', ''); \n\ - }, \n\ - set: noopfn \n\ - }, \n\ - 'onclose': { \n\ - get: function() { \n\ - return fallthruGet(this, 'onclose', null); \n\ - }, \n\ - set: function(value) { \n\ - fallthruSet(this, 'onclose', value); \n\ - } \n\ - }, \n\ - 'onerror': { \n\ - get: function() { \n\ - return fallthruGet(this, 'onerror', null); \n\ - }, \n\ - set: function(value) { \n\ - fallthruSet(this, 'onerror', value); \n\ - } \n\ - }, \n\ - 'onmessage': { \n\ - get: function() { \n\ - return fallthruGet(this, 'onmessage', null); \n\ - }, \n\ - set: function(value) { \n\ - fallthruSet(this, 'onmessage', value); \n\ - } \n\ - }, \n\ - 'onopen': { \n\ - get: function() { \n\ - return fallthruGet(this, 'onopen', null); \n\ - }, \n\ - set: function(value) { \n\ - fallthruSet(this, 'onopen', value); \n\ - } \n\ - }, \n\ - 'protocol': { \n\ - get: function() { \n\ - return fallthruGet(this, 'protocol', ''); \n\ - }, \n\ - set: noopfn \n\ - }, \n\ - 'readyState': { \n\ - get: function() { \n\ - return fallthruGet(this, 'readyState', 0); \n\ - }, \n\ - set: noopfn \n\ - }, \n\ - 'url': { \n\ - get: function() { \n\ - return fallthruGet(this, 'url', ''); \n\ - }, \n\ - set: noopfn \n\ - } \n\ - }); \n\ - toWrapped.set(this, { \n\ - args: { url: url, protocols: protocols }, \n\ - properties: {} \n\ - }); \n\ - var img = new Image(); \n\ - img.src = \n\ - window.location.origin \n\ - + '?url=' + encodeURIComponent(url) \n\ - + '&ubofix=f41665f3028c7fd10eecf573336216d3'; \n\ - img.onload = onResponseReceived.bind(img, this, true); \n\ - img.onerror = onResponseReceived.bind(img, this, false); \n\ - }; \n\ - WebSocket.prototype.CONNECTING = 0; \n\ - WebSocket.prototype.OPEN = 1; \n\ - WebSocket.prototype.CLOSING = 2; \n\ - WebSocket.prototype.CLOSED = 3; \n\ - WebSocket.prototype.close = function(code, reason) { \n\ - var wrapped = toWrapped.get(this); \n\ - if ( wrapped instanceof Wrapped ) { \n\ - wrapped.close(code, reason); \n\ - } \n\ - }; \n\ - WebSocket.prototype.send = function(data) { \n\ - var wrapped = toWrapped.get(this); \n\ - if ( wrapped instanceof Wrapped ) { \n\ - wrapped.send(data); \n\ - } \n\ - }; \n\ - window.WebSocket = WebSocket; \n\ - var me = document.currentScript; \n\ - if ( me && me.parentNode !== null ) { \n\ - me.parentNode.removeChild(me); \n\ - } \n\ - })();"; - - try { - parent.appendChild(script); - } catch (ex) { - } -})(); - /******************************************************************************/ /******************************************************************************/