diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-14 00:18:25 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-14 00:14:45 +0200 |
commit | e89320887efedf2b4241b1a21b3792d7e7fb7961 (patch) | |
tree | d4a3c7fd4067a1d57d70c7e9242443add33a1d47 /Userland | |
parent | fe32c9c3bd41e9753a56b5edfa9ad71e94dd243d (diff) | |
download | serenity-e89320887efedf2b4241b1a21b3792d7e7fb7961.zip |
LibWeb: Add the URL::username, URL::password & URL::origin attributes
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/URL/URL.cpp | 36 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/URL/URL.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/URL/URL.idl | 6 |
3 files changed, 47 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/URL/URL.cpp b/Userland/Libraries/LibWeb/URL/URL.cpp index 8e6ed49b85..949910afae 100644 --- a/Userland/Libraries/LibWeb/URL/URL.cpp +++ b/Userland/Libraries/LibWeb/URL/URL.cpp @@ -75,6 +75,42 @@ DOM::ExceptionOr<void> URL::set_href(String const& href) return {}; } +String URL::origin() const +{ + // return the serialization of this’s URL’s origin. + return m_url.serialize_origin(); +} + +String URL::username() const +{ + // return this’s URL’s username. + return m_url.username(); +} + +void URL::set_username(const String& username) +{ + // 1. If this’s URL cannot have a username/password/port, then return. + if (m_url.cannot_have_a_username_or_password_or_port()) + return; + // 2. Set the username given this’s URL and the given value. + m_url.set_username(AK::URL::percent_encode(username, AK::URL::PercentEncodeSet::Userinfo)); +} + +String URL::password() const +{ + // return this’s URL’s password. + return m_url.password(); +} + +void URL::set_password(String const& password) +{ + // 1. If this’s URL cannot have a username/password/port, then return. + if (m_url.cannot_have_a_username_or_password_or_port()) + return; + // 2. Set the password given this’s URL and the given value. + m_url.set_password(AK::URL::percent_encode(password, AK::URL::PercentEncodeSet::Userinfo)); +} + URLSearchParams const* URL::search_params() const { return m_query; diff --git a/Userland/Libraries/LibWeb/URL/URL.h b/Userland/Libraries/LibWeb/URL/URL.h index 7406aa86e8..0b1b2461ec 100644 --- a/Userland/Libraries/LibWeb/URL/URL.h +++ b/Userland/Libraries/LibWeb/URL/URL.h @@ -31,6 +31,14 @@ public: String href() const; DOM::ExceptionOr<void> set_href(String const&); + String origin() const; + + String username() const; + void set_username(String const&); + + String password() const; + void set_password(String const&); + URLSearchParams const* search_params() const; String to_json() const; diff --git a/Userland/Libraries/LibWeb/URL/URL.idl b/Userland/Libraries/LibWeb/URL/URL.idl index a32ea6e5e5..7ea731e04f 100644 --- a/Userland/Libraries/LibWeb/URL/URL.idl +++ b/Userland/Libraries/LibWeb/URL/URL.idl @@ -2,10 +2,10 @@ interface URL { constructor(USVString url, optional USVString base); stringifier attribute USVString href; - // TODO: readonly attribute USVString origin; + readonly attribute USVString origin; // TODO: attribute USVString protocol; - // TODO: attribute USVString username; - // TODO: attribute USVString password; + attribute USVString username; + attribute USVString password; // TODO: attribute USVString host; // TODO: attribute USVString hostname; // TODO: attribute USVString port; |