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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 297803007: Move profile_chooser enums to a constant place for mac and win. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit tests need love too Created 6 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 DCHECK(oauth2_token_service); 271 DCHECK(oauth2_token_service);
272 oauth2_token_service->RemoveObserver(this); 272 oauth2_token_service->RemoveObserver(this);
273 token_observer_registered_ = false; 273 token_observer_registered_ = false;
274 } 274 }
275 275
276 // OAuth2TokenService::Observer: 276 // OAuth2TokenService::Observer:
277 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE { 277 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE {
278 // Tokens can only be added by adding an account through the inline flow, 278 // Tokens can only be added by adding an account through the inline flow,
279 // which is started from the account management view. Refresh it to show the 279 // which is started from the account management view. Refresh it to show the
280 // update. 280 // update.
281 BubbleViewMode viewMode = [controller_ viewMode]; 281 profiles::BubbleViewMode viewMode = [controller_ viewMode];
282 if (viewMode == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT || 282 if (viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ||
283 viewMode == BUBBLE_VIEW_MODE_GAIA_SIGNIN || 283 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN ||
284 viewMode == BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT) { 284 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT) {
285 [controller_ 285 [controller_ initMenuContentsWithView:
286 initMenuContentsWithView:BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 286 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
287 } 287 }
288 } 288 }
289 289
290 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE { 290 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE {
291 // Tokens can only be removed from the account management view. Refresh it 291 // Tokens can only be removed from the account management view. Refresh it
292 // to show the update. 292 // to show the update.
293 if ([controller_ viewMode] == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) 293 if ([controller_ viewMode] == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT)
294 [controller_ 294 [controller_ initMenuContentsWithView:
295 initMenuContentsWithView:BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 295 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
296 } 296 }
297 297
298 // AvatarMenuObserver: 298 // AvatarMenuObserver:
299 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE { 299 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE {
300 // While the bubble is open, the avatar menu can only change from the 300 // While the bubble is open, the avatar menu can only change from the
301 // profile chooser view by modifying the current profile's photo or name. 301 // profile chooser view by modifying the current profile's photo or name.
302 [controller_ initMenuContentsWithView:BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; 302 [controller_
303 initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER];
303 } 304 }
304 305
305 // content::NotificationObserver: 306 // content::NotificationObserver:
306 virtual void Observe( 307 virtual void Observe(
307 int type, 308 int type,
308 const content::NotificationSource& source, 309 const content::NotificationSource& source,
309 const content::NotificationDetails& details) OVERRIDE { 310 const content::NotificationDetails& details) OVERRIDE {
310 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type); 311 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type);
311 if (browser_ == content::Source<Browser>(source).ptr()) { 312 if (browser_ == content::Source<Browser>(source).ptr()) {
312 RemoveTokenServiceObserver(); 313 RemoveTokenServiceObserver();
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 657
657 @interface ProfileChooserController () 658 @interface ProfileChooserController ()
658 // Builds the profile chooser view. 659 // Builds the profile chooser view.
659 - (NSView*)buildProfileChooserView; 660 - (NSView*)buildProfileChooserView;
660 661
661 // Builds a tutorial card with a title label using |titleMessageId|, a content 662 // Builds a tutorial card with a title label using |titleMessageId|, a content
662 // label using |contentMessageId|, and a bottom row with a right-aligned link 663 // label using |contentMessageId|, and a bottom row with a right-aligned link
663 // using |linkMessageId|, and a left aligned button using |buttonMessageId|. 664 // using |linkMessageId|, and a left aligned button using |buttonMessageId|.
664 // On click, the link would execute |linkAction|, and the button would execute 665 // On click, the link would execute |linkAction|, and the button would execute
665 // |buttonAction|. It sets |tutorialMode_| to the given |mode|. 666 // |buttonAction|. It sets |tutorialMode_| to the given |mode|.
666 - (NSView*)tutorialViewWithMode:(TutorialMode)mode 667 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode
667 titleMessage:(int)titleMessageId 668 titleMessage:(int)titleMessageId
668 contentMessage:(int)contentMessageId 669 contentMessage:(int)contentMessageId
669 linkMessage:(int)linkMessageId 670 linkMessage:(int)linkMessageId
670 buttonMessage:(int)buttonMessageId 671 buttonMessage:(int)buttonMessageId
671 linkAction:(SEL)linkAction 672 linkAction:(SEL)linkAction
672 buttonAction:(SEL)buttonAction; 673 buttonAction:(SEL)buttonAction;
673 674
674 // Builds a a tutorial card for new profile management preview if needed. if 675 // Builds a a tutorial card for new profile management preview if needed. if
675 // new profile management is not enabled yet, then it prompts the user to try 676 // new profile management is not enabled yet, then it prompts the user to try
676 // out the feature. Otherwise, it notifies the user that the feature has been 677 // out the feature. Otherwise, it notifies the user that the feature has been
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 729
729 // Creates an email account button with |title| and a remove icon. |tag| 730 // Creates an email account button with |title| and a remove icon. |tag|
730 // indicates which account the button refers to. 731 // indicates which account the button refers to.
731 - (NSButton*)accountButtonWithRect:(NSRect)rect 732 - (NSButton*)accountButtonWithRect:(NSRect)rect
732 title:(const std::string&)title 733 title:(const std::string&)title
733 tag:(int)tag; 734 tag:(int)tag;
734 735
735 @end 736 @end
736 737
737 @implementation ProfileChooserController 738 @implementation ProfileChooserController
738 - (BubbleViewMode) viewMode { 739 - (profiles::BubbleViewMode) viewMode {
739 return viewMode_; 740 return viewMode_;
740 } 741 }
741 742
742 - (IBAction)switchToProfile:(id)sender { 743 - (IBAction)switchToProfile:(id)sender {
743 // Check the event flags to see if a new window should be created. 744 // Check the event flags to see if a new window should be created.
744 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent( 745 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent(
745 [NSApp currentEvent]) == NEW_WINDOW; 746 [NSApp currentEvent]) == NEW_WINDOW;
746 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate, 747 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate,
747 ProfileMetrics::SWITCH_PROFILE_ICON); 748 ProfileMetrics::SWITCH_PROFILE_ICON);
748 } 749 }
749 750
750 - (IBAction)showUserManager:(id)sender { 751 - (IBAction)showUserManager:(id)sender {
751 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); 752 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile());
752 } 753 }
753 754
754 - (IBAction)exitGuest:(id)sender { 755 - (IBAction)exitGuest:(id)sender {
755 DCHECK(browser_->profile()->IsGuestSession()); 756 DCHECK(browser_->profile()->IsGuestSession());
756 [self showUserManager:sender]; 757 [self showUserManager:sender];
757 profiles::CloseGuestProfileWindows(); 758 profiles::CloseGuestProfileWindows();
758 } 759 }
759 760
760 - (IBAction)showAccountManagement:(id)sender { 761 - (IBAction)showAccountManagement:(id)sender {
761 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 762 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
762 } 763 }
763 764
764 - (IBAction)hideAccountManagement:(id)sender { 765 - (IBAction)hideAccountManagement:(id)sender {
765 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; 766 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER];
766 } 767 }
767 768
768 - (IBAction)lockProfile:(id)sender { 769 - (IBAction)lockProfile:(id)sender {
769 profiles::LockProfile(browser_->profile()); 770 profiles::LockProfile(browser_->profile());
770 } 771 }
771 772
772 - (IBAction)showInlineSigninPage:(id)sender { 773 - (IBAction)showInlineSigninPage:(id)sender {
773 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_GAIA_SIGNIN]; 774 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN];
774 } 775 }
775 776
776 - (IBAction)showTabbedSigninPage:(id)sender { 777 - (IBAction)showTabbedSigninPage:(id)sender {
777 chrome::ShowBrowserSignin(browser_, signin::SOURCE_MENU); 778 chrome::ShowBrowserSignin(browser_, signin::SOURCE_MENU);
778 } 779 }
779 780
780 - (IBAction)addAccount:(id)sender { 781 - (IBAction)addAccount:(id)sender {
781 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT]; 782 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT];
782 } 783 }
783 784
784 - (IBAction)navigateBackFromSigninPage:(id)sender { 785 - (IBAction)navigateBackFromSigninPage:(id)sender {
785 std::string primaryAccount = SigninManagerFactory::GetForProfile( 786 std::string primaryAccount = SigninManagerFactory::GetForProfile(
786 browser_->profile())->GetAuthenticatedUsername(); 787 browser_->profile())->GetAuthenticatedUsername();
787 [self initMenuContentsWithView:primaryAccount.empty() ? 788 [self initMenuContentsWithView:primaryAccount.empty() ?
788 BUBBLE_VIEW_MODE_PROFILE_CHOOSER : BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 789 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER :
790 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
789 } 791 }
790 792
791 - (IBAction)showAccountRemovalView:(id)sender { 793 - (IBAction)showAccountRemovalView:(id)sender {
792 DCHECK(!isGuestSession_); 794 DCHECK(!isGuestSession_);
793 795
794 // Tag is either |kPrimaryProfileTag| for the primary account, or equal to the 796 // Tag is either |kPrimaryProfileTag| for the primary account, or equal to the
795 // index in |currentProfileAccounts_| for a secondary account. 797 // index in |currentProfileAccounts_| for a secondary account.
796 int tag = [sender tag]; 798 int tag = [sender tag];
797 if (tag == kPrimaryProfileTag) { 799 if (tag == kPrimaryProfileTag) {
798 accountIdToRemove_ = SigninManagerFactory::GetForProfile( 800 accountIdToRemove_ = SigninManagerFactory::GetForProfile(
799 browser_->profile())->GetAuthenticatedUsername(); 801 browser_->profile())->GetAuthenticatedUsername();
800 } else { 802 } else {
801 DCHECK(ContainsKey(currentProfileAccounts_, tag)); 803 DCHECK(ContainsKey(currentProfileAccounts_, tag));
802 accountIdToRemove_ = currentProfileAccounts_[tag]; 804 accountIdToRemove_ = currentProfileAccounts_[tag];
803 } 805 }
804 806
805 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; 807 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL];
806 } 808 }
807 809
808 - (IBAction)removeAccount:(id)sender { 810 - (IBAction)removeAccount:(id)sender {
809 DCHECK(!accountIdToRemove_.empty()); 811 DCHECK(!accountIdToRemove_.empty());
810 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( 812 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile(
811 browser_->profile())->RevokeCredentials(accountIdToRemove_); 813 browser_->profile())->RevokeCredentials(accountIdToRemove_);
812 accountIdToRemove_.clear(); 814 accountIdToRemove_.clear();
813 815
814 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 816 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
815 } 817 }
816 818
817 - (IBAction)openTutorialLearnMoreURL:(id)sender { 819 - (IBAction)openTutorialLearnMoreURL:(id)sender {
818 // TODO(guohui): update |learnMoreUrl| once it is decided. 820 // TODO(guohui): update |learnMoreUrl| once it is decided.
819 const GURL learnMoreUrl("https://support.google.com/chrome/?hl=en#to"); 821 const GURL learnMoreUrl("https://support.google.com/chrome/?hl=en#to");
820 chrome::NavigateParams params(browser_->profile(), learnMoreUrl, 822 chrome::NavigateParams params(browser_->profile(), learnMoreUrl,
821 content::PAGE_TRANSITION_LINK); 823 content::PAGE_TRANSITION_LINK);
822 params.disposition = NEW_FOREGROUND_TAB; 824 params.disposition = NEW_FOREGROUND_TAB;
823 chrome::Navigate(&params); 825 chrome::Navigate(&params);
824 } 826 }
825 827
826 - (IBAction)enableNewProfileManagementPreview:(id)sender { 828 - (IBAction)enableNewProfileManagementPreview:(id)sender {
827 profiles::EnableNewProfileManagementPreview(); 829 profiles::EnableNewProfileManagementPreview();
828 } 830 }
829 831
830 - (IBAction)dismissTutorial:(id)sender { 832 - (IBAction)dismissTutorial:(id)sender {
831 // If the user manually dismissed the tutorial, never show it again by setting 833 // If the user manually dismissed the tutorial, never show it again by setting
832 // the number of times shown to the maximum plus 1, so that later we could 834 // the number of times shown to the maximum plus 1, so that later we could
833 // distinguish between the dismiss case and the case when the tutorial is 835 // distinguish between the dismiss case and the case when the tutorial is
834 // indeed shown for the maximum number of times. 836 // indeed shown for the maximum number of times.
835 browser_->profile()->GetPrefs()->SetInteger( 837 browser_->profile()->GetPrefs()->SetInteger(
836 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); 838 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1);
837 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; 839 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER];
838 } 840 }
839 841
840 - (IBAction)showSendFeedbackTutorial:(id)sender { 842 - (IBAction)showSendFeedbackTutorial:(id)sender {
841 tutorialMode_ = TUTORIAL_MODE_SEND_FEEDBACK; 843 tutorialMode_ = profiles::TUTORIAL_MODE_SEND_FEEDBACK;
842 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; 844 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER];
843 } 845 }
844 846
845 - (IBAction)showEndPreviewView:(id)sender { 847 - (IBAction)showEndPreviewView:(id)sender {
846 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_END_PREVIEW]; 848 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_END_PREVIEW];
847 } 849 }
848 850
849 - (IBAction)sendFeedback:(id)sender { 851 - (IBAction)sendFeedback:(id)sender {
850 chrome::OpenFeedbackDialog(browser_); 852 chrome::OpenFeedbackDialog(browser_);
851 } 853 }
852 854
853 - (IBAction)endPreviewAndRelaunch:(id)sender { 855 - (IBAction)endPreviewAndRelaunch:(id)sender {
854 profiles::DisableNewProfileManagementPreview(); 856 profiles::DisableNewProfileManagementPreview();
855 } 857 }
856 858
857 - (void)cleanUpEmbeddedViewContents { 859 - (void)cleanUpEmbeddedViewContents {
858 webContents_.reset(); 860 webContents_.reset();
859 } 861 }
860 862
861 - (id)initWithBrowser:(Browser*)browser 863 - (id)initWithBrowser:(Browser*)browser
862 anchoredAt:(NSPoint)point 864 anchoredAt:(NSPoint)point
863 withMode:(BubbleViewMode)mode { 865 withMode:(profiles::BubbleViewMode)mode {
864 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] 866 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc]
865 initWithContentRect:ui::kWindowSizeDeterminedLater 867 initWithContentRect:ui::kWindowSizeDeterminedLater
866 styleMask:NSBorderlessWindowMask 868 styleMask:NSBorderlessWindowMask
867 backing:NSBackingStoreBuffered 869 backing:NSBackingStoreBuffered
868 defer:NO]); 870 defer:NO]);
869 871
870 if ((self = [super initWithWindow:window 872 if ((self = [super initWithWindow:window
871 parentWindow:browser->window()->GetNativeWindow() 873 parentWindow:browser->window()->GetNativeWindow()
872 anchoredAt:point])) { 874 anchoredAt:point])) {
873 browser_ = browser; 875 browser_ = browser;
874 viewMode_ = mode; 876 viewMode_ = mode;
875 tutorialMode_ = TUTORIAL_MODE_NONE; 877 tutorialMode_ = profiles::TUTORIAL_MODE_NONE;
876 observer_.reset(new ActiveProfileObserverBridge(self, browser_)); 878 observer_.reset(new ActiveProfileObserverBridge(self, browser_));
877 879
878 avatarMenu_.reset(new AvatarMenu( 880 avatarMenu_.reset(new AvatarMenu(
879 &g_browser_process->profile_manager()->GetProfileInfoCache(), 881 &g_browser_process->profile_manager()->GetProfileInfoCache(),
880 observer_.get(), 882 observer_.get(),
881 browser_)); 883 browser_));
882 avatarMenu_->RebuildMenu(); 884 avatarMenu_->RebuildMenu();
883 885
884 // Guest profiles do not have a token service. 886 // Guest profiles do not have a token service.
885 isGuestSession_ = browser_->profile()->IsGuestSession(); 887 isGuestSession_ = browser_->profile()->IsGuestSession();
886 888
887 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; 889 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge];
888 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; 890 [[self bubble] setArrowLocation:info_bubble::kNoArrow];
889 [[self bubble] setBackgroundColor:GetDialogBackgroundColor()]; 891 [[self bubble] setBackgroundColor:GetDialogBackgroundColor()];
890 [self initMenuContentsWithView:viewMode_]; 892 [self initMenuContentsWithView:viewMode_];
891 } 893 }
892 894
893 return self; 895 return self;
894 } 896 }
895 897
896 - (void)initMenuContentsWithView:(BubbleViewMode)viewToDisplay { 898 - (void)initMenuContentsWithView:(profiles::BubbleViewMode)viewToDisplay {
897 viewMode_ = viewToDisplay; 899 viewMode_ = viewToDisplay;
898 NSView* contentView = [[self window] contentView]; 900 NSView* contentView = [[self window] contentView];
899 [contentView setSubviews:[NSArray array]]; 901 [contentView setSubviews:[NSArray array]];
900 NSView* subView; 902 NSView* subView;
901 903
902 switch (viewMode_) { 904 switch (viewMode_) {
903 case BUBBLE_VIEW_MODE_GAIA_SIGNIN: 905 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
904 case BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: 906 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
907 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH:
905 subView = [self buildGaiaEmbeddedView]; 908 subView = [self buildGaiaEmbeddedView];
906 break; 909 break;
907 case BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL: 910 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL:
908 subView = [self buildAccountRemovalView]; 911 subView = [self buildAccountRemovalView];
909 break; 912 break;
910 case BUBBLE_VIEW_MODE_END_PREVIEW: 913 case profiles::BUBBLE_VIEW_MODE_END_PREVIEW:
911 subView = [self buildEndPreviewView]; 914 subView = [self buildEndPreviewView];
912 break; 915 break;
913 case BUBBLE_VIEW_MODE_PROFILE_CHOOSER: 916 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER:
914 case BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: 917 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT:
915 subView = [self buildProfileChooserView]; 918 subView = [self buildProfileChooserView];
919 break;
916 } 920 }
917 921
918 [contentView addSubview:subView]; 922 [contentView addSubview:subView];
919 SetWindowSize([self window], 923 SetWindowSize([self window],
920 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); 924 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame])));
921 } 925 }
922 926
923 - (NSView*)buildProfileChooserView { 927 - (NSView*)buildProfileChooserView {
924 base::scoped_nsobject<NSView> container( 928 base::scoped_nsobject<NSView> container(
925 [[NSView alloc] initWithFrame:NSZeroRect]); 929 [[NSView alloc] initWithFrame:NSZeroRect]);
926 930
927 NSView* tutorialView = nil; 931 NSView* tutorialView = nil;
928 NSView* currentProfileView = nil; 932 NSView* currentProfileView = nil;
929 base::scoped_nsobject<NSMutableArray> otherProfiles( 933 base::scoped_nsobject<NSMutableArray> otherProfiles(
930 [[NSMutableArray alloc] init]); 934 [[NSMutableArray alloc] init]);
931 // Local and guest profiles cannot lock their profile. 935 // Local and guest profiles cannot lock their profile.
932 bool enableLock = false; 936 bool enableLock = false;
933 937
934 // Loop over the profiles in reverse, so that they are sorted by their 938 // Loop over the profiles in reverse, so that they are sorted by their
935 // y-coordinate, and separate them into active and "other" profiles. 939 // y-coordinate, and separate them into active and "other" profiles.
936 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { 940 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) {
937 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); 941 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i);
938 if (item.active) { 942 if (item.active) {
939 if (viewMode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) 943 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER)
940 tutorialView = [self buildPreviewTutorialIfNeeded:item]; 944 tutorialView = [self buildPreviewTutorialIfNeeded:item];
941 currentProfileView = [self createCurrentProfileView:item]; 945 currentProfileView = [self createCurrentProfileView:item];
942 enableLock = item.signed_in; 946 enableLock = item.signed_in;
943 } else { 947 } else {
944 [otherProfiles addObject:[self createOtherProfileView:i]]; 948 [otherProfiles addObject:[self createOtherProfileView:i]];
945 } 949 }
946 } 950 }
947 if (!currentProfileView) // Guest windows don't have an active profile. 951 if (!currentProfileView) // Guest windows don't have an active profile.
948 currentProfileView = [self createGuestProfileView]; 952 currentProfileView = [self createGuestProfileView];
949 953
950 // |yOffset| is the next position at which to draw in |container| 954 // |yOffset| is the next position at which to draw in |container|
951 // coordinates. 955 // coordinates.
952 CGFloat yOffset = 0; 956 CGFloat yOffset = 0;
953 957
954 // Option buttons. Only available with the new profile management flag. 958 // Option buttons. Only available with the new profile management flag.
955 if (switches::IsNewProfileManagement()) { 959 if (switches::IsNewProfileManagement()) {
956 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); 960 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0);
957 NSView* optionsView = [self createOptionsViewWithRect:rect 961 NSView* optionsView = [self createOptionsViewWithRect:rect
958 enableLock:enableLock]; 962 enableLock:enableLock];
959 [container addSubview:optionsView]; 963 [container addSubview:optionsView];
960 rect.origin.y = NSMaxY([optionsView frame]); 964 rect.origin.y = NSMaxY([optionsView frame]);
961 965
962 NSBox* separator = [self separatorWithFrame:rect]; 966 NSBox* separator = [self separatorWithFrame:rect];
963 [container addSubview:separator]; 967 [container addSubview:separator];
964 yOffset = NSMaxY([separator frame]); 968 yOffset = NSMaxY([separator frame]);
965 } 969 }
966 970
967 if (viewMode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER && 971 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER &&
968 switches::IsFastUserSwitching()) { 972 switches::IsFastUserSwitching()) {
969 // Other profiles switcher. The profiles have already been sorted 973 // Other profiles switcher. The profiles have already been sorted
970 // by their y-coordinate, so they can be added in the existing order. 974 // by their y-coordinate, so they can be added in the existing order.
971 for (NSView *otherProfileView in otherProfiles.get()) { 975 for (NSView *otherProfileView in otherProfiles.get()) {
972 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 976 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
973 [container addSubview:otherProfileView]; 977 [container addSubview:otherProfileView];
974 yOffset = NSMaxY([otherProfileView frame]); 978 yOffset = NSMaxY([otherProfileView frame]);
975 979
976 NSBox* separator = 980 NSBox* separator =
977 [self separatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 981 [self separatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)];
978 [container addSubview:separator]; 982 [container addSubview:separator];
979 yOffset = NSMaxY([separator frame]); 983 yOffset = NSMaxY([separator frame]);
980 } 984 }
981 } else if (viewMode_ == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { 985 } else if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
982 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: 986 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView:
983 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 987 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)];
984 [container addSubview:currentProfileAccountsView]; 988 [container addSubview:currentProfileAccountsView];
985 yOffset = NSMaxY([currentProfileAccountsView frame]); 989 yOffset = NSMaxY([currentProfileAccountsView frame]);
986 990
987 NSBox* accountsSeparator = [self separatorWithFrame: 991 NSBox* accountsSeparator = [self separatorWithFrame:
988 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 992 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)];
989 [container addSubview:accountsSeparator]; 993 [container addSubview:accountsSeparator];
990 yOffset = NSMaxY([accountsSeparator frame]); 994 yOffset = NSMaxY([accountsSeparator frame]);
991 } 995 }
992 996
993 // Active profile card. 997 // Active profile card.
994 if (currentProfileView) { 998 if (currentProfileView) {
995 yOffset += kVerticalSpacing; 999 yOffset += kVerticalSpacing;
996 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1000 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
997 [container addSubview:currentProfileView]; 1001 [container addSubview:currentProfileView];
998 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; 1002 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing;
999 } 1003 }
1000 1004
1001 if (tutorialView) { 1005 if (tutorialView) {
1002 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; 1006 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)];
1003 [container addSubview:tutorialView]; 1007 [container addSubview:tutorialView];
1004 yOffset = NSMaxY([tutorialView frame]); 1008 yOffset = NSMaxY([tutorialView frame]);
1005 } else { 1009 } else {
1006 tutorialMode_ = TUTORIAL_MODE_NONE; 1010 tutorialMode_ = profiles::TUTORIAL_MODE_NONE;
1007 } 1011 }
1008 1012
1009 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; 1013 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)];
1010 return container.autorelease();; 1014 return container.autorelease();;
1011 } 1015 }
1012 1016
1013 - (NSView*)buildPreviewTutorialIfNeeded:(const AvatarMenu::Item&)item { 1017 - (NSView*)buildPreviewTutorialIfNeeded:(const AvatarMenu::Item&)item {
1014 if (!switches::IsNewProfileManagement()) { 1018 if (!switches::IsNewProfileManagement()) {
1015 return [self tutorialViewWithMode:TUTORIAL_MODE_ENABLE_PREVIEW 1019 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_ENABLE_PREVIEW
1016 titleMessage:IDS_PROFILES_PREVIEW_TUTORIAL_TITLE 1020 titleMessage:IDS_PROFILES_PREVIEW_TUTORIAL_TITLE
1017 contentMessage:IDS_PROFILES_PREVIEW_TUTORIAL_CONTENT_TEXT 1021 contentMessage:IDS_PROFILES_PREVIEW_TUTORIAL_CONTENT_TEXT
1018 linkMessage:IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE 1022 linkMessage:IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE
1019 buttonMessage:IDS_PROFILES_TUTORIAL_TRY_BUTTON 1023 buttonMessage:IDS_PROFILES_TUTORIAL_TRY_BUTTON
1020 linkAction:@selector(openTutorialLearnMoreURL:) 1024 linkAction:@selector(openTutorialLearnMoreURL:)
1021 buttonAction: 1025 buttonAction:
1022 @selector(enableNewProfileManagementPreview:)]; 1026 @selector(enableNewProfileManagementPreview:)];
1023 } 1027 }
1024 1028
1025 if (!switches::IsNewProfileManagementPreviewEnabled()) 1029 if (!switches::IsNewProfileManagementPreviewEnabled())
1026 return nil; 1030 return nil;
1027 1031
1028 if (tutorialMode_ == TUTORIAL_MODE_SEND_FEEDBACK) { 1032 if (tutorialMode_ == profiles::TUTORIAL_MODE_SEND_FEEDBACK) {
1029 return [self tutorialViewWithMode:TUTORIAL_MODE_SEND_FEEDBACK 1033 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_SEND_FEEDBACK
1030 titleMessage:IDS_PROFILES_FEEDBACK_TUTORIAL_TITLE 1034 titleMessage:IDS_PROFILES_FEEDBACK_TUTORIAL_TITLE
1031 contentMessage: 1035 contentMessage:
1032 IDS_PROFILES_FEEDBACK_TUTORIAL_CONTENT_TEXT 1036 IDS_PROFILES_FEEDBACK_TUTORIAL_CONTENT_TEXT
1033 linkMessage:IDS_PROFILES_END_PREVIEW 1037 linkMessage:IDS_PROFILES_END_PREVIEW
1034 buttonMessage:IDS_PROFILES_SEND_FEEDBACK_BUTTON 1038 buttonMessage:IDS_PROFILES_SEND_FEEDBACK_BUTTON
1035 linkAction:@selector(showEndPreviewView:) 1039 linkAction:@selector(showEndPreviewView:)
1036 buttonAction:@selector(sendFeedback:)]; 1040 buttonAction:@selector(sendFeedback:)];
1037 } 1041 }
1038 1042
1039 Profile* profile = browser_->profile(); 1043 Profile* profile = browser_->profile();
1040 const int showCount = profile->GetPrefs()->GetInteger( 1044 const int showCount = profile->GetPrefs()->GetInteger(
1041 prefs::kProfileAvatarTutorialShown); 1045 prefs::kProfileAvatarTutorialShown);
1042 // Do not show the tutorial if user has dismissed it. 1046 // Do not show the tutorial if user has dismissed it.
1043 if (showCount > kProfileAvatarTutorialShowMax) 1047 if (showCount > kProfileAvatarTutorialShowMax)
1044 return nil; 1048 return nil;
1045 1049
1046 if (tutorialMode_ != TUTORIAL_MODE_WELCOME) { 1050 if (tutorialMode_ != profiles::TUTORIAL_MODE_WELCOME) {
1047 if (showCount == kProfileAvatarTutorialShowMax) 1051 if (showCount == kProfileAvatarTutorialShowMax)
1048 return nil; 1052 return nil;
1049 profile->GetPrefs()->SetInteger( 1053 profile->GetPrefs()->SetInteger(
1050 prefs::kProfileAvatarTutorialShown, showCount + 1); 1054 prefs::kProfileAvatarTutorialShown, showCount + 1);
1051 } 1055 }
1052 1056
1053 return [self tutorialViewWithMode:TUTORIAL_MODE_WELCOME 1057 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME
1054 titleMessage:IDS_PROFILES_PREVIEW_ENABLED_TUTORIAL_TITLE 1058 titleMessage:IDS_PROFILES_PREVIEW_ENABLED_TUTORIAL_TITLE
1055 contentMessage: 1059 contentMessage:
1056 IDS_PROFILES_PREVIEW_ENABLED_TUTORIAL_CONTENT_TEXT 1060 IDS_PROFILES_PREVIEW_ENABLED_TUTORIAL_CONTENT_TEXT
1057 linkMessage:IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE 1061 linkMessage:IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE
1058 buttonMessage:IDS_PROFILES_TUTORIAL_OK_BUTTON 1062 buttonMessage:IDS_PROFILES_TUTORIAL_OK_BUTTON
1059 linkAction:@selector(openTutorialLearnMoreURL:) 1063 linkAction:@selector(openTutorialLearnMoreURL:)
1060 buttonAction:@selector(dismissTutorial:)]; 1064 buttonAction:@selector(dismissTutorial:)];
1061 } 1065 }
1062 1066
1063 - (NSView*)tutorialViewWithMode:(TutorialMode)mode 1067 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode
1064 titleMessage:(int)titleMessageId 1068 titleMessage:(int)titleMessageId
1065 contentMessage:(int)contentMessageId 1069 contentMessage:(int)contentMessageId
1066 linkMessage:(int)linkMessageId 1070 linkMessage:(int)linkMessageId
1067 buttonMessage:(int)buttonMessageId 1071 buttonMessage:(int)buttonMessageId
1068 linkAction:(SEL)linkAction 1072 linkAction:(SEL)linkAction
1069 buttonAction:(SEL)buttonAction { 1073 buttonAction:(SEL)buttonAction {
1070 tutorialMode_ = mode; 1074 tutorialMode_ = mode;
1071 1075
1072 NSColor* tutorialBackgroundColor = 1076 NSColor* tutorialBackgroundColor =
1073 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); 1077 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); 1238 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
1235 1239
1236 // Don't double-apply the left margin to the sub-views. 1240 // Don't double-apply the left margin to the sub-views.
1237 rect.origin.x = 0; 1241 rect.origin.x = 0;
1238 1242
1239 // The available links depend on the type of profile that is active. 1243 // The available links depend on the type of profile that is active.
1240 NSButton* link; 1244 NSButton* link;
1241 if (item.signed_in) { 1245 if (item.signed_in) {
1242 if (switches::IsNewProfileManagement()) { 1246 if (switches::IsNewProfileManagement()) {
1243 NSString* linkTitle = l10n_util::GetNSString( 1247 NSString* linkTitle = l10n_util::GetNSString(
1244 viewMode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? 1248 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ?
1245 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : 1249 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON :
1246 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 1250 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1247 SEL linkSelector = (viewMode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? 1251 SEL linkSelector =
1252 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ?
1248 @selector(showAccountManagement:) : @selector(hideAccountManagement:); 1253 @selector(showAccountManagement:) : @selector(hideAccountManagement:);
1249 link = [self linkButtonWithTitle:linkTitle 1254 link = [self linkButtonWithTitle:linkTitle
1250 frameOrigin:rect.origin 1255 frameOrigin:rect.origin
1251 action:linkSelector]; 1256 action:linkSelector];
1252 } else { 1257 } else {
1253 link = [self linkButtonWithTitle:base::SysUTF16ToNSString(item.sync_state) 1258 link = [self linkButtonWithTitle:base::SysUTF16ToNSString(item.sync_state)
1254 frameOrigin:rect.origin 1259 frameOrigin:rect.origin
1255 action:nil]; 1260 action:nil];
1256 [[link cell] setTextColor:[NSColor blackColor]]; 1261 [[link cell] setTextColor:[NSColor blackColor]];
1257 } 1262 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 [container setFrameSize:NSMakeSize(NSWidth([container frame]), 1436 [container setFrameSize:NSMakeSize(NSWidth([container frame]),
1432 NSMaxY([accountButton frame]))]; 1437 NSMaxY([accountButton frame]))];
1433 return container.autorelease(); 1438 return container.autorelease();
1434 } 1439 }
1435 1440
1436 - (NSView*)buildGaiaEmbeddedView { 1441 - (NSView*)buildGaiaEmbeddedView {
1437 base::scoped_nsobject<NSView> container( 1442 base::scoped_nsobject<NSView> container(
1438 [[NSView alloc] initWithFrame:NSZeroRect]); 1443 [[NSView alloc] initWithFrame:NSZeroRect]);
1439 CGFloat yOffset = 0; 1444 CGFloat yOffset = 0;
1440 1445
1441 bool addSecondaryAccount = viewMode_ == BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT; 1446 bool addSecondaryAccount =
1447 viewMode_ == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT;
1442 signin::Source source = addSecondaryAccount ? 1448 signin::Source source = addSecondaryAccount ?
1443 signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT : 1449 signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT :
1444 signin::SOURCE_AVATAR_BUBBLE_SIGN_IN; 1450 signin::SOURCE_AVATAR_BUBBLE_SIGN_IN;
1445 1451
1446 webContents_.reset(content::WebContents::Create( 1452 webContents_.reset(content::WebContents::Create(
1447 content::WebContents::CreateParams(browser_->profile()))); 1453 content::WebContents::CreateParams(browser_->profile())));
1448 webContents_->GetController().LoadURL( 1454 webContents_->GetController().LoadURL(
1449 signin::GetPromoURL( 1455 signin::GetPromoURL(
1450 source, false /* auto_close */, true /* is_constrained */), 1456 source, false /* auto_close */, true /* is_constrained */),
1451 content::Referrer(), 1457 content::Referrer(),
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 IDR_CLOSE_1_P).ToNSImage()]; 1689 IDR_CLOSE_1_P).ToNSImage()];
1684 [deleteButton setTarget:self]; 1690 [deleteButton setTarget:self];
1685 [deleteButton setAction:@selector(showAccountRemovalView:)]; 1691 [deleteButton setAction:@selector(showAccountRemovalView:)];
1686 [deleteButton setTag:tag]; 1692 [deleteButton setTag:tag];
1687 1693
1688 [button addSubview:deleteButton]; 1694 [button addSubview:deleteButton];
1689 return button.autorelease(); 1695 return button.autorelease();
1690 } 1696 }
1691 1697
1692 @end 1698 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698