profile_chooser_view.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
1c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file. 47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/prefs/pref_service.h" 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/browser_process.h" 10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/browser/lifetime/application_lifetime.h" 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/prefs/incognito_mode_prefs.h" 12c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/profiles/profile_avatar_icon_util.h" 130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "chrome/browser/profiles/profile_info_cache.h" 147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h" 15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/profiles/profile_metrics.h" 16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/profiles/profile_window.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/profiles/profiles_state.h" 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/signin/signin_header_helper.h" 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/signin/signin_manager_factory.h" 21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/signin/signin_promo.h" 226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/signin/signin_ui_util.h" 2368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/ui/browser_commands.h" 250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/ui/browser_dialogs.h" 26c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/chrome_pages.h" 27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/ui/singleton_tabs.h" 28c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/ui/views/profiles/user_manager_view.h" 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/ui/webui/signin/login_ui_service.h" 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/common/pref_names.h" 324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/common/url_constants.h" 33effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" 34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/signin/core/browser/profile_oauth2_token_service.h" 35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/signin/core/browser/signin_error_controller.h" 36e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include "components/signin/core/browser/signin_manager.h" 370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "components/signin/core/common/profile_management_switches.h" 38d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "grit/chromium_strings.h" 397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "grit/generated_resources.h" 403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "grit/theme_resources.h" 4168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h" 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/canvas.h" 457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/gfx/image/image.h" 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/gfx/image/image_skia.h" 47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/gfx/path.h" 48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/gfx/skia_util.h" 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/text_elider.h" 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/native_theme/native_theme.h" 51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/views/controls/button/blue_button.h" 52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/views/controls/button/image_button.h" 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/button/label_button.h" 54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/views/controls/button/menu_button.h" 557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/controls/label.h" 567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/controls/link.h" 577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/controls/separator.h" 58c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/views/controls/styled_label.h" 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/views/controls/textfield/textfield.h" 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/controls/webview/webview.h" 617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/layout/grid_layout.h" 627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/layout/layout_constants.h" 637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/widget/widget.h" 647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace { 66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 6768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// Helpers -------------------------------------------------------------------- 6868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kFixedMenuWidth = 250; 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const int kButtonHeight = 32; 7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int kFixedGaiaViewHeight = 440; 72effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochconst int kFixedGaiaViewWidth = 360; 73effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochconst int kFixedAccountRemovalViewWidth = 280; 745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const int kFixedSwitchUserViewWidth = 280; 755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuconst int kLargeImageSide = 88; 76d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Creates a GridLayout with a single column. This ensures that all the child 78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// views added get auto-expanded to fill the full width of the bubble. 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { 80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::GridLayout* layout = new views::GridLayout(view); 81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) view->SetLayoutManager(layout); 82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 83d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::ColumnSet* columns = layout->AddColumnSet(0); 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::GridLayout::FIXED, width, width); 86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return layout; 87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)views::Link* CreateLink(const base::string16& link_text, 90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::LinkListener* listener) { 91d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::Link* link_button = new views::Link(link_text); 92d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); 93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) link_button->SetUnderline(false); 94d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) link_button->set_listener(listener); 95d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return link_button; 96d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liugfx::ImageSkia CreateSquarePlaceholderImage(int size) { 995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SkBitmap bitmap; 100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bitmap.allocPixels(SkImageInfo::MakeA8(size, size)); 1015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bitmap.eraseARGB(0, 0, 0, 0); 1025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 1035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu} 10468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 105cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool HasAuthError(Profile* profile) { 106cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const SigninErrorController* error = 107cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::GetSigninErrorController(profile); 108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return error && error->HasError(); 109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 110cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 111cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)std::string GetAuthErrorAccountId(Profile* profile) { 112cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const SigninErrorController* error = 113cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::GetSigninErrorController(profile); 114cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!error) 115cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return std::string(); 116cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 117cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return error->error_account_id(); 118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 120cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)std::string GetAuthErrorUsername(Profile* profile) { 121cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const SigninErrorController* error = 122cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::GetSigninErrorController(profile); 123cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!error) 124cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return std::string(); 125cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 126cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return error->error_username(); 127cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 128cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// BackgroundColorHoverButton ------------------------------------------------- 13068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A custom button that allows for setting a background color when hovered over. 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class BackgroundColorHoverButton : public views::LabelButton { 13368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public: 134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) BackgroundColorHoverButton(views::ButtonListener* listener, 135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const base::string16& text, 1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const gfx::ImageSkia& icon) 1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : views::LabelButton(listener, text) { 1386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) SetImageLabelSpacing(views::kItemLabelSpacing); 1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetBorder(views::Border::CreateEmptyBorder( 1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); 1415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetMinSize(gfx::Size(0, 1425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) kButtonHeight + views::kRelatedControlVerticalSpacing)); 1435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetImage(STATE_NORMAL, icon); 14403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetFocusable(true); 1455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual ~BackgroundColorHoverButton() {} 14868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 14968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) private: 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // views::LabelButton: 1515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 1525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if ((state() == STATE_PRESSED) || 1535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) (state() == STATE_HOVERED) || 1545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) HasFocus()) { 1555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) canvas->DrawColor(GetNativeTheme()->GetSystemColor( 1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::NativeTheme::kColorId_ButtonHoverBackgroundColor)); 1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) LabelButton::OnPaint(canvas); 1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 16068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 161f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BackgroundColorHoverButton); 16268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)}; 16368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 164f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// SizedContainer ------------------------------------------------- 165f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 166f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// A simple container view that takes an explicit preferred size. 167f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class SizedContainer : public views::View { 168f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public: 169f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) explicit SizedContainer(const gfx::Size& preferred_size) 170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) : preferred_size_(preferred_size) {} 171f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 172f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual gfx::Size GetPreferredSize() const OVERRIDE { 173f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return preferred_size_; 174f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 175f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 176f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) private: 177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) gfx::Size preferred_size_; 178f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}; 179f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 180f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} // namespace 181f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// RightAlignedIconLabelButton ------------------------------------------------- 1835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// A custom LabelButton that has a centered text and right aligned icon. 1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class RightAlignedIconLabelButton : public views::LabelButton { 1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) public: 1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) RightAlignedIconLabelButton(views::ButtonListener* listener, 1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const base::string16& text) 1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : views::LabelButton(listener, text) { 1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) protected: 1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void Layout() OVERRIDE { 1945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // This layout trick keeps the text left-aligned and the icon right-aligned. 1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetHorizontalAlignment(gfx::ALIGN_RIGHT); 1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::LabelButton::Layout(); 1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); 1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(RightAlignedIconLabelButton); 2015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}; 202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// EditableProfilePhoto ------------------------------------------------- 204f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 205f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A custom Image control that shows a "change" button when moused over. 20603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class EditableProfilePhoto : public views::LabelButton { 20768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) public: 208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EditableProfilePhoto(views::ButtonListener* listener, 209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const gfx::Image& icon, 2105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool is_editing_allowed, 2115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const gfx::Rect& bounds) 21203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) : views::LabelButton(listener, base::string16()), 21303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_(NULL) { 2140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch gfx::Image image = profiles::GetSizedAvatarIcon( 215010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) icon, true, kLargeImageSide, kLargeImageSide); 21603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); 21703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetBorder(views::Border::NullBorder()); 2185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SetBoundsRect(bounds); 219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 220cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Calculate the circular mask that will be used to display the photo. 221f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) circular_mask_.addCircle(SkIntToScalar(bounds.width() / 2), 222f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) SkIntToScalar(bounds.height() / 2), 223cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) SkIntToScalar(bounds.width() / 2)); 224010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 22503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (!is_editing_allowed) { 22603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetEnabled(false); 227a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return; 22803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 23003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetFocusable(true); 231f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) set_notify_enter_exit_on_child(true); 232f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 23303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Photo overlay that appears when hovering over the button. 23403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_ = new views::ImageView(); 235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 236010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); 23703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_->set_background( 238f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) views::Background::CreateSolidBackground(kBackgroundColor)); 23903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_->SetImage(*ui::ResourceBundle::GetSharedInstance(). 24003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_CAMERA)); 241010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 24203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_->SetSize(bounds.size()); 24303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_->SetVisible(false); 24403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) AddChildView(photo_overlay_); 245f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 246f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 247cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 248cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Display the profile picture as a circle. 249cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) canvas->ClipPath(circular_mask_, true); 25003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::LabelButton::OnPaint(canvas); 251cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 252cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 253cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void PaintChildren(gfx::Canvas* canvas, 254f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const views::CullSet& cull_set) OVERRIDE { 255cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Display any children (the "change photo" overlay) as a circle. 256cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) canvas->ClipPath(circular_mask_, true); 257cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) View::PaintChildren(canvas, cull_set); 258cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 259cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 26068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) private: 26103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // views::CustomButton: 26203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void StateChanged() OVERRIDE { 26303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) bool show_overlay = 26403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); 26503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (photo_overlay_) 26603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_->SetVisible(show_overlay); 267f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 26868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 26903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void OnFocus() OVERRIDE { 27003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::LabelButton::OnFocus(); 27103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (photo_overlay_) 27203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_->SetVisible(true); 27303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 27403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 27503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void OnBlur() OVERRIDE { 27603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::LabelButton::OnBlur(); 27703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Don't hide the overlay if it's being shown as a result of a mouseover. 27803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (photo_overlay_ && state() != STATE_HOVERED) 27903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) photo_overlay_->SetVisible(false); 280f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 28168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 282cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) gfx::Path circular_mask_; 283cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 28403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Image that is shown when hovering over the image button. Can be NULL if 285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // the photo isn't allowed to be edited (e.g. for guest profiles). 28603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::ImageView* photo_overlay_; 287f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 288f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); 28968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)}; 29068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 291f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// EditableProfileName ------------------------------------------------- 292f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 293f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A custom text control that turns into a textfield for editing when clicked. 2945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class EditableProfileName : public RightAlignedIconLabelButton, 295f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public views::ButtonListener { 296f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 297f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EditableProfileName(views::TextfieldController* controller, 298a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& text, 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool is_editing_allowed) 3005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : RightAlignedIconLabelButton(this, text), 301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) profile_name_textfield_(NULL) { 302f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::FontList& medium_font_list = 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) rb->GetFontList(ui::ResourceBundle::MediumFont); 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFontList(medium_font_list); 3065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SetHorizontalAlignment(gfx::ALIGN_CENTER); 307a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 308cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!is_editing_allowed) { 309cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) SetBorder(views::Border::CreateEmptyBorder(2, 0, 2, 0)); 310a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return; 311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 312f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 31303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetFocusable(true); 3145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Show an "edit" pencil icon when hovering over. In the default state, 3155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // we need to create an empty placeholder of the correct size, so that 3165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // the text doesn't jump around when the hovered icon appears. 3175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu gfx::ImageSkia hover_image = 3185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_HOVER); 3195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SetImage(STATE_NORMAL, CreateSquarePlaceholderImage(hover_image.width())); 3205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SetImage(STATE_HOVERED, hover_image); 3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetImage(STATE_PRESSED, 3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_PRESSED)); 3235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // To center the text, we need to offest it by the width of the icon we 3245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // are adding and its padding. We need to also add a small top/bottom 3255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // padding to account for the textfield's border. 3265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const int kIconTextLabelButtonSpacing = 5; 3275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SetBorder(views::Border::CreateEmptyBorder( 3285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2, hover_image.width() + kIconTextLabelButtonSpacing, 2, 0)); 329f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 330f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Textfield that overlaps the button. 331f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile_name_textfield_ = new views::Textfield(); 3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_name_textfield_->set_controller(controller); 3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_name_textfield_->SetFontList(medium_font_list); 3345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 3355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 336f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile_name_textfield_->SetVisible(false); 337f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) AddChildView(profile_name_textfield_); 338f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 339f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 340f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) views::Textfield* profile_name_textfield() { 341f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return profile_name_textfield_; 342f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 343f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Hide the editable textfield to show the profile name button instead. 345f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void ShowReadOnlyView() { 346a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (profile_name_textfield_) 347a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) profile_name_textfield_->SetVisible(false); 348f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 349f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 350f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 351f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // views::ButtonListener: 352f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void ButtonPressed(views::Button* sender, 353f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ui::Event& event) OVERRIDE { 354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (profile_name_textfield_) { 355a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) profile_name_textfield_->SetVisible(true); 3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_name_textfield_->SetText(GetText()); 357a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) profile_name_textfield_->SelectAll(false); 358a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) profile_name_textfield_->RequestFocus(); 359a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 360f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 361f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // views::LabelButton: 363f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE { 364f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Override CustomButton's implementation, which presses the button when 365f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // you press space and clicks it when you release space, as the space can be 366f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // part of the new profile name typed in the textfield. 367f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 368f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 369f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 370f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void Layout() OVERRIDE { 371a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (profile_name_textfield_) 372a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) profile_name_textfield_->SetBounds(0, 0, width(), height()); 3735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) RightAlignedIconLabelButton::Layout(); 374f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 375f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 37603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void OnFocus() OVERRIDE { 37703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RightAlignedIconLabelButton::OnFocus(); 37803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetState(STATE_HOVERED); 37903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 38003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 38103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void OnBlur() OVERRIDE { 38203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RightAlignedIconLabelButton::OnBlur(); 38303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) SetState(STATE_NORMAL); 38403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 38503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 3865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Textfield that is shown when editing the profile name. Can be NULL if 387a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // the profile name isn't allowed to be edited (e.g. for guest profiles). 388f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) views::Textfield* profile_name_textfield_; 389f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 390f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(EditableProfileName); 391f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}; 392d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 393effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// A title card with one back button right aligned and one label center aligned. 394effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass TitleCard : public views::View { 395effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public: 3965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TitleCard(const base::string16& message, views::ButtonListener* listener, 3975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::ImageButton** back_button) { 398effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch back_button_ = new views::ImageButton(listener); 399effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch back_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, 400effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::ImageButton::ALIGN_MIDDLE); 401effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 402effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch back_button_->SetImage(views::ImageButton::STATE_NORMAL, 403effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch rb->GetImageSkiaNamed(IDR_BACK)); 404effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch back_button_->SetImage(views::ImageButton::STATE_HOVERED, 405effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch rb->GetImageSkiaNamed(IDR_BACK_H)); 406effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch back_button_->SetImage(views::ImageButton::STATE_PRESSED, 407effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch rb->GetImageSkiaNamed(IDR_BACK_P)); 408effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch back_button_->SetImage(views::ImageButton::STATE_DISABLED, 409effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch rb->GetImageSkiaNamed(IDR_BACK_D)); 41003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) back_button_->SetFocusable(true); 411effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch *back_button = back_button_; 412effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 4135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) title_label_ = new views::Label(message); 414effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 415effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const gfx::FontList& medium_font_list = 416effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch rb->GetFontList(ui::ResourceBundle::MediumFont); 417effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch title_label_->SetFontList(medium_font_list); 418effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 419effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch AddChildView(back_button_); 420effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch AddChildView(title_label_); 421effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 422effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 423010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Creates a new view that has the |title_card| with padding at the top, an 424010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // edge-to-edge separator below, and the specified |view| at the bottom. 425010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) static views::View* AddPaddedTitleCard(views::View* view, 426010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) TitleCard* title_card, 427010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) int width) { 428010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::View* titled_view = new views::View(); 429010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::GridLayout* layout = new views::GridLayout(titled_view); 430010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) titled_view->SetLayoutManager(layout); 431010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 432010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Column set 0 is a single column layout with horizontal padding at left 433010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // and right, and column set 1 is a single column layout with no padding. 434010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::ColumnSet* columns = layout->AddColumnSet(0); 435010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) columns->AddPaddingColumn(1, views::kButtonHEdgeMarginNew); 436010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) int available_width = width - 2 * views::kButtonHEdgeMarginNew; 437010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 438010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::GridLayout::FIXED, available_width, available_width); 439010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) columns->AddPaddingColumn(1, views::kButtonHEdgeMarginNew); 440010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->AddColumnSet(1)->AddColumn(views::GridLayout::FILL, 441010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::GridLayout::FILL, 0,views::GridLayout::FIXED, width, width); 442010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 443010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->StartRowWithPadding(1, 0, 0, views::kButtonVEdgeMarginNew); 444010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->AddView(title_card); 445010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->StartRowWithPadding(1, 1, 0, views::kRelatedControlVerticalSpacing); 446010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 447010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 448010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->StartRow(1, 1); 449010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->AddView(view); 450010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 451010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return titled_view; 452010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 453010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 454effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private: 455effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch virtual void Layout() OVERRIDE{ 45603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int back_button_width = back_button_->GetPreferredSize().width(); 45703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) back_button_->SetBounds(0, 0, back_button_width, height()); 45803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int label_padding = back_button_width + views::kButtonHEdgeMarginNew; 45903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int label_width = width() - 2 * label_padding; 46003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_GT(label_width, 0); 46103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) title_label_->SetBounds(label_padding, 0, label_width, height()); 462effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 463effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 464cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Size GetPreferredSize() const OVERRIDE{ 465010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) int height = std::max(title_label_->GetPreferredSize().height(), 466010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) back_button_->GetPreferredSize().height()); 467effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return gfx::Size(width(), height); 468effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 469effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 470effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::ImageButton* back_button_; 471effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::Label* title_label_; 472effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 473effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DISALLOW_COPY_AND_ASSIGN(TitleCard); 474effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}; 475d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 476d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// ProfileChooserView --------------------------------------------------------- 477d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 4787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static 4797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; 480f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool ProfileChooserView::close_on_deactivate_for_testing_ = true; 4817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static 4837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ProfileChooserView::ShowBubble( 484cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::BubbleViewMode view_mode, 4856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) profiles::TutorialMode tutorial_mode, 4866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) const signin::ManageAccountsParams& manage_accounts_params, 4877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) views::View* anchor_view, 4887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) views::BubbleBorder::Arrow arrow, 4897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) views::BubbleBorder::BubbleAlignment border_alignment, 4907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Browser* browser) { 4916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (IsShowing()) { 4926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { 4936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) profile_bubble_->tutorial_mode_ = tutorial_mode; 4946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) profile_bubble_->ShowView(view_mode, profile_bubble_->avatar_menu_.get()); 4956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 496cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 4976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 498cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 499f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) profile_bubble_ = new ProfileChooserView(anchor_view, arrow, browser, 5006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) view_mode, tutorial_mode, manage_accounts_params.service_type); 5017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) views::BubbleDelegateView::CreateBubble(profile_bubble_); 502f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profile_bubble_->set_close_on_deactivate(close_on_deactivate_for_testing_); 5037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) profile_bubble_->SetAlignment(border_alignment); 5047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) profile_bubble_->GetWidget()->Show(); 5058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 5067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static 5097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool ProfileChooserView::IsShowing() { 5107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return profile_bubble_ != NULL; 5117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static 5147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void ProfileChooserView::Hide() { 5157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (IsShowing()) 5167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) profile_bubble_->GetWidget()->Close(); 5177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 519d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)ProfileChooserView::ProfileChooserView(views::View* anchor_view, 520d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::BubbleBorder::Arrow arrow, 521a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Browser* browser, 522cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::BubbleViewMode view_mode, 5236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) profiles::TutorialMode tutorial_mode, 524cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) signin::GAIAServiceType service_type) 5257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) : BubbleDelegateView(anchor_view, arrow), 526f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) browser_(browser), 527a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch view_mode_(view_mode), 5286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) tutorial_mode_(tutorial_mode), 529cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) gaia_service_type_(service_type) { 530d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Reset the default margins inherited from the BubbleDelegateView. 5316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Add a small bottom inset so that the bubble's rounded corners show up. 5326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) set_margins(gfx::Insets(0, 0, 1, 0)); 533116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch set_background(views::Background::CreateSolidBackground( 534116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch GetNativeTheme()->GetSystemColor( 535116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ui::NativeTheme::kColorId_DialogBackground))); 536f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ResetView(); 53768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 53868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) avatar_menu_.reset(new AvatarMenu( 5397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) &g_browser_process->profile_manager()->GetProfileInfoCache(), 54068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) this, 54168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) browser_)); 54268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) avatar_menu_->RebuildMenu(); 543f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 544f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ProfileOAuth2TokenService* oauth2_token_service = 545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); 546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (oauth2_token_service) 547f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) oauth2_token_service->AddObserver(this); 5487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ProfileChooserView::~ProfileChooserView() { 551f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ProfileOAuth2TokenService* oauth2_token_service = 552f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); 553f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (oauth2_token_service) 554f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) oauth2_token_service->RemoveObserver(this); 5557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 557f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ProfileChooserView::ResetView() { 5585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) open_other_profile_indexes_map_.clear(); 5595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) delete_account_button_map_.clear(); 5605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) reauth_account_button_map_.clear(); 561d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) manage_accounts_link_ = NULL; 562d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) signin_current_profile_link_ = NULL; 5635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) auth_error_email_button_ = NULL; 5645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) current_profile_photo_ = NULL; 5655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) current_profile_name_ = NULL; 566d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) users_button_ = NULL; 5675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) go_incognito_button_ = NULL; 568effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch lock_button_ = NULL; 5695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu add_account_link_ = NULL; 5705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gaia_signin_cancel_button_ = NULL; 571010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) remove_account_button_ = NULL; 572effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch account_removal_cancel_button_ = NULL; 5735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) add_person_button_ = NULL; 5745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) disconnect_button_ = NULL; 5755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switch_user_cancel_button_ = NULL; 5765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) tutorial_sync_settings_ok_button_ = NULL; 57703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) tutorial_close_button_ = NULL; 5785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) tutorial_sync_settings_link_ = NULL; 5795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) tutorial_see_whats_new_button_ = NULL; 5805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) tutorial_not_you_link_ = NULL; 58103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) tutorial_learn_more_link_ = NULL; 5827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 584d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::Init() { 585cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // If view mode is PROFILE_CHOOSER but there is an auth error, force 586cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // ACCOUNT_MANAGEMENT mode. 587cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && 5885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) HasAuthError(browser_->profile()) && 5895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switches::IsEnableAccountConsistency() && 5905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()). 5915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) signed_in) { 592cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) view_mode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT; 593cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 594cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 595a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ShowView(view_mode_, avatar_menu_.get()); 5967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 59868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void ProfileChooserView::OnAvatarMenuChanged( 59968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) AvatarMenu* avatar_menu) { 6005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Do not refresh the avatar menu if the user is on a signin related view. 6015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN || 6025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || 6035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { 6045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return; 6055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 6065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 60768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Refresh the view with the new menu. We can't just update the local copy 608d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // as this may have been triggered by a sign out action, in which case 609d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // the view is being destroyed. 610cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu); 6117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 613f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ProfileChooserView::OnRefreshTokenAvailable( 614f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::string& account_id) { 615cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT || 616cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || 617cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { 6185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // The account management UI is only available through the 6195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // --enable-account-consistency flag. 6205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ShowView(switches::IsEnableAccountConsistency() ? 6215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : 6225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); 623f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 624f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 625f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 626f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void ProfileChooserView::OnRefreshTokenRevoked(const std::string& account_id) { 627f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Refresh the account management view when an account is removed from the 628f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // profile. 629cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) 630cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); 631f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 632f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 633cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void ProfileChooserView::ShowView(profiles::BubbleViewMode view_to_display, 63468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) AvatarMenu* avatar_menu) { 635d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // The account management view should only be displayed if the active profile 636d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // is signed in. 637cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (view_to_display == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { 6385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DCHECK(switches::IsEnableAccountConsistency()); 6396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const AvatarMenu::Item& active_item = avatar_menu->GetItemAt( 6406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) avatar_menu->GetActiveProfileIndex()); 641d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DCHECK(active_item.signed_in); 6427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 6437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 644116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (browser_->profile()->IsSupervised() && 645116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch (view_to_display == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || 646116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch view_to_display == profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL)) { 647116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch LOG(WARNING) << "Supervised user attempted to add/remove account"; 648116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return; 649116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 650116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 651f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ResetView(); 6527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) RemoveAllChildViews(true); 653f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) view_mode_ = view_to_display; 6547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 655a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::GridLayout* layout; 656a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* sub_view; 657a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch switch (view_mode_) { 658cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: 659cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: 660cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: 661a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout = CreateSingleColumnLayout(this, kFixedGaiaViewWidth); 662cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) sub_view = CreateGaiaSigninView(); 663a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch break; 664cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL: 665a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth); 666a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sub_view = CreateAccountRemovalView(); 667a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch break; 6685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: 6695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); 6706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) sub_view = CreateSwitchUserView(); 6716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuNotYou( 6726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); 6735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu break; 674a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch default: 675a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout = CreateSingleColumnLayout(this, kFixedMenuWidth); 6766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) sub_view = CreateProfileChooserView(avatar_menu); 677effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 67803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Clears tutorial mode for all non-profile-chooser views. 67903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) 68003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 68103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 6827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) layout->StartRow(1, 0); 683a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->AddView(sub_view); 6847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Layout(); 6858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (GetBubbleFrameView()) 6868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SizeToContents(); 6877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 689d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::WindowClosing() { 690d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DCHECK_EQ(profile_bubble_, this); 691d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) profile_bubble_ = NULL; 6925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 6935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (tutorial_mode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { 6945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) LoginUIServiceFactory::GetForProfile(browser_->profile())-> 6955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SyncConfirmationUIClosed(false /* configure_sync_first */); 6965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 697d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 6987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 699d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::ButtonPressed(views::Button* sender, 700d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const ui::Event& event) { 701d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Disable button after clicking so that it doesn't get clicked twice and 702d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // start a second action... which can crash Chrome. But don't disable if it 703d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // has no parent (like in tests) because that will also crash. 704d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (sender->parent()) 705d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) sender->SetEnabled(false); 7067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 707effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (sender == users_button_) { 7085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // If this is a guest session, also close all the guest browser windows. 7096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (browser_->profile()->IsGuestSession()) { 7106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) chrome::ShowUserManager(base::FilePath()); 7115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu profiles::CloseGuestProfileWindows(); 7126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } else { 7136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) chrome::ShowUserManager(browser_->profile()->GetPath()); 7146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 7156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER); 7165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == go_incognito_button_) { 7175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DCHECK(ShouldShowGoIncognito()); 7185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) chrome::NewIncognitoWindow(browser_); 719effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } else if (sender == lock_button_) { 720effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch profiles::LockProfile(browser_->profile()); 721cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK); 7225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == auth_error_email_button_) { 7235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get()); 7245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == tutorial_sync_settings_ok_button_) { 7255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) LoginUIServiceFactory::GetForProfile(browser_->profile())-> 7265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SyncConfirmationUIClosed(false /* configure_sync_first */); 72703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DismissTutorial(); 7286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuSignin( 7296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_OK); 73003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } else if (sender == tutorial_close_button_) { 73103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(tutorial_mode_ != profiles::TUTORIAL_MODE_NONE && 73203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) tutorial_mode_ != profiles::TUTORIAL_MODE_CONFIRM_SIGNIN); 73303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DismissTutorial(); 7345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == tutorial_see_whats_new_button_) { 7356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 7366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_WHATS_NEW); 7375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) chrome::ShowUserManagerWithTutorial( 7385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profiles::USER_MANAGER_TUTORIAL_OVERVIEW); 739010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } else if (sender == remove_account_button_) { 740effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch RemoveAccount(); 741effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } else if (sender == account_removal_cancel_button_) { 742effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch account_id_to_remove_.clear(); 743cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); 744effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } else if (sender == gaia_signin_cancel_button_) { 745effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch std::string primary_account = 746effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SigninManagerFactory::GetForProfile(browser_->profile())-> 747effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch GetAuthenticatedUsername(); 7485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // The account management view is only available with the 7495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // --enable-account-consistency flag. 7505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool account_management_available = !primary_account.empty() && 7515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switches::IsEnableAccountConsistency(); 7525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ShowView(account_management_available ? 7535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : 7545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); 75503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } else if (sender == current_profile_photo_) { 756effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); 757cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); 7585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } else if (sender == signin_current_profile_link_) { 7595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); 7605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == add_person_button_) { 7616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuNotYou( 7626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); 7636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) chrome::ShowUserManager(browser_->profile()->GetPath()); 7645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == disconnect_button_) { 7656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuNotYou( 7666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT); 7675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) chrome::ShowSettings(browser_); 7685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == switch_user_cancel_button_) { 7695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); 7706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuNotYou( 7716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK); 772d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } else { 7735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Either one of the "other profiles", or one of the profile accounts 7745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // buttons was pressed. 7755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ButtonIndexes::const_iterator profile_match = 776d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) open_other_profile_indexes_map_.find(sender); 7775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (profile_match != open_other_profile_indexes_map_.end()) { 7785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu avatar_menu_->SwitchToProfile( 7795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu profile_match->second, 7805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW, 7815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ProfileMetrics::SWITCH_PROFILE_ICON); 7825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } else { 7835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // This was a profile accounts button. 7845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu AccountButtonIndexes::const_iterator account_match = 785cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) delete_account_button_map_.find(sender); 786cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (account_match != delete_account_button_map_.end()) { 787cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) account_id_to_remove_ = account_match->second; 788cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, 789cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) avatar_menu_.get()); 790cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } else { 791cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) account_match = reauth_account_button_map_.find(sender); 792cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DCHECK(account_match != reauth_account_button_map_.end()); 793cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get()); 794cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 7955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 796d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 7977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 7987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 799effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid ProfileChooserView::RemoveAccount() { 800effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DCHECK(!account_id_to_remove_.empty()); 8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MutableProfileOAuth2TokenService* oauth2_token_service = 8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( 803effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch browser_->profile()); 804cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (oauth2_token_service) { 805effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch oauth2_token_service->RevokeCredentials(account_id_to_remove_); 806cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT); 807cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 808effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch account_id_to_remove_.clear(); 809effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 810cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); 811f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 812f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 813d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { 814d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (sender == manage_accounts_link_) { 8155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // This link can either mean show/hide the account management view, 8165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // depending on which view it is displayed. ShowView() will DCHECK if 8175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // the account management view is displayed for non signed-in users. 8185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ShowView( 819cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? 820cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER : 821cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, 8225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu avatar_menu_.get()); 8235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } else if (sender == add_account_link_) { 824cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); 825cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT); 8265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (sender == tutorial_sync_settings_link_) { 8275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) LoginUIServiceFactory::GetForProfile(browser_->profile())-> 8285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SyncConfirmationUIClosed(true /* configure_sync_first */); 8295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 8306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuSignin( 8316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS); 83203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } else if (sender == tutorial_not_you_link_){ 8336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 8346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU); 8355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_SWITCH_USER, avatar_menu_.get()); 83603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } else { 83703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(sender == tutorial_learn_more_link_); 83803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile()); 839f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 840f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 841f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 842c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid ProfileChooserView::StyledLabelLinkClicked( 843c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const gfx::Range& range, int event_flags) { 844c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch chrome::ShowSettings(browser_); 845c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch} 846c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 847f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, 848f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ui::KeyEvent& key_event) { 849f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) views::Textfield* name_textfield = 850f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) current_profile_name_->profile_name_textfield(); 851f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DCHECK(sender == name_textfield); 852f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 853f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (key_event.key_code() == ui::VKEY_RETURN || 854f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) key_event.key_code() == ui::VKEY_TAB) { 855f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Pressing Tab/Enter commits the new profile name, unless it's empty. 856f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::string16 new_profile_name = name_textfield->text(); 85703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); 858f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (new_profile_name.empty()) 859f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return true; 860f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 861f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const AvatarMenu::Item& active_item = avatar_menu_->GetItemAt( 86268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) avatar_menu_->GetActiveProfileIndex()); 863f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Profile* profile = g_browser_process->profile_manager()->GetProfile( 864f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) active_item.profile_path); 865f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DCHECK(profile); 866f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 867f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (profile->IsSupervised()) 868f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return true; 869f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 870f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) profiles::UpdateProfileName(profile, new_profile_name); 871cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); 872f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) current_profile_name_->ShowReadOnlyView(); 873f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return true; 874d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 875f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return false; 876d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 8777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 878a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochviews::View* ProfileChooserView::CreateProfileChooserView( 8796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) AvatarMenu* avatar_menu) { 880a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* view = new views::View(); 881a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 882a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Separate items into active and alternatives. 883a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Indexes other_profiles; 884a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* tutorial_view = NULL; 885a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* current_profile_view = NULL; 886a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* current_profile_accounts = NULL; 887a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* option_buttons_view = NULL; 888a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 889a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 890a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (item.active) { 8915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) option_buttons_view = CreateOptionsView( 8925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) switches::IsNewProfileManagement() && item.signed_in); 8935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu current_profile_view = CreateCurrentProfileView(item, false); 894cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 8956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) switch (tutorial_mode_) { 8965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case profiles::TUTORIAL_MODE_NONE: 8975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: 8985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( 8996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, 9005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) item); 9015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) break; 9025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: 9035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) tutorial_view = CreateSigninConfirmationView(); 9045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) break; 9055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) case profiles::TUTORIAL_MODE_SHOW_ERROR: 90603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) tutorial_view = CreateSigninErrorView(); 90703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) break; 9085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 909a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } else { 910a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch current_profile_accounts = CreateCurrentProfileAccountsView(item); 911a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 912a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } else { 913a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch other_profiles.push_back(i); 914a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 915a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 916a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 917a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (tutorial_view) { 9185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // TODO(mlerman): update UMA stats for the new tutorial. 919a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->StartRow(1, 0); 920a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->AddView(tutorial_view); 9216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } else { 9226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 923a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 924a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 925a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (!current_profile_view) { 926a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Guest windows don't have an active profile. 927a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch current_profile_view = CreateGuestProfileView(); 928a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch option_buttons_view = CreateOptionsView(false); 929a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 930a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 931a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->StartRow(1, 0); 932a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->AddView(current_profile_view); 933a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 934f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 935f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) DCHECK(current_profile_accounts); 936f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) layout->StartRow(0, 0); 937f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 938f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) layout->StartRow(1, 0); 939f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) layout->AddView(current_profile_accounts); 940f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 941f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 942f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (browser_->profile()->IsSupervised()) { 943cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->StartRow(0, 0); 944cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 945cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->StartRow(1, 0); 946cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->AddView(CreateSupervisedUserDisclaimerView()); 947cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 948cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 949cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 950a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->StartRow(1, 0); 951a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (switches::IsFastUserSwitching()) 952a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->AddView(CreateOtherProfilesView(other_profiles)); 953a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 954a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 955a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->StartRow(0, 0); 956a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 957a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 958010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (option_buttons_view) { 9595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu layout->StartRow(0, 0); 9605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu layout->AddView(option_buttons_view); 9615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 962a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 963a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return view; 964a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 965a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 96603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)void ProfileChooserView::DismissTutorial() { 96703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Never shows the upgrade tutorial again if manually closed. 96803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { 96903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) browser_->profile()->GetPrefs()->SetInteger( 97003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) prefs::kProfileAvatarTutorialShown, 97103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); 97203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 97303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 97403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 97503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); 97603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 97703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 978a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochviews::View* ProfileChooserView::CreateTutorialView( 979cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profiles::TutorialMode tutorial_mode, 980a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const base::string16& title_text, 981a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const base::string16& content_text, 982a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const base::string16& link_text, 983a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const base::string16& button_text, 98403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) bool stack_button, 985a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::Link** link, 98603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::LabelButton** button, 98703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::ImageButton** close_button) { 9885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu tutorial_mode_ = tutorial_mode; 9895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 990a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) views::View* view = new views::View(); 991c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch view->set_background(views::Background::CreateSolidBackground( 992c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch profiles::kAvatarTutorialBackgroundColor)); 993a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) views::GridLayout* layout = CreateSingleColumnLayout(view, 994a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); 99503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Creates a second column set for buttons and links. 99603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::ColumnSet* button_columns = layout->AddColumnSet(1); 99703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) button_columns->AddColumn(views::GridLayout::LEADING, 99803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); 99903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) button_columns->AddPaddingColumn( 100003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1, views::kUnrelatedControlHorizontalSpacing); 100103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) button_columns->AddColumn(views::GridLayout::TRAILING, 100203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); 1003a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) layout->SetInsets(views::kButtonVEdgeMarginNew, 1004a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) views::kButtonHEdgeMarginNew, 1005a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) views::kButtonVEdgeMarginNew, 1006a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) views::kButtonHEdgeMarginNew); 1007a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 100803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Adds title and close button if needed. 1009a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::Label* title_label = new views::Label(title_text); 10106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) title_label->SetMultiLine(true); 1011a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1012c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch title_label->SetAutoColorReadabilityEnabled(false); 1013c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch title_label->SetEnabledColor(SK_ColorWHITE); 1014010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 1015c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch ui::ResourceBundle::MediumFont)); 101603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 101703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (close_button) { 101803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->StartRow(1, 1); 101903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->AddView(title_label); 102003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *close_button = new views::ImageButton(this); 102103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*close_button)->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, 102203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) views::ImageButton::ALIGN_MIDDLE); 102303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 102403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*close_button)->SetImage(views::ImageButton::STATE_NORMAL, 102503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) rb->GetImageSkiaNamed(IDR_CLOSE_1)); 102603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*close_button)->SetImage(views::ImageButton::STATE_HOVERED, 102703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) rb->GetImageSkiaNamed(IDR_CLOSE_1_H)); 102803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*close_button)->SetImage(views::ImageButton::STATE_PRESSED, 102903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) rb->GetImageSkiaNamed(IDR_CLOSE_1_P)); 103003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->AddView(*close_button); 103103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } else { 103203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->StartRow(1, 0); 103303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->AddView(title_label); 103403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 1035a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1036c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Adds body content. 1037a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::Label* content_label = new views::Label(content_text); 1038c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content_label->SetMultiLine(true); 1039c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1040c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content_label->SetAutoColorReadabilityEnabled(false); 1041c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content_label->SetEnabledColor(profiles::kAvatarTutorialContentTextColor); 1042a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); 1043c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch layout->AddView(content_label); 1044a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1045c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Adds links and buttons. 104603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) bool has_button = !button_text.empty(); 104703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (has_button) { 104803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *button = new views::LabelButton(this, button_text); 104903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*button)->SetHorizontalAlignment(gfx::ALIGN_CENTER); 105003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*button)->SetStyle(views::Button::STYLE_BUTTON); 105103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 1052a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 105303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) bool has_link = !link_text.empty(); 105403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (has_link) { 10556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) *link = CreateLink(link_text, this); 10566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) (*link)->SetHorizontalAlignment(gfx::ALIGN_LEFT); 10576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) (*link)->SetAutoColorReadabilityEnabled(false); 10586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) (*link)->SetEnabledColor(SK_ColorWHITE); 10596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 1060a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 106103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (stack_button) { 106203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(has_button); 106303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->StartRowWithPadding( 106403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1, 0, 0, views::kUnrelatedControlVerticalSpacing); 106503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->AddView(*button); 106603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (has_link) { 106703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->StartRowWithPadding( 106803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1, 0, 0, views::kRelatedControlVerticalSpacing); 106903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) (*link)->SetHorizontalAlignment(gfx::ALIGN_CENTER); 107003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->AddView(*link); 107103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 107203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } else { 107303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK(has_link || has_button); 107403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->StartRowWithPadding( 107503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1, 1, 0, views::kUnrelatedControlVerticalSpacing); 107603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (has_link) 107703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->AddView(*link); 107803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) else 107903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->SkipColumns(1); 108003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (has_button) 108103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->AddView(*button); 108203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) else 108303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) layout->SkipColumns(1); 108403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) } 1085c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 10865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return view; 1087a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 1088a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1089d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)views::View* ProfileChooserView::CreateCurrentProfileView( 109068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const AvatarMenu::Item& avatar_item, 1091d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool is_guest) { 1092d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::View* view = new views::View(); 10935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; 10945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); 109568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) layout->SetInsets(views::kButtonVEdgeMarginNew, 1096d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::kButtonHEdgeMarginNew, 1097010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::kUnrelatedControlVerticalSpacing, 109868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) views::kButtonHEdgeMarginNew); 10997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Profile icon, centered. 1101f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) int x_offset = (column_width - kLargeImageSide) / 2; 11025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu current_profile_photo_ = new EditableProfilePhoto( 11035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu this, avatar_item.icon, !is_guest, 11045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu gfx::Rect(x_offset, 0, kLargeImageSide, kLargeImageSide)); 1105f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) SizedContainer* profile_icon_container = 1106f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) new SizedContainer(gfx::Size(column_width, kLargeImageSide)); 1107f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) profile_icon_container->AddChildView(current_profile_photo_); 1108d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 11095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (browser_->profile()->IsSupervised()) { 111146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) views::ImageView* supervised_icon = new views::ImageView(); 111246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) supervised_icon->SetImage( 111346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_SUPERVISED)); 111446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) gfx::Size preferred_size = supervised_icon->GetPreferredSize(); 111546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) gfx::Rect parent_bounds = current_profile_photo_->bounds(); 111646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) supervised_icon->SetBounds( 111746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) parent_bounds.right() - preferred_size.width(), 111846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) parent_bounds.bottom() - preferred_size.height(), 111946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) preferred_size.width(), 112046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) preferred_size.height()); 1121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) profile_icon_container->AddChildView(supervised_icon); 112246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) } 112346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 11245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu layout->StartRow(1, 0); 1125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) layout->AddView(profile_icon_container); 11267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Profile name, centered. 1128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) bool editing_allowed = !is_guest && !browser_->profile()->IsSupervised(); 1129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) current_profile_name_ = new EditableProfileName( 1130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch this, 1131116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()), 1132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch editing_allowed); 11335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRowWithPadding(1, 0, 0, 11345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::kRelatedControlSmallVerticalSpacing); 1135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) layout->StartRow(1, 0); 1136f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) layout->AddView(current_profile_name_); 11373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 11385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (is_guest) 11395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu return view; 11403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 11415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // The available links depend on the type of profile that is active. 11425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (avatar_item.signed_in) { 1143cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->StartRow(1, 0); 11445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (switches::IsEnableAccountConsistency()) { 11455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::string16 link_title = l10n_util::GetStringUTF16( 1146cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? 11475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : 11485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 11495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu manage_accounts_link_ = CreateLink(link_title, this); 11505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 11515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu layout->AddView(manage_accounts_link_); 11525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } else { 11536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Add a small padding between the email button and the profile name. 11546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) layout->StartRowWithPadding(1, 0, 0, 2); 11555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Badge the email address if there's an authentication error. 11565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (HasAuthError(browser_->profile())) { 11575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const gfx::ImageSkia warning_image = *rb->GetImageNamed( 11585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia(); 11595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) auth_error_email_button_ = 11605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) new RightAlignedIconLabelButton(this, avatar_item.sync_state); 11615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) auth_error_email_button_->SetElideBehavior(gfx::ELIDE_EMAIL); 11625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) auth_error_email_button_->SetBorder(views::Border::NullBorder()); 11635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) auth_error_email_button_->SetImage( 11645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::LabelButton::STATE_NORMAL, warning_image); 11655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) auth_error_email_button_->SetTextColor( 11665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::LabelButton::STATE_NORMAL, 11675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::Link::GetDefaultEnabledColor()); 116803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) auth_error_email_button_->SetFocusable(true); 11695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(auth_error_email_button_); 11705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else { 11715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::Label* email_label = new views::Label(avatar_item.sync_state); 11725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) email_label->SetElideBehavior(gfx::ELIDE_EMAIL); 11736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) email_label->SetEnabled(false); 11745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(email_label); 11755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 11765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 11775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } else { 11785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( 11795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) browser_->profile()->GetOriginalProfile()); 1180cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (signin_manager->IsSigninAllowed()) { 11815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::Label* promo = new views::Label( 11825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); 11835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) promo->SetMultiLine(true); 11845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); 11855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRowWithPadding(1, 0, 0, 11865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::kRelatedControlSmallVerticalSpacing); 11875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 11885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(promo); 11895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1190cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) signin_current_profile_link_ = new views::BlueButton( 1191cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, 1192cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); 11935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRowWithPadding(1, 0, 0, 11945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::kRelatedControlVerticalSpacing); 1195cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->StartRow(1, 0); 1196cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->AddView(signin_current_profile_link_); 1197cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 11985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu } 11995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 12003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return view; 12013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 12023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 12033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)views::View* ProfileChooserView::CreateGuestProfileView() { 1204d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::Image guest_icon = 12050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ui::ResourceBundle::GetSharedInstance().GetImageNamed( 12060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch profiles::GetPlaceholderAvatarIconResourceID()); 120768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) AvatarMenu::Item guest_avatar_item(0, 0, guest_icon); 12083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) guest_avatar_item.active = true; 12093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) guest_avatar_item.name = l10n_util::GetStringUTF16( 1210d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) IDS_PROFILES_GUEST_PROFILE_NAME); 12113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) guest_avatar_item.signed_in = false; 12123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1213d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return CreateCurrentProfileView(guest_avatar_item, true); 12147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 12157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 12167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)views::View* ProfileChooserView::CreateOtherProfilesView( 12177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const Indexes& avatars_to_show) { 12187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) views::View* view = new views::View(); 12195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 12205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 122168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) int num_avatars_to_show = avatars_to_show.size(); 122268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) for (int i = 0; i < num_avatars_to_show; ++i) { 122368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const size_t index = avatars_to_show[i]; 122468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); 1225f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const int kSmallImageSide = 32; 1226d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 12270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch gfx::Image image = profiles::GetSizedAvatarIcon( 1228010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) item.icon, true, kSmallImageSide, kSmallImageSide); 1229d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 12305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu views::LabelButton* button = new BackgroundColorHoverButton( 12315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu this, 12325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu item.name, 12335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *image.ToImageSkia()); 1234d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) open_other_profile_indexes_map_[button] = index; 1235d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1236d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) layout->StartRow(1, 0); 12375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 12385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu layout->StartRow(1, 0); 1239d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) layout->AddView(button); 12407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 12417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 12427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return view; 12437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 12447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1245effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochviews::View* ProfileChooserView::CreateOptionsView(bool enable_lock) { 1246d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) views::View* view = new views::View(); 12475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1248effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 12495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu base::string16 text = browser_->profile()->IsGuestSession() ? 12505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : 12515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); 1252d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 125368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) users_button_ = new BackgroundColorHoverButton( 125468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) this, 12555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu text, 1256effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); 1257d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) layout->StartRow(1, 0); 1258d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) layout->AddView(users_button_); 1259a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 12605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (ShouldShowGoIncognito()) { 12615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 12625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 12635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 12645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) go_incognito_button_ = new BackgroundColorHoverButton( 12655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) this, 12665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON), 12676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_INCOGNITO)); 12685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 12695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(go_incognito_button_); 12705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 12715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1272effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (enable_lock) { 12735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 12745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 12755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1276effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch lock_button_ = new BackgroundColorHoverButton( 1277effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch this, 12785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), 1279effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK)); 12805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 1281effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch layout->AddView(lock_button_); 1282effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 1283d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return view; 1284d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 12857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1286cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { 1287cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::View* view = new views::View(); 1288cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::GridLayout* layout = CreateSingleColumnLayout( 1289cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); 1290cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->SetInsets(views::kRelatedControlVerticalSpacing, 1291cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::kButtonHEdgeMarginNew, 1292cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::kRelatedControlVerticalSpacing, 1293cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::kButtonHEdgeMarginNew); 1294cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::Label* disclaimer = new views::Label( 1295f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) avatar_menu_->GetSupervisedUserInformation()); 1296cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) disclaimer->SetMultiLine(true); 1297cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) disclaimer->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1298cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1299cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) disclaimer->SetFontList(rb->GetFontList(ui::ResourceBundle::SmallFont)); 1300cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->StartRow(1, 0); 1301cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) layout->AddView(disclaimer); 1302cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1303cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return view; 1304cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 1305cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1306d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)views::View* ProfileChooserView::CreateCurrentProfileAccountsView( 130768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const AvatarMenu::Item& avatar_item) { 1308d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DCHECK(avatar_item.signed_in); 1309a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch views::View* view = new views::View(); 13105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu view->set_background(views::Background::CreateSolidBackground( 13115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu profiles::kAvatarBubbleAccountsBackgroundColor)); 13125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 13137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 13141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Profile* profile = browser_->profile(); 1315a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string primary_account = 1316a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); 1317a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DCHECK(!primary_account.empty()); 13185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<std::string>accounts = 13195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles::GetSecondaryAccountsForProfile(profile, primary_account); 13207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1321cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Get state of authentication error, if any. 1322cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) std::string error_account_id = GetAuthErrorAccountId(profile); 1323cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 13245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The primary account should always be listed first. 13255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(rogerta): we still need to further differentiate the primary account 13265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // from the others in the UI, so more work is likely required here: 13275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // crbug.com/311124. 1328cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CreateAccountButton(layout, primary_account, true, 1329cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) error_account_id == primary_account, kFixedMenuWidth); 13305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < accounts.size(); ++i) 1331cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) CreateAccountButton(layout, accounts[i], false, 1332cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) error_account_id == accounts[i], kFixedMenuWidth); 13337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1334116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!profile->IsSupervised()) { 1335116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1336116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1337116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( 1338116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); 1339116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch add_account_link_->SetBorder(views::Border::CreateEmptyBorder( 1340116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 0, views::kButtonVEdgeMarginNew, 1341116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch views::kRelatedControlVerticalSpacing, 0)); 1342116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch layout->StartRow(1, 0); 1343116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch layout->AddView(add_account_link_); 1344116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 1345116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 13467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return view; 13477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 1348a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, 1350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const std::string& account, 13515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_primary_account, 1352cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool reauth_required, 13535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int width) { 1354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1355cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const gfx::ImageSkia* delete_default_image = 13565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia(); 1357cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const int kDeleteButtonWidth = delete_default_image->width(); 13586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) const gfx::ImageSkia warning_default_image = reauth_required ? 13596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) *rb->GetImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia() : 13606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) gfx::ImageSkia(); 1361cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const int kWarningButtonWidth = reauth_required ? 13626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) warning_default_image.width() + views::kRelatedButtonHSpacing : 0; 13636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) int available_width = width - 2 * views::kButtonHEdgeMarginNew 13646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) - kDeleteButtonWidth - kWarningButtonWidth; 13655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu views::LabelButton* email_button = new BackgroundColorHoverButton( 13666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) reauth_required ? this : NULL, 13675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::UTF8ToUTF16(account), 13686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) warning_default_image); 13695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) email_button->SetElideBehavior(gfx::ELIDE_EMAIL); 13705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) email_button->SetMinSize(gfx::Size(0, kButtonHeight)); 13715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) email_button->SetMaxSize(gfx::Size(available_width, kButtonHeight)); 1372a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) layout->StartRow(1, 0); 1373a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) layout->AddView(email_button); 1374a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 13756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) if (reauth_required) 13766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) reauth_account_button_map_[email_button] = account; 1377116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1378116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Delete button. 1379116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!browser_->profile()->IsSupervised()) { 1380116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch views::ImageButton* delete_button = new views::ImageButton(this); 1381116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch delete_button->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, 1382116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch views::ImageButton::ALIGN_MIDDLE); 1383116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch delete_button->SetImage(views::ImageButton::STATE_NORMAL, 1384116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch delete_default_image); 1385116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch delete_button->SetImage(views::ImageButton::STATE_HOVERED, 1386116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch rb->GetImageSkiaNamed(IDR_CLOSE_1_H)); 1387116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch delete_button->SetImage(views::ImageButton::STATE_PRESSED, 1388116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch rb->GetImageSkiaNamed(IDR_CLOSE_1_P)); 1389116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch delete_button->SetBounds( 1390116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch width - views::kButtonHEdgeMarginNew - kDeleteButtonWidth, 1391116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 0, kDeleteButtonWidth, kButtonHeight); 1392116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1393116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch email_button->set_notify_enter_exit_on_child(true); 1394116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch email_button->AddChildView(delete_button); 1395116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1396116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Save the original email address, as the button text could be elided. 1397116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch delete_account_button_map_[delete_button] = account; 1398116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 1399a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 1400effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 1401cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)views::View* ProfileChooserView::CreateGaiaSigninView() { 1402cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) GURL url; 1403cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) int message_id; 1404cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1405cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) switch (view_mode_) { 1406cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: 1407cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) url = signin::GetPromoURL(signin::SOURCE_AVATAR_BUBBLE_SIGN_IN, 1408cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) false /* auto_close */, 1409cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) true /* is_constrained */); 1410cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) message_id = IDS_PROFILES_GAIA_SIGNIN_TITLE; 1411cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) break; 1412cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: 1413cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) url = signin::GetPromoURL(signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT, 1414cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) false /* auto_close */, 1415cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) true /* is_constrained */); 1416cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) message_id = IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE; 1417cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) break; 1418cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: { 1419cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DCHECK(HasAuthError(browser_->profile())); 1420cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) url = signin::GetReauthURL(browser_->profile(), 1421cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) GetAuthErrorUsername(browser_->profile())); 1422cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) message_id = IDS_PROFILES_GAIA_REAUTH_TITLE; 1423cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) break; 1424cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 1425cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) default: 1426cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) NOTREACHED() << "Called with invalid mode=" << view_mode_; 1427cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return NULL; 1428cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 1429cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1430effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Adds Gaia signin webview 1431effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Profile* profile = browser_->profile(); 1432effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::WebView* web_view = new views::WebView(profile); 1433effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch web_view->LoadInitialURL(url); 1434effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch web_view->SetPreferredSize( 1435effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight)); 1436effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 14375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TitleCard* title_card = new TitleCard(l10n_util::GetStringUTF16(message_id), 14385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) this, 1439cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) &gaia_signin_cancel_button_); 1440010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return TitleCard::AddPaddedTitleCard( 1441010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) web_view, title_card, kFixedGaiaViewWidth); 1442effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 1443effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 1444effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochviews::View* ProfileChooserView::CreateAccountRemovalView() { 1445effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::View* view = new views::View(); 1446effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::GridLayout* layout = CreateSingleColumnLayout( 1447effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch view, kFixedAccountRemovalViewWidth - 2 * views::kButtonHEdgeMarginNew); 1448010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->SetInsets(0, 1449effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::kButtonHEdgeMarginNew, 1450effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::kButtonVEdgeMarginNew, 1451effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::kButtonHEdgeMarginNew); 1452effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 1453effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const std::string& primary_account = SigninManagerFactory::GetForProfile( 1454effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch browser_->profile())->GetAuthenticatedUsername(); 1455effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch bool is_primary_account = primary_account == account_id_to_remove_; 1456effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 1457effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Adds main text. 1458c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch layout->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing); 1459effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1460effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const gfx::FontList& small_font_list = 1461effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch rb->GetFontList(ui::ResourceBundle::SmallFont); 1462c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1463c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (is_primary_account) { 1464c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch std::vector<size_t> offsets; 1465c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const base::string16 settings_text = 1466c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch l10n_util::GetStringUTF16(IDS_PROFILES_SETTINGS_LINK); 14670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const base::string16 primary_account_removal_text = 1468c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch l10n_util::GetStringFUTF16(IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, 1469c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch base::UTF8ToUTF16(account_id_to_remove_), settings_text, &offsets); 1470c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch views::StyledLabel* primary_account_removal_label = 14710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch new views::StyledLabel(primary_account_removal_text, this); 1472c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch primary_account_removal_label->AddStyleRange( 1473c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch gfx::Range(offsets[1], offsets[1] + settings_text.size()), 1474c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch views::StyledLabel::RangeStyleInfo::CreateForLink()); 1475c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch primary_account_removal_label->SetBaseFontList(small_font_list); 1476c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch layout->AddView(primary_account_removal_label); 1477c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } else { 1478c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch views::Label* content_label = new views::Label( 1479c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT)); 1480c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content_label->SetMultiLine(true); 1481c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 1482c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content_label->SetFontList(small_font_list); 1483c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch layout->AddView(content_label); 1484c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 1485effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 1486effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Adds button. 1487effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!is_primary_account) { 1488010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) remove_account_button_ = new views::BlueButton( 1489effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch this, l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON)); 1490010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) remove_account_button_->SetHorizontalAlignment( 1491effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch gfx::ALIGN_CENTER); 1492effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch layout->StartRowWithPadding( 1493effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 1, 0, 0, views::kUnrelatedControlVerticalSpacing); 1494010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) layout->AddView(remove_account_button_); 1495effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } else { 1496effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 1497effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 1498effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 14995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TitleCard* title_card = new TitleCard( 15005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE), 1501010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) this, &account_removal_cancel_button_); 1502010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return TitleCard::AddPaddedTitleCard(view, title_card, 1503010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) kFixedAccountRemovalViewWidth); 1504effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 1505a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 15065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)views::View* ProfileChooserView::CreateWelcomeUpgradeTutorialViewIfNeeded( 15075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool tutorial_shown, const AvatarMenu::Item& avatar_item){ 15085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) Profile* profile = browser_->profile(); 15095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 15105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const int show_count = profile->GetPrefs()->GetInteger( 15115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) prefs::kProfileAvatarTutorialShown); 15125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Do not show the tutorial if user has dismissed it. 15136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (show_count > signin_ui_util::kUpgradeWelcomeTutorialShowMax) 15145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return NULL; 15155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 15165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!tutorial_shown) { 15176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) if (show_count == signin_ui_util::kUpgradeWelcomeTutorialShowMax) 15185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return NULL; 15195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profile->GetPrefs()->SetInteger( 15205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) prefs::kProfileAvatarTutorialShown, show_count + 1); 15215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 15226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 15236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); 15246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 15256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // For local profiles, the "Not you" link doesn't make sense. 15266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) base::string16 link_message = avatar_item.signed_in ? 15276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatar_item.name) : 15286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) base::string16(); 15295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 15305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return CreateTutorialView( 15315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profiles::TUTORIAL_MODE_WELCOME_UPGRADE, 15326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) l10n_util::GetStringUTF16( 15336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE), 15345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16( 15355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT), 15366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) link_message, 15375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON), 153803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) true /* stack_button */, 15395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) &tutorial_not_you_link_, 154003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) &tutorial_see_whats_new_button_, 154103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) &tutorial_close_button_); 15425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 15435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 154403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)views::View* ProfileChooserView::CreateSigninConfirmationView() { 15456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::LogProfileNewAvatarMenuSignin( 15466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); 15476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1548a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return CreateTutorialView( 15495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) profiles::TUTORIAL_MODE_CONFIRM_SIGNIN, 15505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE), 15515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16( 15525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_CONTENT_TEXT), 15535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_SYNC_SETTINGS_LINK), 15545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_OK_BUTTON), 155503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) false /* stack_button */, 15565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) &tutorial_sync_settings_link_, 155703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) &tutorial_sync_settings_ok_button_, 155803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) NULL /* close_button*/); 155903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} 156003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 156103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)views::View* ProfileChooserView::CreateSigninErrorView() { 156203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) LoginUIService* login_ui_service = 156303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) LoginUIServiceFactory::GetForProfile(browser_->profile()); 156403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::string16 last_login_result(login_ui_service->GetLastLoginResult()); 156503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return CreateTutorialView( 156603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) profiles::TUTORIAL_MODE_SHOW_ERROR, 156703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_ERROR_TUTORIAL_TITLE), 156803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) last_login_result, 156903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), 157003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) base::string16(), 157103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) false /* stack_button */, 157203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) &tutorial_learn_more_link_, 157303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) NULL, 157403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) &tutorial_close_button_); 1575a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 15765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 15776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)views::View* ProfileChooserView::CreateSwitchUserView() { 15785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu views::View* view = new views::View(); 15795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu views::GridLayout* layout = CreateSingleColumnLayout( 15805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) view, kFixedSwitchUserViewWidth); 15815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::ColumnSet* columns = layout->AddColumnSet(1); 15825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 15835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int label_width = 15845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) kFixedSwitchUserViewWidth - 2 * views::kButtonHEdgeMarginNew; 15855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 15865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::GridLayout::FIXED, label_width, label_width); 15875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 15885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 15895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Adds main text. 15905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRowWithPadding(1, 1, 0, views::kUnrelatedControlVerticalSpacing); 15915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 15925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const gfx::FontList& small_font_list = 15935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu rb->GetFontList(ui::ResourceBundle::SmallFont); 15946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const AvatarMenu::Item& avatar_item = 15956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()); 15965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) views::Label* content_label = new views::Label( 15975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringFUTF16( 15985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) IDS_PROFILES_NOT_YOU_CONTENT_TEXT, avatar_item.name)); 15995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) content_label->SetMultiLine(true); 16005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 16015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu content_label->SetFontList(small_font_list); 16025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu layout->AddView(content_label); 16035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 16045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Adds "Add person" button. 16055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing); 16065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 16075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 16085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) add_person_button_ = new BackgroundColorHoverButton( 16095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) this, 16105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_ADD_PERSON_BUTTON), 16115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); 16125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 16135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(add_person_button_); 16145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 16155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Adds "Disconnect your Google Account" button. 16165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 16175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 16185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 16195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) disconnect_button_ = new BackgroundColorHoverButton( 16205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) this, 16215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringUTF16(IDS_PROFILES_DISCONNECT_BUTTON), 16226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_DISCONNECT)); 16235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->StartRow(1, 0); 16245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) layout->AddView(disconnect_button_); 16255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 1626010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) TitleCard* title_card = new TitleCard( 16275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatar_item.name), 16285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) this, &switch_user_cancel_button_); 16295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return TitleCard::AddPaddedTitleCard(view, title_card, 16305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) kFixedSwitchUserViewWidth); 16315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 16325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 16335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool ProfileChooserView::ShouldShowGoIncognito() const { 16345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool incognito_available = 16355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 16365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) IncognitoModePrefs::DISABLED; 16375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return incognito_available && !browser_->profile()->IsGuestSession(); 16385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu} 16395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 16405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void ProfileChooserView::PostActionPerformed( 16415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ProfileMetrics::ProfileDesktopMenu action_performed) { 16425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 16435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 16445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 1645