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.
5 #ifndef REMOTING_HOST_WIN_RDP_HOST_WINDOW_H_
6 #define REMOTING_HOST_WIN_RDP_HOST_WINDOW_H_
13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/message_loop.h"
16 #include "base/win/scoped_comptr.h"
17 #include "net/base/ip_endpoint.h"
18 #include "third_party/skia/include/core/SkSize.h"
20 #import "PROGID:MsTscAx.MsTscAx" \
21 exclude("wireHWND", "_RemotableHandle", "__MIDL_IWinTypes_0009"), \
22 rename_namespace("mstsc") raw_interfaces_only no_implementation
26 // RdpClientWindow is used to establish a connection to the given RDP endpoint.
27 // It is a GUI window class that hosts Microsoft RDP ActiveX control, which
28 // takes care of handling RDP properly. RdpClientWindow must be used only on
31 : public CWindowImpl
<RdpClientWindow
, CWindow
, CFrameWinTraits
>,
32 public IDispEventImpl
<1, RdpClientWindow
,
33 &__uuidof(mstsc::IMsTscAxEvents
),
34 &__uuidof(mstsc::__MSTSCLib
), 1, 0> {
36 // Receives connect/disconnect notifications. The notifications can be
37 // delivered after RdpClientWindow::Connect() returned success.
39 // RdpClientWindow guarantees that OnDisconnected() is the last notification
40 // the event handler receives. OnDisconnected() is guaranteed to be called
44 virtual ~EventHandler() {}
46 // Invoked when the RDP control has established a connection.
47 virtual void OnConnected() = 0;
49 // Invoked when the RDP control has been disconnected from the RDP server.
50 // This includes both graceful shutdown and any fatal error condition.
52 // Once RdpClientWindow::Connect() returns success the owner of the
53 // |RdpClientWindow| object must keep it alive until OnDisconnected() is
56 // OnDisconnected() should not delete |RdpClientWindow| object directly.
57 // Instead it should post a task to delete the object. The ActiveX code
58 // expects the window be alive until the currently handled window message is
59 // completely processed.
60 virtual void OnDisconnected() = 0;
63 DECLARE_WND_CLASS(L
"RdpClientWindow")
65 // Specifies the endpoint to connect to and passes the event handler pointer
66 // to be notified about connection events.
67 RdpClientWindow(const net::IPEndPoint
& server_endpoint
,
68 EventHandler
* event_handler
);
71 // Creates the window along with the ActiveX control and initiates the
72 // connection. |screen_size| specifies resolution of the screen. Returns false
73 // if an error occurs.
74 bool Connect(const SkISize
& screen_size
);
76 // Initiates shutdown of the connection. The caller must not delete |this|
77 // until it receives OnDisconnected() notification.
81 typedef IDispEventImpl
<1, RdpClientWindow
,
82 &__uuidof(mstsc::IMsTscAxEvents
),
83 &__uuidof(mstsc::__MSTSCLib
), 1, 0> RdpEventsSink
;
85 // Handled window messages.
86 BEGIN_MSG_MAP_EX(RdpClientWindow
)
88 MSG_WM_CREATE(OnCreate
)
89 MSG_WM_DESTROY(OnDestroy
)
92 // Requests the RDP ActiveX control to close the connection gracefully.
95 // Creates the RDP ActiveX control, configures it, and initiates an RDP
96 // connection to |server_endpoint_|.
97 LRESULT
OnCreate(CREATESTRUCT
* create_struct
);
99 // Releases the RDP ActiveX control interfaces.
102 BEGIN_SINK_MAP(RdpClientWindow
)
103 SINK_ENTRY_EX(1, __uuidof(mstsc::IMsTscAxEvents
), 2, OnConnected
)
104 SINK_ENTRY_EX(1, __uuidof(mstsc::IMsTscAxEvents
), 4, OnDisconnected
)
105 SINK_ENTRY_EX(1, __uuidof(mstsc::IMsTscAxEvents
), 10, OnFatalError
)
106 SINK_ENTRY_EX(1, __uuidof(mstsc::IMsTscAxEvents
), 15, OnConfirmClose
)
107 SINK_ENTRY_EX(1, __uuidof(mstsc::IMsTscAxEvents
), 18,
108 OnAuthenticationWarningDisplayed
)
109 SINK_ENTRY_EX(1, __uuidof(mstsc::IMsTscAxEvents
), 19,
110 OnAuthenticationWarningDismissed
)
113 // mstsc::IMsTscAxEvents notifications.
114 STDMETHOD(OnAuthenticationWarningDisplayed
)();
115 STDMETHOD(OnAuthenticationWarningDismissed
)();
116 STDMETHOD(OnConnected
)();
117 STDMETHOD(OnDisconnected
)(long reason
);
118 STDMETHOD(OnFatalError
)(long error_code
);
119 STDMETHOD(OnConfirmClose
)(VARIANT_BOOL
* allow_close
);
121 // Wrappers for the event handler's methods that make sure that
122 // OnDisconnected() is the last notification delivered and is delevered
124 void NotifyConnected();
125 void NotifyDisconnected();
127 // Invoked to report connect/disconnect events.
128 EventHandler
* event_handler_
;
130 // Contains the requested dimensions of the screen.
131 SkISize screen_size_
;
133 // The endpoint to connect to.
134 net::IPEndPoint server_endpoint_
;
136 // Interfaces exposed by the RDP ActiveX control.
137 base::win::ScopedComPtr
<mstsc::IMsRdpClient
> client_
;
138 base::win::ScopedComPtr
<mstsc::IMsRdpClientAdvancedSettings
> client_settings_
;
140 // Used to cancel modal dialog boxes shown by the RDP control.
142 scoped_refptr
<WindowHook
> window_activate_hook_
;
145 } // namespace remoting
147 #endif // REMOTING_HOST_WIN_RDP_HOST_WINDOW_H_