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 #ifndef REMOTING_HOST_WIN_RDP_DESKTOP_SESSION_H_
6 #define REMOTING_HOST_WIN_RDP_DESKTOP_SESSION_H_
7 
8 #include <wrl/client.h>
9 
10 #include <memory>
11 
12 #include "base/win/atl.h"
13 // chromoting_lib.h contains MIDL-generated declarations.
14 #include "remoting/host/win/chromoting_lib.h"
15 #include "remoting/host/win/rdp_client.h"
16 
17 namespace remoting {
18 
19 // Implements IRdpDesktopSession interface providing a way to host RdpClient
20 // objects in a COM component.
uuid(RDP_DESKTOP_SESSION_CLSID)21 class __declspec(uuid(RDP_DESKTOP_SESSION_CLSID)) RdpDesktopSession
22     : public ATL::CComObjectRootEx<ATL::CComSingleThreadModel>,
23       public ATL::CComCoClass<RdpDesktopSession, &__uuidof(RdpDesktopSession)>,
24       public IRdpDesktopSession,
25       public RdpClient::EventHandler {
26  public:
27   // Declare a class factory which must not lock the ATL module. This is the
28   // same as DECLARE_CLASSFACTORY() with the exception that
29   // ATL::CComObjectNoLock is used unconditionally.
30   //
31   // By default ATL generates locking class factories (by wrapping them in
32   // ATL::CComObjectCached) for classes hosted in a DLL. This class is compiled
33   // into a DLL but it is registered as an out-of-process class, so its class
34   // factory should not use locking.
35   typedef ATL::CComCreator<ATL::CComObjectNoLock<ATL::CComClassFactory> >
36       _ClassFactoryCreatorClass;
37 
38   RdpDesktopSession();
39   ~RdpDesktopSession() override;
40 
41   // IRdpDesktopSession implementation.
42   STDMETHOD(Connect)
43       (long width,
44        long height,
45        long dpi_x,
46        long dpi_y,
47        BSTR terminal_id,
48        DWORD port_number,
49        IRdpDesktopSessionEventHandler* event_handler) override;
50   STDMETHOD(Disconnect)() override;
51   STDMETHOD(ChangeResolution)(long width, long height,
52                               long dpi_x, long dpi_y) override;
53   STDMETHOD(InjectSas)() override;
54 
55   DECLARE_NO_REGISTRY()
56 
57  private:
58   // RdpClient::EventHandler interface.
59   void OnRdpConnected() override;
60   void OnRdpClosed() override;
61 
62   BEGIN_COM_MAP(RdpDesktopSession)
63     COM_INTERFACE_ENTRY(IRdpDesktopSession)
64     COM_INTERFACE_ENTRY(IUnknown)
65   END_COM_MAP()
66 
67   // Implements loading and instantiation of the RDP ActiveX client.
68   std::unique_ptr<RdpClient> client_;
69 
70   // Holds a reference to the caller's EventHandler, through which notifications
71   // are dispatched. Released in Disconnect(), to prevent further notifications.
72   Microsoft::WRL::ComPtr<IRdpDesktopSessionEventHandler> event_handler_;
73 
74   DECLARE_PROTECT_FINAL_CONSTRUCT()
75 };
76 
77 } // namespace remoting
78 
79 #endif  // REMOTING_HOST_WIN_RDP_DESKTOP_SESSION_H_
80