blob: 622a49a17713aa62bae4c29e951d0f9d302b2afb [file] [log] [blame]
[email protected]e265ad72012-03-16 17:28:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a07ef3d2011-11-18 01:31:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/protocol/host_control_dispatcher.h"
6
[email protected]1c232c22013-08-30 02:04:047#include "base/callback_helpers.h"
[email protected]2e8b52c2011-11-22 00:07:138#include "net/socket/stream_socket.h"
sergeyuf1005f62016-02-03 21:11:309#include "remoting/base/compound_buffer.h"
[email protected]2e8b52c2011-11-22 00:07:1310#include "remoting/base/constants.h"
[email protected]a07ef3d2011-11-18 01:31:4311#include "remoting/proto/control.pb.h"
12#include "remoting/proto/internal.pb.h"
[email protected]e265ad72012-03-16 17:28:0313#include "remoting/protocol/clipboard_stub.h"
[email protected]a07ef3d2011-11-18 01:31:4314#include "remoting/protocol/host_stub.h"
sergeyuf1005f62016-02-03 21:11:3015#include "remoting/protocol/message_pipe.h"
[email protected]b76a2742014-04-10 05:38:2616#include "remoting/protocol/message_serialization.h"
[email protected]a07ef3d2011-11-18 01:31:4317
18namespace remoting {
19namespace protocol {
20
21HostControlDispatcher::HostControlDispatcher()
sergeyud8af2ca2016-01-30 03:04:3622 : ChannelDispatcherBase(kControlChannelName) {}
Chris Watkins6fe52aa2017-11-28 03:24:0523HostControlDispatcher::~HostControlDispatcher() = default;
[email protected]a07ef3d2011-11-18 01:31:4324
[email protected]a5d181f2013-04-19 14:55:3725void HostControlDispatcher::SetCapabilities(
26 const Capabilities& capabilities) {
27 ControlMessage message;
28 message.mutable_capabilities()->CopyFrom(capabilities);
Evan Stade86dadf152020-03-16 20:06:3329 message_pipe()->Send(&message, {});
[email protected]a5d181f2013-04-19 14:55:3730}
31
[email protected]9ffa78a22013-05-10 04:35:1032void HostControlDispatcher::SetPairingResponse(
33 const PairingResponse& pairing_response) {
34 ControlMessage message;
35 message.mutable_pairing_response()->CopyFrom(pairing_response);
Evan Stade86dadf152020-03-16 20:06:3336 message_pipe()->Send(&message, {});
[email protected]9ffa78a22013-05-10 04:35:1037}
38
[email protected]09eabd65c2013-08-13 00:13:4839void HostControlDispatcher::DeliverHostMessage(
40 const ExtensionMessage& message) {
41 ControlMessage control_message;
42 control_message.mutable_extension_message()->CopyFrom(message);
Evan Stade86dadf152020-03-16 20:06:3343 message_pipe()->Send(&control_message, {});
[email protected]09eabd65c2013-08-13 00:13:4844}
45
sergeyu00a67b12016-04-01 00:07:0046void HostControlDispatcher::SetVideoLayout(const VideoLayout& layout) {
47 ControlMessage message;
48 message.mutable_video_layout()->CopyFrom(layout);
Evan Stade86dadf152020-03-16 20:06:3349 message_pipe()->Send(&message, {});
sergeyu00a67b12016-04-01 00:07:0050}
51
Yuwei Huangcf7fdff2020-05-04 19:46:4352void HostControlDispatcher::SetTransportInfo(
53 const TransportInfo& transport_info) {
54 ControlMessage message;
55 message.mutable_transport_info()->CopyFrom(transport_info);
56 message_pipe()->Send(&message, {});
57}
58
[email protected]ba6d1c2d2012-03-31 01:28:3859void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
60 ControlMessage message;
61 message.mutable_clipboard_event()->CopyFrom(event);
Erik Jensen8627e9e2019-07-30 19:29:2662 std::size_t message_size = message.ByteSizeLong();
63 if (message_size > max_message_size_) {
Erik Jensen839f33c2019-07-24 17:07:3464 // Better to drop the event than drop the connection, which can happen if
65 // the browser receives a message larger than it can handle.
Erik Jensen8627e9e2019-07-30 19:29:2666 LOG(WARNING) << "Clipboard message dropped because message size "
67 << message_size << " is larger than " << max_message_size_;
Erik Jensen839f33c2019-07-24 17:07:3468 return;
69 }
Evan Stade86dadf152020-03-16 20:06:3370 message_pipe()->Send(&message, {});
[email protected]ba6d1c2d2012-03-31 01:28:3871}
72
[email protected]d65e15bd2012-06-02 22:16:4173void HostControlDispatcher::SetCursorShape(
74 const CursorShapeInfo& cursor_shape) {
75 ControlMessage message;
76 message.mutable_cursor_shape()->CopyFrom(cursor_shape);
Jamie Walch07dd79b2019-09-27 02:42:4577 std::size_t message_size = message.ByteSizeLong();
78 if (message_size > max_message_size_) {
79 // Better to drop the event than drop the connection, which can happen if
80 // the browser receives a message larger than it can handle.
81 LOG(WARNING) << "Cursor message dropped because message size "
82 << message_size << " is larger than " << max_message_size_;
83 return;
84 }
Evan Stade86dadf152020-03-16 20:06:3385 message_pipe()->Send(&message, {});
[email protected]d65e15bd2012-06-02 22:16:4186}
87
Erik Jensenb8876672019-12-03 04:30:0588void HostControlDispatcher::SetKeyboardLayout(const KeyboardLayout& layout) {
89 ControlMessage message;
90 message.mutable_keyboard_layout()->CopyFrom(layout);
Evan Stade86dadf152020-03-16 20:06:3391 message_pipe()->Send(&message, {});
Erik Jensenb8876672019-12-03 04:30:0592}
93
sergeyud8af2ca2016-01-30 03:04:3694void HostControlDispatcher::OnIncomingMessage(
dcheng0765c492016-04-06 22:41:5395 std::unique_ptr<CompoundBuffer> buffer) {
[email protected]e265ad72012-03-16 17:28:0396 DCHECK(clipboard_stub_);
[email protected]a07ef3d2011-11-18 01:31:4397 DCHECK(host_stub_);
[email protected]e265ad72012-03-16 17:28:0398
dcheng0765c492016-04-06 22:41:5399 std::unique_ptr<ControlMessage> message =
sergeyud8af2ca2016-01-30 03:04:36100 ParseMessage<ControlMessage>(buffer.get());
101 if (!message)
102 return;
103
Jamie Walch56f354dd2018-05-22 21:59:57104 // TODO(sergeyu): Move message validation from the message handlers here.
[email protected]e265ad72012-03-16 17:28:03105 if (message->has_clipboard_event()) {
106 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
[email protected]48a8ca32013-02-13 04:31:01107 } else if (message->has_client_resolution()) {
sergeyu54624e12016-06-01 10:54:31108 const ClientResolution& resolution = message->client_resolution();
Jamie Walch56f354dd2018-05-22 21:59:57109 if ((resolution.has_dips_width() && resolution.dips_width() <= 0) ||
110 (resolution.has_dips_height() && resolution.dips_height() <= 0)) {
sergeyu54624e12016-06-01 10:54:31111 LOG(ERROR) << "Received invalid ClientResolution message.";
112 return;
113 }
114 host_stub_->NotifyClientResolution(resolution);
[email protected]50d71c72012-05-03 01:28:55115 } else if (message->has_video_control()) {
116 host_stub_->ControlVideo(message->video_control());
[email protected]f458bed2012-10-18 03:27:59117 } else if (message->has_audio_control()) {
118 host_stub_->ControlAudio(message->audio_control());
[email protected]a5d181f2013-04-19 14:55:37119 } else if (message->has_capabilities()) {
120 host_stub_->SetCapabilities(message->capabilities());
[email protected]9ffa78a22013-05-10 04:35:10121 } else if (message->has_pairing_request()) {
122 host_stub_->RequestPairing(message->pairing_request());
[email protected]09eabd65c2013-08-13 00:13:48123 } else if (message->has_extension_message()) {
124 host_stub_->DeliverClientMessage(message->extension_message());
Gary Kacmarcik0c56fda2019-01-17 03:10:12125 } else if (message->has_select_display()) {
126 host_stub_->SelectDesktopDisplay(message->select_display());
Yuwei Huangef530072020-06-19 02:33:44127 } else if (message->has_peer_connection_parameters()) {
128 host_stub_->ControlPeerConnection(message->peer_connection_parameters());
[email protected]e265ad72012-03-16 17:28:03129 } else {
130 LOG(WARNING) << "Unknown control message received.";
131 }
[email protected]a07ef3d2011-11-18 01:31:43132}
133
134} // namespace protocol
135} // namespace remoting