| 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 "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 kMessageTextMaxRows = 32; | |
| 21 | |
| 22 // Helper object that receives the notification that the dialog/sheet is | 20 // Helper object that receives the notification that the dialog/sheet is |
| 23 // going away. Is responsible for cleaning itself up. | 21 // going away. Is responsible for cleaning itself up. |
| 24 @interface JavaScriptAppModalDialogHelper : NSObject<NSAlertDelegate> { | 22 @interface JavaScriptAppModalDialogHelper : NSObject<NSAlertDelegate> { |
| 25 @private | 23 @private |
| 26 base::scoped_nsobject<NSAlert> alert_; | 24 base::scoped_nsobject<NSAlert> alert_; |
| 27 NSTextField* textField_; // WEAK; owned by alert_ | 25 NSTextField* textField_; // WEAK; owned by alert_ |
| 28 } | 26 } |
| 29 | 27 |
| 30 - (NSAlert*)alert; | 28 - (NSAlert*)alert; |
| 31 - (NSTextField*)textField; | 29 - (NSTextField*)textField; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 alert_ = [helper_ alert]; | 139 alert_ = [helper_ alert]; |
| 142 NSTextField* field = nil; | 140 NSTextField* field = nil; |
| 143 if (text_field) { | 141 if (text_field) { |
| 144 field = [helper_ textField]; | 142 field = [helper_ textField]; |
| 145 [field setStringValue:base::SysUTF16ToNSString( | 143 [field setStringValue:base::SysUTF16ToNSString( |
| 146 dialog_->default_prompt_text())]; | 144 dialog_->default_prompt_text())]; |
| 147 } | 145 } |
| 148 [alert_ setDelegate:helper_]; | 146 [alert_ setDelegate:helper_]; |
| 149 NSString* informative_text = | 147 NSString* informative_text = |
| 150 base::SysUTF16ToNSString(dialog_->message_text()); | 148 base::SysUTF16ToNSString(dialog_->message_text()); |
| 151 | |
| 152 // Truncate long JS alerts - crbug.com/331219 | |
| 153 NSArray * info_array = | |
| 154 [informative_text componentsSeparatedByCharactersInSet: | |
| 155 [NSCharacterSet newlineCharacterSet]]; | |
| 156 if ([info_array count] > kMessageTextMaxRows) { | |
| 157 info_array = [info_array subarrayWithRange:NSMakeRange( | |
| 158 0, kMessageTextMaxRows)]; | |
| 159 informative_text = [info_array componentsJoinedByString:@"\n"]; | |
| 160 informative_text = [informative_text stringByAppendingString:@"\n..."]; | |
| 161 } | |
| 162 | |
| 163 [alert_ setInformativeText:informative_text]; | 149 [alert_ setInformativeText:informative_text]; |
| 164 NSString* message_text = | 150 NSString* message_text = |
| 165 base::SysUTF16ToNSString(dialog_->title()); | 151 base::SysUTF16ToNSString(dialog_->title()); |
| 166 [alert_ setMessageText:message_text]; | 152 [alert_ setMessageText:message_text]; |
| 167 [alert_ addButtonWithTitle:default_button]; | 153 [alert_ addButtonWithTitle:default_button]; |
| 168 if (!one_button) { | 154 if (!one_button) { |
| 169 NSButton* other = [alert_ addButtonWithTitle:other_button]; | 155 NSButton* other = [alert_ addButtonWithTitle:other_button]; |
| 170 [other setKeyEquivalent:@"\e"]; | 156 [other setKeyEquivalent:@"\e"]; |
| 171 } | 157 } |
| 172 if (dialog_->display_suppress_checkbox()) { | 158 if (dialog_->display_suppress_checkbox()) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 298 |
| 313 //////////////////////////////////////////////////////////////////////////////// | 299 //////////////////////////////////////////////////////////////////////////////// |
| 314 // NativeAppModalDialog, public: | 300 // NativeAppModalDialog, public: |
| 315 | 301 |
| 316 // static | 302 // static |
| 317 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 303 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
| 318 JavaScriptAppModalDialog* dialog, | 304 JavaScriptAppModalDialog* dialog, |
| 319 gfx::NativeWindow parent_window) { | 305 gfx::NativeWindow parent_window) { |
| 320 return new JavaScriptAppModalDialogCocoa(dialog); | 306 return new JavaScriptAppModalDialogCocoa(dialog); |
| 321 } | 307 } |
| OLD | NEW |