Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/host/desktop_session_win.h" | 5 #include "remoting/host/desktop_session_win.h" |
| 6 | 6 |
| 7 #include <sddl.h> | 7 #include <sddl.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/base_switches.h" | 13 #include "base/base_switches.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/guid.h" | 16 #include "base/guid.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/threading/thread_checker.h" | 23 #include "base/threading/thread_checker.h" |
| 24 #include "base/timer/timer.h" | 24 #include "base/timer/timer.h" |
| 25 #include "base/win/registry.h" | |
| 25 #include "base/win/scoped_bstr.h" | 26 #include "base/win/scoped_bstr.h" |
| 26 #include "base/win/scoped_comptr.h" | 27 #include "base/win/scoped_comptr.h" |
| 27 #include "base/win/scoped_handle.h" | 28 #include "base/win/scoped_handle.h" |
| 28 #include "base/win/windows_version.h" | 29 #include "base/win/windows_version.h" |
| 29 #include "ipc/ipc_message_macros.h" | 30 #include "ipc/ipc_message_macros.h" |
| 30 #include "ipc/ipc_platform_file.h" | 31 #include "ipc/ipc_platform_file.h" |
| 31 #include "remoting/base/auto_thread_task_runner.h" | 32 #include "remoting/base/auto_thread_task_runner.h" |
| 32 // MIDL-generated declarations and definitions. | 33 // MIDL-generated declarations and definitions. |
| 33 #include "remoting/host/chromoting_lib.h" | 34 #include "remoting/host/chromoting_lib.h" |
| 34 #include "remoting/host/chromoting_messages.h" | 35 #include "remoting/host/chromoting_messages.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 // The minimum effective screen dimensions supported by Windows are 800x600. | 76 // The minimum effective screen dimensions supported by Windows are 800x600. |
| 76 const int kMinRdpScreenWidth = 800; | 77 const int kMinRdpScreenWidth = 800; |
| 77 const int kMinRdpScreenHeight = 600; | 78 const int kMinRdpScreenHeight = 600; |
| 78 | 79 |
| 79 // Default dots per inch used by RDP is 96 DPI. | 80 // Default dots per inch used by RDP is 96 DPI. |
| 80 const int kDefaultRdpDpi = 96; | 81 const int kDefaultRdpDpi = 96; |
| 81 | 82 |
| 82 // The session attach notification should arrive within 30 seconds. | 83 // The session attach notification should arrive within 30 seconds. |
| 83 const int kSessionAttachTimeoutSeconds = 30; | 84 const int kSessionAttachTimeoutSeconds = 30; |
| 84 | 85 |
| 86 // The default port number used for establishing an RDP session. | |
| 87 const int kDefaultRdpPort = 3389; | |
| 88 | |
| 89 // The values used to establish RDP connections are stored in the registry. | |
| 90 const wchar_t kRdpTcpSettingsKeyName[] = L"SYSTEM\\CurrentControlSet\\" | |
| 91 L"Control\\Terminal Server\\WinStations\\RDP-Tcp"; | |
| 92 const wchar_t kRdpPortValueName[] = L"PortNumber"; | |
| 93 | |
| 85 // DesktopSession implementation which attaches to the host's physical console. | 94 // DesktopSession implementation which attaches to the host's physical console. |
| 86 // Receives IPC messages from the desktop process, running in the console | 95 // Receives IPC messages from the desktop process, running in the console |
| 87 // session, via |WorkerProcessIpcDelegate|, and monitors console session | 96 // session, via |WorkerProcessIpcDelegate|, and monitors console session |
| 88 // attach/detach events via |WtsConsoleObserer|. | 97 // attach/detach events via |WtsConsoleObserver|. |
| 89 class ConsoleSession : public DesktopSessionWin { | 98 class ConsoleSession : public DesktopSessionWin { |
| 90 public: | 99 public: |
| 91 // Same as DesktopSessionWin(). | 100 // Same as DesktopSessionWin(). |
| 92 ConsoleSession( | 101 ConsoleSession( |
| 93 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 102 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 94 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 103 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 95 DaemonProcess* daemon_process, | 104 DaemonProcess* daemon_process, |
| 96 int id, | 105 int id, |
| 97 WtsTerminalMonitor* monitor); | 106 WtsTerminalMonitor* monitor); |
| 98 ~ConsoleSession() override; | 107 ~ConsoleSession() override; |
| 99 | 108 |
| 100 protected: | 109 protected: |
| 101 // DesktopSession overrides. | 110 // DesktopSession overrides. |
| 102 void SetScreenResolution(const ScreenResolution& resolution) override; | 111 void SetScreenResolution(const ScreenResolution& resolution) override; |
| 103 | 112 |
| 104 // DesktopSessionWin overrides. | 113 // DesktopSessionWin overrides. |
| 105 void InjectSas() override; | 114 void InjectSas() override; |
| 106 | 115 |
| 107 private: | 116 private: |
| 108 std::unique_ptr<SasInjector> sas_injector_; | 117 std::unique_ptr<SasInjector> sas_injector_; |
| 109 | 118 |
| 110 DISALLOW_COPY_AND_ASSIGN(ConsoleSession); | 119 DISALLOW_COPY_AND_ASSIGN(ConsoleSession); |
| 111 }; | 120 }; |
| 112 | 121 |
| 113 // DesktopSession implementation which attaches to virtual RDP console. | 122 // DesktopSession implementation which attaches to virtual RDP console. |
| 114 // Receives IPC messages from the desktop process, running in the console | 123 // Receives IPC messages from the desktop process, running in the console |
| 115 // session, via |WorkerProcessIpcDelegate|, and monitors console session | 124 // session, via |WorkerProcessIpcDelegate|, and monitors console session |
| 116 // attach/detach events via |WtsConsoleObserer|. | 125 // attach/detach events via |WtsConsoleObserver|. |
| 117 class RdpSession : public DesktopSessionWin { | 126 class RdpSession : public DesktopSessionWin { |
| 118 public: | 127 public: |
| 119 // Same as DesktopSessionWin(). | 128 // Same as DesktopSessionWin(). |
| 120 RdpSession( | 129 RdpSession( |
| 121 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 130 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 122 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 131 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 123 DaemonProcess* daemon_process, | 132 DaemonProcess* daemon_process, |
| 124 int id, | 133 int id, |
| 125 WtsTerminalMonitor* monitor); | 134 WtsTerminalMonitor* monitor); |
| 126 ~RdpSession() override; | 135 ~RdpSession() override; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 | 170 |
| 162 // Points to the desktop session object receiving OnRdpXxx() notifications. | 171 // Points to the desktop session object receiving OnRdpXxx() notifications. |
| 163 base::WeakPtr<RdpSession> desktop_session_; | 172 base::WeakPtr<RdpSession> desktop_session_; |
| 164 | 173 |
| 165 // This class must be used on a single thread. | 174 // This class must be used on a single thread. |
| 166 base::ThreadChecker thread_checker_; | 175 base::ThreadChecker thread_checker_; |
| 167 | 176 |
| 168 DISALLOW_COPY_AND_ASSIGN(EventHandler); | 177 DISALLOW_COPY_AND_ASSIGN(EventHandler); |
| 169 }; | 178 }; |
| 170 | 179 |
| 180 // Retrieves a DWORD value from the registry. Returns true on success. | |
| 181 bool RetrieveDwordRegistryValue(const wchar_t* key_name, | |
| 182 const wchar_t* value_name, | |
| 183 DWORD* value); | |
| 184 | |
| 171 // Used to create an RDP desktop session. | 185 // Used to create an RDP desktop session. |
| 172 base::win::ScopedComPtr<IRdpDesktopSession> rdp_desktop_session_; | 186 base::win::ScopedComPtr<IRdpDesktopSession> rdp_desktop_session_; |
| 173 | 187 |
| 174 // Used to match |rdp_desktop_session_| with the session it is attached to. | 188 // Used to match |rdp_desktop_session_| with the session it is attached to. |
| 175 std::string terminal_id_; | 189 std::string terminal_id_; |
| 176 | 190 |
| 177 base::WeakPtrFactory<RdpSession> weak_factory_; | 191 base::WeakPtrFactory<RdpSession> weak_factory_; |
| 178 | 192 |
| 179 DISALLOW_COPY_AND_ASSIGN(RdpSession); | 193 DISALLOW_COPY_AND_ASSIGN(RdpSession); |
| 180 }; | 194 }; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 webrtc::DesktopSize host_size = local_resolution.ScaleDimensionsToDpi( | 262 webrtc::DesktopSize host_size = local_resolution.ScaleDimensionsToDpi( |
| 249 webrtc::DesktopVector(kDefaultRdpDpi, kDefaultRdpDpi)); | 263 webrtc::DesktopVector(kDefaultRdpDpi, kDefaultRdpDpi)); |
| 250 | 264 |
| 251 // Make sure that the host resolution is within the limits supported by RDP. | 265 // Make sure that the host resolution is within the limits supported by RDP. |
| 252 host_size = webrtc::DesktopSize( | 266 host_size = webrtc::DesktopSize( |
| 253 std::min(kMaxRdpScreenWidth, | 267 std::min(kMaxRdpScreenWidth, |
| 254 std::max(kMinRdpScreenWidth, host_size.width())), | 268 std::max(kMinRdpScreenWidth, host_size.width())), |
| 255 std::min(kMaxRdpScreenHeight, | 269 std::min(kMaxRdpScreenHeight, |
| 256 std::max(kMinRdpScreenHeight, host_size.height()))); | 270 std::max(kMinRdpScreenHeight, host_size.height()))); |
| 257 | 271 |
| 272 // Read the port number used by RDP. | |
| 273 DWORD server_port; | |
| 274 if (!RetrieveDwordRegistryValue(kRdpTcpSettingsKeyName, kRdpPortValueName, | |
| 275 &server_port) || | |
| 276 server_port > 65535) { | |
| 277 server_port = kDefaultRdpPort; | |
|
Jamie
2016/05/03 00:18:12
I realize you haven't changed the behaviour here,
joedow
2016/05/03 19:07:08
I think that makes sense. It wouldn't have worked
| |
| 278 } | |
| 279 | |
| 258 // Create an RDP session. | 280 // Create an RDP session. |
| 259 base::win::ScopedComPtr<IRdpDesktopSessionEventHandler> event_handler( | 281 base::win::ScopedComPtr<IRdpDesktopSessionEventHandler> event_handler( |
| 260 new EventHandler(weak_factory_.GetWeakPtr())); | 282 new EventHandler(weak_factory_.GetWeakPtr())); |
| 261 terminal_id_ = base::GenerateGUID(); | 283 terminal_id_ = base::GenerateGUID(); |
| 262 base::win::ScopedBstr terminal_id(base::UTF8ToUTF16(terminal_id_).c_str()); | 284 base::win::ScopedBstr terminal_id(base::UTF8ToUTF16(terminal_id_).c_str()); |
| 263 result = rdp_desktop_session_->Connect(host_size.width(), host_size.height(), | 285 result = rdp_desktop_session_->Connect(host_size.width(), host_size.height(), |
| 264 terminal_id, event_handler.get()); | 286 terminal_id, server_port, |
| 287 event_handler.get()); | |
| 265 if (FAILED(result)) { | 288 if (FAILED(result)) { |
| 266 LOG(ERROR) << "RdpSession::Create() failed, 0x" | 289 LOG(ERROR) << "RdpSession::Create() failed, 0x" |
| 267 << std::hex << result << std::dec << "."; | 290 << std::hex << result << std::dec << "."; |
| 268 return false; | 291 return false; |
| 269 } | 292 } |
| 270 | 293 |
| 271 return true; | 294 return true; |
| 272 } | 295 } |
| 273 | 296 |
| 274 void RdpSession::OnRdpConnected() { | 297 void RdpSession::OnRdpConnected() { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 291 // See http://crbug.com/137696. | 314 // See http://crbug.com/137696. |
| 292 NOTIMPLEMENTED(); | 315 NOTIMPLEMENTED(); |
| 293 } | 316 } |
| 294 | 317 |
| 295 void RdpSession::InjectSas() { | 318 void RdpSession::InjectSas() { |
| 296 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 319 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 297 | 320 |
| 298 rdp_desktop_session_->InjectSas(); | 321 rdp_desktop_session_->InjectSas(); |
| 299 } | 322 } |
| 300 | 323 |
| 324 bool RdpSession::RetrieveDwordRegistryValue(const wchar_t* key_name, | |
| 325 const wchar_t* value_name, | |
| 326 DWORD* value) { | |
| 327 DCHECK(key_name); | |
| 328 DCHECK(value_name); | |
| 329 DCHECK(value); | |
| 330 | |
| 331 base::win::RegKey key(HKEY_LOCAL_MACHINE, key_name, KEY_READ); | |
| 332 if (!key.Valid()) { | |
| 333 LOG(WARNING) << "Failed to open key: " << key_name; | |
| 334 return false; | |
| 335 } | |
| 336 | |
| 337 if (key.ReadValueDW(value_name, value) != ERROR_SUCCESS) { | |
| 338 LOG(WARNING) << "Failed to read registry value: " << value_name; | |
| 339 return false; | |
| 340 } | |
| 341 | |
| 342 return true; | |
| 343 } | |
| 344 | |
| 301 RdpSession::EventHandler::EventHandler( | 345 RdpSession::EventHandler::EventHandler( |
| 302 base::WeakPtr<RdpSession> desktop_session) | 346 base::WeakPtr<RdpSession> desktop_session) |
| 303 : ref_count_(0), | 347 : ref_count_(0), |
| 304 desktop_session_(desktop_session) { | 348 desktop_session_(desktop_session) { |
| 305 } | 349 } |
| 306 | 350 |
| 307 RdpSession::EventHandler::~EventHandler() { | 351 RdpSession::EventHandler::~EventHandler() { |
| 308 DCHECK(thread_checker_.CalledOnValidThread()); | 352 DCHECK(thread_checker_.CalledOnValidThread()); |
| 309 | 353 |
| 310 if (desktop_session_) | 354 if (desktop_session_) |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 exploded.hour, | 643 exploded.hour, |
| 600 exploded.minute, | 644 exploded.minute, |
| 601 exploded.second, | 645 exploded.second, |
| 602 exploded.millisecond, | 646 exploded.millisecond, |
| 603 passed.c_str()); | 647 passed.c_str()); |
| 604 | 648 |
| 605 last_timestamp_ = now; | 649 last_timestamp_ = now; |
| 606 } | 650 } |
| 607 | 651 |
| 608 } // namespace remoting | 652 } // namespace remoting |
| OLD | NEW |