host_event_dispatcher.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/protocol/host_event_dispatcher.h"
  5. #include "base/memory/ref_counted.h"
  6. #include "net/socket/stream_socket.h"
  7. #include "remoting/base/compound_buffer.h"
  8. #include "remoting/base/constants.h"
  9. #include "remoting/proto/event.pb.h"
  10. #include "remoting/proto/internal.pb.h"
  11. #include "remoting/protocol/input_stub.h"
  12. #include "remoting/protocol/message_serialization.h"
  13. namespace remoting {
  14. namespace protocol {
  15. HostEventDispatcher::HostEventDispatcher()
  16. : ChannelDispatcherBase(kEventChannelName),
  17. event_timestamps_source_(new InputEventTimestampsSourceImpl()) {}
  18. HostEventDispatcher::~HostEventDispatcher() = default;
  19. void HostEventDispatcher::OnIncomingMessage(
  20. std::unique_ptr<CompoundBuffer> buffer) {
  21. DCHECK(input_stub_);
  22. std::unique_ptr<EventMessage> message =
  23. ParseMessage<EventMessage>(buffer.get());
  24. if (!message)
  25. return;
  26. event_timestamps_source_->OnEventReceived(InputEventTimestamps{
  27. base::TimeTicks::FromInternalValue(message->timestamp()),
  28. base::TimeTicks::Now()});
  29. if (message->has_key_event()) {
  30. const KeyEvent& event = message->key_event();
  31. if (event.has_usb_keycode() && event.has_pressed()) {
  32. input_stub_->InjectKeyEvent(event);
  33. } else {
  34. LOG(WARNING) << "Received invalid key event.";
  35. }
  36. } else if (message->has_text_event()) {
  37. const TextEvent& event = message->text_event();
  38. if (event.has_text()) {
  39. input_stub_->InjectTextEvent(event);
  40. } else {
  41. LOG(WARNING) << "Received invalid text event.";
  42. }
  43. } else if (message->has_mouse_event()) {
  44. input_stub_->InjectMouseEvent(message->mouse_event());
  45. } else if (message->has_touch_event()) {
  46. input_stub_->InjectTouchEvent(message->touch_event());
  47. } else {
  48. LOG(WARNING) << "Unknown event message received.";
  49. }
  50. }
  51. } // namespace protocol
  52. } // namespace remoting