OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" | 5 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_shutdown.h" | 9 #include "chrome/browser/browser_shutdown.h" |
10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 ui::ElideString(in_string, kMessageTextMaxSize, out_string); | 42 ui::ElideString(in_string, kMessageTextMaxSize, out_string); |
43 } | 43 } |
44 void EnforceMaxPromptSize(const string16& in_string, string16* out_string) { | 44 void EnforceMaxPromptSize(const string16& in_string, string16* out_string) { |
45 ui::ElideString(in_string, kDefaultPromptMaxSize, out_string); | 45 ui::ElideString(in_string, kDefaultPromptMaxSize, out_string); |
46 } | 46 } |
47 #endif | 47 #endif |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 JavaScriptAppModalDialog::JavaScriptAppModalDialog( | 51 JavaScriptAppModalDialog::JavaScriptAppModalDialog( |
52 JavaScriptAppModalDialogDelegate* delegate, | 52 ChromeJavaScriptDialogDelegate* delegate, |
53 const std::wstring& title, | 53 const string16& title, |
54 int dialog_flags, | 54 int dialog_flags, |
55 const std::wstring& message_text, | 55 const string16& message_text, |
56 const std::wstring& default_prompt_text, | 56 const string16& default_prompt_text, |
57 bool display_suppress_checkbox, | 57 bool display_suppress_checkbox, |
58 bool is_before_unload_dialog, | 58 bool is_before_unload_dialog, |
59 IPC::Message* reply_msg) | 59 IPC::Message* reply_msg) |
60 : AppModalDialog(delegate->AsTabContents(), title), | 60 : AppModalDialog(delegate->AsTabContents(), title), |
61 delegate_(delegate), | 61 delegate_(delegate), |
62 extension_host_(delegate->AsExtensionHost()), | 62 extension_host_(delegate->AsExtensionHost()), |
63 dialog_flags_(dialog_flags), | 63 dialog_flags_(dialog_flags), |
64 display_suppress_checkbox_(display_suppress_checkbox), | 64 display_suppress_checkbox_(display_suppress_checkbox), |
65 is_before_unload_dialog_(is_before_unload_dialog), | 65 is_before_unload_dialog_(is_before_unload_dialog), |
66 reply_msg_(reply_msg), | 66 reply_msg_(reply_msg), |
67 use_override_prompt_text_(false) { | 67 use_override_prompt_text_(false) { |
68 string16 elided_text; | 68 EnforceMaxTextSize(message_text, &message_text_); |
69 EnforceMaxTextSize(WideToUTF16(message_text), &elided_text); | 69 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); |
70 message_text_ = UTF16ToWide(elided_text); | |
71 EnforceMaxPromptSize(WideToUTF16Hack(default_prompt_text), | |
72 &default_prompt_text_); | |
73 | 70 |
74 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL)); | 71 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL)); |
75 InitNotifications(); | 72 InitNotifications(); |
76 } | 73 } |
77 | 74 |
78 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { | 75 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { |
79 } | 76 } |
80 | 77 |
81 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { | 78 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { |
82 gfx::NativeWindow parent_window = tab_contents_ ? | 79 gfx::NativeWindow parent_window = delegate_->GetDialogRootWindow(); |
83 tab_contents_->GetMessageBoxRootWindow() : | |
84 extension_host_->GetMessageBoxRootWindow(); | |
85 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this, | 80 return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this, |
86 parent_window); | 81 parent_window); |
87 } | 82 } |
88 | 83 |
89 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { | 84 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { |
90 return true; | 85 return true; |
91 } | 86 } |
92 | 87 |
93 void JavaScriptAppModalDialog::Observe(NotificationType type, | 88 void JavaScriptAppModalDialog::Observe(NotificationType type, |
94 const NotificationSource& source, | 89 const NotificationSource& source, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 browser_shutdown::SetTryingToQuit(false); | 130 browser_shutdown::SetTryingToQuit(false); |
136 | 131 |
137 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame | 132 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame |
138 // will receive its activation messages before this dialog receives | 133 // will receive its activation messages before this dialog receives |
139 // WM_DESTROY. The parent frame would then try to activate any modal dialogs | 134 // WM_DESTROY. The parent frame would then try to activate any modal dialogs |
140 // that were still open in the ModalDialogQueue, which would send activation | 135 // that were still open in the ModalDialogQueue, which would send activation |
141 // back to this one. The framework should be improved to handle this, so this | 136 // back to this one. The framework should be improved to handle this, so this |
142 // is a temporary workaround. | 137 // is a temporary workaround. |
143 CompleteDialog(); | 138 CompleteDialog(); |
144 | 139 |
145 NotifyDelegate(false, L"", suppress_js_messages); | 140 NotifyDelegate(false, string16(), suppress_js_messages); |
146 } | 141 } |
147 | 142 |
148 void JavaScriptAppModalDialog::OnAccept(const std::wstring& prompt_text, | 143 void JavaScriptAppModalDialog::OnAccept(const string16& prompt_text, |
149 bool suppress_js_messages) { | 144 bool suppress_js_messages) { |
150 std::wstring prompt_text_to_use = prompt_text; | 145 string16 prompt_text_to_use = prompt_text; |
151 // This is only for testing. | 146 // This is only for testing. |
152 if (use_override_prompt_text_) | 147 if (use_override_prompt_text_) |
153 prompt_text_to_use = UTF16ToWideHack(override_prompt_text_); | 148 prompt_text_to_use = override_prompt_text_; |
154 | 149 |
155 CompleteDialog(); | 150 CompleteDialog(); |
156 NotifyDelegate(true, prompt_text_to_use, suppress_js_messages); | 151 NotifyDelegate(true, prompt_text_to_use, suppress_js_messages); |
157 } | 152 } |
158 | 153 |
159 void JavaScriptAppModalDialog::OnClose() { | 154 void JavaScriptAppModalDialog::OnClose() { |
160 NotifyDelegate(false, L"", false); | 155 NotifyDelegate(false, string16(), false); |
161 } | 156 } |
162 | 157 |
163 void JavaScriptAppModalDialog::SetOverridePromptText( | 158 void JavaScriptAppModalDialog::SetOverridePromptText( |
164 const string16& override_prompt_text) { | 159 const string16& override_prompt_text) { |
165 override_prompt_text_ = override_prompt_text; | 160 override_prompt_text_ = override_prompt_text; |
166 use_override_prompt_text_ = true; | 161 use_override_prompt_text_ = true; |
167 } | 162 } |
168 | 163 |
169 void JavaScriptAppModalDialog::NotifyDelegate(bool success, | 164 void JavaScriptAppModalDialog::NotifyDelegate(bool success, |
170 const std::wstring& prompt_text, | 165 const string16& user_input, |
171 bool suppress_js_messages) { | 166 bool suppress_js_messages) { |
172 if (skip_this_dialog_) | 167 if (skip_this_dialog_) |
173 return; | 168 return; |
174 | 169 |
175 delegate_->OnMessageBoxClosed(reply_msg_, success, prompt_text); | 170 delegate_->OnDialogClosed(reply_msg_, success, user_input); |
176 if (suppress_js_messages) | 171 if (suppress_js_messages) |
177 delegate_->SetSuppressMessageBoxes(true); | 172 delegate_->SetSuppressDialogs(true); |
178 | 173 |
179 // On Views, we can end up coming through this code path twice :(. | 174 // On Views, we can end up coming through this code path twice :(. |
180 // See crbug.com/63732. | 175 // See crbug.com/63732. |
181 skip_this_dialog_ = true; | 176 skip_this_dialog_ = true; |
182 } | 177 } |
OLD | NEW |