ladybird/Userland/Applications/Browser/WebDriverConnection.cpp
Sam Atkins 8c0f1da9f7 Browser: Add a basic WebDriver API
This adds a new option "--webdriver" that opens a local unix socket
in /tmp/browser_{pid} which the WebDriver server can use to send
commands to the Browser instance.

Co-authored-by: Florent Castelli <florent.castelli@gmail.com>
2022-10-12 23:07:42 +02:00

49 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "WebDriverConnection.h"
#include "BrowserWindow.h"
namespace Browser {
WebDriverConnection::WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window)
: IPC::ConnectionToServer<WebDriverSessionClientEndpoint, WebDriverSessionServerEndpoint>(*this, move(socket))
, m_browser_window(move(browser_window))
{
}
void WebDriverConnection::quit()
{
dbgln("WebDriverConnection: quit");
if (auto browser_window = m_browser_window.strong_ref())
browser_window->close();
}
Messages::WebDriverSessionClient::GetUrlResponse WebDriverConnection::get_url()
{
dbgln("WebDriverConnection: get_url");
if (auto browser_window = m_browser_window.strong_ref())
return { browser_window->active_tab().url() };
return { URL("") };
}
void WebDriverConnection::set_url(AK::URL const& url)
{
dbgln("WebDriverConnection: set_url {}", url);
if (auto browser_window = m_browser_window.strong_ref())
browser_window->active_tab().load(url);
}
Messages::WebDriverSessionClient::GetTitleResponse WebDriverConnection::get_title()
{
dbgln("WebDriverConnection: get_title");
if (auto browser_window = m_browser_window.strong_ref())
return { browser_window->active_tab().title() };
return { "" };
}
}