OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/ref_counted.h" | 5 #include "base/ref_counted.h" |
6 #include "net/base/io_buffer.h" | 6 #include "net/base/io_buffer.h" |
7 #include "remoting/proto/control.pb.h" | 7 #include "remoting/proto/control.pb.h" |
8 #include "remoting/proto/event.pb.h" | 8 #include "remoting/proto/event.pb.h" |
9 #include "remoting/proto/internal.pb.h" | 9 #include "remoting/proto/internal.pb.h" |
| 10 #include "remoting/protocol/connection_to_client.h" |
10 #include "remoting/protocol/host_message_dispatcher.h" | 11 #include "remoting/protocol/host_message_dispatcher.h" |
11 #include "remoting/protocol/host_stub.h" | 12 #include "remoting/protocol/host_stub.h" |
12 #include "remoting/protocol/input_stub.h" | 13 #include "remoting/protocol/input_stub.h" |
13 #include "remoting/protocol/message_reader.h" | 14 #include "remoting/protocol/message_reader.h" |
14 #include "remoting/protocol/session.h" | 15 #include "remoting/protocol/session.h" |
15 | 16 |
16 namespace remoting { | 17 namespace remoting { |
17 namespace protocol { | 18 namespace protocol { |
18 | 19 |
19 HostMessageDispatcher::HostMessageDispatcher() : | 20 HostMessageDispatcher::HostMessageDispatcher() : |
(...skipping 21 matching lines...) Expand all Loading... |
41 event_message_reader_->Init( | 42 event_message_reader_->Init( |
42 session->event_channel(), | 43 session->event_channel(), |
43 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); | 44 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); |
44 control_message_reader_->Init( | 45 control_message_reader_->Init( |
45 session->control_channel(), | 46 session->control_channel(), |
46 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); | 47 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); |
47 } | 48 } |
48 | 49 |
49 void HostMessageDispatcher::OnControlMessageReceived( | 50 void HostMessageDispatcher::OnControlMessageReceived( |
50 ControlMessage* message, Task* done_task) { | 51 ControlMessage* message, Task* done_task) { |
| 52 // BeginSessionRequest is always allowed. |
| 53 if (message->has_begin_session_request()) { |
| 54 host_stub_->BeginSessionRequest( |
| 55 &message->begin_session_request().credentials(), done_task); |
| 56 return; |
| 57 } |
51 if (!host_stub_->authenticated()) { | 58 if (!host_stub_->authenticated()) { |
52 // When the client has not authenticated with the host, we restrict the | 59 // When the client has not authenticated with the host, no other messages |
53 // control messages that we support. | 60 // are allowed. |
54 if (message->has_begin_session_request()) { | 61 LOG(WARNING) << "Invalid control message received " |
55 host_stub_->BeginSessionRequest( | 62 << "(client not authenticated)."; |
56 &message->begin_session_request().credentials(), done_task); | |
57 return; | |
58 } else { | |
59 LOG(WARNING) << "Invalid control message received " | |
60 << "(client not authenticated)."; | |
61 } | |
62 } else { | 63 } else { |
63 // TODO(sergeyu): Add message validation. | 64 // TODO(sergeyu): Add message validation. |
64 if (message->has_suggest_resolution()) { | 65 if (message->has_suggest_resolution()) { |
65 host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); | 66 host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); |
66 return; | 67 return; |
67 } else if (message->has_begin_session_request()) { | |
68 LOG(WARNING) << "BeginSessionRequest sent after client already " | |
69 << "authorized."; | |
70 } else { | 68 } else { |
71 LOG(WARNING) << "Invalid control message received."; | 69 LOG(WARNING) << "Invalid control message received."; |
72 } | 70 } |
73 } | 71 } |
74 done_task->Run(); | 72 done_task->Run(); |
75 delete done_task; | 73 delete done_task; |
76 } | 74 } |
77 | 75 |
78 void HostMessageDispatcher::OnEventMessageReceived( | 76 void HostMessageDispatcher::OnEventMessageReceived( |
79 EventMessage* message, Task* done_task) { | 77 EventMessage* message, Task* done_task) { |
80 if (input_stub_->authenticated()) { | 78 if (input_stub_->authenticated()) { |
81 // TODO(sergeyu): Add message validation. | 79 // TODO(sergeyu): Add message validation. |
82 if (message->has_key_event()) { | 80 if (message->has_key_event()) { |
83 input_stub_->InjectKeyEvent(&message->key_event(), done_task); | 81 input_stub_->InjectKeyEvent(&message->key_event(), done_task); |
84 } else if (message->has_mouse_event()) { | 82 } else if (message->has_mouse_event()) { |
85 input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); | 83 input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); |
86 } else { | 84 } else { |
87 LOG(WARNING) << "Invalid event message received."; | 85 LOG(WARNING) << "Invalid event message received."; |
88 done_task->Run(); | 86 done_task->Run(); |
89 delete done_task; | 87 delete done_task; |
90 } | 88 } |
91 } | 89 } |
92 } | 90 } |
93 | 91 |
94 } // namespace protocol | 92 } // namespace protocol |
95 } // namespace remoting | 93 } // namespace remoting |
OLD | NEW |