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