Serenity Operating System
at master 51 lines 2.3 kB view raw
1/* 2 * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include "ImageCodecPluginSerenity.h" 8#include <LibCore/DeprecatedFile.h> 9#include <LibCore/EventLoop.h> 10#include <LibCore/LocalServer.h> 11#include <LibCore/StandardPaths.h> 12#include <LibCore/System.h> 13#include <LibIPC/SingleServer.h> 14#include <LibMain/Main.h> 15#include <LibWeb/Loader/ResourceLoader.h> 16#include <LibWeb/Platform/EventLoopPlugin.h> 17#include <LibWeb/Platform/EventLoopPluginSerenity.h> 18#include <LibWeb/Platform/FontPluginSerenity.h> 19#include <LibWeb/WebSockets/WebSocket.h> 20#include <LibWebView/RequestServerAdapter.h> 21#include <LibWebView/WebSocketClientAdapter.h> 22#include <WebContent/ConnectionFromClient.h> 23 24ErrorOr<int> serenity_main(Main::Arguments) 25{ 26 Core::EventLoop event_loop; 27 TRY(Core::System::pledge("stdio recvfd sendfd accept unix rpath")); 28 29 // This must be first; we can't check if /tmp/webdriver exists once we've unveiled other paths. 30 auto webdriver_socket_path = DeprecatedString::formatted("{}/webdriver", TRY(Core::StandardPaths::runtime_directory())); 31 if (Core::DeprecatedFile::exists(webdriver_socket_path)) 32 TRY(Core::System::unveil(webdriver_socket_path, "rw"sv)); 33 34 TRY(Core::System::unveil("/res", "r")); 35 TRY(Core::System::unveil("/etc/timezone", "r")); 36 TRY(Core::System::unveil("/usr/lib", "r")); 37 TRY(Core::System::unveil("/tmp/session/%sid/portal/request", "rw")); 38 TRY(Core::System::unveil("/tmp/session/%sid/portal/image", "rw")); 39 TRY(Core::System::unveil("/tmp/session/%sid/portal/websocket", "rw")); 40 TRY(Core::System::unveil(nullptr, nullptr)); 41 42 Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); 43 Web::Platform::ImageCodecPlugin::install(*new WebContent::ImageCodecPluginSerenity); 44 Web::Platform::FontPlugin::install(*new Web::Platform::FontPluginSerenity); 45 46 Web::WebSockets::WebSocketClientManager::initialize(TRY(WebView::WebSocketClientManagerAdapter::try_create())); 47 Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create())); 48 49 auto client = TRY(IPC::take_over_accepted_client_from_system_server<WebContent::ConnectionFromClient>()); 50 return event_loop.exec(); 51}