[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 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 5 | #include "remoting/host/continue_window.h" |
| 6 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 7 | #include <windows.h> |
| 8 | |
Jinho Bang | 138fde3 | 2018-01-18 23:13:42 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/callback.h" |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 13 | #include "base/compiler_specific.h" |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 14 | #include "base/location.h" |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 15 | #include "base/logging.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
Patrick Monette | 643cdf6 | 2021-10-15 19:13:42 | [diff] [blame] | 17 | #include "base/task/single_thread_task_runner.h" |
thakis | d62f5447 | 2016-04-04 02:21:10 | [diff] [blame] | 18 | #include "base/win/current_module.h" |
[email protected] | 45936ac | 2013-02-04 19:07:30 | [diff] [blame] | 19 | #include "remoting/host/win/core_resource.h" |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 20 | |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 21 | namespace remoting { |
| 22 | |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 23 | namespace { |
| 24 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 25 | class ContinueWindowWin : public ContinueWindow { |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 26 | public: |
[email protected] | fc877cf | 2013-07-31 23:08:39 | [diff] [blame] | 27 | ContinueWindowWin(); |
Peter Boström | e9178e4 | 2021-09-22 18:11:49 | [diff] [blame] | 28 | |
| 29 | ContinueWindowWin(const ContinueWindowWin&) = delete; |
| 30 | ContinueWindowWin& operator=(const ContinueWindowWin&) = delete; |
| 31 | |
nick | 697f429 | 2015-04-23 18:22:31 | [diff] [blame] | 32 | ~ContinueWindowWin() override; |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 33 | |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 34 | protected: |
| 35 | // ContinueWindow overrides. |
nick | 697f429 | 2015-04-23 18:22:31 | [diff] [blame] | 36 | void ShowUi() override; |
| 37 | void HideUi() override; |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 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(); |
| 46 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 47 | HWND hwnd_; |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 48 | }; |
| 49 | |
[email protected] | fc877cf | 2013-07-31 23:08:39 | [diff] [blame] | 50 | ContinueWindowWin::ContinueWindowWin() |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 51 | : hwnd_(nullptr) { |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | ContinueWindowWin::~ContinueWindowWin() { |
| 55 | EndDialog(); |
| 56 | } |
| 57 | |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 58 | void ContinueWindowWin::ShowUi() { |
gab | bf77513a | 2017-06-01 14:35:34 | [diff] [blame] | 59 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 60 | DCHECK(!hwnd_); |
| 61 | |
thakis | d62f5447 | 2016-04-04 02:21:10 | [diff] [blame] | 62 | hwnd_ = CreateDialogParam(CURRENT_MODULE(), MAKEINTRESOURCE(IDD_CONTINUE), |
| 63 | nullptr, (DLGPROC)DialogProc, (LPARAM) this); |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 64 | if (!hwnd_) { |
| 65 | LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; |
| 66 | return; |
| 67 | } |
| 68 | |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 69 | ShowWindow(hwnd_, SW_SHOW); |
| 70 | } |
| 71 | |
| 72 | void ContinueWindowWin::HideUi() { |
gab | bf77513a | 2017-06-01 14:35:34 | [diff] [blame] | 73 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 74 | |
| 75 | EndDialog(); |
| 76 | } |
| 77 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 78 | BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg, |
| 79 | WPARAM wParam, LPARAM lParam) { |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 80 | ContinueWindowWin* win = nullptr; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 81 | if (msg == WM_INITDIALOG) { |
| 82 | win = reinterpret_cast<ContinueWindowWin*>(lParam); |
| 83 | CHECK(win); |
| 84 | SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); |
| 85 | } else { |
| 86 | LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); |
| 87 | win = reinterpret_cast<ContinueWindowWin*>(lp); |
| 88 | } |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 89 | if (win == nullptr) |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 90 | return FALSE; |
| 91 | return win->OnDialogMessage(hwnd, msg, wParam, lParam); |
| 92 | } |
| 93 | |
| 94 | BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, |
| 95 | WPARAM wParam, LPARAM lParam) { |
gab | bf77513a | 2017-06-01 14:35:34 | [diff] [blame] | 96 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 97 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 98 | switch (msg) { |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 99 | case WM_CLOSE: |
| 100 | // Ignore close messages. |
| 101 | return TRUE; |
| 102 | case WM_DESTROY: |
| 103 | // Ensure we don't try to use the HWND anymore. |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 104 | hwnd_ = nullptr; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 105 | return TRUE; |
| 106 | case WM_COMMAND: |
| 107 | switch (LOWORD(wParam)) { |
[email protected] | ac6eedd1 | 2011-07-06 22:19:14 | [diff] [blame] | 108 | case IDC_CONTINUE_DEFAULT: |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 109 | ContinueSession(); |
[email protected] | 29b0582 | 2011-09-09 18:17:05 | [diff] [blame] | 110 | ::EndDialog(hwnd, LOWORD(wParam)); |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 111 | hwnd_ = nullptr; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 112 | return TRUE; |
[email protected] | ac6eedd1 | 2011-07-06 22:19:14 | [diff] [blame] | 113 | case IDC_CONTINUE_CANCEL: |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 114 | DisconnectSession(); |
[email protected] | 29b0582 | 2011-09-09 18:17:05 | [diff] [blame] | 115 | ::EndDialog(hwnd, LOWORD(wParam)); |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 116 | hwnd_ = nullptr; |
[email protected] | ac6eedd1 | 2011-07-06 22:19:14 | [diff] [blame] | 117 | return TRUE; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | return FALSE; |
| 121 | } |
| 122 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 123 | void ContinueWindowWin::EndDialog() { |
gab | bf77513a | 2017-06-01 14:35:34 | [diff] [blame] | 124 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 125 | |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 126 | if (hwnd_) { |
[email protected] | c3041a1 | 2012-05-11 23:01:45 | [diff] [blame] | 127 | ::DestroyWindow(hwnd_); |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 128 | hwnd_ = nullptr; |
[email protected] | 0e6a47e | 2011-06-22 22:30:38 | [diff] [blame] | 129 | } |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | ac115ce | 2013-04-24 20:44:38 | [diff] [blame] | 132 | } // namespace |
| 133 | |
| 134 | // static |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 135 | std::unique_ptr<HostWindow> HostWindow::CreateContinueWindow() { |
Jinho Bang | 138fde3 | 2018-01-18 23:13:42 | [diff] [blame] | 136 | return std::make_unique<ContinueWindowWin>(); |
[email protected] | 38a4d77 | 2011-06-16 21:25:34 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | } // namespace remoting |