| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "remoting/host/setup/win/start_host_window.h" |
| 6 |
| 7 #include <atlbase.h> |
| 8 #include <atlwin.h> |
| 9 #include <windows.h> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string16.h" |
| 13 #include "base/utf_string_conversions.h" |
| 14 #include "remoting/host/setup/pin_validator.h" |
| 15 #include "remoting/host/setup/win/load_string_from_resource.h" |
| 16 |
| 17 namespace remoting { |
| 18 |
| 19 StartHostWindow::StartHostWindow( |
| 20 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 21 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
| 22 : host_starter_(remoting::HostStarter::Create(url_request_context_getter)), |
| 23 consent_to_collect_data_(true), |
| 24 mem_mgr_(GetProcessHeap()), |
| 25 string_mgr_(&mem_mgr_), |
| 26 ui_task_runner_(ui_task_runner), |
| 27 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 28 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { |
| 29 } |
| 30 |
| 31 void StartHostWindow::OnCancel(UINT code, int id, HWND control) { |
| 32 EndDialog(IDCANCEL); |
| 33 } |
| 34 |
| 35 void StartHostWindow::OnClose() { |
| 36 EndDialog(IDCANCEL); |
| 37 } |
| 38 |
| 39 LRESULT StartHostWindow::OnInitDialog(HWND wparam, LPARAM lparam) { |
| 40 // Failure of any of these calls is acceptable. |
| 41 SetWindowText(LoadStringFromResource(IDS_TITLE)); |
| 42 GetDlgItem(IDC_CONSENT).SetWindowText(LoadStringFromResource(IDS_CONSENT)); |
| 43 CheckDlgButton(IDC_CONSENT, BST_CHECKED); |
| 44 return TRUE; |
| 45 } |
| 46 |
| 47 void StartHostWindow::OnConsent(UINT code, int id, HWND control) { |
| 48 bool checked = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED); |
| 49 checked = !checked; |
| 50 CheckDlgButton(IDC_CONSENT, checked ? BST_CHECKED : BST_UNCHECKED); |
| 51 } |
| 52 |
| 53 void StartHostWindow::OnOk(UINT code, int id, HWND control) { |
| 54 host_name_ = GetDlgItemString(IDC_HOST_NAME); |
| 55 pin_ = GetDlgItemString(IDC_PIN); |
| 56 std::string confirm_pin = GetDlgItemString(IDC_CONFIRM_PIN); |
| 57 consent_to_collect_data_ = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED); |
| 58 if (pin_ != confirm_pin) { |
| 59 MessageBox(LoadStringFromResource(IDS_SAME_PIN), |
| 60 LoadStringFromResource(IDS_TITLE), |
| 61 MB_ICONEXCLAMATION | MB_OK); |
| 62 return; |
| 63 } |
| 64 if (!IsPinValid(pin_)) { |
| 65 MessageBox(LoadStringFromResource(IDS_INVALID_PIN), |
| 66 LoadStringFromResource(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK); |
| 67 return; |
| 68 } |
| 69 MessageBox(LoadStringFromResource(IDS_USE_BROWSER), |
| 70 LoadStringFromResource(IDS_TITLE), MB_OK); |
| 71 auth_code_getter_.GetAuthCode( |
| 72 base::Bind(&StartHostWindow::OnAuthCode, weak_ptr_)); |
| 73 } |
| 74 |
| 75 void StartHostWindow::OnAuthCode(const std::string& auth_code) { |
| 76 host_starter_->StartHost( |
| 77 host_name_, pin_, consent_to_collect_data_, auth_code, |
| 78 base::Bind(&StartHostWindow::OnHostStarted, weak_ptr_), |
| 79 ui_task_runner_); |
| 80 } |
| 81 |
| 82 void StartHostWindow::OnHostStarted(remoting::HostStarter::Result result) { |
| 83 if (result == remoting::HostStarter::START_COMPLETE) { |
| 84 MessageBox(LoadStringFromResource(IDS_HOST_START_SUCCEEDED), |
| 85 LoadStringFromResource(IDS_TITLE), MB_OK); |
| 86 EndDialog(IDOK); |
| 87 } else { |
| 88 MessageBox(LoadStringFromResource(IDS_HOST_START_FAILED), |
| 89 LoadStringFromResource(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK); |
| 90 } |
| 91 } |
| 92 |
| 93 std::string StartHostWindow::GetDlgItemString(int id) { |
| 94 CSimpleString str(L"", &string_mgr_); |
| 95 GetDlgItemText(id, str); |
| 96 return UTF16ToUTF8(str.GetString()); |
| 97 } |
| 98 |
| 99 } // namespace remoting |
| OLD | NEW |