client_event_dispatcher.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/client_event_dispatcher.h"
  5. #include "base/time/time.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/message_pipe.h"
  12. namespace remoting {
  13. namespace protocol {
  14. ClientEventDispatcher::ClientEventDispatcher()
  15. : ChannelDispatcherBase(kEventChannelName) {}
  16. ClientEventDispatcher::~ClientEventDispatcher() = default;
  17. void ClientEventDispatcher::InjectKeyEvent(const KeyEvent& event) {
  18. DCHECK(event.has_usb_keycode());
  19. DCHECK(event.has_pressed());
  20. EventMessage message;
  21. message.set_timestamp(base::TimeTicks::Now().ToInternalValue());
  22. message.mutable_key_event()->CopyFrom(event);
  23. message_pipe()->Send(&message, {});
  24. }
  25. void ClientEventDispatcher::InjectTextEvent(const TextEvent& event) {
  26. DCHECK(event.has_text());
  27. EventMessage message;
  28. message.set_timestamp(base::TimeTicks::Now().ToInternalValue());
  29. message.mutable_text_event()->CopyFrom(event);
  30. message_pipe()->Send(&message, {});
  31. }
  32. void ClientEventDispatcher::InjectMouseEvent(const MouseEvent& event) {
  33. EventMessage message;
  34. message.set_timestamp(base::TimeTicks::Now().ToInternalValue());
  35. message.mutable_mouse_event()->CopyFrom(event);
  36. message_pipe()->Send(&message, {});
  37. }
  38. void ClientEventDispatcher::InjectTouchEvent(const TouchEvent& event) {
  39. EventMessage message;
  40. message.set_timestamp(base::TimeTicks::Now().ToInternalValue());
  41. message.mutable_touch_event()->CopyFrom(event);
  42. message_pipe()->Send(&message, {});
  43. }
  44. void ClientEventDispatcher::OnIncomingMessage(
  45. std::unique_ptr<CompoundBuffer> message) {
  46. LOG(ERROR) << "Received unexpected message on the event channel.";
  47. }
  48. } // namespace protocol
  49. } // namespace remoting