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