1 // Copyright (c) 2013 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
5 #include "remoting/host/win/rdp_desktop_session.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "remoting/base/auto_thread_task_runner.h"
9 #include "remoting/host/screen_resolution.h"
10 #include "remoting/host/win/chromoting_module.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
12
13 namespace remoting {
14
RdpDesktopSession()15 RdpDesktopSession::RdpDesktopSession() {
16 }
17
~RdpDesktopSession()18 RdpDesktopSession::~RdpDesktopSession() {
19 }
20
Connect(long width,long height,long dpi_x,long dpi_y,BSTR terminal_id,DWORD port_number,IRdpDesktopSessionEventHandler * event_handler)21 STDMETHODIMP RdpDesktopSession::Connect(
22 long width,
23 long height,
24 long dpi_x,
25 long dpi_y,
26 BSTR terminal_id,
27 DWORD port_number,
28 IRdpDesktopSessionEventHandler* event_handler) {
29 event_handler_ = event_handler;
30
31 scoped_refptr<AutoThreadTaskRunner> task_runner =
32 ChromotingModule::task_runner();
33 DCHECK(task_runner->BelongsToCurrentThread());
34
35 client_.reset(
36 new RdpClient(task_runner, task_runner,
37 ScreenResolution(webrtc::DesktopSize(width, height),
38 webrtc::DesktopVector(dpi_x, dpi_y)),
39 base::UTF16ToUTF8(terminal_id), port_number, this));
40 return S_OK;
41 }
42
Disconnect()43 STDMETHODIMP RdpDesktopSession::Disconnect() {
44 client_.reset();
45 event_handler_ = nullptr;
46 return S_OK;
47 }
48
ChangeResolution(long width,long height,long dpi_x,long dpi_y)49 STDMETHODIMP RdpDesktopSession::ChangeResolution(long width,
50 long height,
51 long dpi_x,
52 long dpi_y) {
53 if (client_) {
54 client_->ChangeResolution(ScreenResolution(
55 webrtc::DesktopSize(width, height),
56 webrtc::DesktopVector(dpi_x, dpi_y)));
57 }
58 return S_OK;
59 }
60
InjectSas()61 STDMETHODIMP RdpDesktopSession::InjectSas() {
62 if (client_) {
63 client_->InjectSas();
64 }
65 return S_OK;
66 }
67
OnRdpConnected()68 void RdpDesktopSession::OnRdpConnected() {
69 HRESULT result = event_handler_->OnRdpConnected();
70 CHECK(SUCCEEDED(result)) << "OnRdpConnected() failed: 0x"
71 << std::hex << result << std::dec << ".";
72 }
73
OnRdpClosed()74 void RdpDesktopSession::OnRdpClosed() {
75 HRESULT result = event_handler_->OnRdpClosed();
76 CHECK(SUCCEEDED(result)) << "OnRdpClosed() failed: 0x" << std::hex << result
77 << std::dec << ".";
78 }
79
80 } // namespace remoting
81