From f976ec005c25e10c68961798aee248a403c1e296 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 3 Dec 2023 08:58:43 +1300 Subject: [PATCH] LibWeb: Port DOM::Document from DeprecatedString --- Userland/Libraries/LibWeb/DOM/Document.cpp | 52 +++++++++---------- Userland/Libraries/LibWeb/DOM/Document.h | 32 ++++++------ .../Libraries/LibWeb/DOM/DocumentLoading.cpp | 4 +- .../Libraries/LibWeb/HTML/BrowsingContext.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLFormElement.cpp | 2 +- .../LibWeb/HTML/HTMLTitleElement.cpp | 2 +- .../LibWeb/HTML/Parser/HTMLParser.cpp | 2 +- .../LibWeb/SVG/SVGDecodedImageData.cpp | 2 +- .../Libraries/LibWeb/SVG/SVGTitleElement.cpp | 2 +- .../LibWeb/XML/XMLDocumentBuilder.cpp | 2 +- .../WebContent/ConnectionFromClient.cpp | 6 +-- .../WebContent/WebDriverConnection.cpp | 2 +- 12 files changed, 55 insertions(+), 55 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f2f08f0802..7f963926f4 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -151,7 +151,7 @@ static JS::NonnullGCPtr obtain_a_browsing_context_to_use_ } // https://html.spec.whatwg.org/multipage/browsing-the-web.html#initialise-the-document-object -WebIDL::ExceptionOr> Document::create_and_initialize(Type type, DeprecatedString content_type, HTML::NavigationParams& navigation_params) +WebIDL::ExceptionOr> Document::create_and_initialize(Type type, String content_type, HTML::NavigationParams& navigation_params) { // 1. Let browsingContext be navigationParams's navigable's active browsing context. auto browsing_context = navigation_params.navigable->active_browsing_context(); @@ -264,7 +264,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 = MUST(String::from_deprecated_string(content_type)); + document->m_content_type = move(content_type); document->set_origin(navigation_params.origin); document->set_browsing_context(browsing_context); document->m_policy_container = navigation_params.policy_container; @@ -284,14 +284,14 @@ WebIDL::ExceptionOr> Document::create_and_initialize( // 13. If navigationParams's request is non-null, then: if (navigation_params.request) { // 1. Set document's referrer to the empty string. - document->m_referrer = DeprecatedString::empty(); + document->m_referrer = String {}; // 2. Let referrer be navigationParams's request's referrer. - auto& referrer = navigation_params.request->referrer(); + auto const& referrer = navigation_params.request->referrer(); // 3. If referrer is a URL record, then set document's referrer to the serialization of referrer. if (referrer.has()) { - document->m_referrer = referrer.get().serialize(); + document->m_referrer = MUST(String::from_deprecated_string(referrer.get().serialize())); } } @@ -712,28 +712,28 @@ WebIDL::ExceptionOr Document::set_body(HTML::HTMLElement* new_body) } // https://html.spec.whatwg.org/multipage/dom.html#document.title -DeprecatedString Document::title() const +String Document::title() const { - auto value = DeprecatedString::empty(); + String value; // 1. If the document element is an SVG svg element, then let value be the child text content of the first SVG title // element that is a child of the document element. if (auto const* document_element = this->document_element(); is(document_element)) { if (auto const* title_element = document_element->first_child_of_type()) - value = title_element->child_text_content().to_deprecated_string(); + value = title_element->child_text_content(); } // 2. Otherwise, let value be the child text content of the title element, or the empty string if the title element // is null. else if (auto title_element = this->title_element()) { - value = title_element->text_content().value_or(String {}).to_deprecated_string(); + value = title_element->text_content().value_or(String {}); } // 3. Strip and collapse ASCII whitespace in value. auto title = Infra::strip_and_collapse_whitespace(value).release_value_but_fixme_should_propagate_errors(); // 4. Return value. - return title.to_deprecated_string(); + return title; } // https://html.spec.whatwg.org/multipage/dom.html#document.title @@ -1662,10 +1662,10 @@ DocumentType const* Document::doctype() const return first_child_of_type(); } -DeprecatedString const& Document::compat_mode() const +String const& Document::compat_mode() const { - static DeprecatedString back_compat = "BackCompat"; - static DeprecatedString css1_compat = "CSS1Compat"; + static String const back_compat = "BackCompat"_string; + static String const css1_compat = "CSS1Compat"_string; if (m_quirks_mode == QuirksMode::Yes) return back_compat; @@ -1974,11 +1974,11 @@ void Document::completely_finish_loading() } } -DeprecatedString Document::cookie(Cookie::Source source) +String Document::cookie(Cookie::Source source) { if (auto* page = this->page()) - return page->client().page_did_request_cookie(m_url, source); - return DeprecatedString::empty(); + return MUST(String::from_deprecated_string(page->client().page_did_request_cookie(m_url, source))); + return String {}; } void Document::set_cookie(StringView cookie_string, Cookie::Source source) @@ -1991,14 +1991,14 @@ void Document::set_cookie(StringView cookie_string, Cookie::Source source) page->client().page_did_set_cookie(m_url, cookie.value(), source); } -DeprecatedString Document::dump_dom_tree_as_json() const +String Document::dump_dom_tree_as_json() const { StringBuilder builder; auto json = MUST(JsonObjectSerializer<>::try_create(builder)); serialize_tree_as_json(json); MUST(json.finish()); - return builder.to_deprecated_string(); + return MUST(builder.to_string()); } // https://html.spec.whatwg.org/multipage/semantics.html#has-a-style-sheet-that-is-blocking-scripts @@ -2023,14 +2023,14 @@ bool Document::has_a_style_sheet_that_is_blocking_scripts() const return false; } -DeprecatedString Document::referrer() const +String Document::referrer() const { return m_referrer; } -void Document::set_referrer(DeprecatedString referrer) +void Document::set_referrer(String referrer) { - m_referrer = referrer; + m_referrer = move(referrer); } // https://html.spec.whatwg.org/multipage/document-sequences.html#fully-active @@ -2512,17 +2512,17 @@ JS::NonnullGCPtr Document::history() const } // https://html.spec.whatwg.org/multipage/origin.html#dom-document-domain -DeprecatedString Document::domain() const +String Document::domain() const { // 1. Let effectiveDomain be this's origin's effective domain. auto effective_domain = origin().effective_domain(); // 2. If effectiveDomain is null, then return the empty string. if (!effective_domain.has_value()) - return DeprecatedString::empty(); + return String {}; // 3. Return effectiveDomain, serialized. - return URLParser::serialize_host(effective_domain.release_value()).release_value_but_fixme_should_propagate_errors().to_deprecated_string(); + return MUST(URLParser::serialize_host(effective_domain.release_value())); } void Document::set_domain(String const& domain) @@ -3000,7 +3000,7 @@ JS::NonnullGCPtr Document::appropriate_template_contents_owner_do return *this; } -DeprecatedString Document::dump_accessibility_tree_as_json() +String Document::dump_accessibility_tree_as_json() { StringBuilder builder; auto accessibility_tree = AccessibilityTreeNode::create(this, nullptr); @@ -3016,7 +3016,7 @@ DeprecatedString Document::dump_accessibility_tree_as_json() } MUST(json.finish()); - return builder.to_deprecated_string(); + return MUST(builder.to_string()); } // https://dom.spec.whatwg.org/#dom-document-createattribute diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 1720e79075..33cc6c7069 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -8,10 +8,10 @@ #pragma once -#include #include #include #include +#include #include #include #include @@ -90,7 +90,7 @@ public: HTML }; - static WebIDL::ExceptionOr> create_and_initialize(Type, DeprecatedString content_type, HTML::NavigationParams&); + static WebIDL::ExceptionOr> create_and_initialize(Type, String content_type, HTML::NavigationParams&); [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, AK::URL const& url = "about:blank"sv); static WebIDL::ExceptionOr> construct_impl(JS::Realm&); @@ -98,11 +98,11 @@ public: JS::GCPtr get_selection() const; - DeprecatedString cookie(Cookie::Source = Cookie::Source::NonHttp); + String cookie(Cookie::Source = Cookie::Source::NonHttp); void set_cookie(StringView, Cookie::Source = Cookie::Source::NonHttp); - DeprecatedString referrer() const; - void set_referrer(DeprecatedString); + String referrer() const; + void set_referrer(String); void set_url(const AK::URL& url) { m_url = url; } AK::URL url() const { return m_url; } @@ -112,8 +112,8 @@ public: void update_base_element(Badge); JS::GCPtr first_base_element_with_href_in_tree_order() const; - DeprecatedString url_string() const { return m_url.to_deprecated_string(); } - DeprecatedString document_uri() const { return m_url.to_deprecated_string(); } + String url_string() const { return MUST(m_url.to_string()); } + String document_uri() const { return url_string(); } HTML::Origin origin() const; void set_origin(HTML::Origin const& origin); @@ -173,7 +173,7 @@ public: WebIDL::ExceptionOr set_body(HTML::HTMLElement* new_body); - DeprecatedString title() const; + String title() const; WebIDL::ExceptionOr set_title(String const&); HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); } @@ -230,8 +230,8 @@ public: JS::NonnullGCPtr scripts(); JS::NonnullGCPtr all(); - DeprecatedString const& source() const { return m_source; } - void set_source(DeprecatedString source) { m_source = move(source); } + String const& source() const { return m_source; } + void set_source(String source) { m_source = move(source); } HTML::EnvironmentSettingsObject& relevant_settings_object() const; @@ -282,7 +282,7 @@ public: WebIDL::ExceptionOr> adopt_node_binding(JS::NonnullGCPtr); DocumentType const* doctype() const; - DeprecatedString const& compat_mode() const; + String const& compat_mode() const; void set_editable(bool editable) { m_editable = editable; } virtual bool is_editable() const final; @@ -353,7 +353,7 @@ public: virtual EventTarget* get_parent(Event const&) override; - DeprecatedString dump_dom_tree_as_json() const; + String dump_dom_tree_as_json() const; bool has_a_style_sheet_that_is_blocking_scripts() const; @@ -450,7 +450,7 @@ public: Optional about_base_url() const { return m_about_base_url; } void set_about_base_url(Optional url) { m_about_base_url = url; } - DeprecatedString domain() const; + String domain() const; void set_domain(String const&); auto& pending_scroll_event_targets() { return m_pending_scroll_event_targets; } @@ -507,7 +507,7 @@ public: bool query_command_supported(String const&) const; - DeprecatedString dump_accessibility_tree_as_json(); + String dump_accessibility_tree_as_json(); void make_active(); @@ -595,7 +595,7 @@ private: JS::GCPtr m_parser; bool m_active_parser_was_aborted { false }; - DeprecatedString m_source; + String m_source; JS::GCPtr m_pending_parsing_blocking_script; @@ -686,7 +686,7 @@ private: HTML::CrossOriginOpenerPolicy m_cross_origin_opener_policy; // https://html.spec.whatwg.org/multipage/dom.html#the-document's-referrer - DeprecatedString m_referrer { "" }; + String m_referrer; // https://dom.spec.whatwg.org/#concept-document-origin HTML::Origin m_origin; diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp index be680b8d50..f85e321b81 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -269,7 +269,7 @@ JS::GCPtr load_document(Optional navigati if (!is_supported_document_mime_type(mime_type.essence())) return nullptr; - auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html", *navigation_params).release_value_but_fixme_should_propagate_errors(); + auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, *navigation_params).release_value_but_fixme_should_propagate_errors(); document->set_content_type(mime_type.essence()); auto& realm = document->realm(); @@ -356,7 +356,7 @@ JS::GCPtr create_document_for_inline_content(JS::GCPtr BrowsingContext // 15. If creator is non-null, then: if (creator) { // 1. Set document's referrer to the serialization of creator's URL. - document->set_referrer(creator->url().serialize()); + document->set_referrer(MUST(String::from_deprecated_string(creator->url().serialize()))); // FIXME: 2. Set document's policy container to a clone of creator's policy container. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index f821faf48d..9aaa943bf0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -162,7 +162,7 @@ WebIDL::ExceptionOr HTMLFormElement::submit_form(JS::NonnullGCPtrurl_string(); + action = form_document->url_string().to_deprecated_string(); // 14. Parse a URL given action, relative to the submitter element's node document. If this fails, return. // 15. Let parsed action be the resulting URL record. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp index d8b046805c..fd612e4664 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp @@ -30,7 +30,7 @@ void HTMLTitleElement::children_changed() { HTMLElement::children_changed(); if (navigable() && navigable()->is_traversable()) { - navigable()->traversable_navigable()->page()->client().page_did_change_title(document().title()); + navigable()->traversable_navigable()->page()->client().page_did_change_title(document().title().to_deprecated_string()); } } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 0bce504276..9945ec0f9e 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -219,7 +219,7 @@ void HTMLParser::run() void HTMLParser::run(const AK::URL& url) { m_document->set_url(url); - m_document->set_source(m_tokenizer.source()); + m_document->set_source(MUST(String::from_deprecated_string(m_tokenizer.source()))); run(); the_end(); m_document->detach_parser({}); diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp index 2ad43098a6..b7215596c3 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp @@ -70,7 +70,7 @@ ErrorOr> SVGDecodedImageData::create(Page& ho .about_base_url = {}, }; // FIXME: Use Navigable::navigate() instead of manually replacing the navigable's document. - auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html", navigation_params).release_value_but_fixme_should_propagate_errors(); + auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors(); navigable->set_ongoing_navigation({}); navigable->active_document()->destroy(); navigable->active_session_history_entry()->document_state->set_document(document); diff --git a/Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp index 2cf837b40a..e9790ce112 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp @@ -42,7 +42,7 @@ void SVGTitleElement::children_changed() auto* document_element = document().document_element(); if (document_element == parent() && is(document_element)) - page->client().page_did_change_title(document().title()); + page->client().page_did_change_title(document().title().to_deprecated_string()); } } diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index f9e582073e..e08c79ce8d 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -47,7 +47,7 @@ XMLDocumentBuilder::XMLDocumentBuilder(DOM::Document& document, XMLScriptingSupp void XMLDocumentBuilder::set_source(DeprecatedString source) { - m_document->set_source(move(source)); + m_document->set_source(MUST(String::from_deprecated_string(source))); } void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap const& attributes) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 9231a8f760..daa0fe3b78 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -497,14 +497,14 @@ void ConnectionFromClient::debug_request(DeprecatedString const& request, Deprec void ConnectionFromClient::get_source() { if (auto* doc = page().page().top_level_browsing_context().active_document()) { - async_did_get_source(doc->url(), doc->source()); + async_did_get_source(doc->url(), doc->source().to_deprecated_string()); } } void ConnectionFromClient::inspect_dom_tree() { if (auto* doc = page().page().top_level_browsing_context().active_document()) { - async_did_get_dom_tree(doc->dump_dom_tree_as_json()); + async_did_get_dom_tree(doc->dump_dom_tree_as_json().to_deprecated_string()); } } @@ -927,7 +927,7 @@ void ConnectionFromClient::set_user_style(String const& source) void ConnectionFromClient::inspect_accessibility_tree() { if (auto* doc = page().page().top_level_browsing_context().active_document()) { - async_did_get_accessibility_tree(doc->dump_accessibility_tree_as_json()); + async_did_get_accessibility_tree(doc->dump_accessibility_tree_as_json().to_deprecated_string()); } } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 031798acb9..db166b20fe 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -523,7 +523,7 @@ Messages::WebDriverClient::GetTitleResponse WebDriverConnection::get_title() auto title = m_page_client.page().top_level_browsing_context().active_document()->title(); // 4. Return success with data title. - return title; + return title.to_deprecated_string(); } // 11.1 Get Window Handle, https://w3c.github.io/webdriver/#get-window-handle