mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	Ladybird: Spawn ladybird and headless-browser using helpers in WebDriver
This allows the WebDriver to take advantage of the common helper process spawning code when launching ladybird, and to not assume a particular directory layout.
This commit is contained in:
		
							parent
							
								
									0d5d3f12e2
								
							
						
					
					
						commit
						7598a99ef3
					
				
					 2 changed files with 23 additions and 2 deletions
				
			
		|  | @ -5,6 +5,7 @@ set(SOURCES | ||||||
|     ${WEBDRIVER_SOURCE_DIR}/Session.cpp |     ${WEBDRIVER_SOURCE_DIR}/Session.cpp | ||||||
|     ${WEBDRIVER_SOURCE_DIR}/WebContentConnection.cpp |     ${WEBDRIVER_SOURCE_DIR}/WebContentConnection.cpp | ||||||
|     ../Utilities.cpp |     ../Utilities.cpp | ||||||
|  |     ../HelperProcess.cpp | ||||||
|     main.cpp |     main.cpp | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
| 
 | 
 | ||||||
| #define AK_DONT_REPLACE_STD | #define AK_DONT_REPLACE_STD | ||||||
| 
 | 
 | ||||||
|  | #include "../HelperProcess.h" | ||||||
| #include "../Utilities.h" | #include "../Utilities.h" | ||||||
| #include <AK/Platform.h> | #include <AK/Platform.h> | ||||||
| #include <LibCore/ArgsParser.h> | #include <LibCore/ArgsParser.h> | ||||||
|  | @ -15,6 +16,7 @@ | ||||||
| #include <LibCore/System.h> | #include <LibCore/System.h> | ||||||
| #include <LibCore/TCPServer.h> | #include <LibCore/TCPServer.h> | ||||||
| #include <LibMain/Main.h> | #include <LibMain/Main.h> | ||||||
|  | #include <QCoreApplication> | ||||||
| #include <WebDriver/Client.h> | #include <WebDriver/Client.h> | ||||||
| 
 | 
 | ||||||
| #if defined(AK_OS_MACOS) | #if defined(AK_OS_MACOS) | ||||||
|  | @ -33,6 +35,21 @@ static char** environment() | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static ErrorOr<pid_t> launch_process(StringView application, char const* argv[]) | ||||||
|  | { | ||||||
|  |     auto paths = TRY(get_paths_for_helper_process(application)); | ||||||
|  | 
 | ||||||
|  |     ErrorOr<pid_t> result = -1; | ||||||
|  |     for (auto const& path : paths) { | ||||||
|  |         auto path_view = path.bytes_as_string_view(); | ||||||
|  |         argv[0] = path_view.characters_without_null_termination(); | ||||||
|  |         result = Core::System::posix_spawn(path_view, nullptr, nullptr, const_cast<char**>(argv), environment()); | ||||||
|  |         if (!result.is_error()) | ||||||
|  |             break; | ||||||
|  |     } | ||||||
|  |     return result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path) | static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path) | ||||||
| { | { | ||||||
|     char const* argv[] = { |     char const* argv[] = { | ||||||
|  | @ -42,7 +59,7 @@ static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path) | ||||||
|         nullptr, |         nullptr, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     return Core::System::posix_spawn("./ladybird"sv, nullptr, nullptr, const_cast<char**>(argv), environment()); |     return launch_process("ladybird"sv, argv); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_path) | static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_path) | ||||||
|  | @ -65,11 +82,14 @@ static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_pat | ||||||
|         nullptr, |         nullptr, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     return Core::System::posix_spawn("./_deps/lagom-build/headless-browser"sv, nullptr, nullptr, const_cast<char**>(argv), environment()); |     return launch_process("headless-browser"sv, argv); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ErrorOr<int> serenity_main(Main::Arguments arguments) | ErrorOr<int> serenity_main(Main::Arguments arguments) | ||||||
| { | { | ||||||
|  |     // Note: only creating this to get access to its static methods in HelperProcess
 | ||||||
|  |     QCoreApplication application(arguments.argc, arguments.argv); | ||||||
|  | 
 | ||||||
|     auto listen_address = "0.0.0.0"sv; |     auto listen_address = "0.0.0.0"sv; | ||||||
|     int port = 8000; |     int port = 8000; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Kaster
						Andrew Kaster