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

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: Fix non-standard resource header file. 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
« no previous file with comments | « remoting/host/setup/win/start_host_window.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 : host_starter_(remoting::HostStarter::Create(url_request_context_getter)),
22 consent_to_collect_data_(true),
23 mem_mgr_(GetProcessHeap()),
24 string_mgr_(&mem_mgr_),
25 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
26 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) {
27 }
28
29 void StartHostWindow::OnCancel(UINT code, int id, HWND control) {
30 EndDialog(IDCANCEL);
31 }
32
33 void StartHostWindow::OnClose() {
34 EndDialog(IDCANCEL);
35 }
36
37 LRESULT StartHostWindow::OnInitDialog(HWND wparam, LPARAM lparam) {
38 // Failure of any of these calls is acceptable.
39 SetWindowText(LoadStringFromResource(IDS_TITLE));
40 GetDlgItem(IDC_CONSENT).SetWindowText(LoadStringFromResource(IDS_CONSENT));
41 CheckDlgButton(IDC_CONSENT, BST_CHECKED);
42 return TRUE;
43 }
44
45 void StartHostWindow::OnConsent(UINT code, int id, HWND control) {
46 bool checked = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED);
47 checked = !checked;
48 CheckDlgButton(IDC_CONSENT, checked ? BST_CHECKED : BST_UNCHECKED);
49 }
50
51 void StartHostWindow::OnOk(UINT code, int id, HWND control) {
52 host_name_ = GetDlgItemString(IDC_HOST_NAME);
53 pin_ = GetDlgItemString(IDC_PIN);
54 std::string confirm_pin = GetDlgItemString(IDC_CONFIRM_PIN);
55 consent_to_collect_data_ = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED);
56 if (pin_ != confirm_pin) {
57 MessageBox(LoadStringFromResource(IDS_SAME_PIN),
58 LoadStringFromResource(IDS_TITLE),
59 MB_ICONEXCLAMATION | MB_OK);
60 return;
61 }
62 if (!IsPinValid(pin_)) {
63 MessageBox(LoadStringFromResource(IDS_INVALID_PIN),
64 LoadStringFromResource(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK);
65 return;
66 }
67 MessageBox(LoadStringFromResource(IDS_USE_BROWSER),
68 LoadStringFromResource(IDS_TITLE), MB_OK);
69 auth_code_getter_.GetAuthCode(
70 base::Bind(&StartHostWindow::OnAuthCode, weak_ptr_));
71 }
72
73 void StartHostWindow::OnAuthCode(const std::string& auth_code) {
74 host_starter_->StartHost(
75 host_name_, pin_, consent_to_collect_data_, auth_code,
76 base::Bind(&StartHostWindow::OnHostStarted, weak_ptr_));
77 }
78
79 void StartHostWindow::OnHostStarted(remoting::HostStarter::Result result) {
80 if (result == remoting::HostStarter::START_COMPLETE) {
81 MessageBox(LoadStringFromResource(IDS_HOST_START_SUCCEEDED),
82 LoadStringFromResource(IDS_TITLE), MB_OK);
83 EndDialog(IDOK);
84 } else {
85 MessageBox(LoadStringFromResource(IDS_HOST_START_FAILED),
86 LoadStringFromResource(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK);
87 }
88 }
89
90 std::string StartHostWindow::GetDlgItemString(int id) {
91 CSimpleString str(L"", &string_mgr_);
92 GetDlgItemText(id, str);
93 return UTF16ToUTF8(str.GetString());
94 }
95
96 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/setup/win/start_host_window.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698