File: mojo_render_input_router_delegate_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (81 lines) | stat: -rw-r--r-- 3,563 bytes parent folder | download | duplicates (4)
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_MOJO_RENDER_INPUT_ROUTER_DELEGATE_IMPL_H_
#define CONTENT_BROWSER_RENDERER_HOST_MOJO_RENDER_INPUT_ROUTER_DELEGATE_IMPL_H_

#include <memory>

#include "base/memory/scoped_refptr.h"
#include "components/input/render_input_router.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/blink/public/common/input/web_coalesced_input_event.h"
#include "third_party/blink/public/mojom/input/input_event_result.mojom-shared.h"

namespace content {

class RenderWidgetHostImpl;

// This class is owned by RenderWidgetHostImpl and its lifetime is directly tied
// to the RenderWidgetHostImpl instance that creates it. This class encapsulates
// the mojo-specific communication logic for syncing input handling related
// state, acting as an intermediary between the RenderWidgetHostImpl (on the
// CrBrowserMain thread) and the InputManager (on the VizCompositorThread). See
// mojo interfaces `RenderInputRouterDelegate` and
// `RenderInputRouterDelegateClient` for relevant state syncing methods.
class MojoRenderInputRouterDelegateImpl
    : public input::mojom::RenderInputRouterDelegateClient {
 public:
  explicit MojoRenderInputRouterDelegateImpl(RenderWidgetHostImpl* host);

  ~MojoRenderInputRouterDelegateImpl() override;

  // Sets up RenderInputRouterDelegate mojo connections with InputManager on
  // the VizCompositorThread for input handling with InputVizard.
  void SetupRenderInputRouterDelegateConnection();

  // Get remote for making calls to RenderInputRouterDelegate interface. Returns
  // nullptr if the remote is not bound yet. The mojo connection is setup when
  // layer tree frame sinks from renderer are being requested (see
  // RenderWidgetHostImpl::CreateFrameSink). This connection is setup before
  // input handling starts on VizCompositorThread for its corresponding
  // `frame_sink_id`.
  input::mojom::RenderInputRouterDelegate* GetRenderInputRouterDelegateRemote();

  // input::mojom::RenderInputRouterDelegateClient overrides.
  void NotifyObserversOfInputEvent(
      std::unique_ptr<blink::WebCoalescedInputEvent> event,
      bool dispatched_to_renderer) override;
  void NotifyObserversOfInputEventAcks(
      blink::mojom::InputEventResultSource ack_source,
      blink::mojom::InputEventResultState ack_result,
      std::unique_ptr<blink::WebCoalescedInputEvent> event) override;
  void OnInvalidInputEventSource() override;
  void StateOnOverscrollTransfer(
      blink::mojom::DidOverscrollParamsPtr params) override;
  void RendererInputResponsivenessChanged(
      bool is_responsive,
      std::optional<base::TimeTicks> ack_timeout_ts) override;

  void SetRenderInputRouterDelegateRemoteForTesting(
      mojo::PendingAssociatedRemote<input::mojom::RenderInputRouterDelegate>
          remote) {
    rir_delegate_remote_.Bind(std::move(remote));
  }

 private:
  mojo::AssociatedReceiver<input::mojom::RenderInputRouterDelegateClient>
      rir_delegate_client_receiver_{this};
  mojo::AssociatedRemote<input::mojom::RenderInputRouterDelegate>
      rir_delegate_remote_;

  // It is safe to use `raw_ref` here since RenderWidgetHostImpl owns this class
  // and is bound to outlive |this|.
  raw_ref<RenderWidgetHostImpl> host_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_MOJO_RENDER_INPUT_ROUTER_DELEGATE_IMPL_H_