| 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 39c6a4a28c2befb30b7795bae82bad9c12758bb7..5f5da289d390389433a334b6b05c438c985fcf75 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"
|
| @@ -19,107 +20,114 @@ 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");
|
| +void VerifyConfigWindowWin::CenterWindow() {
|
| + // Get the window dimensions.
|
| + RECT rect;
|
| + if (!GetWindowRect(&rect)) {
|
| + return;
|
| + }
|
|
|
| - HWND hwndOk = GetDlgItem(hwnd_, IDOK);
|
| - CHECK(hwndOk);
|
| - SetWindowText(hwndOk, L"OK");
|
| + // 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 hwndCancel = GetDlgItem(hwnd_, IDCANCEL);
|
| - CHECK(hwndCancel);
|
| - SetWindowText(hwndCancel, L"Cancel");
|
| + // 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 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.");
|
| + // 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 hwndEmail = GetDlgItem(hwnd_, IDC_EMAIL);
|
| - CHECK(hwndEmail);
|
| - SetWindowText(hwndEmail, UTF8ToUTF16(email_).c_str());
|
| + 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;
|
|
|
| - HWND hwndPin = GetDlgItem(hwnd_, IDC_PIN);
|
| - CHECK(hwndPin);
|
| - SetFocus(hwndPin);
|
| -}
|
| + x = std::max(x, area_rect.left);
|
| + x = std::min(x, area_rect.right - width);
|
| + y = std::max(y, area_rect.top);
|
| + y = std::min(y, area_rect.bottom - width);
|
|
|
| -void VerifyConfigWindowWin::EndDialog() {
|
| - if (hwnd_) {
|
| - ::EndDialog(hwnd_, 0);
|
| - hwnd_ = NULL;
|
| - }
|
| + 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);
|
| - std::string pin(UTF16ToUTF8(pinWSTR.get()));
|
| - return VerifyHostPinHash(host_secret_hash_, host_id_, pin);
|
| + 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;
|
| +
|
| + return VerifyHostPinHash(host_secret_hash_, host_id_, UTF16ToUTF8(pin.get()));
|
| }
|
|
|
| } // namespace remoting
|
|
|