1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:57:35 +00:00

Browser+WebContent+WebDriver: Move Get Named Cookie to WebContent

Instead of sending *all* cookies over IPC and filtering by name, we now
filter by name from the cookie jar and send just the first matching
cookie.
This commit is contained in:
Timothy Flynn 2022-11-11 09:55:11 -05:00 committed by Linus Groh
parent c6a0888088
commit a3d6c2f6af
14 changed files with 51 additions and 57 deletions

View file

@ -297,43 +297,6 @@ Web::WebDriver::Response Session::get_window_handles() const
return JsonValue { handles };
}
// https://w3c.github.io/webdriver/#dfn-serialized-cookie
static JsonObject serialize_cookie(Web::Cookie::Cookie const& cookie)
{
JsonObject serialized_cookie = {};
serialized_cookie.set("name", cookie.name);
serialized_cookie.set("value", cookie.value);
serialized_cookie.set("path", cookie.path);
serialized_cookie.set("domain", cookie.domain);
serialized_cookie.set("secure", cookie.secure);
serialized_cookie.set("httpOnly", cookie.http_only);
serialized_cookie.set("expiry", cookie.expiry_time.timestamp());
// FIXME: Add sameSite to Cookie and serialize it here too.
return serialized_cookie;
}
// 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie
Web::WebDriver::Response Session::get_named_cookie(String const& name)
{
// 1. If the current browsing context is no longer open, return error with error code no such window.
TRY(check_for_open_top_level_browsing_context_or_return_error());
// FIXME: 2. Handle any user prompts, and return its value if it is an error.
// 3. If the url variable name is equal to a cookies cookie name amongst all associated cookies of the
// current browsing contexts active document, return success with the serialized cookie as data.
auto maybe_cookie = m_browser_connection->get_named_cookie(name);
if (maybe_cookie.has_value()) {
auto cookie = maybe_cookie.release_value();
auto serialized_cookie = serialize_cookie(cookie);
return JsonValue(serialized_cookie);
}
// 4. Otherwise, return error with error code no such cookie.
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchCookie, "Cookie not found");
}
// 14.3 Add Cookie, https://w3c.github.io/webdriver/#dfn-adding-a-cookie
Web::WebDriver::Response Session::add_cookie(JsonValue const& payload)
{