mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibWeb: Implement assignment of MediaSource to HTMLMediaElement src
Also, support the srcObject attribute, and fire the sourceopen event at the MediaSource.
This commit is contained in:
committed by
Gregory Bertilson
parent
6dcfe20f1e
commit
d960c1eaf5
Notes:
github-actions[bot]
2026-04-01 07:56:26 +00:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/LadybirdBrowser/ladybird/commit/d960c1eaf56 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8655 Reviewed-by: https://github.com/tcl3
@@ -6,12 +6,16 @@
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/MediaSourcePrototype.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/HTMLMediaElement.h>
|
||||
#include <LibWeb/MediaSourceExtensions/EventNames.h>
|
||||
#include <LibWeb/MediaSourceExtensions/MediaSource.h>
|
||||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
|
||||
namespace Web::MediaSourceExtensions {
|
||||
|
||||
using Bindings::ReadyState;
|
||||
|
||||
GC_DEFINE_ALLOCATOR(MediaSource);
|
||||
|
||||
WebIDL::ExceptionOr<GC::Ref<MediaSource>> MediaSource::construct_impl(JS::Realm& realm)
|
||||
@@ -32,6 +36,58 @@ void MediaSource::initialize(JS::Realm& realm)
|
||||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
void MediaSource::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_media_element_assigned_to);
|
||||
}
|
||||
|
||||
void MediaSource::queue_a_media_source_task(GC::Ref<GC::Function<void()>> task)
|
||||
{
|
||||
// FIXME: The MSE spec does not say what task source to use for its tasks. Should this use the media element's
|
||||
// task source? We may not have access to it if we're in a worker.
|
||||
GC::Ptr<DOM::Document> document = nullptr;
|
||||
if (media_element_assigned_to() != nullptr)
|
||||
document = media_element_assigned_to()->document();
|
||||
|
||||
HTML::queue_a_task(HTML::Task::Source::Unspecified, HTML::main_thread_event_loop(), document, task);
|
||||
}
|
||||
|
||||
ReadyState MediaSource::ready_state() const
|
||||
{
|
||||
return m_ready_state;
|
||||
}
|
||||
|
||||
bool MediaSource::ready_state_is_closed() const
|
||||
{
|
||||
return m_ready_state == ReadyState::Closed;
|
||||
}
|
||||
|
||||
void MediaSource::set_has_ever_been_attached()
|
||||
{
|
||||
m_has_ever_been_attached = true;
|
||||
}
|
||||
|
||||
void MediaSource::set_ready_state_to_open_and_fire_sourceopen_event()
|
||||
{
|
||||
m_ready_state = ReadyState::Open;
|
||||
|
||||
queue_a_media_source_task(GC::create_function(heap(), [this] {
|
||||
auto event = DOM::Event::create(realm(), EventNames::sourceopen);
|
||||
dispatch_event(event);
|
||||
}));
|
||||
}
|
||||
|
||||
void MediaSource::set_assigned_to_media_element(Badge<HTML::HTMLMediaElement>, HTML::HTMLMediaElement& media_element)
|
||||
{
|
||||
m_media_element_assigned_to = media_element;
|
||||
}
|
||||
|
||||
void MediaSource::unassign_from_media_element(Badge<HTML::HTMLMediaElement>)
|
||||
{
|
||||
m_media_element_assigned_to = nullptr;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/media-source/#dom-mediasource-onsourceopen
|
||||
void MediaSource::set_onsourceopen(GC::Ptr<WebIDL::CallbackType> event_handler)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user