Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / profiles / profile_chooser_view.h
blobd9b59812d1169b414a1797ffc4ee645fc86132d6
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_
8 #include <map>
9 #include <vector>
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 "content/public/browser/web_contents_delegate.h"
17 #include "google_apis/gaia/oauth2_token_service.h"
18 #include "ui/views/bubble/bubble_delegate.h"
19 #include "ui/views/controls/button/button.h"
20 #include "ui/views/controls/link_listener.h"
21 #include "ui/views/controls/styled_label_listener.h"
22 #include "ui/views/controls/textfield/textfield_controller.h"
24 class EditableProfilePhoto;
25 class EditableProfileName;
27 namespace gfx {
28 class Image;
31 namespace views {
32 class GridLayout;
33 class ImageButton;
34 class Link;
35 class LabelButton;
38 class Browser;
40 // This bubble view is displayed when the user clicks on the avatar button.
41 // It displays a list of profiles and allows users to switch between profiles.
42 class ProfileChooserView : public content::WebContentsDelegate,
43 public views::BubbleDelegateView,
44 public views::ButtonListener,
45 public views::LinkListener,
46 public views::StyledLabelListener,
47 public views::TextfieldController,
48 public AvatarMenuObserver,
49 public OAuth2TokenService::Observer {
50 public:
51 // Shows the bubble if one is not already showing. This allows us to easily
52 // make a button toggle the bubble on and off when clicked: we unconditionally
53 // call this function when the button is clicked and if the bubble isn't
54 // showing it will appear while if it is showing, nothing will happen here and
55 // the existing bubble will auto-close due to focus loss.
56 static void ShowBubble(
57 profiles::BubbleViewMode view_mode,
58 profiles::TutorialMode tutorial_mode,
59 const signin::ManageAccountsParams& manage_accounts_params,
60 views::View* anchor_view,
61 views::BubbleBorder::Arrow arrow,
62 views::BubbleBorder::BubbleAlignment border_alignment,
63 Browser* browser);
64 static bool IsShowing();
65 static void Hide();
67 private:
68 friend class ProfileChooserViewExtensionsTest;
70 typedef std::vector<size_t> Indexes;
71 typedef std::map<views::Button*, int> ButtonIndexes;
72 typedef std::map<views::Button*, std::string> AccountButtonIndexes;
74 ProfileChooserView(views::View* anchor_view,
75 views::BubbleBorder::Arrow arrow,
76 Browser* browser,
77 profiles::BubbleViewMode view_mode,
78 profiles::TutorialMode tutorial_mode,
79 signin::GAIAServiceType service_type);
80 ~ProfileChooserView() override;
82 // views::BubbleDelegateView:
83 void Init() override;
84 void WindowClosing() override;
85 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
87 // content::WebContentsDelegate:
88 bool HandleContextMenu(const content::ContextMenuParams& params) override;
90 // views::ButtonListener:
91 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
93 // views::LinkListener:
94 void LinkClicked(views::Link* sender, int event_flags) override;
96 // views::StyledLabelListener:
97 void StyledLabelLinkClicked(const gfx::Range& range,
98 int event_flags) override;
100 // views::TextfieldController:
101 bool HandleKeyEvent(views::Textfield* sender,
102 const ui::KeyEvent& key_event) override;
104 // AvatarMenuObserver:
105 void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override;
107 // OAuth2TokenService::Observer overrides.
108 void OnRefreshTokenAvailable(const std::string& account_id) override;
109 void OnRefreshTokenRevoked(const std::string& account_id) override;
111 static ProfileChooserView* profile_bubble_;
113 // We normally close the bubble any time it becomes inactive but this can lead
114 // to flaky tests where unexpected UI events are triggering this behavior.
115 // Tests set this to "false" for more consistent operation.
116 static bool close_on_deactivate_for_testing_;
118 void ResetView();
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 // Populates |layout| with only a list of the profiles available to
128 // switch to.
129 void PopulateMinimalProfileChooserView(views::GridLayout* layout,
130 AvatarMenu* avatar_menu);
132 // Populates |layout| with all the elements of the Avatar Menu (current user
133 // bubble, options buttons, tutorials).
134 void PopulateCompleteProfileChooserView(views::GridLayout* layout,
135 AvatarMenu* avatar_menu);
137 // Creates the main profile card for the profile |avatar_item|. |is_guest|
138 // is used to determine whether to show any Sign in/Sign out/Manage accounts
139 // links.
140 views::View* CreateCurrentProfileView(
141 const AvatarMenu::Item& avatar_item,
142 bool is_guest);
143 views::View* CreateGuestProfileView();
144 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show);
145 views::View* CreateOptionsView(bool display_lock);
146 views::View* CreateSupervisedUserDisclaimerView();
148 // Account Management view for the profile |avatar_item|.
149 views::View* CreateCurrentProfileAccountsView(
150 const AvatarMenu::Item& avatar_item);
151 void CreateAccountButton(views::GridLayout* layout,
152 const std::string& account_id,
153 bool is_primary_account,
154 bool reauth_required,
155 int width);
157 // Creates a webview showing the gaia signin page.
158 views::View* CreateGaiaSigninView();
160 // Creates a view to confirm account removal for |account_id_to_remove_|.
161 views::View* CreateAccountRemovalView();
163 // Removes the currently selected account and attempts to restart Chrome.
164 void RemoveAccount();
166 // Close the tutorial card.
167 void DismissTutorial();
169 // Creates a tutorial card to introduce an upgrade user to the new avatar
170 // menu if needed. |tutorial_shown| indicates if the tutorial has already been
171 // shown in the previous active view. |avatar_item| refers to the current
172 // profile.
173 views::View* CreateWelcomeUpgradeTutorialViewIfNeeded(
174 bool tutorial_shown, 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 a tutorial card to show the errors in the last Chrome signin.
182 views::View* CreateSigninErrorView();
184 // Creates a tutorial card. If |stack_button| is true, places the button above
185 // the link otherwise places both on the same row with the link left aligned
186 // and button right aligned. The method sets |link| to point to the newly
187 // create link, |button| to the newly created button, and |tutorial_mode_| to
188 // the given |tutorial_mode|.
189 views::View* CreateTutorialView(
190 profiles::TutorialMode tutorial_mode,
191 const base::string16& title_text,
192 const base::string16& content_text,
193 const base::string16& link_text,
194 const base::string16& button_text,
195 bool stack_button,
196 views::Link** link,
197 views::LabelButton** button,
198 views::ImageButton** close_button);
200 // Create a view that shows various options for an upgrade user who is not
201 // the same person as the currently signed in user.
202 views::View* CreateSwitchUserView();
204 bool ShouldShowGoIncognito() const;
206 // Clean-up done after an action was performed in the ProfileChooser.
207 void PostActionPerformed(ProfileMetrics::ProfileDesktopMenu action_performed);
209 scoped_ptr<AvatarMenu> avatar_menu_;
210 Browser* browser_;
212 // Other profiles used in the "fast profile switcher" view.
213 ButtonIndexes open_other_profile_indexes_map_;
215 // Buttons associated with the current profile.
216 AccountButtonIndexes delete_account_button_map_;
217 AccountButtonIndexes reauth_account_button_map_;
219 // Links and buttons displayed in the tutorial card.
220 views::LabelButton* tutorial_sync_settings_ok_button_;
221 views::Link* tutorial_sync_settings_link_;
222 views::LabelButton* tutorial_see_whats_new_button_;
223 views::Link* tutorial_not_you_link_;
224 views::Link* tutorial_learn_more_link_;
225 views::ImageButton* tutorial_close_button_;
227 // Links and buttons displayed in the active profile card.
228 views::Link* manage_accounts_link_;
229 views::LabelButton* signin_current_profile_link_;
230 views::LabelButton* auth_error_email_button_;
232 // The profile name and photo in the active profile card. Owned by the
233 // views hierarchy.
234 EditableProfilePhoto* current_profile_photo_;
235 EditableProfileName* current_profile_name_;
237 // Action buttons.
238 views::LabelButton* users_button_;
239 views::LabelButton* go_incognito_button_;
240 views::LabelButton* lock_button_;
241 views::Link* add_account_link_;
243 // Buttons displayed in the gaia signin view.
244 views::ImageButton* gaia_signin_cancel_button_;
246 // Links and buttons displayed in the account removal view.
247 views::LabelButton* remove_account_button_;
248 views::ImageButton* account_removal_cancel_button_;
250 // Buttons in the switch user view.
251 views::LabelButton* add_person_button_;
252 views::LabelButton* disconnect_button_;
253 views::ImageButton* switch_user_cancel_button_;
255 // Records the account id to remove.
256 std::string account_id_to_remove_;
258 // Active view mode.
259 profiles::BubbleViewMode view_mode_;
261 // The current tutorial mode.
262 profiles::TutorialMode tutorial_mode_;
264 // The GAIA service type provided in the response header.
265 signin::GAIAServiceType gaia_service_type_;
267 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView);
270 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_