diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index 0e73da1773..bff51dca8c 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include static ErrorOr load_content_filters(); @@ -103,7 +104,7 @@ ErrorOr serenity_main(Main::Arguments arguments) 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())); + webdriver_client = TRY(create_connection_from_passed_socket(webdriver_fd_passing_socket, "WebDriver"sv, webdriver_notifier, webcontent_client->page_host())); return app.exec(); } diff --git a/Ladybird/WebDriver/CMakeLists.txt b/Ladybird/WebDriver/CMakeLists.txt index 69601b1e81..ea0d3c07e9 100644 --- a/Ladybird/WebDriver/CMakeLists.txt +++ b/Ladybird/WebDriver/CMakeLists.txt @@ -3,6 +3,7 @@ set(WEBDRIVER_SOURCE_DIR ${SERENITY_SOURCE_DIR}/Userland/Services/WebDriver) set(SOURCES ${WEBDRIVER_SOURCE_DIR}/Client.cpp ${WEBDRIVER_SOURCE_DIR}/WebContentConnection.cpp + ../Utilities.cpp Session.cpp main.cpp ) @@ -14,3 +15,4 @@ target_include_directories(WebDriver PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..) target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland) target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services) target_link_libraries(WebDriver PRIVATE Qt::Core Qt::Network LibCore LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket) +add_dependencies(WebDriver headless-browser) diff --git a/Ladybird/WebDriver/Session.cpp b/Ladybird/WebDriver/Session.cpp index b3f29348b1..bbd3274901 100644 --- a/Ladybird/WebDriver/Session.cpp +++ b/Ladybird/WebDriver/Session.cpp @@ -11,6 +11,7 @@ #define AK_DONT_REPLACE_STD #include "Session.h" +#include "../Utilities.h" #include #include #include @@ -18,8 +19,9 @@ namespace WebDriver { -Session::Session(unsigned session_id, NonnullRefPtr client) +Session::Session(unsigned session_id, NonnullRefPtr client, Web::WebDriver::LadybirdOptions options) : m_client(move(client)) + , m_options(move(options)) , m_id(session_id) { } @@ -51,15 +53,39 @@ ErrorOr Session::start() auto fd_passing_socket_string = String::number(webcontent_fd_passing_fd); - char const* argv[] = { - "ladybird", - "--webdriver-fd-passing-socket", - fd_passing_socket_string.characters(), - nullptr, - }; + if (m_options.headless) { + auto resouces = String::formatted("{}/res", s_serenity_resource_root); + auto error_page = String::formatted("{}/res/html/error.html", s_serenity_resource_root); + auto certs = String::formatted("{}/etc/ca_certs.ini", s_serenity_resource_root); + + char const* argv[] = { + "headless-browser", + "--resources", + resouces.characters(), + "--error-page", + error_page.characters(), + "--certs", + certs.characters(), + "--webdriver-fd-passing-socket", + fd_passing_socket_string.characters(), + "about:blank", + nullptr, + }; + + if (execvp("./_deps/lagom-build/headless-browser", const_cast(argv)) < 0) + perror("execvp"); + } else { + char const* argv[] = { + "ladybird", + "--webdriver-fd-passing-socket", + fd_passing_socket_string.characters(), + nullptr, + }; + + if (execvp("./ladybird", const_cast(argv)) < 0) + perror("execvp"); + } - if (execvp("./ladybird", const_cast(argv)) < 0) - perror("execvp"); VERIFY_NOT_REACHED(); } diff --git a/Ladybird/WebDriver/Session.h b/Ladybird/WebDriver/Session.h index 601692351c..0f747b44ae 100644 --- a/Ladybird/WebDriver/Session.h +++ b/Ladybird/WebDriver/Session.h @@ -19,7 +19,7 @@ namespace WebDriver { class Session { public: - Session(unsigned session_id, NonnullRefPtr client); + Session(unsigned session_id, NonnullRefPtr client, Web::WebDriver::LadybirdOptions options); ~Session(); unsigned session_id() const { return m_id; } @@ -35,8 +35,11 @@ public: private: NonnullRefPtr m_client; + Web::WebDriver::LadybirdOptions m_options; + bool m_started { false }; unsigned m_id { 0 }; + RefPtr m_web_content_connection; Optional m_browser_pid; }; diff --git a/Ladybird/WebDriver/main.cpp b/Ladybird/WebDriver/main.cpp index ef949e960f..11f68d1dce 100644 --- a/Ladybird/WebDriver/main.cpp +++ b/Ladybird/WebDriver/main.cpp @@ -6,6 +6,7 @@ #define AK_DONT_REPLACE_STD +#include "../Utilities.h" #include #include #include @@ -36,6 +37,8 @@ ErrorOr serenity_main(Main::Arguments arguments) return 1; } + platform_init(); + Core::EventLoop loop; auto server = TRY(Core::TCPServer::try_create());