1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:17:36 +00:00

LibWeb: Port Document interface from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-09-15 21:46:58 +12:00 committed by Andreas Kling
parent 9d88e14f20
commit e74031a396
15 changed files with 108 additions and 96 deletions

View file

@ -56,7 +56,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_docume
// 3. If qualifiedName is not the empty string, then set element to the result of running the internal createElementNS steps, given document, namespace, qualifiedName, and an empty dictionary.
if (!qualified_name.is_empty())
element = TRY(xml_document->create_element_ns(namespace_.value().to_deprecated_string(), qualified_name.to_deprecated_string(), ElementCreationOptions {}));
element = TRY(xml_document->create_element_ns(namespace_.value(), qualified_name, ElementCreationOptions {}));
// 4. If doctype is non-null, append doctype to document.
if (doctype)
@ -74,13 +74,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> DOMImplementation::create_docume
if (deprecated_namespace == Namespace::HTML) {
// -> HTML namespace
xml_document->set_content_type("application/xhtml+xml");
xml_document->set_content_type("application/xhtml+xml"_string);
} else if (deprecated_namespace == Namespace::SVG) {
// -> SVG namespace
xml_document->set_content_type("image/svg+xml");
xml_document->set_content_type("image/svg+xml"_string);
} else {
// -> Any other namespace
xml_document->set_content_type("application/xml");
xml_document->set_content_type("application/xml"_string);
}
// 8. Return document.
@ -94,7 +94,7 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(Optional<Stri
auto html_document = Document::create(realm());
// 2. Set docs content type to "text/html".
html_document->set_content_type("text/html");
html_document->set_content_type("text/html"_string);
html_document->set_ready_for_post_load_tasks(true);

View file

@ -257,7 +257,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> Document::create_and_initialize(
// and navigation id is navigationParams's id.
auto document = HTML::HTMLDocument::create(window->realm());
document->m_type = type;
document->m_content_type = move(content_type);
document->m_content_type = MUST(String::from_deprecated_string(content_type));
document->set_origin(navigation_params.origin);
document->m_policy_container = navigation_params.policy_container;
document->m_active_sandboxing_flag_set = navigation_params.final_sandboxing_flag_set;
@ -410,7 +410,7 @@ JS::GCPtr<Selection::Selection> Document::get_selection() const
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write
WebIDL::ExceptionOr<void> Document::write(Vector<DeprecatedString> const& strings)
WebIDL::ExceptionOr<void> Document::write(Vector<String> const& strings)
{
StringBuilder builder;
builder.join(""sv, strings);
@ -419,7 +419,7 @@ WebIDL::ExceptionOr<void> Document::write(Vector<DeprecatedString> const& string
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-writeln
WebIDL::ExceptionOr<void> Document::writeln(Vector<DeprecatedString> const& strings)
WebIDL::ExceptionOr<void> Document::writeln(Vector<String> const& strings)
{
StringBuilder builder;
builder.join(""sv, strings);
@ -464,7 +464,7 @@ WebIDL::ExceptionOr<void> Document::run_the_document_write_steps(StringView inpu
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-open
WebIDL::ExceptionOr<Document*> Document::open(StringView, StringView)
WebIDL::ExceptionOr<Document*> Document::open(Optional<String> const&, Optional<String> const&)
{
// 1. If document is an XML document, then throw an "InvalidStateError" DOMException exception.
if (m_type == Type::XML)
@ -720,7 +720,7 @@ DeprecatedString Document::title() const
}
// https://html.spec.whatwg.org/multipage/dom.html#document.title
WebIDL::ExceptionOr<void> Document::set_title(DeprecatedString const& title)
WebIDL::ExceptionOr<void> Document::set_title(String const& title)
{
auto* document_element = this->document_element();
@ -744,7 +744,7 @@ WebIDL::ExceptionOr<void> Document::set_title(DeprecatedString const& title)
}
// 3. String replace all with the given value within element.
element->string_replace_all(title);
element->string_replace_all(title.to_deprecated_string());
}
// -> If the document element is in the HTML namespace
@ -773,7 +773,7 @@ WebIDL::ExceptionOr<void> Document::set_title(DeprecatedString const& title)
}
// 4. String replace all with the given value within element.
element->string_replace_all(title);
element->string_replace_all(title.to_deprecated_string());
}
// -> Otherwise
@ -784,7 +784,7 @@ WebIDL::ExceptionOr<void> Document::set_title(DeprecatedString const& title)
if (auto* page = this->page()) {
if (browsing_context() == &page->top_level_browsing_context())
page->client().page_did_change_title(title);
page->client().page_did_change_title(title.to_deprecated_string());
}
return {};
@ -1182,10 +1182,11 @@ void Document::set_hovered_node(Node* node)
}
}
JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(DeprecatedString const& name)
JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(String const& name)
{
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [name](Element const& element) {
return element.name() == name;
auto deprecated_name = name.to_deprecated_string();
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [deprecated_name](Element const& element) {
return element.name() == deprecated_name;
});
}
@ -1359,14 +1360,12 @@ void Document::evaluate_javascript_url(StringView url)
}
// https://dom.spec.whatwg.org/#dom-document-createelement
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(DeprecatedString const& a_local_name, Variant<DeprecatedString, ElementCreationOptions> const& options)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(String const& a_local_name, Variant<String, ElementCreationOptions> const& options)
{
auto& vm = this->vm();
auto local_name = a_local_name;
auto local_name = a_local_name.to_deprecated_string();
// 1. If localName does not match the Name production, then throw an "InvalidCharacterError" DOMException.
if (!is_valid_name(local_name))
if (!is_valid_name(a_local_name))
return WebIDL::InvalidCharacterError::create(realm(), "Invalid character in tag name."_fly_string);
// 2. If this is an HTML document, then set localName to localName in ASCII lowercase.
@ -1379,8 +1378,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(Deprecat
// 4. If options is a dictionary and options["is"] exists, then set is to it.
if (options.has<ElementCreationOptions>()) {
auto const& element_creation_options = options.get<ElementCreationOptions>();
if (!element_creation_options.is.is_null())
is_value = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(element_creation_options.is));
if (element_creation_options.is.has_value())
is_value = element_creation_options.is.value();
}
// 5. Let namespace be the HTML namespace, if this is an HTML document or thiss content type is "application/xhtml+xml"; otherwise null.
@ -1394,12 +1393,15 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element(Deprecat
// https://dom.spec.whatwg.org/#dom-document-createelementns
// https://dom.spec.whatwg.org/#internal-createelementns-steps
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name, Variant<DeprecatedString, ElementCreationOptions> const& options)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Optional<String> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options)
{
auto& vm = this->vm();
// FIXME: This conversion is ugly
StringView namespace_view;
if (namespace_.has_value())
namespace_view = namespace_->bytes_as_string_view();
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name));
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_view, qualified_name.to_deprecated_string()));
// 2. Let is be null.
Optional<String> is_value;
@ -1407,8 +1409,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> Document::create_element_ns(Depre
// 3. If options is a dictionary and options["is"] exists, then set is to it.
if (options.has<ElementCreationOptions>()) {
auto const& element_creation_options = options.get<ElementCreationOptions>();
if (!element_creation_options.is.is_null())
is_value = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(element_creation_options.is));
if (element_creation_options.is.has_value())
is_value = element_creation_options.is.value();
}
// 4. Return the result of creating an element given document, localName, namespace, prefix, is, and with the synchronous custom elements flag set.
@ -1420,25 +1422,25 @@ JS::NonnullGCPtr<DocumentFragment> Document::create_document_fragment()
return heap().allocate<DocumentFragment>(realm(), *this);
}
JS::NonnullGCPtr<Text> Document::create_text_node(DeprecatedString const& data)
JS::NonnullGCPtr<Text> Document::create_text_node(String const& data)
{
return heap().allocate<Text>(realm(), *this, MUST(String::from_deprecated_string(data)));
return heap().allocate<Text>(realm(), *this, data);
}
JS::NonnullGCPtr<Comment> Document::create_comment(DeprecatedString const& data)
JS::NonnullGCPtr<Comment> Document::create_comment(String const& data)
{
return heap().allocate<Comment>(realm(), *this, MUST(String::from_deprecated_string(data)));
return heap().allocate<Comment>(realm(), *this, data);
}
// https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> Document::create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data)
WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> Document::create_processing_instruction(String const& target, String const& data)
{
// FIXME: 1. If target does not match the Name production, then throw an "InvalidCharacterError" DOMException.
// FIXME: 2. If data contains the string "?>", then throw an "InvalidCharacterError" DOMException.
// 3. Return a new ProcessingInstruction node, with target set to target, data set to data, and node document set to this.
return heap().allocate<ProcessingInstruction>(realm(), *this, data, target);
return heap().allocate<ProcessingInstruction>(realm(), *this, data.to_deprecated_string(), target.to_deprecated_string());
}
JS::NonnullGCPtr<Range> Document::create_range()
@ -1447,7 +1449,7 @@ JS::NonnullGCPtr<Range> Document::create_range()
}
// https://dom.spec.whatwg.org/#dom-document-createevent
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedString const& interface)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(StringView interface)
{
auto& realm = this->realm();
@ -2242,7 +2244,7 @@ static inline bool is_valid_name_character(u32 code_point)
|| (code_point >= 0x203f && code_point <= 0x2040);
}
bool Document::is_valid_name(DeprecatedString const& name)
bool Document::is_valid_name(String const& name)
{
auto code_points = Utf8View { name };
auto it = code_points.begin();
@ -2491,7 +2493,7 @@ DeprecatedString Document::domain() const
return URLParser::serialize_host(effective_domain.release_value()).release_value_but_fixme_should_propagate_errors().to_deprecated_string();
}
void Document::set_domain(DeprecatedString const& domain)
void Document::set_domain(String const& domain)
{
dbgln("(STUBBED) Document::set_domain(domain='{}')", domain);
}
@ -2919,7 +2921,7 @@ void Document::did_stop_being_active_document_in_browsing_context(Badge<HTML::Br
}
// https://w3c.github.io/editing/docs/execCommand/#querycommandsupported()
bool Document::query_command_supported(DeprecatedString const& command) const
bool Document::query_command_supported(String const& command) const
{
dbgln("(STUBBED) Document::query_command_supported(command='{}')", command);
return false;
@ -2981,7 +2983,7 @@ DeprecatedString Document::dump_accessibility_tree_as_json()
}
// https://dom.spec.whatwg.org/#dom-document-createattribute
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(DeprecatedString const& local_name)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(String const& local_name)
{
// 1. If localName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
if (!is_valid_name(local_name))
@ -2989,14 +2991,20 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute(Deprecate
// 2. If this is an HTML document, then set localName to localName in ASCII lowercase.
// 3. Return a new attribute whose local name is localName and node document is this.
return Attr::create(*this, is_html_document() ? local_name.to_lowercase() : local_name);
auto deprecated_local_name = local_name.to_deprecated_string();
return Attr::create(*this, is_html_document() ? deprecated_local_name.to_lowercase() : deprecated_local_name);
}
// https://dom.spec.whatwg.org/#dom-document-createattributens
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> Document::create_attribute_ns(Optional<String> const& namespace_, String const& qualified_name)
{
// FIXME: This conversion is ugly
StringView namespace_view;
if (namespace_.has_value())
namespace_view = namespace_->bytes_as_string_view();
// 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name));
auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_view, qualified_name.to_deprecated_string()));
// 2. Return a new attribute whose namespace is namespace, namespace prefix is prefix, local name is localName, and node document is this.

View file

@ -70,7 +70,7 @@ struct DocumentUnloadTimingInfo {
};
struct ElementCreationOptions {
DeprecatedString is;
Optional<String> is;
};
enum class PolicyControlledFeature {
@ -173,7 +173,7 @@ public:
WebIDL::ExceptionOr<void> set_body(HTML::HTMLElement* new_body);
DeprecatedString title() const;
WebIDL::ExceptionOr<void> set_title(DeprecatedString const&);
WebIDL::ExceptionOr<void> set_title(String const&);
HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); }
HTML::BrowsingContext const* browsing_context() const { return m_browsing_context.ptr(); }
@ -216,7 +216,7 @@ public:
void schedule_style_update();
void schedule_layout_update();
JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(DeprecatedString const&);
JS::NonnullGCPtr<HTMLCollection> get_elements_by_name(String const&);
JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(StringView);
JS::NonnullGCPtr<HTMLCollection> applets();
@ -237,17 +237,17 @@ public:
void navigate_to_javascript_url(StringView url);
void evaluate_javascript_url(StringView url);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(DeprecatedString const& local_name, Variant<DeprecatedString, ElementCreationOptions> const& options);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name, Variant<DeprecatedString, ElementCreationOptions> const& options);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(String const& local_name, Variant<String, ElementCreationOptions> const& options);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element_ns(Optional<String> const& namespace_, String const& qualified_name, Variant<String, ElementCreationOptions> const& options);
JS::NonnullGCPtr<DocumentFragment> create_document_fragment();
JS::NonnullGCPtr<Text> create_text_node(DeprecatedString const& data);
JS::NonnullGCPtr<Comment> create_comment(DeprecatedString const& data);
WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data);
JS::NonnullGCPtr<Text> create_text_node(String const& data);
JS::NonnullGCPtr<Comment> create_comment(String const& data);
WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> create_processing_instruction(String const& target, String const& data);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute(DeprecatedString const& local_name);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute(String const& local_name);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create_attribute_ns(Optional<String> const& namespace_, String const& qualified_name);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(DeprecatedString const& interface);
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(StringView interface);
JS::NonnullGCPtr<Range> create_range();
void set_pending_parsing_blocking_script(Badge<HTML::HTMLScriptElement>, HTML::HTMLScriptElement*);
@ -316,28 +316,28 @@ public:
void set_window(HTML::Window&);
WebIDL::ExceptionOr<void> write(Vector<DeprecatedString> const& strings);
WebIDL::ExceptionOr<void> writeln(Vector<DeprecatedString> const& strings);
WebIDL::ExceptionOr<void> write(Vector<String> const& strings);
WebIDL::ExceptionOr<void> writeln(Vector<String> const& strings);
WebIDL::ExceptionOr<Document*> open(StringView = ""sv, StringView = ""sv);
WebIDL::ExceptionOr<Document*> open(Optional<String> const& = {}, Optional<String> const& = {});
WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> open(StringView url, StringView name, StringView features);
WebIDL::ExceptionOr<void> close();
HTML::Window* default_view() { return m_window.ptr(); }
HTML::Window const* default_view() const { return m_window.ptr(); }
DeprecatedString const& content_type() const { return m_content_type; }
void set_content_type(DeprecatedString const& content_type) { m_content_type = content_type; }
String const& content_type() const { return m_content_type; }
void set_content_type(String content_type) { m_content_type = move(content_type); }
bool has_encoding() const { return m_encoding.has_value(); }
Optional<DeprecatedString> const& encoding() const { return m_encoding; }
DeprecatedString encoding_or_default() const { return m_encoding.value_or("UTF-8"); }
void set_encoding(Optional<DeprecatedString> const& encoding) { m_encoding = encoding; }
Optional<String> const& encoding() const { return m_encoding; }
String encoding_or_default() const { return m_encoding.value_or("UTF-8"_string); }
void set_encoding(Optional<String> encoding) { m_encoding = move(encoding); }
// NOTE: These are intended for the JS bindings
DeprecatedString character_set() const { return encoding_or_default(); }
DeprecatedString charset() const { return encoding_or_default(); }
DeprecatedString input_encoding() const { return encoding_or_default(); }
String character_set() const { return encoding_or_default(); }
String charset() const { return encoding_or_default(); }
String input_encoding() const { return encoding_or_default(); }
bool ready_for_post_load_tasks() const { return m_ready_for_post_load_tasks; }
void set_ready_for_post_load_tasks(bool ready) { m_ready_for_post_load_tasks = ready; }
@ -409,7 +409,7 @@ public:
void set_is_temporary_document_for_fragment_parsing(Badge<HTML::HTMLParser>) { m_temporary_document_for_fragment_parsing = true; }
[[nodiscard]] bool is_temporary_document_for_fragment_parsing() const { return m_temporary_document_for_fragment_parsing; }
static bool is_valid_name(DeprecatedString const&);
static bool is_valid_name(String const&);
struct PrefixAndTagName {
DeprecatedFlyString prefix;
@ -449,7 +449,7 @@ public:
void set_is_initial_about_blank(bool b) { m_is_initial_about_blank = b; }
DeprecatedString domain() const;
void set_domain(DeprecatedString const& domain);
void set_domain(String const&);
auto& pending_scroll_event_targets() { return m_pending_scroll_event_targets; }
auto& pending_scrollend_event_targets() { return m_pending_scrollend_event_targets; }
@ -504,7 +504,7 @@ public:
void did_stop_being_active_document_in_browsing_context(Badge<HTML::BrowsingContext>);
bool query_command_supported(DeprecatedString const&) const;
bool query_command_supported(String const&) const;
DeprecatedString dump_accessibility_tree_as_json();
@ -604,8 +604,8 @@ private:
JS::GCPtr<Document> m_appropriate_template_contents_owner_document;
HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading };
DeprecatedString m_content_type { "application/xml" };
Optional<DeprecatedString> m_encoding;
String m_content_type { "application/xml"_string };
Optional<String> m_encoding;
bool m_ready_for_post_load_tasks { false };

View file

@ -23,7 +23,7 @@
#import <Selection/Selection.idl>
// https://dom.spec.whatwg.org/#document
[Exposed=Window, UseDeprecatedAKString]
[Exposed=Window]
interface Document : Node {
constructor();

View file

@ -87,7 +87,7 @@ static bool build_text_document(DOM::Document& document, ByteBuffer const& data)
auto title_element = DOM::create_element(document, HTML::TagNames::title, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(head_element->append_child(title_element));
auto title_text = document.create_text_node(document.url().basename());
auto title_text = document.create_text_node(MUST(String::from_deprecated_string(document.url().basename())));
MUST(title_element->append_child(title_text));
auto body_element = DOM::create_element(document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
@ -96,7 +96,7 @@ static bool build_text_document(DOM::Document& document, ByteBuffer const& data)
auto pre_element = DOM::create_element(document, HTML::TagNames::pre, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(body_element->append_child(pre_element));
MUST(pre_element->append_child(document.create_text_node(DeprecatedString::copy(data))));
MUST(pre_element->append_child(document.create_text_node(String::from_utf8(StringView { data }).release_value_but_fixme_should_propagate_errors())));
return true;
}
@ -206,13 +206,13 @@ bool parse_document(DOM::Document& document, ByteBuffer const& data)
parser->run(document.url());
return true;
}
if (mime_type.ends_with("+xml"sv) || mime_type.is_one_of("text/xml", "application/xml"))
if (mime_type.ends_with_bytes("+xml"sv) || mime_type.is_one_of("text/xml", "application/xml"))
return build_xml_document(document, data);
if (mime_type.starts_with("image/"sv))
if (mime_type.starts_with_bytes("image/"sv))
return build_image_document(document, data);
if (mime_type.starts_with("video/"sv))
if (mime_type.starts_with_bytes("video/"sv))
return build_video_document(document);
if (mime_type.starts_with("audio/"sv))
if (mime_type.starts_with_bytes("audio/"sv))
return build_audio_document(document);
if (mime_type == "text/plain" || mime_type == "application/json")
return build_text_document(document, data);
@ -236,8 +236,8 @@ JS::GCPtr<DOM::Document> load_document(Optional<HTML::NavigationParams> navigati
if (navigation_params->response->body()) {
auto process_body = [navigation_params, document](ByteBuffer bytes) {
auto extracted_mime_type = navigation_params->response->header_list()->extract_mime_type().release_value_but_fixme_should_propagate_errors();
auto mime_type = extracted_mime_type.has_value() ? extracted_mime_type.value().essence().bytes_as_string_view() : StringView {};
document->set_content_type(mime_type);
auto mime_type = extracted_mime_type.has_value() ? extracted_mime_type.value().essence() : String {};
document->set_content_type(move(mime_type));
if (!parse_document(*document, bytes)) {
// FIXME: Load html page with an error if parsing failed.