| 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 <limits> | 7 #include <limits> |
| 8 #include <sddl.h> | 8 #include <sddl.h> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "net/base/ip_endpoint.h" | 24 #include "net/base/ip_endpoint.h" |
| 25 #include "remoting/base/auto_thread_task_runner.h" | 25 #include "remoting/base/auto_thread_task_runner.h" |
| 26 // MIDL-generated declarations and definitions. | 26 // MIDL-generated declarations and definitions. |
| 27 #include "remoting/host/chromoting_lib.h" | 27 #include "remoting/host/chromoting_lib.h" |
| 28 #include "remoting/host/chromoting_messages.h" | 28 #include "remoting/host/chromoting_messages.h" |
| 29 #include "remoting/host/daemon_process.h" | 29 #include "remoting/host/daemon_process.h" |
| 30 #include "remoting/host/desktop_session.h" | 30 #include "remoting/host/desktop_session.h" |
| 31 #include "remoting/host/host_main.h" | 31 #include "remoting/host/host_main.h" |
| 32 #include "remoting/host/ipc_constants.h" | 32 #include "remoting/host/ipc_constants.h" |
| 33 #include "remoting/host/sas_injector.h" | 33 #include "remoting/host/sas_injector.h" |
| 34 #include "remoting/host/screen_resolution.h" |
| 34 #include "remoting/host/win/host_service.h" | 35 #include "remoting/host/win/host_service.h" |
| 35 #include "remoting/host/win/worker_process_launcher.h" | 36 #include "remoting/host/win/worker_process_launcher.h" |
| 36 #include "remoting/host/win/wts_session_process_delegate.h" | 37 #include "remoting/host/win/wts_session_process_delegate.h" |
| 37 #include "remoting/host/win/wts_terminal_monitor.h" | 38 #include "remoting/host/win/wts_terminal_monitor.h" |
| 38 #include "remoting/host/win/wts_terminal_observer.h" | 39 #include "remoting/host/win/wts_terminal_observer.h" |
| 39 #include "remoting/host/worker_process_ipc_delegate.h" | 40 #include "remoting/host/worker_process_ipc_delegate.h" |
| 40 | 41 |
| 41 using base::win::ScopedHandle; | 42 using base::win::ScopedHandle; |
| 42 | 43 |
| 43 namespace remoting { | 44 namespace remoting { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 58 const char* kCopiedSwitchNames[] = { switches::kV, switches::kVModule }; | 59 const char* kCopiedSwitchNames[] = { switches::kV, switches::kVModule }; |
| 59 | 60 |
| 60 // RDC 6.1 (W2K8) supports dimensions of up to 4096x2048. | 61 // RDC 6.1 (W2K8) supports dimensions of up to 4096x2048. |
| 61 const int kMaxRdpScreenWidth = 4096; | 62 const int kMaxRdpScreenWidth = 4096; |
| 62 const int kMaxRdpScreenHeight = 2048; | 63 const int kMaxRdpScreenHeight = 2048; |
| 63 | 64 |
| 64 // The minimum effective screen dimensions supported by Windows are 800x600. | 65 // The minimum effective screen dimensions supported by Windows are 800x600. |
| 65 const int kMinRdpScreenWidth = 800; | 66 const int kMinRdpScreenWidth = 800; |
| 66 const int kMinRdpScreenHeight = 600; | 67 const int kMinRdpScreenHeight = 600; |
| 67 | 68 |
| 68 // Default dots per inch is 96 DPI. | 69 // Default dots per inch used by RDP is 96 DPI. |
| 69 const int kDefaultDpiX = 96; | 70 const int kDefaultRdpDpi = 96; |
| 70 const int kDefaultDpiY = 96; | |
| 71 | 71 |
| 72 // The session attach notification should arrive within 30 seconds. | 72 // The session attach notification should arrive within 30 seconds. |
| 73 const int kSessionAttachTimeoutSeconds = 30; | 73 const int kSessionAttachTimeoutSeconds = 30; |
| 74 | 74 |
| 75 // DesktopSession implementation which attaches to the host's physical console. | 75 // DesktopSession implementation which attaches to the host's physical console. |
| 76 // Receives IPC messages from the desktop process, running in the console | 76 // Receives IPC messages from the desktop process, running in the console |
| 77 // session, via |WorkerProcessIpcDelegate|, and monitors console session | 77 // session, via |WorkerProcessIpcDelegate|, and monitors console session |
| 78 // attach/detach events via |WtsConsoleObserer|. | 78 // attach/detach events via |WtsConsoleObserer|. |
| 79 class ConsoleSession : public DesktopSessionWin { | 79 class ConsoleSession : public DesktopSessionWin { |
| 80 public: | 80 public: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 106 // Same as DesktopSessionWin(). | 106 // Same as DesktopSessionWin(). |
| 107 RdpSession( | 107 RdpSession( |
| 108 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 108 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 109 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 109 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 110 DaemonProcess* daemon_process, | 110 DaemonProcess* daemon_process, |
| 111 int id, | 111 int id, |
| 112 WtsTerminalMonitor* monitor); | 112 WtsTerminalMonitor* monitor); |
| 113 virtual ~RdpSession(); | 113 virtual ~RdpSession(); |
| 114 | 114 |
| 115 // Performs the part of initialization that can fail. | 115 // Performs the part of initialization that can fail. |
| 116 bool Initialize(const DesktopSessionParams& params); | 116 bool Initialize(const ScreenResolution& resolution); |
| 117 | 117 |
| 118 // Mirrors IRdpDesktopSessionEventHandler. | 118 // Mirrors IRdpDesktopSessionEventHandler. |
| 119 void OnRdpConnected(const net::IPEndPoint& client_endpoint); | 119 void OnRdpConnected(const net::IPEndPoint& client_endpoint); |
| 120 void OnRdpClosed(); | 120 void OnRdpClosed(); |
| 121 | 121 |
| 122 protected: | 122 protected: |
| 123 // DesktopSessionWin overrides. | 123 // DesktopSessionWin overrides. |
| 124 virtual void InjectSas() OVERRIDE; | 124 virtual void InjectSas() OVERRIDE; |
| 125 | 125 |
| 126 private: | 126 private: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 int id, | 188 int id, |
| 189 WtsTerminalMonitor* monitor) | 189 WtsTerminalMonitor* monitor) |
| 190 : DesktopSessionWin(caller_task_runner, io_task_runner, daemon_process, id, | 190 : DesktopSessionWin(caller_task_runner, io_task_runner, daemon_process, id, |
| 191 monitor), | 191 monitor), |
| 192 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 192 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 193 } | 193 } |
| 194 | 194 |
| 195 RdpSession::~RdpSession() { | 195 RdpSession::~RdpSession() { |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool RdpSession::Initialize(const DesktopSessionParams& params) { | 198 bool RdpSession::Initialize(const ScreenResolution& resolution) { |
| 199 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 199 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 200 | 200 |
| 201 // Create the RDP wrapper object. | 201 // Create the RDP wrapper object. |
| 202 HRESULT result = rdp_desktop_session_.CreateInstance( | 202 HRESULT result = rdp_desktop_session_.CreateInstance( |
| 203 __uuidof(RdpDesktopSession)); | 203 __uuidof(RdpDesktopSession)); |
| 204 if (FAILED(result)) { | 204 if (FAILED(result)) { |
| 205 LOG(ERROR) << "Failed to create RdpSession object, 0x" | 205 LOG(ERROR) << "Failed to create RdpSession object, 0x" |
| 206 << std::hex << result << std::dec << "."; | 206 << std::hex << result << std::dec << "."; |
| 207 return false; | 207 return false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 // DaemonProcess::CreateDesktopSession() varifies that |client_dpi_| and | 210 // DaemonProcess::CreateDesktopSession() verifies that the resolution is |
| 211 // |client_size_| are positive. | 211 // valid. |
| 212 DCHECK(params.client_dpi_.x() >= 0 && params.client_dpi_.y() >= 0); | 212 DCHECK(resolution.IsValid()); |
| 213 DCHECK(params.client_size_.width() >= 0 && params.client_size_.height() >= 0); | |
| 214 | 213 |
| 215 // Handle the default DPI. | 214 // Get the screen dimensions assuming the default DPI. |
| 216 SkIPoint client_dpi = params.client_dpi_; | 215 SkISize host_size = resolution.ScaleDimensionsToDpi( |
| 217 if (!client_dpi.x()) | 216 SkIPoint::Make(kDefaultRdpDpi, kDefaultRdpDpi)); |
| 218 client_dpi.setX(kDefaultDpiX); | |
| 219 if (!client_dpi.y()) | |
| 220 client_dpi.setY(kDefaultDpiY); | |
| 221 | |
| 222 // Make sure there will be no integer overflow while scaling the client | |
| 223 // resolution. | |
| 224 SkISize client_size = SkISize::Make( | |
| 225 std::min(params.client_size_.width(), | |
| 226 std::numeric_limits<int32_t>::max() / kDefaultDpiX), | |
| 227 std::min(params.client_size_.height(), | |
| 228 std::numeric_limits<int32_t>::max() / kDefaultDpiY)); | |
| 229 | |
| 230 // Scale the client resolution assiming RDP gives us the default 96 DPI. | |
| 231 SkISize host_size = SkISize::Make( | |
| 232 client_size.width() * kDefaultDpiX / client_dpi.x(), | |
| 233 client_size.height() * kDefaultDpiY / client_dpi.y()); | |
| 234 | 217 |
| 235 // Make sure that the host resolution is within the limits supported by RDP. | 218 // Make sure that the host resolution is within the limits supported by RDP. |
| 236 host_size = SkISize::Make( | 219 host_size = SkISize::Make( |
| 237 std::min(kMaxRdpScreenWidth, | 220 std::min(kMaxRdpScreenWidth, |
| 238 std::max(kMinRdpScreenWidth, host_size.width())), | 221 std::max(kMinRdpScreenWidth, host_size.width())), |
| 239 std::min(kMaxRdpScreenHeight, | 222 std::min(kMaxRdpScreenHeight, |
| 240 std::max(kMinRdpScreenHeight, host_size.height()))); | 223 std::max(kMinRdpScreenHeight, host_size.height()))); |
| 241 | 224 |
| 242 // Create an RDP session. | 225 // Create an RDP session. |
| 243 base::win::ScopedComPtr<IRdpDesktopSessionEventHandler> event_handler( | 226 base::win::ScopedComPtr<IRdpDesktopSessionEventHandler> event_handler( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 333 } |
| 351 | 334 |
| 352 } // namespace | 335 } // namespace |
| 353 | 336 |
| 354 // static | 337 // static |
| 355 scoped_ptr<DesktopSession> DesktopSessionWin::CreateForConsole( | 338 scoped_ptr<DesktopSession> DesktopSessionWin::CreateForConsole( |
| 356 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 339 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 357 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 340 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 358 DaemonProcess* daemon_process, | 341 DaemonProcess* daemon_process, |
| 359 int id, | 342 int id, |
| 360 const DesktopSessionParams& params) { | 343 const ScreenResolution& resolution) { |
| 361 scoped_ptr<ConsoleSession> session(new ConsoleSession( | 344 scoped_ptr<ConsoleSession> session(new ConsoleSession( |
| 362 caller_task_runner, io_task_runner, daemon_process, id, | 345 caller_task_runner, io_task_runner, daemon_process, id, |
| 363 HostService::GetInstance())); | 346 HostService::GetInstance())); |
| 364 | 347 |
| 365 return session.PassAs<DesktopSession>(); | 348 return session.PassAs<DesktopSession>(); |
| 366 } | 349 } |
| 367 | 350 |
| 368 // static | 351 // static |
| 369 scoped_ptr<DesktopSession> DesktopSessionWin::CreateForVirtualTerminal( | 352 scoped_ptr<DesktopSession> DesktopSessionWin::CreateForVirtualTerminal( |
| 370 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 353 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 371 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 354 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 372 DaemonProcess* daemon_process, | 355 DaemonProcess* daemon_process, |
| 373 int id, | 356 int id, |
| 374 const DesktopSessionParams& params) { | 357 const ScreenResolution& resolution) { |
| 375 scoped_ptr<RdpSession> session(new RdpSession( | 358 scoped_ptr<RdpSession> session(new RdpSession( |
| 376 caller_task_runner, io_task_runner, daemon_process, id, | 359 caller_task_runner, io_task_runner, daemon_process, id, |
| 377 HostService::GetInstance())); | 360 HostService::GetInstance())); |
| 378 if (!session->Initialize(params)) | 361 if (!session->Initialize(resolution)) |
| 379 return scoped_ptr<DesktopSession>(); | 362 return scoped_ptr<DesktopSession>(); |
| 380 | 363 |
| 381 return session.PassAs<DesktopSession>(); | 364 return session.PassAs<DesktopSession>(); |
| 382 } | 365 } |
| 383 | 366 |
| 384 DesktopSessionWin::DesktopSessionWin( | 367 DesktopSessionWin::DesktopSessionWin( |
| 385 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 368 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 386 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 369 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 387 DaemonProcess* daemon_process, | 370 DaemonProcess* daemon_process, |
| 388 int id, | 371 int id, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 516 } |
| 534 | 517 |
| 535 void DesktopSessionWin::CrashDesktopProcess( | 518 void DesktopSessionWin::CrashDesktopProcess( |
| 536 const tracked_objects::Location& location) { | 519 const tracked_objects::Location& location) { |
| 537 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 520 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 538 | 521 |
| 539 launcher_->Crash(location); | 522 launcher_->Crash(location); |
| 540 } | 523 } |
| 541 | 524 |
| 542 } // namespace remoting | 525 } // namespace remoting |
| OLD | NEW |