profile_chooser_view.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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: 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 // Close the tutorial card. 156 void DismissTutorial(); 157 158 // Creates a tutorial card to introduce an upgrade user to the new avatar 159 // menu if needed. |tutorial_shown| indicates if the tutorial has already been 160 // shown in the previous active view. |avatar_item| refers to the current 161 // profile. 162 views::View* CreateWelcomeUpgradeTutorialViewIfNeeded( 163 bool tutorial_shown, const AvatarMenu::Item& avatar_item); 164 165 // Creates a tutorial card to have the user confirm the last Chrome signin, 166 // Chrome sync will be delayed until the user either dismisses the tutorial, 167 // or configures sync through the "Settings" link. 168 views::View* CreateSigninConfirmationView(); 169 170 // Creates a a tutorial card to show the errors in the last Chrome signin. 171 views::View* CreateSigninErrorView(); 172 173 // Creates a tutorial card. If |stack_button| is true, places the button above 174 // the link otherwise places both on the same row with the link left aligned 175 // and button right aligned. The method sets |link| to point to the newly 176 // create link, |button| to the newly created button, and |tutorial_mode_| to 177 // the given |tutorial_mode|. 178 views::View* CreateTutorialView( 179 profiles::TutorialMode tutorial_mode, 180 const base::string16& title_text, 181 const base::string16& content_text, 182 const base::string16& link_text, 183 const base::string16& button_text, 184 bool stack_button, 185 views::Link** link, 186 views::LabelButton** button, 187 views::ImageButton** close_button); 188 189 // Create a view that shows various options for an upgrade user who is not 190 // the same person as the currently signed in user. 191 views::View* CreateSwitchUserView(); 192 193 bool ShouldShowGoIncognito() const; 194 195 // Clean-up done after an action was performed in the ProfileChooser. 196 void PostActionPerformed(ProfileMetrics::ProfileDesktopMenu action_performed); 197 198 scoped_ptr<AvatarMenu> avatar_menu_; 199 Browser* browser_; 200 201 // Other profiles used in the "fast profile switcher" view. 202 ButtonIndexes open_other_profile_indexes_map_; 203 204 // Buttons associated with the current profile. 205 AccountButtonIndexes delete_account_button_map_; 206 AccountButtonIndexes reauth_account_button_map_; 207 208 // Links and buttons displayed in the tutorial card. 209 views::LabelButton* tutorial_sync_settings_ok_button_; 210 views::Link* tutorial_sync_settings_link_; 211 views::LabelButton* tutorial_see_whats_new_button_; 212 views::Link* tutorial_not_you_link_; 213 views::Link* tutorial_learn_more_link_; 214 views::ImageButton* tutorial_close_button_; 215 216 // Links and buttons displayed in the active profile card. 217 views::Link* manage_accounts_link_; 218 views::LabelButton* signin_current_profile_link_; 219 views::LabelButton* auth_error_email_button_; 220 221 // The profile name and photo in the active profile card. Owned by the 222 // views hierarchy. 223 EditableProfilePhoto* current_profile_photo_; 224 EditableProfileName* current_profile_name_; 225 226 // Action buttons. 227 views::LabelButton* users_button_; 228 views::LabelButton* go_incognito_button_; 229 views::LabelButton* lock_button_; 230 views::Link* add_account_link_; 231 232 // Buttons displayed in the gaia signin view. 233 views::ImageButton* gaia_signin_cancel_button_; 234 235 // Links and buttons displayed in the account removal view. 236 views::LabelButton* remove_account_button_; 237 views::ImageButton* account_removal_cancel_button_; 238 239 // Buttons in the switch user view. 240 views::LabelButton* add_person_button_; 241 views::LabelButton* disconnect_button_; 242 views::ImageButton* switch_user_cancel_button_; 243 244 // Records the account id to remove. 245 std::string account_id_to_remove_; 246 247 // Active view mode. 248 profiles::BubbleViewMode view_mode_; 249 250 // The current tutorial mode. 251 profiles::TutorialMode tutorial_mode_; 252 253 // The GAIA service type provided in the response header. 254 signin::GAIAServiceType gaia_service_type_; 255 256 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView); 257}; 258 259#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_ 260