diff --git a/build/types/polyfill b/build/types/polyfill index 2aeee8cadd..ebc0912781 100644 --- a/build/types/polyfill +++ b/build/types/polyfill @@ -8,7 +8,6 @@ +../../lib/polyfill/media_capabilities.js +../../lib/polyfill/orientation.js +../../lib/polyfill/patchedmediakeys_cert.js -+../../lib/polyfill/patchedmediakeys_nop.js +../../lib/polyfill/patchedmediakeys_webkit.js +../../lib/polyfill/pip_webkit.js +../../lib/polyfill/random_uuid.js diff --git a/docs/tutorials/plugins.md b/docs/tutorials/plugins.md index c70ed72960..f44413189a 100644 --- a/docs/tutorials/plugins.md +++ b/docs/tutorials/plugins.md @@ -76,7 +76,6 @@ __Polyfills__ {@linksource shaka.polyfill.VideoPlaybackQuality} - prefixed EME implementations: - {@linksource shaka.polyfill.PatchedMediaKeysWebkit} - - {@linksource shaka.polyfill.PatchedMediaKeysNop} - variants of VTTCue and TextTrackCue constructors: {@linksource shaka.polyfill.VTTCue} diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index cbe301f5a2..128ff9ba5a 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -899,6 +899,12 @@ shaka.media.DrmEngine = class { await this.getKeySystemAccessByConfigs_(configsByKeySystem); if (!mediaKeySystemAccess) { + if (!navigator.requestMediaKeySystemAccess) { + throw new shaka.util.Error( + shaka.util.Error.Severity.CRITICAL, + shaka.util.Error.Category.DRM, + shaka.util.Error.Code.MISSING_EME_SUPPORT); + } throw new shaka.util.Error( shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.DRM, @@ -1711,9 +1717,6 @@ shaka.media.DrmEngine = class { * @return {!Promise.>} */ static async probeSupport() { - goog.asserts.assert(shaka.util.DrmUtils.isBrowserSupported(), - 'Must have basic EME support'); - const testKeySystems = [ 'org.w3.clearkey', 'com.widevine.alpha', @@ -1725,6 +1728,14 @@ shaka.media.DrmEngine = class { 'com.apple.fps', ]; + if (!shaka.util.DrmUtils.isBrowserSupported()) { + const result = {}; + for (const keySystem of testKeySystems) { + result[keySystem] = null; + } + return result; + } + const widevineRobustness = [ 'SW_SECURE_CRYPTO', 'SW_SECURE_DECODE', diff --git a/lib/player.js b/lib/player.js index 49aded3d3e..7a901ac645 100644 --- a/lib/player.js +++ b/lib/player.js @@ -1110,14 +1110,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget { return false; } - // DRM support is not strictly necessary, but the APIs at least need to be - // there. Our no-op DRM polyfill should handle that. - // TODO(#1017): Consider making even DrmEngine optional. - const drmSupport = shaka.util.DrmUtils.isBrowserSupported(); - if (!drmSupport) { - return false; - } - // If we have MediaSource (MSE) support, we should be able to use Shaka. if (shaka.util.Platform.supportsMediaSource()) { return true; diff --git a/lib/polyfill/patchedmediakeys_nop.js b/lib/polyfill/patchedmediakeys_nop.js deleted file mode 100644 index 9b4d8c5a7a..0000000000 --- a/lib/polyfill/patchedmediakeys_nop.js +++ /dev/null @@ -1,148 +0,0 @@ -/*! @license - * Shaka Player - * Copyright 2016 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -goog.provide('shaka.polyfill.PatchedMediaKeysNop'); - -goog.require('goog.asserts'); -goog.require('shaka.log'); -goog.require('shaka.polyfill'); - - -/** - * @summary A polyfill to stub out - * {@link https://bit.ly/EmeMar15 EME draft 12 March 2015} on browsers without - * EME. - * All methods will fail. - * @export - */ -shaka.polyfill.PatchedMediaKeysNop = class { - /** - * Installs the polyfill if needed. - * @export - */ - static install() { - if (!window.HTMLVideoElement || - (navigator.requestMediaKeySystemAccess && - // eslint-disable-next-line no-restricted-syntax - MediaKeySystemAccess.prototype.getConfiguration)) { - return; - } - shaka.log.info('EME not available.'); - - // Alias. - const PatchedMediaKeysNop = shaka.polyfill.PatchedMediaKeysNop; - - // Install patches. - navigator.requestMediaKeySystemAccess = - PatchedMediaKeysNop.requestMediaKeySystemAccess; - // Delete mediaKeys to work around strict mode compatibility issues. - // eslint-disable-next-line no-restricted-syntax - delete HTMLMediaElement.prototype['mediaKeys']; - // Work around read-only declaration for mediaKeys by using a string. - // eslint-disable-next-line no-restricted-syntax - HTMLMediaElement.prototype['mediaKeys'] = null; - // eslint-disable-next-line no-restricted-syntax - HTMLMediaElement.prototype.setMediaKeys = PatchedMediaKeysNop.setMediaKeys; - // These are not usable, but allow Player.isBrowserSupported to pass. - window.MediaKeys = PatchedMediaKeysNop.MediaKeys; - window.MediaKeySystemAccess = PatchedMediaKeysNop.MediaKeySystemAccess; - - window.shakaMediaKeysPolyfill = PatchedMediaKeysNop.apiName_; - } - - /** - * An implementation of navigator.requestMediaKeySystemAccess. - * Retrieves a MediaKeySystemAccess object. - * - * @this {!Navigator} - * @param {string} keySystem - * @param {!Array.} supportedConfigurations - * @return {!Promise.} - */ - static requestMediaKeySystemAccess(keySystem, supportedConfigurations) { - shaka.log.debug('PatchedMediaKeysNop.requestMediaKeySystemAccess'); - goog.asserts.assert(this == navigator, - 'bad "this" for requestMediaKeySystemAccess'); - - return Promise.reject(new Error( - 'The key system specified is not supported.')); - } - - /** - * An implementation of HTMLMediaElement.prototype.setMediaKeys. - * Attaches a MediaKeys object to the media element. - * - * @this {!HTMLMediaElement} - * @param {MediaKeys} mediaKeys - * @return {!Promise} - */ - static setMediaKeys(mediaKeys) { - shaka.log.debug('PatchedMediaKeysNop.setMediaKeys'); - goog.asserts.assert(this instanceof HTMLMediaElement, - 'bad "this" for setMediaKeys'); - - if (mediaKeys == null) { - return Promise.resolve(); - } - - return Promise.reject(new Error('MediaKeys not supported.')); - } -}; - - -/** - * An unusable constructor for MediaKeys. - * @implements {MediaKeys} - */ -shaka.polyfill.PatchedMediaKeysNop.MediaKeys = class { - /** */ - constructor() { - throw new TypeError('Illegal constructor.'); - } - - /** @override */ - createSession() {} - - /** @override */ - setServerCertificate() {} - - /** @override */ - getStatusForPolicy(policy) { - return Promise.resolve('usable'); - } -}; - - -/** - * An unusable constructor for MediaKeySystemAccess. - * @implements {MediaKeySystemAccess} - */ -shaka.polyfill.PatchedMediaKeysNop.MediaKeySystemAccess = class { - /** */ - constructor() { - /** @override */ - this.keySystem = ''; // For the compiler. - - throw new TypeError('Illegal constructor.'); - } - - /** @override */ - getConfiguration() {} - - /** @override */ - createMediaKeys() {} -}; - -/** - * API name. - * - * @private {string} - */ -shaka.polyfill.PatchedMediaKeysNop.apiName_ = 'nop'; - - -// A low priority ensures this is the last and acts as a fallback. -shaka.polyfill.register(shaka.polyfill.PatchedMediaKeysNop.install, -10); diff --git a/lib/util/error.js b/lib/util/error.js index 8ad8d4509c..5cc99a8373 100644 --- a/lib/util/error.js +++ b/lib/util/error.js @@ -935,6 +935,11 @@ shaka.util.Error.Code = { */ 'ERROR_CHECKING_HDCP_VERSION': 6019, + /** + * The browser does not support EME APIs, so DRM content cannot be played. + */ + 'MISSING_EME_SUPPORT': 6020, + /** * The call to Player.load() was interrupted by a call to Player.unload() diff --git a/shaka-player.uncompiled.js b/shaka-player.uncompiled.js index ba19aa9033..10ef0a121c 100644 --- a/shaka-player.uncompiled.js +++ b/shaka-player.uncompiled.js @@ -40,7 +40,6 @@ goog.require('shaka.polyfill.MediaSource'); goog.require('shaka.polyfill.MediaCapabilities'); goog.require('shaka.polyfill.Orientation'); goog.require('shaka.polyfill.PatchedMediaKeysApple'); -goog.require('shaka.polyfill.PatchedMediaKeysNop'); goog.require('shaka.polyfill.PatchedMediaKeysWebkit'); goog.require('shaka.polyfill.PiPWebkit'); goog.require('shaka.polyfill.RandomUUID');