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

Side by Side Diff: content/shell/shell_javascript_dialog_win.cc

Issue 9918013: Add JavaScript dialogs functionality to content_shell on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: more style fix 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 unified diff | Download patch
« no previous file with comments | « content/shell/shell_javascript_dialog_creator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/shell_javascript_dialog.h"
6
7 #include "content/shell/shell.h"
8 #include "content/shell/resource.h"
9 #include "content/shell/shell_javascript_dialog_creator.h"
10
11 namespace content {
12
13 class ShellJavaScriptDialog;
14
15 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
16 WPARAM wParam,
17 LPARAM lParam) {
18 switch (msg) {
19 case WM_INITDIALOG: {
20 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
21 ShellJavaScriptDialog* owner = (ShellJavaScriptDialog*)lParam;
22 owner->dlg_win_ = hDlg;
23 SetDlgItemText(hDlg, IDC_DIALOGTEXT, owner->message_text_.c_str());
24 if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT)
25 SetDlgItemText(hDlg, IDC_PROMPTEDIT,
jam 2012/03/29 15:50:30 nit: this tabbing isn't according to style guide,
26 owner->default_prompt_text_.c_str());
27 break;
28 }
29 case WM_DESTROY: {
30 ShellJavaScriptDialog* owner =
31 (ShellJavaScriptDialog*) GetWindowLongPtr(hDlg, DWL_USER);
32 if (owner->dlg_win_) {
33 owner->dlg_win_ = 0;
34 owner->callback_.Run(false, string16());
35 owner->creator_->DialogClosed(owner);
36 }
37 break;
38 }
39 case WM_COMMAND: {
40 ShellJavaScriptDialog* owner =
41 (ShellJavaScriptDialog*) GetWindowLongPtr(hDlg, DWL_USER);
42 string16 user_input;
43 bool finish = false;
44 bool result;
45 switch (LOWORD(wParam)) {
46 case IDOK:
jam 2012/03/29 15:50:30 nit: need indentation for each case per style guid
47 finish = true;
48 result = true;
49 if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) {
50 size_t length =
51 GetWindowTextLength(GetDlgItem(hDlg, IDC_PROMPTEDIT)) + 1;
52 TCHAR* buf = new TCHAR[length];
jam 2012/03/29 15:50:30 nit: we don't use TCHAR in code. just use string_u
53 memset(buf, 0, length * sizeof(TCHAR));
54 GetDlgItemText(hDlg, IDC_PROMPTEDIT, buf, length);
55 user_input = buf;
56 delete[] buf;
57 }
58 break;
59 case IDCANCEL:
60 finish = true;
61 result = false;
62 break;
63 }
64 if (finish) {
65 owner->dlg_win_ = 0;
66 owner->callback_.Run(result, user_input);
67 DestroyWindow(hDlg);
68 owner->creator_->DialogClosed(owner);
69 }
70 break;
71 }
72 default:
73 return DefWindowProc(hDlg, msg, wParam, lParam);
74 }
75 return 0;
76 }
77
78 ShellJavaScriptDialog::ShellJavaScriptDialog(
79 ShellJavaScriptDialogCreator* creator,
80 ui::JavascriptMessageType javascript_message_type,
81 const string16& message_text,
82 const string16& default_prompt_text,
83 const JavaScriptDialogCreator::DialogClosedCallback& callback)
84 : creator_(creator),
85 callback_(callback),
86 message_text_(message_text),
87 default_prompt_text_(default_prompt_text),
88 message_type_(javascript_message_type) {
89 int dlgType;
jam 2012/03/29 15:50:30 nit: ditto for variable name
90 if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_ALERT)
91 dlgType = IDD_ALERT;
92 else if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM)
93 dlgType = IDD_CONFIRM;
94 else // JAVASCRIPT_MESSAGE_TYPE_PROMPT
95 dlgType = IDD_PROMPT;
96
97 dlg_win_ = CreateDialogParam(GetModuleHandle(0), MAKEINTRESOURCE(dlgType), 0,
98 DialogProc, (LPARAM) this);
99 ShowWindow(dlg_win_, SW_SHOWNORMAL);
100 }
101
102 ShellJavaScriptDialog::~ShellJavaScriptDialog() {
103 Cancel();
104 }
105
106 void ShellJavaScriptDialog::Cancel() {
107 if (dlg_win_)
108 DestroyWindow(dlg_win_);
109 }
110
111 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_javascript_dialog_creator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698