| 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 #import <Carbon/Carbon.h> // kVK_Return. | 6 #import <Carbon/Carbon.h> // kVK_Return. |
| 7 | 7 |
| 8 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 8 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 9 | 9 |
| 10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 - (BOOL)canBecomeKeyView { | 871 - (BOOL)canBecomeKeyView { |
| 872 return NO; | 872 return NO; |
| 873 } | 873 } |
| 874 | 874 |
| 875 @end | 875 @end |
| 876 | 876 |
| 877 @interface ProfileChooserController () | 877 @interface ProfileChooserController () |
| 878 // Builds the profile chooser view. | 878 // Builds the profile chooser view. |
| 879 - (NSView*)buildProfileChooserView; | 879 - (NSView*)buildProfileChooserView; |
| 880 | 880 |
| 881 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; |
| 882 |
| 881 // Builds a tutorial card with a title label using |titleMessage|, a content | 883 // Builds a tutorial card with a title label using |titleMessage|, a content |
| 882 // label using |contentMessage|, a link using |linkMessage|, and a button using | 884 // label using |contentMessage|, a link using |linkMessage|, and a button using |
| 883 // |buttonMessage|. If |stackButton| is YES, places the button above the link. | 885 // |buttonMessage|. If |stackButton| is YES, places the button above the link. |
| 884 // Otherwise places both on the same row with the link left aligned and button | 886 // Otherwise places both on the same row with the link left aligned and button |
| 885 // right aligned. On click, the link would execute |linkAction|, and the button | 887 // right aligned. On click, the link would execute |linkAction|, and the button |
| 886 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. | 888 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. |
| 887 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 889 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
| 888 titleMessage:(NSString*)titleMessage | 890 titleMessage:(NSString*)titleMessage |
| 889 contentMessage:(NSString*)contentMessage | 891 contentMessage:(NSString*)contentMessage |
| 890 linkMessage:(NSString*)linkMessage | 892 linkMessage:(NSString*)linkMessage |
| 891 buttonMessage:(NSString*)buttonMessage | 893 buttonMessage:(NSString*)buttonMessage |
| 892 stackButton:(BOOL)stackButton | 894 stackButton:(BOOL)stackButton |
| 893 hasCloseButton:(BOOL)hasCloseButton | 895 hasCloseButton:(BOOL)hasCloseButton |
| 894 linkAction:(SEL)linkAction | 896 linkAction:(SEL)linkAction |
| 895 buttonAction:(SEL)buttonAction; | 897 buttonAction:(SEL)buttonAction; |
| 896 | 898 |
| 897 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if | 899 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if |
| 898 // needed. |tutorial_shown| indicates if the tutorial has already been shown in | 900 // needed. |tutorial_shown| indicates if the tutorial has already been shown in |
| 899 // the previous active view. |avatar_item| refers to the current profile. | 901 // the previous active view. |avatar_item| refers to the current profile. |
| 900 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded; | 902 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item; |
| 903 |
| 904 // Builds a tutorial card to inform the user about right-click user switching if |
| 905 // needed. |
| 906 - (NSView*)buildRightClickTutorialView; |
| 901 | 907 |
| 902 // Builds a tutorial card to have the user confirm the last Chrome signin, | 908 // Builds a tutorial card to have the user confirm the last Chrome signin, |
| 903 // Chrome sync will be delayed until the user either dismisses the tutorial, or | 909 // Chrome sync will be delayed until the user either dismisses the tutorial, or |
| 904 // configures sync through the "Settings" link. | 910 // configures sync through the "Settings" link. |
| 905 - (NSView*)buildSigninConfirmationView; | 911 - (NSView*)buildSigninConfirmationView; |
| 906 | 912 |
| 907 // Builds a tutorial card to show the last signin error. | 913 // Builds a tutorial card to show the last signin error. |
| 908 - (NSView*)buildSigninErrorView; | 914 - (NSView*)buildSigninErrorView; |
| 909 | 915 |
| 910 // Creates the main profile card for the profile |item| at the top of | 916 // Creates the main profile card for the profile |item| at the top of |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 } | 1128 } |
| 1123 | 1129 |
| 1124 - (IBAction)dismissTutorial:(id)sender { | 1130 - (IBAction)dismissTutorial:(id)sender { |
| 1125 // Never shows the upgrade tutorial again if manually closed. | 1131 // Never shows the upgrade tutorial again if manually closed. |
| 1126 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | 1132 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
| 1127 browser_->profile()->GetPrefs()->SetInteger( | 1133 browser_->profile()->GetPrefs()->SetInteger( |
| 1128 prefs::kProfileAvatarTutorialShown, | 1134 prefs::kProfileAvatarTutorialShown, |
| 1129 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); | 1135 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); |
| 1130 } | 1136 } |
| 1131 | 1137 |
| 1138 if(tutorialMode_ == profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING) { |
| 1139 PrefService* localState = g_browser_process->local_state(); |
| 1140 localState->SetBoolean( |
| 1141 prefs::kProfileAvatarRightClickTutorialDismissed, true); |
| 1142 } |
| 1143 |
| 1132 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | 1144 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; |
| 1133 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 1145 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
| 1134 } | 1146 } |
| 1135 | 1147 |
| 1136 - (void)windowWillClose:(NSNotification*)notification { | 1148 - (void)windowWillClose:(NSNotification*)notification { |
| 1137 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { | 1149 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { |
| 1138 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 1150 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
| 1139 SyncConfirmationUIClosed(false); | 1151 SyncConfirmationUIClosed(false); |
| 1140 } | 1152 } |
| 1141 | 1153 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 [[NSView alloc] initWithFrame:NSZeroRect]); | 1275 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 1264 | 1276 |
| 1265 NSView* tutorialView = nil; | 1277 NSView* tutorialView = nil; |
| 1266 NSView* currentProfileView = nil; | 1278 NSView* currentProfileView = nil; |
| 1267 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1279 base::scoped_nsobject<NSMutableArray> otherProfiles( |
| 1268 [[NSMutableArray alloc] init]); | 1280 [[NSMutableArray alloc] init]); |
| 1269 // Local and guest profiles cannot lock their profile. | 1281 // Local and guest profiles cannot lock their profile. |
| 1270 bool displayLock = false; | 1282 bool displayLock = false; |
| 1271 bool isFastProfileChooser = | 1283 bool isFastProfileChooser = |
| 1272 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 1284 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 1285 if (isFastProfileChooser) { |
| 1286 // The user is using right-click switching, no need to tell them about it. |
| 1287 PrefService* localState = g_browser_process->local_state(); |
| 1288 localState->SetBoolean( |
| 1289 prefs::kProfileAvatarRightClickTutorialDismissed, true); |
| 1290 } |
| 1273 | 1291 |
| 1274 // Loop over the profiles in reverse, so that they are sorted by their | 1292 // Loop over the profiles in reverse, so that they are sorted by their |
| 1275 // y-coordinate, and separate them into active and "other" profiles. | 1293 // y-coordinate, and separate them into active and "other" profiles. |
| 1276 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { | 1294 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { |
| 1277 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); | 1295 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); |
| 1278 if (item.active) { | 1296 if (item.active) { |
| 1279 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 1297 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { |
| 1280 switch (tutorialMode_) { | 1298 tutorialView = [self buildTutorialViewIfNeededForItem:item]; |
| 1281 case profiles::TUTORIAL_MODE_NONE: | |
| 1282 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: | |
| 1283 tutorialView = | |
| 1284 [self buildWelcomeUpgradeTutorialViewIfNeeded]; | |
| 1285 break; | |
| 1286 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: | |
| 1287 tutorialView = [self buildSigninConfirmationView]; | |
| 1288 break; | |
| 1289 case profiles::TUTORIAL_MODE_SHOW_ERROR: | |
| 1290 tutorialView = [self buildSigninErrorView]; | |
| 1291 } | |
| 1292 } | 1299 } |
| 1293 currentProfileView = [self createCurrentProfileView:item]; | 1300 currentProfileView = [self createCurrentProfileView:item]; |
| 1294 displayLock = item.signed_in && | 1301 displayLock = item.signed_in && |
| 1295 profiles::IsLockAvailable(browser_->profile()); | 1302 profiles::IsLockAvailable(browser_->profile()); |
| 1296 } else { | 1303 } else { |
| 1297 [otherProfiles addObject:[self createOtherProfileView:i]]; | 1304 [otherProfiles addObject:[self createOtherProfileView:i]]; |
| 1298 } | 1305 } |
| 1299 } | 1306 } |
| 1300 if (!currentProfileView) // Guest windows don't have an active profile. | 1307 if (!currentProfileView) // Guest windows don't have an active profile. |
| 1301 currentProfileView = [self createGuestProfileView]; | 1308 currentProfileView = [self createGuestProfileView]; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 titleMessage:titleMessage | 1425 titleMessage:titleMessage |
| 1419 contentMessage:contentMessage | 1426 contentMessage:contentMessage |
| 1420 linkMessage:linkMessage | 1427 linkMessage:linkMessage |
| 1421 buttonMessage:nil | 1428 buttonMessage:nil |
| 1422 stackButton:NO | 1429 stackButton:NO |
| 1423 hasCloseButton:YES | 1430 hasCloseButton:YES |
| 1424 linkAction:@selector(showLearnMorePage:) | 1431 linkAction:@selector(showLearnMorePage:) |
| 1425 buttonAction:nil]; | 1432 buttonAction:nil]; |
| 1426 } | 1433 } |
| 1427 | 1434 |
| 1428 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded { | 1435 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item { |
| 1429 Profile* profile = browser_->profile(); | |
| 1430 const AvatarMenu::Item& avatarItem = | |
| 1431 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | |
| 1432 | |
| 1433 const int showCount = profile->GetPrefs()->GetInteger( | |
| 1434 prefs::kProfileAvatarTutorialShown); | |
| 1435 // Do not show the tutorial if user has dismissed it. | |
| 1436 if (showCount > signin_ui_util::kUpgradeWelcomeTutorialShowMax) | |
| 1437 return nil; | |
| 1438 | |
| 1439 if (tutorialMode_ != profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | |
| 1440 if (showCount == signin_ui_util::kUpgradeWelcomeTutorialShowMax) | |
| 1441 return nil; | |
| 1442 profile->GetPrefs()->SetInteger( | |
| 1443 prefs::kProfileAvatarTutorialShown, showCount + 1); | |
| 1444 } | |
| 1445 | |
| 1446 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( | 1436 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( |
| 1447 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); | 1437 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); |
| 1448 | 1438 |
| 1449 NSString* titleMessage = l10n_util::GetNSString( | 1439 NSString* titleMessage = l10n_util::GetNSString( |
| 1450 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); | 1440 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); |
| 1451 NSString* contentMessage = l10n_util::GetNSString( | 1441 NSString* contentMessage = l10n_util::GetNSString( |
| 1452 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); | 1442 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); |
| 1453 // For local profiles, the "Not you" link doesn't make sense. | 1443 // For local profiles, the "Not you" link doesn't make sense. |
| 1454 NSString* linkMessage = avatarItem.signed_in ? | 1444 NSString* linkMessage = item.signed_in ? |
| 1455 ElideMessage( | 1445 ElideMessage( |
| 1456 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatarItem.name), | 1446 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, item.name), |
| 1457 kFixedMenuWidth - 2 * kHorizontalSpacing) : | 1447 kFixedMenuWidth - 2 * kHorizontalSpacing) : |
| 1458 nil; | 1448 nil; |
| 1459 NSString* buttonMessage = l10n_util::GetNSString( | 1449 NSString* buttonMessage = l10n_util::GetNSString( |
| 1460 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); | 1450 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); |
| 1461 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE | 1451 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE |
| 1462 titleMessage:titleMessage | 1452 titleMessage:titleMessage |
| 1463 contentMessage:contentMessage | 1453 contentMessage:contentMessage |
| 1464 linkMessage:linkMessage | 1454 linkMessage:linkMessage |
| 1465 buttonMessage:buttonMessage | 1455 buttonMessage:buttonMessage |
| 1466 stackButton:YES | 1456 stackButton:YES |
| 1467 hasCloseButton:YES | 1457 hasCloseButton:YES |
| 1468 linkAction:@selector(showSwitchUserView:) | 1458 linkAction:@selector(showSwitchUserView:) |
| 1469 buttonAction:@selector(seeWhatsNew:)]; | 1459 buttonAction:@selector(seeWhatsNew:)]; |
| 1470 } | 1460 } |
| 1471 | 1461 |
| 1462 - (NSView*)buildRightClickTutorialView { |
| 1463 NSString* titleMessage = l10n_util::GetNSString( |
| 1464 IDS_PROFILES_RIGHT_CLICK_TUTORIAL_TITLE); |
| 1465 NSString* contentMessage = l10n_util::GetNSString( |
| 1466 IDS_PROFILES_RIGHT_CLICK_TUTORIAL_CONTENT_TEXT); |
| 1467 NSString* buttonMessage = l10n_util::GetNSString( |
| 1468 IDS_PROFILES_TUTORIAL_OK_BUTTON); |
| 1469 |
| 1470 return |
| 1471 [self tutorialViewWithMode:profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING |
| 1472 titleMessage:titleMessage |
| 1473 contentMessage:contentMessage |
| 1474 linkMessage:nil |
| 1475 buttonMessage:buttonMessage |
| 1476 stackButton:NO |
| 1477 hasCloseButton:NO |
| 1478 linkAction:nil |
| 1479 buttonAction:@selector(dismissTutorial:)]; |
| 1480 } |
| 1481 |
| 1482 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item { |
| 1483 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) |
| 1484 return [self buildSigninConfirmationView]; |
| 1485 |
| 1486 if (tutorialMode_ == profiles::TUTORIAL_MODE_SHOW_ERROR) |
| 1487 return [self buildSigninErrorView]; |
| 1488 |
| 1489 if (profiles::ShouldShowWelcomeUpgradeTutorial( |
| 1490 browser_->profile(), tutorialMode_)) { |
| 1491 if (tutorialMode_ != profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
| 1492 Profile* profile = browser_->profile(); |
| 1493 const int showCount = profile->GetPrefs()->GetInteger( |
| 1494 prefs::kProfileAvatarTutorialShown); |
| 1495 profile->GetPrefs()->SetInteger( |
| 1496 prefs::kProfileAvatarTutorialShown, showCount + 1); |
| 1497 } |
| 1498 |
| 1499 return [self buildWelcomeUpgradeTutorialView:item]; |
| 1500 } |
| 1501 |
| 1502 if (profiles::ShouldShowRightClickTutorial(browser_->profile())) |
| 1503 return [self buildRightClickTutorialView]; |
| 1504 |
| 1505 return nil; |
| 1506 } |
| 1507 |
| 1472 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 1508 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
| 1473 titleMessage:(NSString*)titleMessage | 1509 titleMessage:(NSString*)titleMessage |
| 1474 contentMessage:(NSString*)contentMessage | 1510 contentMessage:(NSString*)contentMessage |
| 1475 linkMessage:(NSString*)linkMessage | 1511 linkMessage:(NSString*)linkMessage |
| 1476 buttonMessage:(NSString*)buttonMessage | 1512 buttonMessage:(NSString*)buttonMessage |
| 1477 stackButton:(BOOL)stackButton | 1513 stackButton:(BOOL)stackButton |
| 1478 hasCloseButton:(BOOL)hasCloseButton | 1514 hasCloseButton:(BOOL)hasCloseButton |
| 1479 linkAction:(SEL)linkAction | 1515 linkAction:(SEL)linkAction |
| 1480 buttonAction:(SEL)buttonAction { | 1516 buttonAction:(SEL)buttonAction { |
| 1481 tutorialMode_ = mode; | 1517 tutorialMode_ = mode; |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2315 } | 2351 } |
| 2316 | 2352 |
| 2317 - (bool)shouldShowGoIncognito { | 2353 - (bool)shouldShowGoIncognito { |
| 2318 bool incognitoAvailable = | 2354 bool incognitoAvailable = |
| 2319 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2355 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2320 IncognitoModePrefs::DISABLED; | 2356 IncognitoModePrefs::DISABLED; |
| 2321 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2357 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2322 } | 2358 } |
| 2323 | 2359 |
| 2324 @end | 2360 @end |
| OLD | NEW |