OLD | NEW |
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 "components/app_modal/javascript_app_modal_dialog.h" | 5 #include "components/app_modal/javascript_app_modal_dialog.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "components/app_modal/javascript_dialog_manager.h" | 10 #include "components/app_modal/javascript_dialog_manager.h" |
11 #include "components/app_modal/javascript_native_dialog_factory.h" | 11 #include "components/app_modal/javascript_native_dialog_factory.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "ui/gfx/text_elider.h" | 13 #include "ui/gfx/text_elider.h" |
14 #include "url/origin.h" | 14 #include "url/origin.h" |
15 | 15 |
16 namespace app_modal { | 16 namespace app_modal { |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Control maximum sizes of various texts passed to us from javascript. | |
20 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
21 // Two-dimensional eliding. Reformat the text of the message dialog | |
22 // inserting line breaks because otherwise a single long line can overflow | |
23 // the message dialog (and crash/hang the GTK, depending on the version). | |
24 const int kMessageTextMaxRows = 32; | |
25 const int kMessageTextMaxCols = 132; | |
26 const int kDefaultPromptMaxRows = 24; | |
27 const int kDefaultPromptMaxCols = 132; | |
28 void EnforceMaxTextSize(const base::string16& in_string, | |
29 base::string16* out_string) { | |
30 gfx::ElideRectangleString(in_string, kMessageTextMaxRows, | |
31 kMessageTextMaxCols, false, out_string); | |
32 } | |
33 void EnforceMaxPromptSize(const base::string16& in_string, | |
34 base::string16* out_string) { | |
35 gfx::ElideRectangleString(in_string, kDefaultPromptMaxRows, | |
36 kDefaultPromptMaxCols, false, out_string); | |
37 } | |
38 #else | |
39 // One-dimensional eliding. Trust the window system to break the string | 19 // One-dimensional eliding. Trust the window system to break the string |
40 // appropriately, but limit its overall length to something reasonable. | 20 // appropriately, but limit its overall length to something reasonable. |
41 const size_t kMessageTextMaxSize = 2000; | 21 const size_t kMessageTextMaxSize = 100; |
42 const size_t kDefaultPromptMaxSize = 2000; | 22 const size_t kDefaultPromptMaxSize = 50; |
43 void EnforceMaxTextSize(const base::string16& in_string, | 23 void EnforceMaxTextSize(const base::string16& in_string, |
44 base::string16* out_string) { | 24 base::string16* out_string) { |
45 gfx::ElideString(in_string, kMessageTextMaxSize, out_string); | 25 gfx::ElideString(in_string, kMessageTextMaxSize, out_string); |
46 } | 26 } |
47 void EnforceMaxPromptSize(const base::string16& in_string, | 27 void EnforceMaxPromptSize(const base::string16& in_string, |
48 base::string16* out_string) { | 28 base::string16* out_string) { |
49 gfx::ElideString(in_string, kDefaultPromptMaxSize, out_string); | 29 gfx::ElideString(in_string, kDefaultPromptMaxSize, out_string); |
50 } | 30 } |
51 #endif | |
52 | 31 |
53 } // namespace | 32 } // namespace |
54 | 33 |
55 ChromeJavaScriptDialogExtraData::ChromeJavaScriptDialogExtraData() | 34 ChromeJavaScriptDialogExtraData::ChromeJavaScriptDialogExtraData() |
56 : has_already_shown_a_dialog_(false), | 35 : has_already_shown_a_dialog_(false), |
57 suppress_javascript_messages_(false), | 36 suppress_javascript_messages_(false), |
58 suppressed_dialog_count_(0) {} | 37 suppressed_dialog_count_(0) {} |
59 | 38 |
60 JavaScriptAppModalDialog::JavaScriptAppModalDialog( | 39 JavaScriptAppModalDialog::JavaScriptAppModalDialog( |
61 content::WebContents* web_contents, | 40 content::WebContents* web_contents, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 155 |
177 // static | 156 // static |
178 std::string JavaScriptAppModalDialog::GetSerializedOriginForWebContents( | 157 std::string JavaScriptAppModalDialog::GetSerializedOriginForWebContents( |
179 content::WebContents* contents) { | 158 content::WebContents* contents) { |
180 if (!contents) | 159 if (!contents) |
181 return url::Origin().Serialize(); | 160 return url::Origin().Serialize(); |
182 return url::Origin(contents->GetLastCommittedURL()).Serialize(); | 161 return url::Origin(contents->GetLastCommittedURL()).Serialize(); |
183 } | 162 } |
184 | 163 |
185 } // namespace app_modal | 164 } // namespace app_modal |
OLD | NEW |