mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
Browser+WebContent+WebDriver: Move Delete Cookie to WebContent
This commit is contained in:
parent
d202999853
commit
b7f21bb92e
7 changed files with 43 additions and 18 deletions
|
@ -374,6 +374,11 @@ Tab::Tab(BrowserWindow& window)
|
|||
on_set_cookie(url, cookie, source);
|
||||
};
|
||||
|
||||
view().on_update_cookie = [this](auto& url, auto& cookie) {
|
||||
if (on_update_cookie)
|
||||
on_update_cookie(url, cookie);
|
||||
};
|
||||
|
||||
view().on_get_source = [this](auto& url, auto& source) {
|
||||
view_source(url, source);
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@ endpoint WebDriverClient {
|
|||
get_all_cookies() => (Web::WebDriver::Response response)
|
||||
get_named_cookie(String name) => (Web::WebDriver::Response response)
|
||||
add_cookie(JsonValue payload) => (Web::WebDriver::Response response)
|
||||
delete_cookie(String name) => (Web::WebDriver::Response response)
|
||||
take_screenshot() => (Web::WebDriver::Response response)
|
||||
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -975,6 +975,21 @@ Messages::WebDriverClient::AddCookieResponse WebDriverConnection::add_cookie(Jso
|
|||
return make_success_response({});
|
||||
}
|
||||
|
||||
// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie
|
||||
Messages::WebDriverClient::DeleteCookieResponse WebDriverConnection::delete_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. Delete cookies using the url variable name parameter as the filter argument.
|
||||
delete_cookies(name);
|
||||
|
||||
// 4. Return success with data null.
|
||||
return make_success_response({});
|
||||
}
|
||||
|
||||
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
||||
Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
|
||||
{
|
||||
|
@ -1138,4 +1153,23 @@ ErrorOr<WebDriverConnection::ScriptArguments, Web::WebDriver::Error> WebDriverCo
|
|||
return ScriptArguments { move(script), move(arguments) };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-delete-cookies
|
||||
void WebDriverConnection::delete_cookies(Optional<StringView> const& name)
|
||||
{
|
||||
// For each cookie among all associated cookies of the current browsing context’s active document, un the substeps of the first matching condition:
|
||||
auto* document = m_page_host.page().top_level_browsing_context().active_document();
|
||||
|
||||
for (auto& cookie : m_web_content_client.did_request_all_cookies(document->url())) {
|
||||
// -> name is undefined
|
||||
// -> name is equal to cookie name
|
||||
if (!name.has_value() || name.value() == cookie.name) {
|
||||
// Set the cookie expiry time to a Unix timestamp in the past.
|
||||
cookie.expiry_time = Core::DateTime::from_timestamp(0);
|
||||
m_web_content_client.async_did_update_cookie(document->url(), cookie);
|
||||
}
|
||||
// -> Otherwise
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ private:
|
|||
virtual Messages::WebDriverClient::GetAllCookiesResponse get_all_cookies() override;
|
||||
virtual Messages::WebDriverClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
||||
virtual Messages::WebDriverClient::AddCookieResponse add_cookie(JsonValue const& payload) override;
|
||||
virtual Messages::WebDriverClient::DeleteCookieResponse delete_cookie(String const& name) override;
|
||||
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
||||
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
||||
|
||||
|
@ -73,6 +74,7 @@ private:
|
|||
JS::MarkedVector<JS::Value> arguments;
|
||||
};
|
||||
ErrorOr<ScriptArguments, Web::WebDriver::Error> extract_the_script_arguments_from_a_request(JsonValue const& payload);
|
||||
void delete_cookies(Optional<StringView> const& name = {});
|
||||
|
||||
ConnectionFromClient& m_web_content_client;
|
||||
PageHost& m_page_host;
|
||||
|
|
|
@ -780,8 +780,7 @@ Web::WebDriver::Response Client::handle_delete_cookie(Vector<StringView> const&
|
|||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie/<name>");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->delete_cookie(parameters[1]));
|
||||
return make_json_value(result);
|
||||
return session->web_content_connection().delete_cookie(parameters[1]);
|
||||
}
|
||||
|
||||
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
|
||||
|
|
|
@ -315,21 +315,6 @@ void Session::delete_cookies(Optional<StringView> const& name)
|
|||
}
|
||||
}
|
||||
|
||||
// 14.4 Delete Cookie, https://w3c.github.io/webdriver/#dfn-delete-cookie
|
||||
Web::WebDriver::Response Session::delete_cookie(StringView 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. Delete cookies using the url variable name parameter as the filter argument.
|
||||
delete_cookies(name);
|
||||
|
||||
// 4. Return success with data null.
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
|
||||
Web::WebDriver::Response Session::delete_all_cookies()
|
||||
{
|
||||
|
|
|
@ -58,7 +58,6 @@ public:
|
|||
Web::WebDriver::Response get_window_handle();
|
||||
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
|
||||
Web::WebDriver::Response get_window_handles() const;
|
||||
Web::WebDriver::Response delete_cookie(StringView name);
|
||||
Web::WebDriver::Response delete_all_cookies();
|
||||
Web::WebDriver::Response take_element_screenshot(StringView element_id);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue