Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: remoting/host/disconnect_window_win.cc

Issue 7219002: Chromoting's ContinueWindow implementation for Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/disconnect_window.h" 5 #include "remoting/host/disconnect_window.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "remoting/host/chromoting_host.h" 12 #include "remoting/host/chromoting_host.h"
13 // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have 13 // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have
14 // a dependency on the plugin's resource header. 14 // a dependency on the plugin's resource header.
15 #include "remoting/host/plugin/host_plugin_resource.h" 15 #include "remoting/host/plugin/host_plugin_resource.h"
16 16
17 // TODO(garykac): Lots of duplicated code in this file and
18 // continue_window_win.cc. These global floating windows are temporary so
19 // they should be deleted soon. If we need to expand this then we should
20 // create a class with the shared code.
21
17 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. 22 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource.
18 // This is defined in: 23 // This is defined in:
19 // Plugin: host_plugin.cc 24 // Plugin: host_plugin.cc
20 // SimpleHost: simple_host_process.cc 25 // SimpleHost: simple_host_process.cc
21 extern HMODULE g_hModule; 26 extern HMODULE g_hModule;
22 27
23 namespace { 28 namespace remoting {
24 29
25 class DisconnectWindowWin : public remoting::DisconnectWindow { 30 class DisconnectWindowWin : public DisconnectWindow {
26 public: 31 public:
27 DisconnectWindowWin(); 32 DisconnectWindowWin();
33 virtual ~DisconnectWindowWin();
34
28 virtual void Show(remoting::ChromotingHost* host, 35 virtual void Show(remoting::ChromotingHost* host,
29 const std::string& username) OVERRIDE; 36 const std::string& username) OVERRIDE;
30 virtual void Hide() OVERRIDE; 37 virtual void Hide() OVERRIDE;
31 38
39 private:
32 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, 40 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam,
33 LPARAM lParam); 41 LPARAM lParam);
34 42
35 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); 43 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
36 44
37 private: 45 void EndDialog();
46
38 remoting::ChromotingHost* host_; 47 remoting::ChromotingHost* host_;
39 std::string username_; 48 std::string username_;
40 HWND hwnd_; 49 HWND hwnd_;
41 50
42 // A "random" key from the tickcount that is used to validate the WM_USER 51 // A "random" key from the tickcount that is used to validate the WM_USER
43 // message sent to end the dialog. This check is used to help protect 52 // message sent to end the dialog. This check is used to help protect
44 // against someone sending (WM_APP,0,0L) to close the dialog. 53 // against someone sending (WM_APP,0,0L) to close the dialog.
45 DWORD key_; 54 DWORD key_;
46 55
47 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); 56 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin);
48 }; 57 };
49 58
50 DisconnectWindowWin::DisconnectWindowWin() 59 DisconnectWindowWin::DisconnectWindowWin()
51 : host_(NULL), 60 : host_(NULL),
52 username_(""), 61 username_(""),
53 hwnd_(NULL), 62 hwnd_(NULL),
54 key_(0L) { 63 key_(0L) {
55 } 64 }
56 65
66 DisconnectWindowWin::~DisconnectWindowWin() {
67 EndDialog();
68 }
69
57 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, 70 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg,
58 WPARAM wParam, LPARAM lParam) { 71 WPARAM wParam, LPARAM lParam) {
59 DisconnectWindowWin* win = NULL; 72 DisconnectWindowWin* win = NULL;
60 if (msg == WM_INITDIALOG) { 73 if (msg == WM_INITDIALOG) {
61 win = reinterpret_cast<DisconnectWindowWin*>(lParam); 74 win = reinterpret_cast<DisconnectWindowWin*>(lParam);
62 CHECK(win); 75 CHECK(win);
63 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); 76 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win);
64 } else { 77 } else {
65 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); 78 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER);
66 win = reinterpret_cast<DisconnectWindowWin*>(lp); 79 win = reinterpret_cast<DisconnectWindowWin*>(lp);
67 } 80 }
68 if (win == NULL) 81 if (win == NULL)
69 return FALSE; 82 return FALSE;
70 return win->OnDialogMessage(hwnd, msg, wParam, lParam); 83 return win->OnDialogMessage(hwnd, msg, wParam, lParam);
71 } 84 }
72 85
73 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, 86 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
74 WPARAM wParam, LPARAM lParam) { 87 WPARAM wParam, LPARAM lParam) {
75 switch (msg) { 88 switch (msg) {
76 case WM_INITDIALOG: 89 case WM_INITDIALOG:
77 { 90 {
78 // Update username in dialog. 91 // Update username in dialog.
79 HWND hwndUsername = GetDlgItem(hwnd, IDC_USERNAME); 92 HWND hwndUsername = GetDlgItem(hwnd, IDC_DISCONNECT_USERNAME);
80 CHECK(hwndUsername); 93 CHECK(hwndUsername);
81 std::wstring w_username = UTF8ToWide(username_); 94 std::wstring w_username = UTF8ToWide(username_);
82 SetWindowText(hwndUsername, w_username.c_str()); 95 SetWindowText(hwndUsername, w_username.c_str());
83 } 96 }
84 return TRUE; 97 return TRUE;
85 case WM_CLOSE: 98 case WM_CLOSE:
86 // Ignore close messages. 99 // Ignore close messages.
87 return TRUE; 100 return TRUE;
88 case WM_DESTROY: 101 case WM_DESTROY:
89 // Ensure we don't try to use the HWND anymore. 102 // Ensure we don't try to use the HWND anymore.
90 hwnd_ = NULL; 103 hwnd_ = NULL;
91 return TRUE; 104 return TRUE;
92 case WM_APP: 105 case WM_APP:
93 if (key_ == static_cast<DWORD>(lParam)) { 106 if (key_ == static_cast<DWORD>(lParam)) {
94 EndDialog(hwnd, LOWORD(wParam)); 107 ::EndDialog(hwnd, LOWORD(wParam));
95 hwnd_ = NULL; 108 hwnd_ = NULL;
96 } 109 }
97 return TRUE; 110 return TRUE;
98 case WM_COMMAND: 111 case WM_COMMAND:
99 switch (LOWORD(wParam)) { 112 switch (LOWORD(wParam)) {
100 case IDC_DISCONNECT: 113 case IDC_DISCONNECT:
101 { 114 {
102 CHECK(host_); 115 CHECK(host_);
103 host_->Shutdown(NULL); 116 host_->Shutdown(NULL);
104 EndDialog(hwnd, LOWORD(wParam)); 117 ::EndDialog(hwnd, LOWORD(wParam));
105 hwnd_ = NULL; 118 hwnd_ = NULL;
106 } 119 }
107 return TRUE; 120 return TRUE;
108 } 121 }
109 } 122 }
110 return FALSE; 123 return FALSE;
111 } 124 }
112 125
113 void DisconnectWindowWin::Show(remoting::ChromotingHost* host, 126 void DisconnectWindowWin::Show(ChromotingHost* host,
114 const std::string& username) { 127 const std::string& username) {
115 host_ = host; 128 host_ = host;
116 username_ = username; 129 username_ = username;
117 // Get a "random" value that we can use to prevent someone from sending a 130 // Get a "random" value that we can use to prevent someone from sending a
118 // simple (WM_APP,0,0L) message to our window to close it. 131 // simple (WM_APP,0,0L) message to our window to close it.
119 key_ = GetTickCount(); 132 key_ = GetTickCount();
120 133
121 CHECK(!hwnd_); 134 CHECK(!hwnd_);
122 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, 135 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL,
123 (DLGPROC)DialogProc, (LPARAM)this); 136 (DLGPROC)DialogProc, (LPARAM)this);
124 if (!hwnd_) { 137 if (!hwnd_) {
125 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; 138 LOG(ERROR) << "Unable to create Disconnect dialog for remoting.";
126 return; 139 return;
127 } 140 }
128 141
129 ShowWindow(hwnd_, SW_SHOW); 142 ShowWindow(hwnd_, SW_SHOW);
130 // TODO(garykac): Remove this UpdateWindow() call once threading issues are 143 // TODO(garykac): Remove this UpdateWindow() call once threading issues are
131 // resolved and it's no longer needed. 144 // resolved and it's no longer needed.
132 UpdateWindow(hwnd_); 145 UpdateWindow(hwnd_);
133 } 146 }
134 147
135 void DisconnectWindowWin::Hide() { 148 void DisconnectWindowWin::Hide() {
149 EndDialog();
150 }
151
152 void DisconnectWindowWin::EndDialog() {
136 if (hwnd_) { 153 if (hwnd_) {
137 SendMessage(hwnd_, WM_APP, 0, (LPARAM)key_); 154 SendMessage(hwnd_, WM_APP, 0, (LPARAM)key_);
138 } 155 }
139 } 156 }
140 157
141 } // namespace 158 DisconnectWindow* DisconnectWindow::Create() {
142
143 remoting::DisconnectWindow* remoting::DisconnectWindow::Create() {
144 return new DisconnectWindowWin; 159 return new DisconnectWindowWin;
145 } 160 }
161
162 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698