1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

WebContent+WebDriver: Move window commands handling back to WebDriver

With current architecture every window has its own WebContent process
and there is one WebDriver process that is responsible for talking to
all opened windows. It thus make sense to manage open windows from
WebDriver process instead of WebContent process that is not supposed
to know about all other opened WebContent processes.

This mostly reverts 826d5f8f9a but also
adds `web_content_connection` to window structure and window id
generation (currently out of spec).

With these changes `get_window_handles`, `switch_to_window` and
`close_window` start to actually switch, close and returned handles
of currently opened windows.
This commit is contained in:
Aliaksandr Kalenik 2023-03-06 01:57:36 +03:00 committed by Tim Flynn
parent d036862f2b
commit 0905fd57e4
6 changed files with 99 additions and 91 deletions

View file

@ -10,6 +10,7 @@
#include <AK/Error.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <LibCore/Promise.h>
#include <LibWeb/WebDriver/Capabilities.h>
#include <LibWeb/WebDriver/Error.h>
@ -28,14 +29,27 @@ public:
unsigned session_id() const { return m_id; }
WebContentConnection& web_content_connection()
struct Window {
String handle;
NonnullRefPtr<WebContentConnection> web_content_connection;
};
WebContentConnection& web_content_connection() const
{
VERIFY(m_web_content_connection);
return *m_web_content_connection;
auto const& current_window = m_windows.get(m_current_window_handle).value();
return current_window.web_content_connection;
}
String const& current_window_handle() const
{
return m_current_window_handle;
}
ErrorOr<void> 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<void>>;
@ -47,7 +61,10 @@ private:
bool m_started { false };
unsigned m_id { 0 };
RefPtr<WebContentConnection> m_web_content_connection;
unsigned m_next_handle_id = 0;
HashMap<String, Window> m_windows;
String m_current_window_handle;
Optional<DeprecatedString> m_web_content_socket_path;
Optional<pid_t> m_browser_pid;
};