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

Unified Diff: remoting/host/verify_config_window_win.cc

Issue 10266024: Make the PIN confirmation dialog an ATL-based one and brushing it up a little bit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « remoting/host/verify_config_window_win.h ('k') | remoting/resources/chromoting.ico » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/verify_config_window_win.cc
diff --git a/remoting/host/verify_config_window_win.cc b/remoting/host/verify_config_window_win.cc
index d2e695ff1c40868c1275608550a553040bf06433..763b30f963b7ddace56ae25290462301a3057641 100644
--- a/remoting/host/verify_config_window_win.cc
+++ b/remoting/host/verify_config_window_win.cc
@@ -5,6 +5,7 @@
#include "remoting/host/verify_config_window_win.h"
#include <atlbase.h>
+#include <atlwin.h>
#include <windows.h>
#include "base/base64.h"
@@ -18,111 +19,122 @@ namespace remoting {
VerifyConfigWindowWin::VerifyConfigWindowWin(const std::string& email,
const std::string& host_id, const std::string& host_secret_hash)
- : hwnd_(NULL),
- email_(email),
+ : email_(email),
host_id_(host_id),
host_secret_hash_(host_secret_hash) {
}
-VerifyConfigWindowWin::~VerifyConfigWindowWin() {
- EndDialog();
+void VerifyConfigWindowWin::OnCancel(UINT code, int id, HWND control) {
+ EndDialog(IDCANCEL);
}
-bool VerifyConfigWindowWin::Run() {
- // TODO(simonmorris): Provide a handle of a parent window for this dialog.
- return (DialogBoxParam(ATL::_AtlBaseModule.GetModuleInstance(),
- MAKEINTRESOURCE(IDD_VERIFY_CONFIG_DIALOG),
- NULL,
- (DLGPROC)DialogProc,
- (LPARAM)this) != 0);
+void VerifyConfigWindowWin::OnClose() {
+ EndDialog(IDCANCEL);
}
-BOOL CALLBACK VerifyConfigWindowWin::DialogProc(HWND hwnd, UINT msg,
- WPARAM wParam, LPARAM lParam) {
- VerifyConfigWindowWin* win = NULL;
- if (msg == WM_INITDIALOG) {
- win = reinterpret_cast<VerifyConfigWindowWin*>(lParam);
- CHECK(win);
- SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)win);
- } else {
- LONG_PTR lp = GetWindowLongPtr(hwnd, DWLP_USER);
- win = reinterpret_cast<VerifyConfigWindowWin*>(lp);
- }
- if (win == NULL)
- return FALSE;
- return win->OnDialogMessage(hwnd, msg, wParam, lParam);
+LRESULT VerifyConfigWindowWin::OnInitDialog(HWND wparam, LPARAM lparam) {
+ CenterWindow();
+
+ // TODO(simonmorris): l10n.
+ SetWindowText(L"Chrome Remote Desktop");
+
+ CWindow email_label(GetDlgItem(IDC_EMAIL_LABEL));
+ email_label.SetWindowText(L"Account:");
+
+ CWindow pin_label(GetDlgItem(IDC_PIN_LABEL));
+ pin_label.SetWindowText(L"PIN:");
+
+ CWindow ok_button(GetDlgItem(IDOK));
+ ok_button.SetWindowText(L"Confirm");
+
+ CWindow cancel_button(GetDlgItem(IDCANCEL));
+ cancel_button.SetWindowText(L"Cancel");
+
+ CWindow message_text(GetDlgItem(IDC_MESSAGE));
+ message_text.SetWindowText(L"Please confirm your account and PIN below to "
+ L"allow access by Chrome Remote Desktop.");
+
+ CWindow email_text(GetDlgItem(IDC_EMAIL));
+ email_text.SetWindowText(UTF8ToUTF16(email_).c_str());
+ return TRUE;
}
-BOOL VerifyConfigWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
- WPARAM wParam, LPARAM lParam) {
- switch (msg) {
- case WM_INITDIALOG:
- hwnd_ = hwnd;
- InitDialog();
- return TRUE;
- case WM_DESTROY:
- ::EndDialog(hwnd, 0);
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- ::EndDialog(hwnd, VerifyHostSecretHash());
- hwnd_ = NULL;
- return TRUE;
- case IDCANCEL:
- ::EndDialog(hwnd, 0);
- hwnd_ = NULL;
- return TRUE;
- }
+void VerifyConfigWindowWin::OnOk(UINT code, int id, HWND control) {
+ if (VerifyHostSecretHash()) {
+ EndDialog(IDOK);
+ } else {
+ EndDialog(IDCANCEL);
}
- return FALSE;
}
-void VerifyConfigWindowWin::InitDialog() {
- // TODO(simonmorris): l10n.
- SetWindowText(hwnd_, L"Chrome Remote Desktop");
-
- HWND hwndOk = GetDlgItem(hwnd_, IDOK);
- CHECK(hwndOk);
- SetWindowText(hwndOk, L"OK");
+void VerifyConfigWindowWin::CenterWindow() {
+ // Get the window dimensions.
+ RECT rect;
+ if (!GetWindowRect(&rect)) {
+ return;
+ }
- HWND hwndCancel = GetDlgItem(hwnd_, IDCANCEL);
- CHECK(hwndCancel);
- SetWindowText(hwndCancel, L"Cancel");
+ // Center against the owner window unless it is minimized or invisible.
+ HWND owner = ::GetWindow(m_hWnd, GW_OWNER);
+ if (owner != NULL) {
+ DWORD style = ::GetWindowLong(owner, GWL_STYLE);
+ if ((style & WS_MINIMIZE) != 0 || (style & WS_VISIBLE) == 0) {
+ owner = NULL;
+ }
+ }
- HWND hwndMessage = GetDlgItem(hwnd_, IDC_MESSAGE);
- CHECK(hwndMessage);
- SetWindowText(hwndMessage, L"To confirm that your Chrome Remote Desktop "
- L"should be accessible by this account, please enter your PIN below.");
+ // Make sure that the window will not end up split by a monitor's boundary.
+ RECT area_rect;
+ if (!::SystemParametersInfo(SPI_GETWORKAREA, NULL, &area_rect, NULL)) {
+ return;
+ }
- HWND hwndEmail = GetDlgItem(hwnd_, IDC_EMAIL);
- CHECK(hwndEmail);
- SetWindowText(hwndEmail, UTF8ToUTF16(email_).c_str());
+ // On a multi-monitor system use the monitor where the owner window is shown.
+ RECT owner_rect = area_rect;
+ if (owner != NULL && ::GetWindowRect(owner, &owner_rect)) {
+ HMONITOR monitor = ::MonitorFromRect(&owner_rect, MONITOR_DEFAULTTONEAREST);
+ if (monitor != NULL) {
+ MONITORINFO monitor_info = {0};
+ monitor_info.cbSize = sizeof(monitor_info);
+ if (::GetMonitorInfo(monitor, &monitor_info)) {
+ area_rect = monitor_info.rcWork;
+ }
+ }
+ }
- HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN);
- CHECK(hwndPin);
- SetFocus(hwndPin);
-}
+ LONG width = rect.right - rect.left;
+ LONG height = rect.bottom - rect.top;
+ LONG x = (owner_rect.left + owner_rect.right - width) / 2;
+ LONG y = (owner_rect.top + owner_rect.bottom - height) / 2;
-void VerifyConfigWindowWin::EndDialog() {
- if (hwnd_) {
- ::EndDialog(hwnd_, 0);
- hwnd_ = NULL;
+ x = std::max(x, area_rect.left);
+ if (x + width > area_rect.right) {
+ x = area_rect.right - width;
+ }
simonmorris 2012/05/01 18:25:45 Or just "x = std::min(x, area_rect.right - width);
alexeypa (please no reviews) 2012/05/01 18:30:08 Done.
+ y = std::max(y, area_rect.top);
+ if (y + width > area_rect.bottom) {
+ y = area_rect.bottom - width;
}
simonmorris 2012/05/01 18:25:45 Same suggestion.
alexeypa (please no reviews) 2012/05/01 18:30:08 Done.
+
+ SetWindowPos(NULL, x, y, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
bool VerifyConfigWindowWin::VerifyHostSecretHash() {
- const int kMaxPinLength = 256;
- // TODO(simonmorris): Use ATL's string class, if it's more convenient.
- scoped_array<WCHAR> pinWSTR(new WCHAR[kMaxPinLength]);
- HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN);
- CHECK(hwndPin);
- GetWindowText(hwndPin, pinWSTR.get(), kMaxPinLength);
+ CWindow pin_edit(GetDlgItem(IDC_PIN));
+
+ // Get the PIN length.
+ int pin_length = pin_edit.GetWindowTextLength();
+ scoped_array<char16> pin(new char16[pin_length + 1]);
+
+ // Get the PIN making sure it is NULL terminated even if an error occurs.
+ int result = pin_edit.GetWindowText(pin.get(), pin_length + 1);
+ pin[std::min(result, pin_length)] = 0;
// TODO(simonmorris): This code was copied from host_script_object.cc.
// Refactor to use PinIsValid(), from CL 10008092.
- std::string pin(UTF16ToUTF8(pinWSTR.get()));
std::string hash = protocol::AuthenticationMethod::ApplyHashFunction(
- protocol::AuthenticationMethod::HMAC_SHA256, host_id_, pin);
+ protocol::AuthenticationMethod::HMAC_SHA256, host_id_,
+ UTF16ToUTF8(pin.get()));
std::string hash_base64;
bool base64_result = base::Base64Encode(hash, &hash_base64);
if (!base64_result) {
« no previous file with comments | « remoting/host/verify_config_window_win.h ('k') | remoting/resources/chromoting.ico » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698