LibWeb/LibURL/LibIPC: Extend createObjectURL to also accept MediaSources

This required some changes in LibURL & LibIPC since it has its own
definition of an BlobURLEntry. For now, we don't have a concrete usage
of MediaSource in LibURL so it is defined as an empty struct.

This removes one FIXME in an idl file.
This commit is contained in:
Tete17 2025-08-18 00:37:34 +02:00 committed by Jelle Raaijmakers
parent f60529dac5
commit 658477620a
Notes: github-actions[bot] 2025-08-19 21:51:41 +00:00
12 changed files with 80 additions and 27 deletions

View file

@ -120,7 +120,7 @@ void DOMURL::visit_edges(Cell::Visitor& visitor)
}
// https://w3c.github.io/FileAPI/#dfn-createObjectURL
WebIDL::ExceptionOr<Utf16String> DOMURL::create_object_url(JS::VM& vm, GC::Ref<FileAPI::Blob> object)
WebIDL::ExceptionOr<Utf16String> DOMURL::create_object_url(JS::VM& vm, FileAPI::BlobURLEntry::Object object)
{
// The createObjectURL(obj) static method must return the result of adding an entry to the blob URL store for obj.
return TRY_OR_THROW_OOM(vm, FileAPI::add_entry_to_blob_url_store(object));
@ -466,10 +466,14 @@ Optional<URL::URL> parse(StringView input, Optional<URL::URL const&> base_url, O
auto blob_url_entry = FileAPI::resolve_a_blob_url(*url);
if (blob_url_entry.has_value()) {
url->set_blob_url_entry(URL::BlobURLEntry {
.object = URL::BlobURLEntry::Object {
.type = blob_url_entry->object->type(),
.data = MUST(ByteBuffer::copy(blob_url_entry->object->raw_bytes())),
},
.object = blob_url_entry->object.visit(
[](const GC::Root<FileAPI::Blob>& blob) -> URL::BlobURLEntry::Object {
return URL::BlobURLEntry::Blob {
.type = blob->type(),
.data = MUST(ByteBuffer::copy(blob->raw_bytes())),
};
},
[](const GC::Root<MediaSourceExtensions::MediaSource>&) -> URL::BlobURLEntry::Object { return URL::BlobURLEntry::MediaSource {}; }),
.environment { .origin = blob_url_entry->environment->origin() },
});
}

View file

@ -12,6 +12,7 @@
#include <LibURL/URL.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/DOMURL/URLSearchParams.h>
#include <LibWeb/FileAPI/BlobURLStore.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::DOMURL {
@ -26,7 +27,7 @@ public:
virtual ~DOMURL() override;
static WebIDL::ExceptionOr<Utf16String> create_object_url(JS::VM&, GC::Ref<FileAPI::Blob> object);
static WebIDL::ExceptionOr<Utf16String> create_object_url(JS::VM&, FileAPI::BlobURLEntry::Object object);
static void revoke_object_url(JS::VM&, StringView url);
static GC::Ptr<DOMURL> parse_for_bindings(JS::VM&, String const& url, Optional<String> const& base = {});

View file

@ -1,5 +1,6 @@
#import <FileAPI/Blob.idl>
#import <DOMURL/URLSearchParams.idl>
#import <MediaSourceExtensions/MediaSource.idl>
// https://url.spec.whatwg.org/#url
[Exposed=*, LegacyWindowAlias=webkitURL, ImplementedAs=DOMURL]
@ -24,6 +25,6 @@ interface URL {
USVString toJSON();
static Utf16DOMString createObjectURL(Blob obj); // FIXME: Should be (Blob or MediaSource).
static Utf16DOMString createObjectURL((Blob or MediaSource) obj);
static undefined revokeObjectURL(DOMString url);
};