/* * Copyright (c) 2022, Florent Castelli * Copyright (c) 2022, Linus Groh * Copyright (c) 2022, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace WebDriver { struct LaunchBrowserCallbacks; class Session : public RefCounted { public: Session(unsigned session_id, NonnullRefPtr client, Web::WebDriver::LadybirdOptions options); ~Session(); unsigned session_id() const { return m_id; } struct Window { String handle; NonnullRefPtr web_content_connection; }; WebContentConnection& web_content_connection() const { auto current_window = m_windows.get(m_current_window_handle); VERIFY(current_window.has_value()); return current_window->web_content_connection; } String const& current_window_handle() const { return m_current_window_handle; } ErrorOr start(LaunchBrowserCallbacks const&); Web::WebDriver::Response stop(); Web::WebDriver::Response close_window(); Web::WebDriver::Response switch_to_window(StringView); Web::WebDriver::Response get_window_handles() const; private: using ServerPromise = Core::Promise>; ErrorOr> create_server(NonnullRefPtr promise); NonnullRefPtr m_client; Web::WebDriver::LadybirdOptions m_options; bool m_started { false }; unsigned m_id { 0 }; unsigned m_next_handle_id = 0; HashMap m_windows; String m_current_window_handle; Optional m_web_content_socket_path; Optional m_browser_pid; RefPtr m_web_content_server; }; }