| 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 SetWindowText(LoadStringFromResource(IDS_TITLE)); |
| 41 GetDlgItem(IDC_CONSENT).SetWindowText(LoadStringFromResource(IDS_CONSENT)); |
| 42 CheckDlgButton(IDC_CONSENT, BST_CHECKED); |
| 43 return TRUE; |
| 44 } |
| 45 |
| 46 void StartHostWindow::OnConsent(UINT code, int id, HWND control) { |
| 47 bool checked = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED); |
| 48 checked = !checked; |
| 49 CheckDlgButton(IDC_CONSENT, checked ? BST_CHECKED : BST_UNCHECKED); |
| 50 } |
| 51 |
| 52 void StartHostWindow::OnOk(UINT code, int id, HWND control) { |
| 53 host_name_ = GetDlgItemString(IDC_HOST_NAME); |
| 54 pin_ = GetDlgItemString(IDC_PIN); |
| 55 std::string confirm_pin = GetDlgItemString(IDC_CONFIRM_PIN); |
| 56 consent_to_collect_data_ = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED); |
| 57 if (pin_ != confirm_pin) { |
| 58 MessageBox(LoadStringFromResource(IDS_SAME_PIN), |
| 59 LoadStringFromResource(IDS_TITLE), |
| 60 MB_ICONEXCLAMATION | MB_OK); |
| 61 return; |
| 62 } |
| 63 if (!IsPinValid(pin_)) { |
| 64 MessageBox(LoadStringFromResource(IDS_INVALID_PIN), |
| 65 LoadStringFromResource(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK); |
| 66 return; |
| 67 } |
| 68 MessageBox(LoadStringFromResource(IDS_USE_BROWSER), |
| 69 LoadStringFromResource(IDS_TITLE), MB_OK); |
| 70 auth_code_getter_.GetAuthCode( |
| 71 base::Bind(&StartHostWindow::OnAuthCode, weak_ptr_)); |
| 72 } |
| 73 |
| 74 void StartHostWindow::OnAuthCode(const std::string& auth_code) { |
| 75 host_starter_->StartHost( |
| 76 host_name_, pin_, consent_to_collect_data_, auth_code, |
| 77 base::Bind(&StartHostWindow::OnHostStarted, weak_ptr_), |
| 78 ui_task_runner_); |
| 79 } |
| 80 |
| 81 void StartHostWindow::OnHostStarted(remoting::HostStarter::Result result) { |
| 82 if (result == remoting::HostStarter::START_COMPLETE) { |
| 83 MessageBox(LoadStringFromResource(IDS_HOST_START_SUCCEEDED), |
| 84 LoadStringFromResource(IDS_TITLE), MB_OK); |
| 85 EndDialog(IDOK); |
| 86 } else { |
| 87 MessageBox(LoadStringFromResource(IDS_HOST_START_FAILED), |
| 88 LoadStringFromResource(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK); |
| 89 } |
| 90 } |
| 91 |
| 92 std::string StartHostWindow::GetDlgItemString(int id) { |
| 93 CSimpleString str(L"", &string_mgr_); |
| 94 GetDlgItemText(id, str); |
| 95 return UTF16ToUTF8(str.GetString()); |
| 96 } |
| 97 |
| 98 } // namespace remoting |
| OLD | NEW |