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

Unified Diff: chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.mm

Issue 140323005: Truncate the Javascript alert message if the length is too long on Mac port (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Truncate the alert message Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b66cb253e20417d117ce4c6391531e94bd0f32fd 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,30 @@ JavaScriptAppModalDialogCocoa::JavaScriptAppModalDialogCocoa(
[alert_ setDelegate:helper_];
NSString* informative_text =
base::SysUTF16ToNSString(dialog_->message_text());
+
+ // Truncate long JS alerts - crbug.com/331219
+ NSArray* info_array =
+ [informative_text componentsSeparatedByCharactersInSet:
+ [NSCharacterSet newlineCharacterSet]];
+ informative_text = [[NSString alloc] init];
Avi (use Gerrit) 2014/01/24 01:53:24 This leaks. You can do informative_text = @"";
+ int occupied_slots = 0;
+ for (NSString* info_text in info_array) {
+ int new_slots =
+ info_text.length < kSlotsPerLine ? kSlotsPerLine : info_text.length;
Avi (use Gerrit) 2014/01/24 01:53:24 std::max?
+ int free_slots = kMessageTextMaxSlots - occupied_slots;
Avi (use Gerrit) 2014/01/24 01:53:24 You recompute free_slots each time; easier is to m
+ if (free_slots >= new_slots) {
+ informative_text = [informative_text stringByAppendingString:info_text];
+ informative_text = [informative_text stringByAppendingString:@"\n"];
+ occupied_slots += new_slots;
+ } else {
+ if ((int)info_text.length > free_slots)
Avi (use Gerrit) 2014/01/24 01:53:24 Alleviate the need for a cast if you make free_slo
+ info_text = [info_text substringToIndex:free_slots];
Avi (use Gerrit) 2014/01/24 01:53:24 Indent 2 for an if().
+ informative_text = [informative_text stringByAppendingString:info_text];
+ informative_text = [informative_text stringByAppendingString:@"\n..."];
Avi (use Gerrit) 2014/01/24 01:53:24 What bums me out is that we have gfx::TruncateStri
+ break;
+ }
+ }
+
[alert_ setInformativeText:informative_text];
NSString* message_text =
base::SysUTF16ToNSString(dialog_->title());
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698