diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp index 3be54fd7ba1..e792088f69f 100644 --- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,7 @@ ErrorOr initialize_main_thread_vm(HTML::EventLoop::Type type) HTML::EventNames::initialize_strings(); HTML::TagNames::initialize_strings(); MathML::TagNames::initialize_strings(); + MediaSourceExtensions::EventNames::initialize_strings(); Namespace::initialize_strings(); NavigationTiming::EntryNames::initialize_strings(); PerformanceTimeline::EntryTypes::initialize_strings(); diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index ee997d93d03..3fb5da23a83 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -576,6 +576,7 @@ set(SOURCES MathML/TagNames.cpp MediaCapabilitiesAPI/MediaCapabilities.cpp MediaSourceExtensions/BufferedChangeEvent.cpp + MediaSourceExtensions/EventNames.cpp MediaSourceExtensions/ManagedMediaSource.cpp MediaSourceExtensions/ManagedSourceBuffer.cpp MediaSourceExtensions/MediaSource.cpp diff --git a/Libraries/LibWeb/MediaSourceExtensions/EventNames.cpp b/Libraries/LibWeb/MediaSourceExtensions/EventNames.cpp new file mode 100644 index 00000000000..289523415aa --- /dev/null +++ b/Libraries/LibWeb/MediaSourceExtensions/EventNames.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::MediaSourceExtensions::EventNames { + +#define __ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE(name) FlyString name; +ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTES(__ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE) +#undef __ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE + +void initialize_strings() +{ + static bool s_initialized = false; + VERIFY(!s_initialized); + +#define __ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE(name) \ + name = #name##_fly_string; + ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTES(__ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE) +#undef __ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE + + s_initialized = true; +} + +} diff --git a/Libraries/LibWeb/MediaSourceExtensions/EventNames.h b/Libraries/LibWeb/MediaSourceExtensions/EventNames.h new file mode 100644 index 00000000000..2175373cd0c --- /dev/null +++ b/Libraries/LibWeb/MediaSourceExtensions/EventNames.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::MediaSourceExtensions::EventNames { + +#define ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTES(E) \ + E(abort) \ + E(addsourcebuffer) \ + E(bufferedchange) \ + E(endstreaming) \ + E(error) \ + E(removesourcebuffer) \ + E(sourceclose) \ + E(sourceended) \ + E(sourceopen) \ + E(startstreaming) \ + E(update) \ + E(updateend) \ + E(updatestart) + +#define __ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE(name) extern FlyString name; +ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTES(__ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE) +#undef __ENUMERATE_MEDIA_SOURCE_EXTENSIONS_ATTRIBUTE + +void initialize_strings(); + +} diff --git a/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.cpp b/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.cpp index fa370995d1f..47fed343732 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.cpp +++ b/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace Web::MediaSourceExtensions { @@ -30,4 +31,28 @@ void ManagedMediaSource::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(ManagedMediaSource); } +// https://w3c.github.io/media-source/#dom-managedmediasource-onstartstreaming +void ManagedMediaSource::set_onstartstreaming(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::startstreaming, event_handler); +} + +// https://w3c.github.io/media-source/#dom-managedmediasource-onstartstreaming +GC::Ptr ManagedMediaSource::onstartstreaming() +{ + return event_handler_attribute(EventNames::startstreaming); +} + +// https://w3c.github.io/media-source/#dom-managedmediasource-onendstreaming +void ManagedMediaSource::set_onendstreaming(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::endstreaming, event_handler); +} + +// https://w3c.github.io/media-source/#dom-managedmediasource-onendstreaming +GC::Ptr ManagedMediaSource::onendstreaming() +{ + return event_handler_attribute(EventNames::endstreaming); +} + } diff --git a/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.h b/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.h index dd9a5045914..b13801d6691 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.h +++ b/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.h @@ -18,6 +18,12 @@ class ManagedMediaSource : public MediaSource { public: [[nodiscard]] static WebIDL::ExceptionOr> construct_impl(JS::Realm&); + void set_onstartstreaming(GC::Ptr); + GC::Ptr onstartstreaming(); + + void set_onendstreaming(GC::Ptr); + GC::Ptr onendstreaming(); + private: ManagedMediaSource(JS::Realm&); diff --git a/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.idl b/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.idl index 0e57b3f80e1..0ca55b7c292 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.idl +++ b/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.idl @@ -6,6 +6,6 @@ interface ManagedMediaSource : MediaSource { constructor(); [FIXME] readonly attribute boolean streaming; - [FIXME] attribute EventHandler onstartstreaming; - [FIXME] attribute EventHandler onendstreaming; + attribute EventHandler onstartstreaming; + attribute EventHandler onendstreaming; }; diff --git a/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.cpp b/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.cpp index 062b4805913..4a57e0bcdcf 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.cpp +++ b/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace Web::MediaSourceExtensions { @@ -25,4 +26,16 @@ void ManagedSourceBuffer::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(ManagedSourceBuffer); } +// https://w3c.github.io/media-source/#dom-managedsourcebuffer-onbufferedchange +void ManagedSourceBuffer::set_onbufferedchange(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::bufferedchange, event_handler); +} + +// https://w3c.github.io/media-source/#dom-managedsourcebuffer-onbufferedchange +GC::Ptr ManagedSourceBuffer::onbufferedchange() +{ + return event_handler_attribute(EventNames::bufferedchange); +} + } diff --git a/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.h b/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.h index 348d177bb3f..d432c4b3d17 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.h +++ b/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.h @@ -16,6 +16,9 @@ class ManagedSourceBuffer : public SourceBuffer { GC_DECLARE_ALLOCATOR(ManagedSourceBuffer); public: + void set_onbufferedchange(GC::Ptr); + GC::Ptr onbufferedchange(); + private: ManagedSourceBuffer(JS::Realm&); diff --git a/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.idl b/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.idl index 972d5b83c24..99a9e58abd4 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.idl +++ b/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.idl @@ -4,5 +4,5 @@ // https://w3c.github.io/media-source/#managedsourcebuffer-interface [Exposed=(Window,DedicatedWorker)] interface ManagedSourceBuffer : SourceBuffer { - [FIXME] attribute EventHandler onbufferedchange; + attribute EventHandler onbufferedchange; }; diff --git a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp index b2027628b65..f809a30b542 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp +++ b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace Web::MediaSourceExtensions { @@ -30,4 +31,40 @@ void MediaSource::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(MediaSource); } +// https://w3c.github.io/media-source/#dom-mediasource-onsourceopen +void MediaSource::set_onsourceopen(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::sourceopen, event_handler); +} + +// https://w3c.github.io/media-source/#dom-mediasource-onsourceopen +GC::Ptr MediaSource::onsourceopen() +{ + return event_handler_attribute(EventNames::sourceopen); +} + +// https://w3c.github.io/media-source/#dom-mediasource-onsourceended +void MediaSource::set_onsourceended(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::sourceended, event_handler); +} + +// https://w3c.github.io/media-source/#dom-mediasource-onsourceended +GC::Ptr MediaSource::onsourceended() +{ + return event_handler_attribute(EventNames::sourceended); +} + +// https://w3c.github.io/media-source/#dom-mediasource-onsourceclose +void MediaSource::set_onsourceclose(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::sourceclose, event_handler); +} + +// https://w3c.github.io/media-source/#dom-mediasource-onsourceclose +GC::Ptr MediaSource::onsourceclose() +{ + return event_handler_attribute(EventNames::sourceclose); +} + } diff --git a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h index eb8a125b11d..d00e94b9329 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h +++ b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h @@ -21,6 +21,15 @@ public: // https://w3c.github.io/media-source/#dom-mediasource-canconstructindedicatedworker static bool can_construct_in_dedicated_worker(JS::VM&) { return true; } + void set_onsourceopen(GC::Ptr); + GC::Ptr onsourceopen(); + + void set_onsourceended(GC::Ptr); + GC::Ptr onsourceended(); + + void set_onsourceclose(GC::Ptr); + GC::Ptr onsourceclose(); + protected: MediaSource(JS::Realm&); diff --git a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl index 1eb5ccedd31..77d7fbd5336 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl +++ b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl @@ -27,9 +27,9 @@ interface MediaSource : EventTarget { [FIXME] readonly attribute ReadyState readyState; [FIXME] attribute unrestricted double duration; - [FIXME] attribute EventHandler onsourceopen; - [FIXME] attribute EventHandler onsourceended; - [FIXME] attribute EventHandler onsourceclose; + attribute EventHandler onsourceopen; + attribute EventHandler onsourceended; + attribute EventHandler onsourceclose; static readonly attribute boolean canConstructInDedicatedWorker; diff --git a/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.cpp b/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.cpp index 8a1a7c8391f..591f4075354 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.cpp +++ b/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace Web::MediaSourceExtensions { @@ -25,4 +26,64 @@ void SourceBuffer::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(SourceBuffer); } +// https://w3c.github.io/media-source/#dom-sourcebuffer-onupdatestart +void SourceBuffer::set_onupdatestart(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::updatestart, event_handler); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onupdatestart +GC::Ptr SourceBuffer::onupdatestart() +{ + return event_handler_attribute(EventNames::updatestart); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onupdate +void SourceBuffer::set_onupdate(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::update, event_handler); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onupdate +GC::Ptr SourceBuffer::onupdate() +{ + return event_handler_attribute(EventNames::update); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onupdateend +void SourceBuffer::set_onupdateend(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::updateend, event_handler); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onupdateend +GC::Ptr SourceBuffer::onupdateend() +{ + return event_handler_attribute(EventNames::updateend); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onerror +void SourceBuffer::set_onerror(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::error, event_handler); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onerror +GC::Ptr SourceBuffer::onerror() +{ + return event_handler_attribute(EventNames::error); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onabort +void SourceBuffer::set_onabort(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::abort, event_handler); +} + +// https://w3c.github.io/media-source/#dom-sourcebuffer-onabort +GC::Ptr SourceBuffer::onabort() +{ + return event_handler_attribute(EventNames::abort); +} + } diff --git a/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.h b/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.h index c1e1a9a0d71..d13f033fe5f 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.h +++ b/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.h @@ -15,6 +15,22 @@ class SourceBuffer : public DOM::EventTarget { WEB_PLATFORM_OBJECT(SourceBuffer, DOM::EventTarget); GC_DECLARE_ALLOCATOR(SourceBuffer); +public: + void set_onupdatestart(GC::Ptr); + GC::Ptr onupdatestart(); + + void set_onupdate(GC::Ptr); + GC::Ptr onupdate(); + + void set_onupdateend(GC::Ptr); + GC::Ptr onupdateend(); + + void set_onerror(GC::Ptr); + GC::Ptr onerror(); + + void set_onabort(GC::Ptr); + GC::Ptr onabort(); + protected: SourceBuffer(JS::Realm&); diff --git a/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.idl b/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.idl index d4fbc99b9f4..3ab8a8c3f47 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.idl +++ b/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.idl @@ -23,11 +23,11 @@ interface SourceBuffer : EventTarget { [FIXME] attribute double appendWindowStart; [FIXME] attribute unrestricted double appendWindowEnd; - [FIXME] attribute EventHandler onupdatestart; - [FIXME] attribute EventHandler onupdate; - [FIXME] attribute EventHandler onupdateend; - [FIXME] attribute EventHandler onerror; - [FIXME] attribute EventHandler onabort; + attribute EventHandler onupdatestart; + attribute EventHandler onupdate; + attribute EventHandler onupdateend; + attribute EventHandler onerror; + attribute EventHandler onabort; [FIXME] undefined appendBuffer(BufferSource data); [FIXME] undefined abort(); diff --git a/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.cpp b/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.cpp index 8a7a33f48ff..35e9d909b34 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.cpp +++ b/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace Web::MediaSourceExtensions { @@ -25,4 +26,28 @@ void SourceBufferList::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(SourceBufferList); } +// https://w3c.github.io/media-source/#dom-sourcebufferlist-onaddsourcebuffer +void SourceBufferList::set_onaddsourcebuffer(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::addsourcebuffer, event_handler); +} + +// https://w3c.github.io/media-source/#dom-sourcebufferlist-onaddsourcebuffer +GC::Ptr SourceBufferList::onaddsourcebuffer() +{ + return event_handler_attribute(EventNames::addsourcebuffer); +} + +// https://w3c.github.io/media-source/#dom-sourcebufferlist-onremovesourcebuffer +void SourceBufferList::set_onremovesourcebuffer(GC::Ptr event_handler) +{ + set_event_handler_attribute(EventNames::removesourcebuffer, event_handler); +} + +// https://w3c.github.io/media-source/#dom-sourcebufferlist-onremovesourcebuffer +GC::Ptr SourceBufferList::onremovesourcebuffer() +{ + return event_handler_attribute(EventNames::removesourcebuffer); +} + } diff --git a/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.h b/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.h index d853dc5ae4a..e241a3b2274 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.h +++ b/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.h @@ -15,6 +15,13 @@ class SourceBufferList : public DOM::EventTarget { WEB_PLATFORM_OBJECT(SourceBufferList, DOM::EventTarget); GC_DECLARE_ALLOCATOR(SourceBufferList); +public: + void set_onaddsourcebuffer(GC::Ptr); + GC::Ptr onaddsourcebuffer(); + + void set_onremovesourcebuffer(GC::Ptr); + GC::Ptr onremovesourcebuffer(); + private: SourceBufferList(JS::Realm&); diff --git a/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.idl b/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.idl index d6c3150d497..a704e596878 100644 --- a/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.idl +++ b/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.idl @@ -6,8 +6,8 @@ interface SourceBufferList : EventTarget { [FIXME] readonly attribute unsigned long length; - [FIXME] attribute EventHandler onaddsourcebuffer; - [FIXME] attribute EventHandler onremovesourcebuffer; + attribute EventHandler onaddsourcebuffer; + attribute EventHandler onremovesourcebuffer; [FIXME] getter SourceBuffer (unsigned long index); };