Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm

Issue 313203004: Make ExtensionInstallPrompt::Prompt ref-counted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest master Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 @interface ExtensionInstallViewController () 48 @interface ExtensionInstallViewController ()
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:(scoped_refptr<ExtensionInstallPrompt::Prompt>)prompt;
59 - (void)updateViewFrame:(NSRect)frame; 59 - (void)updateViewFrame:(NSRect)frame;
60 @end 60 @end
61 61
62 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell { 62 @interface DetailToggleHyperlinkButtonCell : HyperlinkButtonCell {
63 NSUInteger permissionsDetailIndex_; 63 NSUInteger permissionsDetailIndex_;
64 ExtensionInstallPrompt::DetailsType permissionsDetailType_; 64 ExtensionInstallPrompt::DetailsType permissionsDetailType_;
65 SEL linkClickedAction_; 65 SEL linkClickedAction_;
66 } 66 }
67 67
68 @property(assign, nonatomic) NSUInteger permissionsDetailIndex; 68 @property(assign, nonatomic) NSUInteger permissionsDetailIndex;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 @synthesize okButton = okButton_; 173 @synthesize okButton = okButton_;
174 @synthesize outlineView = outlineView_; 174 @synthesize outlineView = outlineView_;
175 @synthesize warningsSeparator = warningsSeparator_; 175 @synthesize warningsSeparator = warningsSeparator_;
176 @synthesize ratingStars = ratingStars_; 176 @synthesize ratingStars = ratingStars_;
177 @synthesize ratingCountField = ratingCountField_; 177 @synthesize ratingCountField = ratingCountField_;
178 @synthesize userCountField = userCountField_; 178 @synthesize userCountField = userCountField_;
179 @synthesize storeLinkButton = storeLinkButton_; 179 @synthesize storeLinkButton = storeLinkButton_;
180 180
181 - (id)initWithNavigator:(content::PageNavigator*)navigator 181 - (id)initWithNavigator:(content::PageNavigator*)navigator
182 delegate:(ExtensionInstallPrompt::Delegate*)delegate 182 delegate:(ExtensionInstallPrompt::Delegate*)delegate
183 prompt:(const ExtensionInstallPrompt::Prompt&)prompt { 183 prompt:(scoped_refptr<ExtensionInstallPrompt::Prompt>)prompt {
184 // We use a different XIB in the case of bundle installs, installs with 184 // We use a different XIB in the case of bundle installs, installs with
185 // webstore data, or no permission warnings. These are laid out nicely for 185 // webstore data, or no permission warnings. These are laid out nicely for
186 // the data they display. 186 // the data they display.
187 NSString* nibName = nil; 187 NSString* nibName = nil;
188 if (prompt.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT) { 188 if (prompt->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT) {
189 nibName = @"ExtensionInstallPromptBundle"; 189 nibName = @"ExtensionInstallPromptBundle";
190 } else if (prompt.has_webstore_data()) { 190 } else if (prompt->has_webstore_data()) {
191 nibName = @"ExtensionInstallPromptWebstoreData"; 191 nibName = @"ExtensionInstallPromptWebstoreData";
192 } else if (!prompt.ShouldShowPermissions() && 192 } else if (!prompt->ShouldShowPermissions() &&
193 prompt.GetRetainedFileCount() == 0) { 193 prompt->GetRetainedFileCount() == 0) {
194 nibName = @"ExtensionInstallPromptNoWarnings"; 194 nibName = @"ExtensionInstallPromptNoWarnings";
195 } else { 195 } else {
196 nibName = @"ExtensionInstallPrompt"; 196 nibName = @"ExtensionInstallPrompt";
197 } 197 }
198 198
199 if ((self = [super initWithNibName:nibName 199 if ((self = [super initWithNibName:nibName
200 bundle:base::mac::FrameworkBundle()])) { 200 bundle:base::mac::FrameworkBundle()])) {
201 navigator_ = navigator; 201 navigator_ = navigator;
202 delegate_ = delegate; 202 delegate_ = delegate;
203 prompt_.reset(new ExtensionInstallPrompt::Prompt(prompt)); 203 prompt_ = prompt;
204 warnings_.reset([[self buildWarnings:prompt] retain]); 204 warnings_.reset([[self buildWarnings:prompt] retain]);
205 } 205 }
206 return self; 206 return self;
207 } 207 }
208 208
209 - (IBAction)storeLinkClicked:(id)sender { 209 - (IBAction)storeLinkClicked:(id)sender {
210 GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() + 210 GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() +
211 prompt_->extension()->id()); 211 prompt_->extension()->id());
212 navigator_->OpenURL(OpenURLParams( 212 navigator_->OpenURL(OpenURLParams(
213 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, 213 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK,
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 for (id child in [item objectForKey:kChildrenKey]) 540 for (id child in [item objectForKey:kChildrenKey])
541 [self expandItemAndChildren:child]; 541 [self expandItemAndChildren:child];
542 } 542 }
543 543
544 - (void)onToggleDetailsLinkClicked:(id)sender { 544 - (void)onToggleDetailsLinkClicked:(id)sender {
545 size_t index = [sender permissionsDetailIndex]; 545 size_t index = [sender permissionsDetailIndex];
546 ExtensionInstallPrompt::DetailsType type = [sender permissionsDetailType]; 546 ExtensionInstallPrompt::DetailsType type = [sender permissionsDetailType];
547 prompt_->SetIsShowingDetails( 547 prompt_->SetIsShowingDetails(
548 type, index, !prompt_->GetIsShowingDetails(type, index)); 548 type, index, !prompt_->GetIsShowingDetails(type, index));
549 549
550 warnings_.reset([[self buildWarnings:*prompt_] retain]); 550 warnings_.reset([[self buildWarnings:prompt_] retain]);
551 [outlineView_ reloadData]; 551 [outlineView_ reloadData];
552 552
553 for (id item in warnings_.get()) 553 for (id item in warnings_.get())
554 [self expandItemAndChildren:item]; 554 [self expandItemAndChildren:item];
555 } 555 }
556 556
557 - (NSDictionary*)buildItemWithTitle:(NSString*)title 557 - (NSDictionary*)buildItemWithTitle:(NSString*)title
558 cellAttributes:(CellAttributes)cellAttributes 558 cellAttributes:(CellAttributes)cellAttributes
559 children:(NSArray*)children { 559 children:(NSArray*)children {
560 if (!children || ([children count] == 0 && cellAttributes & kUseBullet)) { 560 if (!children || ([children count] == 0 && cellAttributes & kUseBullet)) {
(...skipping 21 matching lines...) Expand all
582 return @{ 582 return @{
583 kTitleKey : @"", 583 kTitleKey : @"",
584 kChildrenKey : @[ @{} ], 584 kChildrenKey : @[ @{} ],
585 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell | 585 kCellAttributesKey : [NSNumber numberWithInt:kUseCustomLinkCell |
586 kNoExpandMarker], 586 kNoExpandMarker],
587 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index], 587 kPermissionsDetailIndex : [NSNumber numberWithUnsignedInteger:index],
588 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type], 588 kPermissionsDetailType : [NSNumber numberWithUnsignedInteger:type],
589 }; 589 };
590 } 590 }
591 591
592 - (NSArray*)buildWarnings:(const ExtensionInstallPrompt::Prompt&)prompt { 592 - (NSArray*)buildWarnings:
593 (scoped_refptr<ExtensionInstallPrompt::Prompt>)prompt {
Scott Hess - ex-Googler 2014/06/16 19:29:04 Since you don't actually take a ref of |prompt| in
Devlin 2014/06/17 16:05:26 Went with this option. Thanks! :)
593 NSMutableArray* warnings = [NSMutableArray array]; 594 NSMutableArray* warnings = [NSMutableArray array];
594 NSString* heading = nil; 595 NSString* heading = nil;
595 596
596 ExtensionInstallPrompt::DetailsType type = 597 ExtensionInstallPrompt::DetailsType type =
597 ExtensionInstallPrompt::PERMISSIONS_DETAILS; 598 ExtensionInstallPrompt::PERMISSIONS_DETAILS;
598 if (prompt.ShouldShowPermissions()) { 599 if (prompt->ShouldShowPermissions()) {
599 NSMutableArray* children = [NSMutableArray array]; 600 NSMutableArray* children = [NSMutableArray array];
600 if (prompt.GetPermissionCount() > 0) { 601 if (prompt->GetPermissionCount() > 0) {
601 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { 602 for (size_t i = 0; i < prompt->GetPermissionCount(); ++i) {
602 [children addObject: 603 [children
603 [self buildItemWithTitle:SysUTF16ToNSString(prompt.GetPermission(i)) 604 addObject:[self buildItemWithTitle:SysUTF16ToNSString(
604 cellAttributes:kUseBullet 605 prompt->GetPermission(i))
605 children:nil]]; 606 cellAttributes:kUseBullet
607 children:nil]];
Scott Hess - ex-Googler 2014/06/16 19:29:04 You should feel free to use temporaries to tame th
606 608
607 // If there are additional details, add them below this item. 609 // If there are additional details, add them below this item.
608 if (!prompt.GetPermissionsDetails(i).empty()) { 610 if (!prompt->GetPermissionsDetails(i).empty()) {
609 if (prompt.GetIsShowingDetails( 611 if (prompt->GetIsShowingDetails(
610 ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) { 612 ExtensionInstallPrompt::PERMISSIONS_DETAILS, i)) {
611 [children addObject: 613 [children addObject:[self buildItemWithTitle:
612 [self buildItemWithTitle:SysUTF16ToNSString( 614 SysUTF16ToNSString(
613 prompt.GetPermissionsDetails(i)) 615 prompt->GetPermissionsDetails(i))
614 cellAttributes:kNoExpandMarker 616 cellAttributes:kNoExpandMarker
615 children:nil]]; 617 children:nil]];
616 } 618 }
617 619
618 // Add a row for the link. 620 // Add a row for the link.
619 [children addObject: 621 [children addObject:
620 [self buildDetailToggleItem:type permissionsDetailIndex:i]]; 622 [self buildDetailToggleItem:type permissionsDetailIndex:i]];
621 } 623 }
622 } 624 }
623 625
624 heading = SysUTF16ToNSString(prompt.GetPermissionsHeading()); 626 heading = SysUTF16ToNSString(prompt->GetPermissionsHeading());
625 } else { 627 } else {
626 [children addObject: 628 [children addObject:
627 [self buildItemWithTitle: 629 [self buildItemWithTitle:
628 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS) 630 l10n_util::GetNSString(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS)
629 cellAttributes:kUseBullet 631 cellAttributes:kUseBullet
630 children:nil]]; 632 children:nil]];
631 heading = @""; 633 heading = @"";
632 } 634 }
633 635
634 [warnings addObject:[self 636 [warnings addObject:[self
635 buildItemWithTitle:heading 637 buildItemWithTitle:heading
636 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker 638 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker
637 children:children]]; 639 children:children]];
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
648 [self buildItemWithTitle:SysUTF16ToNSString( 650 addObject:[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
657 prompt.GetRetainedFilesHeading()) 659 buildItemWithTitle:SysUTF16ToNSString(
658 cellAttributes:kBoldText | kAutoExpandCell | kNoExpandMarker 660 prompt->GetRetainedFilesHeading())
659 children:children]]; 661 cellAttributes:kBoldText | kAutoExpandCell |
662 kNoExpandMarker
663 children:children]];
660 664
661 // Add a row for the link. 665 // Add a row for the link.
662 [warnings addObject: 666 [warnings addObject:
663 [self buildDetailToggleItem:type permissionsDetailIndex:0]]; 667 [self buildDetailToggleItem:type permissionsDetailIndex:0]];
664 } 668 }
665 669
666 return warnings; 670 return warnings;
667 } 671 }
668 672
669 - (void)updateViewFrame:(NSRect)frame { 673 - (void)updateViewFrame:(NSRect)frame {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 } 738 }
735 739
736 - (void)accessibilityPerformAction:(NSString*)action { 740 - (void)accessibilityPerformAction:(NSString*)action {
737 if ([action isEqualToString:NSAccessibilityPressAction]) 741 if ([action isEqualToString:NSAccessibilityPressAction])
738 [self handleLinkClicked]; 742 [self handleLinkClicked];
739 else 743 else
740 [super accessibilityPerformAction:action]; 744 [super accessibilityPerformAction:action];
741 } 745 }
742 746
743 @end 747 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698