| 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() : |
| 20 host_stub_(NULL), | 21 host_stub_(NULL), |
| 21 input_stub_(NULL) { | 22 input_stub_(NULL), |
| 23 connection_(NULL) { |
| 22 } | 24 } |
| 23 | 25 |
| 24 HostMessageDispatcher::~HostMessageDispatcher() { | 26 HostMessageDispatcher::~HostMessageDispatcher() { |
| 25 } | 27 } |
| 26 | 28 |
| 27 void HostMessageDispatcher::Initialize( | 29 void HostMessageDispatcher::Initialize( |
| 28 protocol::Session* session, | 30 protocol::ConnectionToClient* connection, |
| 29 HostStub* host_stub, InputStub* input_stub) { | 31 HostStub* host_stub, InputStub* input_stub) { |
| 32 connection_ = connection; |
| 33 |
| 34 protocol::Session* session = connection->session(); |
| 30 if (!session || !host_stub || !input_stub || | 35 if (!session || !host_stub || !input_stub || |
| 31 !session->event_channel() || !session->control_channel()) { | 36 !session->event_channel() || !session->control_channel()) { |
| 32 return; | 37 return; |
| 33 } | 38 } |
| 34 | 39 |
| 35 control_message_reader_.reset(new ProtobufMessageReader<ControlMessage>()); | 40 control_message_reader_.reset(new ProtobufMessageReader<ControlMessage>()); |
| 36 event_message_reader_.reset(new ProtobufMessageReader<EventMessage>()); | 41 event_message_reader_.reset(new ProtobufMessageReader<EventMessage>()); |
| 37 host_stub_ = host_stub; | 42 host_stub_ = host_stub; |
| 38 input_stub_ = input_stub; | 43 input_stub_ = input_stub; |
| 39 | 44 |
| 40 // Initialize the readers on the sockets provided by channels. | 45 // Initialize the readers on the sockets provided by channels. |
| 41 event_message_reader_->Init( | 46 event_message_reader_->Init( |
| 42 session->event_channel(), | 47 session->event_channel(), |
| 43 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); | 48 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); |
| 44 control_message_reader_->Init( | 49 control_message_reader_->Init( |
| 45 session->control_channel(), | 50 session->control_channel(), |
| 46 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); | 51 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); |
| 47 } | 52 } |
| 48 | 53 |
| 49 void HostMessageDispatcher::OnControlMessageReceived( | 54 void HostMessageDispatcher::OnControlMessageReceived( |
| 50 ControlMessage* message, Task* done_task) { | 55 ControlMessage* message, Task* done_task) { |
| 56 // BeginSessionRequest is always allowed. |
| 57 if (message->has_begin_session_request()) { |
| 58 host_stub_->BeginSessionRequest( |
| 59 connection_, &message->begin_session_request().credentials(), |
| 60 done_task); |
| 61 return; |
| 62 } |
| 51 if (!host_stub_->authenticated()) { | 63 if (!host_stub_->authenticated()) { |
| 52 // When the client has not authenticated with the host, we restrict the | 64 // When the client has not authenticated with the host, no other messages |
| 53 // control messages that we support. | 65 // are allowed. |
| 54 if (message->has_begin_session_request()) { | 66 LOG(WARNING) << "Invalid control message received " |
| 55 host_stub_->BeginSessionRequest( | 67 << "(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 { | 68 } else { |
| 63 // TODO(sergeyu): Add message validation. | 69 // TODO(sergeyu): Add message validation. |
| 64 if (message->has_suggest_resolution()) { | 70 if (message->has_suggest_resolution()) { |
| 65 host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); | 71 host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); |
| 66 return; | 72 return; |
| 67 } else if (message->has_begin_session_request()) { | |
| 68 LOG(WARNING) << "BeginSessionRequest sent after client already " | |
| 69 << "authorized."; | |
| 70 } else { | 73 } else { |
| 71 LOG(WARNING) << "Invalid control message received."; | 74 LOG(WARNING) << "Invalid control message received."; |
| 72 } | 75 } |
| 73 } | 76 } |
| 74 done_task->Run(); | 77 done_task->Run(); |
| 75 delete done_task; | 78 delete done_task; |
| 76 } | 79 } |
| 77 | 80 |
| 78 void HostMessageDispatcher::OnEventMessageReceived( | 81 void HostMessageDispatcher::OnEventMessageReceived( |
| 79 EventMessage* message, Task* done_task) { | 82 EventMessage* message, Task* done_task) { |
| 80 if (input_stub_->authenticated()) { | 83 if (input_stub_->authenticated()) { |
| 81 // TODO(sergeyu): Add message validation. | 84 // TODO(sergeyu): Add message validation. |
| 82 if (message->has_key_event()) { | 85 if (message->has_key_event()) { |
| 83 input_stub_->InjectKeyEvent(&message->key_event(), done_task); | 86 input_stub_->InjectKeyEvent(&message->key_event(), done_task); |
| 84 } else if (message->has_mouse_event()) { | 87 } else if (message->has_mouse_event()) { |
| 85 input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); | 88 input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); |
| 86 } else { | 89 } else { |
| 87 LOG(WARNING) << "Invalid event message received."; | 90 LOG(WARNING) << "Invalid event message received."; |
| 88 done_task->Run(); | 91 done_task->Run(); |
| 89 delete done_task; | 92 delete done_task; |
| 90 } | 93 } |
| 91 } | 94 } |
| 92 } | 95 } |
| 93 | 96 |
| 94 } // namespace protocol | 97 } // namespace protocol |
| 95 } // namespace remoting | 98 } // namespace remoting |
| OLD | NEW |