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 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h"
11 #include "chrome/browser/prefs/incognito_mode_prefs.h"
12 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
13 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/profiles/profile_metrics.h"
16 #include "chrome/browser/profiles/profile_window.h"
17 #include "chrome/browser/profiles/profiles_state.h"
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
19 #include "chrome/browser/signin/signin_header_helper.h"
20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/signin/signin_promo.h"
22 #include "chrome/browser/signin/signin_ui_util.h"
23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_commands.h"
25 #include "chrome/browser/ui/browser_dialogs.h"
26 #include "chrome/browser/ui/chrome_pages.h"
27 #include "chrome/browser/ui/singleton_tabs.h"
28 #include "chrome/browser/ui/user_manager.h"
29 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
30 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
31 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
32 #include "chrome/common/pref_names.h"
33 #include "chrome/common/url_constants.h"
34 #include "chrome/grit/chromium_strings.h"
35 #include "chrome/grit/generated_resources.h"
36 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h"
37 #include "components/signin/core/browser/profile_oauth2_token_service.h"
38 #include "components/signin/core/browser/signin_error_controller.h"
39 #include "components/signin/core/browser/signin_manager.h"
40 #include "components/signin/core/common/profile_management_switches.h"
41 #include "content/public/browser/render_widget_host_view.h"
42 #include "grit/theme_resources.h"
43 #include "third_party/skia/include/core/SkColor.h"
44 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/gfx/canvas.h"
47 #include "ui/gfx/image/image.h"
48 #include "ui/gfx/image/image_skia.h"
49 #include "ui/gfx/path.h"
50 #include "ui/gfx/skia_util.h"
51 #include "ui/gfx/text_elider.h"
52 #include "ui/native_theme/native_theme.h"
53 #include "ui/views/controls/button/blue_button.h"
54 #include "ui/views/controls/button/image_button.h"
55 #include "ui/views/controls/button/label_button.h"
56 #include "ui/views/controls/button/label_button_border.h"
57 #include "ui/views/controls/button/menu_button.h"
58 #include "ui/views/controls/label.h"
59 #include "ui/views/controls/link.h"
60 #include "ui/views/controls/separator.h"
61 #include "ui/views/controls/styled_label.h"
62 #include "ui/views/controls/textfield/textfield.h"
63 #include "ui/views/controls/webview/webview.h"
64 #include "ui/views/layout/grid_layout.h"
65 #include "ui/views/layout/layout_constants.h"
66 #include "ui/views/widget/widget.h"
70 // Helpers --------------------------------------------------------------------
72 const int kFixedMenuWidth
= 250;
73 const int kButtonHeight
= 32;
74 const int kFixedGaiaViewHeight
= 440;
75 const int kFixedGaiaViewWidth
= 360;
76 const int kFixedAccountRemovalViewWidth
= 280;
77 const int kFixedSwitchUserViewWidth
= 320;
78 const int kLargeImageSide
= 88;
80 const int kVerticalSpacing
= 16;
82 // Creates a GridLayout with a single column. This ensures that all the child
83 // views added get auto-expanded to fill the full width of the bubble.
84 views::GridLayout
* CreateSingleColumnLayout(views::View
* view
, int width
) {
85 views::GridLayout
* layout
= new views::GridLayout(view
);
86 view
->SetLayoutManager(layout
);
88 views::ColumnSet
* columns
= layout
->AddColumnSet(0);
89 columns
->AddColumn(views::GridLayout::FILL
, views::GridLayout::FILL
, 0,
90 views::GridLayout::FIXED
, width
, width
);
94 views::Link
* CreateLink(const base::string16
& link_text
,
95 views::LinkListener
* listener
) {
96 views::Link
* link_button
= new views::Link(link_text
);
97 link_button
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
98 link_button
->SetUnderline(false);
99 link_button
->set_listener(listener
);
103 gfx::ImageSkia
CreateSquarePlaceholderImage(int size
) {
105 bitmap
.allocPixels(SkImageInfo::MakeA8(size
, size
));
106 bitmap
.eraseARGB(0, 0, 0, 0);
107 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap
);
110 bool HasAuthError(Profile
* profile
) {
111 const SigninErrorController
* error
=
112 profiles::GetSigninErrorController(profile
);
113 return error
&& error
->HasError();
116 std::string
GetAuthErrorAccountId(Profile
* profile
) {
117 const SigninErrorController
* error
=
118 profiles::GetSigninErrorController(profile
);
120 return std::string();
122 return error
->error_account_id();
125 std::string
GetAuthErrorUsername(Profile
* profile
) {
126 const SigninErrorController
* error
=
127 profiles::GetSigninErrorController(profile
);
129 return std::string();
131 return error
->error_username();
134 // BackgroundColorHoverButton -------------------------------------------------
136 // A custom button that allows for setting a background color when hovered over.
137 class BackgroundColorHoverButton
: public views::LabelButton
{
139 BackgroundColorHoverButton(views::ButtonListener
* listener
,
140 const base::string16
& text
,
141 const gfx::ImageSkia
& icon
)
142 : views::LabelButton(listener
, text
) {
143 SetImageLabelSpacing(views::kItemLabelSpacing
);
144 SetBorder(views::Border::CreateEmptyBorder(
145 0, views::kButtonHEdgeMarginNew
, 0, views::kButtonHEdgeMarginNew
));
146 SetMinSize(gfx::Size(0,
147 kButtonHeight
+ views::kRelatedControlVerticalSpacing
));
148 SetImage(STATE_NORMAL
, icon
);
152 ~BackgroundColorHoverButton() override
{}
155 // views::LabelButton:
156 void OnPaint(gfx::Canvas
* canvas
) override
{
157 if ((state() == STATE_PRESSED
) ||
158 (state() == STATE_HOVERED
)) {
159 canvas
->DrawColor(GetNativeTheme()->GetSystemColor(
160 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor
));
162 LabelButton::OnPaint(canvas
);
165 DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton
);
168 // SizedContainer -------------------------------------------------
170 // A simple container view that takes an explicit preferred size.
171 class SizedContainer
: public views::View
{
173 explicit SizedContainer(const gfx::Size
& preferred_size
)
174 : preferred_size_(preferred_size
) {}
176 gfx::Size
GetPreferredSize() const override
{ return preferred_size_
; }
179 gfx::Size preferred_size_
;
184 // RightAlignedIconLabelButton -------------------------------------------------
186 // A custom LabelButton that has a centered text and right aligned icon.
187 class RightAlignedIconLabelButton
: public views::LabelButton
{
189 RightAlignedIconLabelButton(views::ButtonListener
* listener
,
190 const base::string16
& text
)
191 : views::LabelButton(listener
, text
) {
195 void Layout() override
{
196 // This layout trick keeps the text left-aligned and the icon right-aligned.
197 SetHorizontalAlignment(gfx::ALIGN_RIGHT
);
198 views::LabelButton::Layout();
199 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER
);
203 DISALLOW_COPY_AND_ASSIGN(RightAlignedIconLabelButton
);
206 // EditableProfilePhoto -------------------------------------------------
208 // A custom Image control that shows a "change" button when moused over.
209 class EditableProfilePhoto
: public views::LabelButton
{
211 EditableProfilePhoto(views::ButtonListener
* listener
,
212 const gfx::Image
& icon
,
213 bool is_editing_allowed
,
214 const gfx::Rect
& bounds
)
215 : views::LabelButton(listener
, base::string16()),
216 photo_overlay_(NULL
) {
217 gfx::Image image
= profiles::GetSizedAvatarIcon(
218 icon
, true, kLargeImageSide
, kLargeImageSide
);
219 SetImage(views::LabelButton::STATE_NORMAL
, *image
.ToImageSkia());
220 SetBorder(views::Border::NullBorder());
221 SetBoundsRect(bounds
);
223 // Calculate the circular mask that will be used to display the photo.
224 circular_mask_
.addCircle(SkIntToScalar(bounds
.width() / 2),
225 SkIntToScalar(bounds
.height() / 2),
226 SkIntToScalar(bounds
.width() / 2));
228 if (!is_editing_allowed
) {
233 set_notify_enter_exit_on_child(true);
235 // Photo overlay that appears when hovering over the button.
236 photo_overlay_
= new views::ImageView();
238 const SkColor kBackgroundColor
= SkColorSetARGB(65, 255, 255, 255);
239 photo_overlay_
->set_background(
240 views::Background::CreateSolidBackground(kBackgroundColor
));
241 photo_overlay_
->SetImage(*ui::ResourceBundle::GetSharedInstance().
242 GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_CAMERA
));
244 photo_overlay_
->SetSize(bounds
.size());
245 photo_overlay_
->SetVisible(false);
246 AddChildView(photo_overlay_
);
249 void OnPaint(gfx::Canvas
* canvas
) override
{
250 // Display the profile picture as a circle.
251 canvas
->ClipPath(circular_mask_
, true);
252 views::LabelButton::OnPaint(canvas
);
255 void PaintChildren(gfx::Canvas
* canvas
,
256 const views::CullSet
& cull_set
) override
{
257 // Display any children (the "change photo" overlay) as a circle.
258 canvas
->ClipPath(circular_mask_
, true);
259 View::PaintChildren(canvas
, cull_set
);
263 // views::CustomButton:
264 void StateChanged() override
{
266 (state() == STATE_PRESSED
|| state() == STATE_HOVERED
|| HasFocus());
268 photo_overlay_
->SetVisible(show_overlay
);
271 void OnFocus() override
{
272 views::LabelButton::OnFocus();
274 photo_overlay_
->SetVisible(true);
277 void OnBlur() override
{
278 views::LabelButton::OnBlur();
279 // Don't hide the overlay if it's being shown as a result of a mouseover.
280 if (photo_overlay_
&& state() != STATE_HOVERED
)
281 photo_overlay_
->SetVisible(false);
284 gfx::Path circular_mask_
;
286 // Image that is shown when hovering over the image button. Can be NULL if
287 // the photo isn't allowed to be edited (e.g. for guest profiles).
288 views::ImageView
* photo_overlay_
;
290 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto
);
293 // EditableProfileName -------------------------------------------------
295 // A custom text control that turns into a textfield for editing when clicked.
296 class EditableProfileName
: public RightAlignedIconLabelButton
,
297 public views::ButtonListener
{
299 EditableProfileName(views::TextfieldController
* controller
,
300 const base::string16
& text
,
301 bool is_editing_allowed
)
302 : RightAlignedIconLabelButton(this, text
),
303 profile_name_textfield_(NULL
) {
304 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
305 const gfx::FontList
& medium_font_list
=
306 rb
->GetFontList(ui::ResourceBundle::MediumFont
);
307 SetFontList(medium_font_list
);
308 SetHorizontalAlignment(gfx::ALIGN_CENTER
);
310 if (!is_editing_allowed
) {
311 SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0));
315 // Show an "edit" pencil icon when hovering over. In the default state,
316 // we need to create an empty placeholder of the correct size, so that
317 // the text doesn't jump around when the hovered icon appears.
318 gfx::ImageSkia hover_image
=
319 *rb
->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_HOVER
);
320 SetImage(STATE_NORMAL
, CreateSquarePlaceholderImage(hover_image
.width()));
321 SetImage(STATE_HOVERED
, hover_image
);
322 SetImage(STATE_PRESSED
,
323 *rb
->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_PRESSED
));
324 // To center the text, we need to offest it by the width of the icon we
325 // are adding and its padding. We need to also add a small top/bottom
326 // padding to account for the textfield's border.
327 const int kIconTextLabelButtonSpacing
= 5;
328 SetBorder(views::Border::CreateEmptyBorder(
329 2, hover_image
.width() + kIconTextLabelButtonSpacing
, 2, 0));
331 // Textfield that overlaps the button.
332 profile_name_textfield_
= new views::Textfield();
333 profile_name_textfield_
->set_controller(controller
);
334 profile_name_textfield_
->SetFontList(medium_font_list
);
335 profile_name_textfield_
->SetHorizontalAlignment(gfx::ALIGN_CENTER
);
337 profile_name_textfield_
->SetVisible(false);
338 AddChildView(profile_name_textfield_
);
341 views::Textfield
* profile_name_textfield() {
342 return profile_name_textfield_
;
345 // Hide the editable textfield to show the profile name button instead.
346 void ShowReadOnlyView() {
347 if (profile_name_textfield_
)
348 profile_name_textfield_
->SetVisible(false);
352 // views::ButtonListener:
353 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
{
354 if (profile_name_textfield_
) {
355 profile_name_textfield_
->SetVisible(true);
356 profile_name_textfield_
->SetText(GetText());
357 profile_name_textfield_
->SelectAll(false);
358 profile_name_textfield_
->RequestFocus();
362 // views::LabelButton:
363 bool OnKeyReleased(const ui::KeyEvent
& event
) override
{
364 // Override CustomButton's implementation, which presses the button when
365 // you press space and clicks it when you release space, as the space can be
366 // part of the new profile name typed in the textfield.
370 void Layout() override
{
371 if (profile_name_textfield_
)
372 profile_name_textfield_
->SetBounds(0, 0, width(), height());
373 RightAlignedIconLabelButton::Layout();
376 void OnFocus() override
{
377 RightAlignedIconLabelButton::OnFocus();
378 SetState(STATE_HOVERED
);
381 void OnBlur() override
{
382 RightAlignedIconLabelButton::OnBlur();
383 SetState(STATE_NORMAL
);
386 // Textfield that is shown when editing the profile name. Can be NULL if
387 // the profile name isn't allowed to be edited (e.g. for guest profiles).
388 views::Textfield
* profile_name_textfield_
;
390 DISALLOW_COPY_AND_ASSIGN(EditableProfileName
);
393 // A title card with one back button right aligned and one label center aligned.
394 class TitleCard
: public views::View
{
396 TitleCard(const base::string16
& message
, views::ButtonListener
* listener
,
397 views::ImageButton
** back_button
) {
398 back_button_
= new views::ImageButton(listener
);
399 back_button_
->SetImageAlignment(views::ImageButton::ALIGN_LEFT
,
400 views::ImageButton::ALIGN_MIDDLE
);
401 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
402 back_button_
->SetImage(views::ImageButton::STATE_NORMAL
,
403 rb
->GetImageSkiaNamed(IDR_BACK
));
404 back_button_
->SetImage(views::ImageButton::STATE_HOVERED
,
405 rb
->GetImageSkiaNamed(IDR_BACK_H
));
406 back_button_
->SetImage(views::ImageButton::STATE_PRESSED
,
407 rb
->GetImageSkiaNamed(IDR_BACK_P
));
408 back_button_
->SetImage(views::ImageButton::STATE_DISABLED
,
409 rb
->GetImageSkiaNamed(IDR_BACK_D
));
410 back_button_
->SetFocusable(true);
411 *back_button
= back_button_
;
413 title_label_
= new views::Label(message
);
414 title_label_
->SetHorizontalAlignment(gfx::ALIGN_CENTER
);
415 const gfx::FontList
& medium_font_list
=
416 rb
->GetFontList(ui::ResourceBundle::MediumFont
);
417 title_label_
->SetFontList(medium_font_list
);
419 AddChildView(back_button_
);
420 AddChildView(title_label_
);
423 // Creates a new view that has the |title_card| with horizontal padding at the
424 // top, an edge-to-edge separator below, and the specified |view| at the
426 static views::View
* AddPaddedTitleCard(views::View
* view
,
427 TitleCard
* title_card
,
429 views::View
* titled_view
= new views::View();
430 views::GridLayout
* layout
= new views::GridLayout(titled_view
);
431 titled_view
->SetLayoutManager(layout
);
433 // Column set 0 is a single column layout with horizontal padding at left
434 // and right, and column set 1 is a single column layout with no padding.
435 views::ColumnSet
* columns
= layout
->AddColumnSet(0);
436 columns
->AddPaddingColumn(1, views::kButtonHEdgeMarginNew
);
437 int available_width
= width
- 2 * views::kButtonHEdgeMarginNew
;
438 columns
->AddColumn(views::GridLayout::FILL
, views::GridLayout::FILL
, 0,
439 views::GridLayout::FIXED
, available_width
, available_width
);
440 columns
->AddPaddingColumn(1, views::kButtonHEdgeMarginNew
);
441 layout
->AddColumnSet(1)->AddColumn(views::GridLayout::FILL
,
442 views::GridLayout::FILL
, 0,views::GridLayout::FIXED
, width
, width
);
444 layout
->StartRowWithPadding(1, 0, 0, kVerticalSpacing
);
445 layout
->AddView(title_card
);
446 layout
->StartRowWithPadding(1, 1, 0, kVerticalSpacing
);
447 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
449 layout
->StartRow(1, 1);
450 layout
->AddView(view
);
456 void Layout() override
{
457 int back_button_width
= back_button_
->GetPreferredSize().width();
458 back_button_
->SetBounds(0, 0, back_button_width
, height());
459 int label_padding
= back_button_width
+ views::kButtonHEdgeMarginNew
;
460 int label_width
= width() - 2 * label_padding
;
461 DCHECK_GT(label_width
, 0);
462 title_label_
->SetBounds(label_padding
, 0, label_width
, height());
465 gfx::Size
GetPreferredSize() const override
{
466 int height
= std::max(title_label_
->GetPreferredSize().height(),
467 back_button_
->GetPreferredSize().height());
468 return gfx::Size(width(), height
);
471 views::ImageButton
* back_button_
;
472 views::Label
* title_label_
;
474 DISALLOW_COPY_AND_ASSIGN(TitleCard
);
477 // ProfileChooserView ---------------------------------------------------------
480 ProfileChooserView
* ProfileChooserView::profile_bubble_
= NULL
;
481 bool ProfileChooserView::close_on_deactivate_for_testing_
= true;
484 void ProfileChooserView::ShowBubble(
485 profiles::BubbleViewMode view_mode
,
486 profiles::TutorialMode tutorial_mode
,
487 const signin::ManageAccountsParams
& manage_accounts_params
,
488 views::View
* anchor_view
,
489 views::BubbleBorder::Arrow arrow
,
490 views::BubbleBorder::BubbleAlignment border_alignment
,
493 if (tutorial_mode
!= profiles::TUTORIAL_MODE_NONE
) {
494 profile_bubble_
->tutorial_mode_
= tutorial_mode
;
495 profile_bubble_
->ShowView(view_mode
, profile_bubble_
->avatar_menu_
.get());
500 profile_bubble_
= new ProfileChooserView(anchor_view
, arrow
, browser
,
501 view_mode
, tutorial_mode
, manage_accounts_params
.service_type
);
502 views::BubbleDelegateView::CreateBubble(profile_bubble_
);
503 profile_bubble_
->set_close_on_deactivate(close_on_deactivate_for_testing_
);
504 profile_bubble_
->SetAlignment(border_alignment
);
505 profile_bubble_
->GetWidget()->Show();
506 profile_bubble_
->SetArrowPaintType(views::BubbleBorder::PAINT_NONE
);
510 bool ProfileChooserView::IsShowing() {
511 return profile_bubble_
!= NULL
;
515 void ProfileChooserView::Hide() {
517 profile_bubble_
->GetWidget()->Close();
520 ProfileChooserView::ProfileChooserView(views::View
* anchor_view
,
521 views::BubbleBorder::Arrow arrow
,
523 profiles::BubbleViewMode view_mode
,
524 profiles::TutorialMode tutorial_mode
,
525 signin::GAIAServiceType service_type
)
526 : BubbleDelegateView(anchor_view
, arrow
),
528 view_mode_(view_mode
),
529 tutorial_mode_(tutorial_mode
),
530 gaia_service_type_(service_type
) {
531 // Reset the default margins inherited from the BubbleDelegateView.
532 // Add a small bottom inset so that the bubble's rounded corners show up.
533 set_margins(gfx::Insets(0, 0, 1, 0));
534 set_background(views::Background::CreateSolidBackground(
535 GetNativeTheme()->GetSystemColor(
536 ui::NativeTheme::kColorId_DialogBackground
)));
539 avatar_menu_
.reset(new AvatarMenu(
540 &g_browser_process
->profile_manager()->GetProfileInfoCache(),
543 avatar_menu_
->RebuildMenu();
545 ProfileOAuth2TokenService
* oauth2_token_service
=
546 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_
->profile());
547 if (oauth2_token_service
)
548 oauth2_token_service
->AddObserver(this);
551 ProfileChooserView::~ProfileChooserView() {
552 ProfileOAuth2TokenService
* oauth2_token_service
=
553 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_
->profile());
554 if (oauth2_token_service
)
555 oauth2_token_service
->RemoveObserver(this);
558 void ProfileChooserView::ResetView() {
559 open_other_profile_indexes_map_
.clear();
560 delete_account_button_map_
.clear();
561 reauth_account_button_map_
.clear();
562 manage_accounts_link_
= NULL
;
563 signin_current_profile_link_
= NULL
;
564 auth_error_email_button_
= NULL
;
565 current_profile_photo_
= NULL
;
566 current_profile_name_
= NULL
;
567 users_button_
= NULL
;
568 go_incognito_button_
= NULL
;
570 add_account_link_
= NULL
;
571 gaia_signin_cancel_button_
= NULL
;
572 remove_account_button_
= NULL
;
573 account_removal_cancel_button_
= NULL
;
574 add_person_button_
= NULL
;
575 disconnect_button_
= NULL
;
576 switch_user_cancel_button_
= NULL
;
577 tutorial_sync_settings_ok_button_
= NULL
;
578 tutorial_close_button_
= NULL
;
579 tutorial_sync_settings_link_
= NULL
;
580 tutorial_see_whats_new_button_
= NULL
;
581 tutorial_not_you_link_
= NULL
;
582 tutorial_learn_more_link_
= NULL
;
585 void ProfileChooserView::Init() {
586 // If view mode is PROFILE_CHOOSER but there is an auth error, force
587 // ACCOUNT_MANAGEMENT mode.
588 if (view_mode_
== profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
&&
589 HasAuthError(browser_
->profile()) &&
590 switches::IsEnableAccountConsistency() &&
591 avatar_menu_
->GetItemAt(avatar_menu_
->GetActiveProfileIndex()).
593 view_mode_
= profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
;
596 // The arrow keys can be used to tab between items.
597 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN
, ui::EF_NONE
));
598 AddAccelerator(ui::Accelerator(ui::VKEY_UP
, ui::EF_NONE
));
600 ShowView(view_mode_
, avatar_menu_
.get());
603 void ProfileChooserView::OnAvatarMenuChanged(
604 AvatarMenu
* avatar_menu
) {
605 if (view_mode_
== profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
||
606 view_mode_
== profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
) {
607 // Refresh the view with the new menu. We can't just update the local copy
608 // as this may have been triggered by a sign out action, in which case
609 // the view is being destroyed.
610 ShowView(view_mode_
, avatar_menu
);
614 void ProfileChooserView::OnRefreshTokenAvailable(
615 const std::string
& account_id
) {
616 if (view_mode_
== profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
||
617 view_mode_
== profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT
||
618 view_mode_
== profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH
) {
619 // The account management UI is only available through the
620 // --enable-account-consistency flag.
621 ShowView(switches::IsEnableAccountConsistency() ?
622 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
:
623 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
, avatar_menu_
.get());
627 void ProfileChooserView::OnRefreshTokenRevoked(const std::string
& account_id
) {
628 // Refresh the account management view when an account is removed from the
630 if (view_mode_
== profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
)
631 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
, avatar_menu_
.get());
634 void ProfileChooserView::ShowView(profiles::BubbleViewMode view_to_display
,
635 AvatarMenu
* avatar_menu
) {
636 // The account management view should only be displayed if the active profile
638 if (view_to_display
== profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
) {
639 DCHECK(switches::IsEnableAccountConsistency());
640 const AvatarMenu::Item
& active_item
= avatar_menu
->GetItemAt(
641 avatar_menu
->GetActiveProfileIndex());
642 DCHECK(active_item
.signed_in
);
645 if (browser_
->profile()->IsSupervised() &&
646 (view_to_display
== profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT
||
647 view_to_display
== profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL
)) {
648 LOG(WARNING
) << "Supervised user attempted to add/remove account";
653 RemoveAllChildViews(true);
654 view_mode_
= view_to_display
;
656 views::GridLayout
* layout
;
657 views::View
* sub_view
;
658 switch (view_mode_
) {
659 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN
:
660 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT
:
661 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH
:
662 layout
= CreateSingleColumnLayout(this, kFixedGaiaViewWidth
);
663 sub_view
= CreateGaiaSigninView();
665 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL
:
666 layout
= CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth
);
667 sub_view
= CreateAccountRemovalView();
669 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER
:
670 layout
= CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth
);
671 sub_view
= CreateSwitchUserView();
672 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
673 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW
);
676 layout
= CreateSingleColumnLayout(this, kFixedMenuWidth
);
677 sub_view
= CreateProfileChooserView(avatar_menu
);
679 // Clears tutorial mode for all non-profile-chooser views.
680 if (view_mode_
!= profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
)
681 tutorial_mode_
= profiles::TUTORIAL_MODE_NONE
;
683 layout
->StartRow(1, 0);
684 layout
->AddView(sub_view
);
686 if (GetBubbleFrameView())
690 void ProfileChooserView::WindowClosing() {
691 DCHECK_EQ(profile_bubble_
, this);
692 profile_bubble_
= NULL
;
694 if (tutorial_mode_
== profiles::TUTORIAL_MODE_CONFIRM_SIGNIN
) {
695 LoginUIServiceFactory::GetForProfile(browser_
->profile())->
696 SyncConfirmationUIClosed(false /* configure_sync_first */);
700 bool ProfileChooserView::AcceleratorPressed(
701 const ui::Accelerator
& accelerator
) {
702 if (accelerator
.key_code() != ui::VKEY_DOWN
&&
703 accelerator
.key_code() != ui::VKEY_UP
)
704 return BubbleDelegateView::AcceleratorPressed(accelerator
);
705 // Move the focus up or down.
706 GetFocusManager()->AdvanceFocus(accelerator
.key_code() != ui::VKEY_DOWN
);
710 bool ProfileChooserView::HandleContextMenu(
711 const content::ContextMenuParams
& params
) {
712 // Suppresses the context menu because some features, such as inspecting
713 // elements, are not appropriate in a bubble.
717 void ProfileChooserView::ButtonPressed(views::Button
* sender
,
718 const ui::Event
& event
) {
719 if (sender
== users_button_
) {
720 // If this is a guest session, close all the guest browser windows.
721 if (browser_
->profile()->IsGuestSession()) {
722 profiles::CloseGuestProfileWindows();
724 UserManager::Show(base::FilePath(),
725 profiles::USER_MANAGER_NO_TUTORIAL
,
726 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION
);
728 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER
);
729 } else if (sender
== go_incognito_button_
) {
730 DCHECK(ShouldShowGoIncognito());
731 chrome::NewIncognitoWindow(browser_
);
732 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_GO_INCOGNITO
);
733 } else if (sender
== lock_button_
) {
734 profiles::LockProfile(browser_
->profile());
735 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK
);
736 } else if (sender
== auth_error_email_button_
) {
737 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH
, avatar_menu_
.get());
738 } else if (sender
== tutorial_sync_settings_ok_button_
) {
739 LoginUIServiceFactory::GetForProfile(browser_
->profile())->
740 SyncConfirmationUIClosed(false /* configure_sync_first */);
742 ProfileMetrics::LogProfileNewAvatarMenuSignin(
743 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_OK
);
744 } else if (sender
== tutorial_close_button_
) {
745 DCHECK(tutorial_mode_
!= profiles::TUTORIAL_MODE_NONE
&&
746 tutorial_mode_
!= profiles::TUTORIAL_MODE_CONFIRM_SIGNIN
);
748 } else if (sender
== tutorial_see_whats_new_button_
) {
749 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
750 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_WHATS_NEW
);
751 UserManager::Show(base::FilePath(),
752 profiles::USER_MANAGER_TUTORIAL_OVERVIEW
,
753 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION
);
754 } else if (sender
== remove_account_button_
) {
756 } else if (sender
== account_removal_cancel_button_
) {
757 account_id_to_remove_
.clear();
758 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
, avatar_menu_
.get());
759 } else if (sender
== gaia_signin_cancel_button_
) {
760 // The account management view is only available with the
761 // --enable-account-consistency flag.
762 bool account_management_available
=
763 SigninManagerFactory::GetForProfile(browser_
->profile())->
765 switches::IsEnableAccountConsistency();
766 ShowView(account_management_available
?
767 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
:
768 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
, avatar_menu_
.get());
769 } else if (sender
== current_profile_photo_
) {
770 avatar_menu_
->EditProfile(avatar_menu_
->GetActiveProfileIndex());
771 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE
);
772 } else if (sender
== signin_current_profile_link_
) {
773 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN
, avatar_menu_
.get());
774 } else if (sender
== add_person_button_
) {
775 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
776 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON
);
777 UserManager::Show(base::FilePath(),
778 profiles::USER_MANAGER_NO_TUTORIAL
,
779 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION
);
780 } else if (sender
== disconnect_button_
) {
781 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
782 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT
);
783 chrome::ShowSettings(browser_
);
784 } else if (sender
== switch_user_cancel_button_
) {
785 ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
, avatar_menu_
.get());
786 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
787 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK
);
789 // Either one of the "other profiles", or one of the profile accounts
790 // buttons was pressed.
791 ButtonIndexes::const_iterator profile_match
=
792 open_other_profile_indexes_map_
.find(sender
);
793 if (profile_match
!= open_other_profile_indexes_map_
.end()) {
794 avatar_menu_
->SwitchToProfile(
795 profile_match
->second
,
796 ui::DispositionFromEventFlags(event
.flags()) == NEW_WINDOW
,
797 ProfileMetrics::SWITCH_PROFILE_ICON
);
799 // This was a profile accounts button.
800 AccountButtonIndexes::const_iterator account_match
=
801 delete_account_button_map_
.find(sender
);
802 if (account_match
!= delete_account_button_map_
.end()) {
803 account_id_to_remove_
= account_match
->second
;
804 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL
,
807 account_match
= reauth_account_button_map_
.find(sender
);
808 DCHECK(account_match
!= reauth_account_button_map_
.end());
809 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH
, avatar_menu_
.get());
815 void ProfileChooserView::RemoveAccount() {
816 DCHECK(!account_id_to_remove_
.empty());
817 MutableProfileOAuth2TokenService
* oauth2_token_service
=
818 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile(
819 browser_
->profile());
820 if (oauth2_token_service
) {
821 oauth2_token_service
->RevokeCredentials(account_id_to_remove_
);
822 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT
);
824 account_id_to_remove_
.clear();
826 ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
, avatar_menu_
.get());
829 void ProfileChooserView::LinkClicked(views::Link
* sender
, int event_flags
) {
830 if (sender
== manage_accounts_link_
) {
831 // This link can either mean show/hide the account management view,
832 // depending on which view it is displayed. ShowView() will DCHECK if
833 // the account management view is displayed for non signed-in users.
835 view_mode_
== profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
?
836 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
:
837 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT
,
839 } else if (sender
== add_account_link_
) {
840 ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT
, avatar_menu_
.get());
841 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT
);
842 } else if (sender
== tutorial_sync_settings_link_
) {
843 LoginUIServiceFactory::GetForProfile(browser_
->profile())->
844 SyncConfirmationUIClosed(true /* configure_sync_first */);
845 tutorial_mode_
= profiles::TUTORIAL_MODE_NONE
;
846 ProfileMetrics::LogProfileNewAvatarMenuSignin(
847 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS
);
848 } else if (sender
== tutorial_not_you_link_
) {
849 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
850 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU
);
851 ShowView(profiles::BUBBLE_VIEW_MODE_SWITCH_USER
, avatar_menu_
.get());
853 DCHECK(sender
== tutorial_learn_more_link_
);
854 signin_ui_util::ShowSigninErrorLearnMorePage(browser_
->profile());
858 void ProfileChooserView::StyledLabelLinkClicked(
859 const gfx::Range
& range
, int event_flags
) {
860 chrome::ShowSettings(browser_
);
863 bool ProfileChooserView::HandleKeyEvent(views::Textfield
* sender
,
864 const ui::KeyEvent
& key_event
) {
865 views::Textfield
* name_textfield
=
866 current_profile_name_
->profile_name_textfield();
867 DCHECK(sender
== name_textfield
);
869 if (key_event
.key_code() == ui::VKEY_RETURN
||
870 key_event
.key_code() == ui::VKEY_TAB
) {
871 // Pressing Tab/Enter commits the new profile name, unless it's empty.
872 base::string16 new_profile_name
= name_textfield
->text();
873 base::TrimWhitespace(new_profile_name
, base::TRIM_ALL
, &new_profile_name
);
874 if (new_profile_name
.empty())
877 const AvatarMenu::Item
& active_item
= avatar_menu_
->GetItemAt(
878 avatar_menu_
->GetActiveProfileIndex());
879 Profile
* profile
= g_browser_process
->profile_manager()->GetProfile(
880 active_item
.profile_path
);
883 if (profile
->IsLegacySupervised())
886 profiles::UpdateProfileName(profile
, new_profile_name
);
887 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME
);
888 current_profile_name_
->ShowReadOnlyView();
894 views::View
* ProfileChooserView::CreateProfileChooserView(
895 AvatarMenu
* avatar_menu
) {
896 views::View
* view
= new views::View();
897 views::GridLayout
* layout
= CreateSingleColumnLayout(view
, kFixedMenuWidth
);
898 // Separate items into active and alternatives.
899 Indexes other_profiles
;
900 views::View
* tutorial_view
= NULL
;
901 views::View
* current_profile_view
= NULL
;
902 views::View
* current_profile_accounts
= NULL
;
903 views::View
* option_buttons_view
= NULL
;
904 for (size_t i
= 0; i
< avatar_menu
->GetNumberOfItems(); ++i
) {
905 const AvatarMenu::Item
& item
= avatar_menu
->GetItemAt(i
);
907 option_buttons_view
= CreateOptionsView(
908 item
.signed_in
&& profiles::IsLockAvailable(browser_
->profile()));
909 current_profile_view
= CreateCurrentProfileView(item
, false);
910 if (view_mode_
== profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
) {
911 switch (tutorial_mode_
) {
912 case profiles::TUTORIAL_MODE_NONE
:
913 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE
:
914 tutorial_view
= CreateWelcomeUpgradeTutorialViewIfNeeded(
915 tutorial_mode_
== profiles::TUTORIAL_MODE_WELCOME_UPGRADE
,
918 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN
:
919 tutorial_view
= CreateSigninConfirmationView();
921 case profiles::TUTORIAL_MODE_SHOW_ERROR
:
922 tutorial_view
= CreateSigninErrorView();
926 current_profile_accounts
= CreateCurrentProfileAccountsView(item
);
929 other_profiles
.push_back(i
);
934 // TODO(mlerman): update UMA stats for the new tutorial.
935 layout
->StartRow(1, 0);
936 layout
->AddView(tutorial_view
);
938 tutorial_mode_
= profiles::TUTORIAL_MODE_NONE
;
941 if (!current_profile_view
) {
942 // Guest windows don't have an active profile.
943 current_profile_view
= CreateGuestProfileView();
944 option_buttons_view
= CreateOptionsView(false);
947 layout
->StartRow(1, 0);
948 layout
->AddView(current_profile_view
);
950 if (view_mode_
!= profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
) {
951 DCHECK(current_profile_accounts
);
952 layout
->StartRow(0, 0);
953 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
954 layout
->StartRow(1, 0);
955 layout
->AddView(current_profile_accounts
);
958 if (browser_
->profile()->IsSupervised()) {
959 layout
->StartRow(0, 0);
960 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
961 layout
->StartRow(1, 0);
962 layout
->AddView(CreateSupervisedUserDisclaimerView());
965 if (view_mode_
== profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
) {
966 layout
->StartRow(1, 0);
967 if (switches::IsFastUserSwitching())
968 layout
->AddView(CreateOtherProfilesView(other_profiles
));
971 layout
->StartRow(0, 0);
972 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
974 if (option_buttons_view
) {
975 layout
->StartRow(0, 0);
976 layout
->AddView(option_buttons_view
);
982 void ProfileChooserView::DismissTutorial() {
983 // Never shows the upgrade tutorial again if manually closed.
984 if (tutorial_mode_
== profiles::TUTORIAL_MODE_WELCOME_UPGRADE
) {
985 browser_
->profile()->GetPrefs()->SetInteger(
986 prefs::kProfileAvatarTutorialShown
,
987 signin_ui_util::kUpgradeWelcomeTutorialShowMax
+ 1);
990 tutorial_mode_
= profiles::TUTORIAL_MODE_NONE
;
991 ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
, avatar_menu_
.get());
994 views::View
* ProfileChooserView::CreateTutorialView(
995 profiles::TutorialMode tutorial_mode
,
996 const base::string16
& title_text
,
997 const base::string16
& content_text
,
998 const base::string16
& link_text
,
999 const base::string16
& button_text
,
1002 views::LabelButton
** button
,
1003 views::ImageButton
** close_button
) {
1004 tutorial_mode_
= tutorial_mode
;
1006 views::View
* view
= new views::View();
1007 view
->set_background(views::Background::CreateSolidBackground(
1008 profiles::kAvatarTutorialBackgroundColor
));
1009 views::GridLayout
* layout
= CreateSingleColumnLayout(view
,
1010 kFixedMenuWidth
- 2 * views::kButtonHEdgeMarginNew
);
1011 // Creates a second column set for buttons and links.
1012 views::ColumnSet
* button_columns
= layout
->AddColumnSet(1);
1013 button_columns
->AddColumn(views::GridLayout::LEADING
,
1014 views::GridLayout::CENTER
, 0, views::GridLayout::USE_PREF
, 0, 0);
1015 button_columns
->AddPaddingColumn(
1016 1, views::kUnrelatedControlHorizontalSpacing
);
1017 button_columns
->AddColumn(views::GridLayout::TRAILING
,
1018 views::GridLayout::CENTER
, 0, views::GridLayout::USE_PREF
, 0, 0);
1019 layout
->SetInsets(views::kButtonVEdgeMarginNew
,
1020 views::kButtonHEdgeMarginNew
,
1021 views::kButtonVEdgeMarginNew
,
1022 views::kButtonHEdgeMarginNew
);
1024 // Adds title and close button if needed.
1025 views::Label
* title_label
= new views::Label(title_text
);
1026 title_label
->SetMultiLine(true);
1027 title_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1028 title_label
->SetAutoColorReadabilityEnabled(false);
1029 title_label
->SetEnabledColor(SK_ColorWHITE
);
1030 title_label
->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
1031 ui::ResourceBundle::MediumFont
));
1034 layout
->StartRow(1, 1);
1035 layout
->AddView(title_label
);
1036 *close_button
= new views::ImageButton(this);
1037 (*close_button
)->SetImageAlignment(views::ImageButton::ALIGN_RIGHT
,
1038 views::ImageButton::ALIGN_MIDDLE
);
1039 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
1040 (*close_button
)->SetImage(views::ImageButton::STATE_NORMAL
,
1041 rb
->GetImageSkiaNamed(IDR_CLOSE_1
));
1042 (*close_button
)->SetImage(views::ImageButton::STATE_HOVERED
,
1043 rb
->GetImageSkiaNamed(IDR_CLOSE_1_H
));
1044 (*close_button
)->SetImage(views::ImageButton::STATE_PRESSED
,
1045 rb
->GetImageSkiaNamed(IDR_CLOSE_1_P
));
1046 layout
->AddView(*close_button
);
1048 layout
->StartRow(1, 0);
1049 layout
->AddView(title_label
);
1052 // Adds body content.
1053 views::Label
* content_label
= new views::Label(content_text
);
1054 content_label
->SetMultiLine(true);
1055 content_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1056 content_label
->SetAutoColorReadabilityEnabled(false);
1057 content_label
->SetEnabledColor(profiles::kAvatarTutorialContentTextColor
);
1058 layout
->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing
);
1059 layout
->AddView(content_label
);
1061 // Adds links and buttons.
1062 bool has_button
= !button_text
.empty();
1064 *button
= new views::LabelButton(this, button_text
);
1065 (*button
)->SetHorizontalAlignment(gfx::ALIGN_CENTER
);
1066 (*button
)->SetStyle(views::Button::STYLE_BUTTON
);
1069 bool has_link
= !link_text
.empty();
1071 *link
= CreateLink(link_text
, this);
1072 (*link
)->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1073 (*link
)->SetAutoColorReadabilityEnabled(false);
1074 (*link
)->SetEnabledColor(SK_ColorWHITE
);
1079 layout
->StartRowWithPadding(
1080 1, 0, 0, views::kUnrelatedControlVerticalSpacing
);
1081 layout
->AddView(*button
);
1083 layout
->StartRowWithPadding(
1084 1, 0, 0, views::kRelatedControlVerticalSpacing
);
1085 (*link
)->SetHorizontalAlignment(gfx::ALIGN_CENTER
);
1086 layout
->AddView(*link
);
1089 DCHECK(has_link
|| has_button
);
1090 layout
->StartRowWithPadding(
1091 1, 1, 0, views::kUnrelatedControlVerticalSpacing
);
1093 layout
->AddView(*link
);
1095 layout
->SkipColumns(1);
1097 layout
->AddView(*button
);
1099 layout
->SkipColumns(1);
1105 views::View
* ProfileChooserView::CreateCurrentProfileView(
1106 const AvatarMenu::Item
& avatar_item
,
1108 views::View
* view
= new views::View();
1109 int column_width
= kFixedMenuWidth
- 2 * views::kButtonHEdgeMarginNew
;
1110 views::GridLayout
* layout
= CreateSingleColumnLayout(view
, column_width
);
1111 layout
->SetInsets(views::kButtonVEdgeMarginNew
,
1112 views::kButtonHEdgeMarginNew
,
1113 views::kUnrelatedControlVerticalSpacing
,
1114 views::kButtonHEdgeMarginNew
);
1116 // Profile icon, centered.
1117 int x_offset
= (column_width
- kLargeImageSide
) / 2;
1118 current_profile_photo_
= new EditableProfilePhoto(
1119 this, avatar_item
.icon
, !is_guest
,
1120 gfx::Rect(x_offset
, 0, kLargeImageSide
, kLargeImageSide
));
1121 SizedContainer
* profile_icon_container
=
1122 new SizedContainer(gfx::Size(column_width
, kLargeImageSide
));
1123 profile_icon_container
->AddChildView(current_profile_photo_
);
1125 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
1126 if (browser_
->profile()->IsSupervised()) {
1127 views::ImageView
* supervised_icon
= new views::ImageView();
1128 int image_id
= browser_
->profile()->IsChild()
1129 ? IDR_ICON_PROFILES_MENU_CHILD
1130 : IDR_ICON_PROFILES_MENU_SUPERVISED
;
1131 supervised_icon
->SetImage(rb
->GetImageSkiaNamed(image_id
));
1132 gfx::Size preferred_size
= supervised_icon
->GetPreferredSize();
1133 gfx::Rect parent_bounds
= current_profile_photo_
->bounds();
1134 supervised_icon
->SetBounds(
1135 parent_bounds
.right() - preferred_size
.width(),
1136 parent_bounds
.bottom() - preferred_size
.height(),
1137 preferred_size
.width(),
1138 preferred_size
.height());
1139 profile_icon_container
->AddChildView(supervised_icon
);
1142 layout
->StartRow(1, 0);
1143 layout
->AddView(profile_icon_container
);
1145 // Profile name, centered.
1146 bool editing_allowed
= !is_guest
&&
1147 !browser_
->profile()->IsLegacySupervised();
1148 current_profile_name_
= new EditableProfileName(
1150 profiles::GetAvatarNameForProfile(browser_
->profile()->GetPath()),
1152 layout
->StartRowWithPadding(1, 0, 0,
1153 views::kRelatedControlSmallVerticalSpacing
);
1154 layout
->StartRow(1, 0);
1155 layout
->AddView(current_profile_name_
);
1160 // The available links depend on the type of profile that is active.
1161 if (avatar_item
.signed_in
) {
1162 layout
->StartRow(1, 0);
1163 if (switches::IsEnableAccountConsistency()) {
1164 base::string16 link_title
= l10n_util::GetStringUTF16(
1165 view_mode_
== profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
?
1166 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON
:
1167 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON
);
1168 manage_accounts_link_
= CreateLink(link_title
, this);
1169 manage_accounts_link_
->SetHorizontalAlignment(gfx::ALIGN_CENTER
);
1170 layout
->AddView(manage_accounts_link_
);
1172 // Badge the email address if there's an authentication error.
1173 if (HasAuthError(browser_
->profile())) {
1174 const gfx::ImageSkia warning_image
= *rb
->GetImageNamed(
1175 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR
).ToImageSkia();
1176 auth_error_email_button_
=
1177 new RightAlignedIconLabelButton(this, avatar_item
.sync_state
);
1178 auth_error_email_button_
->SetElideBehavior(gfx::ELIDE_EMAIL
);
1179 auth_error_email_button_
->SetImage(
1180 views::LabelButton::STATE_NORMAL
, warning_image
);
1181 auth_error_email_button_
->SetTextColor(
1182 views::LabelButton::STATE_NORMAL
,
1183 views::Link::GetDefaultEnabledColor());
1184 auth_error_email_button_
->SetFocusable(true);
1185 gfx::Insets insets
= views::LabelButtonBorder::GetDefaultInsetsForStyle(
1186 views::Button::STYLE_TEXTBUTTON
);
1187 auth_error_email_button_
->SetBorder(views::Border::CreateEmptyBorder(
1188 insets
.top(), insets
.left(), insets
.bottom(), insets
.right()));
1189 layout
->AddView(auth_error_email_button_
);
1191 // Add a small padding between the email button and the profile name.
1192 layout
->StartRowWithPadding(1, 0, 0, 2);
1193 views::Label
* email_label
= new views::Label(avatar_item
.sync_state
);
1194 email_label
->SetElideBehavior(gfx::ELIDE_EMAIL
);
1195 email_label
->SetEnabled(false);
1196 layout
->AddView(email_label
);
1200 SigninManagerBase
* signin_manager
= SigninManagerFactory::GetForProfile(
1201 browser_
->profile()->GetOriginalProfile());
1202 if (signin_manager
->IsSigninAllowed()) {
1203 views::Label
* promo
= new views::Label(
1204 l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO
));
1205 promo
->SetMultiLine(true);
1206 promo
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1207 layout
->StartRowWithPadding(1, 0, 0,
1208 views::kRelatedControlSmallVerticalSpacing
);
1209 layout
->StartRow(1, 0);
1210 layout
->AddView(promo
);
1212 signin_current_profile_link_
= new views::BlueButton(
1213 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL
,
1214 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME
)));
1215 layout
->StartRowWithPadding(1, 0, 0,
1216 views::kRelatedControlVerticalSpacing
);
1217 layout
->StartRow(1, 0);
1218 layout
->AddView(signin_current_profile_link_
);
1225 views::View
* ProfileChooserView::CreateGuestProfileView() {
1226 gfx::Image guest_icon
=
1227 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
1228 profiles::GetPlaceholderAvatarIconResourceID());
1229 AvatarMenu::Item
guest_avatar_item(0, 0, guest_icon
);
1230 guest_avatar_item
.active
= true;
1231 guest_avatar_item
.name
= l10n_util::GetStringUTF16(
1232 IDS_PROFILES_GUEST_PROFILE_NAME
);
1233 guest_avatar_item
.signed_in
= false;
1235 return CreateCurrentProfileView(guest_avatar_item
, true);
1238 views::View
* ProfileChooserView::CreateOtherProfilesView(
1239 const Indexes
& avatars_to_show
) {
1240 views::View
* view
= new views::View();
1241 views::GridLayout
* layout
= CreateSingleColumnLayout(view
, kFixedMenuWidth
);
1243 int num_avatars_to_show
= avatars_to_show
.size();
1244 for (int i
= 0; i
< num_avatars_to_show
; ++i
) {
1245 const size_t index
= avatars_to_show
[i
];
1246 const AvatarMenu::Item
& item
= avatar_menu_
->GetItemAt(index
);
1247 const int kSmallImageSide
= 32;
1249 gfx::Image image
= profiles::GetSizedAvatarIcon(
1250 item
.icon
, true, kSmallImageSide
, kSmallImageSide
);
1252 views::LabelButton
* button
= new BackgroundColorHoverButton(
1255 *image
.ToImageSkia());
1256 open_other_profile_indexes_map_
[button
] = index
;
1258 layout
->StartRow(1, 0);
1259 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
1260 layout
->StartRow(1, 0);
1261 layout
->AddView(button
);
1267 views::View
* ProfileChooserView::CreateOptionsView(bool display_lock
) {
1268 views::View
* view
= new views::View();
1269 views::GridLayout
* layout
= CreateSingleColumnLayout(view
, kFixedMenuWidth
);
1271 base::string16 text
= browser_
->profile()->IsGuestSession() ?
1272 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST
) :
1273 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON
);
1274 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
1275 users_button_
= new BackgroundColorHoverButton(
1278 *rb
->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR
));
1279 layout
->StartRow(1, 0);
1280 layout
->AddView(users_button_
);
1282 if (ShouldShowGoIncognito()) {
1283 layout
->StartRow(1, 0);
1284 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
1286 go_incognito_button_
= new BackgroundColorHoverButton(
1288 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON
),
1289 *rb
->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_INCOGNITO
));
1290 layout
->StartRow(1, 0);
1291 layout
->AddView(go_incognito_button_
);
1295 layout
->StartRow(1, 0);
1296 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
1298 lock_button_
= new BackgroundColorHoverButton(
1300 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON
),
1301 *rb
->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK
));
1302 layout
->StartRow(1, 0);
1303 layout
->AddView(lock_button_
);
1308 views::View
* ProfileChooserView::CreateSupervisedUserDisclaimerView() {
1309 views::View
* view
= new views::View();
1310 views::GridLayout
* layout
= CreateSingleColumnLayout(
1311 view
, kFixedMenuWidth
- 2 * views::kButtonHEdgeMarginNew
);
1312 layout
->SetInsets(views::kRelatedControlVerticalSpacing
,
1313 views::kButtonHEdgeMarginNew
,
1314 views::kRelatedControlVerticalSpacing
,
1315 views::kButtonHEdgeMarginNew
);
1316 views::Label
* disclaimer
= new views::Label(
1317 avatar_menu_
->GetSupervisedUserInformation());
1318 disclaimer
->SetMultiLine(true);
1319 disclaimer
->SetAllowCharacterBreak(true);
1320 disclaimer
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1321 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
1322 disclaimer
->SetFontList(rb
->GetFontList(ui::ResourceBundle::SmallFont
));
1323 layout
->StartRow(1, 0);
1324 layout
->AddView(disclaimer
);
1329 views::View
* ProfileChooserView::CreateCurrentProfileAccountsView(
1330 const AvatarMenu::Item
& avatar_item
) {
1331 DCHECK(avatar_item
.signed_in
);
1332 views::View
* view
= new views::View();
1333 view
->set_background(views::Background::CreateSolidBackground(
1334 profiles::kAvatarBubbleAccountsBackgroundColor
));
1335 views::GridLayout
* layout
= CreateSingleColumnLayout(view
, kFixedMenuWidth
);
1337 Profile
* profile
= browser_
->profile();
1338 std::string primary_account
=
1339 SigninManagerFactory::GetForProfile(profile
)->GetAuthenticatedAccountId();
1340 DCHECK(!primary_account
.empty());
1341 std::vector
<std::string
>accounts
=
1342 profiles::GetSecondaryAccountsForProfile(profile
, primary_account
);
1344 // Get state of authentication error, if any.
1345 std::string error_account_id
= GetAuthErrorAccountId(profile
);
1347 // The primary account should always be listed first.
1348 // TODO(rogerta): we still need to further differentiate the primary account
1349 // from the others in the UI, so more work is likely required here:
1350 // crbug.com/311124.
1351 CreateAccountButton(layout
, primary_account
, true,
1352 error_account_id
== primary_account
, kFixedMenuWidth
);
1353 for (size_t i
= 0; i
< accounts
.size(); ++i
)
1354 CreateAccountButton(layout
, accounts
[i
], false,
1355 error_account_id
== accounts
[i
], kFixedMenuWidth
);
1357 if (!profile
->IsSupervised()) {
1358 layout
->AddPaddingRow(0, views::kRelatedControlVerticalSpacing
);
1360 add_account_link_
= CreateLink(l10n_util::GetStringFUTF16(
1361 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON
, avatar_item
.name
), this);
1362 add_account_link_
->SetBorder(views::Border::CreateEmptyBorder(
1363 0, views::kButtonVEdgeMarginNew
,
1364 views::kRelatedControlVerticalSpacing
, 0));
1365 layout
->StartRow(1, 0);
1366 layout
->AddView(add_account_link_
);
1372 void ProfileChooserView::CreateAccountButton(views::GridLayout
* layout
,
1373 const std::string
& account_id
,
1374 bool is_primary_account
,
1375 bool reauth_required
,
1377 std::string email
= signin_ui_util::GetDisplayEmail(browser_
->profile(),
1379 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
1380 const gfx::ImageSkia
* delete_default_image
=
1381 rb
->GetImageNamed(IDR_CLOSE_1
).ToImageSkia();
1382 const int kDeleteButtonWidth
= delete_default_image
->width();
1383 const gfx::ImageSkia warning_default_image
= reauth_required
?
1384 *rb
->GetImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR
).ToImageSkia() :
1386 const int kWarningButtonWidth
= reauth_required
?
1387 warning_default_image
.width() + views::kRelatedButtonHSpacing
: 0;
1388 int available_width
= width
- 2 * views::kButtonHEdgeMarginNew
1389 - kDeleteButtonWidth
- kWarningButtonWidth
;
1390 views::LabelButton
* email_button
= new BackgroundColorHoverButton(
1391 reauth_required
? this : NULL
,
1392 base::UTF8ToUTF16(email
),
1393 warning_default_image
);
1394 email_button
->SetElideBehavior(gfx::ELIDE_EMAIL
);
1395 email_button
->SetMinSize(gfx::Size(0, kButtonHeight
));
1396 email_button
->SetMaxSize(gfx::Size(available_width
, kButtonHeight
));
1397 layout
->StartRow(1, 0);
1398 layout
->AddView(email_button
);
1400 if (reauth_required
)
1401 reauth_account_button_map_
[email_button
] = account_id
;
1404 if (!browser_
->profile()->IsSupervised()) {
1405 views::ImageButton
* delete_button
= new views::ImageButton(this);
1406 delete_button
->SetImageAlignment(views::ImageButton::ALIGN_RIGHT
,
1407 views::ImageButton::ALIGN_MIDDLE
);
1408 delete_button
->SetImage(views::ImageButton::STATE_NORMAL
,
1409 delete_default_image
);
1410 delete_button
->SetImage(views::ImageButton::STATE_HOVERED
,
1411 rb
->GetImageSkiaNamed(IDR_CLOSE_1_H
));
1412 delete_button
->SetImage(views::ImageButton::STATE_PRESSED
,
1413 rb
->GetImageSkiaNamed(IDR_CLOSE_1_P
));
1414 delete_button
->SetBounds(
1415 width
- views::kButtonHEdgeMarginNew
- kDeleteButtonWidth
,
1416 0, kDeleteButtonWidth
, kButtonHeight
);
1418 email_button
->set_notify_enter_exit_on_child(true);
1419 email_button
->AddChildView(delete_button
);
1421 // Save the original email address, as the button text could be elided.
1422 delete_account_button_map_
[delete_button
] = account_id
;
1426 views::View
* ProfileChooserView::CreateGaiaSigninView() {
1430 switch (view_mode_
) {
1431 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN
:
1432 url
= signin::GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN
,
1433 false /* auto_close */,
1434 true /* is_constrained */);
1435 message_id
= IDS_PROFILES_GAIA_SIGNIN_TITLE
;
1437 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT
:
1438 url
= signin::GetPromoURL(
1439 signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT
,
1440 false /* auto_close */,
1441 true /* is_constrained */);
1442 message_id
= IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE
;
1444 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH
: {
1445 DCHECK(HasAuthError(browser_
->profile()));
1446 url
= signin::GetReauthURL(browser_
->profile(),
1447 GetAuthErrorUsername(browser_
->profile()));
1448 message_id
= IDS_PROFILES_GAIA_REAUTH_TITLE
;
1452 NOTREACHED() << "Called with invalid mode=" << view_mode_
;
1456 // Adds Gaia signin webview
1457 Profile
* profile
= browser_
->profile();
1458 views::WebView
* web_view
= new views::WebView(profile
);
1459 web_view
->LoadInitialURL(url
);
1460 web_view
->GetWebContents()->SetDelegate(this);
1461 web_view
->SetPreferredSize(
1462 gfx::Size(kFixedGaiaViewWidth
, kFixedGaiaViewHeight
));
1463 content::RenderWidgetHostView
* rwhv
=
1464 web_view
->GetWebContents()->GetRenderWidgetHostView();
1466 rwhv
->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor
);
1467 TitleCard
* title_card
= new TitleCard(l10n_util::GetStringUTF16(message_id
),
1469 &gaia_signin_cancel_button_
);
1470 return TitleCard::AddPaddedTitleCard(
1471 web_view
, title_card
, kFixedGaiaViewWidth
);
1474 views::View
* ProfileChooserView::CreateAccountRemovalView() {
1475 views::View
* view
= new views::View();
1476 views::GridLayout
* layout
= CreateSingleColumnLayout(
1477 view
, kFixedAccountRemovalViewWidth
- 2 * views::kButtonHEdgeMarginNew
);
1478 layout
->SetInsets(0,
1479 views::kButtonHEdgeMarginNew
,
1480 views::kButtonVEdgeMarginNew
,
1481 views::kButtonHEdgeMarginNew
);
1483 const std::string
& primary_account
= SigninManagerFactory::GetForProfile(
1484 browser_
->profile())->GetAuthenticatedAccountId();
1485 bool is_primary_account
= primary_account
== account_id_to_remove_
;
1488 layout
->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing
);
1489 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
1490 const gfx::FontList
& small_font_list
=
1491 rb
->GetFontList(ui::ResourceBundle::SmallFont
);
1493 if (is_primary_account
) {
1494 std::string email
= signin_ui_util::GetDisplayEmail(browser_
->profile(),
1495 account_id_to_remove_
);
1496 std::vector
<size_t> offsets
;
1497 const base::string16 settings_text
=
1498 l10n_util::GetStringUTF16(IDS_PROFILES_SETTINGS_LINK
);
1499 const base::string16 primary_account_removal_text
=
1500 l10n_util::GetStringFUTF16(IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT
,
1501 base::UTF8ToUTF16(email
), settings_text
, &offsets
);
1502 views::StyledLabel
* primary_account_removal_label
=
1503 new views::StyledLabel(primary_account_removal_text
, this);
1504 primary_account_removal_label
->AddStyleRange(
1505 gfx::Range(offsets
[1], offsets
[1] + settings_text
.size()),
1506 views::StyledLabel::RangeStyleInfo::CreateForLink());
1507 primary_account_removal_label
->SetBaseFontList(small_font_list
);
1508 layout
->AddView(primary_account_removal_label
);
1510 views::Label
* content_label
= new views::Label(
1511 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT
));
1512 content_label
->SetMultiLine(true);
1513 content_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1514 content_label
->SetFontList(small_font_list
);
1515 layout
->AddView(content_label
);
1519 if (!is_primary_account
) {
1520 remove_account_button_
= new views::BlueButton(
1521 this, l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON
));
1522 remove_account_button_
->SetHorizontalAlignment(
1524 layout
->StartRowWithPadding(
1525 1, 0, 0, views::kUnrelatedControlVerticalSpacing
);
1526 layout
->AddView(remove_account_button_
);
1528 layout
->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing
);
1531 TitleCard
* title_card
= new TitleCard(
1532 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE
),
1533 this, &account_removal_cancel_button_
);
1534 return TitleCard::AddPaddedTitleCard(view
, title_card
,
1535 kFixedAccountRemovalViewWidth
);
1538 views::View
* ProfileChooserView::CreateWelcomeUpgradeTutorialViewIfNeeded(
1539 bool tutorial_shown
, const AvatarMenu::Item
& avatar_item
) {
1540 Profile
* profile
= browser_
->profile();
1542 const int show_count
= profile
->GetPrefs()->GetInteger(
1543 prefs::kProfileAvatarTutorialShown
);
1544 // Do not show the tutorial if user has dismissed it.
1545 if (show_count
> signin_ui_util::kUpgradeWelcomeTutorialShowMax
)
1548 if (!tutorial_shown
) {
1549 if (show_count
== signin_ui_util::kUpgradeWelcomeTutorialShowMax
)
1551 profile
->GetPrefs()->SetInteger(
1552 prefs::kProfileAvatarTutorialShown
, show_count
+ 1);
1554 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
1555 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW
);
1557 // For local profiles, the "Not you" link doesn't make sense.
1558 base::string16 link_message
= avatar_item
.signed_in
?
1559 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU
, avatar_item
.name
) :
1562 return CreateTutorialView(
1563 profiles::TUTORIAL_MODE_WELCOME_UPGRADE
,
1564 l10n_util::GetStringUTF16(
1565 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE
),
1566 l10n_util::GetStringUTF16(
1567 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT
),
1569 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON
),
1570 true /* stack_button */,
1571 &tutorial_not_you_link_
,
1572 &tutorial_see_whats_new_button_
,
1573 &tutorial_close_button_
);
1576 views::View
* ProfileChooserView::CreateSigninConfirmationView() {
1577 ProfileMetrics::LogProfileNewAvatarMenuSignin(
1578 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW
);
1580 return CreateTutorialView(
1581 profiles::TUTORIAL_MODE_CONFIRM_SIGNIN
,
1582 l10n_util::GetStringUTF16(IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE
),
1583 l10n_util::GetStringUTF16(
1584 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_CONTENT_TEXT
),
1585 l10n_util::GetStringUTF16(IDS_PROFILES_SYNC_SETTINGS_LINK
),
1586 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_OK_BUTTON
),
1587 false /* stack_button */,
1588 &tutorial_sync_settings_link_
,
1589 &tutorial_sync_settings_ok_button_
,
1590 NULL
/* close_button*/);
1593 views::View
* ProfileChooserView::CreateSigninErrorView() {
1594 LoginUIService
* login_ui_service
=
1595 LoginUIServiceFactory::GetForProfile(browser_
->profile());
1596 base::string16
last_login_result(login_ui_service
->GetLastLoginResult());
1597 return CreateTutorialView(
1598 profiles::TUTORIAL_MODE_SHOW_ERROR
,
1599 l10n_util::GetStringUTF16(IDS_PROFILES_ERROR_TUTORIAL_TITLE
),
1601 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE
),
1603 false /* stack_button */,
1604 &tutorial_learn_more_link_
,
1606 &tutorial_close_button_
);
1609 views::View
* ProfileChooserView::CreateSwitchUserView() {
1610 views::View
* view
= new views::View();
1611 views::GridLayout
* layout
= CreateSingleColumnLayout(
1612 view
, kFixedSwitchUserViewWidth
);
1613 views::ColumnSet
* columns
= layout
->AddColumnSet(1);
1614 columns
->AddPaddingColumn(0, views::kButtonHEdgeMarginNew
);
1616 kFixedSwitchUserViewWidth
- 2 * views::kButtonHEdgeMarginNew
;
1617 columns
->AddColumn(views::GridLayout::FILL
, views::GridLayout::FILL
, 0,
1618 views::GridLayout::FIXED
, label_width
, label_width
);
1619 columns
->AddPaddingColumn(0, views::kButtonHEdgeMarginNew
);
1622 layout
->StartRowWithPadding(1, 1, 0, views::kUnrelatedControlVerticalSpacing
);
1623 ui::ResourceBundle
* rb
= &ui::ResourceBundle::GetSharedInstance();
1624 const gfx::FontList
& small_font_list
=
1625 rb
->GetFontList(ui::ResourceBundle::SmallFont
);
1626 const AvatarMenu::Item
& avatar_item
=
1627 avatar_menu_
->GetItemAt(avatar_menu_
->GetActiveProfileIndex());
1628 views::Label
* content_label
= new views::Label(
1629 l10n_util::GetStringFUTF16(
1630 IDS_PROFILES_NOT_YOU_CONTENT_TEXT
, avatar_item
.name
));
1631 content_label
->SetMultiLine(true);
1632 content_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
1633 content_label
->SetFontList(small_font_list
);
1634 layout
->AddView(content_label
);
1636 // Adds "Add person" button.
1637 layout
->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing
);
1638 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
1640 add_person_button_
= new BackgroundColorHoverButton(
1642 l10n_util::GetStringUTF16(IDS_PROFILES_ADD_PERSON_BUTTON
),
1643 *rb
->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR
));
1644 layout
->StartRow(1, 0);
1645 layout
->AddView(add_person_button_
);
1647 // Adds "Disconnect your Google Account" button.
1648 layout
->StartRow(1, 0);
1649 layout
->AddView(new views::Separator(views::Separator::HORIZONTAL
));
1651 disconnect_button_
= new BackgroundColorHoverButton(
1653 l10n_util::GetStringUTF16(IDS_PROFILES_DISCONNECT_BUTTON
),
1654 *rb
->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_DISCONNECT
));
1655 layout
->StartRow(1, 0);
1656 layout
->AddView(disconnect_button_
);
1658 TitleCard
* title_card
= new TitleCard(
1659 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU
, avatar_item
.name
),
1660 this, &switch_user_cancel_button_
);
1661 return TitleCard::AddPaddedTitleCard(view
, title_card
,
1662 kFixedSwitchUserViewWidth
);
1665 bool ProfileChooserView::ShouldShowGoIncognito() const {
1666 bool incognito_available
=
1667 IncognitoModePrefs::GetAvailability(browser_
->profile()->GetPrefs()) !=
1668 IncognitoModePrefs::DISABLED
;
1669 return incognito_available
&& !browser_
->profile()->IsGuestSession();
1672 void ProfileChooserView::PostActionPerformed(
1673 ProfileMetrics::ProfileDesktopMenu action_performed
) {
1674 ProfileMetrics::LogProfileDesktopMenu(action_performed
, gaia_service_type_
);
1675 gaia_service_type_
= signin::GAIA_SERVICE_TYPE_NONE
;