Only sync parent directory once after a leveldb file rename.
[chromium-blink-merge.git] / remoting / host / win / rdp_client_window.h
blobc4b71d233648ac358a920655c60363671c3fb08c
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_
8 #include <atlbase.h>
9 #include <atlcom.h>
10 #include <atlcrack.h>
11 #include <atlctl.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
24 namespace remoting {
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
29 // a UI thread.
30 class RdpClientWindow
31 : public CWindowImpl<RdpClientWindow, CWindow, CFrameWinTraits>,
32 public IDispEventImpl<1, RdpClientWindow,
33 &__uuidof(mstsc::IMsTscAxEvents),
34 &__uuidof(mstsc::__MSTSCLib), 1, 0> {
35 public:
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
41 // only once.
42 class EventHandler {
43 public:
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
54 // called.
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);
69 ~RdpClientWindow();
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.
78 void Disconnect();
80 private:
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)
87 MSG_WM_CLOSE(OnClose)
88 MSG_WM_CREATE(OnCreate)
89 MSG_WM_DESTROY(OnDestroy)
90 END_MSG_MAP()
92 // Requests the RDP ActiveX control to close the connection gracefully.
93 void OnClose();
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.
100 void OnDestroy();
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)
111 END_SINK_MAP()
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
123 // only once.
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.
141 class WindowHook;
142 scoped_refptr<WindowHook> window_activate_hook_;
145 } // namespace remoting
147 #endif // REMOTING_HOST_WIN_RDP_HOST_WINDOW_H_