diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-03-16 08:50:22 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-16 15:02:41 +0000 |
commit | 700ad6bf350f9e74044c015157f8ad7072c7f04c (patch) | |
tree | 6d9957d55b42f72a7b1122ab286c34fdd8922cd0 | |
parent | 3a7257c9fe24f1c21a744a76e97f3ee7a2f42f7e (diff) | |
download | serenity-700ad6bf350f9e74044c015157f8ad7072c7f04c.zip |
WebContent+LibWebView: Consolidate the way browsers connect to WebDriver
Currently, on Serenity, we connect to WebDriver from the browser-side of
the WebContent connection for both Browser and headless-browser.
On Lagom, we connect from within the WebContent process itself, signaled
by a command line flag.
This patch changes Lagom browsers to connect to WebDriver the same way
that Serenity browsers do. This will ensure we can do other initializers
in the same order across all platforms and browsers.
-rw-r--r-- | Ladybird/WebContent/main.cpp | 10 | ||||
-rw-r--r-- | Ladybird/WebContentView.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/ViewImplementation.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/ViewImplementation.h | 2 | ||||
-rw-r--r-- | Userland/Services/WebContent/PageHost.cpp | 4 | ||||
-rw-r--r-- | Userland/Services/WebContent/PageHost.h | 1 | ||||
-rw-r--r-- | Userland/Utilities/headless-browser.cpp | 8 |
7 files changed, 19 insertions, 20 deletions
diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index d1ab62ad9b..f30f672378 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -83,11 +83,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) dbgln("Failed to load content filters: {}", maybe_content_filter_error.error()); int webcontent_fd_passing_socket { -1 }; - DeprecatedString webdriver_content_ipc_path; 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_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path"); args_parser.parse(arguments); VERIFY(webcontent_fd_passing_socket >= 0); @@ -100,11 +98,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) proxy_socket_through_notifier(*webcontent_client, webcontent_notifier); QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read); - RefPtr<WebContent::WebDriverConnection> webdriver_client; - if (!webdriver_content_ipc_path.is_empty()) { - webdriver_client = TRY(WebContent::WebDriverConnection::connect(webcontent_client->page_host(), webdriver_content_ipc_path)); - proxy_socket_through_notifier(*webdriver_client, webdriver_notifier); - } + webcontent_client->page_host().on_webdriver_connection = [&](auto& webdriver) { + proxy_socket_through_notifier(webdriver, webdriver_notifier); + }; return app.exec(); } diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index acc1457ffe..f6394145bf 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -603,7 +603,7 @@ void WebContentView::create_client() m_client_state = {}; auto candidate_web_content_paths = get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); - auto new_client = launch_web_content_process(candidate_web_content_paths, m_webdriver_content_ipc_path).release_value_but_fixme_should_propagate_errors(); + auto new_client = launch_web_content_process(candidate_web_content_paths).release_value_but_fixme_should_propagate_errors(); m_web_content_notifier.setSocket(new_client->socket().fd().value()); m_web_content_notifier.setEnabled(true); @@ -636,6 +636,9 @@ void WebContentView::create_client() // FIXME: Get the screen rect. // client().async_update_screen_rects(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index()); + + if (!m_webdriver_content_ipc_path.is_empty()) + client().async_connect_to_webdriver(m_webdriver_content_ipc_path); } void WebContentView::handle_web_content_process_crash() diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 85332ee979..c77b8c27f9 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -126,7 +126,7 @@ void ViewImplementation::run_javascript(StringView js_source) #if !defined(AK_OS_SERENITY) -ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, StringView webdriver_content_ipc_path) +ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths) { int socket_fds[2] {}; TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); @@ -149,17 +149,12 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ViewImplementation::launch_web auto webcontent_fd_passing_socket_string = TRY(String::number(wc_fd_passing_fd)); - Vector<StringView> arguments { + auto arguments = Array { "WebContent"sv, "--webcontent-fd-passing-socket"sv, webcontent_fd_passing_socket_string }; - if (!webdriver_content_ipc_path.is_empty()) { - TRY(arguments.try_append("--webdriver-content-path"sv)); - TRY(arguments.try_append(webdriver_content_ipc_path)); - } - ErrorOr<void> result; for (auto const& path : candidate_web_content_paths) { result = Core::System::exec(path, arguments, Core::System::SearchInPath::Yes); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index d23e4f7ef4..d065f14c7c 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -118,7 +118,7 @@ protected: virtual void update_zoom() = 0; #if !defined(AK_OS_SERENITY) - ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths, StringView webdriver_content_ipc_path); + ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(ReadonlySpan<String> candidate_web_content_paths); #endif struct SharedBitmap { diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index ae30fd7cf2..582d731735 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -93,6 +93,10 @@ ErrorOr<void> PageHost::connect_to_webdriver(DeprecatedString const& webdriver_i { VERIFY(!m_webdriver); m_webdriver = TRY(WebDriverConnection::connect(*this, webdriver_ipc_path)); + + if (on_webdriver_connection) + on_webdriver_connection(*m_webdriver); + return {}; } diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index b7f3c133c4..fafbb8f676 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -43,6 +43,7 @@ public: Web::DevicePixelSize content_size() const { return m_content_size; } ErrorOr<void> connect_to_webdriver(DeprecatedString const& webdriver_ipc_path); + Function<void(WebDriverConnection&)> on_webdriver_connection; void alert_closed(); void confirm_closed(bool accepted); diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 498a23104f..5ce84c9c39 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -53,12 +53,9 @@ public: #if defined(AK_OS_SERENITY) view->m_client_state.client = TRY(WebView::WebContentClient::try_create(*view)); - - if (!web_driver_ipc_path.is_empty()) - view->client().async_connect_to_webdriver(web_driver_ipc_path); #else auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv)); - view->m_client_state.client = TRY(view->launch_web_content_process(candidate_web_content_paths, web_driver_ipc_path)); + view->m_client_state.client = TRY(view->launch_web_content_process(candidate_web_content_paths)); #endif view->client().async_update_system_theme(move(theme)); @@ -67,6 +64,9 @@ public: view->client().async_set_viewport_rect({ { 0, 0 }, window_size }); view->client().async_set_window_size(window_size); + if (!web_driver_ipc_path.is_empty()) + view->client().async_connect_to_webdriver(web_driver_ipc_path); + return view; } |