1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:27:43 +00:00

LibWeb: Add the URL::username, URL::password & URL::origin attributes

This commit is contained in:
Idan Horowitz 2021-09-14 00:18:25 +03:00 committed by Andreas Kling
parent fe32c9c3bd
commit e89320887e
3 changed files with 47 additions and 3 deletions

View file

@ -75,6 +75,42 @@ DOM::ExceptionOr<void> URL::set_href(String const& href)
return {}; return {};
} }
String URL::origin() const
{
// return the serialization of thiss URLs origin.
return m_url.serialize_origin();
}
String URL::username() const
{
// return thiss URLs username.
return m_url.username();
}
void URL::set_username(const String& username)
{
// 1. If thiss 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 thiss URL and the given value.
m_url.set_username(AK::URL::percent_encode(username, AK::URL::PercentEncodeSet::Userinfo));
}
String URL::password() const
{
// return thiss URLs password.
return m_url.password();
}
void URL::set_password(String const& password)
{
// 1. If thiss 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 thiss URL and the given value.
m_url.set_password(AK::URL::percent_encode(password, AK::URL::PercentEncodeSet::Userinfo));
}
URLSearchParams const* URL::search_params() const URLSearchParams const* URL::search_params() const
{ {
return m_query; return m_query;

View file

@ -31,6 +31,14 @@ public:
String href() const; String href() const;
DOM::ExceptionOr<void> set_href(String 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; URLSearchParams const* search_params() const;
String to_json() const; String to_json() const;

View file

@ -2,10 +2,10 @@ interface URL {
constructor(USVString url, optional USVString base); constructor(USVString url, optional USVString base);
stringifier attribute USVString href; stringifier attribute USVString href;
// TODO: readonly attribute USVString origin; readonly attribute USVString origin;
// TODO: attribute USVString protocol; // TODO: attribute USVString protocol;
// TODO: attribute USVString username; attribute USVString username;
// TODO: attribute USVString password; attribute USVString password;
// TODO: attribute USVString host; // TODO: attribute USVString host;
// TODO: attribute USVString hostname; // TODO: attribute USVString hostname;
// TODO: attribute USVString port; // TODO: attribute USVString port;