mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 17:29:01 +00:00
LibWeb/EME: Implement navigator.requestMediaKeySystemAccess
This commit is contained in:
parent
c9b3365286
commit
f9a13ecb13
Notes:
github-actions[bot]
2025-08-27 07:59:08 +00:00
Author: https://github.com/stelar7
Commit: f9a13ecb13
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5665
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/trflynn89
6 changed files with 124 additions and 0 deletions
|
@ -331,6 +331,7 @@ set(SOURCES
|
|||
Encoding/TextEncoderStream.cpp
|
||||
EncryptedMediaExtensions/Algorithms.cpp
|
||||
EncryptedMediaExtensions/MediaKeySystemAccess.cpp
|
||||
EncryptedMediaExtensions/NavigatorEncryptedMediaExtensionsPartial.cpp
|
||||
EntriesAPI/FileSystemEntry.cpp
|
||||
EventTiming/PerformanceEventTiming.cpp
|
||||
Fetch/Body.cpp
|
||||
|
|
|
@ -35,3 +35,12 @@ enum MediaKeySessionType {
|
|||
"temporary",
|
||||
"persistent-license"
|
||||
};
|
||||
|
||||
// https://w3c.github.io/encrypted-media/#navigator-extension-requestmediakeysystemaccess
|
||||
[Exposed=Window]
|
||||
partial interface Navigator {
|
||||
[SecureContext] Promise<MediaKeySystemAccess> requestMediaKeySystemAccess(
|
||||
Utf16DOMString keySystem,
|
||||
sequence<MediaKeySystemConfiguration> supportedConfigurations
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2025, stelar7 <dudedbz@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/EncryptedMediaExtensions/Algorithms.h>
|
||||
#include <LibWeb/EncryptedMediaExtensions/MediaKeySystemAccess.h>
|
||||
#include <LibWeb/EncryptedMediaExtensions/NavigatorEncryptedMediaExtensionsPartial.h>
|
||||
#include <LibWeb/HTML/Navigator.h>
|
||||
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
|
||||
namespace Web::EncryptedMediaExtensions {
|
||||
|
||||
// https://w3c.github.io/encrypted-media/#dom-navigator-requestmediakeysystemaccess
|
||||
WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> NavigatorEncryptedMediaExtensionsPartial::request_media_key_system_access(Utf16String key_system, Vector<Bindings::MediaKeySystemConfiguration> supported_configurations)
|
||||
{
|
||||
auto& navigator = as<HTML::Navigator>(*this);
|
||||
auto& realm = navigator.realm();
|
||||
|
||||
// 1. If this's relevant global object's associated Document is not allowed to use the encrypted-media feature, then throw a "SecurityError" DOMException and abort these steps.
|
||||
auto& associated_document = as<HTML::Window>(HTML::relevant_global_object(navigator)).associated_document();
|
||||
if (!associated_document.is_allowed_to_use_feature(DOM::PolicyControlledFeature::EncryptedMedia))
|
||||
return WebIDL::SecurityError::create(realm, "This document is not allowed to use the encrypted-media feature"_utf16);
|
||||
|
||||
// 2. If keySystem is the empty string, return a promise rejected with a newly created TypeError.
|
||||
if (key_system.is_empty())
|
||||
return WebIDL::create_rejected_promise(realm, JS::TypeError::create(realm, "keySystem must not be empty"_utf16));
|
||||
|
||||
// 3. If supportedConfigurations is empty, return a promise rejected with a newly created TypeError.
|
||||
if (supported_configurations.is_empty())
|
||||
return WebIDL::create_rejected_promise(realm, JS::TypeError::create(realm, "supportedConfigurations must not be empty"_utf16));
|
||||
|
||||
// 4. Let document be the calling context's Document.
|
||||
// FIXME: Is this the same as the associated document?
|
||||
auto& document = associated_document;
|
||||
|
||||
// 5. Let origin be the origin of document.
|
||||
auto origin = document.origin();
|
||||
|
||||
// 6. Let promise be a new promise.
|
||||
auto promise = WebIDL::create_promise(realm);
|
||||
|
||||
// 7. Run the following steps in parallel:
|
||||
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(realm.heap(), [&realm, key_system, supported_configurations, origin, promise]() {
|
||||
HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
||||
|
||||
// 1. If keySystem is not one of the Key Systems supported by the user agent, reject promise with a NotSupportedError. String comparison is case-sensitive.
|
||||
if (!is_supported_key_system(key_system))
|
||||
return WebIDL::reject_promise(realm, promise, WebIDL::NotSupportedError::create(realm, "Unsupported key system"_utf16));
|
||||
|
||||
// 2. Let implementation be the implementation of keySystem.
|
||||
auto implementation = key_system_from_string(key_system);
|
||||
|
||||
// 3. For each value in supportedConfigurations:
|
||||
for (auto const& candidate_configuration : supported_configurations) {
|
||||
// 1. Let candidate configuration be the value.
|
||||
|
||||
// 2. Let supported configuration be the result of executing the Get Supported Configuration algorithm on implementation, candidate configuration, and origin.
|
||||
auto supported_configuration = get_supported_configuration(*implementation, candidate_configuration, origin);
|
||||
|
||||
// 3. If supported configuration is not NotSupported, run the following steps:
|
||||
if (supported_configuration.has_value()) {
|
||||
// 1. Let access be a new MediaKeySystemAccess object, and initialize it as follows:
|
||||
// 1. Set the keySystem attribute to keySystem.
|
||||
// 2. Let the configuration value be supported configuration.
|
||||
// 3. Let the cdm implementation value be implementation.
|
||||
auto access = MediaKeySystemAccess::create(realm, key_system, *supported_configuration->configuration, move(implementation));
|
||||
|
||||
// 2. Resolve promise with access and abort the parallel steps of this algorithm.
|
||||
return WebIDL::resolve_promise(realm, promise, access);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Reject promise with a NotSupportedError.
|
||||
WebIDL::reject_promise(realm, promise, WebIDL::NotSupportedError::create(realm, "No supported configurations found for the requested key system"_utf16));
|
||||
}));
|
||||
|
||||
// 8. Return promise.
|
||||
return promise;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2025, stelar7 <dudedbz@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibWeb/EncryptedMediaExtensions/EncryptedMediaExtensions.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
#include <LibWeb/WebIDL/Promise.h>
|
||||
|
||||
namespace Web::EncryptedMediaExtensions {
|
||||
|
||||
class NavigatorEncryptedMediaExtensionsPartial {
|
||||
public:
|
||||
WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> request_media_key_system_access(Utf16String, Vector<Bindings::MediaKeySystemConfiguration>);
|
||||
|
||||
private:
|
||||
virtual ~NavigatorEncryptedMediaExtensionsPartial() = default;
|
||||
|
||||
friend class HTML::Navigator;
|
||||
};
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/EncryptedMediaExtensions/NavigatorEncryptedMediaExtensionsPartial.h>
|
||||
#include <LibWeb/Gamepad/NavigatorGamepad.h>
|
||||
#include <LibWeb/HTML/MimeTypeArray.h>
|
||||
#include <LibWeb/HTML/NavigatorBeacon.h>
|
||||
|
@ -28,6 +29,7 @@ class Navigator : public Bindings::PlatformObject
|
|||
, public NavigatorConcurrentHardwareMixin
|
||||
, public NavigatorDeviceMemoryMixin
|
||||
, public Gamepad::NavigatorGamepadPartial
|
||||
, public EncryptedMediaExtensions::NavigatorEncryptedMediaExtensionsPartial
|
||||
, public NavigatorIDMixin
|
||||
, public NavigatorLanguageMixin
|
||||
, public NavigatorOnLineMixin
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#import <Clipboard/Clipboard.idl>
|
||||
#import <CredentialManagement/CredentialsContainer.idl>
|
||||
#import <EncryptedMediaExtensions/MediaKeySystemAccess.idl>
|
||||
#import <Gamepad/Gamepad.idl>
|
||||
#import <Geolocation/Geolocation.idl>
|
||||
#import <HTML/MimeTypeArray.idl>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue