blob: 7f3ea272e1affdf4c0aa8281ce3834115fe84815 [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) {}
23HostControlDispatcher::~HostControlDispatcher() {}
[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
[email protected]e265ad72012-03-16 17:28:0375 if (message->has_clipboard_event()) {
76 clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
[email protected]48a8ca32013-02-13 04:31:0177 } else if (message->has_client_resolution()) {
78 host_stub_->NotifyClientResolution(message->client_resolution());
[email protected]50d71c72012-05-03 01:28:5579 } else if (message->has_video_control()) {
80 host_stub_->ControlVideo(message->video_control());
[email protected]f458bed2012-10-18 03:27:5981 } else if (message->has_audio_control()) {
82 host_stub_->ControlAudio(message->audio_control());
[email protected]a5d181f2013-04-19 14:55:3783 } else if (message->has_capabilities()) {
84 host_stub_->SetCapabilities(message->capabilities());
[email protected]9ffa78a22013-05-10 04:35:1085 } else if (message->has_pairing_request()) {
86 host_stub_->RequestPairing(message->pairing_request());
[email protected]09eabd65c2013-08-13 00:13:4887 } else if (message->has_extension_message()) {
88 host_stub_->DeliverClientMessage(message->extension_message());
[email protected]e265ad72012-03-16 17:28:0389 } else {
90 LOG(WARNING) << "Unknown control message received.";
91 }
[email protected]a07ef3d2011-11-18 01:31:4392}
93
94} // namespace protocol
95} // namespace remoting