Skip to content

Commit 4031630

Browse files
trflynn89ADKaster
authored andcommitted
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.
1 parent 7021d30 commit 4031630

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

Ladybird/BrowserWindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
extern String s_serenity_resource_root;
2222
extern Browser::Settings* s_settings;
2323

24-
BrowserWindow::BrowserWindow()
24+
BrowserWindow::BrowserWindow(int webdriver_fd_passing_socket)
25+
: m_webdriver_fd_passing_socket(webdriver_fd_passing_socket)
2526
{
2627
m_tabs_container = new QTabWidget(this);
2728
m_tabs_container->setElideMode(Qt::TextElideMode::ElideRight);
@@ -282,7 +283,7 @@ void BrowserWindow::debug_request(String const& request, String const& argument)
282283

283284
void BrowserWindow::new_tab()
284285
{
285-
auto tab = make<Tab>(this);
286+
auto tab = make<Tab>(this, m_webdriver_fd_passing_socket);
286287
auto tab_ptr = tab.ptr();
287288
m_tabs.append(std::move(tab));
288289

Ladybird/BrowserWindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class WebContentView;
2222
class BrowserWindow : public QMainWindow {
2323
Q_OBJECT
2424
public:
25-
explicit BrowserWindow();
25+
explicit BrowserWindow(int webdriver_fd_passing_socket);
2626

2727
WebContentView& view() const { return m_current_tab->view(); }
2828

@@ -48,4 +48,6 @@ public slots:
4848
Tab* m_current_tab { nullptr };
4949

5050
Browser::CookieJar m_cookie_jar;
51+
52+
int m_webdriver_fd_passing_socket { -1 };
5153
};

Ladybird/Tab.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
extern String s_serenity_resource_root;
2121
extern Browser::Settings* s_settings;
2222

23-
Tab::Tab(BrowserWindow* window)
23+
Tab::Tab(BrowserWindow* window, int webdriver_fd_passing_socket)
2424
: QWidget(window)
2525
, m_window(window)
2626
{
2727
m_layout = new QBoxLayout(QBoxLayout::Direction::TopToBottom, this);
2828
m_layout->setSpacing(0);
2929
m_layout->setContentsMargins(0, 0, 0, 0);
3030

31-
m_view = new WebContentView;
31+
m_view = new WebContentView(webdriver_fd_passing_socket);
3232
m_toolbar = new QToolBar(this);
3333
m_location_edit = new QLineEdit(this);
3434

@@ -115,8 +115,13 @@ Tab::Tab(BrowserWindow* window)
115115
// FIXME: This is a hack to make the JS console usable in new windows.
116116
// Something else should ensure that there's an initial about:blank document loaded in the view.
117117
// We set m_is_history_navigation = true so that the initial about:blank doesn't get added to the history.
118-
m_is_history_navigation = true;
119-
m_view->load("about:blank"sv);
118+
//
119+
// Note we *don't* do this if we are connected to a WebDriver, as the Set URL command may come in very
120+
// quickly, and become replaced by this load.
121+
if (webdriver_fd_passing_socket == -1) {
122+
m_is_history_navigation = true;
123+
m_view->load("about:blank"sv);
124+
}
120125
}
121126

122127
void Tab::focus_location_editor()

Ladybird/Tab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BrowserWindow;
2222
class Tab final : public QWidget {
2323
Q_OBJECT
2424
public:
25-
explicit Tab(BrowserWindow* window);
25+
Tab(BrowserWindow* window, int webdriver_fd_passing_socket);
2626

2727
WebContentView& view() { return *m_view; }
2828

Ladybird/WebContent/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QSocketNotifier>
3030
#include <QTimer>
3131
#include <WebContent/ConnectionFromClient.h>
32+
#include <WebContent/WebDriverConnection.h>
3233

3334
static ErrorOr<void> load_content_filters();
3435

@@ -89,14 +90,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
8990
dbgln("Failed to load content filters: {}", maybe_content_filter_error.error());
9091

9192
int webcontent_fd_passing_socket { -1 };
93+
int webdriver_fd_passing_socket { -1 };
9294

9395
Core::ArgsParser args_parser;
9496
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");
97+
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");
9598
args_parser.parse(arguments);
9699

97100
QSocketNotifier webcontent_notifier(QSocketNotifier::Type::Read);
98101
auto webcontent_client = TRY(create_connection_from_passed_socket<WebContent::ConnectionFromClient>(webcontent_fd_passing_socket, "WebContent"sv, webcontent_notifier));
99102

103+
QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read);
104+
RefPtr<WebContent::WebDriverConnection> webdriver_client;
105+
if (webdriver_fd_passing_socket >= 0)
106+
webdriver_client = TRY(create_connection_from_passed_socket<WebContent::WebDriverConnection>(webdriver_fd_passing_socket, "WebDriver"sv, webdriver_notifier, *webcontent_client, webcontent_client->page_host()));
107+
100108
return app.exec();
101109
}
102110

Ladybird/WebContentView.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
#include <QTreeView>
5555
#include <QVBoxLayout>
5656

57-
WebContentView::WebContentView()
57+
WebContentView::WebContentView(int webdriver_fd_passing_socket)
58+
: m_webdriver_fd_passing_socket(webdriver_fd_passing_socket)
5859
{
5960
setMouseTracking(true);
6061

@@ -589,12 +590,15 @@ void WebContentView::create_client()
589590
auto takeover_string = String::formatted("WebContent:{}", wc_fd);
590591
MUST(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
591592

592-
auto fd_passing_socket_string = String::number(wc_fd_passing_fd);
593+
auto webcontent_fd_passing_socket_string = String::number(wc_fd_passing_fd);
594+
auto webdriver_fd_passing_socket_string = String::number(m_webdriver_fd_passing_socket);
593595

594596
char const* argv[] = {
595597
"WebContent",
596598
"--webcontent-fd-passing-socket",
597-
fd_passing_socket_string.characters(),
599+
webcontent_fd_passing_socket_string.characters(),
600+
"--webdriver-fd-passing-socket",
601+
webdriver_fd_passing_socket_string.characters(),
598602
nullptr,
599603
};
600604

Ladybird/WebContentView.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class WebContentView final
4848
, public WebView::ViewImplementation {
4949
Q_OBJECT
5050
public:
51-
WebContentView();
51+
explicit WebContentView(int webdriver_fd_passing_socket);
5252
virtual ~WebContentView() override;
5353

5454
void load(AK::URL const&);
@@ -201,4 +201,6 @@ class WebContentView final
201201
} m_client_state;
202202

203203
RefPtr<Gfx::Bitmap> m_backup_bitmap;
204+
205+
int m_webdriver_fd_passing_socket { -1 };
204206
};

Ladybird/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
6161
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");
6262

6363
StringView raw_url;
64+
int webdriver_fd_passing_socket { -1 };
65+
6466
Core::ArgsParser args_parser;
6567
args_parser.set_general_help("The Ladybird web browser :^)");
6668
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
69+
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");
6770
args_parser.parse(arguments);
6871

69-
BrowserWindow window;
72+
BrowserWindow window(webdriver_fd_passing_socket);
7073
s_settings = new Browser::Settings(&window);
7174
window.setWindowTitle("Ladybird");
7275
window.resize(800, 600);

0 commit comments

Comments
 (0)