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

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

Issue 10451047: content: Move javascript_message_type.h into content/ from ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm CONTEXT_EXPORT Created 8 years, 6 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
« no previous file with comments | « content/shell/shell_javascript_dialog_mac.mm ('k') | ui/base/javascript_message_type.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_creator.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, UINT message, 16 INT_PTR CALLBACK ShellJavaScriptDialog::DialogProc(HWND dialog,
17 UINT message,
17 WPARAM wparam, 18 WPARAM wparam,
18 LPARAM lparam) { 19 LPARAM lparam) {
19 switch (message) { 20 switch (message) {
20 case WM_INITDIALOG: { 21 case WM_INITDIALOG: {
21 SetWindowLongPtr(dialog, DWL_USER, static_cast<LONG_PTR>(lparam)); 22 SetWindowLongPtr(dialog, DWL_USER, static_cast<LONG_PTR>(lparam));
22 ShellJavaScriptDialog* owner = 23 ShellJavaScriptDialog* owner =
23 reinterpret_cast<ShellJavaScriptDialog*>(lparam); 24 reinterpret_cast<ShellJavaScriptDialog*>(lparam);
24 owner->dialog_win_ = dialog; 25 owner->dialog_win_ = dialog;
25 SetDlgItemText(dialog, IDC_DIALOGTEXT, owner->message_text_.c_str()); 26 SetDlgItemText(dialog, IDC_DIALOGTEXT, owner->message_text_.c_str());
26 if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) 27 if (owner->message_type_ == JAVASCRIPT_MESSAGE_TYPE_PROMPT)
27 SetDlgItemText(dialog, IDC_PROMPTEDIT, 28 SetDlgItemText(dialog, IDC_PROMPTEDIT,
28 owner->default_prompt_text_.c_str()); 29 owner->default_prompt_text_.c_str());
29 break; 30 break;
30 } 31 }
31 case WM_DESTROY: { 32 case WM_DESTROY: {
32 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>( 33 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
33 GetWindowLongPtr(dialog, DWL_USER)); 34 GetWindowLongPtr(dialog, DWL_USER));
34 if (owner->dialog_win_) { 35 if (owner->dialog_win_) {
35 owner->dialog_win_ = 0; 36 owner->dialog_win_ = 0;
36 owner->callback_.Run(false, string16()); 37 owner->callback_.Run(false, string16());
37 owner->creator_->DialogClosed(owner); 38 owner->creator_->DialogClosed(owner);
38 } 39 }
39 break; 40 break;
40 } 41 }
41 case WM_COMMAND: { 42 case WM_COMMAND: {
42 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>( 43 ShellJavaScriptDialog* owner = reinterpret_cast<ShellJavaScriptDialog*>(
43 GetWindowLongPtr(dialog, DWL_USER)); 44 GetWindowLongPtr(dialog, DWL_USER));
44 string16 user_input; 45 string16 user_input;
45 bool finish = false; 46 bool finish = false;
46 bool result; 47 bool result;
47 switch (LOWORD(wparam)) { 48 switch (LOWORD(wparam)) {
48 case IDOK: 49 case IDOK:
49 finish = true; 50 finish = true;
50 result = true; 51 result = true;
51 if (owner->message_type_ == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { 52 if (owner->message_type_ == JAVASCRIPT_MESSAGE_TYPE_PROMPT) {
52 size_t length = 53 size_t length =
53 GetWindowTextLength(GetDlgItem(dialog, IDC_PROMPTEDIT)) + 1; 54 GetWindowTextLength(GetDlgItem(dialog, IDC_PROMPTEDIT)) + 1;
54 GetDlgItemText(dialog, IDC_PROMPTEDIT, 55 GetDlgItemText(dialog, IDC_PROMPTEDIT,
55 WriteInto(&user_input, length), length); 56 WriteInto(&user_input, length), length);
56 } 57 }
57 break; 58 break;
58 case IDCANCEL: 59 case IDCANCEL:
59 finish = true; 60 finish = true;
60 result = false; 61 result = false;
61 break; 62 break;
62 } 63 }
63 if (finish) { 64 if (finish) {
64 owner->dialog_win_ = 0; 65 owner->dialog_win_ = 0;
65 owner->callback_.Run(result, user_input); 66 owner->callback_.Run(result, user_input);
66 DestroyWindow(dialog); 67 DestroyWindow(dialog);
67 owner->creator_->DialogClosed(owner); 68 owner->creator_->DialogClosed(owner);
68 } 69 }
69 break; 70 break;
70 } 71 }
71 default: 72 default:
72 return DefWindowProc(dialog, message, wparam, lparam); 73 return DefWindowProc(dialog, message, wparam, lparam);
73 } 74 }
74 return 0; 75 return 0;
75 } 76 }
76 77
77 ShellJavaScriptDialog::ShellJavaScriptDialog( 78 ShellJavaScriptDialog::ShellJavaScriptDialog(
78 ShellJavaScriptDialogCreator* creator, 79 ShellJavaScriptDialogCreator* creator,
79 ui::JavascriptMessageType javascript_message_type, 80 JavaScriptMessageType message_type,
80 const string16& message_text, 81 const string16& message_text,
81 const string16& default_prompt_text, 82 const string16& default_prompt_text,
82 const JavaScriptDialogCreator::DialogClosedCallback& callback) 83 const JavaScriptDialogCreator::DialogClosedCallback& callback)
83 : creator_(creator), 84 : creator_(creator),
84 callback_(callback), 85 callback_(callback),
85 message_text_(message_text), 86 message_text_(message_text),
86 default_prompt_text_(default_prompt_text), 87 default_prompt_text_(default_prompt_text),
87 message_type_(javascript_message_type) { 88 message_type_(message_type) {
88 int dialog_type; 89 int dialog_type;
89 if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_ALERT) 90 if (message_type == JAVASCRIPT_MESSAGE_TYPE_ALERT)
90 dialog_type = IDD_ALERT; 91 dialog_type = IDD_ALERT;
91 else if (javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) 92 else if (message_type == JAVASCRIPT_MESSAGE_TYPE_CONFIRM)
92 dialog_type = IDD_CONFIRM; 93 dialog_type = IDD_CONFIRM;
93 else // JAVASCRIPT_MESSAGE_TYPE_PROMPT 94 else // JAVASCRIPT_MESSAGE_TYPE_PROMPT
94 dialog_type = IDD_PROMPT; 95 dialog_type = IDD_PROMPT;
95 96
96 dialog_win_ = CreateDialogParam(GetModuleHandle(0), 97 dialog_win_ = CreateDialogParam(GetModuleHandle(0),
97 MAKEINTRESOURCE(dialog_type), 0, DialogProc, 98 MAKEINTRESOURCE(dialog_type), 0, DialogProc,
98 reinterpret_cast<LPARAM>(this)); 99 reinterpret_cast<LPARAM>(this));
99 ShowWindow(dialog_win_, SW_SHOWNORMAL); 100 ShowWindow(dialog_win_, SW_SHOWNORMAL);
100 } 101 }
101 102
102 ShellJavaScriptDialog::~ShellJavaScriptDialog() { 103 ShellJavaScriptDialog::~ShellJavaScriptDialog() {
103 Cancel(); 104 Cancel();
104 } 105 }
105 106
106 void ShellJavaScriptDialog::Cancel() { 107 void ShellJavaScriptDialog::Cancel() {
107 if (dialog_win_) 108 if (dialog_win_)
108 DestroyWindow(dialog_win_); 109 DestroyWindow(dialog_win_);
109 } 110 }
110 111
111 } // namespace content 112 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_javascript_dialog_mac.mm ('k') | ui/base/javascript_message_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698