| 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 |
| 899 // Returns YES if the Welcome/Upgrade tutorial bubble should be shown to the |
| 900 // user, NO otherwise. |
| 901 - (bool)shouldShowWelcomeUpgradeTutorial; |
| 902 |
| 903 // Returns YES if the tutorial informing the user about right-click user |
| 904 // switching should be shown, NO otherwise. |
| 905 - (bool)shouldShowRightClickTutorialView; |
| 906 |
| 897 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if | 907 // 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 | 908 // needed. |tutorial_shown| indicates if the tutorial has already been shown in |
| 899 // the previous active view. |avatar_item| refers to the current profile. | 909 // the previous active view. |avatar_item| refers to the current profile. |
| 900 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded; | 910 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item; |
| 911 |
| 912 // Builds a tutorial card to inform the user about right-click user switching if |
| 913 // needed. |
| 914 - (NSView*)buildRightClickTutorialView; |
| 901 | 915 |
| 902 // Builds a tutorial card to have the user confirm the last Chrome signin, | 916 // 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 | 917 // Chrome sync will be delayed until the user either dismisses the tutorial, or |
| 904 // configures sync through the "Settings" link. | 918 // configures sync through the "Settings" link. |
| 905 - (NSView*)buildSigninConfirmationView; | 919 - (NSView*)buildSigninConfirmationView; |
| 906 | 920 |
| 907 // Builds a tutorial card to show the last signin error. | 921 // Builds a tutorial card to show the last signin error. |
| 908 - (NSView*)buildSigninErrorView; | 922 - (NSView*)buildSigninErrorView; |
| 909 | 923 |
| 910 // Creates the main profile card for the profile |item| at the top of | 924 // 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 } | 1136 } |
| 1123 | 1137 |
| 1124 - (IBAction)dismissTutorial:(id)sender { | 1138 - (IBAction)dismissTutorial:(id)sender { |
| 1125 // Never shows the upgrade tutorial again if manually closed. | 1139 // Never shows the upgrade tutorial again if manually closed. |
| 1126 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | 1140 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
| 1127 browser_->profile()->GetPrefs()->SetInteger( | 1141 browser_->profile()->GetPrefs()->SetInteger( |
| 1128 prefs::kProfileAvatarTutorialShown, | 1142 prefs::kProfileAvatarTutorialShown, |
| 1129 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); | 1143 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); |
| 1130 } | 1144 } |
| 1131 | 1145 |
| 1146 if(tutorialMode_ == profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING) { |
| 1147 PrefService* localState = g_browser_process->local_state(); |
| 1148 localState->SetBoolean( |
| 1149 prefs::kProfileAvatarRightClickTutorialDismissed, true); |
| 1150 } |
| 1151 |
| 1132 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | 1152 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; |
| 1133 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 1153 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
| 1134 } | 1154 } |
| 1135 | 1155 |
| 1136 - (void)windowWillClose:(NSNotification*)notification { | 1156 - (void)windowWillClose:(NSNotification*)notification { |
| 1137 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { | 1157 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { |
| 1138 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 1158 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
| 1139 SyncConfirmationUIClosed(false); | 1159 SyncConfirmationUIClosed(false); |
| 1140 } | 1160 } |
| 1141 | 1161 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 [[NSView alloc] initWithFrame:NSZeroRect]); | 1283 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 1264 | 1284 |
| 1265 NSView* tutorialView = nil; | 1285 NSView* tutorialView = nil; |
| 1266 NSView* currentProfileView = nil; | 1286 NSView* currentProfileView = nil; |
| 1267 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1287 base::scoped_nsobject<NSMutableArray> otherProfiles( |
| 1268 [[NSMutableArray alloc] init]); | 1288 [[NSMutableArray alloc] init]); |
| 1269 // Local and guest profiles cannot lock their profile. | 1289 // Local and guest profiles cannot lock their profile. |
| 1270 bool displayLock = false; | 1290 bool displayLock = false; |
| 1271 bool isFastProfileChooser = | 1291 bool isFastProfileChooser = |
| 1272 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 1292 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 1293 if (isFastProfileChooser) { |
| 1294 // The user is using right-click switching, no need to tell them about it. |
| 1295 PrefService* localState = g_browser_process->local_state(); |
| 1296 localState->SetBoolean( |
| 1297 prefs::kProfileAvatarRightClickTutorialDismissed, true); |
| 1298 } |
| 1273 | 1299 |
| 1274 // Loop over the profiles in reverse, so that they are sorted by their | 1300 // Loop over the profiles in reverse, so that they are sorted by their |
| 1275 // y-coordinate, and separate them into active and "other" profiles. | 1301 // y-coordinate, and separate them into active and "other" profiles. |
| 1276 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { | 1302 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { |
| 1277 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); | 1303 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); |
| 1278 if (item.active) { | 1304 if (item.active) { |
| 1279 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 1305 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { |
| 1280 switch (tutorialMode_) { | 1306 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 } | 1307 } |
| 1293 currentProfileView = [self createCurrentProfileView:item]; | 1308 currentProfileView = [self createCurrentProfileView:item]; |
| 1294 displayLock = item.signed_in && | 1309 displayLock = item.signed_in && |
| 1295 profiles::IsLockAvailable(browser_->profile()); | 1310 profiles::IsLockAvailable(browser_->profile()); |
| 1296 } else { | 1311 } else { |
| 1297 [otherProfiles addObject:[self createOtherProfileView:i]]; | 1312 [otherProfiles addObject:[self createOtherProfileView:i]]; |
| 1298 } | 1313 } |
| 1299 } | 1314 } |
| 1300 if (!currentProfileView) // Guest windows don't have an active profile. | 1315 if (!currentProfileView) // Guest windows don't have an active profile. |
| 1301 currentProfileView = [self createGuestProfileView]; | 1316 currentProfileView = [self createGuestProfileView]; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 titleMessage:titleMessage | 1433 titleMessage:titleMessage |
| 1419 contentMessage:contentMessage | 1434 contentMessage:contentMessage |
| 1420 linkMessage:linkMessage | 1435 linkMessage:linkMessage |
| 1421 buttonMessage:nil | 1436 buttonMessage:nil |
| 1422 stackButton:NO | 1437 stackButton:NO |
| 1423 hasCloseButton:YES | 1438 hasCloseButton:YES |
| 1424 linkAction:@selector(showLearnMorePage:) | 1439 linkAction:@selector(showLearnMorePage:) |
| 1425 buttonAction:nil]; | 1440 buttonAction:nil]; |
| 1426 } | 1441 } |
| 1427 | 1442 |
| 1428 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded { | 1443 - (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( | 1444 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( |
| 1447 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); | 1445 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); |
| 1448 | 1446 |
| 1449 NSString* titleMessage = l10n_util::GetNSString( | 1447 NSString* titleMessage = l10n_util::GetNSString( |
| 1450 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); | 1448 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); |
| 1451 NSString* contentMessage = l10n_util::GetNSString( | 1449 NSString* contentMessage = l10n_util::GetNSString( |
| 1452 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); | 1450 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); |
| 1453 // For local profiles, the "Not you" link doesn't make sense. | 1451 // For local profiles, the "Not you" link doesn't make sense. |
| 1454 NSString* linkMessage = avatarItem.signed_in ? | 1452 NSString* linkMessage = item.signed_in ? |
| 1455 ElideMessage( | 1453 ElideMessage( |
| 1456 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatarItem.name), | 1454 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, item.name), |
| 1457 kFixedMenuWidth - 2 * kHorizontalSpacing) : | 1455 kFixedMenuWidth - 2 * kHorizontalSpacing) : |
| 1458 nil; | 1456 nil; |
| 1459 NSString* buttonMessage = l10n_util::GetNSString( | 1457 NSString* buttonMessage = l10n_util::GetNSString( |
| 1460 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); | 1458 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); |
| 1461 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE | 1459 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE |
| 1462 titleMessage:titleMessage | 1460 titleMessage:titleMessage |
| 1463 contentMessage:contentMessage | 1461 contentMessage:contentMessage |
| 1464 linkMessage:linkMessage | 1462 linkMessage:linkMessage |
| 1465 buttonMessage:buttonMessage | 1463 buttonMessage:buttonMessage |
| 1466 stackButton:YES | 1464 stackButton:YES |
| 1467 hasCloseButton:YES | 1465 hasCloseButton:YES |
| 1468 linkAction:@selector(showSwitchUserView:) | 1466 linkAction:@selector(showSwitchUserView:) |
| 1469 buttonAction:@selector(seeWhatsNew:)]; | 1467 buttonAction:@selector(seeWhatsNew:)]; |
| 1470 } | 1468 } |
| 1471 | 1469 |
| 1470 - (NSView*)buildRightClickTutorialView { |
| 1471 NSString* titleMessage = l10n_util::GetNSString( |
| 1472 IDS_PROFILES_RIGHT_CLICK_TUTORIAL_TITLE); |
| 1473 NSString* contentMessage = l10n_util::GetNSString( |
| 1474 IDS_PROFILES_RIGHT_CLICK_TUTORIAL_CONTENT_TEXT); |
| 1475 NSString* buttonMessage = l10n_util::GetNSString( |
| 1476 IDS_PROFILES_TUTORIAL_OK_BUTTON); |
| 1477 |
| 1478 return |
| 1479 [self tutorialViewWithMode:profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING |
| 1480 titleMessage:titleMessage |
| 1481 contentMessage:contentMessage |
| 1482 linkMessage:nil |
| 1483 buttonMessage:buttonMessage |
| 1484 stackButton:NO |
| 1485 hasCloseButton:NO |
| 1486 linkAction:nil |
| 1487 buttonAction:@selector(dismissTutorial:)]; |
| 1488 } |
| 1489 |
| 1490 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item { |
| 1491 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) |
| 1492 return [self buildSigninConfirmationView]; |
| 1493 |
| 1494 if (tutorialMode_ == profiles::TUTORIAL_MODE_SHOW_ERROR) |
| 1495 return [self buildSigninErrorView]; |
| 1496 |
| 1497 if (profiles::ShouldShowWelcomeUpgradeTutorial( |
| 1498 browser_->profile(), tutorialMode_)) { |
| 1499 if (tutorialMode_ != profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
| 1500 Profile* profile = browser_->profile(); |
| 1501 const int showCount = profile->GetPrefs()->GetInteger( |
| 1502 prefs::kProfileAvatarTutorialShown); |
| 1503 profile->GetPrefs()->SetInteger( |
| 1504 prefs::kProfileAvatarTutorialShown, showCount + 1); |
| 1505 } |
| 1506 |
| 1507 return [self buildWelcomeUpgradeTutorialView:item]; |
| 1508 } |
| 1509 |
| 1510 if (profiles::ShouldShowRightClickTutorial(browser_->profile())) |
| 1511 return [self buildRightClickTutorialView]; |
| 1512 |
| 1513 return nil; |
| 1514 } |
| 1515 |
| 1472 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 1516 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
| 1473 titleMessage:(NSString*)titleMessage | 1517 titleMessage:(NSString*)titleMessage |
| 1474 contentMessage:(NSString*)contentMessage | 1518 contentMessage:(NSString*)contentMessage |
| 1475 linkMessage:(NSString*)linkMessage | 1519 linkMessage:(NSString*)linkMessage |
| 1476 buttonMessage:(NSString*)buttonMessage | 1520 buttonMessage:(NSString*)buttonMessage |
| 1477 stackButton:(BOOL)stackButton | 1521 stackButton:(BOOL)stackButton |
| 1478 hasCloseButton:(BOOL)hasCloseButton | 1522 hasCloseButton:(BOOL)hasCloseButton |
| 1479 linkAction:(SEL)linkAction | 1523 linkAction:(SEL)linkAction |
| 1480 buttonAction:(SEL)buttonAction { | 1524 buttonAction:(SEL)buttonAction { |
| 1481 tutorialMode_ = mode; | 1525 tutorialMode_ = mode; |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2315 } | 2359 } |
| 2316 | 2360 |
| 2317 - (bool)shouldShowGoIncognito { | 2361 - (bool)shouldShowGoIncognito { |
| 2318 bool incognitoAvailable = | 2362 bool incognitoAvailable = |
| 2319 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2363 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2320 IncognitoModePrefs::DISABLED; | 2364 IncognitoModePrefs::DISABLED; |
| 2321 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2365 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2322 } | 2366 } |
| 2323 | 2367 |
| 2324 @end | 2368 @end |
| OLD | NEW |