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

Unified 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: Review. 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/setup/win/start_host_window.cc
diff --git a/remoting/host/setup/win/start_host_window.cc b/remoting/host/setup/win/start_host_window.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6606ec59503898f563e5e899478cdba55529a659
--- /dev/null
+++ b/remoting/host/setup/win/start_host_window.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/setup/win/start_host_window.h"
+
+#include <atlbase.h>
+#include <atlstr.h>
+#include <atlwin.h>
+#include <windows.h>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/string16.h"
+#include "base/utf_string_conversions.h"
+#include "remoting/host/setup/pin_validator.h"
+
+namespace {
+
+CAtlString LoadString(int id) {
+ CAtlString s;
+ 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
+ return s;
+}
+
+} // namespace
+
+namespace remoting {
+
+StartHostWindow::StartHostWindow(
+ net::URLRequestContextGetter* url_request_context_getter)
+ : host_starter_(remoting::HostStarter::Create(url_request_context_getter)),
+ consent_to_collect_data_(true),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ weak_ptr_(weak_factory_.GetWeakPtr()) {
+}
+
+void StartHostWindow::OnCancel(UINT code, int id, HWND control) {
+ EndDialog(IDCANCEL);
+}
+
+void StartHostWindow::OnClose() {
+ EndDialog(IDCANCEL);
+}
+
+LRESULT StartHostWindow::OnInitDialog(HWND wparam, LPARAM lparam) {
+ 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.
+ ::SetWindowText(GetDlgItem(IDC_CONSENT), LoadString(IDS_CONSENT));
+ CheckDlgButton(IDC_CONSENT, BST_CHECKED);
+ return TRUE;
+}
+
+void StartHostWindow::OnConsent(UINT code, int id, HWND control) {
+ bool checked = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED);
+ checked = !checked;
+ CheckDlgButton(IDC_CONSENT, checked ? BST_CHECKED : BST_UNCHECKED);
+}
+
+void StartHostWindow::OnOk(UINT code, int id, HWND control) {
+ host_name_ = GetDlgItemString(IDC_HOST_NAME);
+ pin_ = GetDlgItemString(IDC_PIN);
+ std::string confirm_pin = GetDlgItemString(IDC_CONFIRM_PIN);
+ consent_to_collect_data_ = (IsDlgButtonChecked(IDC_CONSENT) == BST_CHECKED);
+ if (pin_ != confirm_pin) {
+ MessageBox(LoadString(IDS_SAME_PIN), LoadString(IDS_TITLE),
+ MB_ICONEXCLAMATION | MB_OK);
+ return;
+ }
+ if (!IsPinValid(pin_)) {
+ MessageBox(LoadString(IDS_INVALID_PIN),
+ LoadString(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK);
+ return;
+ }
+ MessageBox(LoadString(IDS_USE_BROWSER),
+ LoadString(IDS_TITLE), MB_OK);
+ auth_code_getter_.GetAuthCode(
+ base::Bind(&StartHostWindow::OnAuthCode, weak_ptr_));
+}
+
+void StartHostWindow::OnAuthCode(const std::string& auth_code) {
+ host_starter_->StartHost(
+ host_name_, pin_, consent_to_collect_data_, auth_code,
+ base::Bind(&StartHostWindow::OnHostStarted, weak_ptr_));
+}
+
+void StartHostWindow::OnHostStarted(remoting::HostStarter::Result result) {
+ if (result == remoting::HostStarter::START_COMPLETE) {
+ MessageBox(LoadString(IDS_HOST_START_SUCCEEDED),
+ LoadString(IDS_TITLE), MB_OK);
+ EndDialog(IDOK);
+ } else {
+ MessageBox(LoadString(IDS_HOST_START_FAILED),
+ LoadString(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK);
+ }
+}
+
+std::string StartHostWindow::GetDlgItemString(int id) {
+ CWindow control(GetDlgItem(id));
+ int length = control.GetWindowTextLength();
+ scoped_array<char16> str(new char16[length + 1]);
+ int result = control.GetWindowText(str.get(), length + 1);
+ str[std::min(result, length)] = 0;
+ return UTF16ToUTF8(str.get());
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698