| 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 |
| 21 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); | 46 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); |
| 22 }; | 47 }; |
| 23 | 48 |
| 24 void ContinueWindowWin::Show(remoting::ChromotingHost* host) { | 49 ContinueWindowWin::ContinueWindowWin() |
| 25 NOTIMPLEMENTED(); | 50 : host_(NULL), |
| 51 hwnd_(NULL) { |
| 52 } |
| 53 |
| 54 ContinueWindowWin::~ContinueWindowWin() { |
| 55 EndDialog(); |
| 56 } |
| 57 |
| 58 BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg, |
| 59 WPARAM wParam, LPARAM lParam) { |
| 60 ContinueWindowWin* win = NULL; |
| 61 if (msg == WM_INITDIALOG) { |
| 62 win = reinterpret_cast<ContinueWindowWin*>(lParam); |
| 63 CHECK(win); |
| 64 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); |
| 65 } else { |
| 66 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); |
| 67 win = reinterpret_cast<ContinueWindowWin*>(lp); |
| 68 } |
| 69 if (win == NULL) |
| 70 return FALSE; |
| 71 return win->OnDialogMessage(hwnd, msg, wParam, lParam); |
| 72 } |
| 73 |
| 74 BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, |
| 75 WPARAM wParam, LPARAM lParam) { |
| 76 switch (msg) { |
| 77 case WM_INITDIALOG: |
| 78 return TRUE; |
| 79 case WM_CLOSE: |
| 80 // Ignore close messages. |
| 81 return TRUE; |
| 82 case WM_DESTROY: |
| 83 // Ensure we don't try to use the HWND anymore. |
| 84 hwnd_ = NULL; |
| 85 return TRUE; |
| 86 case WM_COMMAND: |
| 87 switch (LOWORD(wParam)) { |
| 88 case IDC_CONTINUE: |
| 89 { |
| 90 CHECK(host_); |
| 91 host_->PauseSession(false); |
| 92 ::EndDialog(hwnd, LOWORD(wParam)); |
| 93 hwnd_ = NULL; |
| 94 } |
| 95 return TRUE; |
| 96 } |
| 97 } |
| 98 return FALSE; |
| 99 } |
| 100 |
| 101 void ContinueWindowWin::Show(ChromotingHost* host) { |
| 102 host_ = host; |
| 103 |
| 104 CHECK(!hwnd_); |
| 105 hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_CONTINUE), NULL, |
| 106 (DLGPROC)DialogProc, (LPARAM)this); |
| 107 if (!hwnd_) { |
| 108 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; |
| 109 return; |
| 110 } |
| 111 |
| 112 ShowWindow(hwnd_, SW_SHOW); |
| 26 } | 113 } |
| 27 | 114 |
| 28 void ContinueWindowWin::Hide() { | 115 void ContinueWindowWin::Hide() { |
| 29 NOTIMPLEMENTED(); | 116 EndDialog(); |
| 117 } |
| 118 |
| 119 void ContinueWindowWin::EndDialog() { |
| 120 if (hwnd_) { |
| 121 ::EndDialog(hwnd_, 0); |
| 122 hwnd_ = NULL; |
| 123 } |
| 30 } | 124 } |
| 31 | 125 |
| 32 ContinueWindow* ContinueWindow::Create() { | 126 ContinueWindow* ContinueWindow::Create() { |
| 33 return new ContinueWindowWin(); | 127 return new ContinueWindowWin(); |
| 34 } | 128 } |
| 35 | 129 |
| 36 } // namespace remoting | 130 } // namespace remoting |
| OLD | NEW |