From 5b5b747494742eddf2bab63f29c1e4a25d59efc9 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 4 Dec 2020 16:44:54 +0100 Subject: [PATCH] Remove many small, obsolete, old browser hacks These are for browsers no longer supported anyway. --- app/ui.js | 5 ----- core/display.js | 3 +-- core/input/util.js | 20 -------------------- core/input/vkeys.js | 1 - core/rfb.js | 33 ++++++--------------------------- core/util/cursor.js | 3 --- core/util/events.js | 4 ---- core/util/polyfill.js | 38 -------------------------------------- core/websock.js | 9 +-------- tests/assertions.js | 6 ++---- tests/test.display.js | 21 --------------------- tests/test.helper.js | 3 --- tests/test.rfb.js | 7 +------ vnc.html | 4 ---- vnc_lite.html | 4 ---- 15 files changed, 11 insertions(+), 150 deletions(-) diff --git a/app/ui.js b/app/ui.js index fd3d036..8e2e78f 100644 --- a/app/ui.js +++ b/app/ui.js @@ -761,11 +761,6 @@ const UI = { } } } else { - /*Weird IE9 error leads to 'null' appearring - in textboxes instead of ''.*/ - if (value === null) { - value = ""; - } ctrl.value = value; } }, diff --git a/core/display.js b/core/display.js index 8eaa800..01b1100 100644 --- a/core/display.js +++ b/core/display.js @@ -494,8 +494,7 @@ export default class Display { this.blitImage(a.x, a.y, a.width, a.height, a.data, 0, true); break; case 'img': - /* IE tends to set "complete" prematurely, so check dimensions */ - if (a.img.complete && (a.img.width !== 0) && (a.img.height !== 0)) { + if (a.img.complete) { if (a.img.width !== a.width || a.img.height !== a.height) { Log.Error("Decoded image has incorrect dimensions. Got " + a.img.width + "x" + a.img.height + ". Expected " + diff --git a/core/input/util.js b/core/input/util.js index 3822d4e..182be7f 100644 --- a/core/input/util.js +++ b/core/input/util.js @@ -68,26 +68,6 @@ export function getKeycode(evt) { export function getKey(evt) { // Are we getting a proper key value? if (evt.key !== undefined) { - // IE and Edge use some ancient version of the spec - // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/ - switch (evt.key) { - case 'Spacebar': return ' '; - case 'Esc': return 'Escape'; - case 'Scroll': return 'ScrollLock'; - case 'Win': return 'Meta'; - case 'Apps': return 'ContextMenu'; - case 'Up': return 'ArrowUp'; - case 'Left': return 'ArrowLeft'; - case 'Right': return 'ArrowRight'; - case 'Down': return 'ArrowDown'; - case 'Del': return 'Delete'; - case 'Divide': return '/'; - case 'Multiply': return '*'; - case 'Subtract': return '-'; - case 'Add': return '+'; - case 'Decimal': return evt.char; - } - // Mozilla isn't fully in sync with the spec yet switch (evt.key) { case 'OS': return 'Meta'; diff --git a/core/input/vkeys.js b/core/input/vkeys.js index f84109b..dacc358 100644 --- a/core/input/vkeys.js +++ b/core/input/vkeys.js @@ -13,7 +13,6 @@ export default { 0x08: 'Backspace', 0x09: 'Tab', 0x0a: 'NumpadClear', - 0x0c: 'Numpad5', // IE11 sends evt.keyCode: 12 when numlock is off 0x0d: 'Enter', 0x10: 'ShiftLeft', 0x11: 'ControlLeft', diff --git a/core/rfb.js b/core/rfb.js index b1ed475..7e177ba 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -187,8 +187,6 @@ export default class RFB extends EventTargetMixin { this._canvas.style.margin = 'auto'; // Some browsers add an outline on focus this._canvas.style.outline = 'none'; - // IE miscalculates width without this :( - this._canvas.style.flexShrink = '0'; this._canvas.width = 0; this._canvas.height = 0; this._canvas.tabIndex = -1; @@ -1263,17 +1261,6 @@ export default class RFB extends EventTargetMixin { } _negotiateSecurity() { - // Polyfill since IE and PhantomJS doesn't have - // TypedArray.includes() - function includes(item, array) { - for (let i = 0; i < array.length; i++) { - if (array[i] === item) { - return true; - } - } - return false; - } - if (this._rfbVersion >= 3.7) { // Server sends supported list, client decides const numTypes = this._sock.rQshift8(); @@ -1290,15 +1277,15 @@ export default class RFB extends EventTargetMixin { Log.Debug("Server security types: " + types); // Look for each auth in preferred order - if (includes(1, types)) { + if (types.includes(1)) { this._rfbAuthScheme = 1; // None - } else if (includes(22, types)) { + } else if (types.includes(22)) { this._rfbAuthScheme = 22; // XVP - } else if (includes(16, types)) { + } else if (types.includes(16)) { this._rfbAuthScheme = 16; // Tight - } else if (includes(2, types)) { + } else if (types.includes(2)) { this._rfbAuthScheme = 2; // VNC Auth - } else if (includes(19, types)) { + } else if (types.includes(19)) { this._rfbAuthScheme = 19; // VeNCrypt Auth } else { return this._fail("Unsupported security types (types: " + types + ")"); @@ -2183,15 +2170,7 @@ export default class RFB extends EventTargetMixin { return this._handleCursor(); case encodings.pseudoEncodingQEMUExtendedKeyEvent: - // Old Safari doesn't support creating keyboard events - try { - const keyboardEvent = document.createEvent("keyboardEvent"); - if (keyboardEvent.code !== undefined) { - this._qemuExtKeyEventSupported = true; - } - } catch (err) { - // Do nothing - } + this._qemuExtKeyEventSupported = true; return true; case encodings.pseudoEncodingDesktopName: diff --git a/core/util/cursor.js b/core/util/cursor.js index 4db1dab..1786ed9 100644 --- a/core/util/cursor.js +++ b/core/util/cursor.js @@ -43,9 +43,6 @@ export default class Cursor { if (useFallback) { document.body.appendChild(this._canvas); - // FIXME: These don't fire properly except for mouse - /// movement in IE. We want to also capture element - // movement, size changes, visibility, etc. const options = { capture: true, passive: true }; this._target.addEventListener('mouseover', this._eventHandlers.mouseover, options); this._target.addEventListener('mouseleave', this._eventHandlers.mouseleave, options); diff --git a/core/util/events.js b/core/util/events.js index 39eefd4..eb09fe1 100644 --- a/core/util/events.js +++ b/core/util/events.js @@ -65,10 +65,6 @@ export function setCapture(target) { target.setCapture(); document.captureElement = target; - - // IE releases capture on 'click' events which might not trigger - target.addEventListener('mouseup', releaseCapture); - } else { // Release any existing capture in case this method is // called multiple times without coordination diff --git a/core/util/polyfill.js b/core/util/polyfill.js index 0e458c8..78715a8 100644 --- a/core/util/polyfill.js +++ b/core/util/polyfill.js @@ -6,37 +6,6 @@ /* Polyfills to provide new APIs in old browsers */ -/* Object.assign() (taken from MDN) */ -if (typeof Object.assign != 'function') { - // Must be writable: true, enumerable: false, configurable: true - Object.defineProperty(Object, "assign", { - value: function assign(target, varArgs) { // .length of function is 2 - 'use strict'; - if (target == null) { // TypeError if undefined or null - throw new TypeError('Cannot convert undefined or null to object'); - } - - const to = Object(target); - - for (let index = 1; index < arguments.length; index++) { - const nextSource = arguments[index]; - - if (nextSource != null) { // Skip over if undefined or null - for (let nextKey in nextSource) { - // Avoid bugs when hasOwnProperty is shadowed - if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { - to[nextKey] = nextSource[nextKey]; - } - } - } - } - return to; - }, - writable: true, - configurable: true - }); -} - /* CustomEvent constructor (taken from MDN) */ (() => { function CustomEvent(event, params) { @@ -52,10 +21,3 @@ if (typeof Object.assign != 'function') { window.CustomEvent = CustomEvent; } })(); - -/* Number.isInteger() (taken from MDN) */ -Number.isInteger = Number.isInteger || function isInteger(value) { - return typeof value === 'number' && - isFinite(value) && - Math.floor(value) === value; -}; diff --git a/core/websock.js b/core/websock.js index 3156aed..8e606bc 100644 --- a/core/websock.js +++ b/core/websock.js @@ -17,9 +17,6 @@ import * as Log from './util/logging.js'; // this has performance issues in some versions Chromium, and // doesn't gain a tremendous amount of performance increase in Firefox // at the moment. It may be valuable to turn it on in the future. -// Also copyWithin() for TypedArrays is not supported in IE 11 or -// Safari 13 (at the moment we want to support Safari 11). -const ENABLE_COPYWITHIN = false; const MAX_RQ_GROW_SIZE = 40 * 1024 * 1024; // 40 MiB export default class Websock { @@ -256,11 +253,7 @@ export default class Websock { this._rQ = new Uint8Array(this._rQbufferSize); this._rQ.set(new Uint8Array(oldRQbuffer, this._rQi, this._rQlen - this._rQi)); } else { - if (ENABLE_COPYWITHIN) { - this._rQ.copyWithin(0, this._rQi, this._rQlen); - } else { - this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi, this._rQlen - this._rQi)); - } + this._rQ.copyWithin(0, this._rQi, this._rQlen); } this._rQlen = this._rQlen - this._rQi; diff --git a/tests/assertions.js b/tests/assertions.js index bab932c..c33c81e 100644 --- a/tests/assertions.js +++ b/tests/assertions.js @@ -6,10 +6,8 @@ chai.use(function (_chai, utils) { _chai.Assertion.addMethod('displayed', function (targetData, cmp=_equal) { const obj = this._obj; const ctx = obj._target.getContext('2d'); - const dataCl = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data; - // NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that - const data = new Uint8Array(dataCl); - const len = dataCl.length; + const data = ctx.getImageData(0, 0, obj._target.width, obj._target.height).data; + const len = data.length; new chai.Assertion(len).to.be.equal(targetData.length, "unexpected display size"); let same = true; for (let i = 0; i < len; i++) { diff --git a/tests/test.display.js b/tests/test.display.js index bd5a55f..c2ccdd8 100644 --- a/tests/test.display.js +++ b/tests/test.display.js @@ -361,27 +361,6 @@ describe('Display/Canvas Helper', function () { expect(img.addEventListener).to.have.been.calledOnce; }); - it('should wait if an image is incorrectly loaded', function () { - const img = { complete: true, width: 0, height: 0, addEventListener: sinon.spy() }; - display._renderQ = [{ type: 'img', x: 3, y: 4, width: 4, height: 4, img: img }, - { type: 'fill', x: 1, y: 2, width: 3, height: 4, color: 5 }]; - display.drawImage = sinon.spy(); - display.fillRect = sinon.spy(); - - display._scanRenderQ(); - expect(display.drawImage).to.not.have.been.called; - expect(display.fillRect).to.not.have.been.called; - expect(img.addEventListener).to.have.been.calledOnce; - - display._renderQ[0].img.complete = true; - display._renderQ[0].img.width = 4; - display._renderQ[0].img.height = 4; - display._scanRenderQ(); - expect(display.drawImage).to.have.been.calledOnce; - expect(display.fillRect).to.have.been.calledOnce; - expect(img.addEventListener).to.have.been.calledOnce; - }); - it('should call callback when queue is flushed', function () { display.onflush = sinon.spy(); display.fillRect(0, 0, 4, 4, [0, 0xff, 0]); diff --git a/tests/test.helper.js b/tests/test.helper.js index 79deefe..5552ec4 100644 --- a/tests/test.helper.js +++ b/tests/test.helper.js @@ -99,10 +99,7 @@ describe('Helpers', function () { expect(KeyboardUtil.getKey({key: 'a', charCode: 'Å '.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal('a'); }); it('should map legacy values', function () { - expect(KeyboardUtil.getKey({key: 'Spacebar'})).to.be.equal(' '); - expect(KeyboardUtil.getKey({key: 'Left'})).to.be.equal('ArrowLeft'); expect(KeyboardUtil.getKey({key: 'OS'})).to.be.equal('Meta'); - expect(KeyboardUtil.getKey({key: 'Win'})).to.be.equal('Meta'); expect(KeyboardUtil.getKey({key: 'UIKeyInputLeftArrow'})).to.be.equal('ArrowLeft'); }); it('should handle broken Delete', function () { diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 0ac6622..bdca2f7 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -2260,12 +2260,7 @@ describe('Remote Frame Buffer Protocol Client', function () { }); it('should be able to handle large Provide messages', function () { - // repeat() is not supported in IE so a loop is needed instead - let expectedData = "hello"; - for (let i = 1; i <= 100000; i++) { - expectedData += "hello"; - } - + let expectedData = "hello".repeat(100000); let data = [3, 0, 0, 0]; const flags = [0x10, 0x00, 0x00, 0x01]; diff --git a/vnc.html b/vnc.html index dab5702..7870b7c 100644 --- a/vnc.html +++ b/vnc.html @@ -16,10 +16,6 @@ noVNC - - - diff --git a/vnc_lite.html b/vnc_lite.html index 044f6f4..36b062b 100644 --- a/vnc_lite.html +++ b/vnc_lite.html @@ -18,10 +18,6 @@ - - -