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

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: Fix Mac build 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 namespace {
29
30 class ModalSigninDelegate : public views::WidgetDelegate,
31 public content::WebContentsDelegate {
32 public:
33 explicit ModalSigninDelegate(views::WebView* content_view)
34 : content_view_(content_view) {
35 content_view_->GetWebContents()->SetDelegate(this);
36 }
37
38 views::View* GetContentsView() override {
39 return content_view_;
40 }
41
42 views::Widget* GetWidget() override {
43 return content_view_->GetWidget();
44 }
45
46 const views::Widget* GetWidget() const override {
47 return content_view_->GetWidget();
48 }
49
50 void DeleteDelegate() override {
51 delete this;
52 }
53
54 ui::ModalType GetModalType() const override {
55 return ui::MODAL_TYPE_CHILD;
56 }
57
58 bool ShouldShowWindowTitle() const override {
59 return false;
60 }
61
62 bool ShouldShowCloseButton() const override {
63 return false;
64 }
65
66 views::NonClientFrameView* CreateNonClientFrameView(
67 views::Widget* widget) override {
68 return views::DialogDelegate::CreateDialogFrameView(widget);
sky 2015/11/25 00:30:07 Is there a reason you're not subclassing DialogDel
anthonyvd 2015/11/25 18:49:31 Doing it that way automatically adds the OK/Cancel
sky 2015/11/25 20:57:16 You can override GetDialogButtons if you don't wan
anthonyvd 2015/11/25 23:05:22 Neat, thanks for the info! Done.
69 }
70
71 private:
72 views::WebView* content_view_;
73 };
sky 2015/11/25 00:30:07 DISALLOW...
anthonyvd 2015/11/25 18:49:31 Done.
74
75 } // namespace
76
77 // static
78 views::WebView* SigninViewController::CreateGaiaWebView(
79 WebContentsDelegate* delegate,
80 profiles::BubbleViewMode mode,
81 Profile* profile) {
82 GURL url;
sky 2015/11/25 00:30:07 The code for determining the url doesn't seem plat
anthonyvd 2015/11/25 18:49:31 Done.
83 switch (mode) {
84 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
85 url = signin::GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN,
86 false /* auto_close */,
87 true /* is_constrained */);
88 break;
89 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
90 url = signin::GetPromoURL(
91 signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT,
92 false /* auto_close */,
93 true /* is_constrained */);
94 break;
95 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: {
96 const SigninErrorController* error_controller =
97 SigninErrorControllerFactory::GetForProfile(profile);
98 CHECK(error_controller);
99 DCHECK(error_controller->HasError());
100 url = signin::GetReauthURL(profile, error_controller->error_account_id());
101 break;
102 }
103 default:
104 NOTREACHED() << "Called with invalid mode=" << mode;
105 return NULL;
106 }
107
108 // Adds Gaia signin webview.
109 const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow()
110 ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight)
111 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth,
112 kPasswordCombinedFixedGaiaViewHeight);
113 views::WebView* web_view = new views::WebView(profile);
114 web_view->LoadInitialURL(url);
115 web_view->GetWebContents()->SetDelegate(delegate);
116 web_view->SetPreferredSize(pref_size);
117 content::RenderWidgetHostView* rwhv =
118 web_view->GetWebContents()->GetRenderWidgetHostView();
119 if (rwhv)
120 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor);
121
122 return web_view;
123 }
124
125 void SigninViewController::ShowModalSignin(
126 profiles::BubbleViewMode mode,
127 Browser* browser) {
128 CloseModalSignin();
129 ModalSigninDelegate* delegate = new ModalSigninDelegate(
130 CreateGaiaWebView(this, mode, browser->profile()));
131 modal_signin_widget_ = constrained_window::ShowWebModalDialogViews(
132 delegate, browser->tab_strip_model()->GetActiveWebContents());
133 }
134
135 void SigninViewController::CloseModalSignin() {
136 if (modal_signin_widget_) {
137 modal_signin_widget_->Close();
138 modal_signin_widget_ = nullptr;
sky 2015/11/25 00:30:07 What if the modal_signin_widget_ is deleted out fr
anthonyvd 2015/11/25 18:49:31 Good point. This latest patchset fixes this by set
139 }
140 }
141
142 // static
143 bool SigninViewController::ShouldShowModalSigninForMode(
144 profiles::BubbleViewMode mode) {
145 return switches::UsePasswordSeparatedSigninFlow() &&
146 (mode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN ||
147 mode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT ||
148 mode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH);
149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698