File: application_bridge.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (100 lines) | stat: -rw-r--r-- 4,251 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_REMOTE_COCOA_APP_SHIM_APPLICATION_BRIDGE_H_
#define COMPONENTS_REMOTE_COCOA_APP_SHIM_APPLICATION_BRIDGE_H_

#include "base/no_destructor.h"
#include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h"
#include "components/remote_cocoa/common/alert.mojom.h"
#include "components/remote_cocoa/common/application.mojom.h"
#include "components/remote_cocoa/common/native_widget_ns_window.mojom.h"
#include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
#include "components/system_media_controls/mac/remote_cocoa/system_media_controls.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"

namespace system_media_controls {
class SystemMediaControlsBridge;
}  // namespace system_media_controls

namespace remote_cocoa {

// This class implements the remote_cocoa::mojom::Application interface, and
// bridges that C++ interface to the Objective-C NSApplication. This class is
// the root of all other remote_cocoa classes (e.g, NSAlerts, NSWindows,
// NSViews).
class REMOTE_COCOA_APP_SHIM_EXPORT ApplicationBridge
    : public mojom::Application {
 public:
  static ApplicationBridge* Get();
  void BindReceiver(
      mojo::PendingAssociatedReceiver<mojom::Application> receiver);

  // Set callbacks to create content types (content types cannot be created
  // in remote_cocoa).
  // TODO(crbug.com/40595042): Move these types from content to
  // remote_cocoa.
  using RenderWidgetHostNSViewCreateCallback = base::RepeatingCallback<void(
      uint64_t view_id,
      mojo::ScopedInterfaceEndpointHandle host_handle,
      mojo::ScopedInterfaceEndpointHandle view_request_handle)>;
  using WebContentsNSViewCreateCallback = base::RepeatingCallback<void(
      uint64_t view_id,
      mojo::ScopedInterfaceEndpointHandle host_handle,
      mojo::ScopedInterfaceEndpointHandle view_request_handle)>;
  void SetContentNSViewCreateCallbacks(
      RenderWidgetHostNSViewCreateCallback render_widget_host_create_callback,
      WebContentsNSViewCreateCallback web_contents_create_callback);

  // mojom::Application:
  void CreateAlert(
      mojo::PendingReceiver<mojom::AlertBridge> bridge_receiver) override;
  void CreateNativeWidgetNSWindow(
      uint64_t bridge_id,
      mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
          bridge_receiver,
      mojo::PendingAssociatedRemote<mojom::NativeWidgetNSWindowHost> host,
      mojo::PendingAssociatedRemote<mojom::TextInputHost> text_input_host)
      override;
  void CreateRenderWidgetHostNSView(
      uint64_t view_id,
      mojo::PendingAssociatedRemote<mojom::StubInterface> host,
      mojo::PendingAssociatedReceiver<mojom::StubInterface> view_receiver)
      override;
  void CreateSystemMediaControlsBridge(
      mojo::PendingReceiver<system_media_controls::mojom::SystemMediaControls>
          receiver,
      mojo::PendingRemote<
          system_media_controls::mojom::SystemMediaControlsObserver> host)
      override;
  void CreateWebContentsNSView(
      uint64_t view_id,
      mojo::PendingAssociatedRemote<mojom::StubInterface> host,
      mojo::PendingAssociatedReceiver<mojom::StubInterface> view_receiver)
      override;
  void ForwardCutCopyPaste(mojom::CutCopyPasteCommand command) override;

  static void ForwardCutCopyPasteToNSApp(mojom::CutCopyPasteCommand command);

 private:
  friend class base::NoDestructor<ApplicationBridge>;
  ApplicationBridge();
  ~ApplicationBridge() override;

  RenderWidgetHostNSViewCreateCallback render_widget_host_create_callback_;
  WebContentsNSViewCreateCallback web_contents_create_callback_;

  std::unique_ptr<system_media_controls::SystemMediaControlsBridge>
      system_media_controls_bridge_;

  mojo::AssociatedReceiver<mojom::Application> receiver_{this};
};

}  // namespace remote_cocoa

#endif  // COMPONENTS_REMOTE_COCOA_APP_SHIM_APPLICATION_BRIDGE_H_