summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encrypted-media/polyfill/cast-polyfill.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/encrypted-media/polyfill/cast-polyfill.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/encrypted-media/polyfill/cast-polyfill.js')
-rw-r--r--testing/web-platform/tests/encrypted-media/polyfill/cast-polyfill.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/testing/web-platform/tests/encrypted-media/polyfill/cast-polyfill.js b/testing/web-platform/tests/encrypted-media/polyfill/cast-polyfill.js
new file mode 100644
index 0000000000..576e0ad040
--- /dev/null
+++ b/testing/web-platform/tests/encrypted-media/polyfill/cast-polyfill.js
@@ -0,0 +1,80 @@
+(function() {
+
+ if ( /CrKey\/[0-9]+\.[0-9a-z]+\.[0-9a-z]+/i.exec( navigator.userAgent ) ) {
+
+ var castscript = document.createElement('script');
+ castscript.type = 'text/javascript';
+ castscript.src = 'https://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js'
+ document.head.appendChild( castscript );
+
+ var _requestMediaKeySystemAccess = navigator.requestMediaKeySystemAccess.bind( navigator ),
+ _setMediaKeys = HTMLMediaElement.prototype.setMediaKeys,
+ _load = MediaKeySession.prototype.load;
+
+ MediaKeySession.prototype.load = function load()
+ {
+ return _load.call( this ).then( function( success )
+ {
+ return success ? this.remove() : false;
+ }.bind( this ) );
+ };
+
+ function MediaKeys( mediaKeys )
+ {
+ this._mediaKeys = mediaKeys;
+ }
+
+ MediaKeys.prototype.setServerCertificate = function setServerCertificate( certificate )
+ {
+ return this._mediaKeys.setServerCertificate( certificate );
+ };
+
+ MediaKeys.prototype.createSession = function createSession( sessionType ) {
+
+ if ( sessionType === 'persistent-usage-record' )
+ {
+ return cast.receiver.eme.KeySession.createSession( this._mediaKeys, 'persistent-release-message' );
+ }
+
+ return this._mediaKeys.createSession( sessionType );
+ };
+
+ function MediaKeySystemAccess( access )
+ {
+ this._access = mediaKeySystemAccess;
+ }
+
+ Object.defineProperty( MediaKeySystemAccess.prototype, 'keySystem', { get: function() { return this._access.keySystem; } } );
+
+ MediaKeySystemAccess.prototype.getConfiguration = function getConfiguration() { return this._access.getConfiguration(); };
+
+ MediaKeySystemAccess.prototype.createMediaKeys = function createMediaKeys() {
+
+ return this._access.createMediaKey().then( function( mediaKeys ) { return new MediaKeys( mediaKeys ); } );
+
+ };
+
+ HTMLMediaElement.prototype.setMediaKeys = function setMediaKeys( mediaKeys )
+ {
+ if ( mediaKeys instanceof MediaKeys )
+ {
+ return _setMediaKeys.call( this, mediaKeys._mediaKeys );
+ }
+ else
+ {
+ return _setMediaKeys.call( this, mediaKeys );
+ }
+ };
+
+ navigator.requestMediaKeySystemAccess = function requestMediaKeySystemAccess( keysystem, supportedConfigurations ) {
+
+ if ( keysystem !== 'com.chromecast.playready' )
+ {
+ return _requestMediaKeySystemAccess( keysystem, supportedConfigurations );
+ }
+
+ return _requestMediaKeySystemAccess( keysystem, supportedConfigurations )
+ .then( function( access ) { return new MediaKeySystemAccess( access ); } );
+ };
+ }
+})(); \ No newline at end of file