| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const int kFixedMenuWidth = 250; | 72 const int kFixedMenuWidth = 250; |
| 73 const int kButtonHeight = 32; | 73 const int kButtonHeight = 32; |
| 74 const int kFixedGaiaViewHeight = 440; | 74 const int kFixedGaiaViewHeight = 440; |
| 75 const int kFixedGaiaViewWidth = 360; | 75 const int kFixedGaiaViewWidth = 360; |
| 76 const int kFixedAccountRemovalViewWidth = 280; | 76 const int kFixedAccountRemovalViewWidth = 280; |
| 77 const int kFixedSwitchUserViewWidth = 320; | 77 const int kFixedSwitchUserViewWidth = 320; |
| 78 const int kLargeImageSide = 88; | 78 const int kLargeImageSide = 88; |
| 79 | 79 |
| 80 const int kVerticalSpacing = 16; | 80 const int kVerticalSpacing = 16; |
| 81 | 81 |
| 82 bool IsProfileChooser(profiles::BubbleViewMode mode) { |
| 83 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || |
| 84 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 85 } |
| 86 |
| 82 // Creates a GridLayout with a single column. This ensures that all the child | 87 // Creates a GridLayout with a single column. This ensures that all the child |
| 83 // views added get auto-expanded to fill the full width of the bubble. | 88 // views added get auto-expanded to fill the full width of the bubble. |
| 84 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { | 89 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { |
| 85 views::GridLayout* layout = new views::GridLayout(view); | 90 views::GridLayout* layout = new views::GridLayout(view); |
| 86 view->SetLayoutManager(layout); | 91 view->SetLayoutManager(layout); |
| 87 | 92 |
| 88 views::ColumnSet* columns = layout->AddColumnSet(0); | 93 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 89 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 94 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 90 views::GridLayout::FIXED, width, width); | 95 views::GridLayout::FIXED, width, width); |
| 91 return layout; | 96 return layout; |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 tutorial_close_button_ = NULL; | 583 tutorial_close_button_ = NULL; |
| 579 tutorial_sync_settings_link_ = NULL; | 584 tutorial_sync_settings_link_ = NULL; |
| 580 tutorial_see_whats_new_button_ = NULL; | 585 tutorial_see_whats_new_button_ = NULL; |
| 581 tutorial_not_you_link_ = NULL; | 586 tutorial_not_you_link_ = NULL; |
| 582 tutorial_learn_more_link_ = NULL; | 587 tutorial_learn_more_link_ = NULL; |
| 583 } | 588 } |
| 584 | 589 |
| 585 void ProfileChooserView::Init() { | 590 void ProfileChooserView::Init() { |
| 586 // If view mode is PROFILE_CHOOSER but there is an auth error, force | 591 // If view mode is PROFILE_CHOOSER but there is an auth error, force |
| 587 // ACCOUNT_MANAGEMENT mode. | 592 // ACCOUNT_MANAGEMENT mode. |
| 588 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | 593 if (IsProfileChooser(view_mode_) && |
| 589 HasAuthError(browser_->profile()) && | 594 HasAuthError(browser_->profile()) && |
| 590 switches::IsEnableAccountConsistency() && | 595 switches::IsEnableAccountConsistency() && |
| 591 avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()). | 596 avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()). |
| 592 signed_in) { | 597 signed_in) { |
| 593 view_mode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT; | 598 view_mode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT; |
| 594 } | 599 } |
| 595 | 600 |
| 596 // The arrow keys can be used to tab between items. | 601 // The arrow keys can be used to tab between items. |
| 597 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE)); | 602 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE)); |
| 598 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE)); | 603 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE)); |
| 599 | 604 |
| 600 ShowView(view_mode_, avatar_menu_.get()); | 605 ShowView(view_mode_, avatar_menu_.get()); |
| 601 } | 606 } |
| 602 | 607 |
| 603 void ProfileChooserView::OnAvatarMenuChanged( | 608 void ProfileChooserView::OnAvatarMenuChanged( |
| 604 AvatarMenu* avatar_menu) { | 609 AvatarMenu* avatar_menu) { |
| 605 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || | 610 if (IsProfileChooser(view_mode_) || |
| 606 view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | 611 view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
| 607 // Refresh the view with the new menu. We can't just update the local copy | 612 // Refresh the view with the new menu. We can't just update the local copy |
| 608 // as this may have been triggered by a sign out action, in which case | 613 // as this may have been triggered by a sign out action, in which case |
| 609 // the view is being destroyed. | 614 // the view is being destroyed. |
| 610 ShowView(view_mode_, avatar_menu); | 615 ShowView(view_mode_, avatar_menu); |
| 611 } | 616 } |
| 612 } | 617 } |
| 613 | 618 |
| 614 void ProfileChooserView::OnRefreshTokenAvailable( | 619 void ProfileChooserView::OnRefreshTokenAvailable( |
| 615 const std::string& account_id) { | 620 const std::string& account_id) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 return true; | 889 return true; |
| 885 | 890 |
| 886 profiles::UpdateProfileName(profile, new_profile_name); | 891 profiles::UpdateProfileName(profile, new_profile_name); |
| 887 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); | 892 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); |
| 888 current_profile_name_->ShowReadOnlyView(); | 893 current_profile_name_->ShowReadOnlyView(); |
| 889 return true; | 894 return true; |
| 890 } | 895 } |
| 891 return false; | 896 return false; |
| 892 } | 897 } |
| 893 | 898 |
| 894 views::View* ProfileChooserView::CreateProfileChooserView( | 899 void ProfileChooserView::PopulateCompleteProfileChooserView( |
| 900 views::GridLayout* layout, |
| 895 AvatarMenu* avatar_menu) { | 901 AvatarMenu* avatar_menu) { |
| 896 views::View* view = new views::View(); | |
| 897 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | |
| 898 // Separate items into active and alternatives. | 902 // Separate items into active and alternatives. |
| 899 Indexes other_profiles; | 903 Indexes other_profiles; |
| 900 views::View* tutorial_view = NULL; | 904 views::View* tutorial_view = NULL; |
| 901 views::View* current_profile_view = NULL; | 905 views::View* current_profile_view = NULL; |
| 902 views::View* current_profile_accounts = NULL; | 906 views::View* current_profile_accounts = NULL; |
| 903 views::View* option_buttons_view = NULL; | 907 views::View* option_buttons_view = NULL; |
| 904 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 908 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| 905 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 909 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| 906 if (item.active) { | 910 if (item.active) { |
| 907 option_buttons_view = CreateOptionsView( | 911 option_buttons_view = CreateOptionsView( |
| 908 item.signed_in && profiles::IsLockAvailable(browser_->profile())); | 912 item.signed_in && profiles::IsLockAvailable(browser_->profile())); |
| 909 current_profile_view = CreateCurrentProfileView(item, false); | 913 current_profile_view = CreateCurrentProfileView(item, false); |
| 910 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 914 if (IsProfileChooser(view_mode_)) { |
| 911 switch (tutorial_mode_) { | 915 switch (tutorial_mode_) { |
| 912 case profiles::TUTORIAL_MODE_NONE: | 916 case profiles::TUTORIAL_MODE_NONE: |
| 913 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: | 917 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: |
| 914 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( | 918 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( |
| 915 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, | 919 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, |
| 916 item); | 920 item); |
| 917 break; | 921 break; |
| 918 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: | 922 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: |
| 919 tutorial_view = CreateSigninConfirmationView(); | 923 tutorial_view = CreateSigninConfirmationView(); |
| 920 break; | 924 break; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 940 | 944 |
| 941 if (!current_profile_view) { | 945 if (!current_profile_view) { |
| 942 // Guest windows don't have an active profile. | 946 // Guest windows don't have an active profile. |
| 943 current_profile_view = CreateGuestProfileView(); | 947 current_profile_view = CreateGuestProfileView(); |
| 944 option_buttons_view = CreateOptionsView(false); | 948 option_buttons_view = CreateOptionsView(false); |
| 945 } | 949 } |
| 946 | 950 |
| 947 layout->StartRow(1, 0); | 951 layout->StartRow(1, 0); |
| 948 layout->AddView(current_profile_view); | 952 layout->AddView(current_profile_view); |
| 949 | 953 |
| 950 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 954 if (!IsProfileChooser(view_mode_)) { |
| 951 DCHECK(current_profile_accounts); | 955 DCHECK(current_profile_accounts); |
| 952 layout->StartRow(0, 0); | 956 layout->StartRow(0, 0); |
| 953 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 957 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 954 layout->StartRow(1, 0); | 958 layout->StartRow(1, 0); |
| 955 layout->AddView(current_profile_accounts); | 959 layout->AddView(current_profile_accounts); |
| 956 } | 960 } |
| 957 | 961 |
| 958 if (browser_->profile()->IsSupervised()) { | 962 if (browser_->profile()->IsSupervised()) { |
| 959 layout->StartRow(0, 0); | 963 layout->StartRow(0, 0); |
| 960 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 964 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 961 layout->StartRow(1, 0); | 965 layout->StartRow(1, 0); |
| 962 layout->AddView(CreateSupervisedUserDisclaimerView()); | 966 layout->AddView(CreateSupervisedUserDisclaimerView()); |
| 963 } | 967 } |
| 964 | 968 |
| 965 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 969 if (IsProfileChooser(view_mode_)) { |
| 966 layout->StartRow(1, 0); | 970 layout->StartRow(1, 0); |
| 967 if (switches::IsFastUserSwitching()) | 971 if (switches::IsFastUserSwitching()) { |
| 968 layout->AddView(CreateOtherProfilesView(other_profiles)); | 972 layout->AddView(CreateOtherProfilesView(other_profiles)); |
| 973 } |
| 969 } | 974 } |
| 970 | 975 |
| 971 layout->StartRow(0, 0); | 976 layout->StartRow(0, 0); |
| 972 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 977 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 973 | 978 |
| 974 if (option_buttons_view) { | 979 if (option_buttons_view) { |
| 975 layout->StartRow(0, 0); | 980 layout->StartRow(0, 0); |
| 976 layout->AddView(option_buttons_view); | 981 layout->AddView(option_buttons_view); |
| 977 } | 982 } |
| 983 } |
| 984 |
| 985 void ProfileChooserView::PopulateMinimalProfileChooserView( |
| 986 views::GridLayout* layout, |
| 987 AvatarMenu* avatar_menu) { |
| 988 Indexes other_profiles; |
| 989 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| 990 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| 991 if (!item.active) { |
| 992 other_profiles.push_back(i); |
| 993 } |
| 994 } |
| 995 |
| 996 layout->StartRow(1, 0); |
| 997 layout->AddView(CreateOtherProfilesView(other_profiles)); |
| 998 } |
| 999 |
| 1000 views::View* ProfileChooserView::CreateProfileChooserView( |
| 1001 AvatarMenu* avatar_menu) { |
| 1002 views::View* view = new views::View(); |
| 1003 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 1004 |
| 1005 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) |
| 1006 PopulateMinimalProfileChooserView(layout, avatar_menu); |
| 1007 else |
| 1008 PopulateCompleteProfileChooserView(layout, avatar_menu); |
| 978 | 1009 |
| 979 return view; | 1010 return view; |
| 980 } | 1011 } |
| 981 | 1012 |
| 982 void ProfileChooserView::DismissTutorial() { | 1013 void ProfileChooserView::DismissTutorial() { |
| 983 // Never shows the upgrade tutorial again if manually closed. | 1014 // Never shows the upgrade tutorial again if manually closed. |
| 984 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | 1015 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
| 985 browser_->profile()->GetPrefs()->SetInteger( | 1016 browser_->profile()->GetPrefs()->SetInteger( |
| 986 prefs::kProfileAvatarTutorialShown, | 1017 prefs::kProfileAvatarTutorialShown, |
| 987 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); | 1018 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 layout->AddView(current_profile_name_); | 1186 layout->AddView(current_profile_name_); |
| 1156 | 1187 |
| 1157 if (is_guest) | 1188 if (is_guest) |
| 1158 return view; | 1189 return view; |
| 1159 | 1190 |
| 1160 // The available links depend on the type of profile that is active. | 1191 // The available links depend on the type of profile that is active. |
| 1161 if (avatar_item.signed_in) { | 1192 if (avatar_item.signed_in) { |
| 1162 layout->StartRow(1, 0); | 1193 layout->StartRow(1, 0); |
| 1163 if (switches::IsEnableAccountConsistency()) { | 1194 if (switches::IsEnableAccountConsistency()) { |
| 1164 base::string16 link_title = l10n_util::GetStringUTF16( | 1195 base::string16 link_title = l10n_util::GetStringUTF16( |
| 1165 view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? | 1196 IsProfileChooser(view_mode_) ? |
| 1166 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : | 1197 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
| 1167 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | 1198 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 1168 manage_accounts_link_ = CreateLink(link_title, this); | 1199 manage_accounts_link_ = CreateLink(link_title, this); |
| 1169 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 1200 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 1170 layout->AddView(manage_accounts_link_); | 1201 layout->AddView(manage_accounts_link_); |
| 1171 } else { | 1202 } else { |
| 1172 // Badge the email address if there's an authentication error. | 1203 // Badge the email address if there's an authentication error. |
| 1173 if (HasAuthError(browser_->profile())) { | 1204 if (HasAuthError(browser_->profile())) { |
| 1174 const gfx::ImageSkia warning_image = *rb->GetImageNamed( | 1205 const gfx::ImageSkia warning_image = *rb->GetImageNamed( |
| 1175 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia(); | 1206 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia(); |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 1705 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 1675 IncognitoModePrefs::DISABLED; | 1706 IncognitoModePrefs::DISABLED; |
| 1676 return incognito_available && !browser_->profile()->IsGuestSession(); | 1707 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 1677 } | 1708 } |
| 1678 | 1709 |
| 1679 void ProfileChooserView::PostActionPerformed( | 1710 void ProfileChooserView::PostActionPerformed( |
| 1680 ProfileMetrics::ProfileDesktopMenu action_performed) { | 1711 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 1681 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 1712 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 1682 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 1713 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 1683 } | 1714 } |
| OLD | NEW |