Sfoglia il codice sorgente

LibWeb: Port DOM::Document from DeprecatedString

Shannon Booth 1 anno fa
parent
commit
f976ec005c

+ 26 - 26
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -151,7 +151,7 @@ static JS::NonnullGCPtr<HTML::BrowsingContext> obtain_a_browsing_context_to_use_
 }
 
 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#initialise-the-document-object
-WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> Document::create_and_initialize(Type type, DeprecatedString content_type, HTML::NavigationParams& navigation_params)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> 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<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 = 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<JS::NonnullGCPtr<Document>> 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<AK::URL>()) {
-            document->m_referrer = referrer.get<AK::URL>().serialize();
+            document->m_referrer = MUST(String::from_deprecated_string(referrer.get<AK::URL>().serialize()));
         }
     }
 
@@ -712,28 +712,28 @@ WebIDL::ExceptionOr<void> 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<SVG::SVGElement>(document_element)) {
         if (auto const* title_element = document_element->first_child_of_type<SVG::SVGTitleElement>())
-            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<DocumentType>();
 }
 
-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<HTML::History> 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<DOM::Document> 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

+ 16 - 16
Userland/Libraries/LibWeb/DOM/Document.h

@@ -8,10 +8,10 @@
 
 #pragma once
 
-#include <AK/DeprecatedString.h>
 #include <AK/Function.h>
 #include <AK/HashMap.h>
 #include <AK/OwnPtr.h>
+#include <AK/String.h>
 #include <AK/URL.h>
 #include <AK/Vector.h>
 #include <AK/WeakPtr.h>
@@ -90,7 +90,7 @@ public:
         HTML
     };
 
-    static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_and_initialize(Type, DeprecatedString content_type, HTML::NavigationParams&);
+    static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> create_and_initialize(Type, String content_type, HTML::NavigationParams&);
 
     [[nodiscard]] static JS::NonnullGCPtr<Document> create(JS::Realm&, AK::URL const& url = "about:blank"sv);
     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> construct_impl(JS::Realm&);
@@ -98,11 +98,11 @@ public:
 
     JS::GCPtr<Selection::Selection> 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<HTML::HTMLBaseElement>);
     JS::GCPtr<HTML::HTMLBaseElement const> 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<void> set_body(HTML::HTMLElement* new_body);
 
-    DeprecatedString title() const;
+    String title() const;
     WebIDL::ExceptionOr<void> set_title(String const&);
 
     HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); }
@@ -230,8 +230,8 @@ public:
     JS::NonnullGCPtr<HTMLCollection> scripts();
     JS::NonnullGCPtr<HTMLCollection> 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<JS::NonnullGCPtr<Node>> adopt_node_binding(JS::NonnullGCPtr<Node>);
 
     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<AK::URL> about_base_url() const { return m_about_base_url; }
     void set_about_base_url(Optional<AK::URL> 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<HTML::HTMLParser> m_parser;
     bool m_active_parser_was_aborted { false };
 
-    DeprecatedString m_source;
+    String m_source;
 
     JS::GCPtr<HTML::HTMLScriptElement> 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;

+ 2 - 2
Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp

@@ -269,7 +269,7 @@ JS::GCPtr<DOM::Document> load_document(Optional<HTML::NavigationParams> 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<DOM::Document> create_document_for_inline_content(JS::GCPtr<HTML::Navi
     };
 
     // 5. Let document be the result of creating and initializing a Document object given "html", "text/html", and navigationParams.
-    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();
 
     // 6. Either associate document with a custom rendering that is not rendered using the normal Document rendering rules, or mutate document until it represents the content the
     //    user agent wants to render.

+ 1 - 1
Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp

@@ -225,7 +225,7 @@ WebIDL::ExceptionOr<BrowsingContext::BrowsingContextAndDocument> 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.
 

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp

@@ -162,7 +162,7 @@ WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(JS::NonnullGCPtr<HTMLElem
 
     // 13. If action is the empty string, let action be the URL of the form document.
     if (action.is_empty())
-        action = form_document->url_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.

+ 1 - 1
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());
     }
 }
 

+ 1 - 1
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({});

+ 1 - 1
Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp

@@ -70,7 +70,7 @@ ErrorOr<NonnullRefPtr<SVGDecodedImageData>> 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);

+ 1 - 1
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<SVGElement>(document_element))
-        page->client().page_did_change_title(document().title());
+        page->client().page_did_change_title(document().title().to_deprecated_string());
 }
 
 }

+ 1 - 1
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<XML::Name, DeprecatedString> const& attributes)

+ 3 - 3
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());
     }
 }
 

+ 1 - 1
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