Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller. h" | 5 #import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller. h" |
| 6 | 6 |
| 7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/memory/scoped_nsobject.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 @synthesize warningsField = warningsField_; | 76 @synthesize warningsField = warningsField_; |
| 77 @synthesize cancelButton = cancelButton_; | 77 @synthesize cancelButton = cancelButton_; |
| 78 @synthesize okButton = okButton_; | 78 @synthesize okButton = okButton_; |
| 79 @synthesize warningsSeparator = warningsSeparator_; | 79 @synthesize warningsSeparator = warningsSeparator_; |
| 80 @synthesize ratingStars = ratingStars_; | 80 @synthesize ratingStars = ratingStars_; |
| 81 @synthesize ratingCountField = ratingCountField_; | 81 @synthesize ratingCountField = ratingCountField_; |
| 82 @synthesize userCountField = userCountField_; | 82 @synthesize userCountField = userCountField_; |
| 83 | 83 |
| 84 - (id)initWithParentWindow:(NSWindow*)window | 84 - (id)initWithParentWindow:(NSWindow*)window |
| 85 profile:(Profile*)profile | 85 profile:(Profile*)profile |
| 86 extension:(const Extension*)extension | |
| 87 delegate:(ExtensionInstallUI::Delegate*)delegate | 86 delegate:(ExtensionInstallUI::Delegate*)delegate |
| 88 icon:(SkBitmap*)icon | |
| 89 prompt:(const ExtensionInstallUI::Prompt&)prompt { | 87 prompt:(const ExtensionInstallUI::Prompt&)prompt { |
| 90 NSString* nibpath = nil; | 88 NSString* nibpath = nil; |
| 91 | 89 |
| 92 // We use a different XIB in the case of inline installs or no permission | 90 // We use a different XIB in the case of inline installs or no permission |
| 93 // warnings, that respectively show webstore ratings data and are a more | 91 // warnings, that respectively show webstore ratings data and are a more |
| 94 // nicely laid out. | 92 // nicely laid out. |
| 95 if (prompt.type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT) { | 93 if (prompt.type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT) { |
| 96 nibpath = [base::mac::FrameworkBundle() | 94 nibpath = [base::mac::FrameworkBundle() |
| 97 pathForResource:@"ExtensionInstallPromptInline" | 95 pathForResource:@"ExtensionInstallPromptInline" |
| 98 ofType:@"nib"]; | 96 ofType:@"nib"]; |
| 99 } else if (prompt.GetPermissionCount() == 0) { | 97 } else if (prompt.GetPermissionCount() == 0) { |
| 100 nibpath = [base::mac::FrameworkBundle() | 98 nibpath = [base::mac::FrameworkBundle() |
| 101 pathForResource:@"ExtensionInstallPromptNoWarnings" | 99 pathForResource:@"ExtensionInstallPromptNoWarnings" |
| 102 ofType:@"nib"]; | 100 ofType:@"nib"]; |
| 103 } else { | 101 } else { |
| 104 nibpath = [base::mac::FrameworkBundle() | 102 nibpath = [base::mac::FrameworkBundle() |
| 105 pathForResource:@"ExtensionInstallPrompt" | 103 pathForResource:@"ExtensionInstallPrompt" |
| 106 ofType:@"nib"]; | 104 ofType:@"nib"]; |
| 107 } | 105 } |
| 108 | 106 |
| 109 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 107 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 110 parentWindow_ = window; | 108 parentWindow_ = window; |
| 111 profile_ = profile; | 109 profile_ = profile; |
| 112 icon_ = *icon; | |
| 113 delegate_ = delegate; | 110 delegate_ = delegate; |
| 114 extension_ = extension; | |
| 115 prompt_.reset(new ExtensionInstallUI::Prompt(prompt)); | 111 prompt_.reset(new ExtensionInstallUI::Prompt(prompt)); |
| 116 } | 112 } |
| 117 return self; | 113 return self; |
| 118 } | 114 } |
| 119 | 115 |
| 120 - (void)runAsModalSheet { | 116 - (void)runAsModalSheet { |
| 121 [NSApp beginSheet:[self window] | 117 [NSApp beginSheet:[self window] |
| 122 modalForWindow:parentWindow_ | 118 modalForWindow:parentWindow_ |
| 123 modalDelegate:self | 119 modalDelegate:self |
| 124 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) | 120 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) |
| 125 contextInfo:nil]; | 121 contextInfo:nil]; |
| 126 } | 122 } |
| 127 | 123 |
| 128 - (IBAction)storeLinkClicked:(id)sender { | 124 - (IBAction)storeLinkClicked:(id)sender { |
| 129 GURL store_url( | 125 GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() + |
| 130 extension_urls::GetWebstoreItemDetailURLPrefix() + extension_->id()); | 126 prompt_->extension()->id()); |
| 131 BrowserList::GetLastActiveWithProfile(profile_)->OpenURL(OpenURLParams( | 127 BrowserList::GetLastActiveWithProfile(profile_)->OpenURL(OpenURLParams( |
| 132 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, | 128 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, |
| 133 false)); | 129 false)); |
| 134 | 130 |
| 135 delegate_->InstallUIAbort(/*user_initiated=*/true); | 131 delegate_->InstallUIAbort(/*user_initiated=*/true); |
| 136 [NSApp endSheet:[self window]]; | 132 [NSApp endSheet:[self window]]; |
| 137 } | 133 } |
| 138 | 134 |
| 139 - (IBAction)cancel:(id)sender { | 135 - (IBAction)cancel:(id)sender { |
| 140 delegate_->InstallUIAbort(/*user_initiated=*/true); | 136 delegate_->InstallUIAbort(/*user_initiated=*/true); |
| 141 [NSApp endSheet:[self window]]; | 137 [NSApp endSheet:[self window]]; |
| 142 } | 138 } |
| 143 | 139 |
| 144 - (IBAction)ok:(id)sender { | 140 - (IBAction)ok:(id)sender { |
| 145 delegate_->InstallUIProceed(); | 141 delegate_->InstallUIProceed(); |
| 146 [NSApp endSheet:[self window]]; | 142 [NSApp endSheet:[self window]]; |
| 147 } | 143 } |
| 148 | 144 |
| 149 - (void)awakeFromNib { | 145 - (void)awakeFromNib { |
| 150 // Make sure we're the window's delegate as set in the nib. | 146 // Make sure we're the window's delegate as set in the nib. |
| 151 DCHECK_EQ(self, static_cast<ExtensionInstallDialogController*>( | 147 DCHECK_EQ(self, static_cast<ExtensionInstallDialogController*>( |
| 152 [[self window] delegate])); | 148 [[self window] delegate])); |
| 153 | 149 |
| 154 // Set control labels. | 150 // Set control labels. |
| 155 [titleField_ setStringValue:base::SysUTF16ToNSString( | 151 [titleField_ setStringValue:base::SysUTF16ToNSString( |
|
Robert Sesek
2012/02/23 20:12:32
Can you re-wrap this line?
jstritar
2012/02/24 18:21:46
Done.
| |
| 156 prompt_->GetHeading(extension_->name()))]; | 152 prompt_->GetHeading())]; |
| 157 [okButton_ setTitle:base::SysUTF16ToNSString( | 153 [okButton_ setTitle:base::SysUTF16ToNSString( |
| 158 prompt_->GetAcceptButtonLabel())]; | 154 prompt_->GetAcceptButtonLabel())]; |
| 159 [cancelButton_ setTitle:prompt_->HasAbortButtonLabel() ? | 155 [cancelButton_ setTitle:prompt_->HasAbortButtonLabel() ? |
| 160 base::SysUTF16ToNSString(prompt_->GetAbortButtonLabel()) : | 156 base::SysUTF16ToNSString(prompt_->GetAbortButtonLabel()) : |
| 161 l10n_util::GetNSString(IDS_CANCEL)]; | 157 l10n_util::GetNSString(IDS_CANCEL)]; |
| 162 if ([self isInlineInstall]) { | 158 if ([self isInlineInstall]) { |
| 163 prompt_->AppendRatingStars(AppendRatingStarsShim, self); | 159 prompt_->AppendRatingStars(AppendRatingStarsShim, self); |
| 164 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( | 160 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( |
| 165 prompt_->GetRatingCount())]; | 161 prompt_->GetRatingCount())]; |
| 166 [userCountField_ setStringValue:base::SysUTF16ToNSString( | 162 [userCountField_ setStringValue:base::SysUTF16ToNSString( |
| 167 prompt_->GetUserCount())]; | 163 prompt_->GetUserCount())]; |
| 168 } | 164 } |
| 169 | 165 |
| 170 NSImage* image = gfx::SkBitmapToNSImage(icon_); | 166 NSImage* image = gfx::SkBitmapToNSImage(prompt_->icon()); |
| 171 [iconView_ setImage:image]; | 167 [iconView_ setImage:image]; |
| 172 | 168 |
| 173 // Resize |titleField_| to fit the title. | 169 // Resize |titleField_| to fit the title. |
| 174 CGFloat originalTitleWidth = [titleField_ frame].size.width; | 170 CGFloat originalTitleWidth = [titleField_ frame].size.width; |
| 175 [titleField_ sizeToFit]; | 171 [titleField_ sizeToFit]; |
| 176 CGFloat newTitleWidth = [titleField_ frame].size.width; | 172 CGFloat newTitleWidth = [titleField_ frame].size.width; |
| 177 if (newTitleWidth > originalTitleWidth) { | 173 if (newTitleWidth > originalTitleWidth) { |
| 178 NSRect frame = [[self window] frame]; | 174 NSRect frame = [[self window] frame]; |
| 179 frame.size.width += newTitleWidth - originalTitleWidth; | 175 frame.size.width += newTitleWidth - originalTitleWidth; |
| 180 [[self window] setFrame:frame display:NO]; | 176 [[self window] setFrame:frame display:NO]; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 191 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; | 187 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; |
| 192 if (buttonDelta.width) { | 188 if (buttonDelta.width) { |
| 193 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], | 189 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], |
| 194 -buttonDelta.width, 0)]; | 190 -buttonDelta.width, 0)]; |
| 195 } | 191 } |
| 196 | 192 |
| 197 CGFloat totalOffset = 0.0; | 193 CGFloat totalOffset = 0.0; |
| 198 // If there are any warnings, then we have to do some special layout. | 194 // If there are any warnings, then we have to do some special layout. |
| 199 if (prompt_->GetPermissionCount() > 0) { | 195 if (prompt_->GetPermissionCount() > 0) { |
| 200 [subtitleField_ setStringValue:base::SysUTF16ToNSString( | 196 [subtitleField_ setStringValue:base::SysUTF16ToNSString( |
| 201 prompt_->GetPermissionsHeader())]; | 197 prompt_->GetPermissionsHeading())]; |
| 202 | 198 |
| 203 // We display the permission warnings as a simple text string, separated by | 199 // We display the permission warnings as a simple text string, separated by |
| 204 // newlines. | 200 // newlines. |
| 205 NSMutableString* joinedWarnings = [NSMutableString string]; | 201 NSMutableString* joinedWarnings = [NSMutableString string]; |
| 206 for (size_t i = 0; i < prompt_->GetPermissionCount(); ++i) { | 202 for (size_t i = 0; i < prompt_->GetPermissionCount(); ++i) { |
| 207 if (i > 0) | 203 if (i > 0) |
| 208 [joinedWarnings appendString:@"\n"]; | 204 [joinedWarnings appendString:@"\n"]; |
| 209 [joinedWarnings appendString:base::SysUTF16ToNSString( | 205 [joinedWarnings appendString:base::SysUTF16ToNSString( |
| 210 prompt_->GetPermission(i))]; | 206 prompt_->GetPermission(i))]; |
| 211 } | 207 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 skiaImage->width(), skiaImage->height()); | 284 skiaImage->width(), skiaImage->height()); |
| 289 [view setFrame:starBounds]; | 285 [view setFrame:starBounds]; |
| 290 [ratingStars_ addSubview:view]; | 286 [ratingStars_ addSubview:view]; |
| 291 } | 287 } |
| 292 | 288 |
| 293 @end // ExtensionInstallDialogController | 289 @end // ExtensionInstallDialogController |
| 294 | 290 |
| 295 void ShowExtensionInstallDialogImpl( | 291 void ShowExtensionInstallDialogImpl( |
| 296 Profile* profile, | 292 Profile* profile, |
| 297 ExtensionInstallUI::Delegate* delegate, | 293 ExtensionInstallUI::Delegate* delegate, |
| 298 const Extension* extension, | |
| 299 SkBitmap* icon, | |
| 300 const ExtensionInstallUI::Prompt& prompt) { | 294 const ExtensionInstallUI::Prompt& prompt) { |
| 301 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 295 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 302 if (!browser) { | 296 if (!browser) { |
| 303 delegate->InstallUIAbort(false); | 297 delegate->InstallUIAbort(false); |
| 304 return; | 298 return; |
| 305 } | 299 } |
| 306 | 300 |
| 307 BrowserWindow* window = browser->window(); | 301 BrowserWindow* window = browser->window(); |
| 308 if (!window) { | 302 if (!window) { |
| 309 delegate->InstallUIAbort(false); | 303 delegate->InstallUIAbort(false); |
| 310 return; | 304 return; |
| 311 } | 305 } |
| 312 | 306 |
| 313 gfx::NativeWindow native_window = window->GetNativeHandle(); | 307 gfx::NativeWindow native_window = window->GetNativeHandle(); |
| 314 | 308 |
| 315 ExtensionInstallDialogController* controller = | 309 ExtensionInstallDialogController* controller = |
| 316 [[ExtensionInstallDialogController alloc] | 310 [[ExtensionInstallDialogController alloc] |
| 317 initWithParentWindow:native_window | 311 initWithParentWindow:native_window |
| 318 profile:profile | 312 profile:profile |
| 319 extension:extension | |
| 320 delegate:delegate | 313 delegate:delegate |
| 321 icon:icon | |
| 322 prompt:prompt]; | 314 prompt:prompt]; |
| 323 | 315 |
| 324 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455) | 316 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455) |
| 325 [controller runAsModalSheet]; | 317 [controller runAsModalSheet]; |
| 326 } | 318 } |
| OLD | NEW |