Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 1344443002: Implement new password separated sign in flow for chrome desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "ui/views/controls/button/image_button.h" 61 #include "ui/views/controls/button/image_button.h"
62 #include "ui/views/controls/button/label_button.h" 62 #include "ui/views/controls/button/label_button.h"
63 #include "ui/views/controls/button/label_button_border.h" 63 #include "ui/views/controls/button/label_button_border.h"
64 #include "ui/views/controls/button/menu_button.h" 64 #include "ui/views/controls/button/menu_button.h"
65 #include "ui/views/controls/label.h" 65 #include "ui/views/controls/label.h"
66 #include "ui/views/controls/link.h" 66 #include "ui/views/controls/link.h"
67 #include "ui/views/controls/separator.h" 67 #include "ui/views/controls/separator.h"
68 #include "ui/views/controls/styled_label.h" 68 #include "ui/views/controls/styled_label.h"
69 #include "ui/views/controls/textfield/textfield.h" 69 #include "ui/views/controls/textfield/textfield.h"
70 #include "ui/views/controls/webview/webview.h" 70 #include "ui/views/controls/webview/webview.h"
71 #include "ui/views/layout/fill_layout.h"
71 #include "ui/views/layout/grid_layout.h" 72 #include "ui/views/layout/grid_layout.h"
72 #include "ui/views/layout/layout_constants.h" 73 #include "ui/views/layout/layout_constants.h"
73 #include "ui/views/widget/widget.h" 74 #include "ui/views/widget/widget.h"
74 75
75 namespace { 76 namespace {
76 77
77 // Helpers -------------------------------------------------------------------- 78 // Helpers --------------------------------------------------------------------
78 79
79 const int kFixedMenuWidth = 250; 80 const int kFixedMenuWidth = 250;
80 const int kButtonHeight = 32; 81 const int kButtonHeight = 32;
81 const int kFixedGaiaViewHeight = 440; 82 const int kPasswordCombinedFixedGaiaViewHeight = 440;
82 const int kFixedGaiaViewWidth = 360; 83 const int kPasswordCombinedFixedGaiaViewWidth = 360;
84 const int kFixedGaiaViewHeight = 512;
85 const int kFixedGaiaViewWidth = 448;
83 const int kFixedAccountRemovalViewWidth = 280; 86 const int kFixedAccountRemovalViewWidth = 280;
84 const int kFixedSwitchUserViewWidth = 320; 87 const int kFixedSwitchUserViewWidth = 320;
85 const int kLargeImageSide = 88; 88 const int kLargeImageSide = 88;
86 89
87 const int kVerticalSpacing = 16; 90 const int kVerticalSpacing = 16;
88 91
92 const int kTitleViewNativeWidgetOffset = 8;
93
89 bool IsProfileChooser(profiles::BubbleViewMode mode) { 94 bool IsProfileChooser(profiles::BubbleViewMode mode) {
90 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || 95 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
91 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 96 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
92 } 97 }
93 98
94 // Creates a GridLayout with a single column. This ensures that all the child 99 // Creates a GridLayout with a single column. This ensures that all the child
95 // views added get auto-expanded to fill the full width of the bubble. 100 // views added get auto-expanded to fill the full width of the bubble.
96 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { 101 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) {
97 views::GridLayout* layout = new views::GridLayout(view); 102 views::GridLayout* layout = new views::GridLayout(view);
98 view->SetLayoutManager(layout); 103 view->SetLayoutManager(layout);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 public: 180 public:
176 explicit SizedContainer(const gfx::Size& preferred_size) 181 explicit SizedContainer(const gfx::Size& preferred_size)
177 : preferred_size_(preferred_size) {} 182 : preferred_size_(preferred_size) {}
178 183
179 gfx::Size GetPreferredSize() const override { return preferred_size_; } 184 gfx::Size GetPreferredSize() const override { return preferred_size_; }
180 185
181 private: 186 private:
182 gfx::Size preferred_size_; 187 gfx::Size preferred_size_;
183 }; 188 };
184 189
190 // A view to host the GAIA webview overlapped with a back button. This class
191 // is needed to reparent the back button inside a native view so that on
192 // windows, user input can be be properly routed to the button.
193 class HostView : public views::View {
194 public:
195 HostView() : title_view_(nullptr), title_widget_(nullptr) {}
achuithb 2015/09/28 21:51:38 Use data member initialization instead for title_v
Roger Tawa OOO till Jul 10th 2015/10/02 01:16:31 Done.
196 ~HostView() override;
197
198 void Initialize(views::View* title_view, views::View* main_view);
199
200 private:
201 // views::View:
202 void ViewHierarchyChanged(
203 const ViewHierarchyChangedDetails& details) override;
204
205 // The title itself and the overlaped widget that contains it.
achuithb 2015/09/28 21:51:37 Also add comment: Not owned.
Roger Tawa OOO till Jul 10th 2015/10/02 01:16:31 Done.
206 views::View* title_view_;
achuithb 2015/09/28 21:51:37 = null_ptr
Roger Tawa OOO till Jul 10th 2015/10/02 01:16:31 Done.
207 scoped_ptr<views::Widget> title_widget_;
208
209 DISALLOW_COPY_AND_ASSIGN(HostView);
210 };
211
212 HostView::~HostView() {}
213
214 void HostView::Initialize(views::View* title_view, views::View* main_view) {
215 title_view_ = title_view;
216 title_view_->set_owned_by_client();
217 AddChildView(main_view);
218 SetLayoutManager(new views::FillLayout());
219 }
220
221 void HostView::ViewHierarchyChanged(
222 const ViewHierarchyChangedDetails& details) {
223 if (title_widget_ != nullptr || GetWidget() == nullptr)
224 return;
225
226 // The title view must be placed within its own widget so that it can
227 // properly receive user input when overlapped on another view.
228 views::Widget::InitParams params(
229 views::Widget::InitParams::TYPE_CONTROL);
230 params.parent = GetWidget()->GetNativeView();
231 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
232 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
233 title_widget_.reset(new views::Widget);
234 title_widget_->Init(params);
235 title_widget_->SetContentsView(title_view_);
236
237 gfx::Rect bounds(title_view_->GetPreferredSize());
238 title_view_->SetBoundsRect(bounds);
239 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset);
240 title_widget_->SetBounds(bounds);
241 }
242
185 } // namespace 243 } // namespace
186 244
187 // RightAlignedIconLabelButton ------------------------------------------------- 245 // RightAlignedIconLabelButton -------------------------------------------------
188 246
189 // A custom LabelButton that has a centered text and right aligned icon. 247 // A custom LabelButton that has a centered text and right aligned icon.
190 class RightAlignedIconLabelButton : public views::LabelButton { 248 class RightAlignedIconLabelButton : public views::LabelButton {
191 public: 249 public:
192 RightAlignedIconLabelButton(views::ButtonListener* listener, 250 RightAlignedIconLabelButton(views::ButtonListener* listener,
193 const base::string16& text) 251 const base::string16& text)
194 : views::LabelButton(listener, text) { 252 : views::LabelButton(listener, text) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 views::Textfield* profile_name_textfield_; 452 views::Textfield* profile_name_textfield_;
395 453
396 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); 454 DISALLOW_COPY_AND_ASSIGN(EditableProfileName);
397 }; 455 };
398 456
399 // A title card with one back button right aligned and one label center aligned. 457 // A title card with one back button right aligned and one label center aligned.
400 class TitleCard : public views::View { 458 class TitleCard : public views::View {
401 public: 459 public:
402 TitleCard(const base::string16& message, views::ButtonListener* listener, 460 TitleCard(const base::string16& message, views::ButtonListener* listener,
403 views::ImageButton** back_button) { 461 views::ImageButton** back_button) {
404 back_button_ = new views::ImageButton(listener); 462 back_button_ = CreateBackButton(listener);
405 back_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
406 views::ImageButton::ALIGN_MIDDLE);
407 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
408 back_button_->SetImage(views::ImageButton::STATE_NORMAL,
409 rb->GetImageSkiaNamed(IDR_BACK));
410 back_button_->SetImage(views::ImageButton::STATE_HOVERED,
411 rb->GetImageSkiaNamed(IDR_BACK_H));
412 back_button_->SetImage(views::ImageButton::STATE_PRESSED,
413 rb->GetImageSkiaNamed(IDR_BACK_P));
414 back_button_->SetImage(views::ImageButton::STATE_DISABLED,
415 rb->GetImageSkiaNamed(IDR_BACK_D));
416 back_button_->SetFocusable(true);
417 *back_button = back_button_; 463 *back_button = back_button_;
418 464
419 title_label_ = new views::Label(message); 465 title_label_ = new views::Label(message);
420 title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 466 title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
467 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
421 const gfx::FontList& medium_font_list = 468 const gfx::FontList& medium_font_list =
422 rb->GetFontList(ui::ResourceBundle::MediumFont); 469 rb->GetFontList(ui::ResourceBundle::MediumFont);
423 title_label_->SetFontList(medium_font_list); 470 title_label_->SetFontList(medium_font_list);
424 471
425 AddChildView(back_button_); 472 AddChildView(back_button_);
426 AddChildView(title_label_); 473 AddChildView(title_label_);
427 } 474 }
428 475
476 static views::ImageButton* CreateBackButton(views::ButtonListener* listener) {
achuithb 2015/09/28 21:51:38 We prefer this here rather than the anonymous name
Roger Tawa OOO till Jul 10th 2015/10/02 01:16:31 Nope. Moved to anonymous namespace.
477 views::ImageButton* back_button = new views::ImageButton(listener);
478 back_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
479 views::ImageButton::ALIGN_MIDDLE);
480 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
481 back_button->SetImage(views::ImageButton::STATE_NORMAL,
482 rb->GetImageSkiaNamed(IDR_BACK));
483 back_button->SetImage(views::ImageButton::STATE_HOVERED,
484 rb->GetImageSkiaNamed(IDR_BACK_H));
485 back_button->SetImage(views::ImageButton::STATE_PRESSED,
486 rb->GetImageSkiaNamed(IDR_BACK_P));
487 back_button->SetImage(views::ImageButton::STATE_DISABLED,
488 rb->GetImageSkiaNamed(IDR_BACK_D));
489 back_button->SetFocusable(true);
490 return back_button;
491 }
492
429 // Creates a new view that has the |title_card| with horizontal padding at the 493 // Creates a new view that has the |title_card| with horizontal padding at the
430 // top, an edge-to-edge separator below, and the specified |view| at the 494 // top, an edge-to-edge separator below, and the specified |view| at the
431 // bottom. 495 // bottom.
432 static views::View* AddPaddedTitleCard(views::View* view, 496 static views::View* AddPaddedTitleCard(views::View* view,
433 TitleCard* title_card, 497 TitleCard* title_card,
434 int width) { 498 int width) {
435 views::View* titled_view = new views::View(); 499 views::View* titled_view = new views::View();
436 views::GridLayout* layout = new views::GridLayout(titled_view); 500 views::GridLayout* layout = new views::GridLayout(titled_view);
437 titled_view->SetLayoutManager(layout); 501 titled_view->SetLayoutManager(layout);
438 502
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 ResetView(); 781 ResetView();
718 RemoveAllChildViews(true); 782 RemoveAllChildViews(true);
719 view_mode_ = view_to_display; 783 view_mode_ = view_to_display;
720 784
721 views::GridLayout* layout = nullptr; 785 views::GridLayout* layout = nullptr;
722 views::View* sub_view = nullptr; 786 views::View* sub_view = nullptr;
723 views::View* view_to_focus = nullptr; 787 views::View* view_to_focus = nullptr;
724 switch (view_mode_) { 788 switch (view_mode_) {
725 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: 789 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
726 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: 790 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
727 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: 791 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: {
728 layout = CreateSingleColumnLayout(this, kFixedGaiaViewWidth); 792 int width = switches::UsePasswordSeparatedSigninFlow()
achuithb 2015/09/28 21:51:37 const
Roger Tawa OOO till Jul 10th 2015/10/02 01:16:31 Done.
793 ? kFixedGaiaViewWidth : kPasswordCombinedFixedGaiaViewWidth;
794 layout = CreateSingleColumnLayout(this, width);
729 sub_view = CreateGaiaSigninView(&view_to_focus); 795 sub_view = CreateGaiaSigninView(&view_to_focus);
730 break; 796 break;
797 }
731 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL: 798 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL:
732 layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth); 799 layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth);
733 sub_view = CreateAccountRemovalView(); 800 sub_view = CreateAccountRemovalView();
734 break; 801 break;
735 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: 802 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER:
736 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); 803 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth);
737 sub_view = CreateSwitchUserView(); 804 sub_view = CreateSwitchUserView();
738 ProfileMetrics::LogProfileNewAvatarMenuNotYou( 805 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
739 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); 806 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW);
740 break; 807 break;
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 url = signin::GetReauthURL(browser_->profile(), 1639 url = signin::GetReauthURL(browser_->profile(),
1573 GetAuthErrorAccountId(browser_->profile())); 1640 GetAuthErrorAccountId(browser_->profile()));
1574 message_id = IDS_PROFILES_GAIA_REAUTH_TITLE; 1641 message_id = IDS_PROFILES_GAIA_REAUTH_TITLE;
1575 break; 1642 break;
1576 } 1643 }
1577 default: 1644 default:
1578 NOTREACHED() << "Called with invalid mode=" << view_mode_; 1645 NOTREACHED() << "Called with invalid mode=" << view_mode_;
1579 return NULL; 1646 return NULL;
1580 } 1647 }
1581 1648
1582 // Adds Gaia signin webview 1649 // Adds Gaia signin webview.
1650 const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow()
1651 ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight)
1652 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth,
1653 kPasswordCombinedFixedGaiaViewHeight);
1583 Profile* profile = browser_->profile(); 1654 Profile* profile = browser_->profile();
1584 views::WebView* web_view = new views::WebView(profile); 1655 views::WebView* web_view = new views::WebView(profile);
1585 web_view->LoadInitialURL(url); 1656 web_view->LoadInitialURL(url);
1586 web_view->GetWebContents()->SetDelegate(this); 1657 web_view->GetWebContents()->SetDelegate(this);
1587 web_view->SetPreferredSize( 1658 web_view->SetPreferredSize(pref_size);
1588 gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight));
1589 content::RenderWidgetHostView* rwhv = 1659 content::RenderWidgetHostView* rwhv =
1590 web_view->GetWebContents()->GetRenderWidgetHostView(); 1660 web_view->GetWebContents()->GetRenderWidgetHostView();
1591 if (rwhv) 1661 if (rwhv)
1592 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); 1662 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor);
1663
1664 if (signin_content_view)
1665 *signin_content_view = web_view;
1666
1667 if (switches::UsePasswordSeparatedSigninFlow()) {
1668 gaia_signin_cancel_button_ = TitleCard::CreateBackButton(this);
1669 HostView* host = new HostView();
1670 host->Initialize(gaia_signin_cancel_button_, web_view);
1671 return host;
1672 }
1673
1593 TitleCard* title_card = new TitleCard(l10n_util::GetStringUTF16(message_id), 1674 TitleCard* title_card = new TitleCard(l10n_util::GetStringUTF16(message_id),
1594 this, 1675 this,
1595 &gaia_signin_cancel_button_); 1676 &gaia_signin_cancel_button_);
1596 if (signin_content_view)
1597 *signin_content_view = web_view;
1598 return TitleCard::AddPaddedTitleCard( 1677 return TitleCard::AddPaddedTitleCard(
1599 web_view, title_card, kFixedGaiaViewWidth); 1678 web_view, title_card, kPasswordCombinedFixedGaiaViewWidth);
1600 } 1679 }
1601 1680
1602 views::View* ProfileChooserView::CreateAccountRemovalView() { 1681 views::View* ProfileChooserView::CreateAccountRemovalView() {
1603 views::View* view = new views::View(); 1682 views::View* view = new views::View();
1604 views::GridLayout* layout = CreateSingleColumnLayout( 1683 views::GridLayout* layout = CreateSingleColumnLayout(
1605 view, kFixedAccountRemovalViewWidth - 2 * views::kButtonHEdgeMarginNew); 1684 view, kFixedAccountRemovalViewWidth - 2 * views::kButtonHEdgeMarginNew);
1606 layout->SetInsets(0, 1685 layout->SetInsets(0,
1607 views::kButtonHEdgeMarginNew, 1686 views::kButtonHEdgeMarginNew,
1608 views::kButtonVEdgeMarginNew, 1687 views::kButtonVEdgeMarginNew,
1609 views::kButtonHEdgeMarginNew); 1688 views::kButtonHEdgeMarginNew);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1874 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1796 IncognitoModePrefs::DISABLED; 1875 IncognitoModePrefs::DISABLED;
1797 return incognito_available && !browser_->profile()->IsGuestSession(); 1876 return incognito_available && !browser_->profile()->IsGuestSession();
1798 } 1877 }
1799 1878
1800 void ProfileChooserView::PostActionPerformed( 1879 void ProfileChooserView::PostActionPerformed(
1801 ProfileMetrics::ProfileDesktopMenu action_performed) { 1880 ProfileMetrics::ProfileDesktopMenu action_performed) {
1802 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1881 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1803 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1882 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1804 } 1883 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698