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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 471333003: Make sure avatar menu does not use account_id for display purposes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 3 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 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 chrome::ShowUserManagerWithTutorial( 737 chrome::ShowUserManagerWithTutorial(
738 profiles::USER_MANAGER_TUTORIAL_OVERVIEW); 738 profiles::USER_MANAGER_TUTORIAL_OVERVIEW);
739 } else if (sender == remove_account_button_) { 739 } else if (sender == remove_account_button_) {
740 RemoveAccount(); 740 RemoveAccount();
741 } else if (sender == account_removal_cancel_button_) { 741 } else if (sender == account_removal_cancel_button_) {
742 account_id_to_remove_.clear(); 742 account_id_to_remove_.clear();
743 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); 743 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get());
744 } else if (sender == gaia_signin_cancel_button_) { 744 } else if (sender == gaia_signin_cancel_button_) {
745 std::string primary_account = 745 std::string primary_account =
746 SigninManagerFactory::GetForProfile(browser_->profile())-> 746 SigninManagerFactory::GetForProfile(browser_->profile())->
747 GetAuthenticatedUsername(); 747 GetAuthenticatedAccountId();
748 // The account management view is only available with the 748 // The account management view is only available with the
749 // --enable-account-consistency flag. 749 // --enable-account-consistency flag.
750 bool account_management_available = !primary_account.empty() && 750 bool account_management_available = !primary_account.empty() &&
751 switches::IsEnableAccountConsistency(); 751 switches::IsEnableAccountConsistency();
752 ShowView(account_management_available ? 752 ShowView(account_management_available ?
753 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : 753 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
754 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); 754 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get());
755 } else if (sender == current_profile_photo_) { 755 } else if (sender == current_profile_photo_) {
756 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); 756 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex());
757 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); 757 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE);
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( 1307 views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
1308 const AvatarMenu::Item& avatar_item) { 1308 const AvatarMenu::Item& avatar_item) {
1309 DCHECK(avatar_item.signed_in); 1309 DCHECK(avatar_item.signed_in);
1310 views::View* view = new views::View(); 1310 views::View* view = new views::View();
1311 view->set_background(views::Background::CreateSolidBackground( 1311 view->set_background(views::Background::CreateSolidBackground(
1312 profiles::kAvatarBubbleAccountsBackgroundColor)); 1312 profiles::kAvatarBubbleAccountsBackgroundColor));
1313 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1313 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1314 1314
1315 Profile* profile = browser_->profile(); 1315 Profile* profile = browser_->profile();
1316 std::string primary_account = 1316 std::string primary_account =
1317 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); 1317 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
1318 DCHECK(!primary_account.empty()); 1318 DCHECK(!primary_account.empty());
1319 std::vector<std::string>accounts = 1319 std::vector<std::string>accounts =
1320 profiles::GetSecondaryAccountsForProfile(profile, primary_account); 1320 profiles::GetSecondaryAccountsForProfile(profile, primary_account);
1321 1321
1322 // Get state of authentication error, if any. 1322 // Get state of authentication error, if any.
1323 std::string error_account_id = GetAuthErrorAccountId(profile); 1323 std::string error_account_id = GetAuthErrorAccountId(profile);
1324 1324
1325 // The primary account should always be listed first. 1325 // The primary account should always be listed first.
1326 // TODO(rogerta): we still need to further differentiate the primary account 1326 // TODO(rogerta): we still need to further differentiate the primary account
1327 // from the others in the UI, so more work is likely required here: 1327 // from the others in the UI, so more work is likely required here:
(...skipping 13 matching lines...) Expand all
1341 0, views::kButtonVEdgeMarginNew, 1341 0, views::kButtonVEdgeMarginNew,
1342 views::kRelatedControlVerticalSpacing, 0)); 1342 views::kRelatedControlVerticalSpacing, 0));
1343 layout->StartRow(1, 0); 1343 layout->StartRow(1, 0);
1344 layout->AddView(add_account_link_); 1344 layout->AddView(add_account_link_);
1345 } 1345 }
1346 1346
1347 return view; 1347 return view;
1348 } 1348 }
1349 1349
1350 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, 1350 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout,
1351 const std::string& account, 1351 const std::string& account_id,
1352 bool is_primary_account, 1352 bool is_primary_account,
1353 bool reauth_required, 1353 bool reauth_required,
1354 int width) { 1354 int width) {
1355 std::string email = signin_ui_util::GetDisplayEmail(browser_->profile(),
1356 account_id);
1355 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1357 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1356 const gfx::ImageSkia* delete_default_image = 1358 const gfx::ImageSkia* delete_default_image =
1357 rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia(); 1359 rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia();
1358 const int kDeleteButtonWidth = delete_default_image->width(); 1360 const int kDeleteButtonWidth = delete_default_image->width();
1359 const gfx::ImageSkia warning_default_image = reauth_required ? 1361 const gfx::ImageSkia warning_default_image = reauth_required ?
1360 *rb->GetImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia() : 1362 *rb->GetImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia() :
1361 gfx::ImageSkia(); 1363 gfx::ImageSkia();
1362 const int kWarningButtonWidth = reauth_required ? 1364 const int kWarningButtonWidth = reauth_required ?
1363 warning_default_image.width() + views::kRelatedButtonHSpacing : 0; 1365 warning_default_image.width() + views::kRelatedButtonHSpacing : 0;
1364 int available_width = width - 2 * views::kButtonHEdgeMarginNew 1366 int available_width = width - 2 * views::kButtonHEdgeMarginNew
1365 - kDeleteButtonWidth - kWarningButtonWidth; 1367 - kDeleteButtonWidth - kWarningButtonWidth;
1366 views::LabelButton* email_button = new BackgroundColorHoverButton( 1368 views::LabelButton* email_button = new BackgroundColorHoverButton(
1367 reauth_required ? this : NULL, 1369 reauth_required ? this : NULL,
1368 base::UTF8ToUTF16(account), 1370 base::UTF8ToUTF16(email),
1369 warning_default_image); 1371 warning_default_image);
1370 email_button->SetElideBehavior(gfx::ELIDE_EMAIL); 1372 email_button->SetElideBehavior(gfx::ELIDE_EMAIL);
1371 email_button->SetMinSize(gfx::Size(0, kButtonHeight)); 1373 email_button->SetMinSize(gfx::Size(0, kButtonHeight));
1372 email_button->SetMaxSize(gfx::Size(available_width, kButtonHeight)); 1374 email_button->SetMaxSize(gfx::Size(available_width, kButtonHeight));
1373 layout->StartRow(1, 0); 1375 layout->StartRow(1, 0);
1374 layout->AddView(email_button); 1376 layout->AddView(email_button);
1375 1377
1376 if (reauth_required) 1378 if (reauth_required)
1377 reauth_account_button_map_[email_button] = account; 1379 reauth_account_button_map_[email_button] = account_id;
1378 1380
1379 // Delete button. 1381 // Delete button.
1380 if (!browser_->profile()->IsSupervised()) { 1382 if (!browser_->profile()->IsSupervised()) {
1381 views::ImageButton* delete_button = new views::ImageButton(this); 1383 views::ImageButton* delete_button = new views::ImageButton(this);
1382 delete_button->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, 1384 delete_button->SetImageAlignment(views::ImageButton::ALIGN_RIGHT,
1383 views::ImageButton::ALIGN_MIDDLE); 1385 views::ImageButton::ALIGN_MIDDLE);
1384 delete_button->SetImage(views::ImageButton::STATE_NORMAL, 1386 delete_button->SetImage(views::ImageButton::STATE_NORMAL,
1385 delete_default_image); 1387 delete_default_image);
1386 delete_button->SetImage(views::ImageButton::STATE_HOVERED, 1388 delete_button->SetImage(views::ImageButton::STATE_HOVERED,
1387 rb->GetImageSkiaNamed(IDR_CLOSE_1_H)); 1389 rb->GetImageSkiaNamed(IDR_CLOSE_1_H));
1388 delete_button->SetImage(views::ImageButton::STATE_PRESSED, 1390 delete_button->SetImage(views::ImageButton::STATE_PRESSED,
1389 rb->GetImageSkiaNamed(IDR_CLOSE_1_P)); 1391 rb->GetImageSkiaNamed(IDR_CLOSE_1_P));
1390 delete_button->SetBounds( 1392 delete_button->SetBounds(
1391 width - views::kButtonHEdgeMarginNew - kDeleteButtonWidth, 1393 width - views::kButtonHEdgeMarginNew - kDeleteButtonWidth,
1392 0, kDeleteButtonWidth, kButtonHeight); 1394 0, kDeleteButtonWidth, kButtonHeight);
1393 1395
1394 email_button->set_notify_enter_exit_on_child(true); 1396 email_button->set_notify_enter_exit_on_child(true);
1395 email_button->AddChildView(delete_button); 1397 email_button->AddChildView(delete_button);
1396 1398
1397 // Save the original email address, as the button text could be elided. 1399 // Save the original email address, as the button text could be elided.
1398 delete_account_button_map_[delete_button] = account; 1400 delete_account_button_map_[delete_button] = account_id;
1399 } 1401 }
1400 } 1402 }
1401 1403
1402 views::View* ProfileChooserView::CreateGaiaSigninView() { 1404 views::View* ProfileChooserView::CreateGaiaSigninView() {
1403 GURL url; 1405 GURL url;
1404 int message_id; 1406 int message_id;
1405 1407
1406 switch (view_mode_) { 1408 switch (view_mode_) {
1407 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: 1409 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
1408 url = signin::GetPromoURL(signin::SOURCE_AVATAR_BUBBLE_SIGN_IN, 1410 url = signin::GetPromoURL(signin::SOURCE_AVATAR_BUBBLE_SIGN_IN,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 views::View* ProfileChooserView::CreateAccountRemovalView() { 1447 views::View* ProfileChooserView::CreateAccountRemovalView() {
1446 views::View* view = new views::View(); 1448 views::View* view = new views::View();
1447 views::GridLayout* layout = CreateSingleColumnLayout( 1449 views::GridLayout* layout = CreateSingleColumnLayout(
1448 view, kFixedAccountRemovalViewWidth - 2 * views::kButtonHEdgeMarginNew); 1450 view, kFixedAccountRemovalViewWidth - 2 * views::kButtonHEdgeMarginNew);
1449 layout->SetInsets(0, 1451 layout->SetInsets(0,
1450 views::kButtonHEdgeMarginNew, 1452 views::kButtonHEdgeMarginNew,
1451 views::kButtonVEdgeMarginNew, 1453 views::kButtonVEdgeMarginNew,
1452 views::kButtonHEdgeMarginNew); 1454 views::kButtonHEdgeMarginNew);
1453 1455
1454 const std::string& primary_account = SigninManagerFactory::GetForProfile( 1456 const std::string& primary_account = SigninManagerFactory::GetForProfile(
1455 browser_->profile())->GetAuthenticatedUsername(); 1457 browser_->profile())->GetAuthenticatedAccountId();
1456 bool is_primary_account = primary_account == account_id_to_remove_; 1458 bool is_primary_account = primary_account == account_id_to_remove_;
1457 1459
1458 // Adds main text. 1460 // Adds main text.
1459 layout->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing); 1461 layout->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing);
1460 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1462 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1461 const gfx::FontList& small_font_list = 1463 const gfx::FontList& small_font_list =
1462 rb->GetFontList(ui::ResourceBundle::SmallFont); 1464 rb->GetFontList(ui::ResourceBundle::SmallFont);
1463 1465
1464 if (is_primary_account) { 1466 if (is_primary_account) {
1467 std::string email = signin_ui_util::GetDisplayEmail(browser_->profile(),
1468 account_id_to_remove_);
1465 std::vector<size_t> offsets; 1469 std::vector<size_t> offsets;
1466 const base::string16 settings_text = 1470 const base::string16 settings_text =
1467 l10n_util::GetStringUTF16(IDS_PROFILES_SETTINGS_LINK); 1471 l10n_util::GetStringUTF16(IDS_PROFILES_SETTINGS_LINK);
1468 const base::string16 primary_account_removal_text = 1472 const base::string16 primary_account_removal_text =
1469 l10n_util::GetStringFUTF16(IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, 1473 l10n_util::GetStringFUTF16(IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT,
1470 base::UTF8ToUTF16(account_id_to_remove_), settings_text, &offsets); 1474 base::UTF8ToUTF16(email), settings_text, &offsets);
1471 views::StyledLabel* primary_account_removal_label = 1475 views::StyledLabel* primary_account_removal_label =
1472 new views::StyledLabel(primary_account_removal_text, this); 1476 new views::StyledLabel(primary_account_removal_text, this);
1473 primary_account_removal_label->AddStyleRange( 1477 primary_account_removal_label->AddStyleRange(
1474 gfx::Range(offsets[1], offsets[1] + settings_text.size()), 1478 gfx::Range(offsets[1], offsets[1] + settings_text.size()),
1475 views::StyledLabel::RangeStyleInfo::CreateForLink()); 1479 views::StyledLabel::RangeStyleInfo::CreateForLink());
1476 primary_account_removal_label->SetBaseFontList(small_font_list); 1480 primary_account_removal_label->SetBaseFontList(small_font_list);
1477 layout->AddView(primary_account_removal_label); 1481 layout->AddView(primary_account_removal_label);
1478 } else { 1482 } else {
1479 views::Label* content_label = new views::Label( 1483 views::Label* content_label = new views::Label(
1480 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT)); 1484 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT));
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1640 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1637 IncognitoModePrefs::DISABLED; 1641 IncognitoModePrefs::DISABLED;
1638 return incognito_available && !browser_->profile()->IsGuestSession(); 1642 return incognito_available && !browser_->profile()->IsGuestSession();
1639 } 1643 }
1640 1644
1641 void ProfileChooserView::PostActionPerformed( 1645 void ProfileChooserView::PostActionPerformed(
1642 ProfileMetrics::ProfileDesktopMenu action_performed) { 1646 ProfileMetrics::ProfileDesktopMenu action_performed) {
1643 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1647 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1644 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1648 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1645 } 1649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698