From c63d30ce67bce4c19b6933f29d33c962b9c9b3b3 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 24 Dec 2023 15:44:50 +1300 Subject: [PATCH] LibWeb: Port HTML Environments from ByteString --- Userland/Libraries/LibWeb/HTML/Navigable.cpp | 3 +-- .../Libraries/LibWeb/HTML/Scripting/Environments.cpp | 2 +- .../Libraries/LibWeb/HTML/Scripting/Environments.h | 6 +++--- .../Scripting/WindowEnvironmentSettingsObject.cpp | 12 ++++++------ .../HTML/Scripting/WindowEnvironmentSettingsObject.h | 2 +- .../HTML/Scripting/WorkerEnvironmentSettingsObject.h | 4 ++-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index a9e421ef28..6c2af8e4ad 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -674,8 +674,7 @@ static WebIDL::ExceptionOrset_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include); request->set_use_url_credentials(true); request->set_redirect_mode(Fetch::Infrastructure::Request::RedirectMode::Manual); - auto replaces_client_id = TRY_OR_THROW_OOM(vm, String::from_byte_string(active_document.relevant_settings_object().id)); - request->set_replaces_client_id(replaces_client_id); + request->set_replaces_client_id(active_document.relevant_settings_object().id); request->set_mode(Fetch::Infrastructure::Request::Mode::Navigate); request->set_referrer(entry->document_state->request_referrer()); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 117b9c5861..4214fb6693 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -308,7 +308,7 @@ bool EnvironmentSettingsObject::is_scripting_disabled() const } // https://html.spec.whatwg.org/multipage/webappapis.html#module-type-allowed -bool EnvironmentSettingsObject::module_type_allowed(AK::ByteString const& module_type) const +bool EnvironmentSettingsObject::module_type_allowed(StringView module_type) const { // 1. If moduleType is not "javascript", "css", or "json", then return false. if (module_type != "javascript"sv && module_type != "css"sv && module_type != "json"sv) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h index 28d7800cd3..ca99e14fc1 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -20,7 +20,7 @@ struct Environment { virtual ~Environment() = default; // An id https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-id - ByteString id; + String id; // https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-creation-url AK::URL creation_url; @@ -69,7 +69,7 @@ struct EnvironmentSettingsObject virtual JS::GCPtr responsible_document() = 0; // https://html.spec.whatwg.org/multipage/webappapis.html#api-url-character-encoding - virtual ByteString api_url_character_encoding() = 0; + virtual String api_url_character_encoding() = 0; // https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url virtual AK::URL api_base_url() = 0; @@ -111,7 +111,7 @@ struct EnvironmentSettingsObject bool is_scripting_enabled() const; bool is_scripting_disabled() const; - bool module_type_allowed(ByteString const& module_type) const; + bool module_type_allowed(StringView module_type) const; void disallow_further_import_maps(); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp index 4d3a767233..4f70181571 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp @@ -51,7 +51,7 @@ void WindowEnvironmentSettingsObject::setup(Page& page, AK::URL const& creation_ settings_object->target_browsing_context = reserved_environment->target_browsing_context; // 2. Set reservedEnvironment's id to the empty string. - reserved_environment->id = ByteString::empty(); + reserved_environment->id = String {}; } // 5. Otherwise, ... @@ -60,7 +60,7 @@ void WindowEnvironmentSettingsObject::setup(Page& page, AK::URL const& creation_ // settings object's target browsing context to null, // and settings object's active service worker to null. static i64 next_id = 1; - settings_object->id = ByteString::number(next_id++); + settings_object->id = MUST(String::number(next_id++)); settings_object->target_browsing_context = nullptr; } @@ -68,8 +68,8 @@ void WindowEnvironmentSettingsObject::setup(Page& page, AK::URL const& creation_ // settings object's top-level creation URL to topLevelCreationURL, // and settings object's top-level origin to topLevelOrigin. settings_object->creation_url = creation_url; - settings_object->top_level_creation_url = top_level_creation_url; - settings_object->top_level_origin = top_level_origin; + settings_object->top_level_creation_url = move(top_level_creation_url); + settings_object->top_level_origin = move(top_level_origin); // 7. Set realm's [[HostDefined]] field to settings object. // Non-Standard: We store the ESO next to the web intrinsics in a custom HostDefined object @@ -90,10 +90,10 @@ JS::GCPtr WindowEnvironmentSettingsObject::responsible_document() } // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-url-character-encoding -ByteString WindowEnvironmentSettingsObject::api_url_character_encoding() +String WindowEnvironmentSettingsObject::api_url_character_encoding() { // Return the current character encoding of window's associated Document. - return m_window->associated_document().encoding_or_default().to_byte_string(); + return m_window->associated_document().encoding_or_default(); } // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-base-url diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h index 8a66e1b165..13b7489c16 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h @@ -21,7 +21,7 @@ public: virtual ~WindowEnvironmentSettingsObject() override; virtual JS::GCPtr responsible_document() override; - virtual ByteString api_url_character_encoding() override; + virtual String api_url_character_encoding() override; virtual AK::URL api_base_url() override; virtual Origin origin() override; virtual PolicyContainer policy_container() override; diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h b/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h index d35fd468e3..6d55cb2d34 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h @@ -29,7 +29,7 @@ public: virtual ~WorkerEnvironmentSettingsObject() override = default; JS::GCPtr responsible_document() override { return nullptr; } - ByteString api_url_character_encoding() override { return m_api_url_character_encoding; } + String api_url_character_encoding() override { return m_api_url_character_encoding; } AK::URL api_base_url() override { return m_url; } Origin origin() override { return m_origin; } PolicyContainer policy_container() override { return m_policy_container; } @@ -38,7 +38,7 @@ public: private: virtual void visit_edges(JS::Cell::Visitor&) override; - ByteString m_api_url_character_encoding; + String m_api_url_character_encoding; AK::URL m_url; HTML::Origin m_origin; HTML::PolicyContainer m_policy_container;