diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp index d01cb7df65..01e24b2e84 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp @@ -56,7 +56,7 @@ WebIDL::ExceptionOr> 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> 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 DOMImplementation::create_html_document(Optionalset_content_type("text/html"); + html_document->set_content_type("text/html"_string); html_document->set_ready_for_post_load_tasks(true); diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 2e84456cf5..14dfc31fd4 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -257,7 +257,7 @@ WebIDL::ExceptionOr> 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 Document::get_selection() const } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write -WebIDL::ExceptionOr Document::write(Vector const& strings) +WebIDL::ExceptionOr Document::write(Vector const& strings) { StringBuilder builder; builder.join(""sv, strings); @@ -419,7 +419,7 @@ WebIDL::ExceptionOr Document::write(Vector const& string } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-writeln -WebIDL::ExceptionOr Document::writeln(Vector const& strings) +WebIDL::ExceptionOr Document::writeln(Vector const& strings) { StringBuilder builder; builder.join(""sv, strings); @@ -464,7 +464,7 @@ WebIDL::ExceptionOr Document::run_the_document_write_steps(StringView inpu } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-open -WebIDL::ExceptionOr Document::open(StringView, StringView) +WebIDL::ExceptionOr Document::open(Optional const&, Optional 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 Document::set_title(DeprecatedString const& title) +WebIDL::ExceptionOr Document::set_title(String const& title) { auto* document_element = this->document_element(); @@ -744,7 +744,7 @@ WebIDL::ExceptionOr 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 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 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 Document::get_elements_by_name(DeprecatedString const& name) +JS::NonnullGCPtr 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> Document::create_element(DeprecatedString const& a_local_name, Variant const& options) +WebIDL::ExceptionOr> Document::create_element(String const& a_local_name, Variant 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> Document::create_element(Deprecat // 4. If options is a dictionary and options["is"] exists, then set is to it. if (options.has()) { auto const& element_creation_options = options.get(); - 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 this’s content type is "application/xhtml+xml"; otherwise null. @@ -1394,12 +1393,15 @@ WebIDL::ExceptionOr> Document::create_element(Deprecat // https://dom.spec.whatwg.org/#dom-document-createelementns // https://dom.spec.whatwg.org/#internal-createelementns-steps -WebIDL::ExceptionOr> Document::create_element_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name, Variant const& options) +WebIDL::ExceptionOr> Document::create_element_ns(Optional const& namespace_, String const& qualified_name, Variant 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 is_value; @@ -1407,8 +1409,8 @@ WebIDL::ExceptionOr> Document::create_element_ns(Depre // 3. If options is a dictionary and options["is"] exists, then set is to it. if (options.has()) { auto const& element_creation_options = options.get(); - 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 Document::create_document_fragment() return heap().allocate(realm(), *this); } -JS::NonnullGCPtr Document::create_text_node(DeprecatedString const& data) +JS::NonnullGCPtr Document::create_text_node(String const& data) { - return heap().allocate(realm(), *this, MUST(String::from_deprecated_string(data))); + return heap().allocate(realm(), *this, data); } -JS::NonnullGCPtr Document::create_comment(DeprecatedString const& data) +JS::NonnullGCPtr Document::create_comment(String const& data) { - return heap().allocate(realm(), *this, MUST(String::from_deprecated_string(data))); + return heap().allocate(realm(), *this, data); } // https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction -WebIDL::ExceptionOr> Document::create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data) +WebIDL::ExceptionOr> 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(realm(), *this, data, target); + return heap().allocate(realm(), *this, data.to_deprecated_string(), target.to_deprecated_string()); } JS::NonnullGCPtr Document::create_range() @@ -1447,7 +1449,7 @@ JS::NonnullGCPtr Document::create_range() } // https://dom.spec.whatwg.org/#dom-document-createevent -WebIDL::ExceptionOr> Document::create_event(DeprecatedString const& interface) +WebIDL::ExceptionOr> 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> Document::create_attribute(DeprecatedString const& local_name) +WebIDL::ExceptionOr> 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> 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> Document::create_attribute_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name) +WebIDL::ExceptionOr> Document::create_attribute_ns(Optional 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. diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index fe3d68be5c..587f0144d6 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -70,7 +70,7 @@ struct DocumentUnloadTimingInfo { }; struct ElementCreationOptions { - DeprecatedString is; + Optional is; }; enum class PolicyControlledFeature { @@ -173,7 +173,7 @@ public: WebIDL::ExceptionOr set_body(HTML::HTMLElement* new_body); DeprecatedString title() const; - WebIDL::ExceptionOr set_title(DeprecatedString const&); + WebIDL::ExceptionOr 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 get_elements_by_name(DeprecatedString const&); + JS::NonnullGCPtr get_elements_by_name(String const&); JS::NonnullGCPtr get_elements_by_class_name(StringView); JS::NonnullGCPtr applets(); @@ -237,17 +237,17 @@ public: void navigate_to_javascript_url(StringView url); void evaluate_javascript_url(StringView url); - WebIDL::ExceptionOr> create_element(DeprecatedString const& local_name, Variant const& options); - WebIDL::ExceptionOr> create_element_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name, Variant const& options); + WebIDL::ExceptionOr> create_element(String const& local_name, Variant const& options); + WebIDL::ExceptionOr> create_element_ns(Optional const& namespace_, String const& qualified_name, Variant const& options); JS::NonnullGCPtr create_document_fragment(); - JS::NonnullGCPtr create_text_node(DeprecatedString const& data); - JS::NonnullGCPtr create_comment(DeprecatedString const& data); - WebIDL::ExceptionOr> create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data); + JS::NonnullGCPtr create_text_node(String const& data); + JS::NonnullGCPtr create_comment(String const& data); + WebIDL::ExceptionOr> create_processing_instruction(String const& target, String const& data); - WebIDL::ExceptionOr> create_attribute(DeprecatedString const& local_name); - WebIDL::ExceptionOr> create_attribute_ns(DeprecatedString const& namespace_, DeprecatedString const& qualified_name); + WebIDL::ExceptionOr> create_attribute(String const& local_name); + WebIDL::ExceptionOr> create_attribute_ns(Optional const& namespace_, String const& qualified_name); - WebIDL::ExceptionOr> create_event(DeprecatedString const& interface); + WebIDL::ExceptionOr> create_event(StringView interface); JS::NonnullGCPtr create_range(); void set_pending_parsing_blocking_script(Badge, HTML::HTMLScriptElement*); @@ -316,28 +316,28 @@ public: void set_window(HTML::Window&); - WebIDL::ExceptionOr write(Vector const& strings); - WebIDL::ExceptionOr writeln(Vector const& strings); + WebIDL::ExceptionOr write(Vector const& strings); + WebIDL::ExceptionOr writeln(Vector const& strings); - WebIDL::ExceptionOr open(StringView = ""sv, StringView = ""sv); + WebIDL::ExceptionOr open(Optional const& = {}, Optional const& = {}); WebIDL::ExceptionOr> open(StringView url, StringView name, StringView features); WebIDL::ExceptionOr 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 const& encoding() const { return m_encoding; } - DeprecatedString encoding_or_default() const { return m_encoding.value_or("UTF-8"); } - void set_encoding(Optional const& encoding) { m_encoding = encoding; } + Optional const& encoding() const { return m_encoding; } + String encoding_or_default() const { return m_encoding.value_or("UTF-8"_string); } + void set_encoding(Optional 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) { 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); - 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 m_appropriate_template_contents_owner_document; HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Loading }; - DeprecatedString m_content_type { "application/xml" }; - Optional m_encoding; + String m_content_type { "application/xml"_string }; + Optional m_encoding; bool m_ready_for_post_load_tasks { false }; diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index becfc025cc..a2d285b1c4 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -23,7 +23,7 @@ #import // https://dom.spec.whatwg.org/#document -[Exposed=Window, UseDeprecatedAKString] +[Exposed=Window] interface Document : Node { constructor(); diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp index 30dae81445..6c65b004de 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -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 load_document(Optional 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. diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 43876867f6..0054282e72 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -210,7 +210,7 @@ JS::NonnullGCPtr BrowsingContext::create_a_new_browsing_context window->set_associated_document(*document); document->set_quirks_mode(DOM::QuirksMode::Yes); - document->set_content_type("text/html"); + document->set_content_type("text/html"_string); document->set_origin(origin); document->set_url(AK::URL("about:blank")); document->set_cross_origin_opener_policy(coop); @@ -370,7 +370,7 @@ WebIDL::ExceptionOr BrowsingContext document->set_document_type(DOM::Document::Type::HTML); // content type: "text/html" - document->set_content_type("text/html"); + document->set_content_type("text/html"_string); // mode: "quirks" document->set_quirks_mode(DOM::QuirksMode::Yes); @@ -626,7 +626,7 @@ void BrowsingContext::scroll_to_anchor(DeprecatedString const& fragment) auto element = document->get_element_by_id(fragment); if (!element) { - auto candidates = document->get_elements_by_name(fragment); + auto candidates = document->get_elements_by_name(MUST(String::from_deprecated_string(fragment))); for (auto& candidate : candidates->collect_matching_elements()) { if (is(*candidate)) { element = &verify_cast(*candidate); diff --git a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp index 0ef54dd61c..a75754c8c5 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp @@ -43,7 +43,7 @@ JS::NonnullGCPtr DOMParser::parse_from_string(StringView string, // -> "text/html" // 1. Set document's type to "html". document = HTML::HTMLDocument::create(realm(), verify_cast(relevant_global_object(*this)).associated_document().url()); - document->set_content_type(Bindings::idl_enum_to_string(type).to_deprecated_string()); + document->set_content_type(Bindings::idl_enum_to_string(type)); document->set_document_type(DOM::Document::Type::HTML); // 2. Create an HTML parser parser, associated with document. @@ -57,7 +57,7 @@ JS::NonnullGCPtr DOMParser::parse_from_string(StringView string, } else { // -> Otherwise document = DOM::Document::create(realm(), verify_cast(relevant_global_object(*this)).associated_document().url()); - document->set_content_type(Bindings::idl_enum_to_string(type).to_deprecated_string()); + document->set_content_type(Bindings::idl_enum_to_string(type)); // 1. Create an XML parser parse, associated with document, and with XML scripting support disabled. XML::Parser parser(string, { .resolve_external_resource = resolve_xml_resource }); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 53c65a38e4..e0b8ae366a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -125,7 +125,7 @@ WebIDL::ExceptionOr HTMLElement::set_content_editable(StringView content_e void HTMLElement::set_inner_text(StringView text) { remove_all_children(); - MUST(append_child(document().create_text_node(text))); + MUST(append_child(document().create_text_node(MUST(String::from_utf8(text))))); set_needs_style_update(true); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 10d0b4d052..489d25ab85 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -346,7 +346,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru if (auto charset = deprecated_attribute(HTML::AttributeNames::charset); !charset.is_null()) encoding = charset; else - encoding = document().encoding_or_default(); + encoding = document().encoding_or_default().to_deprecated_string(); auto decoder = TextCodec::decoder_for(encoding); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index 817adda7b7..0c7d99bd9d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -290,8 +290,7 @@ void HTMLScriptElement::prepare_script() } if (!encoding.has_value()) { - auto document_encoding = document().encoding_or_default(); - encoding = String::from_deprecated_string(document_encoding).release_value_but_fixme_should_propagate_errors(); + encoding = document().encoding_or_default(); } VERIFY(encoding.has_value()); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 70fc9b000d..45308401ba 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -136,7 +136,7 @@ HTMLParser::HTMLParser(DOM::Document& document, StringView input, DeprecatedStri m_document->set_parser({}, *this); auto standardized_encoding = TextCodec::get_standardized_encoding(encoding); VERIFY(standardized_encoding.has_value()); - m_document->set_encoding(standardized_encoding.value()); + m_document->set_encoding(MUST(String::from_utf8(standardized_encoding.value()))); } HTMLParser::HTMLParser(DOM::Document& document) @@ -3774,7 +3774,7 @@ JS::NonnullGCPtr HTMLParser::create_for_scripting(DOM::Document& doc JS::NonnullGCPtr HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input) { if (document.has_encoding()) - return document.heap().allocate_without_realm(document, input, document.encoding().value()); + return document.heap().allocate_without_realm(document, input, document.encoding().value().to_deprecated_string()); auto encoding = run_encoding_sniffing_algorithm(document, input); dbgln_if(HTML_PARSER_DEBUG, "The encoding sniffing algorithm returned encoding '{}'", encoding); return document.heap().allocate_without_realm(document, input, encoding); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp index 0fe78ec19e..64b6d8dcfa 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp @@ -91,7 +91,7 @@ JS::GCPtr WindowEnvironmentSettingsObject::responsible_document() DeprecatedString WindowEnvironmentSettingsObject::api_url_character_encoding() { // Return the current character encoding of window's associated Document. - return m_window->associated_document().encoding_or_default(); + return m_window->associated_document().encoding_or_default().to_deprecated_string(); } // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-base-url diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 576cad8f2a..ad1a74618a 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -326,8 +326,13 @@ void FrameLoader::resource_did_load() }; auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html", move(navigation_params)).release_value_but_fixme_should_propagate_errors(); document->set_url(url); - document->set_encoding(resource()->encoding()); - document->set_content_type(resource()->mime_type()); + + if (resource()->encoding().has_value()) + document->set_encoding(MUST(String::from_deprecated_string(resource()->encoding().value()))); + else + document->set_encoding({}); + + document->set_content_type(MUST(String::from_deprecated_string(resource()->mime_type()))); browsing_context().set_active_document(document); if (auto* page = browsing_context().page()) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 257fa19900..75149cb73b 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -324,10 +324,10 @@ void XMLHttpRequest::set_document_response() charset = "UTF-8"sv; // 8. Set document’s encoding to charset. - document->set_encoding(charset->to_deprecated_string()); + document->set_encoding(MUST(String::from_utf8(charset.value()))); // 9. Set document’s content type to finalMIME. - document->set_content_type(MUST(final_mine.serialized()).to_deprecated_string()); + document->set_content_type(MUST(final_mine.serialized())); // 10. Set document’s URL to xhr’s response’s URL. document->set_url(m_response->url().value_or({})); diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index 18ac9d3d5d..76a5fd4c9d 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -146,7 +146,7 @@ void XMLDocumentBuilder::text(StringView data) auto string = DeprecatedString::empty(); if (!data.is_null()) string = data.to_deprecated_string(); - auto node = m_document->create_text_node(string); + auto node = m_document->create_text_node(MUST(String::from_deprecated_string(string))); MUST(m_current_node->append_child(node)); } } @@ -158,7 +158,7 @@ void XMLDocumentBuilder::comment(StringView data) auto string = DeprecatedString::empty(); if (!data.is_null()) string = data.to_deprecated_string(); - MUST(m_document->append_child(m_document->create_comment(string))); + MUST(m_document->append_child(m_document->create_comment(MUST(String::from_deprecated_string(string))))); } void XMLDocumentBuilder::document_end()