1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:27: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

@ -25,6 +25,7 @@ endpoint WebDriverClient {
execute_script(JsonValue payload) => (Web::WebDriver::Response response)
execute_async_script(JsonValue payload) => (Web::WebDriver::Response response)
get_all_cookies() => (Web::WebDriver::Response response)
get_named_cookie(String name) => (Web::WebDriver::Response response)
take_screenshot() => (Web::WebDriver::Response response)
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
}

View file

@ -872,6 +872,26 @@ Messages::WebDriverClient::GetAllCookiesResponse WebDriverConnection::get_all_co
return make_success_response(move(cookies));
}
// 14.2 Get Named Cookie, https://w3c.github.io/webdriver/#dfn-get-named-cookie
Messages::WebDriverClient::GetNamedCookieResponse WebDriverConnection::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(ensure_open_top_level_browsing_context());
// 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* document = m_page_host.page().top_level_browsing_context().active_document();
if (auto cookie = m_web_content_client.did_request_named_cookie(document->url(), name); cookie.has_value()) {
auto serialized_cookie = serialize_cookie(*cookie);
return make_success_response(move(serialized_cookie));
}
// 4. Otherwise, return error with error code no such cookie.
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchCookie, String::formatted("Cookie '{}' not found", name));
}
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
{

View file

@ -57,6 +57,7 @@ private:
virtual Messages::WebDriverClient::ExecuteScriptResponse execute_script(JsonValue const& payload) override;
virtual Messages::WebDriverClient::ExecuteAsyncScriptResponse execute_async_script(JsonValue const& payload) override;
virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override;
virtual Messages::WebDriverClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;