fake_desktop_environment.cc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright 2014 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/host/fake_desktop_environment.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "base/memory/weak_ptr.h"
  8. #include "remoting/host/audio_capturer.h"
  9. #include "remoting/host/desktop_capturer_proxy.h"
  10. #include "remoting/host/desktop_display_info_monitor.h"
  11. #include "remoting/host/fake_keyboard_layout_monitor.h"
  12. #include "remoting/host/file_transfer/file_operations.h"
  13. #include "remoting/host/input_injector.h"
  14. #include "remoting/host/keyboard_layout_monitor.h"
  15. #include "remoting/host/remote_open_url/fake_url_forwarder_configurator.h"
  16. #include "remoting/host/remote_open_url/url_forwarder_configurator.h"
  17. #include "remoting/proto/event.pb.h"
  18. #include "remoting/protocol/fake_desktop_capturer.h"
  19. namespace remoting {
  20. FakeInputInjector::FakeInputInjector() {}
  21. FakeInputInjector::~FakeInputInjector() = default;
  22. void FakeInputInjector::Start(
  23. std::unique_ptr<protocol::ClipboardStub> client_clipboard) {}
  24. void FakeInputInjector::InjectKeyEvent(const protocol::KeyEvent& event) {
  25. if (key_events_)
  26. key_events_->push_back(event);
  27. }
  28. void FakeInputInjector::InjectTextEvent(const protocol::TextEvent& event) {
  29. if (text_events_)
  30. text_events_->push_back(event);
  31. }
  32. void FakeInputInjector::InjectMouseEvent(const protocol::MouseEvent& event) {
  33. if (mouse_events_)
  34. mouse_events_->push_back(event);
  35. }
  36. void FakeInputInjector::InjectTouchEvent(const protocol::TouchEvent& event) {
  37. if (touch_events_)
  38. touch_events_->push_back(event);
  39. }
  40. void FakeInputInjector::InjectClipboardEvent(
  41. const protocol::ClipboardEvent& event) {
  42. if (clipboard_events_)
  43. clipboard_events_->push_back(event);
  44. }
  45. FakeScreenControls::FakeScreenControls() = default;
  46. FakeScreenControls::~FakeScreenControls() = default;
  47. void FakeScreenControls::SetScreenResolution(
  48. const ScreenResolution& resolution,
  49. absl::optional<webrtc::ScreenId> screen_id) {}
  50. FakeDesktopEnvironment::FakeDesktopEnvironment(
  51. scoped_refptr<base::SingleThreadTaskRunner> capture_thread,
  52. const DesktopEnvironmentOptions& options)
  53. : capture_thread_(std::move(capture_thread)), options_(options) {}
  54. FakeDesktopEnvironment::~FakeDesktopEnvironment() = default;
  55. // DesktopEnvironment implementation.
  56. std::unique_ptr<ActionExecutor> FakeDesktopEnvironment::CreateActionExecutor() {
  57. return nullptr;
  58. }
  59. std::unique_ptr<AudioCapturer> FakeDesktopEnvironment::CreateAudioCapturer() {
  60. return nullptr;
  61. }
  62. std::unique_ptr<InputInjector> FakeDesktopEnvironment::CreateInputInjector() {
  63. std::unique_ptr<FakeInputInjector> result(new FakeInputInjector());
  64. last_input_injector_ = result->weak_factory_.GetWeakPtr();
  65. return std::move(result);
  66. }
  67. std::unique_ptr<ScreenControls> FakeDesktopEnvironment::CreateScreenControls() {
  68. return std::make_unique<FakeScreenControls>();
  69. }
  70. std::unique_ptr<DesktopCapturer> FakeDesktopEnvironment::CreateVideoCapturer() {
  71. auto fake_capturer = std::make_unique<protocol::FakeDesktopCapturer>();
  72. if (!frame_generator_.is_null())
  73. fake_capturer->set_frame_generator(frame_generator_);
  74. auto result =
  75. std::make_unique<DesktopCapturerProxy>(capture_thread_, capture_thread_);
  76. result->set_capturer(std::move(fake_capturer));
  77. return std::move(result);
  78. }
  79. DesktopDisplayInfoMonitor* FakeDesktopEnvironment::GetDisplayInfoMonitor() {
  80. return nullptr;
  81. }
  82. std::unique_ptr<webrtc::MouseCursorMonitor>
  83. FakeDesktopEnvironment::CreateMouseCursorMonitor() {
  84. return std::make_unique<FakeMouseCursorMonitor>();
  85. }
  86. std::unique_ptr<KeyboardLayoutMonitor>
  87. FakeDesktopEnvironment::CreateKeyboardLayoutMonitor(
  88. base::RepeatingCallback<void(const protocol::KeyboardLayout&)> callback) {
  89. return std::make_unique<FakeKeyboardLayoutMonitor>();
  90. }
  91. std::unique_ptr<FileOperations> FakeDesktopEnvironment::CreateFileOperations() {
  92. return nullptr;
  93. }
  94. std::unique_ptr<UrlForwarderConfigurator>
  95. FakeDesktopEnvironment::CreateUrlForwarderConfigurator() {
  96. return std::make_unique<FakeUrlForwarderConfigurator>();
  97. }
  98. std::string FakeDesktopEnvironment::GetCapabilities() const {
  99. return std::string();
  100. }
  101. void FakeDesktopEnvironment::SetCapabilities(const std::string& capabilities) {}
  102. uint32_t FakeDesktopEnvironment::GetDesktopSessionId() const {
  103. return desktop_session_id_;
  104. }
  105. std::unique_ptr<DesktopAndCursorConditionalComposer>
  106. FakeDesktopEnvironment::CreateComposingVideoCapturer() {
  107. return nullptr;
  108. }
  109. std::unique_ptr<RemoteWebAuthnStateChangeNotifier>
  110. FakeDesktopEnvironment::CreateRemoteWebAuthnStateChangeNotifier() {
  111. return nullptr;
  112. }
  113. const DesktopEnvironmentOptions& FakeDesktopEnvironment::options() const {
  114. return options_;
  115. }
  116. FakeDesktopEnvironmentFactory::FakeDesktopEnvironmentFactory(
  117. scoped_refptr<base::SingleThreadTaskRunner> capture_thread)
  118. : capture_thread_(std::move(capture_thread)) {}
  119. FakeDesktopEnvironmentFactory::~FakeDesktopEnvironmentFactory() = default;
  120. // DesktopEnvironmentFactory implementation.
  121. std::unique_ptr<DesktopEnvironment> FakeDesktopEnvironmentFactory::Create(
  122. base::WeakPtr<ClientSessionControl> client_session_control,
  123. base::WeakPtr<ClientSessionEvents> client_session_events,
  124. const DesktopEnvironmentOptions& options) {
  125. std::unique_ptr<FakeDesktopEnvironment> result(
  126. new FakeDesktopEnvironment(capture_thread_, options));
  127. result->set_frame_generator(frame_generator_);
  128. result->set_desktop_session_id(desktop_session_id_);
  129. last_desktop_environment_ = result->weak_factory_.GetWeakPtr();
  130. return std::move(result);
  131. }
  132. bool FakeDesktopEnvironmentFactory::SupportsAudioCapture() const {
  133. return false;
  134. }
  135. } // namespace remoting