mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
LibWeb: Implement URL.createObjectURL and URL.revokeObjectURL
This commit is contained in:
parent
dd36a0c12d
commit
9957d48f48
3 changed files with 40 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/IPv6Address.h>
|
#include <AK/IPv6Address.h>
|
||||||
#include <AK/URLParser.h>
|
#include <AK/URLParser.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/FileAPI/Blob.h>
|
||||||
#include <LibWeb/FileAPI/BlobURLStore.h>
|
#include <LibWeb/FileAPI/BlobURLStore.h>
|
||||||
#include <LibWeb/URL/URL.h>
|
#include <LibWeb/URL/URL.h>
|
||||||
|
|
||||||
|
@ -97,6 +98,38 @@ void URL::visit_edges(Cell::Visitor& visitor)
|
||||||
visitor.visit(m_query.ptr());
|
visitor.visit(m_query.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/FileAPI/#dfn-createObjectURL
|
||||||
|
WebIDL::ExceptionOr<String> URL::create_object_url(JS::VM& vm, JS::NonnullGCPtr<FileAPI::Blob> 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/FileAPI/#dfn-revokeObjectURL
|
||||||
|
WebIDL::ExceptionOr<void> URL::revoke_object_url(JS::VM& vm, StringView url)
|
||||||
|
{
|
||||||
|
// 1. Let url record be the result of parsing url.
|
||||||
|
auto url_record = parse(url);
|
||||||
|
|
||||||
|
// 2. If url record’s scheme is not "blob", return.
|
||||||
|
if (url_record.scheme() != "blob"sv)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 3. Let origin be the origin of url record.
|
||||||
|
auto origin = url_origin(url_record);
|
||||||
|
|
||||||
|
// 4. Let settings be the current settings object.
|
||||||
|
auto& settings = HTML::current_settings_object();
|
||||||
|
|
||||||
|
// 5. If origin is not same origin with settings’s origin, return.
|
||||||
|
if (!origin.is_same_origin(settings.origin()))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 6. Remove an entry from the Blob URL Store for url.
|
||||||
|
TRY_OR_THROW_OOM(vm, FileAPI::remove_entry_from_blob_url_store(url));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#dom-url-canparse
|
// https://url.spec.whatwg.org/#dom-url-canparse
|
||||||
bool URL::can_parse(JS::VM&, String const& url, Optional<String> const& base)
|
bool URL::can_parse(JS::VM&, String const& url, Optional<String> const& base)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,9 @@ public:
|
||||||
|
|
||||||
virtual ~URL() override;
|
virtual ~URL() override;
|
||||||
|
|
||||||
|
static WebIDL::ExceptionOr<String> create_object_url(JS::VM&, JS::NonnullGCPtr<FileAPI::Blob> object);
|
||||||
|
static WebIDL::ExceptionOr<void> revoke_object_url(JS::VM&, StringView url);
|
||||||
|
|
||||||
static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
|
static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> href() const;
|
WebIDL::ExceptionOr<String> href() const;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#import <FileAPI/Blob.idl>
|
||||||
#import <URL/URLSearchParams.idl>
|
#import <URL/URLSearchParams.idl>
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#url
|
// https://url.spec.whatwg.org/#url
|
||||||
|
@ -21,4 +22,7 @@ interface URL {
|
||||||
attribute USVString hash;
|
attribute USVString hash;
|
||||||
|
|
||||||
USVString toJSON();
|
USVString toJSON();
|
||||||
|
|
||||||
|
static DOMString createObjectURL(Blob obj); // FIXME: Should be (Blob or MediaSource).
|
||||||
|
static undefined revokeObjectURL(DOMString url);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue