Chromium Code Reviews| 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 <atlstr.h> | |
| 9 #include <atlwin.h> | |
| 10 #include <windows.h> | |
| 11 | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/string16.h" | |
| 14 #include "base/utf_string_conversions.h" | |
| 15 #include "remoting/host/setup/pin_validator.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 CAtlString LoadString(int id) { | |
| 20 CAtlString s; | |
| 21 s.LoadString(id); | |
|
alexeypa (please no reviews)
2012/10/12 17:09:35
How do you handle an error returned by LoadString?
simonmorris
2012/10/15 16:51:42
This code has moved to load_string_from_resource.c
| |
| 22 return s; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 namespace remoting { | |
| 28 | |
| 29 StartHostWindow::StartHostWindow( | |
| 30 net::URLRequestContextGetter* url_request_context_getter) | |
| 31 : host_starter_(remoting::HostStarter::Create(url_request_context_getter)), | |
| 32 consent_to_collect_data_(true), | |
| 33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | |
| 34 weak_ptr_(weak_factory_.GetWeakPtr()) { | |
| 35 } | |
| 36 | |
| 37 void StartHostWindow::OnCancel(UINT code, int id, HWND control) { | |
| 38 EndDialog(IDCANCEL); | |
| 39 } | |
| 40 | |
| 41 void StartHostWindow::OnClose() { | |
| 42 EndDialog(IDCANCEL); | |
| 43 } | |
| 44 | |
| 45 LRESULT StartHostWindow::OnInitDialog(HWND wparam, LPARAM lparam) { | |
| 46 SetWindowText(LoadString(IDS_TITLE)); | |
|
alexeypa (please no reviews)
2012/10/12 17:09:35
Same comments as in the other file:
- GetDlgItem r
simonmorris
2012/10/15 16:51:42
Done.
| |
| 47 ::SetWindowText(GetDlgItem(IDC_CONSENT), LoadString(IDS_CONSENT)); | |
| 48 CheckDlgButton(IDC_CONSENT, BST_CHECKED); | |
| 49 return TRUE; | |
| 50 } | |
| 51 | |
| 52 void StartHostWindow::OnConsent(UINT code, int id, HWND control) { | |
| 53 bool checked = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED); | |
| 54 checked = !checked; | |
| 55 CheckDlgButton(IDC_CONSENT, checked ? BST_CHECKED : BST_UNCHECKED); | |
| 56 } | |
| 57 | |
| 58 void StartHostWindow::OnOk(UINT code, int id, HWND control) { | |
| 59 host_name_ = GetDlgItemString(IDC_HOST_NAME); | |
| 60 pin_ = GetDlgItemString(IDC_PIN); | |
| 61 std::string confirm_pin = GetDlgItemString(IDC_CONFIRM_PIN); | |
| 62 consent_to_collect_data_ = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED); | |
| 63 if (pin_ != confirm_pin) { | |
| 64 MessageBox(LoadString(IDS_SAME_PIN), LoadString(IDS_TITLE), | |
| 65 MB_ICONEXCLAMATION | MB_OK); | |
| 66 return; | |
| 67 } | |
| 68 if (!IsPinValid(pin_)) { | |
| 69 MessageBox(LoadString(IDS_INVALID_PIN), | |
| 70 LoadString(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK); | |
| 71 return; | |
| 72 } | |
| 73 MessageBox(LoadString(IDS_USE_BROWSER), | |
| 74 LoadString(IDS_TITLE), MB_OK); | |
| 75 auth_code_getter_.GetAuthCode( | |
| 76 base::Bind(&StartHostWindow::OnAuthCode, weak_ptr_)); | |
| 77 } | |
| 78 | |
| 79 void StartHostWindow::OnAuthCode(const std::string& auth_code) { | |
| 80 host_starter_->StartHost( | |
| 81 host_name_, pin_, consent_to_collect_data_, auth_code, | |
| 82 base::Bind(&StartHostWindow::OnHostStarted, weak_ptr_)); | |
| 83 } | |
| 84 | |
| 85 void StartHostWindow::OnHostStarted(remoting::HostStarter::Result result) { | |
| 86 if (result == remoting::HostStarter::START_COMPLETE) { | |
| 87 MessageBox(LoadString(IDS_HOST_START_SUCCEEDED), | |
| 88 LoadString(IDS_TITLE), MB_OK); | |
| 89 EndDialog(IDOK); | |
| 90 } else { | |
| 91 MessageBox(LoadString(IDS_HOST_START_FAILED), | |
| 92 LoadString(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 std::string StartHostWindow::GetDlgItemString(int id) { | |
| 97 CWindow control(GetDlgItem(id)); | |
| 98 int length = control.GetWindowTextLength(); | |
| 99 scoped_array<char16> str(new char16[length + 1]); | |
| 100 int result = control.GetWindowText(str.get(), length + 1); | |
| 101 str[std::min(result, length)] = 0; | |
| 102 return UTF16ToUTF8(str.get()); | |
| 103 } | |
| 104 | |
| 105 } // namespace remoting | |
| OLD | NEW |