2023-11-08 13:47:41 -05:00
/*
* Copyright ( c ) 2023 , Andrew Kaster < akaster @ serenityos . org >
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
# include <LibCore/ArgsParser.h>
# include <LibCore/EventLoop.h>
# include <LibCore/LocalServer.h>
2024-08-01 07:03:03 -04:00
# include <LibCore/Process.h>
2023-11-08 13:47:41 -05:00
# include <LibCore/StandardPaths.h>
# include <LibCore/System.h>
# include <LibFileSystem/FileSystem.h>
# include <LibIPC/SingleServer.h>
# include <LibMain/Main.h>
# include <LibWeb/Bindings/MainThreadVM.h>
# include <LibWeb/Loader/GeneratedPagesLoader.h>
# include <LibWeb/Loader/ResourceLoader.h>
# include <LibWeb/Platform/EventLoopPlugin.h>
# include <LibWeb/Platform/EventLoopPluginSerenity.h>
# include <LibWeb/WebSockets/WebSocket.h>
2024-11-10 10:26:07 -05:00
# include <LibWebView/HelperProcess.h>
2024-11-10 09:53:15 -05:00
# include <LibWebView/Plugins/FontPlugin.h>
2024-11-10 10:26:07 -05:00
# include <LibWebView/Utilities.h>
2023-11-08 13:47:41 -05:00
# include <WebWorker/ConnectionFromClient.h>
2024-07-05 22:41:07 -04:00
# if defined(HAVE_QT)
2024-11-10 09:23:10 -05:00
# include <LibWebView / EventLoop / EventLoopImplementationQt.h>
2024-07-05 22:41:07 -04:00
# include <QCoreApplication>
# endif
2024-11-14 10:01:23 -05:00
static ErrorOr < void > initialize_resource_loader ( GC : : Heap & , int request_server_socket ) ;
2023-11-08 13:47:41 -05:00
ErrorOr < int > serenity_main ( Main : : Arguments arguments )
{
2023-12-11 13:19:41 -05:00
AK : : set_rich_debug_enabled ( true ) ;
2024-04-15 19:39:48 -04:00
int request_server_socket { - 1 } ;
2024-01-06 15:13:59 -05:00
StringView serenity_resource_root ;
2024-07-10 07:50:21 -04:00
Vector < ByteString > certificates ;
2024-08-01 07:03:03 -04:00
bool wait_for_debugger = false ;
2023-11-08 13:47:41 -05:00
Core : : ArgsParser args_parser ;
2024-04-15 19:39:48 -04:00
args_parser . add_option ( request_server_socket , " File descriptor of the request server socket " , " request-server-socket " , ' s ' , " request-server-socket " ) ;
2024-01-06 15:13:59 -05:00
args_parser . add_option ( serenity_resource_root , " Absolute path to directory for serenity resources " , " serenity-resource-root " , ' r ' , " serenity-resource-root " ) ;
2024-07-10 07:50:21 -04:00
args_parser . add_option ( certificates , " Path to a certificate file " , " certificate " , ' C ' , " certificate " ) ;
2024-08-01 07:03:03 -04:00
args_parser . add_option ( wait_for_debugger , " Wait for debugger " , " wait-for-debugger " ) ;
2023-11-08 13:47:41 -05:00
args_parser . parse ( arguments ) ;
2024-08-01 07:03:03 -04:00
if ( wait_for_debugger )
Core : : Process : : wait_for_debugger_and_break ( ) ;
2024-07-05 22:41:07 -04:00
# if defined(HAVE_QT)
QCoreApplication app ( arguments . argc , arguments . argv ) ;
2024-11-10 09:23:10 -05:00
Core : : EventLoopManager : : install ( * new WebView : : EventLoopManagerQt ) ;
2024-07-05 22:41:07 -04:00
# endif
Core : : EventLoop event_loop ;
2024-11-10 10:26:07 -05:00
WebView : : platform_init ( ) ;
2023-11-08 13:47:41 -05:00
Web : : Platform : : EventLoopPlugin : : install ( * new Web : : Platform : : EventLoopPluginSerenity ) ;
2024-11-10 09:53:15 -05:00
Web : : Platform : : FontPlugin : : install ( * new WebView : : FontPlugin ( false ) ) ;
2023-11-08 13:47:41 -05:00
2024-07-09 04:59:25 -04:00
TRY ( Web : : Bindings : : initialize_main_thread_vm ( Web : : HTML : : EventLoop : : Type : : Worker ) ) ;
2023-11-08 13:47:41 -05:00
2024-10-30 09:38:57 -04:00
TRY ( initialize_resource_loader ( Web : : Bindings : : main_thread_vm ( ) . heap ( ) , request_server_socket ) ) ;
2023-11-08 13:47:41 -05:00
auto client = TRY ( IPC : : take_over_accepted_client_from_system_server < WebWorker : : ConnectionFromClient > ( ) ) ;
return event_loop . exec ( ) ;
}
2024-11-14 10:01:23 -05:00
static ErrorOr < void > initialize_resource_loader ( GC : : Heap & heap , int request_server_socket )
2023-11-08 13:47:41 -05:00
{
2024-10-22 17:47:33 -04:00
static_assert ( IsSame < IPC : : Transport , IPC : : TransportSocket > , " Need to handle other IPC transports here " ) ;
2024-04-15 19:39:48 -04:00
auto socket = TRY ( Core : : LocalSocket : : adopt_fd ( request_server_socket ) ) ;
TRY ( socket - > set_blocking ( true ) ) ;
2024-10-22 17:47:33 -04:00
auto request_client = TRY ( try_make_ref_counted < Requests : : RequestClient > ( IPC : : Transport ( move ( socket ) ) ) ) ;
2024-10-30 09:38:57 -04:00
Web : : ResourceLoader : : initialize ( heap , move ( request_client ) ) ;
2023-11-08 13:47:41 -05:00
return { } ;
}