Chromium Code Reviews| Index: chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm b/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
| index df708813c6d13897c38c52112c02c69dcc13e9be..1dec33ca492a98241a5d5eeeab09dbe4d42c413b 100644 |
| --- a/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
| +++ b/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
| @@ -56,6 +56,10 @@ typedef NSUInteger CellAttributes; |
| - (NSDictionary*)buildDetailToggleItem:(size_t)type |
| permissionsDetailIndex:(size_t)index; |
| - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt; |
| +- (bool)appendPermissions:(const ExtensionInstallPrompt::Prompt&)prompt |
|
Alexei Svitkine (slow)
2014/09/12 19:32:23
How about the following name, which more closely f
gpdavis
2014/09/12 21:56:09
Done.
|
| + type:(ExtensionInstallPrompt::PermissionsType)type |
| + heading:(NSString**)heading |
| + children:(NSMutableArray*)children; |
| - (void)updateViewFrame:(NSRect)frame; |
| @end |
| @@ -592,37 +596,28 @@ bool HasAttribute(id item, CellAttributesMask attributeMask) { |
| - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { |
| NSMutableArray* warnings = [NSMutableArray array]; |
| NSString* heading = nil; |
| + NSString* withheld_heading = nil; |
|
Alexei Svitkine (slow)
2014/09/12 19:32:24
Using camelCase in ObjC methods. Here and in the c
gpdavis
2014/09/12 21:56:09
Done.
|
| ExtensionInstallPrompt::DetailsType type = |
| ExtensionInstallPrompt::PERMISSIONS_DETAILS; |
| + bool has_permissions = prompt.GetPermissionCount( |
| + ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); |
| if (prompt.ShouldShowPermissions()) { |
| NSMutableArray* children = [NSMutableArray array]; |
| - if (prompt.GetPermissionCount() > 0) { |
| - for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { |
| - [children addObject: |
| - [self buildItemWithTitle:SysUTF16ToNSString(prompt.GetPermission(i)) |
| - cellAttributes:kUseBullet |
| - children:nil]]; |
| - |
| - // If there are additional details, add them below this item. |
| - if (!prompt.GetPermissionsDetails(i).empty()) { |
| - if (prompt.GetIsShowingDetails( |
| - ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { |
| - [children addObject: |
| - [self buildItemWithTitle:SysUTF16ToNSString( |
| - prompt.GetPermissionsDetails(i)) |
| - cellAttributes:kNoExpandMarker |
| - children:nil]]; |
| - } |
| - |
| - // Add a row for the link. |
| - [children addObject: |
| - [self buildDetailToggleItem:type permissionsDetailIndex:i]]; |
| - } |
| - } |
| - |
| - heading = SysUTF16ToNSString(prompt.GetPermissionsHeading()); |
| - } else { |
| + NSMutableArray* withheld_children = [NSMutableArray array]; |
| + |
| + [self appendPermissions:prompt |
| + type:ExtensionInstallPrompt::PermissionsType:: |
| + REGULAR_PERMISSIONS |
| + heading:&heading |
| + children:children]; |
| + [self appendPermissions:prompt |
| + type:ExtensionInstallPrompt::PermissionsType:: |
| + WITHHELD_PERMISSIONS |
| + heading:&withheld_heading |
| + children:withheld_children]; |
| + |
| + if (!has_permissions) { |
| [children addObject: |
| [self buildItemWithTitle: |
| l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) |
| @@ -635,6 +630,14 @@ bool HasAttribute(id item, CellAttributesMask attributeMask) { |
| buildItemWithTitle:heading |
| cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker |
| children:children]]; |
| + |
| + // Add withheld permissions to the prompt if they exist. |
| + if (withheld_heading) { |
| + [warnings addObject:[self buildItemWithTitle:withheld_heading |
| + cellAttributes:kBoldText | kAutoExpandCell | |
|
Alexei Svitkine (slow)
2014/09/12 19:32:24
Nit: Make a local var for attributes to avoid this
gpdavis
2014/09/12 21:56:09
Done.
|
| + kNoExpandMarker |
| + children:withheld_children]]; |
| + } |
| } |
| if (prompt.GetRetainedFileCount() > 0) { |
| @@ -666,6 +669,44 @@ bool HasAttribute(id item, CellAttributesMask attributeMask) { |
| return warnings; |
| } |
| +- (bool)appendPermissions:(const ExtensionInstallPrompt::Prompt&)prompt |
| + type:(ExtensionInstallPrompt::PermissionsType)type |
| + heading:(NSString**)heading |
| + children:(NSMutableArray*)children { |
| + size_t permissions_count = prompt.GetPermissionCount(type); |
| + if (permissions_count > 0) { |
|
Alexei Svitkine (slow)
2014/09/12 19:32:24
Prefer an early return here.
gpdavis
2014/09/12 21:56:09
Done.
|
| + for (size_t i = 0; i < permissions_count; ++i) { |
| + [children |
| + addObject:[self buildItemWithTitle:SysUTF16ToNSString( |
| + prompt.GetPermission(i, type)) |
| + cellAttributes:kUseBullet |
| + children:nil]]; |
| + |
| + // If there are additional details, add them below this item. |
| + if (!prompt.GetPermissionsDetails(i, type).empty()) { |
| + if (prompt.GetIsShowingDetails( |
| + ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { |
| + [children |
| + addObject:[self |
| + buildItemWithTitle:SysUTF16ToNSString( |
| + prompt.GetPermissionsDetails( |
| + i, type)) |
| + cellAttributes:kNoExpandMarker |
| + children:nil]]; |
| + } |
| + |
| + // Add a row for the link. |
| + [children addObject:[self buildDetailToggleItem:type |
| + permissionsDetailIndex:i]]; |
| + } |
| + } |
| + |
| + *heading = SysUTF16ToNSString(prompt.GetPermissionsHeading(type)); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| - (void)updateViewFrame:(NSRect)frame { |
| NSWindow* window = [[self view] window]; |
| [window setFrame:[window frameRectForContentRect:frame] display:YES]; |