OLD | NEW |
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" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/lifetime/application_lifetime.h" | 15 #include "chrome/browser/lifetime/application_lifetime.h" |
16 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 16 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
17 #include "chrome/browser/profiles/avatar_menu.h" | 17 #include "chrome/browser/profiles/avatar_menu.h" |
18 #include "chrome/browser/profiles/avatar_menu_observer.h" | 18 #include "chrome/browser/profiles/avatar_menu_observer.h" |
19 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 19 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
20 #include "chrome/browser/profiles/profile_info_cache.h" | 20 #include "chrome/browser/profiles/profile_info_cache.h" |
21 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
22 #include "chrome/browser/profiles/profile_metrics.h" | 22 #include "chrome/browser/profiles/profile_metrics.h" |
23 #include "chrome/browser/profiles/profile_window.h" | 23 #include "chrome/browser/profiles/profile_window.h" |
24 #include "chrome/browser/profiles/profiles_state.h" | 24 #include "chrome/browser/profiles/profiles_state.h" |
| 25 #include "chrome/browser/signin/local_auth.h" |
25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
26 #include "chrome/browser/signin/signin_header_helper.h" | 27 #include "chrome/browser/signin/signin_header_helper.h" |
27 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
28 #include "chrome/browser/signin/signin_promo.h" | 29 #include "chrome/browser/signin/signin_promo.h" |
29 #include "chrome/browser/signin/signin_ui_util.h" | 30 #include "chrome/browser/signin/signin_ui_util.h" |
30 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
31 #include "chrome/browser/ui/browser_commands.h" | 32 #include "chrome/browser/ui/browser_commands.h" |
32 #include "chrome/browser/ui/browser_dialogs.h" | 33 #include "chrome/browser/ui/browser_dialogs.h" |
33 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
34 #include "chrome/browser/ui/chrome_pages.h" | 35 #include "chrome/browser/ui/chrome_pages.h" |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 | 820 |
820 // Creates a main profile card for the guest user. | 821 // Creates a main profile card for the guest user. |
821 - (NSView*)createGuestProfileView; | 822 - (NSView*)createGuestProfileView; |
822 | 823 |
823 // Creates an item for the profile |itemIndex| that is used in the fast profile | 824 // Creates an item for the profile |itemIndex| that is used in the fast profile |
824 // switcher in the middle of the bubble. | 825 // switcher in the middle of the bubble. |
825 - (NSButton*)createOtherProfileView:(int)itemIndex; | 826 - (NSButton*)createOtherProfileView:(int)itemIndex; |
826 | 827 |
827 // Creates the "Not you" and Lock option buttons. | 828 // Creates the "Not you" and Lock option buttons. |
828 - (NSView*)createOptionsViewWithRect:(NSRect)rect | 829 - (NSView*)createOptionsViewWithRect:(NSRect)rect |
829 enableLock:(BOOL)enableLock; | 830 displayLock:(BOOL)displayLock; |
830 | 831 |
831 // Creates the account management view for the active profile. | 832 // Creates the account management view for the active profile. |
832 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; | 833 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; |
833 | 834 |
834 // Creates the list of accounts for the active profile. | 835 // Creates the list of accounts for the active profile. |
835 - (NSView*)createAccountsListWithRect:(NSRect)rect; | 836 - (NSView*)createAccountsListWithRect:(NSRect)rect; |
836 | 837 |
837 // Creates the Gaia sign-in/add account view. | 838 // Creates the Gaia sign-in/add account view. |
838 - (NSView*)buildGaiaEmbeddedView; | 839 - (NSView*)buildGaiaEmbeddedView; |
839 | 840 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1134 |
1134 - (NSView*)buildProfileChooserView { | 1135 - (NSView*)buildProfileChooserView { |
1135 base::scoped_nsobject<NSView> container( | 1136 base::scoped_nsobject<NSView> container( |
1136 [[NSView alloc] initWithFrame:NSZeroRect]); | 1137 [[NSView alloc] initWithFrame:NSZeroRect]); |
1137 | 1138 |
1138 NSView* tutorialView = nil; | 1139 NSView* tutorialView = nil; |
1139 NSView* currentProfileView = nil; | 1140 NSView* currentProfileView = nil; |
1140 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1141 base::scoped_nsobject<NSMutableArray> otherProfiles( |
1141 [[NSMutableArray alloc] init]); | 1142 [[NSMutableArray alloc] init]); |
1142 // Local and guest profiles cannot lock their profile. | 1143 // Local and guest profiles cannot lock their profile. |
1143 bool enableLock = false; | 1144 bool displayLock = false; |
1144 | 1145 |
1145 // Loop over the profiles in reverse, so that they are sorted by their | 1146 // Loop over the profiles in reverse, so that they are sorted by their |
1146 // y-coordinate, and separate them into active and "other" profiles. | 1147 // y-coordinate, and separate them into active and "other" profiles. |
1147 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { | 1148 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { |
1148 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); | 1149 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); |
1149 if (item.active) { | 1150 if (item.active) { |
1150 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 1151 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { |
1151 switch (tutorialMode_) { | 1152 switch (tutorialMode_) { |
1152 case profiles::TUTORIAL_MODE_NONE: | 1153 case profiles::TUTORIAL_MODE_NONE: |
1153 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: | 1154 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: |
1154 tutorialView = | 1155 tutorialView = |
1155 [self buildWelcomeUpgradeTutorialViewIfNeeded]; | 1156 [self buildWelcomeUpgradeTutorialViewIfNeeded]; |
1156 break; | 1157 break; |
1157 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: | 1158 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: |
1158 tutorialView = [self buildSigninConfirmationView]; | 1159 tutorialView = [self buildSigninConfirmationView]; |
1159 break; | 1160 break; |
1160 case profiles::TUTORIAL_MODE_SHOW_ERROR: | 1161 case profiles::TUTORIAL_MODE_SHOW_ERROR: |
1161 tutorialView = [self buildSigninErrorView]; | 1162 tutorialView = [self buildSigninErrorView]; |
1162 } | 1163 } |
1163 } | 1164 } |
1164 currentProfileView = [self createCurrentProfileView:item]; | 1165 currentProfileView = [self createCurrentProfileView:item]; |
1165 enableLock = switches::IsNewProfileManagement() && item.signed_in; | 1166 displayLock = switches::IsNewProfileManagement() && item.signed_in; |
1166 } else { | 1167 } else { |
1167 [otherProfiles addObject:[self createOtherProfileView:i]]; | 1168 [otherProfiles addObject:[self createOtherProfileView:i]]; |
1168 } | 1169 } |
1169 } | 1170 } |
1170 if (!currentProfileView) // Guest windows don't have an active profile. | 1171 if (!currentProfileView) // Guest windows don't have an active profile. |
1171 currentProfileView = [self createGuestProfileView]; | 1172 currentProfileView = [self createGuestProfileView]; |
1172 | 1173 |
1173 // |yOffset| is the next position at which to draw in |container| | 1174 // |yOffset| is the next position at which to draw in |container| |
1174 // coordinates. Add a pixel offset so that the bottom option buttons don't | 1175 // coordinates. Add a pixel offset so that the bottom option buttons don't |
1175 // overlap the bubble's rounded corners. | 1176 // overlap the bubble's rounded corners. |
1176 CGFloat yOffset = 1; | 1177 CGFloat yOffset = 1; |
1177 | 1178 |
1178 // Option buttons. | 1179 // Option buttons. |
1179 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); | 1180 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); |
1180 NSView* optionsView = [self createOptionsViewWithRect:rect | 1181 NSView* optionsView = [self createOptionsViewWithRect:rect |
1181 enableLock:enableLock]; | 1182 displayLock:displayLock]; |
1182 [container addSubview:optionsView]; | 1183 [container addSubview:optionsView]; |
1183 rect.origin.y = NSMaxY([optionsView frame]); | 1184 rect.origin.y = NSMaxY([optionsView frame]); |
1184 | 1185 |
1185 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; | 1186 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; |
1186 [container addSubview:separator]; | 1187 [container addSubview:separator]; |
1187 yOffset = NSMaxY([separator frame]); | 1188 yOffset = NSMaxY([separator frame]); |
1188 | 1189 |
1189 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | 1190 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && |
1190 switches::IsFastUserSwitching()) { | 1191 switches::IsFastUserSwitching()) { |
1191 // Other profiles switcher. The profiles have already been sorted | 1192 // Other profiles switcher. The profiles have already been sorted |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 [profileButton setAlignment:NSLeftTextAlignment]; | 1684 [profileButton setAlignment:NSLeftTextAlignment]; |
1684 [profileButton setBordered:NO]; | 1685 [profileButton setBordered:NO]; |
1685 [profileButton setTag:itemIndex]; | 1686 [profileButton setTag:itemIndex]; |
1686 [profileButton setTarget:self]; | 1687 [profileButton setTarget:self]; |
1687 [profileButton setAction:@selector(switchToProfile:)]; | 1688 [profileButton setAction:@selector(switchToProfile:)]; |
1688 | 1689 |
1689 return profileButton.autorelease(); | 1690 return profileButton.autorelease(); |
1690 } | 1691 } |
1691 | 1692 |
1692 - (NSView*)createOptionsViewWithRect:(NSRect)rect | 1693 - (NSView*)createOptionsViewWithRect:(NSRect)rect |
1693 enableLock:(BOOL)enableLock { | 1694 displayLock:(BOOL)displayLock { |
1694 NSRect viewRect = NSMakeRect(0, 0, | 1695 NSRect viewRect = NSMakeRect(0, 0, |
1695 rect.size.width, | 1696 rect.size.width, |
1696 kBlueButtonHeight + kSmallVerticalSpacing); | 1697 kBlueButtonHeight + kSmallVerticalSpacing); |
1697 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 1698 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
1698 | 1699 |
1699 if (enableLock) { | 1700 if (displayLock) { |
1700 NSButton* lockButton = | 1701 NSButton* lockButton = |
1701 [self hoverButtonWithRect:viewRect | 1702 [self hoverButtonWithRect:viewRect |
1702 text:l10n_util::GetNSString( | 1703 text:l10n_util::GetNSString( |
1703 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) | 1704 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) |
1704 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK | 1705 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK |
1705 action:@selector(lockProfile:)]; | 1706 action:@selector(lockProfile:)]; |
| 1707 if (!chrome::LocalAuthCredentialsExist(browser_->profile())) |
| 1708 [lockButton setEnabled:NO]; |
1706 [container addSubview:lockButton]; | 1709 [container addSubview:lockButton]; |
1707 viewRect.origin.y = NSMaxY([lockButton frame]); | 1710 viewRect.origin.y = NSMaxY([lockButton frame]); |
1708 | 1711 |
1709 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; | 1712 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; |
1710 [container addSubview:separator]; | 1713 [container addSubview:separator]; |
1711 viewRect.origin.y = NSMaxY([separator frame]); | 1714 viewRect.origin.y = NSMaxY([separator frame]); |
1712 } | 1715 } |
1713 | 1716 |
1714 if ([self shouldShowGoIncognito]) { | 1717 if ([self shouldShowGoIncognito]) { |
1715 NSButton* goIncognitoButton = | 1718 NSButton* goIncognitoButton = |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2152 } | 2155 } |
2153 | 2156 |
2154 - (bool)shouldShowGoIncognito { | 2157 - (bool)shouldShowGoIncognito { |
2155 bool incognitoAvailable = | 2158 bool incognitoAvailable = |
2156 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2159 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2157 IncognitoModePrefs::DISABLED; | 2160 IncognitoModePrefs::DISABLED; |
2158 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2161 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2159 } | 2162 } |
2160 | 2163 |
2161 @end | 2164 @end |
OLD | NEW |