Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/continue_window.h" | 5 #include "remoting/host/continue_window.h" |
| 6 | 6 |
| 7 #include <windows.h> | |
| 8 | |
| 7 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "remoting/host/chromoting_host.h" | |
| 12 #include "remoting/host/host_plugin_resource.h" | |
| 13 | |
| 14 // TODO(garykac): Lots of duplicated code in this file and | |
| 15 // disconnect_window_win.cc. These global floating windows are temporary so | |
| 16 // they should be deleted soon. If we need to expand this then we should | |
| 17 // create a class with the shared code. | |
| 18 | |
| 19 // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. | |
| 20 // This is defined in: | |
| 21 // Plugin: host_plugin.cc | |
| 22 // SimpleHost: simple_host_process.cc | |
| 23 extern HMODULE g_hModule; | |
| 9 | 24 |
| 10 namespace remoting { | 25 namespace remoting { |
| 11 | 26 |
| 12 class ContinueWindowWin : public remoting::ContinueWindow { | 27 class ContinueWindowWin : public ContinueWindow { |
| 13 public: | 28 public: |
| 14 ContinueWindowWin() {} | 29 ContinueWindowWin(); |
| 15 virtual ~ContinueWindowWin() {} | 30 virtual ~ContinueWindowWin(); |
| 16 | 31 |
| 17 virtual void Show(remoting::ChromotingHost* host) OVERRIDE; | 32 virtual void Show(remoting::ChromotingHost* host) OVERRIDE; |
| 18 virtual void Hide() OVERRIDE; | 33 virtual void Hide() OVERRIDE; |
| 19 | 34 |
| 20 private: | 35 private: |
| 36 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, | |
| 37 LPARAM lParam); | |
| 38 | |
| 39 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); | |
| 40 | |
| 41 void EndDialog(); | |
| 42 | |
| 43 remoting::ChromotingHost* host_; | |
| 44 HWND hwnd_; | |
| 45 | |
| 46 // A "random" key from the tickcount that is used to validate the WM_USER | |
| 47 // message sent to end the dialog. This check is used to help protect | |
| 48 // against someone sending (WM_APP,0,0L) to close the dialog. | |
| 49 DWORD key_; | |
|
Jamie
2011/06/21 23:09:45
What is this designed to protect against? EndDialo
garykac
2011/06/22 00:36:59
Removed. Now that we're on the proper thread, I'm
| |
| 50 | |
| 21 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); | 51 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); |
| 22 }; | 52 }; |
| 23 | 53 |
| 24 void ContinueWindowWin::Show(remoting::ChromotingHost* host) { | 54 ContinueWindowWin::ContinueWindowWin() |
| 25 NOTIMPLEMENTED(); | 55 : host_(NULL), |
| 56 hwnd_(NULL), | |
| 57 key_(0L) { | |
| 58 } | |
| 59 | |
| 60 ContinueWindowWin::~ContinueWindowWin() { | |
| 61 EndDialog(); | |
| 62 } | |
| 63 | |
| 64 BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg, | |
| 65 WPARAM wParam, LPARAM lParam) { | |
| 66 ContinueWindowWin* win = NULL; | |
| 67 if (msg == WM_INITDIALOG) { | |
| 68 win = reinterpret_cast<ContinueWindowWin*>(lParam); | |
| 69 CHECK(win); | |
| 70 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); | |
| 71 } else { | |
| 72 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); | |
| 73 win = reinterpret_cast<ContinueWindowWin*>(lp); | |
| 74 } | |
| 75 if (win == NULL) | |
| 76 return FALSE; | |
| 77 return win->OnDialogMessage(hwnd, msg, wParam, lParam); | |
| 78 } | |
| 79 | |
| 80 BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, | |
| 81 WPARAM wParam, LPARAM lParam) { | |
| 82 switch (msg) { | |
| 83 case WM_INITDIALOG: | |
| 84 return TRUE; | |
| 85 case WM_CLOSE: | |
| 86 // Ignore close messages. | |
| 87 return TRUE; | |
| 88 case WM_DESTROY: | |
| 89 // Ensure we don't try to use the HWND anymore. | |
| 90 hwnd_ = NULL; | |
| 91 return TRUE; | |
| 92 case WM_APP: | |
|
Jamie
2011/06/21 23:09:45
I think WM_USER would be more appropriate here.
garykac
2011/06/22 00:36:59
Removed.
| |
| 93 if (key_ == static_cast<DWORD>(lParam)) { | |
| 94 ::EndDialog(hwnd, LOWORD(wParam)); | |
| 95 hwnd_ = NULL; | |
| 96 } | |
| 97 return TRUE; | |
| 98 case WM_COMMAND: | |
| 99 switch (LOWORD(wParam)) { | |
| 100 case IDC_CONTINUE: | |
| 101 { | |
| 102 CHECK(host_); | |
| 103 host_->PauseSession(false); | |
| 104 ::EndDialog(hwnd, LOWORD(wParam)); | |
| 105 hwnd_ = NULL; | |
| 106 } | |
| 107 return TRUE; | |
| 108 } | |
| 109 } | |
| 110 return FALSE; | |
| 111 } | |
| 112 | |
| 113 void ContinueWindowWin::Show(ChromotingHost* host) { | |
| 114 host_ = host; | |
| 115 // Get a "random" value that we can use to prevent someone from sending a | |
| 116 // simple (WM_APP,0,0L) message to our window to close it. | |
| 117 key_ = GetTickCount(); | |
| 118 | |
| 119 CHECK(!hwnd_); | |
| 120 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_CONTINUE), NULL, | |
| 121 (DLGPROC)DialogProc, (LPARAM)this); | |
| 122 if (!hwnd_) { | |
| 123 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; | |
| 124 return; | |
| 125 } | |
| 126 | |
| 127 ShowWindow(hwnd_, SW_SHOW); | |
| 26 } | 128 } |
| 27 | 129 |
| 28 void ContinueWindowWin::Hide() { | 130 void ContinueWindowWin::Hide() { |
| 29 NOTIMPLEMENTED(); | 131 EndDialog(); |
| 132 } | |
| 133 | |
| 134 void ContinueWindowWin::EndDialog() { | |
| 135 if (hwnd_) { | |
| 136 SendMessage(hwnd_, WM_APP, 0, (LPARAM)key_); | |
| 137 } | |
| 30 } | 138 } |
| 31 | 139 |
| 32 ContinueWindow* ContinueWindow::Create() { | 140 ContinueWindow* ContinueWindow::Create() { |
| 33 return new ContinueWindowWin(); | 141 return new ContinueWindowWin(); |
| 34 } | 142 } |
| 35 | 143 |
| 36 } // namespace remoting | 144 } // namespace remoting |
| OLD | NEW |