mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 19:15:08 +00:00
Ladybird: Construct a WebDriverConnection when instructed to do so
The WebDriver will pass the --webdriver-fd-passing-socket command line option when it launches Ladybird. Forward this flag onto the WebContent process, where it will create the WebDriverConnection for IPC.
This commit is contained in:
parent
7021d30288
commit
4031630b49
8 changed files with 38 additions and 13 deletions
|
@ -21,7 +21,8 @@
|
||||||
extern String s_serenity_resource_root;
|
extern String s_serenity_resource_root;
|
||||||
extern Browser::Settings* s_settings;
|
extern Browser::Settings* s_settings;
|
||||||
|
|
||||||
BrowserWindow::BrowserWindow()
|
BrowserWindow::BrowserWindow(int webdriver_fd_passing_socket)
|
||||||
|
: m_webdriver_fd_passing_socket(webdriver_fd_passing_socket)
|
||||||
{
|
{
|
||||||
m_tabs_container = new QTabWidget(this);
|
m_tabs_container = new QTabWidget(this);
|
||||||
m_tabs_container->setElideMode(Qt::TextElideMode::ElideRight);
|
m_tabs_container->setElideMode(Qt::TextElideMode::ElideRight);
|
||||||
|
@ -282,7 +283,7 @@ void BrowserWindow::debug_request(String const& request, String const& argument)
|
||||||
|
|
||||||
void BrowserWindow::new_tab()
|
void BrowserWindow::new_tab()
|
||||||
{
|
{
|
||||||
auto tab = make<Tab>(this);
|
auto tab = make<Tab>(this, m_webdriver_fd_passing_socket);
|
||||||
auto tab_ptr = tab.ptr();
|
auto tab_ptr = tab.ptr();
|
||||||
m_tabs.append(std::move(tab));
|
m_tabs.append(std::move(tab));
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WebContentView;
|
||||||
class BrowserWindow : public QMainWindow {
|
class BrowserWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit BrowserWindow();
|
explicit BrowserWindow(int webdriver_fd_passing_socket);
|
||||||
|
|
||||||
WebContentView& view() const { return m_current_tab->view(); }
|
WebContentView& view() const { return m_current_tab->view(); }
|
||||||
|
|
||||||
|
@ -48,4 +48,6 @@ private:
|
||||||
Tab* m_current_tab { nullptr };
|
Tab* m_current_tab { nullptr };
|
||||||
|
|
||||||
Browser::CookieJar m_cookie_jar;
|
Browser::CookieJar m_cookie_jar;
|
||||||
|
|
||||||
|
int m_webdriver_fd_passing_socket { -1 };
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
extern String s_serenity_resource_root;
|
extern String s_serenity_resource_root;
|
||||||
extern Browser::Settings* s_settings;
|
extern Browser::Settings* s_settings;
|
||||||
|
|
||||||
Tab::Tab(BrowserWindow* window)
|
Tab::Tab(BrowserWindow* window, int webdriver_fd_passing_socket)
|
||||||
: QWidget(window)
|
: QWidget(window)
|
||||||
, m_window(window)
|
, m_window(window)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ Tab::Tab(BrowserWindow* window)
|
||||||
m_layout->setSpacing(0);
|
m_layout->setSpacing(0);
|
||||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
m_view = new WebContentView;
|
m_view = new WebContentView(webdriver_fd_passing_socket);
|
||||||
m_toolbar = new QToolBar(this);
|
m_toolbar = new QToolBar(this);
|
||||||
m_location_edit = new QLineEdit(this);
|
m_location_edit = new QLineEdit(this);
|
||||||
|
|
||||||
|
@ -115,8 +115,13 @@ Tab::Tab(BrowserWindow* window)
|
||||||
// FIXME: This is a hack to make the JS console usable in new windows.
|
// FIXME: This is a hack to make the JS console usable in new windows.
|
||||||
// Something else should ensure that there's an initial about:blank document loaded in the view.
|
// Something else should ensure that there's an initial about:blank document loaded in the view.
|
||||||
// We set m_is_history_navigation = true so that the initial about:blank doesn't get added to the history.
|
// We set m_is_history_navigation = true so that the initial about:blank doesn't get added to the history.
|
||||||
m_is_history_navigation = true;
|
//
|
||||||
m_view->load("about:blank"sv);
|
// Note we *don't* do this if we are connected to a WebDriver, as the Set URL command may come in very
|
||||||
|
// quickly, and become replaced by this load.
|
||||||
|
if (webdriver_fd_passing_socket == -1) {
|
||||||
|
m_is_history_navigation = true;
|
||||||
|
m_view->load("about:blank"sv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::focus_location_editor()
|
void Tab::focus_location_editor()
|
||||||
|
|
|
@ -22,7 +22,7 @@ class BrowserWindow;
|
||||||
class Tab final : public QWidget {
|
class Tab final : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Tab(BrowserWindow* window);
|
Tab(BrowserWindow* window, int webdriver_fd_passing_socket);
|
||||||
|
|
||||||
WebContentView& view() { return *m_view; }
|
WebContentView& view() { return *m_view; }
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <WebContent/ConnectionFromClient.h>
|
#include <WebContent/ConnectionFromClient.h>
|
||||||
|
#include <WebContent/WebDriverConnection.h>
|
||||||
|
|
||||||
static ErrorOr<void> load_content_filters();
|
static ErrorOr<void> load_content_filters();
|
||||||
|
|
||||||
|
@ -89,14 +90,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
dbgln("Failed to load content filters: {}", maybe_content_filter_error.error());
|
dbgln("Failed to load content filters: {}", maybe_content_filter_error.error());
|
||||||
|
|
||||||
int webcontent_fd_passing_socket { -1 };
|
int webcontent_fd_passing_socket { -1 };
|
||||||
|
int webdriver_fd_passing_socket { -1 };
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(webcontent_fd_passing_socket, "File descriptor of the passing socket for the WebContent connection", "webcontent-fd-passing-socket", 'c', "webcontent_fd_passing_socket");
|
args_parser.add_option(webcontent_fd_passing_socket, "File descriptor of the passing socket for the WebContent connection", "webcontent-fd-passing-socket", 'c', "webcontent_fd_passing_socket");
|
||||||
|
args_parser.add_option(webdriver_fd_passing_socket, "File descriptor of the passing socket for the WebDriver connection", "webdriver-fd-passing-socket", 'd', "webdriver_fd_passing_socket");
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
QSocketNotifier webcontent_notifier(QSocketNotifier::Type::Read);
|
QSocketNotifier webcontent_notifier(QSocketNotifier::Type::Read);
|
||||||
auto webcontent_client = TRY(create_connection_from_passed_socket<WebContent::ConnectionFromClient>(webcontent_fd_passing_socket, "WebContent"sv, webcontent_notifier));
|
auto webcontent_client = TRY(create_connection_from_passed_socket<WebContent::ConnectionFromClient>(webcontent_fd_passing_socket, "WebContent"sv, webcontent_notifier));
|
||||||
|
|
||||||
|
QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read);
|
||||||
|
RefPtr<WebContent::WebDriverConnection> webdriver_client;
|
||||||
|
if (webdriver_fd_passing_socket >= 0)
|
||||||
|
webdriver_client = TRY(create_connection_from_passed_socket<WebContent::WebDriverConnection>(webdriver_fd_passing_socket, "WebDriver"sv, webdriver_notifier, *webcontent_client, webcontent_client->page_host()));
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,8 @@
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
WebContentView::WebContentView()
|
WebContentView::WebContentView(int webdriver_fd_passing_socket)
|
||||||
|
: m_webdriver_fd_passing_socket(webdriver_fd_passing_socket)
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
|
@ -589,12 +590,15 @@ void WebContentView::create_client()
|
||||||
auto takeover_string = String::formatted("WebContent:{}", wc_fd);
|
auto takeover_string = String::formatted("WebContent:{}", wc_fd);
|
||||||
MUST(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
|
MUST(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
|
||||||
|
|
||||||
auto fd_passing_socket_string = String::number(wc_fd_passing_fd);
|
auto webcontent_fd_passing_socket_string = String::number(wc_fd_passing_fd);
|
||||||
|
auto webdriver_fd_passing_socket_string = String::number(m_webdriver_fd_passing_socket);
|
||||||
|
|
||||||
char const* argv[] = {
|
char const* argv[] = {
|
||||||
"WebContent",
|
"WebContent",
|
||||||
"--webcontent-fd-passing-socket",
|
"--webcontent-fd-passing-socket",
|
||||||
fd_passing_socket_string.characters(),
|
webcontent_fd_passing_socket_string.characters(),
|
||||||
|
"--webdriver-fd-passing-socket",
|
||||||
|
webdriver_fd_passing_socket_string.characters(),
|
||||||
nullptr,
|
nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class WebContentView final
|
||||||
, public WebView::ViewImplementation {
|
, public WebView::ViewImplementation {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
WebContentView();
|
explicit WebContentView(int webdriver_fd_passing_socket);
|
||||||
virtual ~WebContentView() override;
|
virtual ~WebContentView() override;
|
||||||
|
|
||||||
void load(AK::URL const&);
|
void load(AK::URL const&);
|
||||||
|
@ -201,4 +201,6 @@ private:
|
||||||
} m_client_state;
|
} m_client_state;
|
||||||
|
|
||||||
RefPtr<Gfx::Bitmap> m_backup_bitmap;
|
RefPtr<Gfx::Bitmap> m_backup_bitmap;
|
||||||
|
|
||||||
|
int m_webdriver_fd_passing_socket { -1 };
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,12 +61,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");
|
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");
|
||||||
|
|
||||||
StringView raw_url;
|
StringView raw_url;
|
||||||
|
int webdriver_fd_passing_socket { -1 };
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.set_general_help("The Ladybird web browser :^)");
|
args_parser.set_general_help("The Ladybird web browser :^)");
|
||||||
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
|
||||||
|
args_parser.add_option(webdriver_fd_passing_socket, "File descriptor of the passing socket for the WebDriver connection", "webdriver-fd-passing-socket", 'd', "webdriver_fd_passing_socket");
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
BrowserWindow window;
|
BrowserWindow window(webdriver_fd_passing_socket);
|
||||||
s_settings = new Browser::Settings(&window);
|
s_settings = new Browser::Settings(&window);
|
||||||
window.setWindowTitle("Ladybird");
|
window.setWindowTitle("Ladybird");
|
||||||
window.resize(800, 600);
|
window.resize(800, 600);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue