diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index 22e3fb56be..cf73060466 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -21,7 +21,8 @@ extern String s_serenity_resource_root; 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->setElideMode(Qt::TextElideMode::ElideRight); @@ -282,7 +283,7 @@ void BrowserWindow::debug_request(String const& request, String const& argument) void BrowserWindow::new_tab() { - auto tab = make(this); + auto tab = make(this, m_webdriver_fd_passing_socket); auto tab_ptr = tab.ptr(); m_tabs.append(std::move(tab)); diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index d8c1dc3007..252f58ec94 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -22,7 +22,7 @@ class WebContentView; class BrowserWindow : public QMainWindow { Q_OBJECT public: - explicit BrowserWindow(); + explicit BrowserWindow(int webdriver_fd_passing_socket); WebContentView& view() const { return m_current_tab->view(); } @@ -48,4 +48,6 @@ private: Tab* m_current_tab { nullptr }; Browser::CookieJar m_cookie_jar; + + int m_webdriver_fd_passing_socket { -1 }; }; diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index 7bb6bda055..d040ce82b8 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -20,7 +20,7 @@ extern String s_serenity_resource_root; extern Browser::Settings* s_settings; -Tab::Tab(BrowserWindow* window) +Tab::Tab(BrowserWindow* window, int webdriver_fd_passing_socket) : QWidget(window) , m_window(window) { @@ -28,7 +28,7 @@ Tab::Tab(BrowserWindow* window) m_layout->setSpacing(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_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. // 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. - 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() diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index 94c2e81cec..838e669e75 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -22,7 +22,7 @@ class BrowserWindow; class Tab final : public QWidget { Q_OBJECT public: - explicit Tab(BrowserWindow* window); + Tab(BrowserWindow* window, int webdriver_fd_passing_socket); WebContentView& view() { return *m_view; } diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index a98656903b..0e73da1773 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -29,6 +29,7 @@ #include #include #include +#include static ErrorOr load_content_filters(); @@ -89,14 +90,21 @@ ErrorOr serenity_main(Main::Arguments arguments) dbgln("Failed to load content filters: {}", maybe_content_filter_error.error()); int webcontent_fd_passing_socket { -1 }; + int webdriver_fd_passing_socket { -1 }; 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(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); QSocketNotifier webcontent_notifier(QSocketNotifier::Type::Read); auto webcontent_client = TRY(create_connection_from_passed_socket(webcontent_fd_passing_socket, "WebContent"sv, webcontent_notifier)); + QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read); + RefPtr webdriver_client; + if (webdriver_fd_passing_socket >= 0) + webdriver_client = TRY(create_connection_from_passed_socket(webdriver_fd_passing_socket, "WebDriver"sv, webdriver_notifier, *webcontent_client, webcontent_client->page_host())); + return app.exec(); } diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 2c2dfca039..15a41350e0 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -54,7 +54,8 @@ #include #include -WebContentView::WebContentView() +WebContentView::WebContentView(int webdriver_fd_passing_socket) + : m_webdriver_fd_passing_socket(webdriver_fd_passing_socket) { setMouseTracking(true); @@ -589,12 +590,15 @@ void WebContentView::create_client() auto takeover_string = String::formatted("WebContent:{}", wc_fd); 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[] = { "WebContent", "--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, }; diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index f8d0b27098..a1dd0d1055 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -48,7 +48,7 @@ class WebContentView final , public WebView::ViewImplementation { Q_OBJECT public: - WebContentView(); + explicit WebContentView(int webdriver_fd_passing_socket); virtual ~WebContentView() override; void load(AK::URL const&); @@ -201,4 +201,6 @@ private: } m_client_state; RefPtr m_backup_bitmap; + + int m_webdriver_fd_passing_socket { -1 }; }; diff --git a/Ladybird/main.cpp b/Ladybird/main.cpp index 28400e5611..188d555fd1 100644 --- a/Ladybird/main.cpp +++ b/Ladybird/main.cpp @@ -61,12 +61,15 @@ ErrorOr serenity_main(Main::Arguments arguments) Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0"); StringView raw_url; + int webdriver_fd_passing_socket { -1 }; + Core::ArgsParser args_parser; 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_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); - BrowserWindow window; + BrowserWindow window(webdriver_fd_passing_socket); s_settings = new Browser::Settings(&window); window.setWindowTitle("Ladybird"); window.resize(800, 600);