From ce9f970f1a8ba1ddb9694f2843eb0944c92af6ba Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Thu, 21 Oct 2021 12:25:12 -0700 Subject: [PATCH] cleanup!: Drop support for prefixed EME This has not been in Chrome for some time, so this should not hurt anyone in a Chrome extension. Change-Id: Idca0f28eb16998f944c362032cbc13e9bfc616ae --- README.md | 10 ----- eme_listeners.js | 59 +++---------------------- spec/eme_listeners_spec.js | 89 -------------------------------------- 3 files changed, 6 insertions(+), 152 deletions(-) diff --git a/README.md b/README.md index 538c06d..77796e8 100644 --- a/README.md +++ b/README.md @@ -27,22 +27,12 @@ function SomeSystemFormatter() { this.isKeySystemSupported = function (keySystem) { return keySystem == "com.example.somesystem"; } - - // Unprefixed logging methods. this.formatUpdateCall = function (response) { return "SomeSystemFormatter saw an UpdateCall with: " + response; } this.formatmessage = function (message) { return "SomeSystemFormatter saw a MessageEvent with: " + message; } - - // Prefixed logging methods. - this.formatwebkitkeymessage = function (message) { - return "SomeSystemFormatter saw a KeyMessageEvent with: " + message; - } - this.formatAddKeyCall = function (key) { - return "SomeSystemFormatter saw an AddKeyCall with: " + key; - } } if (!document.emeFormatters) diff --git a/eme_listeners.js b/eme_listeners.js index 95ff03d..d545f0d 100644 --- a/eme_listeners.js +++ b/eme_listeners.js @@ -32,12 +32,7 @@ function setUp_() { * Manager for EME event and method listeners. * @constructor */ -function EmeListeners() { - this.unprefixedEmeEnabled = - Navigator.prototype.requestMediaKeySystemAccess ? true : false; - this.prefixedEmeEnabled = - HTMLMediaElement.prototype.webkitGenerateKeyRequest ? true : false; -} +function EmeListeners() {} /** @@ -51,17 +46,12 @@ EmeListeners.NUM_MEDIA_ELEMENT_TYPES = 3; * Sets up EME listeners for whichever type of EME is enabled. */ EmeListeners.prototype.setUpListeners = function() { - if (!this.unprefixedEmeEnabled && !this.prefixedEmeEnabled) { + if (!navigator.requestMediaKeySystemAccess) { console.log('EME not available.'); return; } - if (this.unprefixedEmeEnabled) { - console.log('Unprefixed EME is enabled.'); - this.addListenersToNavigator_(); - } - if (this.prefixedEmeEnabled) { - console.log('Prefixed EME is enabled.'); - } + + this.addListenersToNavigator_(); this.addListenersToAllEmeElements_(); }; @@ -261,20 +251,6 @@ EmeListeners.prototype.addEmeEventListeners_ = function(element) { if (element.eventListenersAdded_) { return; } - if (this.prefixedEmeEnabled) { - element.addEventListener('webkitneedkey', - EmeListeners.logEvent.bind(null, emeLogger.NeedKeyEvent)); - - element.addEventListener('webkitkeymessage', - EmeListeners.logEvent.bind(null, emeLogger.KeyMessageEvent)); - - element.addEventListener('webkitkeyadded', - EmeListeners.logEvent.bind(null, emeLogger.KeyAddedEvent)); - - element.addEventListener('webkitkeyerror', - EmeListeners.logEvent.bind(null, emeLogger.KeyErrorEvent)); - } - element.addEventListener('encrypted', EmeListeners.logEvent.bind(null, emeLogger.EncryptedEvent)); @@ -302,31 +278,8 @@ EmeListeners.prototype.addEmeMethodListeners_ = function(element) { element.play = EmeListeners.extendEmeMethod( element, element.play, emeLogger.PlayCall); - if (this.prefixedEmeEnabled) { - element.canPlayType = EmeListeners.extendEmeMethod( - element, element.canPlayType, emeLogger.CanPlayTypeCall); - - element.webkitGenerateKeyRequest = EmeListeners.extendEmeMethod( - element, - element.webkitGenerateKeyRequest, - emeLogger.GenerateKeyRequestCall); - - element.webkitAddKey = EmeListeners.extendEmeMethod( - element, - element.webkitAddKey, - emeLogger.AddKeyCall); - - element.webkitCancelKeyRequest = EmeListeners.extendEmeMethod( - element, - element.webkitCancelKeyRequest, - emeLogger.CancelKeyRequestCall); - - } - - if (this.unprefixedEmeEnabled) { - element.setMediaKeys = EmeListeners.extendEmeMethod( - element, element.setMediaKeys, emeLogger.SetMediaKeysCall); - } + element.setMediaKeys = EmeListeners.extendEmeMethod( + element, element.setMediaKeys, emeLogger.SetMediaKeysCall); element.methodListenersAdded_ = true; }; diff --git a/spec/eme_listeners_spec.js b/spec/eme_listeners_spec.js index 610afa4..20de639 100644 --- a/spec/eme_listeners_spec.js +++ b/spec/eme_listeners_spec.js @@ -41,10 +41,6 @@ describe('emeListeners', function() { }; const events = { - webkitNeedKeyEvent: new Event('webkitneedkey'), - webkitKeyMessageEvent: new Event('webkitkeymessage'), - webkitKeyAddedEvent: new Event('webkitkeyadded'), - webkitKeyErrorEvent: new Event('webkitkeyerror'), encryptedEvent: new Event('encrypted'), playEvent: new Event('play'), errorEvent: new Event('error'), @@ -249,95 +245,10 @@ describe('emeListeners', function() { }); }); - describe('logs prefixed EME', function() { - var mockHtmlMedia; - - beforeEach(function() { - listener.prefixedEmeEnabled = true; - listener.unprefixedEmeEnabled = false; - mockHtmlMedia = { - canPlayType: mockFn, - webkitGenerateKeyRequest: mockFn, - webkitAddKey: mockFn, - webkitCancelKeyRequest: mockFn, - play: mockFn - }; - listener.addEmeMethodListeners_(mockHtmlMedia); - }); - - - it('canPlayType calls', function(done) { - logsCall( - mockHtmlMedia.canPlayType, - emeLogger.CanPlayTypeCall, - ['fakeType', 'fakeKeySystem'], - mockHtmlMedia, - done); - }); - - it('generateKeyRequest calls', function(done) { - logsCall( - mockHtmlMedia.webkitGenerateKeyRequest, - emeLogger.GenerateKeyRequestCall, - ['fakeKeySystem', 'fakeInitData'], - mockHtmlMedia, - done); - }); - - it('addKey calls', function(done) { - logsCall( - mockHtmlMedia.webkitAddKey, - emeLogger.AddKeyCall, - ['fakeKeySystem', 'fakeKey', 'fakeInitData', 'fakeSessionId'], - mockHtmlMedia, - done, - 'fakeKey', - 'fakeKeySystem'); - }); - - it('cancelKeyRequest calls', function(done) { - logsCall( - mockHtmlMedia.webkitCancelKeyRequest, - emeLogger.CancelKeyRequestCall, - ['fakeKeySystem', 'fakeSessionId'], - mockHtmlMedia, - done); - }); - - it('play calls', function(done) { - logsCall( - mockHtmlMedia.play, - emeLogger.PlayCall, - [], - mockHtmlMedia, - done); - }); - - it('events', function() { - spyOn(console, 'error'); - mockHtmlMedia = document.createElement('media'); - listener.addEmeEventListeners_(mockHtmlMedia); - for (var e in events) { - mockHtmlMedia.dispatchEvent(events[e]); - } - expect(EmeListeners.logEvent.calls.count()).toEqual(7); - expectLogEvent(emeLogger.NeedKeyEvent, 'webkitNeedKeyEvent'); - expectLogEvent(emeLogger.KeyMessageEvent, 'webkitKeyMessageEvent'); - expectLogEvent(emeLogger.KeyAddedEvent, 'webkitKeyAddedEvent'); - expectLogEvent(emeLogger.KeyErrorEvent, 'webkitKeyErrorEvent'); - expectLogEvent(emeLogger.PlayEvent, 'playEvent'); - expectLogEvent(emeLogger.ErrorEvent, 'errorEvent'); - expectLogEvent(emeLogger.EncryptedEvent, 'encryptedEvent'); - expect(console.error.calls.count()).toEqual(1); - }); - }); - describe('logs unprefixed EME', function() { var mockHtmlMedia; beforeEach(function() { - listener.prefixedEmeEnabled = false; - listener.unprefixedEmeEnabled = true; mockHtmlMedia = { setMediaKeys: mockFn, play: mockFn