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 - (NSString*)appendPermissionsToPrompt:(const ExtensionInstallPrompt::Prompt&) | |
Alexei Svitkine (slow)
2014/09/15 20:48:16
Can you add a comment documenting this function? I
gpdavis
2014/09/16 19:01:47
Done.
| |
60 prompt withType:(ExtensionInstallPrompt::PermissionsType)type | |
Alexei Svitkine (slow)
2014/09/15 20:48:16
I don't think git cl format works well for ObjC.
gpdavis
2014/09/16 19:01:47
Done.
| |
61 children:(NSMutableArray*)children; | |
59 - (void)updateViewFrame:(NSRect)frame; | 62 - (void)updateViewFrame:(NSRect)frame; |
60 @end | 63 @end |
61 | 64 |
62 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell { | 65 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell { |
63 NSUInteger permissionsDetailIndex_; | 66 NSUInteger permissionsDetailIndex_; |
64 ExtensionInstallPrompt::DetailsType permissionsDetailType_; | 67 ExtensionInstallPrompt::DetailsType permissionsDetailType_; |
65 SEL linkClickedAction_; | 68 SEL linkClickedAction_; |
66 } | 69 } |
67 | 70 |
68 @property(assign, nonatomic) NSUInteger permissionsDetailIndex; | 71 @property(assign, nonatomic) NSUInteger permissionsDetailIndex; |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell | | 588 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell | |
586 kNoExpandMarker], | 589 kNoExpandMarker], |
587 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], | 590 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], |
588 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], | 591 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], |
589 }; | 592 }; |
590 } | 593 } |
591 | 594 |
592 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { | 595 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { |
593 NSMutableArray* warnings = [NSMutableArray array]; | 596 NSMutableArray* warnings = [NSMutableArray array]; |
594 NSString* heading = nil; | 597 NSString* heading = nil; |
598 NSString* withheldHeading = nil; | |
595 | 599 |
596 ExtensionInstallPrompt::DetailsType type = | 600 ExtensionInstallPrompt::DetailsType type = |
597 ExtensionInstallPrompt::PERMISSIONS_DETAILS; | 601 ExtensionInstallPrompt::PERMISSIONS_DETAILS; |
602 bool hasPermissions = prompt.GetPermissionCount( | |
603 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); | |
604 CellAttributes warningCellAttributes = | |
605 kBoldText | kAutoExpandCell | kNoExpandMarker; | |
598 if (prompt.ShouldShowPermissions()) { | 606 if (prompt.ShouldShowPermissions()) { |
599 NSMutableArray* children = [NSMutableArray array]; | 607 NSMutableArray* children = [NSMutableArray array]; |
600 if (prompt.GetPermissionCount() > 0) { | 608 NSMutableArray* withheldChildren = [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 | 609 |
607 // If there are additional details, add them below this item. | 610 heading = |
608 if (!prompt.GetPermissionsDetails(i).empty()) { | 611 [self appendPermissionsToPrompt:prompt |
609 if (prompt.GetIsShowingDetails( | 612 withType:ExtensionInstallPrompt:: |
610 ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { | 613 PermissionsType::REGULAR_PERMISSIONS |
611 [children addObject: | 614 children:children]; |
612 [self buildItemWithTitle:SysUTF16ToNSString( | 615 withheldHeading = [self |
Alexei Svitkine (slow)
2014/09/15 20:48:16
Nit: I'd wrap the same way as the line above.
gpdavis
2014/09/16 19:01:47
Unfortunately this one is 1 character too long to
| |
613 prompt.GetPermissionsDetails(i)) | 616 appendPermissionsToPrompt:prompt |
614 cellAttributes:kNoExpandMarker | 617 withType:ExtensionInstallPrompt::PermissionsType:: |
615 children:nil]]; | 618 WITHHELD_PERMISSIONS |
616 } | 619 children:withheldChildren]; |
617 | 620 |
618 // Add a row for the link. | 621 if (!hasPermissions) { |
619 [children addObject: | |
620 [self buildDetailToggleItem:type permissionsDetailIndex:i]]; | |
621 } | |
622 } | |
623 | |
624 heading = SysUTF16ToNSString(prompt.GetPermissionsHeading()); | |
625 } else { | |
626 [children addObject: | 622 [children addObject: |
627 [self buildItemWithTitle: | 623 [self buildItemWithTitle: |
628 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) | 624 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) |
629 cellAttributes:kUseBullet | 625 cellAttributes:kUseBullet |
630 children:nil]]; | 626 children:nil]]; |
631 heading = @""; | 627 heading = @""; |
632 } | 628 } |
633 | 629 |
634 [warnings addObject:[self | 630 [warnings addObject:[self buildItemWithTitle:heading |
635 buildItemWithTitle:heading | 631 cellAttributes:warningCellAttributes |
636 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker | 632 children:children]]; |
637 children:children]]; | 633 |
634 // Add withheld permissions to the prompt if they exist. | |
635 if (withheldHeading) { | |
636 [warnings addObject:[self buildItemWithTitle:withheldHeading | |
637 cellAttributes:warningCellAttributes | |
638 children:withheldChildren]]; | |
639 } | |
638 } | 640 } |
639 | 641 |
640 if (prompt.GetRetainedFileCount() > 0) { | 642 if (prompt.GetRetainedFileCount() > 0) { |
641 type = ExtensionInstallPrompt::RETAINED_FILES_DETAILS; | 643 type = ExtensionInstallPrompt::RETAINED_FILES_DETAILS; |
642 | 644 |
643 NSMutableArray* children = [NSMutableArray array]; | 645 NSMutableArray* children = [NSMutableArray array]; |
644 | 646 |
645 if (prompt.GetIsShowingDetails(type, 0)) { | 647 if (prompt.GetIsShowingDetails(type, 0)) { |
646 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { | 648 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { |
647 [children addObject: | 649 [children addObject: |
648 [self buildItemWithTitle:SysUTF16ToNSString( | 650 [self buildItemWithTitle:SysUTF16ToNSString( |
649 prompt.GetRetainedFile(i)) | 651 prompt.GetRetainedFile(i)) |
650 cellAttributes:kUseBullet | 652 cellAttributes:kUseBullet |
651 children:nil]]; | 653 children:nil]]; |
652 } | 654 } |
653 } | 655 } |
654 | 656 |
655 [warnings addObject: | 657 [warnings |
656 [self buildItemWithTitle:SysUTF16ToNSString( | 658 addObject:[self buildItemWithTitle:SysUTF16ToNSString( |
657 prompt.GetRetainedFilesHeading()) | 659 prompt.GetRetainedFilesHeading()) |
658 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker | 660 cellAttributes:warningCellAttributes |
659 children:children]]; | 661 children:children]]; |
660 | 662 |
661 // Add a row for the link. | 663 // Add a row for the link. |
662 [warnings addObject: | 664 [warnings addObject: |
663 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; | 665 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; |
664 } | 666 } |
665 | 667 |
666 return warnings; | 668 return warnings; |
667 } | 669 } |
668 | 670 |
671 - (NSString*)appendPermissionsToPrompt:(const ExtensionInstallPrompt::Prompt&) | |
672 prompt withType:(ExtensionInstallPrompt::PermissionsType)type | |
Alexei Svitkine (slow)
2014/09/15 20:48:16
Use same wrapping I suggested above.
gpdavis
2014/09/16 19:01:47
Done.
| |
673 children:(NSMutableArray*)children { | |
674 size_t permissionsCount = prompt.GetPermissionCount(type); | |
675 if (permissionsCount == 0) | |
676 return NULL; | |
677 | |
678 for (size_t i = 0; i < permissionsCount; ++i) { | |
679 NSDictionary* item = [self | |
Alexei Svitkine (slow)
2014/09/15 20:48:16
Nit: I'd wrap after the = if it still lets you ali
gpdavis
2014/09/16 19:01:47
Not without wrapping the line, unfortunately (it's
| |
680 buildItemWithTitle:SysUTF16ToNSString(prompt.GetPermission(i, type)) | |
681 cellAttributes:kUseBullet | |
682 children:nil]; | |
683 [children addObject:item]; | |
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 item = | |
690 [self buildItemWithTitle:SysUTF16ToNSString( | |
691 prompt.GetPermissionsDetails(i, type)) | |
692 cellAttributes:kNoExpandMarker | |
693 children:nil]; | |
694 [children addObject:item]; | |
695 } | |
696 | |
697 // Add a row for the link. | |
698 [children | |
699 addObject:[self buildDetailToggleItem:type permissionsDetailIndex:i]]; | |
Alexei Svitkine (slow)
2014/09/15 20:48:16
Nit: I'd wrap after the first : here instead.
gpdavis
2014/09/16 19:01:47
Done.
| |
700 } | |
701 } | |
702 | |
703 return SysUTF16ToNSString(prompt.GetPermissionsHeading(type)); | |
704 } | |
705 | |
669 - (void)updateViewFrame:(NSRect)frame { | 706 - (void)updateViewFrame:(NSRect)frame { |
670 NSWindow* window = [[self view] window]; | 707 NSWindow* window = [[self view] window]; |
671 [window setFrame:[window frameRectForContentRect:frame] display:YES]; | 708 [window setFrame:[window frameRectForContentRect:frame] display:YES]; |
672 [[self view] setFrame:frame]; | 709 [[self view] setFrame:frame]; |
673 } | 710 } |
674 | 711 |
675 @end | 712 @end |
676 | 713 |
677 | 714 |
678 @implementation DetailToggleHyperlinkButtonCell | 715 @implementation DetailToggleHyperlinkButtonCell |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 } | 771 } |
735 | 772 |
736 - (void)accessibilityPerformAction:(NSString*)action { | 773 - (void)accessibilityPerformAction:(NSString*)action { |
737 if ([action isEqualToString:NSAccessibilityPressAction]) | 774 if ([action isEqualToString:NSAccessibilityPressAction]) |
738 [self handleLinkClicked]; | 775 [self handleLinkClicked]; |
739 else | 776 else |
740 [super accessibilityPerformAction:action]; | 777 [super accessibilityPerformAction:action]; |
741 } | 778 } |
742 | 779 |
743 @end | 780 @end |
OLD | NEW |