blob: e2fd353e4a1f058c3afbf2508317e0882177a372 [file] [log] [blame]
[email protected]3361e1f2012-03-20 20:31:441// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]38a4d772011-06-16 21:25:342// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
dcheng0765c492016-04-06 22:41:535#include "remoting/host/continue_window.h"
6
[email protected]0e6a47e2011-06-22 22:30:387#include <windows.h>
8
Jinho Bang138fde32018-01-18 23:13:429#include <memory>
10
[email protected]ac115ce2013-04-24 20:44:3811#include "base/bind.h"
12#include "base/callback.h"
[email protected]38a4d772011-06-16 21:25:3413#include "base/compiler_specific.h"
[email protected]ac115ce2013-04-24 20:44:3814#include "base/location.h"
[email protected]38a4d772011-06-16 21:25:3415#include "base/logging.h"
[email protected]906265872013-06-07 22:40:4516#include "base/strings/utf_string_conversions.h"
Patrick Monette643cdf62021-10-15 19:13:4217#include "base/task/single_thread_task_runner.h"
thakisd62f54472016-04-04 02:21:1018#include "base/win/current_module.h"
[email protected]45936ac2013-02-04 19:07:3019#include "remoting/host/win/core_resource.h"
[email protected]0e6a47e2011-06-22 22:30:3820
[email protected]38a4d772011-06-16 21:25:3421namespace remoting {
22
[email protected]ac115ce2013-04-24 20:44:3823namespace {
24
[email protected]0e6a47e2011-06-22 22:30:3825class ContinueWindowWin : public ContinueWindow {
[email protected]38a4d772011-06-16 21:25:3426 public:
[email protected]fc877cf2013-07-31 23:08:3927 ContinueWindowWin();
Peter Boströme9178e42021-09-22 18:11:4928
29 ContinueWindowWin(const ContinueWindowWin&) = delete;
30 ContinueWindowWin& operator=(const ContinueWindowWin&) = delete;
31
nick697f4292015-04-23 18:22:3132 ~ContinueWindowWin() override;
[email protected]38a4d772011-06-16 21:25:3433
[email protected]ac115ce2013-04-24 20:44:3834 protected:
35 // ContinueWindow overrides.
nick697f4292015-04-23 18:22:3136 void ShowUi() override;
37 void HideUi() override;
[email protected]38a4d772011-06-16 21:25:3438
39 private:
[email protected]0e6a47e2011-06-22 22:30:3840 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]0e6a47e2011-06-22 22:30:3847 HWND hwnd_;
[email protected]38a4d772011-06-16 21:25:3448};
49
[email protected]fc877cf2013-07-31 23:08:3950ContinueWindowWin::ContinueWindowWin()
sergeyuc5f104b2015-01-09 19:33:2451 : hwnd_(nullptr) {
[email protected]0e6a47e2011-06-22 22:30:3852}
53
54ContinueWindowWin::~ContinueWindowWin() {
55 EndDialog();
56}
57
[email protected]ac115ce2013-04-24 20:44:3858void ContinueWindowWin::ShowUi() {
gabbf77513a2017-06-01 14:35:3459 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]ac115ce2013-04-24 20:44:3860 DCHECK(!hwnd_);
61
thakisd62f54472016-04-04 02:21:1062 hwnd_ = CreateDialogParam(CURRENT_MODULE(), MAKEINTRESOURCE(IDD_CONTINUE),
63 nullptr, (DLGPROC)DialogProc, (LPARAM) this);
[email protected]ac115ce2013-04-24 20:44:3864 if (!hwnd_) {
65 LOG(ERROR) << "Unable to create Disconnect dialog for remoting.";
66 return;
67 }
68
[email protected]ac115ce2013-04-24 20:44:3869 ShowWindow(hwnd_, SW_SHOW);
70}
71
72void ContinueWindowWin::HideUi() {
gabbf77513a2017-06-01 14:35:3473 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]ac115ce2013-04-24 20:44:3874
75 EndDialog();
76}
77
[email protected]0e6a47e2011-06-22 22:30:3878BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg,
79 WPARAM wParam, LPARAM lParam) {
sergeyuc5f104b2015-01-09 19:33:2480 ContinueWindowWin* win = nullptr;
[email protected]0e6a47e2011-06-22 22:30:3881 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 }
sergeyuc5f104b2015-01-09 19:33:2489 if (win == nullptr)
[email protected]0e6a47e2011-06-22 22:30:3890 return FALSE;
91 return win->OnDialogMessage(hwnd, msg, wParam, lParam);
92}
93
94BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
95 WPARAM wParam, LPARAM lParam) {
gabbf77513a2017-06-01 14:35:3496 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]ac115ce2013-04-24 20:44:3897
[email protected]0e6a47e2011-06-22 22:30:3898 switch (msg) {
[email protected]0e6a47e2011-06-22 22:30:3899 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.
sergeyuc5f104b2015-01-09 19:33:24104 hwnd_ = nullptr;
[email protected]0e6a47e2011-06-22 22:30:38105 return TRUE;
106 case WM_COMMAND:
107 switch (LOWORD(wParam)) {
[email protected]ac6eedd12011-07-06 22:19:14108 case IDC_CONTINUE_DEFAULT:
[email protected]ac115ce2013-04-24 20:44:38109 ContinueSession();
[email protected]29b05822011-09-09 18:17:05110 ::EndDialog(hwnd, LOWORD(wParam));
sergeyuc5f104b2015-01-09 19:33:24111 hwnd_ = nullptr;
[email protected]0e6a47e2011-06-22 22:30:38112 return TRUE;
[email protected]ac6eedd12011-07-06 22:19:14113 case IDC_CONTINUE_CANCEL:
[email protected]ac115ce2013-04-24 20:44:38114 DisconnectSession();
[email protected]29b05822011-09-09 18:17:05115 ::EndDialog(hwnd, LOWORD(wParam));
sergeyuc5f104b2015-01-09 19:33:24116 hwnd_ = nullptr;
[email protected]ac6eedd12011-07-06 22:19:14117 return TRUE;
[email protected]0e6a47e2011-06-22 22:30:38118 }
119 }
120 return FALSE;
121}
122
[email protected]0e6a47e2011-06-22 22:30:38123void ContinueWindowWin::EndDialog() {
gabbf77513a2017-06-01 14:35:34124 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]ac115ce2013-04-24 20:44:38125
[email protected]0e6a47e2011-06-22 22:30:38126 if (hwnd_) {
[email protected]c3041a12012-05-11 23:01:45127 ::DestroyWindow(hwnd_);
sergeyuc5f104b2015-01-09 19:33:24128 hwnd_ = nullptr;
[email protected]0e6a47e2011-06-22 22:30:38129 }
[email protected]38a4d772011-06-16 21:25:34130}
131
[email protected]ac115ce2013-04-24 20:44:38132} // namespace
133
134// static
dcheng0765c492016-04-06 22:41:53135std::unique_ptr<HostWindow> HostWindow::CreateContinueWindow() {
Jinho Bang138fde32018-01-18 23:13:42136 return std::make_unique<ContinueWindowWin>();
[email protected]38a4d772011-06-16 21:25:34137}
138
139} // namespace remoting