Chromium Code Reviews| 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 "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 Loading... | |
| 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" | |
| 35 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/browser_commands.h" | 37 #include "chrome/browser/ui/browser_commands.h" |
| 37 #include "chrome/browser/ui/browser_list.h" | 38 #include "chrome/browser/ui/browser_list.h" |
| 38 #include "chrome/browser/ui/browser_window.h" | 39 #include "chrome/browser/ui/browser_window.h" |
| 39 #include "chrome/browser/ui/chrome_pages.h" | 40 #include "chrome/browser/ui/chrome_pages.h" |
| 40 #include "chrome/browser/ui/chrome_style.h" | 41 #include "chrome/browser/ui/chrome_style.h" |
| 41 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 42 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 42 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 43 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 43 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 44 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 44 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " | 45 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " |
| 45 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" | 46 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" |
| 46 #include "chrome/browser/ui/singleton_tabs.h" | 47 #include "chrome/browser/ui/singleton_tabs.h" |
| 47 #include "chrome/browser/ui/user_manager.h" | 48 #include "chrome/browser/ui/user_manager.h" |
| 48 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 49 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 49 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 50 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 50 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
| 51 #include "chrome/common/url_constants.h" | 52 #include "chrome/common/url_constants.h" |
| 52 #include "chrome/grit/chromium_strings.h" | 53 #include "chrome/grit/chromium_strings.h" |
| 53 #include "chrome/grit/generated_resources.h" | 54 #include "chrome/grit/generated_resources.h" |
| 55 #include "components/browser_sync/browser/profile_sync_service.h" | |
| 54 #include "components/prefs/pref_service.h" | 56 #include "components/prefs/pref_service.h" |
| 55 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 57 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 56 #include "components/signin/core/browser/signin_manager.h" | 58 #include "components/signin/core/browser/signin_manager.h" |
| 57 #include "components/signin/core/browser/signin_metrics.h" | 59 #include "components/signin/core/browser/signin_metrics.h" |
| 58 #include "components/signin/core/common/profile_management_switches.h" | 60 #include "components/signin/core/common/profile_management_switches.h" |
| 61 #include "components/sync_driver/sync_error_controller.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" |
| 64 #include "google_apis/gaia/oauth2_token_service.h" | 67 #include "google_apis/gaia/oauth2_token_service.h" |
| 65 #include "grit/theme_resources.h" | 68 #include "grit/theme_resources.h" |
| 66 #include "skia/ext/skia_utils_mac.h" | 69 #include "skia/ext/skia_utils_mac.h" |
| 67 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | 70 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
| 68 #import "ui/base/cocoa/cocoa_base_utils.h" | 71 #import "ui/base/cocoa/cocoa_base_utils.h" |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 22 matching lines...) Expand all Loading... | |
| 1443 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; | 1475 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 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 |
| 1485 const AvatarMenu::Item& item = | |
| 1486 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | |
| 1453 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | 1487 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
| 1454 NSView* currentProfileAccountsView = [self | 1488 if (item.signed_in) { |
| 1455 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, | 1489 NSView* currentProfileAccountsView = [self |
| 1456 GetFixedMenuWidth(), 0)]; | 1490 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, |
| 1457 [container addSubview:currentProfileAccountsView]; | 1491 GetFixedMenuWidth(), 0)]; |
| 1458 yOffset = NSMaxY([currentProfileAccountsView frame]); | 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 Loading... | |
| 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 ProfileSyncService* service = | |
| 1860 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); | |
| 1861 | |
| 1862 // The order or priority is going to be: 1. Unrecoverable errors. | |
| 1863 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. | |
| 1864 if (service && service->HasUnrecoverableError()) { | |
|
groby-ooo-7-16
2016/07/22 23:53:16
It seems a ton of this logic is shared with the Vi
| |
| 1865 // An unrecoverable error is sometimes accompanied by an actionable error. | |
| 1866 // If an actionable error is not set to be UPGRADE_CLIENT, then show a | |
| 1867 // generic unrecoverable error message. | |
| 1868 ProfileSyncService::Status status; | |
| 1869 service->QueryDetailedSyncStatus(&status); | |
| 1870 if (status.sync_protocol_error.action != syncer::UPGRADE_CLIENT) { | |
| 1871 // Display different messages and buttons for managed accounts. | |
| 1872 if (SigninManagerFactory::GetForProfile(browser_->profile()) | |
| 1873 ->IsSignoutProhibited()) { | |
| 1874 // For a managed user, the user is directed to the signout | |
| 1875 // confirmation dialogue in the settings page. | |
| 1876 return [self buildSyncErrorViewWithContent: | |
| 1877 IDS_SYNC_ERROR_USER_MENU_SIGNOUT_MESSAGE | |
| 1878 buttonStringId: | |
| 1879 IDS_SYNC_ERROR_USER_MENU_SIGNOUT_BUTTON | |
| 1880 buttonAction:@selector(showSignoutView:)]; | |
| 1881 } | |
| 1882 // For a non-managed user, we sign out on the user's behalf and prompt | |
| 1883 // the user to sign in again. | |
| 1884 return [self | |
| 1885 buildSyncErrorViewWithContent: | |
| 1886 IDS_SYNC_ERROR_USER_MENU_SIGNIN_AGAIN_MESSAGE | |
| 1887 buttonStringId: | |
| 1888 IDS_SYNC_ERROR_USER_MENU_SIGNIN_AGAIN_BUTTON | |
| 1889 buttonAction:@selector(showSignoutSigninView:)]; | |
| 1890 } | |
| 1891 } | |
| 1892 | |
| 1893 // Check for an auth error. | |
| 1894 if (HasAuthError(browser_->profile())) { | |
| 1895 return [self | |
| 1896 buildSyncErrorViewWithContent:IDS_SYNC_ERROR_USER_MENU_SIGNIN_MESSAGE | |
| 1897 buttonStringId:IDS_SYNC_ERROR_USER_MENU_SIGNIN_BUTTON | |
| 1898 buttonAction:@selector( | |
| 1899 showAccountReauthenticationView:)]; | |
| 1900 } | |
| 1901 | |
| 1902 // Check for sync errors if the sync service is enabled. | |
| 1903 if (service) { | |
| 1904 // Check for an actionable UPGRADE_CLIENT error. | |
| 1905 ProfileSyncService::Status status; | |
| 1906 service->QueryDetailedSyncStatus(&status); | |
| 1907 if (status.sync_protocol_error.action == syncer::UPGRADE_CLIENT) { | |
| 1908 return [self | |
| 1909 buildSyncErrorViewWithContent:IDS_SYNC_ERROR_USER_MENU_UPGRADE_MESSAGE | |
| 1910 buttonStringId:IDS_SYNC_ERROR_USER_MENU_UPGRADE_BUTTON | |
| 1911 buttonAction:@selector(showUpdateChromeView:)]; | |
| 1912 } | |
| 1913 | |
| 1914 // Check for a sync passphrase error. | |
| 1915 SyncErrorController* sync_error_controller = | |
| 1916 service->sync_error_controller(); | |
| 1917 if (sync_error_controller && sync_error_controller->HasError()) { | |
| 1918 return [self | |
| 1919 buildSyncErrorViewWithContent: | |
| 1920 IDS_SYNC_ERROR_USER_MENU_PASSPHRASE_MESSAGE | |
| 1921 buttonStringId: | |
| 1922 IDS_SYNC_ERROR_USER_MENU_PASSPHRASE_BUTTON | |
| 1923 buttonAction:@selector( | |
| 1924 showSyncPassphraseSetupView:)]; | |
| 1925 } | |
| 1926 } | |
| 1927 | |
| 1928 // There is no error. | |
| 1929 return nil; | |
| 1930 } | |
| 1931 | |
| 1932 - (NSView*)buildSyncErrorViewWithContent:(int)contentStringId | |
| 1933 buttonStringId:(int)buttonStringId | |
| 1934 buttonAction:(SEL)buttonAction { | |
| 1935 base::scoped_nsobject<NSView> container( | |
| 1936 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, GetFixedMenuWidth(), 0)]); | |
| 1937 CGFloat iconSize = 20.0; | |
| 1938 CGFloat xOffset = kHorizontalSpacing + iconSize + 12.0; | |
| 1939 CGFloat availableWidth = GetFixedMenuWidth() - xOffset - kHorizontalSpacing; | |
| 1940 CGFloat yOffset = 20.0; | |
| 1941 | |
| 1942 // Adds an action button for resolving the error at the bottom. | |
| 1943 base::scoped_nsobject<NSButton> resolveErrorButton( | |
| 1944 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); | |
| 1945 [resolveErrorButton setTitle:l10n_util::GetNSString(buttonStringId)]; | |
| 1946 [resolveErrorButton setTarget:self]; | |
| 1947 [resolveErrorButton setAction:buttonAction]; | |
| 1948 [resolveErrorButton setAlignment:NSCenterTextAlignment]; | |
| 1949 [resolveErrorButton sizeToFit]; | |
| 1950 [resolveErrorButton setFrameOrigin:NSMakePoint(xOffset, yOffset)]; | |
| 1951 [container addSubview:resolveErrorButton]; | |
| 1952 yOffset = NSMaxY([resolveErrorButton frame]) + kVerticalSpacing; | |
| 1953 | |
| 1954 // Adds the error message content. | |
| 1955 NSTextField* contentLabel = | |
| 1956 BuildLabel(l10n_util::GetNSString(contentStringId), | |
| 1957 NSMakePoint(xOffset, yOffset), nil); | |
| 1958 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | |
| 1959 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; | |
| 1960 [container addSubview:contentLabel]; | |
| 1961 yOffset = NSMaxY([contentLabel frame]) + 4; | |
| 1962 | |
| 1963 // Adds the title for the error card. | |
| 1964 NSTextField* titleLabel = | |
| 1965 BuildLabel(l10n_util::GetNSString(IDS_SYNC_ERROR_USER_MENU_TITLE), | |
| 1966 NSMakePoint(xOffset, yOffset), | |
| 1967 skia::SkColorToCalibratedNSColor(gfx::kGoogleRed700)); | |
| 1968 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | |
| 1969 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; | |
| 1970 [container addSubview:titleLabel]; | |
| 1971 yOffset = NSMaxY([titleLabel frame]); | |
| 1972 | |
| 1973 // Adds the sync problem icon. | |
| 1974 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc] | |
| 1975 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize, | |
| 1976 iconSize)]); | |
| 1977 [syncProblemIcon setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 1978 gfx::VectorIconId::SYNC_PROBLEM, iconSize, | |
| 1979 gfx::kGoogleRed700))]; | |
| 1980 [container addSubview:syncProblemIcon]; | |
| 1981 | |
| 1982 [container | |
| 1983 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)]; | |
| 1984 return container.autorelease(); | |
| 1985 } | |
| 1986 | |
| 1806 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { | 1987 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { |
| 1807 base::scoped_nsobject<NSView> container([[NSView alloc] | 1988 base::scoped_nsobject<NSView> container([[NSView alloc] |
| 1808 initWithFrame:NSZeroRect]); | 1989 initWithFrame:NSZeroRect]); |
| 1809 | 1990 |
| 1810 CGFloat xOffset = kHorizontalSpacing; | 1991 CGFloat xOffset = kHorizontalSpacing; |
| 1811 CGFloat yOffset = 0; | 1992 CGFloat yOffset = 0; |
| 1812 CGFloat availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing; | 1993 CGFloat availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing; |
| 1813 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing; | 1994 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing; |
| 1814 | 1995 |
| 1815 // Profile options. This can be a link to the accounts view, the profile's | 1996 // 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 Loading... | |
| 2754 } | 2935 } |
| 2755 | 2936 |
| 2756 - (bool)shouldShowGoIncognito { | 2937 - (bool)shouldShowGoIncognito { |
| 2757 bool incognitoAvailable = | 2938 bool incognitoAvailable = |
| 2758 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2939 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2759 IncognitoModePrefs::DISABLED; | 2940 IncognitoModePrefs::DISABLED; |
| 2760 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2941 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2761 } | 2942 } |
| 2762 | 2943 |
| 2763 @end | 2944 @end |
| OLD | NEW |