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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_
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"
23 class EditableProfilePhoto;
24 class EditableProfileName;
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.
41 class 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 {
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,
62 static bool IsShowing();
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;
73 friend class NewAvatarMenuButtonTest;
74 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut);
76 typedef std::vector<size_t> Indexes;
77 typedef std::map<views::Button*, int> ButtonIndexes;
78 typedef std::map<views::Button*, std::string> AccountButtonIndexes;
80 ProfileChooserView(views::View* anchor_view,
81 views::BubbleBorder::Arrow arrow,
83 profiles::BubbleViewMode view_mode,
84 profiles::TutorialMode tutorial_mode,
85 signin::GAIAServiceType service_type);
86 virtual ~ProfileChooserView();
88 // views::BubbleDelegateView:
89 virtual void Init() OVERRIDE;
90 virtual void WindowClosing() OVERRIDE;
91 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
93 // views::ButtonListener:
94 virtual void ButtonPressed(views::Button* sender,
95 const ui::Event& event) OVERRIDE;
97 // views::LinkListener:
98 virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE;
100 // views::StyledLabelListener:
101 virtual void StyledLabelLinkClicked(
102 const gfx::Range& range, int event_flags) OVERRIDE;
104 // views::TextfieldController:
105 virtual bool HandleKeyEvent(views::Textfield* sender,
106 const ui::KeyEvent& key_event) OVERRIDE;
108 // AvatarMenuObserver:
109 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE;
111 // OAuth2TokenService::Observer overrides.
112 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
113 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
115 static ProfileChooserView* profile_bubble_;
116 static bool close_on_deactivate_for_testing_;
120 // Shows the bubble with the |view_to_display|.
121 void ShowView(profiles::BubbleViewMode view_to_display,
122 AvatarMenu* avatar_menu);
124 // Creates the profile chooser view.
125 views::View* CreateProfileChooserView(AvatarMenu* avatar_menu);
127 // Creates the main profile card for the profile |avatar_item|. |is_guest|
128 // is used to determine whether to show any Sign in/Sign out/Manage accounts
130 views::View* CreateCurrentProfileView(
131 const AvatarMenu::Item& avatar_item,
133 views::View* CreateGuestProfileView();
134 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show);
135 views::View* CreateOptionsView(bool display_lock);
136 views::View* CreateSupervisedUserDisclaimerView();
138 // Account Management view for the profile |avatar_item|.
139 views::View* CreateCurrentProfileAccountsView(
140 const AvatarMenu::Item& avatar_item);
141 void CreateAccountButton(views::GridLayout* layout,
142 const std::string& account_id,
143 bool is_primary_account,
144 bool reauth_required,
147 // Creates a webview showing the gaia signin page.
148 views::View* CreateGaiaSigninView();
150 // Creates a view to confirm account removal for |account_id_to_remove_|.
151 views::View* CreateAccountRemovalView();
153 // Removes the currently selected account and attempts to restart Chrome.
154 void RemoveAccount();
156 // Close the tutorial card.
157 void DismissTutorial();
159 // Creates a tutorial card to introduce an upgrade user to the new avatar
160 // menu if needed. |tutorial_shown| indicates if the tutorial has already been
161 // shown in the previous active view. |avatar_item| refers to the current
163 views::View* CreateWelcomeUpgradeTutorialViewIfNeeded(
164 bool tutorial_shown, const AvatarMenu::Item& avatar_item);
166 // Creates a tutorial card to have the user confirm the last Chrome signin,
167 // Chrome sync will be delayed until the user either dismisses the tutorial,
168 // or configures sync through the "Settings" link.
169 views::View* CreateSigninConfirmationView();
171 // Creates a a tutorial card to show the errors in the last Chrome signin.
172 views::View* CreateSigninErrorView();
174 // Creates a tutorial card. If |stack_button| is true, places the button above
175 // the link otherwise places both on the same row with the link left aligned
176 // and button right aligned. The method sets |link| to point to the newly
177 // create link, |button| to the newly created button, and |tutorial_mode_| to
178 // the given |tutorial_mode|.
179 views::View* CreateTutorialView(
180 profiles::TutorialMode tutorial_mode,
181 const base::string16& title_text,
182 const base::string16& content_text,
183 const base::string16& link_text,
184 const base::string16& button_text,
187 views::LabelButton** button,
188 views::ImageButton** close_button);
190 // Create a view that shows various options for an upgrade user who is not
191 // the same person as the currently signed in user.
192 views::View* CreateSwitchUserView();
194 bool ShouldShowGoIncognito() const;
196 // Clean-up done after an action was performed in the ProfileChooser.
197 void PostActionPerformed(ProfileMetrics::ProfileDesktopMenu action_performed);
199 scoped_ptr<AvatarMenu> avatar_menu_;
202 // Other profiles used in the "fast profile switcher" view.
203 ButtonIndexes open_other_profile_indexes_map_;
205 // Buttons associated with the current profile.
206 AccountButtonIndexes delete_account_button_map_;
207 AccountButtonIndexes reauth_account_button_map_;
209 // Links and buttons displayed in the tutorial card.
210 views::LabelButton* tutorial_sync_settings_ok_button_;
211 views::Link* tutorial_sync_settings_link_;
212 views::LabelButton* tutorial_see_whats_new_button_;
213 views::Link* tutorial_not_you_link_;
214 views::Link* tutorial_learn_more_link_;
215 views::ImageButton* tutorial_close_button_;
217 // Links and buttons displayed in the active profile card.
218 views::Link* manage_accounts_link_;
219 views::LabelButton* signin_current_profile_link_;
220 views::LabelButton* auth_error_email_button_;
222 // The profile name and photo in the active profile card. Owned by the
224 EditableProfilePhoto* current_profile_photo_;
225 EditableProfileName* current_profile_name_;
228 views::LabelButton* users_button_;
229 views::LabelButton* go_incognito_button_;
230 views::LabelButton* lock_button_;
231 views::Link* add_account_link_;
233 // Buttons displayed in the gaia signin view.
234 views::ImageButton* gaia_signin_cancel_button_;
236 // Links and buttons displayed in the account removal view.
237 views::LabelButton* remove_account_button_;
238 views::ImageButton* account_removal_cancel_button_;
240 // Buttons in the switch user view.
241 views::LabelButton* add_person_button_;
242 views::LabelButton* disconnect_button_;
243 views::ImageButton* switch_user_cancel_button_;
245 // Records the account id to remove.
246 std::string account_id_to_remove_;
249 profiles::BubbleViewMode view_mode_;
251 // The current tutorial mode.
252 profiles::TutorialMode tutorial_mode_;
254 // The GAIA service type provided in the response header.
255 signin::GAIAServiceType gaia_service_type_;
257 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView);
260 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_