Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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" | |
| 6 | |
| 7 #include <windows.h> | 5 #include <windows.h> |
| 8 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/location.h" | |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/single_thread_task_runner.h" | |
| 12 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "remoting/host/continue_window.h" | |
| 13 #include "remoting/host/ui_strings.h" | 16 #include "remoting/host/ui_strings.h" |
| 14 #include "remoting/host/win/core_resource.h" | 17 #include "remoting/host/win/core_resource.h" |
| 15 | 18 |
| 16 // TODO(garykac): Lots of duplicated code in this file and | 19 namespace remoting { |
| 17 // disconnect_window_win.cc. These global floating windows are temporary so | |
| 18 // they should be deleted soon. If we need to expand this then we should | |
| 19 // create a class with the shared code. | |
| 20 | 20 |
| 21 namespace remoting { | 21 namespace { |
| 22 | 22 |
| 23 class ContinueWindowWin : public ContinueWindow { | 23 class ContinueWindowWin : public ContinueWindow { |
| 24 public: | 24 public: |
| 25 explicit ContinueWindowWin(const UiStrings* ui_strings); | 25 explicit ContinueWindowWin(const UiStrings& ui_strings); |
| 26 virtual ~ContinueWindowWin(); | 26 virtual ~ContinueWindowWin(); |
| 27 | 27 |
| 28 virtual void Show(const ContinueSessionCallback& callback) OVERRIDE; | 28 protected: |
| 29 virtual void Hide() OVERRIDE; | 29 // ContinueWindow overrides. |
| 30 virtual void ShowUi() OVERRIDE; | |
| 31 virtual void HideUi() OVERRIDE; | |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, | 34 static BOOL CALLBACK DialogProc(HWND hwmd, UINT msg, WPARAM wParam, |
| 33 LPARAM lParam); | 35 LPARAM lParam); |
| 34 | 36 |
| 35 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); | 37 BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
| 36 | 38 |
| 37 void EndDialog(); | 39 void EndDialog(); |
| 38 void SetStrings(); | 40 void SetStrings(); |
| 39 | 41 |
| 40 ContinueSessionCallback callback_; | |
| 41 HWND hwnd_; | 42 HWND hwnd_; |
| 42 | 43 |
| 43 // Points to the localized strings. | 44 // Localized UI strings. |
| 44 const UiStrings* ui_strings_; | 45 UiStrings ui_strings_; |
|
Sergey Ulanov
2013/04/04 21:04:26
Can this be moved to the base class?
alexeypa (please no reviews)
2013/04/06 18:07:56
Done.
| |
| 45 | 46 |
| 46 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); | 47 DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 ContinueWindowWin::ContinueWindowWin(const UiStrings* ui_strings) | 50 ContinueWindowWin::ContinueWindowWin(const UiStrings& ui_strings) |
| 50 : hwnd_(NULL), | 51 : hwnd_(NULL), |
| 51 ui_strings_(ui_strings) { | 52 ui_strings_(ui_strings) { |
| 52 } | 53 } |
| 53 | 54 |
| 54 ContinueWindowWin::~ContinueWindowWin() { | 55 ContinueWindowWin::~ContinueWindowWin() { |
| 55 EndDialog(); | 56 EndDialog(); |
| 56 } | 57 } |
| 57 | 58 |
| 59 void ContinueWindowWin::ShowUi() { | |
| 60 DCHECK(CalledOnValidThread()); | |
| 61 DCHECK(!hwnd_); | |
| 62 | |
| 63 HMODULE instance = base::GetModuleFromAddress(&DialogProc); | |
| 64 hwnd_ = CreateDialogParam(instance, MAKEINTRESOURCE(IDD_CONTINUE), NULL, | |
| 65 (DLGPROC)DialogProc, (LPARAM)this); | |
| 66 if (!hwnd_) { | |
| 67 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; | |
| 68 return; | |
| 69 } | |
| 70 | |
| 71 SetStrings(); | |
| 72 ShowWindow(hwnd_, SW_SHOW); | |
| 73 } | |
| 74 | |
| 75 void ContinueWindowWin::HideUi() { | |
| 76 DCHECK(CalledOnValidThread()); | |
| 77 | |
| 78 EndDialog(); | |
| 79 } | |
| 80 | |
| 58 BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg, | 81 BOOL CALLBACK ContinueWindowWin::DialogProc(HWND hwnd, UINT msg, |
| 59 WPARAM wParam, LPARAM lParam) { | 82 WPARAM wParam, LPARAM lParam) { |
| 60 ContinueWindowWin* win = NULL; | 83 ContinueWindowWin* win = NULL; |
| 61 if (msg == WM_INITDIALOG) { | 84 if (msg == WM_INITDIALOG) { |
| 62 win = reinterpret_cast<ContinueWindowWin*>(lParam); | 85 win = reinterpret_cast<ContinueWindowWin*>(lParam); |
| 63 CHECK(win); | 86 CHECK(win); |
| 64 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); | 87 SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win); |
| 65 } else { | 88 } else { |
| 66 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); | 89 LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER); |
| 67 win = reinterpret_cast<ContinueWindowWin*>(lp); | 90 win = reinterpret_cast<ContinueWindowWin*>(lp); |
| 68 } | 91 } |
| 69 if (win == NULL) | 92 if (win == NULL) |
| 70 return FALSE; | 93 return FALSE; |
| 71 return win->OnDialogMessage(hwnd, msg, wParam, lParam); | 94 return win->OnDialogMessage(hwnd, msg, wParam, lParam); |
| 72 } | 95 } |
| 73 | 96 |
| 74 BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, | 97 BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, |
| 75 WPARAM wParam, LPARAM lParam) { | 98 WPARAM wParam, LPARAM lParam) { |
| 99 DCHECK(CalledOnValidThread()); | |
| 100 | |
| 76 switch (msg) { | 101 switch (msg) { |
| 77 case WM_CLOSE: | 102 case WM_CLOSE: |
| 78 // Ignore close messages. | 103 // Ignore close messages. |
| 79 return TRUE; | 104 return TRUE; |
| 80 case WM_DESTROY: | 105 case WM_DESTROY: |
| 81 // Ensure we don't try to use the HWND anymore. | 106 // Ensure we don't try to use the HWND anymore. |
| 82 hwnd_ = NULL; | 107 hwnd_ = NULL; |
| 83 return TRUE; | 108 return TRUE; |
| 84 case WM_COMMAND: | 109 case WM_COMMAND: |
| 85 switch (LOWORD(wParam)) { | 110 switch (LOWORD(wParam)) { |
| 86 case IDC_CONTINUE_DEFAULT: | 111 case IDC_CONTINUE_DEFAULT: |
| 87 callback_.Run(true); | 112 ContinueSession(); |
| 88 ::EndDialog(hwnd, LOWORD(wParam)); | 113 ::EndDialog(hwnd, LOWORD(wParam)); |
| 89 hwnd_ = NULL; | 114 hwnd_ = NULL; |
| 90 return TRUE; | 115 return TRUE; |
| 91 case IDC_CONTINUE_CANCEL: | 116 case IDC_CONTINUE_CANCEL: |
| 92 callback_.Run(false); | 117 DisconnectSession(); |
| 93 ::EndDialog(hwnd, LOWORD(wParam)); | 118 ::EndDialog(hwnd, LOWORD(wParam)); |
| 94 hwnd_ = NULL; | 119 hwnd_ = NULL; |
| 95 return TRUE; | 120 return TRUE; |
| 96 } | 121 } |
| 97 } | 122 } |
| 98 return FALSE; | 123 return FALSE; |
| 99 } | 124 } |
| 100 | 125 |
| 101 void ContinueWindowWin::Show(const ContinueSessionCallback& callback) { | 126 void ContinueWindowWin::EndDialog() { |
| 102 callback_ = callback; | 127 DCHECK(CalledOnValidThread()); |
| 103 | 128 |
| 104 HMODULE instance = base::GetModuleFromAddress(&DialogProc); | |
| 105 | |
| 106 CHECK(!hwnd_); | |
| 107 hwnd_ = CreateDialogParam(instance, MAKEINTRESOURCE(IDD_CONTINUE), NULL, | |
| 108 (DLGPROC)DialogProc, (LPARAM)this); | |
| 109 if (!hwnd_) { | |
| 110 LOG(ERROR) << "Unable to create Disconnect dialog for remoting."; | |
| 111 return; | |
| 112 } | |
| 113 | |
| 114 SetStrings(); | |
| 115 ShowWindow(hwnd_, SW_SHOW); | |
| 116 } | |
| 117 | |
| 118 void ContinueWindowWin::Hide() { | |
| 119 EndDialog(); | |
| 120 } | |
| 121 | |
| 122 void ContinueWindowWin::EndDialog() { | |
| 123 if (hwnd_) { | 129 if (hwnd_) { |
| 124 ::DestroyWindow(hwnd_); | 130 ::DestroyWindow(hwnd_); |
| 125 hwnd_ = NULL; | 131 hwnd_ = NULL; |
| 126 } | 132 } |
| 127 } | 133 } |
| 128 | 134 |
| 129 void ContinueWindowWin::SetStrings() { | 135 void ContinueWindowWin::SetStrings() { |
| 130 SetWindowText(hwnd_, ui_strings_->product_name.c_str()); | 136 DCHECK(CalledOnValidThread()); |
| 137 | |
| 138 SetWindowText(hwnd_, ui_strings_.product_name.c_str()); | |
| 131 | 139 |
| 132 HWND hwndMessage = GetDlgItem(hwnd_, IDC_CONTINUE_MESSAGE); | 140 HWND hwndMessage = GetDlgItem(hwnd_, IDC_CONTINUE_MESSAGE); |
| 133 CHECK(hwndMessage); | 141 CHECK(hwndMessage); |
| 134 SetWindowText(hwndMessage, ui_strings_->continue_prompt.c_str()); | 142 SetWindowText(hwndMessage, ui_strings_.continue_prompt.c_str()); |
| 135 | 143 |
| 136 HWND hwndDefault = GetDlgItem(hwnd_, IDC_CONTINUE_DEFAULT); | 144 HWND hwndDefault = GetDlgItem(hwnd_, IDC_CONTINUE_DEFAULT); |
| 137 CHECK(hwndDefault); | 145 CHECK(hwndDefault); |
| 138 SetWindowText(hwndDefault, ui_strings_->continue_button_text.c_str()); | 146 SetWindowText(hwndDefault, ui_strings_.continue_button_text.c_str()); |
| 139 | 147 |
| 140 HWND hwndCancel = GetDlgItem(hwnd_, IDC_CONTINUE_CANCEL); | 148 HWND hwndCancel = GetDlgItem(hwnd_, IDC_CONTINUE_CANCEL); |
| 141 CHECK(hwndCancel); | 149 CHECK(hwndCancel); |
| 142 SetWindowText(hwndCancel, ui_strings_->stop_sharing_button_text.c_str()); | 150 SetWindowText(hwndCancel, ui_strings_.stop_sharing_button_text.c_str()); |
| 143 } | 151 } |
| 144 | 152 |
| 145 scoped_ptr<ContinueWindow> ContinueWindow::Create(const UiStrings* ui_strings) { | 153 } // namespace |
| 146 return scoped_ptr<ContinueWindow>(new ContinueWindowWin(ui_strings)); | 154 |
| 155 // static | |
| 156 scoped_ptr<HostWindow> HostWindow::CreateContinueWindow( | |
| 157 const UiStrings& ui_strings) { | |
| 158 return scoped_ptr<HostWindow>(new ContinueWindowWin(ui_strings)); | |
| 147 } | 159 } |
| 148 | 160 |
| 149 } // namespace remoting | 161 } // namespace remoting |
| OLD | NEW |