profile_chooser_view.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ 7 8#include <map> 9#include <vector> 10 11#include "chrome/browser/profiles/avatar_menu.h" 12#include "chrome/browser/profiles/avatar_menu_observer.h" 13#include "chrome/browser/profiles/profile_metrics.h" 14#include "chrome/browser/ui/browser_window.h" 15#include "chrome/browser/ui/profile_chooser_constants.h" 16#include "google_apis/gaia/oauth2_token_service.h" 17#include "ui/views/bubble/bubble_delegate.h" 18#include "ui/views/controls/button/button.h" 19#include "ui/views/controls/link_listener.h" 20#include "ui/views/controls/styled_label_listener.h" 21#include "ui/views/controls/textfield/textfield_controller.h" 22 23class EditableProfilePhoto; 24class EditableProfileName; 25 26namespace gfx { 27class Image; 28} 29 30namespace views { 31class GridLayout; 32class ImageButton; 33class Link; 34class LabelButton; 35} 36 37class Browser; 38 39// This bubble view is displayed when the user clicks on the avatar button. 40// It displays a list of profiles and allows users to switch between profiles. 41class ProfileChooserView : public views::BubbleDelegateView, 42 public views::ButtonListener, 43 public views::LinkListener, 44 public views::StyledLabelListener, 45 public views::TextfieldController, 46 public AvatarMenuObserver, 47 public OAuth2TokenService::Observer { 48 public: 49 // Shows the bubble if one is not already showing. This allows us to easily 50 // make a button toggle the bubble on and off when clicked: we unconditionally 51 // call this function when the button is clicked and if the bubble isn't 52 // showing it will appear while if it is showing, nothing will happen here and 53 // the existing bubble will auto-close due to focus loss. 54 static void ShowBubble( 55 profiles::BubbleViewMode view_mode, 56 profiles::TutorialMode tutorial_mode, 57 const signin::ManageAccountsParams& manage_accounts_params, 58 views::View* anchor_view, 59 views::BubbleBorder::Arrow arrow, 60 views::BubbleBorder::BubbleAlignment border_alignment, 61 Browser* browser); 62 static bool IsShowing(); 63 static void Hide(); 64 65 // We normally close the bubble any time it becomes inactive but this can lead 66 // to flaky tests where unexpected UI events are triggering this behavior. 67 // Tests should call this with "false" for more consistent operation. 68 static void clear_close_on_deactivate_for_testing() { 69 close_on_deactivate_for_testing_ = false; 70 } 71 72 private: 73 friend class NewAvatarMenuButtonTest; 74 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut); 75 76 typedef std::vector<size_t> Indexes; 77 typedef std::map<views::Button*, int> ButtonIndexes; 78 typedef std::map<views::Button*, std::string> AccountButtonIndexes; 79 80 ProfileChooserView(views::View* anchor_view, 81 views::BubbleBorder::Arrow arrow, 82 Browser* browser, 83 profiles::BubbleViewMode view_mode, 84 profiles::TutorialMode tutorial_mode, 85 signin::GAIAServiceType service_type); 86 virtual ~ProfileChooserView(); 87 88 // views::BubbleDelegateView: 89 virtual void Init() OVERRIDE; 90 virtual void WindowClosing() OVERRIDE; 91 92 // views::ButtonListener: 93 virtual void ButtonPressed(views::Button* sender, 94 const ui::Event& event) OVERRIDE; 95 96 // views::LinkListener: 97 virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE; 98 99 // views::StyledLabelListener implementation. 100 virtual void StyledLabelLinkClicked( 101 const gfx::Range& range, int event_flags) OVERRIDE; 102 103 // views::TextfieldController: 104 virtual bool HandleKeyEvent(views::Textfield* sender, 105 const ui::KeyEvent& key_event) OVERRIDE; 106 107 // AvatarMenuObserver: 108 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE; 109 110 // OAuth2TokenService::Observer overrides. 111 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; 112 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; 113 114 static ProfileChooserView* profile_bubble_; 115 static bool close_on_deactivate_for_testing_; 116 117 void ResetView(); 118 119 // Shows the bubble with the |view_to_display|. 120 void ShowView(profiles::BubbleViewMode view_to_display, 121 AvatarMenu* avatar_menu); 122 123 // Creates the profile chooser view. 124 views::View* CreateProfileChooserView(AvatarMenu* avatar_menu); 125 126 // Creates the main profile card for the profile |avatar_item|. |is_guest| 127 // is used to determine whether to show any Sign in/Sign out/Manage accounts 128 // links. 129 views::View* CreateCurrentProfileView( 130 const AvatarMenu::Item& avatar_item, 131 bool is_guest); 132 views::View* CreateGuestProfileView(); 133 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show); 134 views::View* CreateOptionsView(bool enable_lock); 135 views::View* CreateSupervisedUserDisclaimerView(); 136 137 // Account Management view for the profile |avatar_item|. 138 views::View* CreateCurrentProfileAccountsView( 139 const AvatarMenu::Item& avatar_item); 140 void CreateAccountButton(views::GridLayout* layout, 141 const std::string& account, 142 bool is_primary_account, 143 bool reauth_required, 144 int width); 145 146 // Creates a webview showing the gaia signin page. 147 views::View* CreateGaiaSigninView(); 148 149 // Creates a view to confirm account removal for |account_id_to_remove_|. 150 views::View* CreateAccountRemovalView(); 151 152 // Removes the currently selected account and attempts to restart Chrome. 153 void RemoveAccount(); 154 155 // Creates a tutorial card to introduce an upgrade user to the new avatar 156 // menu if needed. |tutorial_shown| indicates if the tutorial has already been 157 // shown in the previous active view. |avatar_item| refers to the current 158 // profile. 159 views::View* CreateWelcomeUpgradeTutorialViewIfNeeded( 160 bool tutorial_shown, const AvatarMenu::Item& avatar_item); 161 162 // Creates a tutorial card to have the user confirm the last Chrome signin, 163 // Chrome sync will be delayed until the user either dismisses the tutorial, 164 // or configures sync through the "Settings" link. 165 views::View* CreateSigninConfirmationView(); 166 167 // Creates a a tutorial card to show the errors in the last Chrome signin. 168 views::View* CreateSigninErrorView(); 169 170 // Creates a tutorial card with the specified |title_text|, |context_text|, 171 // and a bottom row with a right-aligned link using the specified |link_text|, 172 // and a left aligned button using the specified |button_text|. The method 173 // sets |link| to point to the newly created link, |button| to the newly 174 // created button, and |tutorial_mode_| to the given |tutorial_mode|. 175 views::View* CreateTutorialView( 176 profiles::TutorialMode tutorial_mode, 177 const base::string16& title_text, 178 const base::string16& content_text, 179 const base::string16& link_text, 180 const base::string16& button_text, 181 views::Link** link, 182 views::LabelButton** button); 183 184 // Create a view that shows various options for an upgrade user who is not 185 // the same person as the currently signed in user. 186 views::View* CreateSwitchUserView(); 187 188 bool ShouldShowGoIncognito() const; 189 190 // Clean-up done after an action was performed in the ProfileChooser. 191 void PostActionPerformed(ProfileMetrics::ProfileDesktopMenu action_performed); 192 193 scoped_ptr<AvatarMenu> avatar_menu_; 194 Browser* browser_; 195 196 // Other profiles used in the "fast profile switcher" view. 197 ButtonIndexes open_other_profile_indexes_map_; 198 199 // Buttons associated with the current profile. 200 AccountButtonIndexes delete_account_button_map_; 201 AccountButtonIndexes reauth_account_button_map_; 202 203 // Links and buttons displayed in the tutorial card. 204 views::LabelButton* tutorial_sync_settings_ok_button_; 205 views::Link* tutorial_sync_settings_link_; 206 views::LabelButton* tutorial_see_whats_new_button_; 207 views::Link* tutorial_not_you_link_; 208 209 // Links and buttons displayed in the active profile card. 210 views::Link* manage_accounts_link_; 211 views::LabelButton* signin_current_profile_link_; 212 views::LabelButton* auth_error_email_button_; 213 214 // The profile name and photo in the active profile card. Owned by the 215 // views hierarchy. 216 EditableProfilePhoto* current_profile_photo_; 217 EditableProfileName* current_profile_name_; 218 219 // Action buttons. 220 views::LabelButton* users_button_; 221 views::LabelButton* go_incognito_button_; 222 views::LabelButton* lock_button_; 223 views::Link* add_account_link_; 224 225 // Buttons displayed in the gaia signin view. 226 views::ImageButton* gaia_signin_cancel_button_; 227 228 // Links and buttons displayed in the account removal view. 229 views::LabelButton* remove_account_button_; 230 views::ImageButton* account_removal_cancel_button_; 231 232 // Buttons in the switch user view. 233 views::LabelButton* add_person_button_; 234 views::LabelButton* disconnect_button_; 235 views::ImageButton* switch_user_cancel_button_; 236 237 // Records the account id to remove. 238 std::string account_id_to_remove_; 239 240 // Active view mode. 241 profiles::BubbleViewMode view_mode_; 242 243 // The current tutorial mode. 244 profiles::TutorialMode tutorial_mode_; 245 246 // The GAIA service type provided in the response header. 247 signin::GAIAServiceType gaia_service_type_; 248 249 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView); 250}; 251 252#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ 253