Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: remoting/host/setup/win/start_host_window.cc

Issue 11090063: [Chromoting] Add a simple Windows app that registers and starts a host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
16 namespace {
17
18 string16 LoadString(int id) {
alexeypa (please no reviews) 2012/10/11 16:57:52 An identcal function is defined in host_configurer
simonmorris 2012/10/11 21:27:35 True. This shorter function is also defined there.
19 const int kMaxStringSize = 8 * 1024;
20 scoped_array<char16> str(new char16[kMaxStringSize + 1]);
21 int result = ::LoadString(NULL, id, str.get(), kMaxStringSize);
22 str[std::min(result, kMaxStringSize)] = 0;
23 return string16(str.get());
24 }
25
26 } // namespace
27
28 namespace remoting {
29
30 StartHostWindow::StartHostWindow(
31 net::URLRequestContextGetter* url_request_context_getter)
32 : host_starter_(remoting::HostStarter::Create(url_request_context_getter)),
33 consent_to_collect_data_(true) {
34 }
35
36 void StartHostWindow::OnCancel(UINT code, int id, HWND control) {
37 EndDialog(IDCANCEL);
38 }
39
40 void StartHostWindow::OnClose() {
41 EndDialog(IDCANCEL);
42 }
43
44 LRESULT StartHostWindow::OnInitDialog(HWND wparam, LPARAM lparam) {
45 SetWindowText(LoadString(IDS_TITLE).c_str());
46 ::SetWindowText(GetDlgItem(IDC_CONSENT), LoadString(IDS_CONSENT).c_str());
47 CheckDlgButton(IDC_CONSENT, BST_CHECKED);
48 return TRUE;
49 }
50
51 void StartHostWindow::OnConsent(UINT code, int id, HWND control) {
52 bool checked = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED);
53 checked = !checked;
54 CheckDlgButton(IDC_CONSENT, checked ? BST_CHECKED : BST_UNCHECKED);
55 }
56
57 void StartHostWindow::OnOk(UINT code, int id, HWND control) {
58 host_name_ = GetDlgItemString(IDC_HOST_NAME);
59 pin_ = GetDlgItemString(IDC_PIN);
60 std::string confirm_pin = GetDlgItemString(IDC_CONFIRM_PIN);
61 consent_to_collect_data_ = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED);
62 if (pin_ != confirm_pin) {
63 MessageBox(LoadString(IDS_SAME_PIN).c_str(), LoadString(IDS_TITLE).c_str(),
alexeypa (please no reviews) 2012/10/11 16:57:52 MessageBox disrupts the UI flow. Is there a way to
simonmorris 2012/10/11 21:27:35 There are many possibilities for the UI flow. Expe
64 MB_ICONEXCLAMATION | MB_OK);
65 return;
66 }
67 if (!IsPinValid(pin_)) {
68 MessageBox(LoadString(IDS_INVALID_PIN).c_str(),
alexeypa (please no reviews) 2012/10/11 16:57:52 Looking at the way LoadString is used, it's ATL co
simonmorris 2012/10/11 21:27:35 Done.
69 LoadString(IDS_TITLE).c_str(), MB_ICONEXCLAMATION | MB_OK);
70 return;
71 }
72 MessageBox(LoadString(IDS_USE_BROWSER).c_str(),
73 LoadString(IDS_TITLE).c_str(), MB_OK);
74 auth_code_getter_.GetAuthCode(
75 base::Bind(&StartHostWindow::OnAuthCode, base::Unretained(this)));
alexeypa (please no reviews) 2012/10/11 16:57:52 Now do you make sure that |auth_code_getter_| will
simonmorris 2012/10/11 21:27:35 I've added a WeakPtr.
76 }
77
78 void StartHostWindow::OnAuthCode(const std::string& auth_code) {
79 host_starter_->StartHost(
80 host_name_, pin_, consent_to_collect_data_, auth_code,
81 base::Bind(&StartHostWindow::OnHostStarted, base::Unretained(this)));
82 }
83
84 void StartHostWindow::OnHostStarted(remoting::HostStarter::Result result) {
85 if (result == remoting::HostStarter::START_COMPLETE) {
86 MessageBox(LoadString(IDS_HOST_START_SUCCEEDED).c_str(),
87 LoadString(IDS_TITLE).c_str(), MB_OK);
88 EndDialog(IDOK);
89 } else {
90 MessageBox(LoadString(IDS_HOST_START_FAILED).c_str(),
91 LoadString(IDS_TITLE).c_str(), MB_ICONEXCLAMATION | MB_OK);
92 }
93 }
94
95 std::string StartHostWindow::GetDlgItemString(int id) {
alexeypa (please no reviews) 2012/10/11 16:57:52 I'm pretty sure an ATL equivalent of this function
simonmorris 2012/10/11 21:27:35 I couldn't find a similar function that didn't inv
alexeypa (please no reviews) 2012/10/12 17:09:35 UINT CWidnowCWindow::GetDlgItemText(int nID, CSimp
simonmorris 2012/10/15 16:51:41 Done.
96 CWindow control(GetDlgItem(id));
97 int length = control.GetWindowTextLength();
98 scoped_array<char16> str(new char16[length + 1]);
99 int result = control.GetWindowText(str.get(), length + 1);
100 str[std::min(result, length)] = 0;
101 return UTF16ToUTF8(str.get());
102 }
103
104 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698