OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 449 |
450 // ProfileChooserView --------------------------------------------------------- | 450 // ProfileChooserView --------------------------------------------------------- |
451 | 451 |
452 // static | 452 // static |
453 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; | 453 ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; |
454 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; | 454 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; |
455 | 455 |
456 // static | 456 // static |
457 void ProfileChooserView::ShowBubble( | 457 void ProfileChooserView::ShowBubble( |
458 profiles::BubbleViewMode view_mode, | 458 profiles::BubbleViewMode view_mode, |
| 459 profiles::TutorialMode tutorial_mode, |
459 const signin::ManageAccountsParams& manage_accounts_params, | 460 const signin::ManageAccountsParams& manage_accounts_params, |
460 views::View* anchor_view, | 461 views::View* anchor_view, |
461 views::BubbleBorder::Arrow arrow, | 462 views::BubbleBorder::Arrow arrow, |
462 views::BubbleBorder::BubbleAlignment border_alignment, | 463 views::BubbleBorder::BubbleAlignment border_alignment, |
463 Browser* browser) { | 464 Browser* browser) { |
464 if (IsShowing()) | 465 if (IsShowing()) |
465 return; | 466 return; |
466 | 467 |
467 profile_bubble_ = new ProfileChooserView(anchor_view, arrow, browser, | 468 profile_bubble_ = new ProfileChooserView(anchor_view, arrow, browser, |
468 view_mode, manage_accounts_params.service_type); | 469 view_mode, tutorial_mode, manage_accounts_params.service_type); |
469 views::BubbleDelegateView::CreateBubble(profile_bubble_); | 470 views::BubbleDelegateView::CreateBubble(profile_bubble_); |
470 profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_); | 471 profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_); |
471 profile_bubble_->SetAlignment(border_alignment); | 472 profile_bubble_->SetAlignment(border_alignment); |
472 profile_bubble_->GetWidget()->Show(); | 473 profile_bubble_->GetWidget()->Show(); |
473 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 474 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
474 } | 475 } |
475 | 476 |
476 // static | 477 // static |
477 bool ProfileChooserView::IsShowing() { | 478 bool ProfileChooserView::IsShowing() { |
478 return profile_bubble_ != NULL; | 479 return profile_bubble_ != NULL; |
479 } | 480 } |
480 | 481 |
481 // static | 482 // static |
482 void ProfileChooserView::Hide() { | 483 void ProfileChooserView::Hide() { |
483 if (IsShowing()) | 484 if (IsShowing()) |
484 profile_bubble_->GetWidget()->Close(); | 485 profile_bubble_->GetWidget()->Close(); |
485 } | 486 } |
486 | 487 |
487 ProfileChooserView::ProfileChooserView(views::View* anchor_view, | 488 ProfileChooserView::ProfileChooserView(views::View* anchor_view, |
488 views::BubbleBorder::Arrow arrow, | 489 views::BubbleBorder::Arrow arrow, |
489 Browser* browser, | 490 Browser* browser, |
490 profiles::BubbleViewMode view_mode, | 491 profiles::BubbleViewMode view_mode, |
| 492 profiles::TutorialMode tutorial_mode, |
491 signin::GAIAServiceType service_type) | 493 signin::GAIAServiceType service_type) |
492 : BubbleDelegateView(anchor_view, arrow), | 494 : BubbleDelegateView(anchor_view, arrow), |
493 browser_(browser), | 495 browser_(browser), |
494 view_mode_(view_mode), | 496 view_mode_(view_mode), |
495 tutorial_mode_(profiles::TUTORIAL_MODE_NONE), | 497 tutorial_mode_(tutorial_mode), |
496 gaia_service_type_(service_type) { | 498 gaia_service_type_(service_type) { |
497 // Reset the default margins inherited from the BubbleDelegateView. | 499 // Reset the default margins inherited from the BubbleDelegateView. |
498 // Add a small bottom inset so that the bubble's rounded corners show up. | 500 // Add a small bottom inset so that the bubble's rounded corners show up. |
499 set_margins(gfx::Insets(0, 0, 1, 0)); | 501 set_margins(gfx::Insets(0, 0, 1, 0)); |
500 set_background(views::Background::CreateSolidBackground( | 502 set_background(views::Background::CreateSolidBackground( |
501 GetNativeTheme()->GetSystemColor( | 503 GetNativeTheme()->GetSystemColor( |
502 ui::NativeTheme::kColorId_DialogBackground))); | 504 ui::NativeTheme::kColorId_DialogBackground))); |
503 ResetView(); | 505 ResetView(); |
504 | 506 |
505 avatar_menu_.reset(new AvatarMenu( | 507 avatar_menu_.reset(new AvatarMenu( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 gaia_signin_cancel_button_ = NULL; | 539 gaia_signin_cancel_button_ = NULL; |
538 remove_account_button_ = NULL; | 540 remove_account_button_ = NULL; |
539 account_removal_cancel_button_ = NULL; | 541 account_removal_cancel_button_ = NULL; |
540 add_person_button_ = NULL; | 542 add_person_button_ = NULL; |
541 disconnect_button_ = NULL; | 543 disconnect_button_ = NULL; |
542 switch_user_cancel_button_ = NULL; | 544 switch_user_cancel_button_ = NULL; |
543 tutorial_sync_settings_ok_button_ = NULL; | 545 tutorial_sync_settings_ok_button_ = NULL; |
544 tutorial_sync_settings_link_ = NULL; | 546 tutorial_sync_settings_link_ = NULL; |
545 tutorial_see_whats_new_button_ = NULL; | 547 tutorial_see_whats_new_button_ = NULL; |
546 tutorial_not_you_link_ = NULL; | 548 tutorial_not_you_link_ = NULL; |
547 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; | |
548 } | 549 } |
549 | 550 |
550 void ProfileChooserView::Init() { | 551 void ProfileChooserView::Init() { |
551 // If view mode is PROFILE_CHOOSER but there is an auth error, force | 552 // If view mode is PROFILE_CHOOSER but there is an auth error, force |
552 // ACCOUNT_MANAGEMENT mode. | 553 // ACCOUNT_MANAGEMENT mode. |
553 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | 554 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && |
554 HasAuthError(browser_->profile()) && | 555 HasAuthError(browser_->profile()) && |
555 switches::IsEnableAccountConsistency() && | 556 switches::IsEnableAccountConsistency() && |
556 avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()). | 557 avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()). |
557 signed_in) { | 558 signed_in) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 DCHECK(active_item.signed_in); | 611 DCHECK(active_item.signed_in); |
611 } | 612 } |
612 | 613 |
613 if (browser_->profile()->IsSupervised() && | 614 if (browser_->profile()->IsSupervised() && |
614 (view_to_display == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || | 615 (view_to_display == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || |
615 view_to_display == profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL)) { | 616 view_to_display == profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL)) { |
616 LOG(WARNING) << "Supervised user attempted to add/remove account"; | 617 LOG(WARNING) << "Supervised user attempted to add/remove account"; |
617 return; | 618 return; |
618 } | 619 } |
619 | 620 |
620 // Records the last tutorial mode. | |
621 profiles::TutorialMode last_tutorial_mode = tutorial_mode_; | |
622 ResetView(); | 621 ResetView(); |
623 RemoveAllChildViews(true); | 622 RemoveAllChildViews(true); |
624 view_mode_ = view_to_display; | 623 view_mode_ = view_to_display; |
625 | 624 |
626 views::GridLayout* layout; | 625 views::GridLayout* layout; |
627 views::View* sub_view; | 626 views::View* sub_view; |
628 switch (view_mode_) { | 627 switch (view_mode_) { |
629 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: | 628 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: |
630 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: | 629 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: |
631 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: | 630 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: |
632 layout = CreateSingleColumnLayout(this, kFixedGaiaViewWidth); | 631 layout = CreateSingleColumnLayout(this, kFixedGaiaViewWidth); |
633 sub_view = CreateGaiaSigninView(); | 632 sub_view = CreateGaiaSigninView(); |
634 break; | 633 break; |
635 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL: | 634 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL: |
636 layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth); | 635 layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth); |
637 sub_view = CreateAccountRemovalView(); | 636 sub_view = CreateAccountRemovalView(); |
638 break; | 637 break; |
639 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: | 638 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: |
640 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); | 639 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); |
641 sub_view = CreateSwitchUserView(); | 640 sub_view = CreateSwitchUserView(); |
642 break; | 641 break; |
643 default: | 642 default: |
644 layout = CreateSingleColumnLayout(this, kFixedMenuWidth); | 643 layout = CreateSingleColumnLayout(this, kFixedMenuWidth); |
645 sub_view = CreateProfileChooserView(avatar_menu, last_tutorial_mode); | 644 sub_view = CreateProfileChooserView(avatar_menu); |
646 } | 645 } |
647 layout->StartRow(1, 0); | 646 layout->StartRow(1, 0); |
648 layout->AddView(sub_view); | 647 layout->AddView(sub_view); |
649 Layout(); | 648 Layout(); |
650 if (GetBubbleFrameView()) | 649 if (GetBubbleFrameView()) |
651 SizeToContents(); | 650 SizeToContents(); |
652 } | 651 } |
653 | 652 |
654 void ProfileChooserView::WindowClosing() { | 653 void ProfileChooserView::WindowClosing() { |
655 DCHECK_EQ(profile_bubble_, this); | 654 DCHECK_EQ(profile_bubble_, this); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 811 |
813 profiles::UpdateProfileName(profile, new_profile_name); | 812 profiles::UpdateProfileName(profile, new_profile_name); |
814 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); | 813 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); |
815 current_profile_name_->ShowReadOnlyView(); | 814 current_profile_name_->ShowReadOnlyView(); |
816 return true; | 815 return true; |
817 } | 816 } |
818 return false; | 817 return false; |
819 } | 818 } |
820 | 819 |
821 views::View* ProfileChooserView::CreateProfileChooserView( | 820 views::View* ProfileChooserView::CreateProfileChooserView( |
822 AvatarMenu* avatar_menu, | 821 AvatarMenu* avatar_menu) { |
823 profiles::TutorialMode last_tutorial_mode) { | |
824 // TODO(guohui, noms): the view should be customized based on whether new | 822 // TODO(guohui, noms): the view should be customized based on whether new |
825 // profile management preview is enabled or not. | 823 // profile management preview is enabled or not. |
826 | 824 |
827 views::View* view = new views::View(); | 825 views::View* view = new views::View(); |
828 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 826 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
829 // Separate items into active and alternatives. | 827 // Separate items into active and alternatives. |
830 Indexes other_profiles; | 828 Indexes other_profiles; |
831 views::View* tutorial_view = NULL; | 829 views::View* tutorial_view = NULL; |
832 views::View* current_profile_view = NULL; | 830 views::View* current_profile_view = NULL; |
833 views::View* current_profile_accounts = NULL; | 831 views::View* current_profile_accounts = NULL; |
834 views::View* option_buttons_view = NULL; | 832 views::View* option_buttons_view = NULL; |
835 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 833 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
836 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 834 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
837 if (item.active) { | 835 if (item.active) { |
838 option_buttons_view = CreateOptionsView( | 836 option_buttons_view = CreateOptionsView( |
839 switches::IsNewProfileManagement() && item.signed_in); | 837 switches::IsNewProfileManagement() && item.signed_in); |
840 current_profile_view = CreateCurrentProfileView(item, false); | 838 current_profile_view = CreateCurrentProfileView(item, false); |
841 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 839 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { |
842 switch (last_tutorial_mode) { | 840 switch (tutorial_mode_) { |
843 case profiles::TUTORIAL_MODE_NONE: | 841 case profiles::TUTORIAL_MODE_NONE: |
844 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: | 842 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: |
845 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( | 843 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( |
846 last_tutorial_mode == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, | 844 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, |
847 item); | 845 item); |
848 break; | 846 break; |
849 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: | 847 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: |
850 tutorial_view = CreateSigninConfirmationView(); | 848 tutorial_view = CreateSigninConfirmationView(); |
851 break; | 849 break; |
852 case profiles::TUTORIAL_MODE_SHOW_ERROR: | 850 case profiles::TUTORIAL_MODE_SHOW_ERROR: |
853 // TODO(guohui): not implemented yet. | 851 // TODO(guohui): not implemented yet. |
854 NOTREACHED(); | 852 NOTREACHED(); |
855 } | 853 } |
856 } else { | 854 } else { |
857 current_profile_accounts = CreateCurrentProfileAccountsView(item); | 855 current_profile_accounts = CreateCurrentProfileAccountsView(item); |
858 } | 856 } |
859 } else { | 857 } else { |
860 other_profiles.push_back(i); | 858 other_profiles.push_back(i); |
861 } | 859 } |
862 } | 860 } |
863 | 861 |
864 if (tutorial_view) { | 862 if (tutorial_view) { |
865 // TODO(mlerman): update UMA stats for the new tutorial. | 863 // TODO(mlerman): update UMA stats for the new tutorial. |
866 layout->StartRow(1, 0); | 864 layout->StartRow(1, 0); |
867 layout->AddView(tutorial_view); | 865 layout->AddView(tutorial_view); |
| 866 } else { |
| 867 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; |
868 } | 868 } |
869 | 869 |
870 if (!current_profile_view) { | 870 if (!current_profile_view) { |
871 // Guest windows don't have an active profile. | 871 // Guest windows don't have an active profile. |
872 current_profile_view = CreateGuestProfileView(); | 872 current_profile_view = CreateGuestProfileView(); |
873 option_buttons_view = CreateOptionsView(false); | 873 option_buttons_view = CreateOptionsView(false); |
874 } | 874 } |
875 | 875 |
876 layout->StartRow(1, 0); | 876 layout->StartRow(1, 0); |
877 layout->AddView(current_profile_view); | 877 layout->AddView(current_profile_view); |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 1497 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
1498 IncognitoModePrefs::DISABLED; | 1498 IncognitoModePrefs::DISABLED; |
1499 return incognito_available && !browser_->profile()->IsGuestSession(); | 1499 return incognito_available && !browser_->profile()->IsGuestSession(); |
1500 } | 1500 } |
1501 | 1501 |
1502 void ProfileChooserView::PostActionPerformed( | 1502 void ProfileChooserView::PostActionPerformed( |
1503 ProfileMetrics::ProfileDesktopMenu action_performed) { | 1503 ProfileMetrics::ProfileDesktopMenu action_performed) { |
1504 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 1504 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
1505 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 1505 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
1506 } | 1506 } |
OLD | NEW |