Skip to content

Commit

Permalink
LibWeb: Add stubbed Media Source Extensions API
Browse files Browse the repository at this point in the history
Just the boilerplate :^)
  • Loading branch information
gmta committed Nov 1, 2024
1 parent 3ef5ce2 commit 3af28f3
Show file tree
Hide file tree
Showing 30 changed files with 549 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ static bool is_platform_object(Type const& type)
"ServiceWorkerRegistration"sv,
"SVGTransform"sv,
"ShadowRoot"sv,
"SourceBuffer"sv,
"Table"sv,
"Text"sv,
"TextMetrics"sv,
"TextTrack"sv,
"TimeRanges"sv,
"URLSearchParams"sv,
"VTTRegion"sv,
"VideoTrack"sv,
Expand Down Expand Up @@ -4240,6 +4242,7 @@ static void generate_using_namespace_definitions(SourceGenerator& generator)
using namespace Web::Internals;
using namespace Web::IntersectionObserver;
using namespace Web::MediaCapabilitiesAPI;
using namespace Web::MediaSourceExtensions;
using namespace Web::NavigationTiming;
using namespace Web::PerformanceTimeline;
using namespace Web::RequestIdleCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static constexpr Array libweb_interface_namespaces = {
"Internals"sv,
"IntersectionObserver"sv,
"MathML"sv,
"MediaSourceExtensions"sv,
"NavigationTiming"sv,
"RequestIdleCallback"sv,
"ResizeObserver"sv,
Expand Down
1 change: 1 addition & 0 deletions Meta/gn/secondary/Userland/Libraries/LibWeb/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ shared_library("LibWeb") {
"Loader",
"MathML",
"MediaCapabilitiesAPI",
"MediaSourceExtensions",
"MimeSniff",
"MixedContent",
"NavigationTiming",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
source_set("MediaSourceExtensions") {
configs += [ "//Userland/Libraries/LibWeb:configs" ]
deps = [ "//Userland/Libraries/LibWeb:all_generated" ]
sources = [
"BufferedChangeEvent.cpp",
"ManagedMediaSource.cpp",
"ManagedSourceBuffer.cpp",
"MediaSource.cpp",
"MediaSourceHandle.cpp",
"SourceBuffer.cpp",
"SourceBufferList.cpp",
]
}
7 changes: 7 additions & 0 deletions Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserverEntry.idl",
"//Userland/Libraries/LibWeb/MathML/MathMLElement.idl",
"//Userland/Libraries/LibWeb/MediaCapabilitiesAPI/MediaCapabilities.idl",
"//Userland/Libraries/LibWeb/MediaSourceExtensions/BufferedChangeEvent.idl",
"//Userland/Libraries/LibWeb/MediaSourceExtensions/ManagedMediaSource.idl",
"//Userland/Libraries/LibWeb/MediaSourceExtensions/ManagedSourceBuffer.idl",
"//Userland/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl",
"//Userland/Libraries/LibWeb/MediaSourceExtensions/MediaSourceHandle.idl",
"//Userland/Libraries/LibWeb/MediaSourceExtensions/SourceBuffer.idl",
"//Userland/Libraries/LibWeb/MediaSourceExtensions/SourceBufferList.idl",
"//Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.idl",
"//Userland/Libraries/LibWeb/NavigationTiming/PerformanceNavigation.idl",
"//Userland/Libraries/LibWeb/PerformanceTimeline/PerformanceEntry.idl",
Expand Down
7 changes: 7 additions & 0 deletions Tests/LibWeb/Text/expected/all-window-properties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ BiquadFilterNode
Blob
Boolean
BroadcastChannel
BufferedChangeEvent
ByteLengthQueuingStrategy
CDATASection
CSSAnimation
Expand Down Expand Up @@ -212,13 +213,17 @@ Iterator
KeyboardEvent
KeyframeEffect
Location
ManagedMediaSource
ManagedSourceBuffer
Map
MathMLElement
MediaCapabilities
MediaError
MediaList
MediaQueryList
MediaQueryListEvent
MediaSource
MediaSourceHandle
MessageChannel
MessageEvent
MessagePort
Expand Down Expand Up @@ -335,6 +340,8 @@ Set
ShadowRealm
ShadowRoot
SharedArrayBuffer
SourceBuffer
SourceBufferList
StaticRange
Storage
StorageManager
Expand Down
7 changes: 7 additions & 0 deletions Userland/Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,13 @@ set(SOURCES
MathML/MathMLElement.cpp
MathML/TagNames.cpp
MediaCapabilitiesAPI/MediaCapabilities.cpp
MediaSourceExtensions/BufferedChangeEvent.cpp
MediaSourceExtensions/ManagedMediaSource.cpp
MediaSourceExtensions/ManagedSourceBuffer.cpp
MediaSourceExtensions/MediaSource.cpp
MediaSourceExtensions/MediaSourceHandle.cpp
MediaSourceExtensions/SourceBuffer.cpp
MediaSourceExtensions/SourceBufferList.cpp
MimeSniff/MimeType.cpp
MimeSniff/Resource.cpp
MixedContent/AbstractOperations.cpp
Expand Down
10 changes: 10 additions & 0 deletions Userland/Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,16 @@ namespace Web::MediaCapabilitiesAPI {
class MediaCapabilities;
}

namespace Web::MediaSourceExtensions {
class BufferedChangeEvent;
class ManagedMediaSource;
class ManagedSourceBuffer;
class MediaSource;
class MediaSourceHandle;
class SourceBuffer;
class SourceBufferList;
}

namespace Web::MimeSniff {
class MimeType;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/BufferedChangeEventPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/MediaSourceExtensions/BufferedChangeEvent.h>

namespace Web::MediaSourceExtensions {

JS_DEFINE_ALLOCATOR(BufferedChangeEvent);

JS::NonnullGCPtr<BufferedChangeEvent> BufferedChangeEvent::construct_impl(JS::Realm& realm, AK::FlyString const& type, BufferedChangeEventInit const& event_init)
{
return realm.heap().allocate<BufferedChangeEvent>(realm, realm, type, event_init);
}

BufferedChangeEvent::BufferedChangeEvent(JS::Realm& realm, AK::FlyString const& type, BufferedChangeEventInit const&)
: DOM::Event(realm, type)
{
}

BufferedChangeEvent::~BufferedChangeEvent() = default;

void BufferedChangeEvent::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(BufferedChangeEvent);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/TimeRanges.h>

namespace Web::MediaSourceExtensions {

struct BufferedChangeEventInit : public DOM::EventInit {
JS::GCPtr<HTML::TimeRanges> added_ranges;
JS::GCPtr<HTML::TimeRanges> removed_ranges;
};

// https://w3c.github.io/media-source/#bufferedchangeevent-interface
class BufferedChangeEvent : public DOM::Event {
WEB_PLATFORM_OBJECT(BufferedChangeEvent, DOM::Event);
JS_DECLARE_ALLOCATOR(BufferedChangeEvent);

public:
[[nodiscard]] static JS::NonnullGCPtr<BufferedChangeEvent> construct_impl(JS::Realm&, FlyString const& type, BufferedChangeEventInit const& = {});

private:
BufferedChangeEvent(JS::Realm&, FlyString const& type, BufferedChangeEventInit const& event_init);

virtual ~BufferedChangeEvent() override;

virtual void initialize(JS::Realm&) override;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#import <DOM/Event.idl>
#import <HTML/TimeRanges.idl>

// https://w3c.github.io/media-source/#dom-bufferedchangeevent
[Exposed=(Window,DedicatedWorker)]
interface BufferedChangeEvent : Event {
constructor(DOMString type, optional BufferedChangeEventInit eventInitDict = {});

[FIXME,SameObject] readonly attribute TimeRanges addedRanges;
[FIXME,SameObject] readonly attribute TimeRanges removedRanges;
};

// https://w3c.github.io/media-source/#dom-bufferedchangeeventinit
dictionary BufferedChangeEventInit : EventInit {
TimeRanges addedRanges;
TimeRanges removedRanges;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/ManagedMediaSourcePrototype.h>
#include <LibWeb/MediaSourceExtensions/ManagedMediaSource.h>

namespace Web::MediaSourceExtensions {

JS_DEFINE_ALLOCATOR(ManagedMediaSource);

ManagedMediaSource::~ManagedMediaSource() = default;

void ManagedMediaSource::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(ManagedMediaSource);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibWeb/MediaSourceExtensions/MediaSource.h>

namespace Web::MediaSourceExtensions {

// https://w3c.github.io/media-source/#managedmediasource-interface
class ManagedMediaSource : public MediaSource {
WEB_PLATFORM_OBJECT(ManagedMediaSource, MediaSource);
JS_DECLARE_ALLOCATOR(ManagedMediaSource);

public:
private:
virtual ~ManagedMediaSource() override;

virtual void initialize(JS::Realm&) override;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import <DOM/EventHandler.idl>
#import <MediaSourceExtensions/MediaSource.idl>

// https://w3c.github.io/media-source/#managedmediasource-interface
[Exposed=(Window,DedicatedWorker)]
interface ManagedMediaSource : MediaSource {
[FIXME] constructor();
[FIXME] readonly attribute boolean streaming;
[FIXME] attribute EventHandler onstartstreaming;
[FIXME] attribute EventHandler onendstreaming;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/ManagedSourceBufferPrototype.h>
#include <LibWeb/MediaSourceExtensions/ManagedSourceBuffer.h>

namespace Web::MediaSourceExtensions {

JS_DEFINE_ALLOCATOR(ManagedSourceBuffer);

ManagedSourceBuffer::~ManagedSourceBuffer() = default;

void ManagedSourceBuffer::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(ManagedSourceBuffer);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibWeb/MediaSourceExtensions/SourceBuffer.h>

namespace Web::MediaSourceExtensions {

// https://w3c.github.io/media-source/#managedsourcebuffer-interface
class ManagedSourceBuffer : public SourceBuffer {
WEB_PLATFORM_OBJECT(ManagedSourceBuffer, SourceBuffer);
JS_DECLARE_ALLOCATOR(ManagedSourceBuffer);

public:
private:
virtual ~ManagedSourceBuffer() override;

virtual void initialize(JS::Realm&) override;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <DOM/EventHandler.idl>
#import <MediaSourceExtensions/SourceBuffer.idl>

// https://w3c.github.io/media-source/#managedsourcebuffer-interface
[Exposed=(Window,DedicatedWorker)]
interface ManagedSourceBuffer : SourceBuffer {
[FIXME] attribute EventHandler onbufferedchange;
};
23 changes: 23 additions & 0 deletions Userland/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/MediaSourcePrototype.h>
#include <LibWeb/MediaSourceExtensions/MediaSource.h>

namespace Web::MediaSourceExtensions {

JS_DEFINE_ALLOCATOR(MediaSource);

MediaSource::~MediaSource() = default;

void MediaSource::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(MediaSource);
}

}
30 changes: 30 additions & 0 deletions Userland/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibWeb/DOM/EventTarget.h>

namespace Web::MediaSourceExtensions {

// https://w3c.github.io/media-source/#dom-mediasource
class MediaSource : public DOM::EventTarget {
WEB_PLATFORM_OBJECT(MediaSource, DOM::EventTarget);
JS_DECLARE_ALLOCATOR(MediaSource);

public:
// https://w3c.github.io/media-source/#dom-mediasource-canconstructindedicatedworker
static bool can_construct_in_dedicated_worker(JS::VM&) { return true; }

protected:
virtual ~MediaSource() override;

virtual void initialize(JS::Realm&) override;

private:
};

}
Loading

0 comments on commit 3af28f3

Please sign in to comment.