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

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

Issue 2174973002: [Mac][MD User Menu] Revamped signin/sync error surfacing UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After refactoring Created 4 years, 4 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
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
6 6
7 #import <Carbon/Carbon.h> // kVK_Return. 7 #import <Carbon/Carbon.h> // kVK_Return.
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/profiles/profile_metrics.h" 26 #include "chrome/browser/profiles/profile_metrics.h"
27 #include "chrome/browser/profiles/profile_window.h" 27 #include "chrome/browser/profiles/profile_window.h"
28 #include "chrome/browser/profiles/profiles_state.h" 28 #include "chrome/browser/profiles/profiles_state.h"
29 #include "chrome/browser/signin/chrome_signin_helper.h" 29 #include "chrome/browser/signin/chrome_signin_helper.h"
30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
31 #include "chrome/browser/signin/signin_error_controller_factory.h" 31 #include "chrome/browser/signin/signin_error_controller_factory.h"
32 #include "chrome/browser/signin/signin_manager_factory.h" 32 #include "chrome/browser/signin/signin_manager_factory.h"
33 #include "chrome/browser/signin/signin_promo.h" 33 #include "chrome/browser/signin/signin_promo.h"
34 #include "chrome/browser/signin/signin_ui_util.h" 34 #include "chrome/browser/signin/signin_ui_util.h"
35 #include "chrome/browser/sync/profile_sync_service_factory.h"
36 #include "chrome/browser/sync/sync_ui_util.h"
35 #include "chrome/browser/ui/browser.h" 37 #include "chrome/browser/ui/browser.h"
36 #include "chrome/browser/ui/browser_commands.h" 38 #include "chrome/browser/ui/browser_commands.h"
37 #include "chrome/browser/ui/browser_list.h" 39 #include "chrome/browser/ui/browser_list.h"
38 #include "chrome/browser/ui/browser_window.h" 40 #include "chrome/browser/ui/browser_window.h"
39 #include "chrome/browser/ui/chrome_pages.h" 41 #include "chrome/browser/ui/chrome_pages.h"
40 #include "chrome/browser/ui/chrome_style.h" 42 #include "chrome/browser/ui/chrome_style.h"
41 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 43 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
42 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 44 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
43 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 45 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
44 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " 46 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h "
45 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" 47 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h"
46 #include "chrome/browser/ui/singleton_tabs.h" 48 #include "chrome/browser/ui/singleton_tabs.h"
47 #include "chrome/browser/ui/user_manager.h" 49 #include "chrome/browser/ui/user_manager.h"
48 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 50 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
49 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 51 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
50 #include "chrome/common/pref_names.h" 52 #include "chrome/common/pref_names.h"
51 #include "chrome/common/url_constants.h" 53 #include "chrome/common/url_constants.h"
52 #include "chrome/grit/chromium_strings.h" 54 #include "chrome/grit/chromium_strings.h"
53 #include "chrome/grit/generated_resources.h" 55 #include "chrome/grit/generated_resources.h"
56 #include "components/browser_sync/browser/profile_sync_service.h"
54 #include "components/prefs/pref_service.h" 57 #include "components/prefs/pref_service.h"
55 #include "components/signin/core/browser/profile_oauth2_token_service.h" 58 #include "components/signin/core/browser/profile_oauth2_token_service.h"
56 #include "components/signin/core/browser/signin_manager.h" 59 #include "components/signin/core/browser/signin_manager.h"
57 #include "components/signin/core/browser/signin_metrics.h" 60 #include "components/signin/core/browser/signin_metrics.h"
58 #include "components/signin/core/common/profile_management_switches.h" 61 #include "components/signin/core/common/profile_management_switches.h"
59 #include "content/public/browser/native_web_keyboard_event.h" 62 #include "content/public/browser/native_web_keyboard_event.h"
60 #include "content/public/browser/notification_service.h" 63 #include "content/public/browser/notification_service.h"
61 #include "content/public/browser/render_widget_host_view.h" 64 #include "content/public/browser/render_widget_host_view.h"
62 #include "content/public/browser/user_metrics.h" 65 #include "content/public/browser/user_metrics.h"
63 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 // triggered by right-clicking the avatar button; in the material design user 927 // triggered by right-clicking the avatar button; in the material design user
925 // menu, this appears as part of the user menu. Returns the yOffset 928 // menu, this appears as part of the user menu. Returns the yOffset
926 // corresponding to after the profile switcher buttons. 929 // corresponding to after the profile switcher buttons.
927 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles 930 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles
928 atYOffset:(CGFloat)yOffset 931 atYOffset:(CGFloat)yOffset
929 inContainer:(NSView*)container; 932 inContainer:(NSView*)container;
930 933
931 // Builds the regular profile chooser view. 934 // Builds the regular profile chooser view.
932 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView 935 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView
933 tutorialView:(NSView*)tutorialView 936 tutorialView:(NSView*)tutorialView
937 syncErrorView:(NSView*)syncErrorView
934 otherProfiles:(NSArray*)otherProfiles 938 otherProfiles:(NSArray*)otherProfiles
935 atYOffset:(CGFloat)yOffset 939 atYOffset:(CGFloat)yOffset
936 inContainer:(NSView*)container 940 inContainer:(NSView*)container
937 showLock:(bool)showLock; 941 showLock:(bool)showLock;
938 942
939 // Builds the profile chooser view. 943 // Builds the profile chooser view.
940 - (NSView*)buildProfileChooserView; 944 - (NSView*)buildProfileChooserView;
941 945
942 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; 946 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item;
943 947
944 // Builds a tutorial card with a title label using |titleMessage|, a content 948 // Builds a tutorial card with a title label using |titleMessage|, a content
945 // label using |contentMessage|, a link using |linkMessage|, and a button using 949 // label using |contentMessage|, a link using |linkMessage|, and a button using
946 // |buttonMessage|. If |stackButton| is YES, places the button above the link. 950 // |buttonMessage|. If |stackButton| is YES, places the button above the link.
947 // Otherwise places both on the same row with the link left aligned and button 951 // Otherwise places both on the same row with the link left aligned and button
948 // right aligned. On click, the link would execute |linkAction|, and the button 952 // right aligned. On click, the link would execute |linkAction|, and the button
949 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. 953 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|.
950 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode 954 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode
951 titleMessage:(NSString*)titleMessage 955 titleMessage:(NSString*)titleMessage
952 contentMessage:(NSString*)contentMessage 956 contentMessage:(NSString*)contentMessage
953 linkMessage:(NSString*)linkMessage 957 linkMessage:(NSString*)linkMessage
954 buttonMessage:(NSString*)buttonMessage 958 buttonMessage:(NSString*)buttonMessage
955 stackButton:(BOOL)stackButton 959 stackButton:(BOOL)stackButton
956 hasCloseButton:(BOOL)hasCloseButton 960 hasCloseButton:(BOOL)hasCloseButton
957 linkAction:(SEL)linkAction 961 linkAction:(SEL)linkAction
958 buttonAction:(SEL)buttonAction; 962 buttonAction:(SEL)buttonAction;
959 963
964 // Builds a header for signin and sync error surfacing on the user menu.
965 - (NSView*)buildSyncErrorViewIfNeeded;
966 - (NSView*)buildSyncErrorViewWithContent:(int)contentStringId
967 buttonStringId:(int)buttonStringId
968 buttonAction:(SEL)buttonAction;
969
960 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if 970 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if
961 // needed. |tutorial_shown| indicates if the tutorial has already been shown in 971 // needed. |tutorial_shown| indicates if the tutorial has already been shown in
962 // the previous active view. |avatar_item| refers to the current profile. 972 // the previous active view. |avatar_item| refers to the current profile.
963 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item; 973 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item;
964 974
965 // Builds a tutorial card to inform the user about right-click user switching if 975 // Builds a tutorial card to inform the user about right-click user switching if
966 // needed. 976 // needed.
967 - (NSView*)buildRightClickTutorialView; 977 - (NSView*)buildRightClickTutorialView;
968 978
969 // Builds a tutorial card to have the user confirm the last Chrome signin, 979 // Builds a tutorial card to have the user confirm the last Chrome signin,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 accountIdToRemove_ = SigninManagerFactory::GetForProfile( 1168 accountIdToRemove_ = SigninManagerFactory::GetForProfile(
1159 browser_->profile())->GetAuthenticatedAccountId(); 1169 browser_->profile())->GetAuthenticatedAccountId();
1160 } else { 1170 } else {
1161 DCHECK(ContainsKey(currentProfileAccounts_, tag)); 1171 DCHECK(ContainsKey(currentProfileAccounts_, tag));
1162 accountIdToRemove_ = currentProfileAccounts_[tag]; 1172 accountIdToRemove_ = currentProfileAccounts_[tag];
1163 } 1173 }
1164 1174
1165 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; 1175 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL];
1166 } 1176 }
1167 1177
1178 - (IBAction)showSignoutView:(id)sender {
1179 chrome::ShowSettingsSubPage(browser_, chrome::kSignOutSubPage);
1180 }
1181
1182 - (IBAction)showSignoutSigninView:(id)sender {
1183 if (ProfileSyncServiceFactory::GetForProfile(browser_->profile()))
1184 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
1185 SigninManagerFactory::GetForProfile(browser_->profile())
1186 ->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS,
1187 signin_metrics::SignoutDelete::IGNORE_METRIC);
1188 [self showSigninUIForMode:profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN];
1189 }
1190
1168 - (IBAction)showAccountReauthenticationView:(id)sender { 1191 - (IBAction)showAccountReauthenticationView:(id)sender {
1169 DCHECK(!isGuestSession_); 1192 DCHECK(!isGuestSession_);
1170 [self showSigninUIForMode:profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH]; 1193 [self showSigninUIForMode:profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH];
1171 } 1194 }
1172 1195
1196 - (IBAction)showUpdateChromeView:(id)sender {
1197 chrome::OpenUpdateChromeDialog(browser_);
1198 }
1199
1200 - (IBAction)showSyncPassphraseSetupView:(id)sender {
1201 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage);
1202 }
1203
1173 - (IBAction)removeAccount:(id)sender { 1204 - (IBAction)removeAccount:(id)sender {
1174 DCHECK(!accountIdToRemove_.empty()); 1205 DCHECK(!accountIdToRemove_.empty());
1175 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()) 1206 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())
1176 ->RevokeCredentials(accountIdToRemove_); 1207 ->RevokeCredentials(accountIdToRemove_);
1177 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT]; 1208 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT];
1178 accountIdToRemove_.clear(); 1209 accountIdToRemove_.clear();
1179 1210
1180 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 1211 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
1181 } 1212 }
1182 1213
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 if (!switches::IsMaterialDesignUserMenu()) 1428 if (!switches::IsMaterialDesignUserMenu())
1398 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; 1429 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1399 } 1430 }
1400 1431
1401 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1432 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1402 return yOffset; 1433 return yOffset;
1403 } 1434 }
1404 1435
1405 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView 1436 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView
1406 tutorialView:(NSView*)tutorialView 1437 tutorialView:(NSView*)tutorialView
1438 syncErrorView:(NSView*)syncErrorView
1407 otherProfiles:(NSArray*)otherProfiles 1439 otherProfiles:(NSArray*)otherProfiles
1408 atYOffset:(CGFloat)yOffset 1440 atYOffset:(CGFloat)yOffset
1409 inContainer:(NSView*)container 1441 inContainer:(NSView*)container
1410 showLock:(bool)showLock { 1442 showLock:(bool)showLock {
1411 if (switches::IsMaterialDesignUserMenu()) 1443 if (switches::IsMaterialDesignUserMenu())
1412 yOffset += kRelatedControllVerticalSpacing; 1444 yOffset += kRelatedControllVerticalSpacing;
1413 1445
1414 // Option buttons. 1446 // Option buttons.
1415 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); 1447 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0);
1416 NSView* optionsView = 1448 NSView* optionsView =
1417 switches::IsMaterialDesignUserMenu() 1449 switches::IsMaterialDesignUserMenu()
1418 ? [self createMaterialDesignOptionsViewWithFrame:rect 1450 ? [self createMaterialDesignOptionsViewWithFrame:rect
1419 showLock:showLock] 1451 showLock:showLock]
1420 : [self createOptionsViewWithRect:rect showLock:showLock]; 1452 : [self createOptionsViewWithRect:rect showLock:showLock];
(...skipping 23 matching lines...) Expand all
1444 [container addSubview:disclaimerContainer]; 1476 [container addSubview:disclaimerContainer];
1445 yOffset = NSMaxY([disclaimerContainer frame]); 1477 yOffset = NSMaxY([disclaimerContainer frame]);
1446 1478
1447 if (!switches::IsMaterialDesignUserMenu()) { 1479 if (!switches::IsMaterialDesignUserMenu()) {
1448 yOffset += kSmallVerticalSpacing; 1480 yOffset += kSmallVerticalSpacing;
1449 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; 1481 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1450 } 1482 }
1451 } 1483 }
1452 1484
1453 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { 1485 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
1454 NSView* currentProfileAccountsView = [self 1486 const AvatarMenu::Item& item =
1455 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, 1487 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex());
1456 GetFixedMenuWidth(), 0)]; 1488 if (item.signed_in) {
1457 [container addSubview:currentProfileAccountsView]; 1489 NSView* currentProfileAccountsView = [self
1458 yOffset = NSMaxY([currentProfileAccountsView frame]); 1490 createCurrentProfileAccountsView:NSMakeRect(0, yOffset,
1491 GetFixedMenuWidth(), 0)];
1492 [container addSubview:currentProfileAccountsView];
1493 yOffset = NSMaxY([currentProfileAccountsView frame]);
1459 1494
1460 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; 1495 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1496 } else {
1497 // This is the case when the user selects the sign out option in the user
1498 // menu upon encountering unrecoverable errors. Afterwards, the profile
1499 // chooser view is shown instead of the account management view.
1500 viewMode_ = profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
1501 }
1461 } 1502 }
1462 1503
1463 // Active profile card. 1504 // Active profile card.
1464 if (currentProfileView) { 1505 if (currentProfileView) {
1465 const CGFloat verticalSpacing = switches::IsMaterialDesignUserMenu() 1506 const CGFloat verticalSpacing = switches::IsMaterialDesignUserMenu()
1466 ? kRelatedControllVerticalSpacing 1507 ? kRelatedControllVerticalSpacing
1467 : kVerticalSpacing; 1508 : kVerticalSpacing;
1468 yOffset += verticalSpacing; 1509 yOffset += verticalSpacing;
1469 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1510 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1470 [container addSubview:currentProfileView]; 1511 [container addSubview:currentProfileView];
1471 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; 1512 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing;
1472 } 1513 }
1473 1514
1515 if (syncErrorView) {
1516 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1517 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)];
1518 [container addSubview:syncErrorView];
1519 yOffset = NSMaxY([syncErrorView frame]);
1520 }
1521
1474 if (tutorialView) { 1522 if (tutorialView) {
1475 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; 1523 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)];
1476 [container addSubview:tutorialView]; 1524 [container addSubview:tutorialView];
1477 yOffset = NSMaxY([tutorialView frame]); 1525 yOffset = NSMaxY([tutorialView frame]);
1478 //TODO(mlerman): update UMA stats for the new tutorials. 1526 //TODO(mlerman): update UMA stats for the new tutorials.
1479 } else { 1527 } else {
1480 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; 1528 tutorialMode_ = profiles::TUTORIAL_MODE_NONE;
1481 } 1529 }
1482 1530
1483 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1531 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1484 } 1532 }
1485 1533
1486 - (NSView*)buildProfileChooserView { 1534 - (NSView*)buildProfileChooserView {
1487 base::scoped_nsobject<NSView> container( 1535 base::scoped_nsobject<NSView> container(
1488 [[NSView alloc] initWithFrame:NSZeroRect]); 1536 [[NSView alloc] initWithFrame:NSZeroRect]);
1489 1537
1490 NSView* tutorialView = nil; 1538 NSView* tutorialView = nil;
1539 NSView* syncErrorView = nil;
1491 NSView* currentProfileView = nil; 1540 NSView* currentProfileView = nil;
1492 base::scoped_nsobject<NSMutableArray> otherProfiles( 1541 base::scoped_nsobject<NSMutableArray> otherProfiles(
1493 [[NSMutableArray alloc] init]); 1542 [[NSMutableArray alloc] init]);
1494 // Local and guest profiles cannot lock their profile. 1543 // Local and guest profiles cannot lock their profile.
1495 bool showLock = false; 1544 bool showLock = false;
1496 bool isFastProfileChooser = 1545 bool isFastProfileChooser =
1497 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 1546 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
1498 if (isFastProfileChooser) { 1547 if (isFastProfileChooser) {
1499 // The user is using right-click switching, no need to tell them about it. 1548 // The user is using right-click switching, no need to tell them about it.
1500 PrefService* localState = g_browser_process->local_state(); 1549 PrefService* localState = g_browser_process->local_state();
1501 localState->SetBoolean( 1550 localState->SetBoolean(
1502 prefs::kProfileAvatarRightClickTutorialDismissed, true); 1551 prefs::kProfileAvatarRightClickTutorialDismissed, true);
1503 } 1552 }
1504 1553
1505 // Loop over the profiles in reverse, so that they are sorted by their 1554 // Loop over the profiles in reverse, so that they are sorted by their
1506 // y-coordinate, and separate them into active and "other" profiles. 1555 // y-coordinate, and separate them into active and "other" profiles.
1507 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { 1556 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) {
1508 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); 1557 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i);
1509 if (item.active) { 1558 if (item.active) {
1510 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 1559 if (switches::IsMaterialDesignUserMenu()) {
1560 syncErrorView = [self buildSyncErrorViewIfNeeded];
1561 } else if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) {
1511 tutorialView = [self buildTutorialViewIfNeededForItem:item]; 1562 tutorialView = [self buildTutorialViewIfNeededForItem:item];
1512 } 1563 }
1513 currentProfileView = 1564 currentProfileView =
1514 switches::IsMaterialDesignUserMenu() 1565 switches::IsMaterialDesignUserMenu()
1515 ? [self createMaterialDesignCurrentProfileView:item] 1566 ? [self createMaterialDesignCurrentProfileView:item]
1516 : [self createCurrentProfileView:item]; 1567 : [self createCurrentProfileView:item];
1517 showLock = item.signed_in && 1568 showLock = item.signed_in &&
1518 profiles::IsLockAvailable(browser_->profile()); 1569 profiles::IsLockAvailable(browser_->profile());
1519 } else { 1570 } else {
1520 [otherProfiles addObject:[self createOtherProfileView:i]]; 1571 [otherProfiles addObject:[self createOtherProfileView:i]];
1521 } 1572 }
1522 } 1573 }
1523 if (!currentProfileView) // Guest windows don't have an active profile. 1574 if (!currentProfileView) // Guest windows don't have an active profile.
1524 currentProfileView = [self createGuestProfileView]; 1575 currentProfileView = [self createGuestProfileView];
1525 1576
1526 // |yOffset| is the next position at which to draw in |container| 1577 // |yOffset| is the next position at which to draw in |container|
1527 // coordinates. Add a pixel offset so that the bottom option buttons don't 1578 // coordinates. Add a pixel offset so that the bottom option buttons don't
1528 // overlap the bubble's rounded corners. 1579 // overlap the bubble's rounded corners.
1529 CGFloat yOffset = 1; 1580 CGFloat yOffset = 1;
1530 1581
1531 if (isFastProfileChooser) { 1582 if (isFastProfileChooser) {
1532 if (!switches::IsMaterialDesignUserMenu()) { 1583 if (!switches::IsMaterialDesignUserMenu()) {
1533 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() 1584 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get()
1534 atYOffset:yOffset 1585 atYOffset:yOffset
1535 inContainer:container]; 1586 inContainer:container];
1536 } 1587 }
1537 } else { 1588 } else {
1538 [self buildProfileChooserViewWithProfileView:currentProfileView 1589 [self buildProfileChooserViewWithProfileView:currentProfileView
1539 tutorialView:tutorialView 1590 tutorialView:tutorialView
1591 syncErrorView:syncErrorView
1540 otherProfiles:otherProfiles.get() 1592 otherProfiles:otherProfiles.get()
1541 atYOffset:yOffset 1593 atYOffset:yOffset
1542 inContainer:container 1594 inContainer:container
1543 showLock:showLock]; 1595 showLock:showLock];
1544 } 1596 }
1545 1597
1546 return container.autorelease(); 1598 return container.autorelease();
1547 } 1599 }
1548 1600
1549 - (NSView*)buildSigninConfirmationView { 1601 - (NSView*)buildSigninConfirmationView {
1550 ProfileMetrics::LogProfileNewAvatarMenuSignin( 1602 ProfileMetrics::LogProfileNewAvatarMenuSignin(
1551 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); 1603 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW);
1552 1604
1553 NSString* titleMessage = l10n_util::GetNSString( 1605 NSString* titleMessage = l10n_util::GetNSString(
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 1848
1797 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; 1849 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel];
1798 [container addSubview:titleLabel]; 1850 [container addSubview:titleLabel];
1799 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; 1851 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing;
1800 1852
1801 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1853 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1802 [container setFrameOrigin:NSZeroPoint]; 1854 [container setFrameOrigin:NSZeroPoint];
1803 return container.autorelease(); 1855 return container.autorelease();
1804 } 1856 }
1805 1857
1858 - (NSView*)buildSyncErrorViewIfNeeded {
1859 int contentStringId, buttonStringId;
1860 SEL buttonAction;
1861 sync_ui_util::AvatarSyncErrorType error =
1862 sync_ui_util::GetMessagesForAvatarSyncError(
1863 browser_->profile(), &contentStringId, &buttonStringId);
1864 switch (error) {
1865 case sync_ui_util::MANAGED_USER_UNRECOVERABLE_ERROR:
1866 buttonAction = @selector(showSignoutView:);
1867 break;
1868 case sync_ui_util::UNRECOVERABLE_ERROR:
1869 buttonAction = @selector(showSignoutSigninView:);
1870 break;
1871 case sync_ui_util::AUTH_ERROR:
1872 buttonAction = @selector(showAccountReauthenticationView:);
1873 break;
1874 case sync_ui_util::UPGRADE_CLIENT_ERROR:
1875 buttonAction = @selector(showUpdateChromeView:);
1876 break;
1877 case sync_ui_util::PASSPHRASE_ERROR:
1878 buttonAction = @selector(showSyncPassphraseSetupView:);
1879 break;
1880 case sync_ui_util::NO_SYNC_ERROR:
1881 return nil;
1882 default:
1883 NOTREACHED();
1884 }
1885 return [self buildSyncErrorViewWithContent:contentStringId
1886 buttonStringId:buttonStringId
1887 buttonAction:buttonAction];
1888 }
1889
1890 - (NSView*)buildSyncErrorViewWithContent:(int)contentStringId
1891 buttonStringId:(int)buttonStringId
1892 buttonAction:(SEL)buttonAction {
1893 base::scoped_nsobject<NSView> container(
1894 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, GetFixedMenuWidth(), 0)]);
1895 CGFloat iconSize = 20.0;
1896 CGFloat xOffset = kHorizontalSpacing + iconSize + 12.0;
1897 CGFloat availableWidth = GetFixedMenuWidth() - xOffset - kHorizontalSpacing;
1898 CGFloat yOffset = 20.0;
1899
1900 // Adds an action button for resolving the error at the bottom.
1901 base::scoped_nsobject<NSButton> resolveErrorButton(
1902 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]);
1903 [resolveErrorButton setTitle:l10n_util::GetNSString(buttonStringId)];
1904 [resolveErrorButton setTarget:self];
1905 [resolveErrorButton setAction:buttonAction];
1906 [resolveErrorButton setAlignment:NSCenterTextAlignment];
1907 [resolveErrorButton sizeToFit];
1908 [resolveErrorButton setFrameOrigin:NSMakePoint(xOffset, yOffset)];
1909 [container addSubview:resolveErrorButton];
1910 yOffset = NSMaxY([resolveErrorButton frame]) + kVerticalSpacing;
1911
1912 // Adds the error message content.
1913 NSTextField* contentLabel =
1914 BuildLabel(l10n_util::GetNSString(contentStringId),
1915 NSMakePoint(xOffset, yOffset), nil);
1916 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)];
1917 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel];
1918 [container addSubview:contentLabel];
1919 yOffset = NSMaxY([contentLabel frame]) + 4;
1920
1921 // Adds the title for the error card.
1922 NSTextField* titleLabel =
1923 BuildLabel(l10n_util::GetNSString(IDS_SYNC_ERROR_USER_MENU_TITLE),
1924 NSMakePoint(xOffset, yOffset),
1925 skia::SkColorToCalibratedNSColor(gfx::kGoogleRed700));
1926 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)];
1927 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel];
1928 [container addSubview:titleLabel];
1929 yOffset = NSMaxY([titleLabel frame]);
1930
1931 // Adds the sync problem icon.
1932 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc]
1933 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize,
1934 iconSize)]);
1935 [syncProblemIcon setImage:NSImageFromImageSkia(gfx::CreateVectorIcon(
1936 gfx::VectorIconId::SYNC_PROBLEM, iconSize,
1937 gfx::kGoogleRed700))];
1938 [container addSubview:syncProblemIcon];
1939
1940 [container
1941 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)];
1942 return container.autorelease();
1943 }
1944
1806 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { 1945 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item {
1807 base::scoped_nsobject<NSView> container([[NSView alloc] 1946 base::scoped_nsobject<NSView> container([[NSView alloc]
1808 initWithFrame:NSZeroRect]); 1947 initWithFrame:NSZeroRect]);
1809 1948
1810 CGFloat xOffset = kHorizontalSpacing; 1949 CGFloat xOffset = kHorizontalSpacing;
1811 CGFloat yOffset = 0; 1950 CGFloat yOffset = 0;
1812 CGFloat availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing; 1951 CGFloat availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing;
1813 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing; 1952 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing;
1814 1953
1815 // Profile options. This can be a link to the accounts view, the profile's 1954 // Profile options. This can be a link to the accounts view, the profile's
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 } 2893 }
2755 2894
2756 - (bool)shouldShowGoIncognito { 2895 - (bool)shouldShowGoIncognito {
2757 bool incognitoAvailable = 2896 bool incognitoAvailable =
2758 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2897 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2759 IncognitoModePrefs::DISABLED; 2898 IncognitoModePrefs::DISABLED;
2760 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2899 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2761 } 2900 }
2762 2901
2763 @end 2902 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698