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

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

Issue 485073002: Migrate signin error messages to the new avatar bubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adds mac implementation Created 6 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 | Annotate | Revision Log
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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 token_observer_registered_ = false; 284 token_observer_registered_ = false;
285 } 285 }
286 286
287 // OAuth2TokenService::Observer: 287 // OAuth2TokenService::Observer:
288 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE { 288 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE {
289 // Tokens can only be added by adding an account through the inline flow, 289 // Tokens can only be added by adding an account through the inline flow,
290 // which is started from the account management view. Refresh it to show the 290 // which is started from the account management view. Refresh it to show the
291 // update. 291 // update.
292 profiles::BubbleViewMode viewMode = [controller_ viewMode]; 292 profiles::BubbleViewMode viewMode = [controller_ viewMode];
293 if (viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT || 293 if (viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ||
294 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN ||
295 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || 294 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT ||
296 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { 295 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) {
297 if (viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN)
298 [controller_ setTutorialMode:profiles::TUTORIAL_MODE_CONFIRM_SIGNIN];
299 [controller_ initMenuContentsWithView: 296 [controller_ initMenuContentsWithView:
300 switches::IsEnableAccountConsistency() ? 297 switches::IsEnableAccountConsistency() ?
301 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : 298 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
302 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; 299 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER];
303 } 300 }
304 } 301 }
305 302
306 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE { 303 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE {
307 // Tokens can only be removed from the account management view. Refresh it 304 // Tokens can only be removed from the account management view. Refresh it
308 // to show the update. 305 // to show the update.
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if 795 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if
799 // needed. |tutorial_shown| indicates if the tutorial has already been shown in 796 // needed. |tutorial_shown| indicates if the tutorial has already been shown in
800 // the previous active view. |avatar_item| refers to the current profile. 797 // the previous active view. |avatar_item| refers to the current profile.
801 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded; 798 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded;
802 799
803 // Builds a tutorial card to have the user confirm the last Chrome signin, 800 // Builds a tutorial card to have the user confirm the last Chrome signin,
804 // Chrome sync will be delayed until the user either dismisses the tutorial, or 801 // Chrome sync will be delayed until the user either dismisses the tutorial, or
805 // configures sync through the "Settings" link. 802 // configures sync through the "Settings" link.
806 - (NSView*)buildSigninConfirmationView; 803 - (NSView*)buildSigninConfirmationView;
807 804
805 // Builds a tutorial card to show the last signin error.
806 - (NSView*)buildSigninErrorView;
807
808 // Creates the main profile card for the profile |item| at the top of 808 // Creates the main profile card for the profile |item| at the top of
809 // the bubble. 809 // the bubble.
810 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; 810 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item;
811 811
812 // Creates the possible links for the main profile card with profile |item|. 812 // Creates the possible links for the main profile card with profile |item|.
813 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item 813 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item
814 rect:(NSRect)rect; 814 rect:(NSRect)rect;
815 815
816 // Creates the disclaimer text for supervised users, telling them that the 816 // Creates the disclaimer text for supervised users, telling them that the
817 // manager can view their history etc. 817 // manager can view their history etc.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 972 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
973 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_WHATS_NEW); 973 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_WHATS_NEW);
974 } 974 }
975 975
976 - (IBAction)showSwitchUserView:(id)sender { 976 - (IBAction)showSwitchUserView:(id)sender {
977 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_SWITCH_USER]; 977 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_SWITCH_USER];
978 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 978 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
979 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU); 979 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU);
980 } 980 }
981 981
982 - (IBAction)showLearnMorePage:(id)sender {
983 // TODO(guohui): updates the code once the URL is available.
984 }
985
982 - (IBAction)configureSyncSettings:(id)sender { 986 - (IBAction)configureSyncSettings:(id)sender {
983 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; 987 tutorialMode_ = profiles::TUTORIAL_MODE_NONE;
984 LoginUIServiceFactory::GetForProfile(browser_->profile())-> 988 LoginUIServiceFactory::GetForProfile(browser_->profile())->
985 SyncConfirmationUIClosed(true); 989 SyncConfirmationUIClosed(true);
986 ProfileMetrics::LogProfileNewAvatarMenuSignin( 990 ProfileMetrics::LogProfileNewAvatarMenuSignin(
987 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS); 991 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS);
988 } 992 }
989 993
990 - (IBAction)syncSettingsConfirmed:(id)sender { 994 - (IBAction)syncSettingsConfirmed:(id)sender {
991 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; 995 tutorialMode_ = profiles::TUTORIAL_MODE_NONE;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 switch (tutorialMode_) { 1151 switch (tutorialMode_) {
1148 case profiles::TUTORIAL_MODE_NONE: 1152 case profiles::TUTORIAL_MODE_NONE:
1149 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: 1153 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE:
1150 tutorialView = 1154 tutorialView =
1151 [self buildWelcomeUpgradeTutorialViewIfNeeded]; 1155 [self buildWelcomeUpgradeTutorialViewIfNeeded];
1152 break; 1156 break;
1153 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: 1157 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN:
1154 tutorialView = [self buildSigninConfirmationView]; 1158 tutorialView = [self buildSigninConfirmationView];
1155 break; 1159 break;
1156 case profiles::TUTORIAL_MODE_SHOW_ERROR: 1160 case profiles::TUTORIAL_MODE_SHOW_ERROR:
1157 // TODO(guohui): not implemented yet. 1161 tutorialView = [self buildSigninErrorView];
1158 NOTREACHED();
1159 } 1162 }
1160 } 1163 }
1161 currentProfileView = [self createCurrentProfileView:item]; 1164 currentProfileView = [self createCurrentProfileView:item];
1162 enableLock = switches::IsNewProfileManagement() && item.signed_in; 1165 enableLock = switches::IsNewProfileManagement() && item.signed_in;
1163 } else { 1166 } else {
1164 [otherProfiles addObject:[self createOtherProfileView:i]]; 1167 [otherProfiles addObject:[self createOtherProfileView:i]];
1165 } 1168 }
1166 } 1169 }
1167 if (!currentProfileView) // Guest windows don't have an active profile. 1170 if (!currentProfileView) // Guest windows don't have an active profile.
1168 currentProfileView = [self createGuestProfileView]; 1171 currentProfileView = [self createGuestProfileView];
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 titleMessage:titleMessage 1266 titleMessage:titleMessage
1264 contentMessage:contentMessage 1267 contentMessage:contentMessage
1265 linkMessage:linkMessage 1268 linkMessage:linkMessage
1266 buttonMessage:buttonMessage 1269 buttonMessage:buttonMessage
1267 stackButton:NO 1270 stackButton:NO
1268 hasCloseButton:NO 1271 hasCloseButton:NO
1269 linkAction:@selector(configureSyncSettings:) 1272 linkAction:@selector(configureSyncSettings:)
1270 buttonAction:@selector(syncSettingsConfirmed:)]; 1273 buttonAction:@selector(syncSettingsConfirmed:)];
1271 } 1274 }
1272 1275
1276 - (NSView*)buildSigninErrorView {
1277 NSString* titleMessage = l10n_util::GetNSString(
1278 IDS_PROFILES_ERROR_TUTORIAL_TITLE);
1279 LoginUIService* login_ui_service =
Alexei Svitkine (slow) 2014/08/19 19:06:22 Nit: camelCase
guohui 2014/08/19 19:51:03 Done.
1280 LoginUIServiceFactory::GetForProfile(browser_->profile());
1281 NSString* contentMessage =
1282 base::SysUTF16ToNSString(login_ui_service->GetLastLoginResult());
1283 NSString* linkMessage = l10n_util::GetNSString(
1284 IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE);
1285 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_CONFIRM_SIGNIN
1286 titleMessage:titleMessage
1287 contentMessage:contentMessage
1288 linkMessage:linkMessage
1289 buttonMessage:nil
1290 stackButton:NO
1291 hasCloseButton:YES
1292 linkAction:@selector(showLearnMorePage:)
1293 buttonAction:nil];
1294 }
1295
1273 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded { 1296 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded {
1274 Profile* profile = browser_->profile(); 1297 Profile* profile = browser_->profile();
1275 const AvatarMenu::Item& avatarItem = 1298 const AvatarMenu::Item& avatarItem =
1276 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); 1299 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex());
1277 1300
1278 const int showCount = profile->GetPrefs()->GetInteger( 1301 const int showCount = profile->GetPrefs()->GetInteger(
1279 prefs::kProfileAvatarTutorialShown); 1302 prefs::kProfileAvatarTutorialShown);
1280 // Do not show the tutorial if user has dismissed it. 1303 // Do not show the tutorial if user has dismissed it.
1281 if (showCount > signin_ui_util::kUpgradeWelcomeTutorialShowMax) 1304 if (showCount > signin_ui_util::kUpgradeWelcomeTutorialShowMax)
1282 return nil; 1305 return nil;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 1350
1328 NSColor* tutorialBackgroundColor = 1351 NSColor* tutorialBackgroundColor =
1329 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); 1352 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor);
1330 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] 1353 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc]
1331 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) 1354 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0)
1332 withColor:tutorialBackgroundColor]); 1355 withColor:tutorialBackgroundColor]);
1333 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; 1356 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing;
1334 CGFloat yOffset = kVerticalSpacing; 1357 CGFloat yOffset = kVerticalSpacing;
1335 1358
1336 // Adds links and buttons at the bottom. 1359 // Adds links and buttons at the bottom.
1337 base::scoped_nsobject<NSButton> tutorialOkButton([[HoverButton alloc] 1360 base::scoped_nsobject<NSButton> tutorialOkButton;
1338 initWithFrame:NSZeroRect]); 1361 if (buttonMessage) {
1339 [tutorialOkButton setTitle:buttonMessage]; 1362 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]);
1340 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; 1363 [tutorialOkButton setTitle:buttonMessage];
1341 [tutorialOkButton setTarget:self]; 1364 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle];
1342 [tutorialOkButton setAction:buttonAction]; 1365 [tutorialOkButton setTarget:self];
1343 [tutorialOkButton setAlignment:NSCenterTextAlignment]; 1366 [tutorialOkButton setAction:buttonAction];
1344 [tutorialOkButton sizeToFit]; 1367 [tutorialOkButton setAlignment:NSCenterTextAlignment];
1368 [tutorialOkButton sizeToFit];
1369 }
1345 1370
1346 NSButton* learnMoreLink = nil; 1371 NSButton* learnMoreLink = nil;
1347 if (linkMessage) { 1372 if (linkMessage) {
1348 learnMoreLink = [self linkButtonWithTitle:linkMessage 1373 learnMoreLink = [self linkButtonWithTitle:linkMessage
1349 frameOrigin:NSZeroPoint 1374 frameOrigin:NSZeroPoint
1350 action:linkAction]; 1375 action:linkAction];
1351 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; 1376 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]];
1352 } 1377 }
1353 1378
1354 if (stackButton) { 1379 if (stackButton) {
1355 if (learnMoreLink) { 1380 if (linkMessage) {
1356 [learnMoreLink setFrameOrigin:NSMakePoint( 1381 [learnMoreLink setFrameOrigin:NSMakePoint(
1357 (kFixedMenuWidth - NSWidth([learnMoreLink frame])) / 2, yOffset)]; 1382 (kFixedMenuWidth - NSWidth([learnMoreLink frame])) / 2, yOffset)];
1358 } 1383 }
1359 [tutorialOkButton setFrameSize:NSMakeSize( 1384 [tutorialOkButton setFrameSize:NSMakeSize(
1360 availableWidth, NSHeight([tutorialOkButton frame]))]; 1385 availableWidth, NSHeight([tutorialOkButton frame]))];
1361 [tutorialOkButton setFrameOrigin:NSMakePoint( 1386 [tutorialOkButton setFrameOrigin:NSMakePoint(
1362 kHorizontalSpacing, 1387 kHorizontalSpacing,
1363 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))]; 1388 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))];
1364 } else { 1389 } else {
1365 NSSize buttonSize = [tutorialOkButton frame].size; 1390 if (buttonMessage) {
1366 const CGFloat kTopBottomTextPadding = 6; 1391 NSSize buttonSize = [tutorialOkButton frame].size;
1367 const CGFloat kLeftRightTextPadding = 15; 1392 const CGFloat kTopBottomTextPadding = 6;
1368 buttonSize.width += 2 * kLeftRightTextPadding; 1393 const CGFloat kLeftRightTextPadding = 15;
1369 buttonSize.height += 2 * kTopBottomTextPadding; 1394 buttonSize.width += 2 * kLeftRightTextPadding;
1370 [tutorialOkButton setFrameSize:buttonSize]; 1395 buttonSize.height += 2 * kTopBottomTextPadding;
1371 CGFloat buttonXOffset = kFixedMenuWidth - 1396 [tutorialOkButton setFrameSize:buttonSize];
1372 NSWidth([tutorialOkButton frame]) - kHorizontalSpacing; 1397 CGFloat buttonXOffset = kFixedMenuWidth -
1373 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)]; 1398 NSWidth([tutorialOkButton frame]) - kHorizontalSpacing;
1399 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)];
1400 }
1374 1401
1375 if (learnMoreLink) { 1402 if (linkMessage) {
1376 CGFloat linkYOffset = yOffset + (NSHeight([tutorialOkButton frame]) - 1403 CGFloat linkYOffset = yOffset;
1377 NSHeight([learnMoreLink frame])) / 2; 1404 if(buttonMessage) {
Alexei Svitkine (slow) 2014/08/19 19:06:22 Nit: Space after if
guohui 2014/08/19 19:51:03 Done.
1405 linkYOffset += (NSHeight([tutorialOkButton frame]) -
1406 NSHeight([learnMoreLink frame])) / 2;
1407 }
1378 [learnMoreLink setFrameOrigin:NSMakePoint( 1408 [learnMoreLink setFrameOrigin:NSMakePoint(
1379 kHorizontalSpacing, linkYOffset)]; 1409 kHorizontalSpacing, linkYOffset)];
1380 } 1410 }
1381 } 1411 }
1382 1412
1383 [container addSubview:tutorialOkButton]; 1413 if (buttonMessage) {
1384 if (learnMoreLink) { 1414 [container addSubview:tutorialOkButton];
1415 yOffset = NSMaxY([tutorialOkButton frame]);
1416 }
1417
1418 if (linkMessage) {
1385 [container addSubview:learnMoreLink]; 1419 [container addSubview:learnMoreLink];
1386 yOffset = std::max(NSMaxY([learnMoreLink frame]), 1420 yOffset = std::max(NSMaxY([learnMoreLink frame]), yOffset);
1387 NSMaxY([tutorialOkButton frame])) + kVerticalSpacing;
1388 } else {
1389 yOffset = NSMaxY([tutorialOkButton frame]) + kVerticalSpacing;
1390 } 1421 }
1391 1422
1423 yOffset += kVerticalSpacing;
1424
1392 // Adds body content. 1425 // Adds body content.
1393 NSTextField* contentLabel = BuildLabel( 1426 NSTextField* contentLabel = BuildLabel(
1394 contentMessage, 1427 contentMessage,
1395 NSMakePoint(kHorizontalSpacing, yOffset), 1428 NSMakePoint(kHorizontalSpacing, yOffset),
1396 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialContentTextColor)); 1429 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialContentTextColor));
1397 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; 1430 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)];
1398 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; 1431 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel];
1399 [container addSubview:contentLabel]; 1432 [container addSubview:contentLabel];
1400 yOffset = NSMaxY([contentLabel frame]) + kSmallVerticalSpacing; 1433 yOffset = NSMaxY([contentLabel frame]) + kSmallVerticalSpacing;
1401 1434
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 } 2152 }
2120 2153
2121 - (bool)shouldShowGoIncognito { 2154 - (bool)shouldShowGoIncognito {
2122 bool incognitoAvailable = 2155 bool incognitoAvailable =
2123 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2156 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2124 IncognitoModePrefs::DISABLED; 2157 IncognitoModePrefs::DISABLED;
2125 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2158 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2126 } 2159 }
2127 2160
2128 @end 2161 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698