Chromium Code Reviews| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 - (BOOL)isBundleInstall; | 49 - (BOOL)isBundleInstall; |
| 50 - (BOOL)hasWebstoreData; | 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 - (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.
| |
| 60 type:(ExtensionInstallPrompt::PermissionsType)type | |
| 61 heading:(NSString**)heading | |
| 62 children:(NSMutableArray*)children; | |
| 59 - (void)updateViewFrame:(NSRect)frame; | 63 - (void)updateViewFrame:(NSRect)frame; |
| 60 @end | 64 @end |
| 61 | 65 |
| 62 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell { | 66 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell { |
| 63 NSUInteger permissionsDetailIndex_; | 67 NSUInteger permissionsDetailIndex_; |
| 64 ExtensionInstallPrompt::DetailsType permissionsDetailType_; | 68 ExtensionInstallPrompt::DetailsType permissionsDetailType_; |
| 65 SEL linkClickedAction_; | 69 SEL linkClickedAction_; |
| 66 } | 70 } |
| 67 | 71 |
| 68 @property(assign, nonatomic) NSUInteger permissionsDetailIndex; | 72 @property(assign, nonatomic) NSUInteger permissionsDetailIndex; |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell | | 589 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell | |
| 586 kNoExpandMarker], | 590 kNoExpandMarker], |
| 587 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], | 591 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], |
| 588 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], | 592 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], |
| 589 }; | 593 }; |
| 590 } | 594 } |
| 591 | 595 |
| 592 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { | 596 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { |
| 593 NSMutableArray* warnings = [NSMutableArray array]; | 597 NSMutableArray* warnings = [NSMutableArray array]; |
| 594 NSString* heading = nil; | 598 NSString* heading = nil; |
| 599 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.
| |
| 595 | 600 |
| 596 ExtensionInstallPrompt::DetailsType type = | 601 ExtensionInstallPrompt::DetailsType type = |
| 597 ExtensionInstallPrompt::PERMISSIONS_DETAILS; | 602 ExtensionInstallPrompt::PERMISSIONS_DETAILS; |
| 603 bool has_permissions = prompt.GetPermissionCount( | |
| 604 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); | |
| 598 if (prompt.ShouldShowPermissions()) { | 605 if (prompt.ShouldShowPermissions()) { |
| 599 NSMutableArray* children = [NSMutableArray array]; | 606 NSMutableArray* children = [NSMutableArray array]; |
| 600 if (prompt.GetPermissionCount() > 0) { | 607 NSMutableArray* withheld_children = [NSMutableArray array]; |
| 601 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { | |
| 602 [children addObject: | |
| 603 [self buildItemWithTitle:SysUTF16ToNSString(prompt.GetPermission(i)) | |
| 604 cellAttributes:kUseBullet | |
| 605 children:nil]]; | |
| 606 | 608 |
| 607 // If there are additional details, add them below this item. | 609 [self appendPermissions:prompt |
| 608 if (!prompt.GetPermissionsDetails(i).empty()) { | 610 type:ExtensionInstallPrompt::PermissionsType:: |
| 609 if (prompt.GetIsShowingDetails( | 611 REGULAR_PERMISSIONS |
| 610 ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { | 612 heading:&heading |
| 611 [children addObject: | 613 children:children]; |
| 612 [self buildItemWithTitle:SysUTF16ToNSString( | 614 [self appendPermissions:prompt |
| 613 prompt.GetPermissionsDetails(i)) | 615 type:ExtensionInstallPrompt::PermissionsType:: |
| 614 cellAttributes:kNoExpandMarker | 616 WITHHELD_PERMISSIONS |
| 615 children:nil]]; | 617 heading:&withheld_heading |
| 616 } | 618 children:withheld_children]; |
| 617 | 619 |
| 618 // Add a row for the link. | 620 if (!has_permissions) { |
| 619 [children addObject: | |
| 620 [self buildDetailToggleItem:type permissionsDetailIndex:i]]; | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 heading = SysUTF16ToNSString(prompt.GetPermissionsHeading()); | |
| 625 } else { | |
| 626 [children addObject: | 621 [children addObject: |
| 627 [self buildItemWithTitle: | 622 [self buildItemWithTitle: |
| 628 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) | 623 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) |
| 629 cellAttributes:kUseBullet | 624 cellAttributes:kUseBullet |
| 630 children:nil]]; | 625 children:nil]]; |
| 631 heading = @""; | 626 heading = @""; |
| 632 } | 627 } |
| 633 | 628 |
| 634 [warnings addObject:[self | 629 [warnings addObject:[self |
| 635 buildItemWithTitle:heading | 630 buildItemWithTitle:heading |
| 636 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker | 631 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker |
| 637 children:children]]; | 632 children:children]]; |
| 633 | |
| 634 // Add withheld permissions to the prompt if they exist. | |
| 635 if (withheld_heading) { | |
| 636 [warnings addObject:[self buildItemWithTitle:withheld_heading | |
| 637 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.
| |
| 638 kNoExpandMarker | |
| 639 children:withheld_children]]; | |
| 640 } | |
| 638 } | 641 } |
| 639 | 642 |
| 640 if (prompt.GetRetainedFileCount() > 0) { | 643 if (prompt.GetRetainedFileCount() > 0) { |
| 641 type = ExtensionInstallPrompt::RETAINED_FILES_DETAILS; | 644 type = ExtensionInstallPrompt::RETAINED_FILES_DETAILS; |
| 642 | 645 |
| 643 NSMutableArray* children = [NSMutableArray array]; | 646 NSMutableArray* children = [NSMutableArray array]; |
| 644 | 647 |
| 645 if (prompt.GetIsShowingDetails(type, 0)) { | 648 if (prompt.GetIsShowingDetails(type, 0)) { |
| 646 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { | 649 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { |
| 647 [children addObject: | 650 [children addObject: |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 659 children:children]]; | 662 children:children]]; |
| 660 | 663 |
| 661 // Add a row for the link. | 664 // Add a row for the link. |
| 662 [warnings addObject: | 665 [warnings addObject: |
| 663 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; | 666 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; |
| 664 } | 667 } |
| 665 | 668 |
| 666 return warnings; | 669 return warnings; |
| 667 } | 670 } |
| 668 | 671 |
| 672 - (bool)appendPermissions:(const ExtensionInstallPrompt::Prompt&)prompt | |
| 673 type:(ExtensionInstallPrompt::PermissionsType)type | |
| 674 heading:(NSString**)heading | |
| 675 children:(NSMutableArray*)children { | |
| 676 size_t permissions_count = prompt.GetPermissionCount(type); | |
| 677 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.
| |
| 678 for (size_t i = 0; i < permissions_count; ++i) { | |
| 679 [children | |
| 680 addObject:[self buildItemWithTitle:SysUTF16ToNSString( | |
| 681 prompt.GetPermission(i, type)) | |
| 682 cellAttributes:kUseBullet | |
| 683 children:nil]]; | |
| 684 | |
| 685 // If there are additional details, add them below this item. | |
| 686 if (!prompt.GetPermissionsDetails(i, type).empty()) { | |
| 687 if (prompt.GetIsShowingDetails( | |
| 688 ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { | |
| 689 [children | |
| 690 addObject:[self | |
| 691 buildItemWithTitle:SysUTF16ToNSString( | |
| 692 prompt.GetPermissionsDetails( | |
| 693 i, type)) | |
| 694 cellAttributes:kNoExpandMarker | |
| 695 children:nil]]; | |
| 696 } | |
| 697 | |
| 698 // Add a row for the link. | |
| 699 [children addObject:[self buildDetailToggleItem:type | |
| 700 permissionsDetailIndex:i]]; | |
| 701 } | |
| 702 } | |
| 703 | |
| 704 *heading = SysUTF16ToNSString(prompt.GetPermissionsHeading(type)); | |
| 705 return true; | |
| 706 } | |
| 707 return false; | |
| 708 } | |
| 709 | |
| 669 - (void)updateViewFrame:(NSRect)frame { | 710 - (void)updateViewFrame:(NSRect)frame { |
| 670 NSWindow* window = [[self view] window]; | 711 NSWindow* window = [[self view] window]; |
| 671 [window setFrame:[window frameRectForContentRect:frame] display:YES]; | 712 [window setFrame:[window frameRectForContentRect:frame] display:YES]; |
| 672 [[self view] setFrame:frame]; | 713 [[self view] setFrame:frame]; |
| 673 } | 714 } |
| 674 | 715 |
| 675 @end | 716 @end |
| 676 | 717 |
| 677 | 718 |
| 678 @implementation DetailToggleHyperlinkButtonCell | 719 @implementation DetailToggleHyperlinkButtonCell |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 } | 775 } |
| 735 | 776 |
| 736 - (void)accessibilityPerformAction:(NSString*)action { | 777 - (void)accessibilityPerformAction:(NSString*)action { |
| 737 if ([action isEqualToString:NSAccessibilityPressAction]) | 778 if ([action isEqualToString:NSAccessibilityPressAction]) |
| 738 [self handleLinkClicked]; | 779 [self handleLinkClicked]; |
| 739 else | 780 else |
| 740 [super accessibilityPerformAction:action]; | 781 [super accessibilityPerformAction:action]; |
| 741 } | 782 } |
| 742 | 783 |
| 743 @end | 784 @end |
| OLD | NEW |