application_bridge.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_REMOTE_COCOA_APP_SHIM_APPLICATION_BRIDGE_H_
  5. #define COMPONENTS_REMOTE_COCOA_APP_SHIM_APPLICATION_BRIDGE_H_
  6. #include "base/no_destructor.h"
  7. #include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h"
  8. #include "components/remote_cocoa/common/alert.mojom.h"
  9. #include "components/remote_cocoa/common/application.mojom.h"
  10. #include "components/remote_cocoa/common/native_widget_ns_window.mojom.h"
  11. #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
  12. #include "mojo/public/cpp/bindings/associated_receiver.h"
  13. #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
  14. #include "mojo/public/cpp/bindings/pending_associated_remote.h"
  15. #include "mojo/public/cpp/bindings/pending_receiver.h"
  16. #include "mojo/public/cpp/bindings/pending_remote.h"
  17. namespace remote_cocoa {
  18. // This class implements the remote_cocoa::mojom::Application interface, and
  19. // bridges that C++ interface to the Objective-C NSApplication. This class is
  20. // the root of all other remote_cocoa classes (e.g, NSAlerts, NSWindows,
  21. // NSViews).
  22. class REMOTE_COCOA_APP_SHIM_EXPORT ApplicationBridge
  23. : public mojom::Application {
  24. public:
  25. static ApplicationBridge* Get();
  26. void BindReceiver(
  27. mojo::PendingAssociatedReceiver<mojom::Application> receiver);
  28. // Set callbacks to create content types (content types cannot be created
  29. // in remote_cocoa).
  30. // TODO(https://crbug.com/888290): Move these types from content to
  31. // remote_cocoa.
  32. using RenderWidgetHostNSViewCreateCallback = base::RepeatingCallback<void(
  33. uint64_t view_id,
  34. mojo::ScopedInterfaceEndpointHandle host_handle,
  35. mojo::ScopedInterfaceEndpointHandle view_request_handle)>;
  36. using WebContentsNSViewCreateCallback = base::RepeatingCallback<void(
  37. uint64_t view_id,
  38. mojo::ScopedInterfaceEndpointHandle host_handle,
  39. mojo::ScopedInterfaceEndpointHandle view_request_handle)>;
  40. void SetContentNSViewCreateCallbacks(
  41. RenderWidgetHostNSViewCreateCallback render_widget_host_create_callback,
  42. WebContentsNSViewCreateCallback web_conents_create_callback);
  43. // mojom::Application:
  44. void CreateAlert(
  45. mojo::PendingReceiver<mojom::AlertBridge> bridge_receiver) override;
  46. void ShowColorPanel(mojo::PendingReceiver<mojom::ColorPanel> receiver,
  47. mojo::PendingRemote<mojom::ColorPanelHost> host) override;
  48. void CreateNativeWidgetNSWindow(
  49. uint64_t bridge_id,
  50. mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
  51. bridge_receiver,
  52. mojo::PendingAssociatedRemote<mojom::NativeWidgetNSWindowHost> host,
  53. mojo::PendingAssociatedRemote<mojom::TextInputHost> text_input_host)
  54. override;
  55. void CreateRenderWidgetHostNSView(
  56. uint64_t view_id,
  57. mojo::PendingAssociatedRemote<mojom::StubInterface> host,
  58. mojo::PendingAssociatedReceiver<mojom::StubInterface> view_receiver)
  59. override;
  60. void CreateWebContentsNSView(
  61. uint64_t view_id,
  62. mojo::PendingAssociatedRemote<mojom::StubInterface> host,
  63. mojo::PendingAssociatedReceiver<mojom::StubInterface> view_receiver)
  64. override;
  65. void ForwardCutCopyPaste(mojom::CutCopyPasteCommand command) override;
  66. static void ForwardCutCopyPasteToNSApp(mojom::CutCopyPasteCommand command);
  67. private:
  68. friend class base::NoDestructor<ApplicationBridge>;
  69. ApplicationBridge();
  70. ~ApplicationBridge() override;
  71. RenderWidgetHostNSViewCreateCallback render_widget_host_create_callback_;
  72. WebContentsNSViewCreateCallback web_conents_create_callback_;
  73. mojo::AssociatedReceiver<mojom::Application> receiver_{this};
  74. };
  75. } // namespace remote_cocoa
  76. #endif // COMPONENTS_REMOTE_COCOA_APP_SHIM_APPLICATION_BRIDGE_H_