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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 prompt:(scoped_refptr<ExtensionInstallPrompt::Prompt>)prompt { | 191 prompt:(scoped_refptr<ExtensionInstallPrompt::Prompt>)prompt { |
192 // We use a different XIB in the case of bundle installs, installs with | 192 // We use a different XIB in the case of bundle installs, installs with |
193 // webstore data, or no permission warnings. These are laid out nicely for | 193 // webstore data, or no permission warnings. These are laid out nicely for |
194 // the data they display. | 194 // the data they display. |
195 NSString* nibName = nil; | 195 NSString* nibName = nil; |
196 if (prompt->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT) { | 196 if (prompt->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT) { |
197 nibName = @"ExtensionInstallPromptBundle"; | 197 nibName = @"ExtensionInstallPromptBundle"; |
198 } else if (prompt->has_webstore_data()) { | 198 } else if (prompt->has_webstore_data()) { |
199 nibName = @"ExtensionInstallPromptWebstoreData"; | 199 nibName = @"ExtensionInstallPromptWebstoreData"; |
200 } else if (!prompt->ShouldShowPermissions() && | 200 } else if (!prompt->ShouldShowPermissions() && |
201 prompt->GetRetainedFileCount() == 0) { | 201 prompt->GetRetainedFileCount() == 0 && |
| 202 prompt->GetRetainedDeviceCount() == 0) { |
202 nibName = @"ExtensionInstallPromptNoWarnings"; | 203 nibName = @"ExtensionInstallPromptNoWarnings"; |
203 } else { | 204 } else { |
204 nibName = @"ExtensionInstallPrompt"; | 205 nibName = @"ExtensionInstallPrompt"; |
205 } | 206 } |
206 | 207 |
207 if ((self = [super initWithNibName:nibName | 208 if ((self = [super initWithNibName:nibName |
208 bundle:base::mac::FrameworkBundle()])) { | 209 bundle:base::mac::FrameworkBundle()])) { |
209 navigator_ = navigator; | 210 navigator_ = navigator; |
210 delegate_ = delegate; | 211 delegate_ = delegate; |
211 prompt_ = prompt; | 212 prompt_ = prompt; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 [joinedItems appendString:@"\n"]; | 309 [joinedItems appendString:@"\n"]; |
309 [joinedItems appendString:base::SysUTF16ToNSString( | 310 [joinedItems appendString:base::SysUTF16ToNSString( |
310 items[i].GetNameForDisplay())]; | 311 items[i].GetNameForDisplay())]; |
311 } | 312 } |
312 [itemsField_ setStringValue:joinedItems]; | 313 [itemsField_ setStringValue:joinedItems]; |
313 | 314 |
314 // Adjust the controls to fit the list of extensions. | 315 // Adjust the controls to fit the list of extensions. |
315 OffsetControlVerticallyToFitContent(itemsField_, &totalOffset); | 316 OffsetControlVerticallyToFitContent(itemsField_, &totalOffset); |
316 } | 317 } |
317 | 318 |
318 // If there are any warnings or retained files, then we have to do | 319 // If there are any warnings, retained devices or retained files, then we |
319 // some special layout. | 320 // have to do some special layout. |
320 if (prompt_->ShouldShowPermissions() || prompt_->GetRetainedFileCount() > 0) { | 321 if (prompt_->ShouldShowPermissions() || prompt_->GetRetainedFileCount() > 0) { |
321 NSSize spacing = [outlineView_ intercellSpacing]; | 322 NSSize spacing = [outlineView_ intercellSpacing]; |
322 spacing.width += 2; | 323 spacing.width += 2; |
323 spacing.height += 2; | 324 spacing.height += 2; |
324 [outlineView_ setIntercellSpacing:spacing]; | 325 [outlineView_ setIntercellSpacing:spacing]; |
325 [[[[outlineView_ tableColumns] objectAtIndex:0] dataCell] setWraps:YES]; | 326 [[[[outlineView_ tableColumns] objectAtIndex:0] dataCell] setWraps:YES]; |
326 for (id item in warnings_.get()) | 327 for (id item in warnings_.get()) |
327 [self expandItemAndChildren:item]; | 328 [self expandItemAndChildren:item]; |
328 | 329 |
329 // Adjust the outline view to fit the warnings. | 330 // Adjust the outline view to fit the warnings. |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], | 596 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], |
596 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], | 597 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], |
597 }; | 598 }; |
598 } | 599 } |
599 | 600 |
600 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { | 601 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { |
601 NSMutableArray* warnings = [NSMutableArray array]; | 602 NSMutableArray* warnings = [NSMutableArray array]; |
602 NSString* heading = nil; | 603 NSString* heading = nil; |
603 NSString* withheldHeading = nil; | 604 NSString* withheldHeading = nil; |
604 | 605 |
605 ExtensionInstallPrompt::DetailsType type = | |
606 ExtensionInstallPrompt::PERMISSIONS_DETAILS; | |
607 bool hasPermissions = prompt.GetPermissionCount( | 606 bool hasPermissions = prompt.GetPermissionCount( |
608 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); | 607 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); |
609 CellAttributes warningCellAttributes = | 608 CellAttributes warningCellAttributes = |
610 kBoldText | kAutoExpandCell | kNoExpandMarker; | 609 kBoldText | kAutoExpandCell | kNoExpandMarker; |
611 if (prompt.ShouldShowPermissions()) { | 610 if (prompt.ShouldShowPermissions()) { |
612 NSMutableArray* children = [NSMutableArray array]; | 611 NSMutableArray* children = [NSMutableArray array]; |
613 NSMutableArray* withheldChildren = [NSMutableArray array]; | 612 NSMutableArray* withheldChildren = [NSMutableArray array]; |
614 | 613 |
615 heading = | 614 heading = |
616 [self appendPermissionsForPrompt:prompt | 615 [self appendPermissionsForPrompt:prompt |
(...skipping 23 matching lines...) Expand all Loading... |
640 | 639 |
641 // Add withheld permissions to the prompt if they exist. | 640 // Add withheld permissions to the prompt if they exist. |
642 if (withheldHeading) { | 641 if (withheldHeading) { |
643 [warnings addObject:[self buildItemWithTitle:withheldHeading | 642 [warnings addObject:[self buildItemWithTitle:withheldHeading |
644 cellAttributes:warningCellAttributes | 643 cellAttributes:warningCellAttributes |
645 children:withheldChildren]]; | 644 children:withheldChildren]]; |
646 } | 645 } |
647 } | 646 } |
648 | 647 |
649 if (prompt.GetRetainedFileCount() > 0) { | 648 if (prompt.GetRetainedFileCount() > 0) { |
650 type = ExtensionInstallPrompt::RETAINED_FILES_DETAILS; | 649 const ExtensionInstallPrompt::DetailsType type = |
| 650 ExtensionInstallPrompt::RETAINED_FILES_DETAILS; |
651 | 651 |
652 NSMutableArray* children = [NSMutableArray array]; | 652 NSMutableArray* children = [NSMutableArray array]; |
653 | 653 |
654 if (prompt.GetIsShowingDetails(type, 0)) { | 654 if (prompt.GetIsShowingDetails(type, 0)) { |
655 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { | 655 for (size_t i = 0; i < prompt.GetRetainedFileCount(); ++i) { |
656 [children addObject: | 656 NSString* title = SysUTF16ToNSString(prompt.GetRetainedFile(i)); |
657 [self buildItemWithTitle:SysUTF16ToNSString( | 657 [children addObject:[self buildItemWithTitle:title |
658 prompt.GetRetainedFile(i)) | 658 cellAttributes:kUseBullet |
659 cellAttributes:kUseBullet | 659 children:nil]]; |
660 children:nil]]; | |
661 } | 660 } |
662 } | 661 } |
663 | 662 |
664 [warnings | 663 NSString* title = SysUTF16ToNSString(prompt.GetRetainedFilesHeading()); |
665 addObject:[self buildItemWithTitle:SysUTF16ToNSString( | 664 [warnings addObject:[self buildItemWithTitle:title |
666 prompt.GetRetainedFilesHeading()) | 665 cellAttributes:warningCellAttributes |
667 cellAttributes:warningCellAttributes | 666 children:children]]; |
668 children:children]]; | |
669 | 667 |
670 // Add a row for the link. | 668 // Add a row for the link. |
671 [warnings addObject: | 669 [warnings addObject: |
672 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; | 670 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; |
673 } | 671 } |
674 | 672 |
| 673 if (prompt.GetRetainedDeviceCount() > 0) { |
| 674 const ExtensionInstallPrompt::DetailsType type = |
| 675 ExtensionInstallPrompt::RETAINED_DEVICES_DETAILS; |
| 676 |
| 677 NSMutableArray* children = [NSMutableArray array]; |
| 678 |
| 679 if (prompt.GetIsShowingDetails(type, 0)) { |
| 680 for (size_t i = 0; i < prompt.GetRetainedDeviceCount(); ++i) { |
| 681 NSString* title = |
| 682 SysUTF16ToNSString(prompt.GetRetainedDeviceMessageString(i)); |
| 683 [children addObject:[self buildItemWithTitle:title |
| 684 cellAttributes:kUseBullet |
| 685 children:nil]]; |
| 686 } |
| 687 } |
| 688 |
| 689 NSString* title = SysUTF16ToNSString(prompt.GetRetainedDevicesHeading()); |
| 690 [warnings addObject:[self buildItemWithTitle:title |
| 691 cellAttributes:warningCellAttributes |
| 692 children:children]]; |
| 693 |
| 694 // Add a row for the link. |
| 695 [warnings |
| 696 addObject:[self buildDetailToggleItem:type permissionsDetailIndex:0]]; |
| 697 } |
| 698 |
675 return warnings; | 699 return warnings; |
676 } | 700 } |
677 | 701 |
678 - (NSString*) | 702 - (NSString*) |
679 appendPermissionsForPrompt:(const ExtensionInstallPrompt::Prompt&)prompt | 703 appendPermissionsForPrompt:(const ExtensionInstallPrompt::Prompt&)prompt |
680 withType:(ExtensionInstallPrompt::PermissionsType)type | 704 withType:(ExtensionInstallPrompt::PermissionsType)type |
681 children:(NSMutableArray*)children { | 705 children:(NSMutableArray*)children { |
682 size_t permissionsCount = prompt.GetPermissionCount(type); | 706 size_t permissionsCount = prompt.GetPermissionCount(type); |
683 if (permissionsCount == 0) | 707 if (permissionsCount == 0) |
684 return NULL; | 708 return NULL; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 } | 803 } |
780 | 804 |
781 - (void)accessibilityPerformAction:(NSString*)action { | 805 - (void)accessibilityPerformAction:(NSString*)action { |
782 if ([action isEqualToString:NSAccessibilityPressAction]) | 806 if ([action isEqualToString:NSAccessibilityPressAction]) |
783 [self handleLinkClicked]; | 807 [self handleLinkClicked]; |
784 else | 808 else |
785 [super accessibilityPerformAction:action]; | 809 [super accessibilityPerformAction:action]; |
786 } | 810 } |
787 | 811 |
788 @end | 812 @end |
OLD | NEW |