| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 - (BOOL)isBundleInstall; | 50 - (BOOL)isBundleInstall; |
| 51 - (BOOL)hasWebstoreData; | 51 - (BOOL)hasWebstoreData; |
| 52 - (void)appendRatingStar:(const gfx::ImageSkia*)skiaImage; | 52 - (void)appendRatingStar:(const gfx::ImageSkia*)skiaImage; |
| 53 - (void)onOutlineViewRowCountDidChange; | 53 - (void)onOutlineViewRowCountDidChange; |
| 54 - (NSDictionary*)buildItemWithTitle:(NSString*)title | 54 - (NSDictionary*)buildItemWithTitle:(NSString*)title |
| 55 cellAttributes:(CellAttributes)cellAttributes | 55 cellAttributes:(CellAttributes)cellAttributes |
| 56 children:(NSArray*)children; | 56 children:(NSArray*)children; |
| 57 - (NSDictionary*)buildDetailToggleItem:(size_t)type | 57 - (NSDictionary*)buildDetailToggleItem:(size_t)type |
| 58 permissionsDetailIndex:(size_t)index; | 58 permissionsDetailIndex:(size_t)index; |
| 59 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt; | 59 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt; |
| 60 // Adds permissions of |type| from |prompt| to |children| and returns the |
| 61 // the appropriate permissions header. If no permissions are found, NULL is |
| 62 // returned. |
| 63 - (NSString*) |
| 64 appendPermissionsForPrompt:(const ExtensionInstallPrompt::Prompt&)prompt |
| 65 withType:(ExtensionInstallPrompt::PermissionsType)type |
| 66 children:(NSMutableArray*)children; |
| 60 - (void)updateViewFrame:(NSRect)frame; | 67 - (void)updateViewFrame:(NSRect)frame; |
| 61 @end | 68 @end |
| 62 | 69 |
| 63 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell { | 70 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell { |
| 64 NSUInteger permissionsDetailIndex_; | 71 NSUInteger permissionsDetailIndex_; |
| 65 ExtensionInstallPrompt::DetailsType permissionsDetailType_; | 72 ExtensionInstallPrompt::DetailsType permissionsDetailType_; |
| 66 SEL linkClickedAction_; | 73 SEL linkClickedAction_; |
| 67 } | 74 } |
| 68 | 75 |
| 69 @property(assign, nonatomic) NSUInteger permissionsDetailIndex; | 76 @property(assign, nonatomic) NSUInteger permissionsDetailIndex; |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell | | 593 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell | |
| 587 kNoExpandMarker], | 594 kNoExpandMarker], |
| 588 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], | 595 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], |
| 589 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], | 596 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], |
| 590 }; | 597 }; |
| 591 } | 598 } |
| 592 | 599 |
| 593 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { | 600 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { |
| 594 NSMutableArray* warnings = [NSMutableArray array]; | 601 NSMutableArray* warnings = [NSMutableArray array]; |
| 595 NSString* heading = nil; | 602 NSString* heading = nil; |
| 603 NSString* withheldHeading = nil; |
| 596 | 604 |
| 597 ExtensionInstallPrompt::DetailsType type = | 605 ExtensionInstallPrompt::DetailsType type = |
| 598 ExtensionInstallPrompt::PERMISSIONS_DETAILS; | 606 ExtensionInstallPrompt::PERMISSIONS_DETAILS; |
| 607 bool hasPermissions = prompt.GetPermissionCount( |
| 608 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); |
| 609 CellAttributes warningCellAttributes = |
| 610 kBoldText | kAutoExpandCell | kNoExpandMarker; |
| 599 if (prompt.ShouldShowPermissions()) { | 611 if (prompt.ShouldShowPermissions()) { |
| 600 NSMutableArray* children = [NSMutableArray array]; | 612 NSMutableArray* children = [NSMutableArray array]; |
| 601 if (prompt.GetPermissionCount() > 0) { | 613 NSMutableArray* withheldChildren = [NSMutableArray array]; |
| 602 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { | |
| 603 [children addObject: | |
| 604 [self buildItemWithTitle:SysUTF16ToNSString(prompt.GetPermission(i)) | |
| 605 cellAttributes:kUseBullet | |
| 606 children:nil]]; | |
| 607 | 614 |
| 608 // If there are additional details, add them below this item. | 615 heading = |
| 609 if (!prompt.GetPermissionsDetails(i).empty()) { | 616 [self appendPermissionsForPrompt:prompt |
| 610 if (prompt.GetIsShowingDetails( | 617 withType:ExtensionInstallPrompt::PermissionsType |
| 611 ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { | 618 ::REGULAR_PERMISSIONS |
| 612 [children addObject: | 619 children:children]; |
| 613 [self buildItemWithTitle:SysUTF16ToNSString( | 620 withheldHeading = |
| 614 prompt.GetPermissionsDetails(i)) | 621 [self appendPermissionsForPrompt:prompt |
| 615 cellAttributes:kNoExpandMarker | 622 withType:ExtensionInstallPrompt::PermissionsType |
| 616 children:nil]]; | 623 ::WITHHELD_PERMISSIONS |
| 617 } | 624 children:withheldChildren]; |
| 618 | 625 |
| 619 // Add a row for the link. | 626 if (!hasPermissions) { |
| 620 [children addObject: | |
| 621 [self buildDetailToggleItem:type permissionsDetailIndex:i]]; | |
| 622 } | |
| 623 } | |
| 624 | |
| 625 heading = SysUTF16ToNSString(prompt.GetPermissionsHeading()); | |
| 626 } else { | |
| 627 [children addObject: | 627 [children addObject: |
| 628 [self buildItemWithTitle: | 628 [self buildItemWithTitle: |
| 629 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) | 629 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) |
| 630 cellAttributes:kUseBullet | 630 cellAttributes:kUseBullet |
| 631 children:nil]]; | 631 children:nil]]; |
| 632 heading = @""; | 632 heading = @""; |
| 633 } | 633 } |
| 634 | 634 |
| 635 [warnings addObject:[self | 635 if (heading) { |
| 636 buildItemWithTitle:heading | 636 [warnings addObject:[self buildItemWithTitle:heading |
| 637 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker | 637 cellAttributes:warningCellAttributes |
| 638 children:children]]; | 638 children:children]]; |
| 639 } |
| 640 |
| 641 // Add withheld permissions to the prompt if they exist. |
| 642 if (withheldHeading) { |
| 643 [warnings addObject:[self buildItemWithTitle:withheldHeading |
| 644 cellAttributes:warningCellAttributes |
| 645 children:withheldChildren]]; |
| 646 } |
| 639 } | 647 } |
| 640 | 648 |
| 641 if (prompt.GetRetainedFileCount() > 0) { | 649 if (prompt.GetRetainedFileCount() > 0) { |
| 642 type = ExtensionInstallPrompt::RETAINED_FILES_DETAILS; | 650 type = ExtensionInstallPrompt::RETAINED_FILES_DETAILS; |
| 643 | 651 |
| 644 NSMutableArray* children = [NSMutableArray array]; | 652 NSMutableArray* children = [NSMutableArray array]; |
| 645 | 653 |
| 646 if (prompt.GetIsShowingDetails(type, 0)) { | 654 if (prompt.GetIsShowingDetails(type, 0)) { |
| 647 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { | 655 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { |
| 648 [children addObject: | 656 [children addObject: |
| 649 [self buildItemWithTitle:SysUTF16ToNSString( | 657 [self buildItemWithTitle:SysUTF16ToNSString( |
| 650 prompt.GetRetainedFile(i)) | 658 prompt.GetRetainedFile(i)) |
| 651 cellAttributes:kUseBullet | 659 cellAttributes:kUseBullet |
| 652 children:nil]]; | 660 children:nil]]; |
| 653 } | 661 } |
| 654 } | 662 } |
| 655 | 663 |
| 656 [warnings addObject: | 664 [warnings |
| 657 [self buildItemWithTitle:SysUTF16ToNSString( | 665 addObject:[self buildItemWithTitle:SysUTF16ToNSString( |
| 658 prompt.GetRetainedFilesHeading()) | 666 prompt.GetRetainedFilesHeading()) |
| 659 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker | 667 cellAttributes:warningCellAttributes |
| 660 children:children]]; | 668 children:children]]; |
| 661 | 669 |
| 662 // Add a row for the link. | 670 // Add a row for the link. |
| 663 [warnings addObject: | 671 [warnings addObject: |
| 664 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; | 672 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; |
| 665 } | 673 } |
| 666 | 674 |
| 667 return warnings; | 675 return warnings; |
| 668 } | 676 } |
| 669 | 677 |
| 678 - (NSString*) |
| 679 appendPermissionsForPrompt:(const ExtensionInstallPrompt::Prompt&)prompt |
| 680 withType:(ExtensionInstallPrompt::PermissionsType)type |
| 681 children:(NSMutableArray*)children { |
| 682 size_t permissionsCount = prompt.GetPermissionCount(type); |
| 683 if (permissionsCount == 0) |
| 684 return NULL; |
| 685 |
| 686 for (size_t i = 0; i < permissionsCount; ++i) { |
| 687 NSDictionary* item = [self |
| 688 buildItemWithTitle:SysUTF16ToNSString(prompt.GetPermission(i, type)) |
| 689 cellAttributes:kUseBullet |
| 690 children:nil]; |
| 691 [children addObject:item]; |
| 692 |
| 693 // If there are additional details, add them below this item. |
| 694 if (!prompt.GetPermissionsDetails(i, type).empty()) { |
| 695 if (prompt.GetIsShowingDetails( |
| 696 ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { |
| 697 item = |
| 698 [self buildItemWithTitle:SysUTF16ToNSString( |
| 699 prompt.GetPermissionsDetails(i, type)) |
| 700 cellAttributes:kNoExpandMarker |
| 701 children:nil]; |
| 702 [children addObject:item]; |
| 703 } |
| 704 |
| 705 // Add a row for the link. |
| 706 [children addObject: |
| 707 [self buildDetailToggleItem:type permissionsDetailIndex:i]]; |
| 708 } |
| 709 } |
| 710 |
| 711 return SysUTF16ToNSString(prompt.GetPermissionsHeading(type)); |
| 712 } |
| 713 |
| 670 - (void)updateViewFrame:(NSRect)frame { | 714 - (void)updateViewFrame:(NSRect)frame { |
| 671 NSWindow* window = [[self view] window]; | 715 NSWindow* window = [[self view] window]; |
| 672 [window setFrame:[window frameRectForContentRect:frame] display:YES]; | 716 [window setFrame:[window frameRectForContentRect:frame] display:YES]; |
| 673 [[self view] setFrame:frame]; | 717 [[self view] setFrame:frame]; |
| 674 } | 718 } |
| 675 | 719 |
| 676 @end | 720 @end |
| 677 | 721 |
| 678 | 722 |
| 679 @implementation DetailToggleHyperlinkButtonCell | 723 @implementation DetailToggleHyperlinkButtonCell |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 } | 779 } |
| 736 | 780 |
| 737 - (void)accessibilityPerformAction:(NSString*)action { | 781 - (void)accessibilityPerformAction:(NSString*)action { |
| 738 if ([action isEqualToString:NSAccessibilityPressAction]) | 782 if ([action isEqualToString:NSAccessibilityPressAction]) |
| 739 [self handleLinkClicked]; | 783 [self handleLinkClicked]; |
| 740 else | 784 else |
| 741 [super accessibilityPerformAction:action]; | 785 [super accessibilityPerformAction:action]; |
| 742 } | 786 } |
| 743 | 787 |
| 744 @end | 788 @end |
| OLD | NEW |