Chromium Code Reviews| Index: content/shell/shell_javascript_dialog_win.cc |
| diff --git a/content/shell/shell_javascript_dialog_win.cc b/content/shell/shell_javascript_dialog_win.cc |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..e932969b84e27742aca626d89de32241548eb6be |
| --- /dev/null |
| +++ b/content/shell/shell_javascript_dialog_win.cc |
| @@ -0,0 +1,111 @@ |
| +// 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 "content/shell/shell_javascript_dialog.h" |
| + |
| +#include "content/shell/shell.h" |
| +#include "content/shell/resource.h" |
| +#include "content/shell/shell_javascript_dialog_creator.h" |
| + |
| +namespace content { |
| + |
| +class ShellJavaScriptDialog; |
| + |
| +INT_PTR CALLBACK ShellJavaScriptDialog::DialogProc(HWND hDlg, UINT msg, |
|
jam
2012/03/29 15:50:30
nit: per style guide, this should e HWND dialog, U
|
| + WPARAM wParam, |
| + LPARAM lParam) { |
| + switch (msg) { |
| + case WM_INITDIALOG: { |
| + SetWindowLongPtr(hDlg, DWL_USER, (LONG_PTR)lParam); |
|
jam
2012/03/29 15:50:30
nit: here and below, we don't use c style casts pe
|
| + ShellJavaScriptDialog* owner = (ShellJavaScriptDialog*)lParam; |
| + owner->dlg_win_ = hDlg; |
| + SetDlgItemText(hDlg, IDC_DIALOGTEXT, owner->message_text_.c_str()); |
| + if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) |
| + SetDlgItemText(hDlg, IDC_PROMPTEDIT, |
|
jam
2012/03/29 15:50:30
nit: this tabbing isn't according to style guide,
|
| + owner->default_prompt_text_.c_str()); |
| + break; |
| + } |
| + case WM_DESTROY: { |
| + ShellJavaScriptDialog* owner = |
| + (ShellJavaScriptDialog*) GetWindowLongPtr(hDlg, DWL_USER); |
| + if (owner->dlg_win_) { |
| + owner->dlg_win_ = 0; |
| + owner->callback_.Run(false, string16()); |
| + owner->creator_->DialogClosed(owner); |
| + } |
| + break; |
| + } |
| + case WM_COMMAND: { |
| + ShellJavaScriptDialog* owner = |
| + (ShellJavaScriptDialog*) GetWindowLongPtr(hDlg, DWL_USER); |
| + string16 user_input; |
| + bool finish = false; |
| + bool result; |
| + switch (LOWORD(wParam)) { |
| + case IDOK: |
|
jam
2012/03/29 15:50:30
nit: need indentation for each case per style guid
|
| + finish = true; |
| + result = true; |
| + if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { |
| + size_t length = |
| + GetWindowTextLength(GetDlgItem(hDlg, IDC_PROMPTEDIT)) + 1; |
| + TCHAR* buf = new TCHAR[length]; |
|
jam
2012/03/29 15:50:30
nit: we don't use TCHAR in code. just use string_u
|
| + memset(buf, 0, length * sizeof(TCHAR)); |
| + GetDlgItemText(hDlg, IDC_PROMPTEDIT, buf, length); |
| + user_input = buf; |
| + delete[] buf; |
| + } |
| + break; |
| + case IDCANCEL: |
| + finish = true; |
| + result = false; |
| + break; |
| + } |
| + if (finish) { |
| + owner->dlg_win_ = 0; |
| + owner->callback_.Run(result, user_input); |
| + DestroyWindow(hDlg); |
| + owner->creator_->DialogClosed(owner); |
| + } |
| + break; |
| + } |
| + default: |
| + return DefWindowProc(hDlg, msg, wParam, lParam); |
| + } |
| + return 0; |
| +} |
| + |
| +ShellJavaScriptDialog::ShellJavaScriptDialog( |
| + ShellJavaScriptDialogCreator* creator, |
| + ui::JavascriptMessageType javascript_message_type, |
| + const string16& message_text, |
| + const string16& default_prompt_text, |
| + const JavaScriptDialogCreator::DialogClosedCallback& callback) |
| + : creator_(creator), |
| + callback_(callback), |
| + message_text_(message_text), |
| + default_prompt_text_(default_prompt_text), |
| + message_type_(javascript_message_type) { |
| + int dlgType; |
|
jam
2012/03/29 15:50:30
nit: ditto for variable name
|
| + if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_ALERT) |
| + dlgType = IDD_ALERT; |
| + else if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) |
| + dlgType = IDD_CONFIRM; |
| + else // JAVASCRIPT_MESSAGE_TYPE_PROMPT |
| + dlgType = IDD_PROMPT; |
| + |
| + dlg_win_ = CreateDialogParam(GetModuleHandle(0), MAKEINTRESOURCE(dlgType), 0, |
| + DialogProc, (LPARAM) this); |
| + ShowWindow(dlg_win_, SW_SHOWNORMAL); |
| +} |
| + |
| +ShellJavaScriptDialog::~ShellJavaScriptDialog() { |
| + Cancel(); |
| +} |
| + |
| +void ShellJavaScriptDialog::Cancel() { |
| + if (dlg_win_) |
| + DestroyWindow(dlg_win_); |
| +} |
| + |
| +} // namespace content |