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

Side by Side 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: updated patch 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 unified diff | Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.h" 5 #include "chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #import "base/mac/foundation_util.h" 11 #import "base/mac/foundation_util.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #import "chrome/browser/chrome_browser_application_mac.h" 13 #import "chrome/browser/chrome_browser_application_mac.h"
14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" 14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "grit/ui_strings.h" 16 #include "grit/ui_strings.h"
17 #include "ui/base/l10n/l10n_util_mac.h" 17 #include "ui/base/l10n/l10n_util_mac.h"
18 #include "ui/base/ui_base_types.h" 18 #include "ui/base/ui_base_types.h"
19 19
20 const int kSlotsPerLine = 50;
21 const int kMessageTextMaxSlots = 2000;
22
20 // Helper object that receives the notification that the dialog/sheet is 23 // Helper object that receives the notification that the dialog/sheet is
21 // going away. Is responsible for cleaning itself up. 24 // going away. Is responsible for cleaning itself up.
22 @interface JavaScriptAppModalDialogHelper : NSObject<NSAlertDelegate> { 25 @interface JavaScriptAppModalDialogHelper : NSObject<NSAlertDelegate> {
23 @private 26 @private
24 base::scoped_nsobject<NSAlert> alert_; 27 base::scoped_nsobject<NSAlert> alert_;
25 NSTextField* textField_; // WEAK; owned by alert_ 28 NSTextField* textField_; // WEAK; owned by alert_
26 } 29 }
27 30
28 - (NSAlert*)alert; 31 - (NSAlert*)alert;
29 - (NSTextField*)textField; 32 - (NSTextField*)textField;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 alert_ = [helper_ alert]; 142 alert_ = [helper_ alert];
140 NSTextField* field = nil; 143 NSTextField* field = nil;
141 if (text_field) { 144 if (text_field) {
142 field = [helper_ textField]; 145 field = [helper_ textField];
143 [field setStringValue:base::SysUTF16ToNSString( 146 [field setStringValue:base::SysUTF16ToNSString(
144 dialog_->default_prompt_text())]; 147 dialog_->default_prompt_text())];
145 } 148 }
146 [alert_ setDelegate:helper_]; 149 [alert_ setDelegate:helper_];
147 NSString* informative_text = 150 NSString* informative_text =
148 base::SysUTF16ToNSString(dialog_->message_text()); 151 base::SysUTF16ToNSString(dialog_->message_text());
152
153 // Truncate long JS alerts - crbug.com/331219
154 NSCharacterSet* newline_char_set = [NSCharacterSet newlineCharacterSet];
155 for (size_t index = 0, slots_count = 0; index < informative_text.length;
156 ++index) {
157 unichar current_char = [informative_text characterAtIndex:index];
158 if ([newline_char_set characterIsMember:current_char])
159 slots_count += kSlotsPerLine;
160 else
161 slots_count++;
162 if (slots_count > kMessageTextMaxSlots) {
163 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
164 informative_text = [informative_text stringByAppendingString:@"\n..."];
165 break;
166 }
167 }
168
149 [alert_ setInformativeText:informative_text]; 169 [alert_ setInformativeText:informative_text];
150 NSString* message_text = 170 NSString* message_text =
151 base::SysUTF16ToNSString(dialog_->title()); 171 base::SysUTF16ToNSString(dialog_->title());
152 [alert_ setMessageText:message_text]; 172 [alert_ setMessageText:message_text];
153 [alert_ addButtonWithTitle:default_button]; 173 [alert_ addButtonWithTitle:default_button];
154 if (!one_button) { 174 if (!one_button) {
155 NSButton* other = [alert_ addButtonWithTitle:other_button]; 175 NSButton* other = [alert_ addButtonWithTitle:other_button];
156 [other setKeyEquivalent:@"\e"]; 176 [other setKeyEquivalent:@"\e"];
157 } 177 }
158 if (dialog_->display_suppress_checkbox()) { 178 if (dialog_->display_suppress_checkbox()) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 318
299 //////////////////////////////////////////////////////////////////////////////// 319 ////////////////////////////////////////////////////////////////////////////////
300 // NativeAppModalDialog, public: 320 // NativeAppModalDialog, public:
301 321
302 // static 322 // static
303 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( 323 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt(
304 JavaScriptAppModalDialog* dialog, 324 JavaScriptAppModalDialog* dialog,
305 gfx::NativeWindow parent_window) { 325 gfx::NativeWindow parent_window) {
306 return new JavaScriptAppModalDialogCocoa(dialog); 326 return new JavaScriptAppModalDialogCocoa(dialog);
307 } 327 }
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698