1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

LibWeb: Port HTML Environments from ByteString

This commit is contained in:
Shannon Booth 2023-12-24 15:44:50 +13:00 committed by Andreas Kling
parent 562e0d710c
commit c63d30ce67
6 changed files with 14 additions and 15 deletions

View file

@ -674,8 +674,7 @@ static WebIDL::ExceptionOr<Variant<Empty, NavigationParams, NonFetchSchemeNaviga
request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include); request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include);
request->set_use_url_credentials(true); request->set_use_url_credentials(true);
request->set_redirect_mode(Fetch::Infrastructure::Request::RedirectMode::Manual); 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(active_document.relevant_settings_object().id);
request->set_replaces_client_id(replaces_client_id);
request->set_mode(Fetch::Infrastructure::Request::Mode::Navigate); request->set_mode(Fetch::Infrastructure::Request::Mode::Navigate);
request->set_referrer(entry->document_state->request_referrer()); request->set_referrer(entry->document_state->request_referrer());

View file

@ -308,7 +308,7 @@ bool EnvironmentSettingsObject::is_scripting_disabled() const
} }
// https://html.spec.whatwg.org/multipage/webappapis.html#module-type-allowed // 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. // 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) if (module_type != "javascript"sv && module_type != "css"sv && module_type != "json"sv)

View file

@ -20,7 +20,7 @@ struct Environment {
virtual ~Environment() = default; virtual ~Environment() = default;
// An id https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-id // 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 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-creation-url
AK::URL creation_url; AK::URL creation_url;
@ -69,7 +69,7 @@ struct EnvironmentSettingsObject
virtual JS::GCPtr<DOM::Document> responsible_document() = 0; virtual JS::GCPtr<DOM::Document> responsible_document() = 0;
// https://html.spec.whatwg.org/multipage/webappapis.html#api-url-character-encoding // 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 // https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url
virtual AK::URL api_base_url() = 0; virtual AK::URL api_base_url() = 0;
@ -111,7 +111,7 @@ struct EnvironmentSettingsObject
bool is_scripting_enabled() const; bool is_scripting_enabled() const;
bool is_scripting_disabled() 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(); void disallow_further_import_maps();

View file

@ -51,7 +51,7 @@ void WindowEnvironmentSettingsObject::setup(Page& page, AK::URL const& creation_
settings_object->target_browsing_context = reserved_environment->target_browsing_context; settings_object->target_browsing_context = reserved_environment->target_browsing_context;
// 2. Set reservedEnvironment's id to the empty string. // 2. Set reservedEnvironment's id to the empty string.
reserved_environment->id = ByteString::empty(); reserved_environment->id = String {};
} }
// 5. Otherwise, ... // 5. Otherwise, ...
@ -60,7 +60,7 @@ void WindowEnvironmentSettingsObject::setup(Page& page, AK::URL const& creation_
// settings object's target browsing context to null, // settings object's target browsing context to null,
// and settings object's active service worker to null. // and settings object's active service worker to null.
static i64 next_id = 1; 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; 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, // settings object's top-level creation URL to topLevelCreationURL,
// and settings object's top-level origin to topLevelOrigin. // and settings object's top-level origin to topLevelOrigin.
settings_object->creation_url = creation_url; settings_object->creation_url = creation_url;
settings_object->top_level_creation_url = top_level_creation_url; settings_object->top_level_creation_url = move(top_level_creation_url);
settings_object->top_level_origin = top_level_origin; settings_object->top_level_origin = move(top_level_origin);
// 7. Set realm's [[HostDefined]] field to settings object. // 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 // Non-Standard: We store the ESO next to the web intrinsics in a custom HostDefined object
@ -90,10 +90,10 @@ JS::GCPtr<DOM::Document> WindowEnvironmentSettingsObject::responsible_document()
} }
// https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-url-character-encoding // 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 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 // https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-base-url

View file

@ -21,7 +21,7 @@ public:
virtual ~WindowEnvironmentSettingsObject() override; virtual ~WindowEnvironmentSettingsObject() override;
virtual JS::GCPtr<DOM::Document> responsible_document() override; virtual JS::GCPtr<DOM::Document> 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 AK::URL api_base_url() override;
virtual Origin origin() override; virtual Origin origin() override;
virtual PolicyContainer policy_container() override; virtual PolicyContainer policy_container() override;

View file

@ -29,7 +29,7 @@ public:
virtual ~WorkerEnvironmentSettingsObject() override = default; virtual ~WorkerEnvironmentSettingsObject() override = default;
JS::GCPtr<DOM::Document> responsible_document() override { return nullptr; } JS::GCPtr<DOM::Document> 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; } AK::URL api_base_url() override { return m_url; }
Origin origin() override { return m_origin; } Origin origin() override { return m_origin; }
PolicyContainer policy_container() override { return m_policy_container; } PolicyContainer policy_container() override { return m_policy_container; }
@ -38,7 +38,7 @@ public:
private: private:
virtual void visit_edges(JS::Cell::Visitor&) override; virtual void visit_edges(JS::Cell::Visitor&) override;
ByteString m_api_url_character_encoding; String m_api_url_character_encoding;
AK::URL m_url; AK::URL m_url;
HTML::Origin m_origin; HTML::Origin m_origin;
HTML::PolicyContainer m_policy_container; HTML::PolicyContainer m_policy_container;