Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / continue_window_win.cc
blob36aaba91f637c7d3573ba3854d04b85b357e2833
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <windows.h>
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "base/process/memory.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "remoting/host/continue_window.h"
16 #include "remoting/host/win/core_resource.h"
18 namespace remoting {
20 namespace {
22 class ContinueWindowWin : public ContinueWindow {
23 public:
24 ContinueWindowWin();
25 ~ContinueWindowWin() override;
27 protected:
28 // ContinueWindow overrides.
29 void ShowUi() override;
30 void HideUi() override;
32 private:
33 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam,
34 LPARAM lParam);
36 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
38 void EndDialog();
40 HWND hwnd_;
42 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin);
45 ContinueWindowWin::ContinueWindowWin()
46 : hwnd_(nullptr) {
49 ContinueWindowWin::~ContinueWindowWin() {
50 EndDialog();
53 void ContinueWindowWin::ShowUi() {
54 DCHECK(CalledOnValidThread());
55 DCHECK(!hwnd_);
57 HMODULE instance = base::GetModuleFromAddress(&DialogProc);
58 hwnd_ = CreateDialogParam(instance, MAKEINTRESOURCE(IDD_CONTINUE), nullptr,
59 (DLGPROC)DialogProc, (LPARAM)this);
60 if (!hwnd_) {
61 LOG(ERROR) << "Unable to create Disconnect dialog for remoting.";
62 return;
65 ShowWindow(hwnd_, SW_SHOW);
68 void ContinueWindowWin::HideUi() {
69 DCHECK(CalledOnValidThread());
71 EndDialog();
74 BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg,
75 WPARAM wParam, LPARAM lParam) {
76 ContinueWindowWin* win = nullptr;
77 if (msg == WM_INITDIALOG) {
78 win = reinterpret_cast<ContinueWindowWin*>(lParam);
79 CHECK(win);
80 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win);
81 } else {
82 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER);
83 win = reinterpret_cast<ContinueWindowWin*>(lp);
85 if (win == nullptr)
86 return FALSE;
87 return win->OnDialogMessage(hwnd, msg, wParam, lParam);
90 BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
91 WPARAM wParam, LPARAM lParam) {
92 DCHECK(CalledOnValidThread());
94 switch (msg) {
95 case WM_CLOSE:
96 // Ignore close messages.
97 return TRUE;
98 case WM_DESTROY:
99 // Ensure we don't try to use the HWND anymore.
100 hwnd_ = nullptr;
101 return TRUE;
102 case WM_COMMAND:
103 switch (LOWORD(wParam)) {
104 case IDC_CONTINUE_DEFAULT:
105 ContinueSession();
106 ::EndDialog(hwnd, LOWORD(wParam));
107 hwnd_ = nullptr;
108 return TRUE;
109 case IDC_CONTINUE_CANCEL:
110 DisconnectSession();
111 ::EndDialog(hwnd, LOWORD(wParam));
112 hwnd_ = nullptr;
113 return TRUE;
116 return FALSE;
119 void ContinueWindowWin::EndDialog() {
120 DCHECK(CalledOnValidThread());
122 if (hwnd_) {
123 ::DestroyWindow(hwnd_);
124 hwnd_ = nullptr;
128 } // namespace
130 // static
131 scoped_ptr<HostWindow> HostWindow::CreateContinueWindow() {
132 return make_scoped_ptr(new ContinueWindowWin());
135 } // namespace remoting