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_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 kUseCustomLinkCell = 1 << 4, | 40 kUseCustomLinkCell = 1 << 4, |
41 kCanExpand = 1 << 5, | 41 kCanExpand = 1 << 5, |
42 }; | 42 }; |
43 | 43 |
44 typedef NSUInteger CellAttributes; | 44 typedef NSUInteger CellAttributes; |
45 | 45 |
46 } // namespace. | 46 } // namespace. |
47 | 47 |
48 @interface ExtensionInstallViewController () | 48 @interface ExtensionInstallViewController () |
49 - (BOOL)isBundleInstall; | 49 - (BOOL)isBundleInstall; |
50 - (BOOL)isInlineInstall; | 50 - (BOOL)hasWebstoreData; |
51 - (void)appendRatingStar:(const gfx::ImageSkia*)skiaImage; | 51 - (void)appendRatingStar:(const gfx::ImageSkia*)skiaImage; |
52 - (void)onOutlineViewRowCountDidChange; | 52 - (void)onOutlineViewRowCountDidChange; |
53 - (NSDictionary*)buildItemWithTitle:(NSString*)title | 53 - (NSDictionary*)buildItemWithTitle:(NSString*)title |
54 cellAttributes:(CellAttributes)cellAttributes | 54 cellAttributes:(CellAttributes)cellAttributes |
55 children:(NSArray*)children; | 55 children:(NSArray*)children; |
56 - (NSDictionary*)buildDetailToggleItem:(size_t)type | 56 - (NSDictionary*)buildDetailToggleItem:(size_t)type |
57 permissionsDetailIndex:(size_t)index; | 57 permissionsDetailIndex:(size_t)index; |
58 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt; | 58 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt; |
59 - (void)updateViewFrame:(NSRect)frame; | 59 - (void)updateViewFrame:(NSRect)frame; |
60 @end | 60 @end |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 @synthesize outlineView = outlineView_; | 174 @synthesize outlineView = outlineView_; |
175 @synthesize warningsSeparator = warningsSeparator_; | 175 @synthesize warningsSeparator = warningsSeparator_; |
176 @synthesize ratingStars = ratingStars_; | 176 @synthesize ratingStars = ratingStars_; |
177 @synthesize ratingCountField = ratingCountField_; | 177 @synthesize ratingCountField = ratingCountField_; |
178 @synthesize userCountField = userCountField_; | 178 @synthesize userCountField = userCountField_; |
179 @synthesize storeLinkButton = storeLinkButton_; | 179 @synthesize storeLinkButton = storeLinkButton_; |
180 | 180 |
181 - (id)initWithNavigator:(content::PageNavigator*)navigator | 181 - (id)initWithNavigator:(content::PageNavigator*)navigator |
182 delegate:(ExtensionInstallPrompt::Delegate*)delegate | 182 delegate:(ExtensionInstallPrompt::Delegate*)delegate |
183 prompt:(const ExtensionInstallPrompt::Prompt&)prompt { | 183 prompt:(const ExtensionInstallPrompt::Prompt&)prompt { |
184 // We use a different XIB in the case of bundle installs, inline installs or | 184 // We use a different XIB in the case of bundle installs, installs with |
185 // no permission warnings. These are laid out nicely for the data they | 185 // webstore data, or no permission warnings. These are laid out nicely for |
186 // display. | 186 // the data they display. |
187 NSString* nibName = nil; | 187 NSString* nibName = nil; |
188 if (prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT) { | 188 if (prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT) { |
189 nibName = @"ExtensionInstallPromptBundle"; | 189 nibName = @"ExtensionInstallPromptBundle"; |
190 } else if (prompt.type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT) { | 190 } else if (prompt.has_webstore_data()) { |
191 nibName = @"ExtensionInstallPromptInline"; | 191 nibName = @"ExtensionInstallPromptWebstoreData"; |
192 } else if (!prompt.ShouldShowPermissions() && | 192 } else if (!prompt.ShouldShowPermissions() && |
193 prompt.GetOAuthIssueCount() == 0 && | 193 prompt.GetOAuthIssueCount() == 0 && |
194 prompt.GetRetainedFileCount() == 0) { | 194 prompt.GetRetainedFileCount() == 0) { |
195 nibName = @"ExtensionInstallPromptNoWarnings"; | 195 nibName = @"ExtensionInstallPromptNoWarnings"; |
196 } else { | 196 } else { |
197 nibName = @"ExtensionInstallPrompt"; | 197 nibName = @"ExtensionInstallPrompt"; |
198 } | 198 } |
199 | 199 |
200 if ((self = [super initWithNibName:nibName | 200 if ((self = [super initWithNibName:nibName |
201 bundle:base::mac::FrameworkBundle()])) { | 201 bundle:base::mac::FrameworkBundle()])) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 [okButton_ setTitle:base::SysUTF16ToNSString( | 233 [okButton_ setTitle:base::SysUTF16ToNSString( |
234 prompt_->GetAcceptButtonLabel())]; | 234 prompt_->GetAcceptButtonLabel())]; |
235 } else { | 235 } else { |
236 [okButton_ removeFromSuperview]; | 236 [okButton_ removeFromSuperview]; |
237 okButtonRect = [okButton_ frame]; | 237 okButtonRect = [okButton_ frame]; |
238 okButton_ = nil; | 238 okButton_ = nil; |
239 } | 239 } |
240 [cancelButton_ setTitle:prompt_->HasAbortButtonLabel() ? | 240 [cancelButton_ setTitle:prompt_->HasAbortButtonLabel() ? |
241 base::SysUTF16ToNSString(prompt_->GetAbortButtonLabel()) : | 241 base::SysUTF16ToNSString(prompt_->GetAbortButtonLabel()) : |
242 l10n_util::GetNSString(IDS_CANCEL)]; | 242 l10n_util::GetNSString(IDS_CANCEL)]; |
243 if ([self isInlineInstall]) { | 243 if ([self hasWebstoreData]) { |
244 prompt_->AppendRatingStars(AppendRatingStarsShim, self); | 244 prompt_->AppendRatingStars(AppendRatingStarsShim, self); |
245 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( | 245 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( |
246 prompt_->GetRatingCount())]; | 246 prompt_->GetRatingCount())]; |
247 [userCountField_ setStringValue:base::SysUTF16ToNSString( | 247 [userCountField_ setStringValue:base::SysUTF16ToNSString( |
248 prompt_->GetUserCount())]; | 248 prompt_->GetUserCount())]; |
249 [[storeLinkButton_ cell] setUnderlineOnHover:YES]; | 249 [[storeLinkButton_ cell] setUnderlineOnHover:YES]; |
250 [[storeLinkButton_ cell] setTextColor: | 250 [[storeLinkButton_ cell] setTextColor: |
251 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; | 251 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; |
252 } | 252 } |
253 | 253 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 NSSize spacing = [outlineView_ intercellSpacing]; | 315 NSSize spacing = [outlineView_ intercellSpacing]; |
316 spacing.width += 2; | 316 spacing.width += 2; |
317 spacing.height += 2; | 317 spacing.height += 2; |
318 [outlineView_ setIntercellSpacing:spacing]; | 318 [outlineView_ setIntercellSpacing:spacing]; |
319 [[[[outlineView_ tableColumns] objectAtIndex:0] dataCell] setWraps:YES]; | 319 [[[[outlineView_ tableColumns] objectAtIndex:0] dataCell] setWraps:YES]; |
320 for (id item in warnings_.get()) | 320 for (id item in warnings_.get()) |
321 [self expandItemAndChildren:item]; | 321 [self expandItemAndChildren:item]; |
322 | 322 |
323 // Adjust the outline view to fit the warnings. | 323 // Adjust the outline view to fit the warnings. |
324 OffsetOutlineViewVerticallyToFitContent(outlineView_, &totalOffset); | 324 OffsetOutlineViewVerticallyToFitContent(outlineView_, &totalOffset); |
325 } else if ([self isInlineInstall] || [self isBundleInstall]) { | 325 } else if ([self hasWebstoreData] || [self isBundleInstall]) { |
326 // Inline and bundle installs that don't have a permissions section need to | 326 // Installs with webstore data and bundle installs that don't have a |
327 // hide controls related to that and shrink the window by the space they | 327 // permissions section need to hide controls related to that and shrink the |
328 // take up. | 328 // window by the space they take up. |
329 NSRect hiddenRect = NSUnionRect([warningsSeparator_ frame], | 329 NSRect hiddenRect = NSUnionRect([warningsSeparator_ frame], |
330 [[outlineView_ enclosingScrollView] frame]); | 330 [[outlineView_ enclosingScrollView] frame]); |
331 [warningsSeparator_ setHidden:YES]; | 331 [warningsSeparator_ setHidden:YES]; |
332 [[outlineView_ enclosingScrollView] setHidden:YES]; | 332 [[outlineView_ enclosingScrollView] setHidden:YES]; |
333 totalOffset -= NSHeight(hiddenRect) + kWarningsSeparatorPadding; | 333 totalOffset -= NSHeight(hiddenRect) + kWarningsSeparatorPadding; |
334 } | 334 } |
335 | 335 |
336 // If necessary, adjust the window size. | 336 // If necessary, adjust the window size. |
337 if (totalOffset) { | 337 if (totalOffset) { |
338 NSRect currentRect = [[self view] bounds]; | 338 NSRect currentRect = [[self view] bounds]; |
339 currentRect.size.height += totalOffset; | 339 currentRect.size.height += totalOffset; |
340 [self updateViewFrame:currentRect]; | 340 [self updateViewFrame:currentRect]; |
341 } | 341 } |
342 } | 342 } |
343 | 343 |
344 - (BOOL)isBundleInstall { | 344 - (BOOL)isBundleInstall { |
345 return prompt_->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; | 345 return prompt_->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; |
346 } | 346 } |
347 | 347 |
348 - (BOOL)isInlineInstall { | 348 - (BOOL)hasWebstoreData { |
349 return prompt_->type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT; | 349 return prompt_->has_webstore_data(); |
350 } | 350 } |
351 | 351 |
352 - (void)appendRatingStar:(const gfx::ImageSkia*)skiaImage { | 352 - (void)appendRatingStar:(const gfx::ImageSkia*)skiaImage { |
353 NSImage* image = gfx::NSImageFromImageSkiaWithColorSpace( | 353 NSImage* image = gfx::NSImageFromImageSkiaWithColorSpace( |
354 *skiaImage, base::mac::GetSystemColorSpace()); | 354 *skiaImage, base::mac::GetSystemColorSpace()); |
355 NSRect frame = NSMakeRect(0, 0, skiaImage->width(), skiaImage->height()); | 355 NSRect frame = NSMakeRect(0, 0, skiaImage->width(), skiaImage->height()); |
356 base::scoped_nsobject<NSImageView> view( | 356 base::scoped_nsobject<NSImageView> view( |
357 [[NSImageView alloc] initWithFrame:frame]); | 357 [[NSImageView alloc] initWithFrame:frame]); |
358 [view setImage:image]; | 358 [view setImage:image]; |
359 | 359 |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 } | 771 } |
772 | 772 |
773 - (void)accessibilityPerformAction:(NSString*)action { | 773 - (void)accessibilityPerformAction:(NSString*)action { |
774 if ([action isEqualToString:NSAccessibilityPressAction]) | 774 if ([action isEqualToString:NSAccessibilityPressAction]) |
775 [self handleLinkClicked]; | 775 [self handleLinkClicked]; |
776 else | 776 else |
777 [super accessibilityPerformAction:action]; | 777 [super accessibilityPerformAction:action]; |
778 } | 778 } |
779 | 779 |
780 @end | 780 @end |
OLD | NEW |