Index: chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.mm |
diff --git a/chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.mm b/chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.mm |
index 7341835b372e3527306b29bcf4a07474317b3d93..f98b7d39974368f3600a3c354bdb459db06a2e12 100644 |
--- a/chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.mm |
+++ b/chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.mm |
@@ -17,6 +17,9 @@ |
#include "ui/base/l10n/l10n_util_mac.h" |
#include "ui/base/ui_base_types.h" |
+const int kSlotsPerLine = 50; |
+const int kMessageTextMaxSlots = 2000; |
+ |
// Helper object that receives the notification that the dialog/sheet is |
// going away. Is responsible for cleaning itself up. |
@interface JavaScriptAppModalDialogHelper : NSObject<NSAlertDelegate> { |
@@ -146,6 +149,23 @@ JavaScriptAppModalDialogCocoa::JavaScriptAppModalDialogCocoa( |
[alert_ setDelegate:helper_]; |
NSString* informative_text = |
base::SysUTF16ToNSString(dialog_->message_text()); |
+ |
+ // Truncate long JS alerts - crbug.com/331219 |
+ NSCharacterSet* newline_char_set = [NSCharacterSet newlineCharacterSet]; |
+ for (size_t index = 0, slots_count = 0; index < informative_text.length; |
+ ++index) { |
+ unichar current_char = [informative_text characterAtIndex:index]; |
+ if ([newline_char_set characterIsMember:current_char]) |
+ slots_count += kSlotsPerLine; |
+ else |
+ slots_count++; |
+ if (slots_count > kMessageTextMaxSlots) { |
+ informative_text = [informative_text substringToIndex:index - 1]; |
Avi (use Gerrit)
2014/01/24 20:08:08
But that's what you're doing here with -substringT
|
+ informative_text = [informative_text stringByAppendingString:@"\n..."]; |
+ break; |
+ } |
+ } |
+ |
[alert_ setInformativeText:informative_text]; |
NSString* message_text = |
base::SysUTF16ToNSString(dialog_->title()); |