Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / profiles / profile_chooser_view.cc
index 5cfbdd4..a0f2a32 100644 (file)
@@ -15,6 +15,7 @@
 #include "chrome/browser/profiles/profile_metrics.h"
 #include "chrome/browser/profiles/profile_window.h"
 #include "chrome/browser/profiles/profiles_state.h"
+#include "chrome/browser/signin/local_auth.h"
 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
 #include "chrome/browser/signin/signin_header_helper.h"
 #include "chrome/browser/signin/signin_manager_factory.h"
 #include "chrome/browser/ui/browser_dialogs.h"
 #include "chrome/browser/ui/chrome_pages.h"
 #include "chrome/browser/ui/singleton_tabs.h"
+#include "chrome/browser/ui/user_manager.h"
 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/url_constants.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h"
 #include "components/signin/core/browser/profile_oauth2_token_service.h"
 #include "components/signin/core/browser/signin_error_controller.h"
 #include "components/signin/core/browser/signin_manager.h"
 #include "components/signin/core/common/profile_management_switches.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
 #include "grit/theme_resources.h"
 #include "third_party/skia/include/core/SkColor.h"
 #include "ui/base/l10n/l10n_util.h"
@@ -199,6 +201,7 @@ class RightAlignedIconLabelButton : public views::LabelButton {
     label()->SetHorizontalAlignment(gfx::ALIGN_CENTER);
   }
 
+ private:
   DISALLOW_COPY_AND_ASSIGN(RightAlignedIconLabelButton);
 };
 
@@ -229,7 +232,6 @@ class EditableProfilePhoto : public views::LabelButton {
       return;
     }
 
-    SetFocusable(true);
     set_notify_enter_exit_on_child(true);
 
     // Photo overlay that appears when hovering over the button.
@@ -312,7 +314,6 @@ class EditableProfileName : public RightAlignedIconLabelButton,
       return;
     }
 
-    SetFocusable(true);
     // Show an "edit" pencil icon when hovering over. In the default state,
     // we need to create an empty placeholder of the correct size, so that
     // the text doesn't jump around when the hovered icon appears.
@@ -455,7 +456,7 @@ class TitleCard : public views::View {
   }
 
  private:
-  virtual void Layout() OVERRIDE{
+  virtual void Layout() OVERRIDE {
     int back_button_width = back_button_->GetPreferredSize().width();
     back_button_->SetBounds(0, 0, back_button_width, height());
     int label_padding = back_button_width + views::kButtonHEdgeMarginNew;
@@ -464,7 +465,7 @@ class TitleCard : public views::View {
     title_label_->SetBounds(label_padding, 0, label_width, height());
   }
 
-  virtual gfx::Size GetPreferredSize() const OVERRIDE{
+  virtual gfx::Size GetPreferredSize() const OVERRIDE {
     int height = std::max(title_label_->GetPreferredSize().height(),
         back_button_->GetPreferredSize().height());
     return gfx::Size(width(), height);
@@ -595,22 +596,22 @@ void ProfileChooserView::Init() {
     view_mode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT;
   }
 
+  // The arrow keys can be used to tab between items.
+  AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE));
+  AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE));
+
   ShowView(view_mode_, avatar_menu_.get());
 }
 
 void ProfileChooserView::OnAvatarMenuChanged(
     AvatarMenu* avatar_menu) {
-  // Do not refresh the avatar menu if the user is on a signin related view.
-  if (view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN ||
-      view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT ||
-      view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) {
-    return;
+  if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
+      view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
+    // Refresh the view with the new menu. We can't just update the local copy
+    // as this may have been triggered by a sign out action, in which case
+    // the view is being destroyed.
+    ShowView(view_mode_, avatar_menu);
   }
-
-  // Refresh the view with the new menu. We can't just update the local copy
-  // as this may have been triggered by a sign out action, in which case
-  // the view is being destroyed.
-  ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu);
 }
 
 void ProfileChooserView::OnRefreshTokenAvailable(
@@ -699,6 +700,16 @@ void ProfileChooserView::WindowClosing() {
   }
 }
 
+bool ProfileChooserView::AcceleratorPressed(
+    const ui::Accelerator& accelerator) {
+  if (accelerator.key_code() != ui::VKEY_DOWN &&
+      accelerator.key_code() != ui::VKEY_UP)
+    return BubbleDelegateView::AcceleratorPressed(accelerator);
+  // Move the focus up or down.
+  GetFocusManager()->AdvanceFocus(accelerator.key_code() != ui::VKEY_DOWN);
+  return true;
+}
+
 void ProfileChooserView::ButtonPressed(views::Button* sender,
                                        const ui::Event& event) {
   // Disable button after clicking so that it doesn't get clicked twice and
@@ -708,12 +719,13 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
     sender->SetEnabled(false);
 
   if (sender == users_button_) {
-    // If this is a guest session, also close all the guest browser windows.
+    // If this is a guest session, close all the guest browser windows.
     if (browser_->profile()->IsGuestSession()) {
-      chrome::ShowUserManager(base::FilePath());
       profiles::CloseGuestProfileWindows();
     } else {
-      chrome::ShowUserManager(browser_->profile()->GetPath());
+      UserManager::Show(base::FilePath(),
+                        profiles::USER_MANAGER_NO_TUTORIAL,
+                        profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
     }
     PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER);
   } else if (sender == go_incognito_button_) {
@@ -737,20 +749,20 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
   } else if (sender == tutorial_see_whats_new_button_) {
     ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
         ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_WHATS_NEW);
-    chrome::ShowUserManagerWithTutorial(
-        profiles::USER_MANAGER_TUTORIAL_OVERVIEW);
+    UserManager::Show(base::FilePath(),
+                      profiles::USER_MANAGER_TUTORIAL_OVERVIEW,
+                      profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
   } else if (sender == remove_account_button_) {
     RemoveAccount();
   } else if (sender == account_removal_cancel_button_) {
     account_id_to_remove_.clear();
     ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get());
   } else if (sender == gaia_signin_cancel_button_) {
-    std::string primary_account =
-        SigninManagerFactory::GetForProfile(browser_->profile())->
-        GetAuthenticatedUsername();
     // The account management view is only available with the
     // --enable-account-consistency flag.
-    bool account_management_available = !primary_account.empty() &&
+    bool account_management_available =
+        SigninManagerFactory::GetForProfile(browser_->profile())->
+            IsAuthenticated() &&
         switches::IsEnableAccountConsistency();
     ShowView(account_management_available ?
         profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT :
@@ -763,7 +775,9 @@ void ProfileChooserView::ButtonPressed(views::Button* sender,
   } else if (sender == add_person_button_) {
     ProfileMetrics::LogProfileNewAvatarMenuNotYou(
         ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON);
-    chrome::ShowUserManager(browser_->profile()->GetPath());
+    UserManager::Show(base::FilePath(),
+                      profiles::USER_MANAGER_NO_TUTORIAL,
+                      profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
   } else if (sender == disconnect_button_) {
     ProfileMetrics::LogProfileNewAvatarMenuNotYou(
         ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT);
@@ -832,7 +846,7 @@ void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) {
     tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
     ProfileMetrics::LogProfileNewAvatarMenuSignin(
         ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS);
-  } else if (sender == tutorial_not_you_link_){
+  } else if (sender == tutorial_not_you_link_) {
     ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
         ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU);
     ShowView(profiles::BUBBLE_VIEW_MODE_SWITCH_USER, avatar_menu_.get());
@@ -1245,7 +1259,7 @@ views::View* ProfileChooserView::CreateOtherProfilesView(
   return view;
 }
 
-views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) {
+views::View* ProfileChooserView::CreateOptionsView(bool display_lock) {
   views::View* view = new views::View();
   views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
 
@@ -1272,7 +1286,7 @@ views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) {
     layout->AddView(go_incognito_button_);
   }
 
-  if (enable_lock) {
+  if (display_lock) {
     layout->StartRow(1, 0);
     layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
 
@@ -1297,6 +1311,7 @@ views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() {
   views::Label* disclaimer = new views::Label(
       avatar_menu_->GetSupervisedUserInformation());
   disclaimer->SetMultiLine(true);
+  disclaimer->SetAllowCharacterBreak(true);
   disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT);
   ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
   disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont));
@@ -1316,7 +1331,7 @@ views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
 
   Profile* profile = browser_->profile();
   std::string primary_account =
-      SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername();
+      SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
   DCHECK(!primary_account.empty());
   std::vector<std::string>accounts =
       profiles::GetSecondaryAccountsForProfile(profile, primary_account);
@@ -1350,10 +1365,12 @@ views::View* ProfileChooserView::CreateCurrentProfileAccountsView(
 }
 
 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout,
-                                             const std::string& account,
+                                             const std::string& account_id,
                                              bool is_primary_account,
                                              bool reauth_required,
                                              int width) {
+  std::string email = signin_ui_util::GetDisplayEmail(browser_->profile(),
+                                                      account_id);
   ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
   const gfx::ImageSkia* delete_default_image =
       rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia();
@@ -1367,7 +1384,7 @@ void ProfileChooserView::CreateAccountButton(views::GridLayout* layout,
       - kDeleteButtonWidth - kWarningButtonWidth;
   views::LabelButton* email_button = new BackgroundColorHoverButton(
       reauth_required ? this : NULL,
-      base::UTF8ToUTF16(account),
+      base::UTF8ToUTF16(email),
       warning_default_image);
   email_button->SetElideBehavior(gfx::ELIDE_EMAIL);
   email_button->SetMinSize(gfx::Size(0, kButtonHeight));
@@ -1376,7 +1393,7 @@ void ProfileChooserView::CreateAccountButton(views::GridLayout* layout,
   layout->AddView(email_button);
 
   if (reauth_required)
-    reauth_account_button_map_[email_button] = account;
+    reauth_account_button_map_[email_button] = account_id;
 
   // Delete button.
   if (!browser_->profile()->IsSupervised()) {
@@ -1397,7 +1414,7 @@ void ProfileChooserView::CreateAccountButton(views::GridLayout* layout,
     email_button->AddChildView(delete_button);
 
     // Save the original email address, as the button text could be elided.
-    delete_account_button_map_[delete_button] = account;
+    delete_account_button_map_[delete_button] = account_id;
   }
 }
 
@@ -1454,7 +1471,7 @@ views::View* ProfileChooserView::CreateAccountRemovalView() {
                     views::kButtonHEdgeMarginNew);
 
   const std::string& primary_account = SigninManagerFactory::GetForProfile(
-      browser_->profile())->GetAuthenticatedUsername();
+      browser_->profile())->GetAuthenticatedAccountId();
   bool is_primary_account = primary_account == account_id_to_remove_;
 
   // Adds main text.
@@ -1464,12 +1481,14 @@ views::View* ProfileChooserView::CreateAccountRemovalView() {
       rb->GetFontList(ui::ResourceBundle::SmallFont);
 
   if (is_primary_account) {
+    std::string email = signin_ui_util::GetDisplayEmail(browser_->profile(),
+                                                        account_id_to_remove_);
     std::vector<size_t> offsets;
     const base::string16 settings_text =
         l10n_util::GetStringUTF16(IDS_PROFILES_SETTINGS_LINK);
     const base::string16 primary_account_removal_text =
         l10n_util::GetStringFUTF16(IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT,
-            base::UTF8ToUTF16(account_id_to_remove_), settings_text, &offsets);
+            base::UTF8ToUTF16(email), settings_text, &offsets);
     views::StyledLabel* primary_account_removal_label =
         new views::StyledLabel(primary_account_removal_text, this);
     primary_account_removal_label->AddStyleRange(
@@ -1507,7 +1526,7 @@ views::View* ProfileChooserView::CreateAccountRemovalView() {
 }
 
 views::View* ProfileChooserView::CreateWelcomeUpgradeTutorialViewIfNeeded(
-    bool tutorial_shown, const AvatarMenu::Item& avatar_item){
+    bool tutorial_shown, const AvatarMenu::Item& avatar_item) {
   Profile* profile = browser_->profile();
 
   const int show_count = profile->GetPrefs()->GetInteger(