mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb+WebDriver: Convert WebDriver session flags to an enumeration
Rather than a list of strings, this will be easier to deal with as a bitwise enumeration.
This commit is contained in:
@@ -54,7 +54,7 @@ Web::WebDriver::Response Client::new_session(Web::WebDriver::Parameters, JsonVal
|
||||
// commands may be forwarded to this associated session on subsequent commands.
|
||||
|
||||
// 3. Let flags be a set containing "http".
|
||||
static constexpr Array flags { "http"sv };
|
||||
static constexpr auto flags = Web::WebDriver::SessionFlags::Http;
|
||||
|
||||
// 4. Let capabilities be the result of trying to process capabilities with parameters and flags.
|
||||
auto capabilities = TRY(Web::WebDriver::process_capabilities(payload, flags));
|
||||
|
||||
@@ -25,13 +25,13 @@ namespace WebDriver {
|
||||
static HashMap<String, NonnullRefPtr<Session>> s_sessions;
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-create-a-session
|
||||
ErrorOr<NonnullRefPtr<Session>> Session::create(NonnullRefPtr<Client> client, JsonObject& capabilities, ReadonlySpan<StringView> flags)
|
||||
ErrorOr<NonnullRefPtr<Session>> Session::create(NonnullRefPtr<Client> client, JsonObject& capabilities, Web::WebDriver::SessionFlags flags)
|
||||
{
|
||||
// 1. Let session id be the result of generating a UUID.
|
||||
auto session_id = MUST(Web::Crypto::generate_random_uuid());
|
||||
|
||||
// 2. Let session be a new session with session ID session id, and HTTP flag flags contains "http".
|
||||
auto session = adopt_ref(*new Session(client, capabilities, move(session_id), flags.contains_slow("http"sv)));
|
||||
auto session = adopt_ref(*new Session(client, capabilities, move(session_id), flags));
|
||||
TRY(session->start(client->launch_browser_callbacks()));
|
||||
|
||||
// FIXME: 3. Let proxy be the result of getting property "proxy" from capabilities and run the substeps of the first matching statement:
|
||||
@@ -59,7 +59,7 @@ ErrorOr<NonnullRefPtr<Session>> Session::create(NonnullRefPtr<Client> client, Js
|
||||
capabilities.set("unhandledPromptBehavior"sv, move(serialized_user_prompt_handler));
|
||||
|
||||
// 9. If flags contains "http":
|
||||
if (flags.contains_slow("http"sv)) {
|
||||
if (has_flag(flags, Web::WebDriver::SessionFlags::Http)) {
|
||||
// 1. Let strategy be the result of getting property "pageLoadStrategy" from capabilities. If strategy is a
|
||||
// string, set the session's page loading strategy to strategy. Otherwise, set the page loading strategy to
|
||||
// normal and set a property of capabilities with name "pageLoadStrategy" and value "normal".
|
||||
@@ -106,11 +106,11 @@ ErrorOr<NonnullRefPtr<Session>> Session::create(NonnullRefPtr<Client> client, Js
|
||||
return session;
|
||||
}
|
||||
|
||||
Session::Session(NonnullRefPtr<Client> client, JsonObject const& capabilities, String session_id, bool http)
|
||||
Session::Session(NonnullRefPtr<Client> client, JsonObject const& capabilities, String session_id, Web::WebDriver::SessionFlags flags)
|
||||
: m_client(move(client))
|
||||
, m_options(capabilities)
|
||||
, m_session_id(move(session_id))
|
||||
, m_http(http)
|
||||
, m_session_flags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ struct LaunchBrowserCallbacks;
|
||||
|
||||
class Session : public RefCounted<Session> {
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<Session>> create(NonnullRefPtr<Client> client, JsonObject& capabilities, ReadonlySpan<StringView> flags);
|
||||
static ErrorOr<NonnullRefPtr<Session>> create(NonnullRefPtr<Client> client, JsonObject& capabilities, Web::WebDriver::SessionFlags flags);
|
||||
~Session();
|
||||
|
||||
enum class AllowInvalidWindowHandle {
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Session(NonnullRefPtr<Client> client, JsonObject const& capabilities, String session_id, bool http);
|
||||
Session(NonnullRefPtr<Client> client, JsonObject const& capabilities, String session_id, Web::WebDriver::SessionFlags flags);
|
||||
|
||||
ErrorOr<void> start(LaunchBrowserCallbacks const&);
|
||||
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
Web::WebDriver::LadybirdOptions m_options;
|
||||
|
||||
String m_session_id;
|
||||
bool m_http { false };
|
||||
Web::WebDriver::SessionFlags m_session_flags { Web::WebDriver::SessionFlags::Default };
|
||||
|
||||
HashMap<String, Window> m_windows;
|
||||
String m_current_window_handle;
|
||||
|
||||
Reference in New Issue
Block a user