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

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

Issue 12082123: Rename JavaScriptDialogCreator to JavaScriptDialogManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/shell/shell_javascript_dialog.h" 5 #include "content/shell/shell_javascript_dialog.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "content/shell/resource.h" 8 #include "content/shell/resource.h"
9 #include "content/shell/shell.h" 9 #include "content/shell/shell.h"
10 #include "content/shell/shell_javascript_dialog_creator.h" 10 #include "content/shell/shell_javascript_dialog_manager.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 class ShellJavaScriptDialog; 14 class ShellJavaScriptDialog;
15 15
16 INT_PTR CALLBACK ShellJavaScriptDialog::DialogProc(HWND dialog, 16 INT_PTR CALLBACK ShellJavaScriptDialog::DialogProc(HWND dialog,
17 UINT message, 17 UINT message,
18 WPARAM wparam, 18 WPARAM wparam,
19 LPARAM lparam) { 19 LPARAM lparam) {
20 switch (message) { 20 switch (message) {
21 case WM_INITDIALOG: { 21 case WM_INITDIALOG: {
22 SetWindowLongPtr(dialog, DWL_USER, static_cast<LONG_PTR>(lparam)); 22 SetWindowLongPtr(dialog, DWL_USER, static_cast<LONG_PTR>(lparam));
23 ShellJavaScriptDialog* owner = 23 ShellJavaScriptDialog* owner =
24 reinterpret_cast<ShellJavaScriptDialog*>(lparam); 24 reinterpret_cast<ShellJavaScriptDialog*>(lparam);
25 owner->dialog_win_ = dialog; 25 owner->dialog_win_ = dialog;
26 SetDlgItemText(dialog, IDC_DIALOGTEXT, owner->message_text_.c_str()); 26 SetDlgItemText(dialog, IDC_DIALOGTEXT, owner->message_text_.c_str());
27 if (owner->message_type_ == JAVASCRIPT_MESSAGE_TYPE_PROMPT) 27 if (owner->message_type_ == JAVASCRIPT_MESSAGE_TYPE_PROMPT)
28 SetDlgItemText(dialog, IDC_PROMPTEDIT, 28 SetDlgItemText(dialog, IDC_PROMPTEDIT,
29 owner->default_prompt_text_.c_str()); 29 owner->default_prompt_text_.c_str());
30 break; 30 break;
31 } 31 }
32 case WM_DESTROY: { 32 case WM_DESTROY: {
33 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>( 33 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
34 GetWindowLongPtr(dialog, DWL_USER)); 34 GetWindowLongPtr(dialog, DWL_USER));
35 if (owner->dialog_win_) { 35 if (owner->dialog_win_) {
36 owner->dialog_win_ = 0; 36 owner->dialog_win_ = 0;
37 owner->callback_.Run(false, string16()); 37 owner->callback_.Run(false, string16());
38 owner->creator_->DialogClosed(owner); 38 owner->manager_->DialogClosed(owner);
39 } 39 }
40 break; 40 break;
41 } 41 }
42 case WM_COMMAND: { 42 case WM_COMMAND: {
43 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>( 43 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
44 GetWindowLongPtr(dialog, DWL_USER)); 44 GetWindowLongPtr(dialog, DWL_USER));
45 string16 user_input; 45 string16 user_input;
46 bool finish = false; 46 bool finish = false;
47 bool result; 47 bool result;
48 switch (LOWORD(wparam)) { 48 switch (LOWORD(wparam)) {
49 case IDOK: 49 case IDOK:
50 finish = true; 50 finish = true;
51 result = true; 51 result = true;
52 if (owner->message_type_ == JAVASCRIPT_MESSAGE_TYPE_PROMPT) { 52 if (owner->message_type_ == JAVASCRIPT_MESSAGE_TYPE_PROMPT) {
53 size_t length = 53 size_t length =
54 GetWindowTextLength(GetDlgItem(dialog, IDC_PROMPTEDIT)) + 1; 54 GetWindowTextLength(GetDlgItem(dialog, IDC_PROMPTEDIT)) + 1;
55 GetDlgItemText(dialog, IDC_PROMPTEDIT, 55 GetDlgItemText(dialog, IDC_PROMPTEDIT,
56 WriteInto(&user_input, length), length); 56 WriteInto(&user_input, length), length);
57 } 57 }
58 break; 58 break;
59 case IDCANCEL: 59 case IDCANCEL:
60 finish = true; 60 finish = true;
61 result = false; 61 result = false;
62 break; 62 break;
63 } 63 }
64 if (finish) { 64 if (finish) {
65 owner->dialog_win_ = 0; 65 owner->dialog_win_ = 0;
66 owner->callback_.Run(result, user_input); 66 owner->callback_.Run(result, user_input);
67 DestroyWindow(dialog); 67 DestroyWindow(dialog);
68 owner->creator_->DialogClosed(owner); 68 owner->manager_->DialogClosed(owner);
69 } 69 }
70 break; 70 break;
71 } 71 }
72 default: 72 default:
73 return DefWindowProc(dialog, message, wparam, lparam); 73 return DefWindowProc(dialog, message, wparam, lparam);
74 } 74 }
75 return 0; 75 return 0;
76 } 76 }
77 77
78 ShellJavaScriptDialog::ShellJavaScriptDialog( 78 ShellJavaScriptDialog::ShellJavaScriptDialog(
79 ShellJavaScriptDialogCreator* creator, 79 ShellJavaScriptDialogManager* manager,
80 gfx::NativeWindow parent_window, 80 gfx::NativeWindow parent_window,
81 JavaScriptMessageType message_type, 81 JavaScriptMessageType message_type,
82 const string16& message_text, 82 const string16& message_text,
83 const string16& default_prompt_text, 83 const string16& default_prompt_text,
84 const JavaScriptDialogCreator::DialogClosedCallback& callback) 84 const JavaScriptDialogManager::DialogClosedCallback& callback)
85 : creator_(creator), 85 : manager_(manager),
86 callback_(callback), 86 callback_(callback),
87 message_text_(message_text), 87 message_text_(message_text),
88 default_prompt_text_(default_prompt_text), 88 default_prompt_text_(default_prompt_text),
89 message_type_(message_type) { 89 message_type_(message_type) {
90 int dialog_type; 90 int dialog_type;
91 if (message_type == JAVASCRIPT_MESSAGE_TYPE_ALERT) 91 if (message_type == JAVASCRIPT_MESSAGE_TYPE_ALERT)
92 dialog_type = IDD_ALERT; 92 dialog_type = IDD_ALERT;
93 else if (message_type == JAVASCRIPT_MESSAGE_TYPE_CONFIRM) 93 else if (message_type == JAVASCRIPT_MESSAGE_TYPE_CONFIRM)
94 dialog_type = IDD_CONFIRM; 94 dialog_type = IDD_CONFIRM;
95 else // JAVASCRIPT_MESSAGE_TYPE_PROMPT 95 else // JAVASCRIPT_MESSAGE_TYPE_PROMPT
96 dialog_type = IDD_PROMPT; 96 dialog_type = IDD_PROMPT;
97 97
98 dialog_win_ = CreateDialogParam(GetModuleHandle(0), 98 dialog_win_ = CreateDialogParam(GetModuleHandle(0),
99 MAKEINTRESOURCE(dialog_type), 0, DialogProc, 99 MAKEINTRESOURCE(dialog_type), 0, DialogProc,
100 reinterpret_cast<LPARAM>(this)); 100 reinterpret_cast<LPARAM>(this));
101 ShowWindow(dialog_win_, SW_SHOWNORMAL); 101 ShowWindow(dialog_win_, SW_SHOWNORMAL);
102 } 102 }
103 103
104 ShellJavaScriptDialog::~ShellJavaScriptDialog() { 104 ShellJavaScriptDialog::~ShellJavaScriptDialog() {
105 Cancel(); 105 Cancel();
106 } 106 }
107 107
108 void ShellJavaScriptDialog::Cancel() { 108 void ShellJavaScriptDialog::Cancel() {
109 if (dialog_win_) 109 if (dialog_win_)
110 DestroyWindow(dialog_win_); 110 DestroyWindow(dialog_win_);
111 } 111 }
112 112
113 } // namespace content 113 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_javascript_dialog_manager.cc ('k') | content/test/content_browser_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698