mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
Browser+WebContent+WebDriver: Move Delete All Cookies to WebContent
This commit is contained in:
parent
b7f21bb92e
commit
ff6055e0a3
9 changed files with 18 additions and 69 deletions
|
@ -10,8 +10,6 @@
|
|||
#include "WebDriverConnection.h"
|
||||
#include "BrowserWindow.h"
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/Cookie/Cookie.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
#include <LibWebView/WebContentClient.h>
|
||||
|
||||
namespace Browser {
|
||||
|
@ -58,26 +56,4 @@ void WebDriverConnection::forward()
|
|||
browser_window->active_tab().go_forward();
|
||||
}
|
||||
|
||||
Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies");
|
||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||
if (browser_window->active_tab().on_get_cookies_entries) {
|
||||
return { browser_window->active_tab().on_get_cookies_entries() };
|
||||
}
|
||||
}
|
||||
return { {} };
|
||||
}
|
||||
|
||||
void WebDriverConnection::update_cookie(Web::Cookie::Cookie const& cookie)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: update_cookie {}", cookie.name);
|
||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||
auto& tab = browser_window->active_tab();
|
||||
if (tab.on_update_cookie) {
|
||||
tab.on_update_cookie(tab.url(), cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,8 +42,6 @@ public:
|
|||
virtual void refresh() override;
|
||||
virtual void back() override;
|
||||
virtual void forward() override;
|
||||
virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override;
|
||||
virtual void update_cookie(Web::Cookie::Cookie const&) override;
|
||||
|
||||
private:
|
||||
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);
|
||||
|
|
|
@ -18,6 +18,4 @@ endpoint WebDriverSessionClient {
|
|||
refresh() =|
|
||||
back() =|
|
||||
forward() =|
|
||||
get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
|
||||
update_cookie(Web::Cookie::Cookie cookie) =|
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ endpoint WebDriverClient {
|
|||
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)
|
||||
delete_all_cookies() => (Web::WebDriver::Response response)
|
||||
take_screenshot() => (Web::WebDriver::Response response)
|
||||
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
|
||||
}
|
||||
|
|
|
@ -990,6 +990,21 @@ Messages::WebDriverClient::DeleteCookieResponse WebDriverConnection::delete_cook
|
|||
return make_success_response({});
|
||||
}
|
||||
|
||||
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
|
||||
Messages::WebDriverClient::DeleteAllCookiesResponse WebDriverConnection::delete_all_cookies()
|
||||
{
|
||||
// 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, giving no filtering argument.
|
||||
delete_cookies();
|
||||
|
||||
// 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()
|
||||
{
|
||||
|
|
|
@ -60,6 +60,7 @@ private:
|
|||
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::DeleteAllCookiesResponse delete_all_cookies() override;
|
||||
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
||||
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
||||
|
||||
|
|
|
@ -789,8 +789,7 @@ Web::WebDriver::Response Client::handle_delete_all_cookies(Vector<StringView> co
|
|||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->delete_all_cookies());
|
||||
return make_json_value(result);
|
||||
return session->web_content_connection().delete_all_cookies();
|
||||
}
|
||||
|
||||
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
#include <LibGfx/Point.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/Size.h>
|
||||
#include <LibWeb/Cookie/Cookie.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
#include <LibWeb/WebDriver/ExecuteScript.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace WebDriver {
|
||||
|
@ -297,37 +294,4 @@ Web::WebDriver::Response Session::get_window_handles() const
|
|||
return JsonValue { handles };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-delete-cookies
|
||||
void Session::delete_cookies(Optional<StringView> const& name)
|
||||
{
|
||||
// For each cookie among all associated cookies of the current browsing context’s active document,
|
||||
// run the substeps of the first matching condition:
|
||||
for (auto& cookie : m_browser_connection->get_all_cookies()) {
|
||||
// -> 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_browser_connection->async_update_cookie(cookie);
|
||||
}
|
||||
// -> Otherwise
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
// 14.5 Delete All Cookies, https://w3c.github.io/webdriver/#dfn-delete-all-cookies
|
||||
Web::WebDriver::Response Session::delete_all_cookies()
|
||||
{
|
||||
// 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, giving no filtering argument.
|
||||
delete_cookies();
|
||||
|
||||
// 4. Return success with data null.
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,12 +58,9 @@ 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_all_cookies();
|
||||
Web::WebDriver::Response take_element_screenshot(StringView element_id);
|
||||
|
||||
private:
|
||||
void delete_cookies(Optional<StringView> const& name = {});
|
||||
|
||||
enum class ServerType {
|
||||
Browser,
|
||||
WebContent,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue