blob: 2b86a9fa89c30171f52c7c2d1d0d98a776645dff [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);
sergeyuf1005f62016-02-03 21:11:3029 message_pipe()->Send(&message, base::Closure());
[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);
sergeyuf1005f62016-02-03 21:11:3036 message_pipe()->Send(&message, base::Closure());
[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);
sergeyuf1005f62016-02-03 21:11:3043 message_pipe()->Send(&control_message, base::Closure());
[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);
49 message_pipe()->Send(&message, base::Closure());
50}
51
[email protected]ba6d1c2d2012-03-31 01:28:3852void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
53 ControlMessage message;
54 message.mutable_clipboard_event()->CopyFrom(event);
sergeyuf1005f62016-02-03 21:11:3055 message_pipe()->Send(&message, base::Closure());
[email protected]ba6d1c2d2012-03-31 01:28:3856}
57
[email protected]d65e15bd2012-06-02 22:16:4158void HostControlDispatcher::SetCursorShape(
59 const CursorShapeInfo& cursor_shape) {
60 ControlMessage message;
61 message.mutable_cursor_shape()->CopyFrom(cursor_shape);
sergeyuf1005f62016-02-03 21:11:3062 message_pipe()->Send(&message, base::Closure());
[email protected]d65e15bd2012-06-02 22:16:4163}
64
sergeyud8af2ca2016-01-30 03:04:3665void HostControlDispatcher::OnIncomingMessage(
dcheng0765c492016-04-06 22:41:5366 std::unique_ptr<CompoundBuffer> buffer) {
[email protected]e265ad72012-03-16 17:28:0367 DCHECK(clipboard_stub_);
[email protected]a07ef3d2011-11-18 01:31:4368 DCHECK(host_stub_);
[email protected]e265ad72012-03-16 17:28:0369
dcheng0765c492016-04-06 22:41:5370 std::unique_ptr<ControlMessage> message =
sergeyud8af2ca2016-01-30 03:04:3671 ParseMessage<ControlMessage>(buffer.get());
72 if (!message)
73 return;
74
Jamie Walch56f354dd2018-05-22 21:59:5775 // TODO(sergeyu): Move message validation from the message handlers here.
[email protected]e265ad72012-03-16 17:28:0376 if (message->has_clipboard_event()) {
77 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
[email protected]48a8ca32013-02-13 04:31:0178 } else if (message->has_client_resolution()) {
sergeyu54624e12016-06-01 10:54:3179 const ClientResolution& resolution = message->client_resolution();
Jamie Walch56f354dd2018-05-22 21:59:5780 if ((resolution.has_dips_width() && resolution.dips_width() <= 0) ||
81 (resolution.has_dips_height() && resolution.dips_height() <= 0)) {
sergeyu54624e12016-06-01 10:54:3182 LOG(ERROR) << "Received invalid ClientResolution message.";
83 return;
84 }
85 host_stub_->NotifyClientResolution(resolution);
[email protected]50d71c72012-05-03 01:28:5586 } else if (message->has_video_control()) {
87 host_stub_->ControlVideo(message->video_control());
[email protected]f458bed2012-10-18 03:27:5988 } else if (message->has_audio_control()) {
89 host_stub_->ControlAudio(message->audio_control());
[email protected]a5d181f2013-04-19 14:55:3790 } else if (message->has_capabilities()) {
91 host_stub_->SetCapabilities(message->capabilities());
[email protected]9ffa78a22013-05-10 04:35:1092 } else if (message->has_pairing_request()) {
93 host_stub_->RequestPairing(message->pairing_request());
[email protected]09eabd65c2013-08-13 00:13:4894 } else if (message->has_extension_message()) {
95 host_stub_->DeliverClientMessage(message->extension_message());
Gary Kacmarcik0c56fda2019-01-17 03:10:1296 } else if (message->has_select_display()) {
97 host_stub_->SelectDesktopDisplay(message->select_display());
[email protected]e265ad72012-03-16 17:28:0398 } else {
99 LOG(WARNING) << "Unknown control message received.";
100 }
[email protected]a07ef3d2011-11-18 01:31:43101}
102
103} // namespace protocol
104} // namespace remoting