Skip to content

Commit

Permalink
Add Input injection methods to Chromoting Mojo interface
Browse files Browse the repository at this point in the history
This CL removes the input injection messages from our Chromoting IPC
messages file and implements them via our new Mojo interface.

The majority of this CL is the code needed to serialize and
deserialize the protobuf messages involved.  One quirk that I
encountered with this is that you can't have optional primitive
fields in a Mojo struct. I solved this by boxing the primitive
in a struct which I could declare as nullable in the message struct.
If there is a better or pre-existing mechanism, I'm happy to switch
to it.

Bug: b:178114059
Change-Id: Ib1e200f0b49483ef448757ca8b32d4781bc70718
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3287408
Commit-Queue: Joe Downing <joedow@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/main@{#948346}
  • Loading branch information
joedow-42 authored and Chromium LUCI CQ committed Dec 4, 2021
1 parent c8494f8 commit 6e8fa43
Show file tree
Hide file tree
Showing 10 changed files with 758 additions and 108 deletions.
20 changes: 0 additions & 20 deletions remoting/host/chromoting_messages.h
Expand Up @@ -227,26 +227,6 @@ IPC_MESSAGE_CONTROL(ChromotingNetworkDesktopMsg_CaptureFrame)
IPC_MESSAGE_CONTROL(ChromotingNetworkDesktopMsg_SelectSource,
int /* desktop_display_id */)

// Carries a keyboard event from the client to the desktop session agent.
// |serialized_event| is a serialized protocol::KeyEvent.
IPC_MESSAGE_CONTROL(ChromotingNetworkDesktopMsg_InjectKeyEvent,
std::string /* serialized_event */)

// Carries a keyboard event from the client to the desktop session agent.
// |serialized_event| is a serialized protocol::TextEvent.
IPC_MESSAGE_CONTROL(ChromotingNetworkDesktopMsg_InjectTextEvent,
std::string /* serialized_event */)

// Carries a mouse event from the client to the desktop session agent.
// |serialized_event| is a serialized protocol::MouseEvent.
IPC_MESSAGE_CONTROL(ChromotingNetworkDesktopMsg_InjectMouseEvent,
std::string /* serialized_event */)

// Carries a touch event from the client to the desktop session agent.
// |serialized_event| is a serialized protocol::TouchEvent.
IPC_MESSAGE_CONTROL(ChromotingNetworkDesktopMsg_InjectTouchEvent,
std::string /* serialized_event */)

// Changes the screen resolution in the desktop session.
IPC_MESSAGE_CONTROL(ChromotingNetworkDesktopMsg_SetScreenResolution,
remoting::ScreenResolution /* resolution */)
Expand Down
44 changes: 4 additions & 40 deletions remoting/host/desktop_session_agent.cc
Expand Up @@ -243,14 +243,6 @@ bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) {
OnCaptureFrame)
IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SelectSource,
OnSelectSource)
IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectKeyEvent,
OnInjectKeyEvent)
IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectTextEvent,
OnInjectTextEvent)
IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectMouseEvent,
OnInjectMouseEvent)
IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectTouchEvent,
OnInjectTouchEvent)
IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_ExecuteActionRequest,
OnExecuteActionRequestEvent)
IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SetScreenResolution,
Expand Down Expand Up @@ -647,16 +639,9 @@ void DesktopSessionAgent::InjectClipboardEvent(
input_injector_->InjectClipboardEvent(event);
}

void DesktopSessionAgent::OnInjectKeyEvent(
const std::string& serialized_event) {
void DesktopSessionAgent::InjectKeyEvent(const protocol::KeyEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

protocol::KeyEvent event;
if (!event.ParseFromString(serialized_event)) {
LOG(ERROR) << "Failed to parse protocol::KeyEvent.";
return;
}

// InputStub implementations must verify events themselves, so we need only
// basic verification here. This matches HostEventDispatcher.
if (!event.has_usb_keycode() || !event.has_pressed()) {
Expand All @@ -667,16 +652,9 @@ void DesktopSessionAgent::OnInjectKeyEvent(
remote_input_filter_->InjectKeyEvent(event);
}

void DesktopSessionAgent::OnInjectTextEvent(
const std::string& serialized_event) {
void DesktopSessionAgent::InjectTextEvent(const protocol::TextEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

protocol::TextEvent event;
if (!event.ParseFromString(serialized_event)) {
LOG(ERROR) << "Failed to parse protocol::TextEvent.";
return;
}

// InputStub implementations must verify events themselves, so we need only
// basic verification here. This matches HostEventDispatcher.
if (!event.has_text()) {
Expand All @@ -687,16 +665,9 @@ void DesktopSessionAgent::OnInjectTextEvent(
remote_input_filter_->InjectTextEvent(event);
}

void DesktopSessionAgent::OnInjectMouseEvent(
const std::string& serialized_event) {
void DesktopSessionAgent::InjectMouseEvent(const protocol::MouseEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

protocol::MouseEvent event;
if (!event.ParseFromString(serialized_event)) {
LOG(ERROR) << "Failed to parse protocol::MouseEvent.";
return;
}

if (video_capturer_)
video_capturer_->SetComposeEnabled(event.has_delta_x() ||
event.has_delta_y());
Expand All @@ -706,16 +677,9 @@ void DesktopSessionAgent::OnInjectMouseEvent(
remote_input_filter_->InjectMouseEvent(event);
}

void DesktopSessionAgent::OnInjectTouchEvent(
const std::string& serialized_event) {
void DesktopSessionAgent::InjectTouchEvent(const protocol::TouchEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

protocol::TouchEvent event;
if (!event.ParseFromString(serialized_event)) {
LOG(ERROR) << "Failed to parse protocol::TouchEvent.";
return;
}

remote_input_filter_->InjectTouchEvent(event);
}

Expand Down
8 changes: 4 additions & 4 deletions remoting/host/desktop_session_agent.h
Expand Up @@ -133,6 +133,10 @@ class DesktopSessionAgent

// mojom::DesktopSessionControl implementation.
void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
void InjectKeyEvent(const protocol::KeyEvent& event) override;
void InjectMouseEvent(const protocol::MouseEvent& event) override;
void InjectTextEvent(const protocol::TextEvent& event) override;
void InjectTouchEvent(const protocol::TouchEvent& event) override;
void SetUpUrlForwarder() override;

// Creates desktop integration components and a connected IPC channel to be
Expand Down Expand Up @@ -169,10 +173,6 @@ class DesktopSessionAgent
void OnSelectSource(int id);

// Handles event executor requests from the client.
void OnInjectKeyEvent(const std::string& serialized_event);
void OnInjectTextEvent(const std::string& serialized_event);
void OnInjectMouseEvent(const std::string& serialized_event);
void OnInjectTouchEvent(const std::string& serialized_event);
void OnExecuteActionRequestEvent(const protocol::ActionRequest& request);

// Handles keyboard layout changes.
Expand Down
36 changes: 8 additions & 28 deletions remoting/host/desktop_session_proxy.cc
Expand Up @@ -418,53 +418,33 @@ void DesktopSessionProxy::InjectClipboardEvent(
void DesktopSessionProxy::InjectKeyEvent(const protocol::KeyEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

std::string serialized_event;
if (!event.SerializeToString(&serialized_event)) {
LOG(ERROR) << "Failed to serialize protocol::KeyEvent.";
return;
if (desktop_session_control_) {
desktop_session_control_->InjectKeyEvent(event);
}

SendToDesktop(
new ChromotingNetworkDesktopMsg_InjectKeyEvent(serialized_event));
}

void DesktopSessionProxy::InjectTextEvent(const protocol::TextEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

std::string serialized_event;
if (!event.SerializeToString(&serialized_event)) {
LOG(ERROR) << "Failed to serialize protocol::TextEvent.";
return;
if (desktop_session_control_) {
desktop_session_control_->InjectTextEvent(event);
}

SendToDesktop(
new ChromotingNetworkDesktopMsg_InjectTextEvent(serialized_event));
}

void DesktopSessionProxy::InjectMouseEvent(const protocol::MouseEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

std::string serialized_event;
if (!event.SerializeToString(&serialized_event)) {
LOG(ERROR) << "Failed to serialize protocol::MouseEvent.";
return;
if (desktop_session_control_) {
desktop_session_control_->InjectMouseEvent(event);
}

SendToDesktop(
new ChromotingNetworkDesktopMsg_InjectMouseEvent(serialized_event));
}

void DesktopSessionProxy::InjectTouchEvent(const protocol::TouchEvent& event) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());

std::string serialized_event;
if (!event.SerializeToString(&serialized_event)) {
LOG(ERROR) << "Failed to serialize protocol::TouchEvent.";
return;
if (desktop_session_control_) {
desktop_session_control_->InjectTouchEvent(event);
}

SendToDesktop(
new ChromotingNetworkDesktopMsg_InjectTouchEvent(serialized_event));
}

void DesktopSessionProxy::StartInputInjector(
Expand Down
51 changes: 36 additions & 15 deletions remoting/host/mojom/BUILD.gn
Expand Up @@ -14,10 +14,12 @@ mojom("mojom") {
"remoting_host.mojom",
"testing.mojom",
"webauthn_proxy.mojom",
"wrapped_primitives.mojom",
]

deps = [
"//mojo/public/mojom/base",
"//ui/gfx/geometry/mojom",
"//url/mojom:url_mojom_gurl",
]

Expand All @@ -28,23 +30,42 @@ mojom("mojom") {
mojom = "remoting.mojom.ClipboardEvent"
cpp = "::remoting::protocol::ClipboardEvent"
},
{
mojom = "remoting.mojom.KeyEvent"
cpp = "::remoting::protocol::KeyEvent"
},
{
mojom = "remoting.mojom.MouseButton"
cpp = "::remoting::protocol::MouseEvent::MouseButton"
},
{
mojom = "remoting.mojom.MouseEvent"
cpp = "::remoting::protocol::MouseEvent"
},
{
mojom = "remoting.mojom.TextEvent"
cpp = "::remoting::protocol::TextEvent"
},
{
mojom = "remoting.mojom.TouchEvent"
cpp = "::remoting::protocol::TouchEvent"
},
{
mojom = "remoting.mojom.TouchEventPoint"
cpp = "::remoting::protocol::TouchEventPoint"
},
{
mojom = "remoting.mojom.TouchEventType"
cpp = "::remoting::protocol::TouchEvent::TouchEventType"
},
]
traits_headers = [ "remoting_mojom_traits.h" ]
traits_public_deps = [ ":mojom_traits" ]
traits_sources = [ "remoting_mojom_traits.cc" ]
traits_public_deps = [
"//mojo/public/cpp/base:shared_typemap_traits",
"//mojo/public/cpp/bindings",
"//remoting/proto",
]
},
]
}

source_set("mojom_traits") {
sources = [
"remoting_mojom_traits.cc",
"remoting_mojom_traits.h",
]

public_deps = [
":mojom_shared_cpp_sources",
"//mojo/public/cpp/base:shared_typemap_traits",
"//mojo/public/cpp/bindings",
"//remoting/proto",
]
}

0 comments on commit 6e8fa43

Please sign in to comment.