Skip to content

Truly independent web browser

LibWeb: Hold a fetch body's source as immutable bytes

Luke Wilde381050df0c0b
diff --git a/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Libraries/LibWeb/DOM/DocumentLoading.cpp
index f39d151d79b..9be42f5f57d 100644
--- a/Libraries/LibWeb/DOM/DocumentLoading.cpp
+++ b/Libraries/LibWeb/DOM/DocumentLoading.cpp
@@ -132,11 +132,11 @@ static WebIDL::ExceptionOr<GC::Ref<DOM::Document>> load_html_document(HTML::Navi
// AD-HOC: For about:srcdoc, the body bytes are always immediately available in the response source (the srcdoc
// string was inlined when the navigation params were created). Bypass the async body-reading pipeline
// and set up a deferred parser directly, so the document is parsed as soon as scripts may run for it.
- else if (auto const* data = navigation_params.response->body()->source().get_pointer<ByteBuffer>();
- data && document->url() == URL::about_srcdoc()) {
+ else if (auto const& source = navigation_params.response->body()->source();
+ source.has_value() && document->url() == URL::about_srcdoc()) {
auto mime_type = Fetch::Infrastructure::extract_mime_type(navigation_params.response->header_list());
auto url = navigation_params.response->url().value();
- auto parser = HTML::HTMLParser::create_with_uncertain_encoding(document, *data, mime_type);
+ auto parser = HTML::HTMLParser::create_with_uncertain_encoding(document, source->bytes(), mime_type);
document->set_deferred_parser_start(GC::create_function(GC::Heap::the(), [parser, url] {
parser->run(url);
}));
diff --git a/Libraries/LibWeb/Fetch/BodyInit.cpp b/Libraries/LibWeb/Fetch/BodyInit.cpp
index 3a7917740a6..138e14bed13 100644
--- a/Libraries/LibWeb/Fetch/BodyInit.cpp
+++ b/Libraries/LibWeb/Fetch/BodyInit.cpp
@@ -65,7 +65,7 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
Function<ByteBuffer()> action;
// 7. Let source be null.
- Infrastructure::Body::SourceType source {};
+ Optional<Core::ImmutableBytes> source;
// 8. Let length be null.
Optional<u64> length {};
@@ -77,7 +77,7 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
TRY(object.visit(
[&](GC::Ref<FileAPI::Blob> blob) -> WebIDL::ExceptionOr<void> {
// Set source to object.
- source = blob;
+ source = TRY_OR_THROW_OOM(realm.vm(), blob->immutable_bytes());
// Set length to object’s size.
length = blob->size();
// If object’s type attribute is not the empty byte sequence, set type to its value.
@@ -87,7 +87,7 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
},
[&](ReadonlyBytes bytes) -> WebIDL::ExceptionOr<void> {
// Set source to object.
- source = MUST(ByteBuffer::copy(bytes));
+ source = MUST(Core::ImmutableBytes::copy(bytes));
return {};
},
[&](Core::ImmutableBytes const& bytes) -> WebIDL::ExceptionOr<void> {
@@ -97,14 +97,14 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
},
[&](WebIDL::BufferSourceVariant buffer_source) -> WebIDL::ExceptionOr<void> {
// Set source to a copy of the bytes held by object.
- source = MUST(WebIDL::get_buffer_source_copy(buffer_source));
+ source = Core::ImmutableBytes::adopt(MUST(WebIDL::get_buffer_source_copy(buffer_source)));
return {};
},
[&](GC::Ref<XHR::FormData> form_data) -> WebIDL::ExceptionOr<void> {
// Set action to this step: run the multipart/form-data encoding algorithm, with object’s entry list and UTF-8.
auto serialized_form_data = MUST(HTML::serialize_to_multipart_form_data(form_data->entry_list()));
// Set source to object.
- source = serialized_form_data.serialized_data;
+ source = Core::ImmutableBytes::adopt(move(serialized_form_data.serialized_data));
// FIXME: Set length to unclear, see html/6424 for improving this.
// Set type to `multipart/form-data; boundary=`, followed by the multipart/form-data boundary string generated by the multipart/form-data encoding algorithm.
type = Utf16String::formatted("multipart/form-data; boundary={}", serialized_form_data.boundary);
@@ -113,7 +113,7 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
[&](GC::Ref<DOMURL::URLSearchParams> url_search_params) -> WebIDL::ExceptionOr<void> {
// Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list.
auto search_params_string = url_search_params->serialize_to_byte_string();
- source = MUST(ByteBuffer::copy(search_params_string.bytes()));
+ source = MUST(Core::ImmutableBytes::copy(search_params_string.bytes()));
// Set type to `application/x-www-form-urlencoded;charset=UTF-8`.
type = "application/x-www-form-urlencoded;charset=UTF-8"_utf16;
return {};
@@ -121,7 +121,7 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
[&](Utf16String const& scalar_value_string) -> WebIDL::ExceptionOr<void> {
// Set source to the UTF-8 encoding of object.
auto utf8_scalar_value_string = scalar_value_string.to_utf8();
- source = MUST(ByteBuffer::copy(utf8_scalar_value_string.bytes()));
+ source = MUST(Core::ImmutableBytes::copy(utf8_scalar_value_string.bytes()));
// Set type to `text/plain;charset=UTF-8`.
type = "text/plain;charset=UTF-8"_utf16;
return {};
@@ -139,16 +139,12 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
}));
// 11. If source is a byte sequence, then set action to a step that returns source and length to source’s length.
- if (source.has<ByteBuffer>()) {
- action = [source = MUST(ByteBuffer::copy(source.get<ByteBuffer>()))]() mutable {
- return move(source);
+ // NB: A Blob source is held as its bytes too, and is not a byte sequence here.
+ if (source.has_value() && !object.has<GC::Ref<FileAPI::Blob>>()) {
+ action = [bytes = *source] {
+ return bytes.copy_to_byte_buffer().release_value_but_fixme_should_propagate_errors();
};
- length = source.get<ByteBuffer>().size();
- } else if (source.has<Core::ImmutableBytes>()) {
- action = [source = source.get<Core::ImmutableBytes>()]() mutable {
- return source.copy_to_byte_buffer().release_value_but_fixme_should_propagate_errors();
- };
- length = source.get<Core::ImmutableBytes>().size();
+ length = source->size();
}
// 12. If action is non-null, then run these steps in parallel:
diff --git a/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp b/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp
index 66008b7f2ec..4b718bf259d 100644
--- a/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp
@@ -93,7 +93,7 @@ void FetchedDataReceiver::handle_network_data(JS::Realm& realm, Requests::Respon
// Capture bytes for MIME sniffing
if (m_body) {
- if (auto const* file_backed = data.file_backed_slice(); file_backed && m_body->source().has<Empty>())
+ if (auto const* file_backed = data.file_backed_slice(); file_backed && !m_body->source().has_value())
m_body->set_source(file_backed->payload, static_cast<u64>(file_backed->payload.size()));
m_body->append_sniff_bytes(bytes);
} else if (m_pre_body_sniff_buffer.size() < Infrastructure::MAX_SNIFF_BYTES) {
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index ec06ed14bd1..664ff7624bf 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -1026,8 +1026,8 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// response and nullOrBytes.
auto process_body = GC::create_function(GC::Heap::the(), [algorithms, &response](ByteBuffer bytes) {
if (response.body()) {
- if (auto const* source_bytes = response.body()->source().get_pointer<Core::ImmutableBytes>()) {
- (algorithms->process_response_consume_body())(response, *source_bytes);
+ if (auto const& source = response.body()->source(); source.has_value()) {
+ (algorithms->process_response_consume_body())(response, *source);
return;
}
}
@@ -1076,18 +1076,9 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// NB: A body that carries its full contents as an in-memory source (data: URLs, cached responses, and such)
// is read from that directly: Its stream may be populated thru the event loop (Blob::get_stream()
// enqueues from a queued global task, e.g.) — which can't happen while the loop is paused.
- if (auto const& source = internal_response->body()->source(); !source.has<Empty>()) {
- // NB: process_body() re-reads response.body()->source() and, when it is Core::ImmutableBytes, uses
- // that directly and ignores the bytes passed here — so copying it would be pure waste.
- if (source.has<Core::ImmutableBytes>()) {
- success_steps->function()({});
- } else {
- auto bytes = source.visit(
- [](ByteBuffer const& byte_buffer) { return MUST(ByteBuffer::copy(byte_buffer)); },
- [](GC::Ref<FileAPI::Blob> const& blob) { return MUST(ByteBuffer::copy(blob->raw_bytes())); },
- [](auto const&) -> ByteBuffer { VERIFY_NOT_REACHED(); });
- success_steps->function()(move(bytes));
- }
+ if (internal_response->body()->source().has_value()) {
+ // NB: process_body() reads the body's source itself and ignores the bytes passed here.
+ success_steps->function()({});
fetch_params.controller()->stop_body_transport();
} else {
auto reader = internal_response->body()->stream()->get_a_reader();
@@ -1671,7 +1662,7 @@ GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm& realm, Infrastructure::F
// return a network error.
if (internal_response->status() != 303
&& !request->body().has<Empty>()
- && request->body().get<GC::Ref<Infrastructure::Body>>()->source().has<Empty>()) {
+ && !request->body().get<GC::Ref<Infrastructure::Body>>()->source().has_value()) {
return PendingResponse::create(request, Infrastructure::Response::network_error("Request has body but no body source"_string));
}
@@ -1713,14 +1704,7 @@ GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm& realm, Infrastructure::F
// request’s body’s source.
// NOTE: request’s body’s source’s nullity has already been checked.
if (!request->body().has<Empty>()) {
- auto const& source = request->body().get<GC::Ref<Infrastructure::Body>>()->source();
- // NOTE: BodyInitOrReadableBytes is a superset of Body::SourceType
- auto converted_source = source.visit(
- [](ByteBuffer const& byte_buffer) -> BodyInitOrReadableBytes { return byte_buffer.bytes(); },
- [](Core::ImmutableBytes const& bytes) -> BodyInitOrReadableBytes { return bytes; },
- [](GC::Ref<FileAPI::Blob> blob) -> BodyInitOrReadableBytes { return blob; },
- [](Empty) -> BodyInitOrReadableBytes { VERIFY_NOT_REACHED(); });
- auto [body, _] = safely_extract_body(realm, converted_source);
+ auto [body, _] = safely_extract_body(realm, *request->body().get<GC::Ref<Infrastructure::Body>>()->source());
request->set_body(body);
}
@@ -2178,20 +2162,14 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// 2. If request’s body is non-null, then:
if (!request->body().has<Empty>()) {
// 1. If request’s body’s source is null, then return a network error.
- if (request->body().get<GC::Ref<Infrastructure::Body>>()->source().has<Empty>()) {
+ auto const& source = request->body().get<GC::Ref<Infrastructure::Body>>()->source();
+ if (!source.has_value()) {
returned_pending_response->resolve(Infrastructure::Response::network_error("Request has body but no body source"_string));
return;
}
// 2. Set request’s body to the body of the result of safely extracting request’s body’s source.
- auto const& source = request->body().get<GC::Ref<Infrastructure::Body>>()->source();
- // NOTE: BodyInitOrReadableBytes is a superset of Body::SourceType
- auto converted_source = source.visit(
- [](ByteBuffer const& byte_buffer) -> BodyInitOrReadableBytes { return byte_buffer.bytes(); },
- [](Core::ImmutableBytes const& bytes) -> BodyInitOrReadableBytes { return bytes; },
- [](GC::Ref<FileAPI::Blob> blob) -> BodyInitOrReadableBytes { return blob; },
- [](Empty) -> BodyInitOrReadableBytes { VERIFY_NOT_REACHED(); });
- auto [body, _] = safely_extract_body(realm, converted_source);
+ auto [body, _] = safely_extract_body(realm, *source);
request->set_body(body);
}
@@ -2253,7 +2231,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// - isNewConnectionFetch is false
&& is_new_connection_fetch == IsNewConnectionFetch::No
// - request’s body is null, or request’s body is non-null and request’s body’s source is non-null
- && (request->body().has<Empty>() || !request->body().get<GC::Ref<Infrastructure::Body>>()->source().has<Empty>())
+ && (request->body().has<Empty>() || request->body().get<GC::Ref<Infrastructure::Body>>()->source().has_value())
// then:
) {
// 1. If fetchParams is canceled, then return the appropriate network error for fetchParams.
@@ -2374,18 +2352,8 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
load_request.set_top_level_creation_url(client->top_level_creation_url);
if (auto const* body = request->body().get_pointer<GC::Ref<Infrastructure::Body>>()) {
- (*body)->source().visit(
- [&](ByteBuffer const& byte_buffer) {
- load_request.set_body(MUST(ByteBuffer::copy(byte_buffer)));
- },
- [&](Core::ImmutableBytes const& bytes) {
- load_request.set_body(MUST(bytes.copy_to_byte_buffer()));
- },
- [&](GC::Ref<FileAPI::Blob> const& blob) {
- load_request.set_body(MUST(ByteBuffer::copy(blob->raw_bytes())));
- },
- [](Empty) {
- });
+ if (auto const& source = (*body)->source(); source.has_value())
+ load_request.set_body(MUST(source->copy_to_byte_buffer()));
}
auto pending_response = PendingResponse::create(request);
diff --git a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
index 0df809fb055..e7616cada72 100644
--- a/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/NetworkBodyPump.cpp
@@ -87,7 +87,7 @@ void NetworkBodyPump::handle_network_data(Requests::ResponseData data)
// Capture bytes for MIME sniffing
if (m_body) {
- if (file_backed && m_body->source().has<Empty>())
+ if (file_backed && !m_body->source().has_value())
m_body->set_source(file_backed->payload, static_cast<u64>(file_backed->payload.size()));
m_body->append_sniff_bytes(bytes);
} else if (m_pre_body_sniff_buffer.size() < Infrastructure::MAX_SNIFF_BYTES) {
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
index 0425b2b47cd..87668c41712 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
@@ -25,9 +25,9 @@ GC::Ref<Body> Body::create(GC::Ref<Streams::ReadableStream> stream)
return GC::Heap::the().allocate<Body>(stream);
}
-GC::Ref<Body> Body::create(GC::Ref<Streams::ReadableStream> stream, SourceType source, Optional<u64> length)
+GC::Ref<Body> Body::create(GC::Ref<Streams::ReadableStream> stream, Optional<Core::ImmutableBytes> source, Optional<u64> length)
{
- return GC::Heap::the().allocate<Body>(stream, source, length);
+ return GC::Heap::the().allocate<Body>(stream, move(source), length);
}
Body::Body(GC::Ref<Streams::ReadableStream> stream)
@@ -35,10 +35,10 @@ Body::Body(GC::Ref<Streams::ReadableStream> stream)
{
}
-Body::Body(GC::Ref<Streams::ReadableStream> stream, SourceType source, Optional<u64> length)
+Body::Body(GC::Ref<Streams::ReadableStream> stream, Optional<Core::ImmutableBytes> source, Optional<u64> length)
: m_stream(stream)
, m_source(move(source))
- , m_length(move(length))
+ , m_length(length)
{
}
@@ -53,9 +53,6 @@ void Body::visit_edges(Cell::Visitor& visitor)
Base::visit_edges(visitor);
visitor.visit(m_stream);
visitor.visit(m_sniff_bytes_callback);
- m_source.visit(
- [&](GC::Ref<FileAPI::Blob> const& blob) { visitor.visit(blob); },
- [](auto const&) { });
}
void Body::append_sniff_bytes(ReadonlyBytes bytes)
@@ -101,21 +98,11 @@ void Body::set_sniff_bytes_failed()
Optional<Body::SniffBytes> Body::sniff_bytes_if_available() const
{
// Non-streaming body: source has bytes
- if (m_source.has<ByteBuffer>()) {
- auto const& buffer = m_source.get<ByteBuffer>();
- return SniffBytes { buffer.bytes().slice(0, min(buffer.size(), MAX_SNIFF_BYTES)) };
- }
-
- if (m_source.has<Core::ImmutableBytes>()) {
- auto bytes = m_source.get<Core::ImmutableBytes>().bytes();
+ if (m_source.has_value()) {
+ auto bytes = m_source->bytes();
return SniffBytes { bytes.slice(0, min(bytes.size(), MAX_SNIFF_BYTES)) };
}
- if (m_source.has<GC::Ref<FileAPI::Blob>>()) {
- auto raw = m_source.get<GC::Ref<FileAPI::Blob>>()->raw_bytes();
- return SniffBytes { raw.slice(0, min(raw.size(), MAX_SNIFF_BYTES)) };
- }
-
// Streaming body: bytes captured during fetch
if (m_sniff_outcome.has_value())
return SniffBytes { m_sniff_bytes, *m_sniff_outcome };
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h
index e02ca39d2e9..6b2c9a5b0db 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h
@@ -17,7 +17,6 @@
#include <LibGC/Root.h>
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Infrastructure/Task.h>
-#include <LibWeb/FileAPI/Blob.h>
#include <LibWeb/Streams/ReadableStream.h>
#include <LibWeb/WebIDL/Promise.h>
@@ -32,7 +31,6 @@ class WEB_API Body final : public JS::Cell {
GC_DECLARE_ALLOCATOR(Body);
public:
- using SourceType = Variant<Empty, ByteBuffer, Core::ImmutableBytes, GC::Ref<FileAPI::Blob>>;
// processBody must be an algorithm accepting a byte sequence.
using ProcessBodyCallback = GC::Ref<GC::Function<void(ByteBuffer)>>;
// processBodyError must be an algorithm optionally accepting an exception.
@@ -43,11 +41,11 @@ public:
using ProcessEndOfBodyCallback = GC::Ref<GC::Function<void()>>;
[[nodiscard]] static GC::Ref<Body> create(GC::Ref<Streams::ReadableStream>);
- [[nodiscard]] static GC::Ref<Body> create(GC::Ref<Streams::ReadableStream>, SourceType, Optional<u64>);
+ [[nodiscard]] static GC::Ref<Body> create(GC::Ref<Streams::ReadableStream>, Optional<Core::ImmutableBytes>, Optional<u64>);
[[nodiscard]] GC::Ref<Streams::ReadableStream> stream() const { return *m_stream; }
void set_stream(GC::Ref<Streams::ReadableStream> value) { m_stream = value; }
- [[nodiscard]] SourceType const& source() const { return m_source; }
+ [[nodiscard]] Optional<Core::ImmutableBytes> const& source() const { return m_source; }
void set_source(Core::ImmutableBytes, Optional<u64> length);
[[nodiscard]] Optional<u64> const& length() const { return m_length; }
@@ -55,7 +53,7 @@ public:
// Non-standard infrastructure to obtain the "resource header" for MIME type sniffing.
// The spec defines resource header as the byte sequence to sniff, obtained by reading
// "until [...] 1445 or more bytes have been read" or end of resource is reached.
- // For non-streaming bodies (ByteBuffer/Blob source), bytes are available immediately.
+ // For a body with a source, bytes are available immediately.
// For streaming bodies, bytes are captured during fetch and delivered via callback.
enum class SniffOutcome : u8 {
Complete,
@@ -86,7 +84,7 @@ public:
private:
explicit Body(GC::Ref<Streams::ReadableStream>);
- Body(GC::Ref<Streams::ReadableStream>, SourceType, Optional<u64>);
+ Body(GC::Ref<Streams::ReadableStream>, Optional<Core::ImmutableBytes>, Optional<u64>);
// https://fetch.spec.whatwg.org/#concept-body-stream
// A stream (a ReadableStream object).
@@ -94,7 +92,8 @@ private:
// https://fetch.spec.whatwg.org/#concept-body-source
// A source (null, a byte sequence, a Blob object, or a FormData object), initially null.
- SourceType m_source;
+ // NB: A Blob or FormData source is held as its bytes.
+ Optional<Core::ImmutableBytes> m_source;
// https://fetch.spec.whatwg.org/#concept-body-total-bytes
// A length (null or an integer), initially null.
diff --git a/Libraries/LibWeb/Fetch/Request.cpp b/Libraries/LibWeb/Fetch/Request.cpp
index a8a0beee2c2..9274ff93d07 100644
--- a/Libraries/LibWeb/Fetch/Request.cpp
+++ b/Libraries/LibWeb/Fetch/Request.cpp
@@ -627,7 +627,7 @@ WebIDL::ExceptionOr<GC::Ref<Request>> Request::create_with_settings(HTML::Enviro
// 39. If inputOrInitBody is non-null and inputOrInitBody’s source is null, then:
// FIXME: The spec doesn't check if inputOrInitBody is a body before accessing source.
- if (input_or_init_body.has_value() && input_or_init_body->has<GC::Ref<Infrastructure::Body>>() && input_or_init_body->get<GC::Ref<Infrastructure::Body>>()->source().has<Empty>()) {
+ if (input_or_init_body.has_value() && input_or_init_body->has<GC::Ref<Infrastructure::Body>>() && !input_or_init_body->get<GC::Ref<Infrastructure::Body>>()->source().has_value()) {
// 1. If initBody is non-null and init["duplex"] does not exist, then throw a TypeError.
if (init_body.has_value() && !init.duplex.has_value())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Body without source requires 'duplex' value to be set"_utf16 };
diff --git a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
index c35083201db..02b5bb76106 100644
--- a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
+++ b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
@@ -59,11 +59,9 @@ static NavigationRequestDescriptor create_navigation_request_descriptor(Fetch::I
static Optional<ByteBuffer> copy_body_source(Fetch::Infrastructure::Body const& body)
{
- return body.source().visit(
- [](Empty) -> Optional<ByteBuffer> { return {}; },
- [](ByteBuffer const& bytes) -> Optional<ByteBuffer> { return MUST(ByteBuffer::copy(bytes)); },
- [](Core::ImmutableBytes const& bytes) -> Optional<ByteBuffer> { return MUST(ByteBuffer::copy(bytes.bytes())); },
- [](GC::Ref<FileAPI::Blob> const& blob) -> Optional<ByteBuffer> { return MUST(ByteBuffer::copy(blob->raw_bytes())); });
+ if (auto const& source = body.source(); source.has_value())
+ return MUST(source->copy_to_byte_buffer());
+ return {};
}
static NavigationResponseDescriptor create_navigation_response_descriptor(Fetch::Infrastructure::Response const& response)
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index 0dfc2e98bcd..35e44ba8c3c 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -1978,7 +1978,7 @@ GC::Ref<HTMLParser> HTMLParser::create_with_open_input_stream(DOM::Document& doc
return document.relevant_settings_object().realm().create<HTMLParser>(document, scripting_mode, ScriptCreatedParser::No, encoding_confidence);
}
-GC::Ref<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input, Optional<MimeSniff::MimeType> maybe_mime_type)
+GC::Ref<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ReadonlyBytes input, Optional<MimeSniff::MimeType> maybe_mime_type)
{
auto scripting_mode = document.is_scripting_enabled() ? ParserScriptingMode::Normal : ParserScriptingMode::Disabled;
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.h b/Libraries/LibWeb/HTML/Parser/HTMLParser.h
index 131176bdb0d..df107663fe9 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLParser.h
+++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.h
@@ -39,7 +39,7 @@ public:
static GC::Ref<HTMLParser> create_for_scripting(DOM::Document&);
static GC::Ref<HTMLParser> create_with_open_input_stream(DOM::Document&, EncodingConfidence = EncodingConfidence::Irrelevant);
- static GC::Ref<HTMLParser> create_with_uncertain_encoding(DOM::Document&, ByteBuffer const& input, Optional<MimeSniff::MimeType> maybe_mime_type = {});
+ static GC::Ref<HTMLParser> create_with_uncertain_encoding(DOM::Document&, ReadonlyBytes input, Optional<MimeSniff::MimeType> maybe_mime_type = {});
static GC::Ref<HTMLParser> create_from_byte_string(DOM::Document&, StringView input, ParserScriptingMode, StringView encoding);
static GC::Ref<HTMLParser> create_for_decoded_string(DOM::Document&, Utf16View input, ParserScriptingMode, Utf16View encoding);