ApplicationBridge.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/ByteString.h>
  7. #include <Application/ApplicationBridge.h>
  8. #include <Ladybird/AppKit/UI/LadybirdWebViewBridge.h>
  9. #include <Ladybird/HelperProcess.h>
  10. #include <Ladybird/Utilities.h>
  11. #include <LibProtocol/RequestClient.h>
  12. #include <LibWebView/WebContentClient.h>
  13. namespace Ladybird {
  14. // Unfortunately, the Protocol namespace conflicts hard with a @Protocol interface defined by Objective-C. And the #define
  15. // trick we use for e.g. Duration does not work for Protocol. So here, we make sure that any use of the Protocol namespace
  16. // is limited to .cpp files (i.e. not .h files that an Objective-C file can include).
  17. struct ApplicationBridgeImpl {
  18. RefPtr<Protocol::RequestClient> request_server_client;
  19. };
  20. ApplicationBridge::ApplicationBridge()
  21. : m_impl(make<ApplicationBridgeImpl>())
  22. {
  23. }
  24. ApplicationBridge::~ApplicationBridge() = default;
  25. ErrorOr<void> ApplicationBridge::launch_request_server(Vector<ByteString> const& certificates)
  26. {
  27. auto request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv));
  28. auto protocol_client = TRY(launch_request_server_process(request_server_paths, s_serenity_resource_root, certificates));
  29. m_impl->request_server_client = move(protocol_client);
  30. return {};
  31. }
  32. ErrorOr<NonnullRefPtr<SQL::SQLClient>> ApplicationBridge::launch_sql_server()
  33. {
  34. auto sql_server_paths = TRY(get_paths_for_helper_process("SQLServer"sv));
  35. auto sql_client = TRY(launch_sql_server_process(sql_server_paths));
  36. return sql_client;
  37. }
  38. ErrorOr<NonnullRefPtr<WebView::WebContentClient>> ApplicationBridge::launch_web_content(WebViewBridge& web_view_bridge)
  39. {
  40. // FIXME: Fail to open the tab, rather than crashing the whole application if this fails
  41. auto request_server_socket = TRY(connect_new_request_server_client(*m_impl->request_server_client));
  42. auto web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv));
  43. auto web_content = TRY(launch_web_content_process(web_view_bridge, web_content_paths, web_view_bridge.web_content_options(), move(request_server_socket)));
  44. return web_content;
  45. }
  46. ErrorOr<IPC::File> ApplicationBridge::launch_web_worker()
  47. {
  48. auto web_worker_paths = TRY(get_paths_for_helper_process("WebWorker"sv));
  49. auto worker_client = TRY(launch_web_worker_process(web_worker_paths, *m_impl->request_server_client));
  50. return worker_client->dup_socket();
  51. }
  52. }