OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/text_elider.h" | 7 #include "app/text_elider.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_shutdown.h" | 10 #include "chrome/browser/browser_shutdown.h" |
10 #include "chrome/browser/extensions/extension_host.h" | 11 #include "chrome/browser/extensions/extension_host.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 13 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
13 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
14 #include "chrome/common/notification_type.h" | 15 #include "chrome/common/notification_type.h" |
15 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // The maximum sizes of various texts passed to us from javascript. | 20 // The maximum sizes of various texts passed to us from javascript. |
20 const int kMessageTextMaxSize = 3000; | 21 const int kMessageTextMaxRows = 32; |
| 22 const int kMessageTextMaxCols = 132; |
21 const int kDefaultPromptTextSize = 2000; | 23 const int kDefaultPromptTextSize = 2000; |
22 | 24 |
23 } // namespace | 25 } // namespace |
24 | 26 |
25 JavaScriptAppModalDialog::JavaScriptAppModalDialog( | 27 JavaScriptAppModalDialog::JavaScriptAppModalDialog( |
26 JavaScriptAppModalDialogDelegate* delegate, | 28 JavaScriptAppModalDialogDelegate* delegate, |
27 const std::wstring& title, | 29 const std::wstring& title, |
28 int dialog_flags, | 30 int dialog_flags, |
29 const std::wstring& message_text, | 31 const std::wstring& message_text, |
30 const std::wstring& default_prompt_text, | 32 const std::wstring& default_prompt_text, |
31 bool display_suppress_checkbox, | 33 bool display_suppress_checkbox, |
32 bool is_before_unload_dialog, | 34 bool is_before_unload_dialog, |
33 IPC::Message* reply_msg) | 35 IPC::Message* reply_msg) |
34 : AppModalDialog(delegate->AsTabContents(), title), | 36 : AppModalDialog(delegate->AsTabContents(), title), |
35 delegate_(delegate), | 37 delegate_(delegate), |
36 extension_host_(delegate->AsExtensionHost()), | 38 extension_host_(delegate->AsExtensionHost()), |
37 dialog_flags_(dialog_flags), | 39 dialog_flags_(dialog_flags), |
38 display_suppress_checkbox_(display_suppress_checkbox), | 40 display_suppress_checkbox_(display_suppress_checkbox), |
39 is_before_unload_dialog_(is_before_unload_dialog), | 41 is_before_unload_dialog_(is_before_unload_dialog), |
40 reply_msg_(reply_msg) { | 42 reply_msg_(reply_msg) { |
41 // We trim the various parts of the message dialog because otherwise we can | 43 // We trim the various parts of the message dialog because otherwise we can |
42 // overflow the message dialog (and crash/hang the GTK+ version). | 44 // overflow the message dialog (and crash/hang the GTK+ version). |
43 gfx::ElideString(message_text, kMessageTextMaxSize, &message_text_); | 45 string16 elided_text; |
| 46 gfx::ElideRectangleString(WideToUTF16(message_text), |
| 47 kMessageTextMaxRows, kMessageTextMaxCols, &elided_text); |
| 48 message_text_ = UTF16ToWide(elided_text); |
44 gfx::ElideString(default_prompt_text, kDefaultPromptTextSize, | 49 gfx::ElideString(default_prompt_text, kDefaultPromptTextSize, |
45 &default_prompt_text_); | 50 &default_prompt_text_); |
46 | 51 |
47 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL)); | 52 DCHECK((tab_contents_ != NULL) != (extension_host_ != NULL)); |
48 InitNotifications(); | 53 InitNotifications(); |
49 } | 54 } |
50 | 55 |
51 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { | 56 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { |
52 } | 57 } |
53 | 58 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return; | 136 return; |
132 | 137 |
133 delegate_->OnMessageBoxClosed(reply_msg_, success, prompt_text); | 138 delegate_->OnMessageBoxClosed(reply_msg_, success, prompt_text); |
134 if (suppress_js_messages) | 139 if (suppress_js_messages) |
135 delegate_->SetSuppressMessageBoxes(true); | 140 delegate_->SetSuppressMessageBoxes(true); |
136 | 141 |
137 // On Views, we can end up coming through this code path twice :(. | 142 // On Views, we can end up coming through this code path twice :(. |
138 // See crbug.com/63732. | 143 // See crbug.com/63732. |
139 skip_this_dialog_ = true; | 144 skip_this_dialog_ = true; |
140 } | 145 } |
OLD | NEW |