[email protected] | 3361e1f | 2012-03-20 20:31:44 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "remoting/host/continue_window.h" |
| 6 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 7 | #include <windows.h> |
| 8 | |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
| 10 | #include "base/logging.h" |
[email protected] | ac6eedd1 | 2011-07-06 22:19:14 | [diff] [blame] | 11 | #include "base/utf_string_conversions.h" |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 12 | #include "remoting/host/chromoting_host.h" |
| 13 | // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have |
| 14 | // a dependency on the plugin's resource header. |
| 15 | #include "remoting/host/plugin/host_plugin_resource.h" |
| 16 | |
| 17 | // TODO(garykac): Lots of duplicated code in this file and |
| 18 | // disconnect_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 | |
| 22 | // HMODULE from DllMain/WinMain. This is needed to find our dialog resource. |
| 23 | // This is defined in: |
| 24 | // Plugin: host_plugin.cc |
| 25 | // SimpleHost: simple_host_process.cc |
| 26 | extern HMODULE g_hModule; |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 27 | |
| 28 | namespace remoting { |
| 29 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 30 | class ContinueWindowWin : public ContinueWindow { |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 31 | public: |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 32 | ContinueWindowWin(); |
| 33 | virtual ~ContinueWindowWin(); |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 34 | |
[email protected] | 1bafb3c | 2011-11-23 23:39:50 | [diff] [blame] | 35 | virtual void Show(remoting::ChromotingHost* host, |
| 36 | const ContinueSessionCallback& callback) OVERRIDE; |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 37 | virtual void Hide() OVERRIDE; |
| 38 | |
| 39 | private: |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 40 | static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, |
| 41 | LPARAM lParam); |
| 42 | |
| 43 | BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
| 44 | |
| 45 | void EndDialog(); |
[email protected] | 29b0582 | 2011-09-09 18:17:05 | [diff] [blame] | 46 | void SetStrings(const UiStrings& strings); |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 47 | |
| 48 | remoting::ChromotingHost* host_; |
[email protected] | 1bafb3c | 2011-11-23 23:39:50 | [diff] [blame] | 49 | ContinueSessionCallback callback_; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 50 | HWND hwnd_; |
| 51 | |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 52 | DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); |
| 53 | }; |
| 54 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 55 | ContinueWindowWin::ContinueWindowWin() |
| 56 | : host_(NULL), |
| 57 | hwnd_(NULL) { |
| 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) { |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 83 | case WM_CLOSE: |
| 84 | // Ignore close messages. |
| 85 | return TRUE; |
| 86 | case WM_DESTROY: |
| 87 | // Ensure we don't try to use the HWND anymore. |
| 88 | hwnd_ = NULL; |
| 89 | return TRUE; |
| 90 | case WM_COMMAND: |
| 91 | switch (LOWORD(wParam)) { |
[email protected] | ac6eedd1 | 2011-07-06 22:19:14 | [diff] [blame] | 92 | case IDC_CONTINUE_DEFAULT: |
[email protected] | 1bafb3c | 2011-11-23 23:39:50 | [diff] [blame] | 93 | callback_.Run(true); |
[email protected] | 29b0582 | 2011-09-09 18:17:05 | [diff] [blame] | 94 | ::EndDialog(hwnd, LOWORD(wParam)); |
| 95 | hwnd_ = NULL; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 96 | return TRUE; |
[email protected] | ac6eedd1 | 2011-07-06 22:19:14 | [diff] [blame] | 97 | case IDC_CONTINUE_CANCEL: |
[email protected] | 1bafb3c | 2011-11-23 23:39:50 | [diff] [blame] | 98 | callback_.Run(false); |
[email protected] | 29b0582 | 2011-09-09 18:17:05 | [diff] [blame] | 99 | ::EndDialog(hwnd, LOWORD(wParam)); |
| 100 | hwnd_ = NULL; |
[email protected] | ac6eedd1 | 2011-07-06 22:19:14 | [diff] [blame] | 101 | return TRUE; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | return FALSE; |
| 105 | } |
| 106 | |
[email protected] | 1bafb3c | 2011-11-23 23:39:50 | [diff] [blame] | 107 | void ContinueWindowWin::Show(ChromotingHost* host, |
| 108 | const ContinueSessionCallback& callback) { |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 109 | host_ = host; |
[email protected] | 1bafb3c | 2011-11-23 23:39:50 | [diff] [blame] | 110 | callback_ = callback; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 111 | |
| 112 | CHECK(!hwnd_); |
| 113 | hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_CONTINUE), NULL, |
| 114 | (DLGPROC)DialogProc, (LPARAM)this); |
| 115 | if (!hwnd_) { |
| 116 | LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; |
| 117 | return; |
| 118 | } |
| 119 | |
[email protected] | 29b0582 | 2011-09-09 18:17:05 | [diff] [blame] | 120 | SetStrings(host->ui_strings()); |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 121 | ShowWindow(hwnd_, SW_SHOW); |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void ContinueWindowWin::Hide() { |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 125 | EndDialog(); |
| 126 | } |
| 127 | |
| 128 | void ContinueWindowWin::EndDialog() { |
| 129 | if (hwnd_) { |
| 130 | ::EndDialog(hwnd_, 0); |
| 131 | hwnd_ = NULL; |
| 132 | } |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | 29b0582 | 2011-09-09 18:17:05 | [diff] [blame] | 135 | void ContinueWindowWin::SetStrings(const UiStrings& strings) { |
| 136 | SetWindowText(hwnd_, strings.product_name.c_str()); |
| 137 | |
| 138 | HWND hwndMessage = GetDlgItem(hwnd_, IDC_CONTINUE_MESSAGE); |
| 139 | CHECK(hwndMessage); |
| 140 | SetWindowText(hwndMessage, strings.continue_prompt.c_str()); |
| 141 | |
| 142 | HWND hwndDefault = GetDlgItem(hwnd_, IDC_CONTINUE_DEFAULT); |
| 143 | CHECK(hwndDefault); |
| 144 | SetWindowText(hwndDefault, strings.continue_button_text.c_str()); |
| 145 | |
| 146 | HWND hwndCancel = GetDlgItem(hwnd_, IDC_CONTINUE_CANCEL); |
| 147 | CHECK(hwndCancel); |
| 148 | SetWindowText(hwndCancel, strings.stop_sharing_button_text.c_str()); |
| 149 | } |
| 150 | |
[email protected] | 3361e1f | 2012-03-20 20:31:44 | [diff] [blame] | 151 | scoped_ptr<ContinueWindow> ContinueWindow::Create() { |
| 152 | return scoped_ptr<ContinueWindow>(new ContinueWindowWin()); |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | } // namespace remoting |