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

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
« no previous file with comments | « remoting/host/continue_window_win.cc ('k') | remoting/host/plugin/host_plugin.rc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
43 // 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.
45 DWORD key_;
46
47 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); 51 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin);
48 }; 52 };
49 53
50 DisconnectWindowWin::DisconnectWindowWin() 54 DisconnectWindowWin::DisconnectWindowWin()
51 : host_(NULL), 55 : host_(NULL),
52 username_(""), 56 username_(""),
53 hwnd_(NULL), 57 hwnd_(NULL) {
54 key_(0L) { 58 }
59
60 DisconnectWindowWin::~DisconnectWindowWin() {
61 EndDialog();
55 } 62 }
56 63
57 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, 64 BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg,
58 WPARAM wParam, LPARAM lParam) { 65 WPARAM wParam, LPARAM lParam) {
59 DisconnectWindowWin* win = NULL; 66 DisconnectWindowWin* win = NULL;
60 if (msg == WM_INITDIALOG) { 67 if (msg == WM_INITDIALOG) {
61 win = reinterpret_cast<DisconnectWindowWin*>(lParam); 68 win = reinterpret_cast<DisconnectWindowWin*>(lParam);
62 CHECK(win); 69 CHECK(win);
63 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); 70 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win);
64 } else { 71 } else {
65 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); 72 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER);
66 win = reinterpret_cast<DisconnectWindowWin*>(lp); 73 win = reinterpret_cast<DisconnectWindowWin*>(lp);
67 } 74 }
68 if (win == NULL) 75 if (win == NULL)
69 return FALSE; 76 return FALSE;
70 return win->OnDialogMessage(hwnd, msg, wParam, lParam); 77 return win->OnDialogMessage(hwnd, msg, wParam, lParam);
71 } 78 }
72 79
73 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, 80 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
74 WPARAM wParam, LPARAM lParam) { 81 WPARAM wParam, LPARAM lParam) {
75 switch (msg) { 82 switch (msg) {
76 case WM_INITDIALOG: 83 case WM_INITDIALOG:
77 { 84 {
78 // Update username in dialog. 85 // Update username in dialog.
79 HWND hwndUsername = GetDlgItem(hwnd, IDC_USERNAME); 86 HWND hwndUsername = GetDlgItem(hwnd, IDC_DISCONNECT_USERNAME);
80 CHECK(hwndUsername); 87 CHECK(hwndUsername);
81 std::wstring w_username = UTF8ToWide(username_); 88 std::wstring w_username = UTF8ToWide(username_);
82 SetWindowText(hwndUsername, w_username.c_str()); 89 SetWindowText(hwndUsername, w_username.c_str());
83 } 90 }
84 return TRUE; 91 return TRUE;
85 case WM_CLOSE: 92 case WM_CLOSE:
86 // Ignore close messages. 93 // Ignore close messages.
87 return TRUE; 94 return TRUE;
88 case WM_DESTROY: 95 case WM_DESTROY:
89 // Ensure we don't try to use the HWND anymore. 96 // Ensure we don't try to use the HWND anymore.
90 hwnd_ = NULL; 97 hwnd_ = NULL;
91 return TRUE; 98 return TRUE;
92 case WM_APP:
93 if (key_ == static_cast<DWORD>(lParam)) {
94 EndDialog(hwnd, LOWORD(wParam));
95 hwnd_ = NULL;
96 }
97 return TRUE;
98 case WM_COMMAND: 99 case WM_COMMAND:
99 switch (LOWORD(wParam)) { 100 switch (LOWORD(wParam)) {
100 case IDC_DISCONNECT: 101 case IDC_DISCONNECT:
101 { 102 {
102 CHECK(host_); 103 CHECK(host_);
103 host_->Shutdown(NULL); 104 host_->Shutdown(NULL);
104 EndDialog(hwnd, LOWORD(wParam)); 105 ::EndDialog(hwnd, LOWORD(wParam));
105 hwnd_ = NULL; 106 hwnd_ = NULL;
106 } 107 }
107 return TRUE; 108 return TRUE;
108 } 109 }
109 } 110 }
110 return FALSE; 111 return FALSE;
111 } 112 }
112 113
113 void DisconnectWindowWin::Show(remoting::ChromotingHost* host, 114 void DisconnectWindowWin::Show(ChromotingHost* host,
114 const std::string& username) { 115 const std::string& username) {
115 host_ = host; 116 host_ = host;
116 username_ = username; 117 username_ = username;
117 // 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.
119 key_ = GetTickCount();
120 118
121 CHECK(!hwnd_); 119 CHECK(!hwnd_);
122 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL, 120 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_DISCONNECT), NULL,
123 (DLGPROC)DialogProc, (LPARAM)this); 121 (DLGPROC)DialogProc, (LPARAM)this);
124 if (!hwnd_) { 122 if (!hwnd_) {
125 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; 123 LOG(ERROR) << "Unable to create Disconnect dialog for remoting.";
126 return; 124 return;
127 } 125 }
128 126
129 ShowWindow(hwnd_, SW_SHOW); 127 ShowWindow(hwnd_, SW_SHOW);
130 // TODO(garykac): Remove this UpdateWindow() call once threading issues are
131 // resolved and it's no longer needed.
132 UpdateWindow(hwnd_);
133 } 128 }
134 129
135 void DisconnectWindowWin::Hide() { 130 void DisconnectWindowWin::Hide() {
131 EndDialog();
132 }
133
134 void DisconnectWindowWin::EndDialog() {
136 if (hwnd_) { 135 if (hwnd_) {
137 SendMessage(hwnd_, WM_APP, 0, (LPARAM)key_); 136 ::EndDialog(hwnd_, 0);
137 hwnd_ = NULL;
138 } 138 }
139 } 139 }
140 140
141 } // namespace 141 DisconnectWindow* DisconnectWindow::Create() {
142
143 remoting::DisconnectWindow* remoting::DisconnectWindow::Create() {
144 return new DisconnectWindowWin; 142 return new DisconnectWindowWin;
145 } 143 }
144
145 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/continue_window_win.cc ('k') | remoting/host/plugin/host_plugin.rc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698