main.cpp 2.6 KB

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