Parcourir la source

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.
Timothy Flynn il y a 2 ans
Parent
commit
700ad6bf35

+ 3 - 7
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());
         dbgln("Failed to load content filters: {}", maybe_content_filter_error.error());
 
 
     int webcontent_fd_passing_socket { -1 };
     int webcontent_fd_passing_socket { -1 };
-    DeprecatedString webdriver_content_ipc_path;
 
 
     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_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path");
     args_parser.parse(arguments);
     args_parser.parse(arguments);
 
 
     VERIFY(webcontent_fd_passing_socket >= 0);
     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);
     proxy_socket_through_notifier(*webcontent_client, webcontent_notifier);
 
 
     QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read);
     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();
     return app.exec();
 }
 }

+ 4 - 1
Ladybird/WebContentView.cpp

@@ -603,7 +603,7 @@ void WebContentView::create_client()
     m_client_state = {};
     m_client_state = {};
 
 
     auto candidate_web_content_paths = get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors();
     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.setSocket(new_client->socket().fd().value());
     m_web_content_notifier.setEnabled(true);
     m_web_content_notifier.setEnabled(true);
@@ -636,6 +636,9 @@ void WebContentView::create_client()
 
 
     // FIXME: Get the screen rect.
     // FIXME: Get the screen rect.
     // client().async_update_screen_rects(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index());
     // 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()
 void WebContentView::handle_web_content_process_crash()

+ 2 - 7
Userland/Libraries/LibWebView/ViewImplementation.cpp

@@ -126,7 +126,7 @@ void ViewImplementation::run_javascript(StringView js_source)
 
 
 #if !defined(AK_OS_SERENITY)
 #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] {};
     int socket_fds[2] {};
     TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds));
     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));
         auto webcontent_fd_passing_socket_string = TRY(String::number(wc_fd_passing_fd));
 
 
-        Vector<StringView> arguments {
+        auto arguments = Array {
             "WebContent"sv,
             "WebContent"sv,
             "--webcontent-fd-passing-socket"sv,
             "--webcontent-fd-passing-socket"sv,
             webcontent_fd_passing_socket_string
             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;
         ErrorOr<void> result;
         for (auto const& path : candidate_web_content_paths) {
         for (auto const& path : candidate_web_content_paths) {
             result = Core::System::exec(path, arguments, Core::System::SearchInPath::Yes);
             result = Core::System::exec(path, arguments, Core::System::SearchInPath::Yes);

+ 1 - 1
Userland/Libraries/LibWebView/ViewImplementation.h

@@ -118,7 +118,7 @@ protected:
     virtual void update_zoom() = 0;
     virtual void update_zoom() = 0;
 
 
 #if !defined(AK_OS_SERENITY)
 #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
 #endif
 
 
     struct SharedBitmap {
     struct SharedBitmap {

+ 4 - 0
Userland/Services/WebContent/PageHost.cpp

@@ -93,6 +93,10 @@ ErrorOr<void> PageHost::connect_to_webdriver(DeprecatedString const& webdriver_i
 {
 {
     VERIFY(!m_webdriver);
     VERIFY(!m_webdriver);
     m_webdriver = TRY(WebDriverConnection::connect(*this, webdriver_ipc_path));
     m_webdriver = TRY(WebDriverConnection::connect(*this, webdriver_ipc_path));
+
+    if (on_webdriver_connection)
+        on_webdriver_connection(*m_webdriver);
+
     return {};
     return {};
 }
 }
 
 

+ 1 - 0
Userland/Services/WebContent/PageHost.h

@@ -43,6 +43,7 @@ public:
     Web::DevicePixelSize content_size() const { return m_content_size; }
     Web::DevicePixelSize content_size() const { return m_content_size; }
 
 
     ErrorOr<void> connect_to_webdriver(DeprecatedString const& webdriver_ipc_path);
     ErrorOr<void> connect_to_webdriver(DeprecatedString const& webdriver_ipc_path);
+    Function<void(WebDriverConnection&)> on_webdriver_connection;
 
 
     void alert_closed();
     void alert_closed();
     void confirm_closed(bool accepted);
     void confirm_closed(bool accepted);

+ 4 - 4
Userland/Utilities/headless-browser.cpp

@@ -53,12 +53,9 @@ public:
 
 
 #if defined(AK_OS_SERENITY)
 #if defined(AK_OS_SERENITY)
         view->m_client_state.client = TRY(WebView::WebContentClient::try_create(*view));
         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
 #else
         auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv));
         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
 #endif
 
 
         view->client().async_update_system_theme(move(theme));
         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_viewport_rect({ { 0, 0 }, window_size });
         view->client().async_set_window_size(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;
         return view;
     }
     }