[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 2 | // 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] | 1c232c2 | 2013-08-30 02:04:04 | [diff] [blame] | 7 | #include "base/callback_helpers.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 8 | #include "net/socket/stream_socket.h" |
sergeyu | f1005f6 | 2016-02-03 21:11:30 | [diff] [blame] | 9 | #include "remoting/base/compound_buffer.h" |
[email protected] | 2e8b52c | 2011-11-22 00:07:13 | [diff] [blame] | 10 | #include "remoting/base/constants.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 11 | #include "remoting/proto/control.pb.h" |
12 | #include "remoting/proto/internal.pb.h" | ||||
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 13 | #include "remoting/protocol/clipboard_stub.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 14 | #include "remoting/protocol/host_stub.h" |
sergeyu | f1005f6 | 2016-02-03 21:11:30 | [diff] [blame] | 15 | #include "remoting/protocol/message_pipe.h" |
[email protected] | b76a274 | 2014-04-10 05:38:26 | [diff] [blame] | 16 | #include "remoting/protocol/message_serialization.h" |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 17 | |
18 | namespace remoting { | ||||
19 | namespace protocol { | ||||
20 | |||||
21 | HostControlDispatcher::HostControlDispatcher() | ||||
sergeyu | d8af2ca | 2016-01-30 03:04:36 | [diff] [blame] | 22 | : ChannelDispatcherBase(kControlChannelName) {} |
Chris Watkins | 6fe52aa | 2017-11-28 03:24:05 | [diff] [blame] | 23 | HostControlDispatcher::~HostControlDispatcher() = default; |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 24 | |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 25 | void HostControlDispatcher::SetCapabilities( |
26 | const Capabilities& capabilities) { | ||||
27 | ControlMessage message; | ||||
28 | message.mutable_capabilities()->CopyFrom(capabilities); | ||||
sergeyu | f1005f6 | 2016-02-03 21:11:30 | [diff] [blame] | 29 | message_pipe()->Send(&message, base::Closure()); |
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 30 | } |
31 | |||||
[email protected] | 9ffa78a2 | 2013-05-10 04:35:10 | [diff] [blame] | 32 | void HostControlDispatcher::SetPairingResponse( |
33 | const PairingResponse& pairing_response) { | ||||
34 | ControlMessage message; | ||||
35 | message.mutable_pairing_response()->CopyFrom(pairing_response); | ||||
sergeyu | f1005f6 | 2016-02-03 21:11:30 | [diff] [blame] | 36 | message_pipe()->Send(&message, base::Closure()); |
[email protected] | 9ffa78a2 | 2013-05-10 04:35:10 | [diff] [blame] | 37 | } |
38 | |||||
[email protected] | 09eabd65c | 2013-08-13 00:13:48 | [diff] [blame] | 39 | void HostControlDispatcher::DeliverHostMessage( |
40 | const ExtensionMessage& message) { | ||||
41 | ControlMessage control_message; | ||||
42 | control_message.mutable_extension_message()->CopyFrom(message); | ||||
sergeyu | f1005f6 | 2016-02-03 21:11:30 | [diff] [blame] | 43 | message_pipe()->Send(&control_message, base::Closure()); |
[email protected] | 09eabd65c | 2013-08-13 00:13:48 | [diff] [blame] | 44 | } |
45 | |||||
sergeyu | 00a67b1 | 2016-04-01 00:07:00 | [diff] [blame] | 46 | void 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] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 52 | void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) { |
53 | ControlMessage message; | ||||
54 | message.mutable_clipboard_event()->CopyFrom(event); | ||||
sergeyu | f1005f6 | 2016-02-03 21:11:30 | [diff] [blame] | 55 | message_pipe()->Send(&message, base::Closure()); |
[email protected] | ba6d1c2d | 2012-03-31 01:28:38 | [diff] [blame] | 56 | } |
57 | |||||
[email protected] | d65e15bd | 2012-06-02 22:16:41 | [diff] [blame] | 58 | void HostControlDispatcher::SetCursorShape( |
59 | const CursorShapeInfo& cursor_shape) { | ||||
60 | ControlMessage message; | ||||
61 | message.mutable_cursor_shape()->CopyFrom(cursor_shape); | ||||
sergeyu | f1005f6 | 2016-02-03 21:11:30 | [diff] [blame] | 62 | message_pipe()->Send(&message, base::Closure()); |
[email protected] | d65e15bd | 2012-06-02 22:16:41 | [diff] [blame] | 63 | } |
64 | |||||
sergeyu | d8af2ca | 2016-01-30 03:04:36 | [diff] [blame] | 65 | void HostControlDispatcher::OnIncomingMessage( |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 66 | std::unique_ptr<CompoundBuffer> buffer) { |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 67 | DCHECK(clipboard_stub_); |
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 68 | DCHECK(host_stub_); |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 69 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 70 | std::unique_ptr<ControlMessage> message = |
sergeyu | d8af2ca | 2016-01-30 03:04:36 | [diff] [blame] | 71 | ParseMessage<ControlMessage>(buffer.get()); |
72 | if (!message) | ||||
73 | return; | ||||
74 | |||||
Jamie Walch | 56f354dd | 2018-05-22 21:59:57 | [diff] [blame] | 75 | // TODO(sergeyu): Move message validation from the message handlers here. |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 76 | if (message->has_clipboard_event()) { |
77 | clipboard_stub_->InjectClipboardEvent(message->clipboard_event()); | ||||
[email protected] | 48a8ca3 | 2013-02-13 04:31:01 | [diff] [blame] | 78 | } else if (message->has_client_resolution()) { |
sergeyu | 54624e1 | 2016-06-01 10:54:31 | [diff] [blame] | 79 | const ClientResolution& resolution = message->client_resolution(); |
Jamie Walch | 56f354dd | 2018-05-22 21:59:57 | [diff] [blame] | 80 | if ((resolution.has_dips_width() && resolution.dips_width() <= 0) || |
81 | (resolution.has_dips_height() && resolution.dips_height() <= 0)) { | ||||
sergeyu | 54624e1 | 2016-06-01 10:54:31 | [diff] [blame] | 82 | LOG(ERROR) << "Received invalid ClientResolution message."; |
83 | return; | ||||
84 | } | ||||
85 | host_stub_->NotifyClientResolution(resolution); | ||||
[email protected] | 50d71c7 | 2012-05-03 01:28:55 | [diff] [blame] | 86 | } else if (message->has_video_control()) { |
87 | host_stub_->ControlVideo(message->video_control()); | ||||
[email protected] | f458bed | 2012-10-18 03:27:59 | [diff] [blame] | 88 | } else if (message->has_audio_control()) { |
89 | host_stub_->ControlAudio(message->audio_control()); | ||||
[email protected] | a5d181f | 2013-04-19 14:55:37 | [diff] [blame] | 90 | } else if (message->has_capabilities()) { |
91 | host_stub_->SetCapabilities(message->capabilities()); | ||||
[email protected] | 9ffa78a2 | 2013-05-10 04:35:10 | [diff] [blame] | 92 | } else if (message->has_pairing_request()) { |
93 | host_stub_->RequestPairing(message->pairing_request()); | ||||
[email protected] | 09eabd65c | 2013-08-13 00:13:48 | [diff] [blame] | 94 | } else if (message->has_extension_message()) { |
95 | host_stub_->DeliverClientMessage(message->extension_message()); | ||||
Gary Kacmarcik | 0c56fda | 2019-01-17 03:10:12 | [diff] [blame] | 96 | } else if (message->has_select_display()) { |
97 | host_stub_->SelectDesktopDisplay(message->select_display()); | ||||
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 98 | } else { |
99 | LOG(WARNING) << "Unknown control message received."; | ||||
100 | } | ||||
[email protected] | a07ef3d | 2011-11-18 01:31:43 | [diff] [blame] | 101 | } |
102 | |||||
103 | } // namespace protocol | ||||
104 | } // namespace remoting |