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

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: 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..44538f46ccff5f8697f82a9e3e41d46c88fefdf0
--- /dev/null
+++ b/remoting/host/setup/win/start_host_window.cc
@@ -0,0 +1,104 @@
+// 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 <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 {
+
+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.
+ const int kMaxStringSize = 8 * 1024;
+ scoped_array<char16> str(new char16[kMaxStringSize + 1]);
+ int result = ::LoadString(NULL, id, str.get(), kMaxStringSize);
+ str[std::min(result, kMaxStringSize)] = 0;
+ return string16(str.get());
+}
+
+} // 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) {
+}
+
+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).c_str());
+ ::SetWindowText(GetDlgItem(IDC_CONSENT), LoadString(IDS_CONSENT).c_str());
+ 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).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
+ MB_ICONEXCLAMATION | MB_OK);
+ return;
+ }
+ if (!IsPinValid(pin_)) {
+ 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.
+ LoadString(IDS_TITLE).c_str(), MB_ICONEXCLAMATION | MB_OK);
+ return;
+ }
+ MessageBox(LoadString(IDS_USE_BROWSER).c_str(),
+ LoadString(IDS_TITLE).c_str(), MB_OK);
+ auth_code_getter_.GetAuthCode(
+ 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.
+}
+
+void StartHostWindow::OnAuthCode(const std::string& auth_code) {
+ host_starter_->StartHost(
+ host_name_, pin_, consent_to_collect_data_, auth_code,
+ base::Bind(&StartHostWindow::OnHostStarted, base::Unretained(this)));
+}
+
+void StartHostWindow::OnHostStarted(remoting::HostStarter::Result result) {
+ if (result == remoting::HostStarter::START_COMPLETE) {
+ MessageBox(LoadString(IDS_HOST_START_SUCCEEDED).c_str(),
+ LoadString(IDS_TITLE).c_str(), MB_OK);
+ EndDialog(IDOK);
+ } else {
+ MessageBox(LoadString(IDS_HOST_START_FAILED).c_str(),
+ LoadString(IDS_TITLE).c_str(), MB_ICONEXCLAMATION | MB_OK);
+ }
+}
+
+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.
+ 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