mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibURL+LibWeb+LibIPC: Represent blob URL entry's object using structs
Instead of just putting in members directly, wrap them up in structs which represent what a URL blob entry is meant to hold per the spec. This makes more obvious what this is meant to represent, such as the ByteBuffer being used to represent the bytes behind a Blob. This also allows us to use a stronger type for a function that needs to return a Blob URL entry's object.
This commit is contained in:
parent
a0b0e91d4f
commit
ca3d9d9ee0
Notes:
github-actions[bot]
2025-01-21 19:23:20 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/ca3d9d9ee07 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3303 Reviewed-by: https://github.com/tcl3 ✅
7 changed files with 29 additions and 16 deletions
|
@ -89,9 +89,11 @@ ErrorOr<URL::URL> decode(Decoder& decoder)
|
|||
return url;
|
||||
|
||||
url.set_blob_url_entry(URL::BlobURLEntry {
|
||||
.type = TRY(decoder.decode<String>()),
|
||||
.byte_buffer = TRY(decoder.decode<ByteBuffer>()),
|
||||
.environment_origin = TRY(decoder.decode<URL::Origin>()),
|
||||
.object = URL::BlobURLEntry::Object {
|
||||
.type = TRY(decoder.decode<String>()),
|
||||
.data = TRY(decoder.decode<ByteBuffer>()),
|
||||
},
|
||||
.environment { .origin = TRY(decoder.decode<URL::Origin>()) },
|
||||
});
|
||||
|
||||
return url;
|
||||
|
|
|
@ -109,9 +109,9 @@ ErrorOr<void> encode(Encoder& encoder, URL::URL const& value)
|
|||
|
||||
auto const& blob = value.blob_url_entry().value();
|
||||
|
||||
TRY(encoder.encode(blob.type));
|
||||
TRY(encoder.encode(blob.byte_buffer));
|
||||
TRY(encoder.encode(blob.environment_origin));
|
||||
TRY(encoder.encode(blob.object.type));
|
||||
TRY(encoder.encode(blob.object.data));
|
||||
TRY(encoder.encode(blob.environment.origin));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ Origin URL::origin() const
|
|||
if (scheme() == "blob"sv) {
|
||||
// 1. If url’s blob URL entry is non-null, then return url’s blob URL entry’s environment’s origin.
|
||||
if (blob_url_entry().has_value())
|
||||
return blob_url_entry()->environment_origin;
|
||||
return blob_url_entry()->environment.origin;
|
||||
|
||||
// 2. Let pathURL be the result of parsing the result of URL path serializing url.
|
||||
auto path_url = Parser::basic_parse(serialize_path());
|
||||
|
|
|
@ -41,11 +41,20 @@ enum class ExcludeFragment {
|
|||
};
|
||||
|
||||
// https://w3c.github.io/FileAPI/#blob-url-entry
|
||||
// NOTE: This represents the raw bytes behind a 'Blob' (and does not yet support a MediaSourceQuery).
|
||||
struct BlobURLEntry {
|
||||
String type;
|
||||
ByteBuffer byte_buffer;
|
||||
Origin environment_origin;
|
||||
// This represents the raw bytes behind a 'Blob' (and does not yet support a MediaSourceQuery).
|
||||
struct Object {
|
||||
String type;
|
||||
ByteBuffer data;
|
||||
};
|
||||
|
||||
// This represents the parts of HTML::Environment that we need for a BlobURL entry.
|
||||
struct Environment {
|
||||
Origin origin;
|
||||
};
|
||||
|
||||
Object object;
|
||||
Environment environment;
|
||||
};
|
||||
|
||||
void append_percent_encoded_if_necessary(StringBuilder&, u32 code_point, PercentEncodeSet set = PercentEncodeSet::Userinfo);
|
||||
|
|
|
@ -516,9 +516,11 @@ URL::URL parse(StringView input, Optional<URL::URL const&> base_url, Optional<St
|
|||
auto blob_url_entry = FileAPI::resolve_a_blob_url(*url);
|
||||
if (blob_url_entry.has_value()) {
|
||||
url->set_blob_url_entry(URL::BlobURLEntry {
|
||||
.type = blob_url_entry->object->type(),
|
||||
.byte_buffer = MUST(ByteBuffer::copy(blob_url_entry->object->raw_bytes())),
|
||||
.environment_origin = blob_url_entry->environment->origin(),
|
||||
.object = URL::BlobURLEntry::Object {
|
||||
.type = blob_url_entry->object->type(),
|
||||
.data = MUST(ByteBuffer::copy(blob_url_entry->object->raw_bytes())),
|
||||
},
|
||||
.environment { .origin = blob_url_entry->environment->origin() },
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -826,7 +826,7 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> scheme_fetch(JS::Realm& realm, Inf
|
|||
}
|
||||
|
||||
// 3. Let blob be blobURLEntry’s object.
|
||||
auto const blob = FileAPI::Blob::create(realm, blob_url_entry.value().byte_buffer, blob_url_entry.value().type);
|
||||
auto const blob = FileAPI::Blob::create(realm, blob_url_entry.value().object.data, blob_url_entry.value().object.type);
|
||||
|
||||
// 4. Let response be a new response.
|
||||
auto response = Infrastructure::Response::create(vm);
|
||||
|
|
|
@ -161,7 +161,7 @@ static TokenizedFeature::NoOpener get_noopener_for_window_open(DOM::Document con
|
|||
// 1. If url is not null and url's blob URL entry is not null:
|
||||
if (url.has_value() && url->blob_url_entry().has_value()) {
|
||||
// 1. Let blobOrigin be url's blob URL entry's environment's origin.
|
||||
auto blob_origin = url->blob_url_entry()->environment_origin;
|
||||
auto blob_origin = url->blob_url_entry()->environment.origin;
|
||||
|
||||
// 2. Let topLevelOrigin be sourceDocument's relevant settings object's top-level origin.
|
||||
auto top_level_origin = source_document.relevant_settings_object().top_level_origin;
|
||||
|
|
Loading…
Add table
Reference in a new issue