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 "components/signin/core/browser/signin_header_helper.h"
17 #include "content/public/browser/web_contents_delegate.h"
18 #include "google_apis/gaia/oauth2_token_service.h"
19 #include "ui/views/bubble/bubble_delegate.h"
20 #include "ui/views/controls/button/button.h"
21 #include "ui/views/controls/link_listener.h"
22 #include "ui/views/controls/styled_label_listener.h"
23 #include "ui/views/controls/textfield/textfield_controller.h"
25 class EditableProfilePhoto
;
26 class EditableProfileName
;
41 // This bubble view is displayed when the user clicks on the avatar button.
42 // It displays a list of profiles and allows users to switch between profiles.
43 class ProfileChooserView
: public content::WebContentsDelegate
,
44 public views::BubbleDelegateView
,
45 public views::ButtonListener
,
46 public views::LinkListener
,
47 public views::StyledLabelListener
,
48 public views::TextfieldController
,
49 public AvatarMenuObserver
,
50 public OAuth2TokenService::Observer
{
52 // Shows the bubble if one is not already showing. This allows us to easily
53 // make a button toggle the bubble on and off when clicked: we unconditionally
54 // call this function when the button is clicked and if the bubble isn't
55 // showing it will appear while if it is showing, nothing will happen here and
56 // the existing bubble will auto-close due to focus loss.
57 static void ShowBubble(
58 profiles::BubbleViewMode view_mode
,
59 profiles::TutorialMode tutorial_mode
,
60 const signin::ManageAccountsParams
& manage_accounts_params
,
61 views::View
* anchor_view
,
62 views::BubbleBorder::Arrow arrow
,
63 views::BubbleBorder::BubbleAlignment border_alignment
,
65 static bool IsShowing();
69 friend class ProfileChooserViewExtensionsTest
;
71 typedef std::vector
<size_t> Indexes
;
72 typedef std::map
<views::Button
*, int> ButtonIndexes
;
73 typedef std::map
<views::Button
*, std::string
> AccountButtonIndexes
;
75 ProfileChooserView(views::View
* anchor_view
,
76 views::BubbleBorder::Arrow arrow
,
78 profiles::BubbleViewMode view_mode
,
79 profiles::TutorialMode tutorial_mode
,
80 signin::GAIAServiceType service_type
);
81 ~ProfileChooserView() override
;
83 // views::BubbleDelegateView:
85 void WindowClosing() override
;
86 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
87 views::View
* GetInitiallyFocusedView() override
;
89 // content::WebContentsDelegate:
90 bool HandleContextMenu(const content::ContextMenuParams
& params
) override
;
92 // views::ButtonListener:
93 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
95 // views::LinkListener:
96 void LinkClicked(views::Link
* sender
, int event_flags
) override
;
98 // views::StyledLabelListener:
99 void StyledLabelLinkClicked(const gfx::Range
& range
,
100 int event_flags
) override
;
102 // views::TextfieldController:
103 bool HandleKeyEvent(views::Textfield
* sender
,
104 const ui::KeyEvent
& key_event
) override
;
106 // AvatarMenuObserver:
107 void OnAvatarMenuChanged(AvatarMenu
* avatar_menu
) override
;
109 // OAuth2TokenService::Observer overrides.
110 void OnRefreshTokenAvailable(const std::string
& account_id
) override
;
111 void OnRefreshTokenRevoked(const std::string
& account_id
) override
;
113 static ProfileChooserView
* profile_bubble_
;
115 // We normally close the bubble any time it becomes inactive but this can lead
116 // to flaky tests where unexpected UI events are triggering this behavior.
117 // Tests set this to "false" for more consistent operation.
118 static bool close_on_deactivate_for_testing_
;
122 // Shows the bubble with the |view_to_display|.
123 void ShowView(profiles::BubbleViewMode view_to_display
,
124 AvatarMenu
* avatar_menu
);
126 // Creates the profile chooser view.
127 views::View
* CreateProfileChooserView(AvatarMenu
* avatar_menu
);
129 // Populates |layout| with only a list of the profiles available to
131 void PopulateMinimalProfileChooserView(views::GridLayout
* layout
,
132 AvatarMenu
* avatar_menu
);
134 // Populates |layout| with all the elements of the Avatar Menu (current user
135 // bubble, options buttons, tutorials).
136 void PopulateCompleteProfileChooserView(views::GridLayout
* layout
,
137 AvatarMenu
* avatar_menu
);
139 // Creates the main profile card for the profile |avatar_item|. |is_guest|
140 // is used to determine whether to show any Sign in/Sign out/Manage accounts
142 views::View
* CreateCurrentProfileView(
143 const AvatarMenu::Item
& avatar_item
,
145 views::View
* CreateGuestProfileView();
146 views::View
* CreateOtherProfilesView(const Indexes
& avatars_to_show
);
147 views::View
* CreateOptionsView(bool display_lock
);
148 views::View
* CreateSupervisedUserDisclaimerView();
150 // Account Management view for the profile |avatar_item|.
151 views::View
* CreateCurrentProfileAccountsView(
152 const AvatarMenu::Item
& avatar_item
);
153 void CreateAccountButton(views::GridLayout
* layout
,
154 const std::string
& account_id
,
155 bool is_primary_account
,
156 bool reauth_required
,
159 // Creates a webview showing the gaia signin page.
160 views::View
* CreateGaiaSigninView(views::View
** signin_content_view
);
162 // Creates a view to confirm account removal for |account_id_to_remove_|.
163 views::View
* CreateAccountRemovalView();
165 // Removes the currently selected account and attempts to restart Chrome.
166 void RemoveAccount();
168 // Close the tutorial card.
169 void DismissTutorial();
171 // Creates a tutorial card to introduce an upgrade user to the new avatar
172 // menu. |avatar_item| refers to the current profile.
173 views::View
* CreateWelcomeUpgradeTutorialView(
174 const AvatarMenu::Item
& avatar_item
);
176 // Creates a tutorial card to have the user confirm the last Chrome signin,
177 // Chrome sync will be delayed until the user either dismisses the tutorial,
178 // or configures sync through the "Settings" link.
179 views::View
* CreateSigninConfirmationView();
181 // Creates a tutorial card to show the errors in the last Chrome signin.
182 views::View
* CreateSigninErrorView();
184 // Creates a tutorial card telling the user about right-click user switching.
185 views::View
* CreateRightClickTutorialView();
187 views::View
* CreateTutorialViewIfNeeded(const AvatarMenu::Item
& item
);
189 // Creates a tutorial card. If |stack_button| is true, places the button above
190 // the link otherwise places both on the same row with the link left aligned
191 // and button right aligned. The method sets |link| to point to the newly
192 // create link, |button| to the newly created button, and |tutorial_mode_| to
193 // the given |tutorial_mode|.
194 views::View
* CreateTutorialView(
195 profiles::TutorialMode tutorial_mode
,
196 const base::string16
& title_text
,
197 const base::string16
& content_text
,
198 const base::string16
& link_text
,
199 const base::string16
& button_text
,
202 views::LabelButton
** button
,
203 views::ImageButton
** close_button
);
205 // Create a view that shows various options for an upgrade user who is not
206 // the same person as the currently signed in user.
207 views::View
* CreateSwitchUserView();
209 bool ShouldShowGoIncognito() const;
211 // Clean-up done after an action was performed in the ProfileChooser.
212 void PostActionPerformed(ProfileMetrics::ProfileDesktopMenu action_performed
);
214 scoped_ptr
<AvatarMenu
> avatar_menu_
;
217 // Other profiles used in the "fast profile switcher" view.
218 ButtonIndexes open_other_profile_indexes_map_
;
220 // Buttons associated with the current profile.
221 AccountButtonIndexes delete_account_button_map_
;
222 AccountButtonIndexes reauth_account_button_map_
;
224 // Links and buttons displayed in the tutorial card.
225 views::LabelButton
* tutorial_sync_settings_ok_button_
;
226 views::Link
* tutorial_sync_settings_link_
;
227 views::LabelButton
* tutorial_see_whats_new_button_
;
228 views::Link
* tutorial_not_you_link_
;
229 views::Link
* tutorial_learn_more_link_
;
230 views::ImageButton
* tutorial_close_button_
;
232 // Links and buttons displayed in the active profile card.
233 views::Link
* manage_accounts_link_
;
234 views::LabelButton
* signin_current_profile_link_
;
235 views::LabelButton
* auth_error_email_button_
;
237 // The profile name and photo in the active profile card. Owned by the
239 EditableProfilePhoto
* current_profile_photo_
;
240 EditableProfileName
* current_profile_name_
;
243 views::LabelButton
* users_button_
;
244 views::LabelButton
* go_incognito_button_
;
245 views::LabelButton
* lock_button_
;
246 views::Link
* add_account_link_
;
248 // Buttons displayed in the gaia signin view.
249 views::ImageButton
* gaia_signin_cancel_button_
;
251 // Links and buttons displayed in the account removal view.
252 views::LabelButton
* remove_account_button_
;
253 views::ImageButton
* account_removal_cancel_button_
;
255 // Buttons in the switch user view.
256 views::LabelButton
* add_person_button_
;
257 views::LabelButton
* disconnect_button_
;
258 views::ImageButton
* switch_user_cancel_button_
;
260 // Records the account id to remove.
261 std::string account_id_to_remove_
;
264 profiles::BubbleViewMode view_mode_
;
266 // The current tutorial mode.
267 profiles::TutorialMode tutorial_mode_
;
269 // The GAIA service type provided in the response header.
270 signin::GAIAServiceType gaia_service_type_
;
272 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView
);
275 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_