| 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 #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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
| 9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #include "base/memory/scoped_nsobject.h" | 10 #include "base/memory/scoped_nsobject.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 @synthesize warningsField = warningsField_; | 83 @synthesize warningsField = warningsField_; |
| 84 @synthesize cancelButton = cancelButton_; | 84 @synthesize cancelButton = cancelButton_; |
| 85 @synthesize okButton = okButton_; | 85 @synthesize okButton = okButton_; |
| 86 @synthesize warningsSeparator = warningsSeparator_; | 86 @synthesize warningsSeparator = warningsSeparator_; |
| 87 @synthesize ratingStars = ratingStars_; | 87 @synthesize ratingStars = ratingStars_; |
| 88 @synthesize ratingCountField = ratingCountField_; | 88 @synthesize ratingCountField = ratingCountField_; |
| 89 @synthesize userCountField = userCountField_; | 89 @synthesize userCountField = userCountField_; |
| 90 | 90 |
| 91 - (id)initWithParentWindow:(NSWindow*)window | 91 - (id)initWithParentWindow:(NSWindow*)window |
| 92 profile:(Profile*)profile | 92 profile:(Profile*)profile |
| 93 delegate:(ExtensionInstallUI::Delegate*)delegate | 93 delegate:(ExtensionInstallPrompt::Delegate*)delegate |
| 94 prompt:(const ExtensionInstallUI::Prompt&)prompt { | 94 prompt:(const ExtensionInstallPrompt::Prompt&)prompt { |
| 95 NSString* nibpath = nil; | 95 NSString* nibpath = nil; |
| 96 | 96 |
| 97 // We use a different XIB in the case of bundle installs, inline installs or | 97 // We use a different XIB in the case of bundle installs, inline installs or |
| 98 // no permission warnings. These are laid out nicely for the data they | 98 // no permission warnings. These are laid out nicely for the data they |
| 99 // display. | 99 // display. |
| 100 if (prompt.type() == ExtensionInstallUI::BUNDLE_INSTALL_PROMPT) { | 100 if (prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT) { |
| 101 nibpath = [base::mac::FrameworkBundle() | 101 nibpath = [base::mac::FrameworkBundle() |
| 102 pathForResource:@"ExtensionInstallPromptBundle" | 102 pathForResource:@"ExtensionInstallPromptBundle" |
| 103 ofType:@"nib"]; | 103 ofType:@"nib"]; |
| 104 } else if (prompt.type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT) { | 104 } else if (prompt.type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT) { |
| 105 nibpath = [base::mac::FrameworkBundle() | 105 nibpath = [base::mac::FrameworkBundle() |
| 106 pathForResource:@"ExtensionInstallPromptInline" | 106 pathForResource:@"ExtensionInstallPromptInline" |
| 107 ofType:@"nib"]; | 107 ofType:@"nib"]; |
| 108 } else if (prompt.GetPermissionCount() == 0) { | 108 } else if (prompt.GetPermissionCount() == 0) { |
| 109 nibpath = [base::mac::FrameworkBundle() | 109 nibpath = [base::mac::FrameworkBundle() |
| 110 pathForResource:@"ExtensionInstallPromptNoWarnings" | 110 pathForResource:@"ExtensionInstallPromptNoWarnings" |
| 111 ofType:@"nib"]; | 111 ofType:@"nib"]; |
| 112 } else { | 112 } else { |
| 113 nibpath = [base::mac::FrameworkBundle() | 113 nibpath = [base::mac::FrameworkBundle() |
| 114 pathForResource:@"ExtensionInstallPrompt" | 114 pathForResource:@"ExtensionInstallPrompt" |
| 115 ofType:@"nib"]; | 115 ofType:@"nib"]; |
| 116 } | 116 } |
| 117 | 117 |
| 118 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 118 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 119 parentWindow_ = window; | 119 parentWindow_ = window; |
| 120 profile_ = profile; | 120 profile_ = profile; |
| 121 delegate_ = delegate; | 121 delegate_ = delegate; |
| 122 prompt_.reset(new ExtensionInstallUI::Prompt(prompt)); | 122 prompt_.reset(new ExtensionInstallPrompt::Prompt(prompt)); |
| 123 } | 123 } |
| 124 return self; | 124 return self; |
| 125 } | 125 } |
| 126 | 126 |
| 127 - (void)runAsModalSheet { | 127 - (void)runAsModalSheet { |
| 128 [NSApp beginSheet:[self window] | 128 [NSApp beginSheet:[self window] |
| 129 modalForWindow:parentWindow_ | 129 modalForWindow:parentWindow_ |
| 130 modalDelegate:self | 130 modalDelegate:self |
| 131 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) | 131 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) |
| 132 contextInfo:nil]; | 132 contextInfo:nil]; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 returnCode:(int)returnCode | 283 returnCode:(int)returnCode |
| 284 contextInfo:(void*)contextInfo { | 284 contextInfo:(void*)contextInfo { |
| 285 [sheet close]; | 285 [sheet close]; |
| 286 } | 286 } |
| 287 | 287 |
| 288 - (void)windowWillClose:(NSNotification*)notification { | 288 - (void)windowWillClose:(NSNotification*)notification { |
| 289 [self autorelease]; | 289 [self autorelease]; |
| 290 } | 290 } |
| 291 | 291 |
| 292 - (BOOL)isBundleInstall { | 292 - (BOOL)isBundleInstall { |
| 293 return prompt_->type() == ExtensionInstallUI::BUNDLE_INSTALL_PROMPT; | 293 return prompt_->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; |
| 294 } | 294 } |
| 295 | 295 |
| 296 - (BOOL)isInlineInstall { | 296 - (BOOL)isInlineInstall { |
| 297 return prompt_->type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT; | 297 return prompt_->type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT; |
| 298 } | 298 } |
| 299 | 299 |
| 300 - (void)appendRatingStar:(const SkBitmap*)skiaImage { | 300 - (void)appendRatingStar:(const SkBitmap*)skiaImage { |
| 301 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( | 301 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( |
| 302 *skiaImage, base::mac::GetSystemColorSpace()); | 302 *skiaImage, base::mac::GetSystemColorSpace()); |
| 303 NSRect frame = NSMakeRect(0, 0, skiaImage->width(), skiaImage->height()); | 303 NSRect frame = NSMakeRect(0, 0, skiaImage->width(), skiaImage->height()); |
| 304 scoped_nsobject<NSImageView> view([[NSImageView alloc] initWithFrame:frame]); | 304 scoped_nsobject<NSImageView> view([[NSImageView alloc] initWithFrame:frame]); |
| 305 [view setImage:image]; | 305 [view setImage:image]; |
| 306 | 306 |
| 307 // Add this star after all the other ones | 307 // Add this star after all the other ones |
| 308 CGFloat maxStarRight = 0; | 308 CGFloat maxStarRight = 0; |
| 309 if ([[ratingStars_ subviews] count]) { | 309 if ([[ratingStars_ subviews] count]) { |
| 310 maxStarRight = NSMaxX([[[ratingStars_ subviews] lastObject] frame]); | 310 maxStarRight = NSMaxX([[[ratingStars_ subviews] lastObject] frame]); |
| 311 } | 311 } |
| 312 NSRect starBounds = NSMakeRect(maxStarRight, 0, | 312 NSRect starBounds = NSMakeRect(maxStarRight, 0, |
| 313 skiaImage->width(), skiaImage->height()); | 313 skiaImage->width(), skiaImage->height()); |
| 314 [view setFrame:starBounds]; | 314 [view setFrame:starBounds]; |
| 315 [ratingStars_ addSubview:view]; | 315 [ratingStars_ addSubview:view]; |
| 316 } | 316 } |
| 317 | 317 |
| 318 @end // ExtensionInstallDialogController | 318 @end // ExtensionInstallDialogController |
| 319 | 319 |
| 320 void ShowExtensionInstallDialogImpl( | 320 void ShowExtensionInstallDialogImpl( |
| 321 Profile* profile, | 321 Profile* profile, |
| 322 ExtensionInstallUI::Delegate* delegate, | 322 ExtensionInstallPrompt::Delegate* delegate, |
| 323 const ExtensionInstallUI::Prompt& prompt) { | 323 const ExtensionInstallPrompt::Prompt& prompt) { |
| 324 Browser* browser = browser::FindLastActiveWithProfile(profile); | 324 Browser* browser = BrowserList::FindLastActiveWithProfile(profile); |
| 325 if (!browser) { | 325 if (!browser) { |
| 326 delegate->InstallUIAbort(false); | 326 delegate->InstallUIAbort(false); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 BrowserWindow* window = browser->window(); | 330 BrowserWindow* window = browser->window(); |
| 331 if (!window) { | 331 if (!window) { |
| 332 delegate->InstallUIAbort(false); | 332 delegate->InstallUIAbort(false); |
| 333 return; | 333 return; |
| 334 } | 334 } |
| 335 | 335 |
| 336 gfx::NativeWindow native_window = window->GetNativeHandle(); | 336 gfx::NativeWindow native_window = window->GetNativeHandle(); |
| 337 | 337 |
| 338 ExtensionInstallDialogController* controller = | 338 ExtensionInstallDialogController* controller = |
| 339 [[ExtensionInstallDialogController alloc] | 339 [[ExtensionInstallDialogController alloc] |
| 340 initWithParentWindow:native_window | 340 initWithParentWindow:native_window |
| 341 profile:profile | 341 profile:profile |
| 342 delegate:delegate | 342 delegate:delegate |
| 343 prompt:prompt]; | 343 prompt:prompt]; |
| 344 | 344 |
| 345 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455) | 345 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455) |
| 346 [controller runAsModalSheet]; | 346 [controller runAsModalSheet]; |
| 347 } | 347 } |
| OLD | NEW |