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

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

Issue 1413533009: Make the new Gaia password separated signin flow modal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use DialogDelegateView Created 5 years 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/profiles/signin_view_controller.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
9 #include "chrome/browser/signin/signin_error_controller_factory.h"
10 #include "chrome/browser/signin/signin_promo.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "components/constrained_window/constrained_window_views.h"
14 #include "components/signin/core/browser/signin_error_controller.h"
15 #include "components/signin/core/common/profile_management_switches.h"
16 #include "content/public/browser/render_widget_host_view.h"
17 #include "content/public/browser/web_contents.h"
18 #include "ui/views/controls/webview/webview.h"
19 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_delegate.h"
21 #include "ui/views/window/dialog_delegate.h"
22
23 const int kPasswordCombinedFixedGaiaViewHeight = 440;
24 const int kPasswordCombinedFixedGaiaViewWidth = 360;
25 const int kFixedGaiaViewHeight = 512;
26 const int kFixedGaiaViewWidth = 448;
27
28 class SigninViewControllerImpl {
29 public:
30 SigninViewControllerImpl() : modal_signin_widget_(nullptr) {}
31
32 void ShowModalSignin(views::Widget* widget) {
33 modal_signin_widget_ = widget;
34 }
35
36 void CloseModalSignin() {
37 if (modal_signin_widget_) {
38 modal_signin_widget_->Close();
sky 2015/11/30 16:16:38 Close is not synchronous. DeleteDelegate will be c
anthonyvd 2015/11/30 21:59:34 Ahh, I didn't think about that! I believe the lat
39 modal_signin_widget_ = nullptr;
40 }
41 }
42
43 void Reset() {
44 modal_signin_widget_ = nullptr;
45 }
46
47 private:
48 views::Widget* modal_signin_widget_; // Not owned.
49
50 DISALLOW_COPY_AND_ASSIGN(SigninViewControllerImpl);
51 };
52
53 class ModalSigninDelegate : public views::DialogDelegateView,
54 public content::WebContentsDelegate {
55 public:
56 explicit ModalSigninDelegate(SigninViewControllerImpl* signin_view_controller,
57 views::WebView* content_view)
58 : content_view_(content_view),
59 signin_view_controller_(signin_view_controller) {
60 content_view_->GetWebContents()->SetDelegate(this);
61 }
62
63 views::View* GetContentsView() override {
64 return content_view_;
65 }
66
67 views::Widget* GetWidget() override {
68 return content_view_->GetWidget();
69 }
70
71 const views::Widget* GetWidget() const override {
72 return content_view_->GetWidget();
73 }
74
75 void DeleteDelegate() override {
76 signin_view_controller_->Reset();
77 delete this;
78 }
79
80 ui::ModalType GetModalType() const override {
81 return ui::MODAL_TYPE_CHILD;
82 }
83
84 bool ShouldShowCloseButton() const override {
85 return false;
86 }
87
88 int GetDialogButtons() const override {
89 return ui::DIALOG_BUTTON_NONE;
90 }
91
92 private:
93 views::WebView* content_view_;
94 SigninViewControllerImpl* signin_view_controller_; // Not owned.
95
96 DISALLOW_COPY_AND_ASSIGN(ModalSigninDelegate);
97 };
98
99 SigninViewController::SigninViewController()
100 : impl_(new SigninViewControllerImpl) {}
101
102 SigninViewController::~SigninViewController() {
103 CloseModalSignin();
104 delete impl_;
105 }
106
107 // static
108 views::WebView* SigninViewController::CreateGaiaWebView(
109 WebContentsDelegate* delegate,
110 profiles::BubbleViewMode mode,
111 Profile* profile) {
112 GURL url = signin::GetSigninURLFromBubbleViewMode(profile, mode);
113
114 // Adds Gaia signin webview.
115 const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow()
116 ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight)
117 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth,
118 kPasswordCombinedFixedGaiaViewHeight);
119 views::WebView* web_view = new views::WebView(profile);
120 web_view->LoadInitialURL(url);
121 web_view->GetWebContents()->SetDelegate(delegate);
122 web_view->SetPreferredSize(pref_size);
123 content::RenderWidgetHostView* rwhv =
124 web_view->GetWebContents()->GetRenderWidgetHostView();
125 if (rwhv)
126 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor);
127
128 return web_view;
129 }
130
131 void SigninViewController::ShowModalSignin(
132 profiles::BubbleViewMode mode,
133 Browser* browser) {
134 CloseModalSignin();
135 ModalSigninDelegate* delegate = new ModalSigninDelegate(impl_,
136 CreateGaiaWebView(this, mode, browser->profile()));
137 views::Widget* widget = constrained_window::ShowWebModalDialogViews(
138 delegate, browser->tab_strip_model()->GetActiveWebContents());
139 impl_->ShowModalSignin(widget);
140 }
141
142 void SigninViewController::CloseModalSignin() {
143 impl_->CloseModalSignin();
144 }
145
146 // static
147 bool SigninViewController::ShouldShowModalSigninForMode(
148 profiles::BubbleViewMode mode) {
149 return switches::UsePasswordSeparatedSigninFlow() &&
150 (mode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN ||
151 mode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT ||
152 mode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH);
153 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/signin_view_controller.h ('k') | chrome/browser/ui/webui/signin/inline_login_handler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698