1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibWeb+WebContentr+WebDriver: Move driver response wrapping to LibWeb

Success responses are meant to be wrapped in a JSON object with a single
"value" key. Instead of doing this in both WebContent and WebDriver, do
it once in LibWeb.
This commit is contained in:
Timothy Flynn 2022-11-13 00:52:44 -05:00 committed by Linus Groh
parent 09c59ee7c0
commit 5385cb1287
Notes: sideshowbarker 2024-07-17 20:58:35 +09:00
4 changed files with 43 additions and 55 deletions

View file

@ -71,13 +71,6 @@ void Client::close_session(unsigned session_id)
dbgln_if(WEBDRIVER_DEBUG, "Unable to shut down session {}: Not found", session_id);
}
JsonValue Client::make_json_value(JsonValue const& value)
{
JsonObject result;
result.set("value", value);
return result;
}
// 8.1 New Session, https://w3c.github.io/webdriver/#dfn-new-sessions
// POST /session
Web::WebDriver::Response Client::new_session(Web::WebDriver::Parameters, JsonValue)
@ -144,7 +137,7 @@ Web::WebDriver::Response Client::new_session(Web::WebDriver::Parameters, JsonVal
// FIXME: 15. Set the request queue to a new queue.
// 16. Return success with data body.
return make_json_value(body);
return JsonValue { move(body) };
}
// 8.2 Delete Session, https://w3c.github.io/webdriver/#dfn-delete-session
@ -158,7 +151,7 @@ Web::WebDriver::Response Client::delete_session(Web::WebDriver::Parameters param
TRY(session->stop());
// 2. Return success with data null.
return make_json_value(JsonValue());
return JsonValue {};
}
// 8.3 Status, https://w3c.github.io/webdriver/#dfn-status
@ -259,8 +252,7 @@ Web::WebDriver::Response Client::get_window_handle(Web::WebDriver::Parameters pa
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window");
auto* session = TRY(find_session_with_id(parameters[0]));
auto result = TRY(session->get_window_handle());
return make_json_value(result);
return session->get_window_handle();
}
// 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
@ -269,8 +261,7 @@ Web::WebDriver::Response Client::close_window(Web::WebDriver::Parameters paramet
{
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/window");
auto* session = TRY(find_session_with_id(parameters[0]));
auto result = TRY(session->close_window());
return make_json_value(result);
return session->close_window();
}
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
@ -279,8 +270,7 @@ Web::WebDriver::Response Client::get_window_handles(Web::WebDriver::Parameters p
{
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window/handles");
auto* session = TRY(find_session_with_id(parameters[0]));
auto result = TRY(session->get_window_handles());
return make_json_value(result);
return session->get_window_handles();
}
// 11.8.1 Get Window Rect, https://w3c.github.io/webdriver/#dfn-get-window-rect