OLD | NEW |
---|---|
(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 "base/observer_list.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | |
10 #include "chrome/browser/signin/signin_error_controller_factory.h" | |
11 #include "chrome/browser/signin/signin_promo.h" | |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
14 #include "components/constrained_window/constrained_window_views.h" | |
15 #include "components/signin/core/browser/signin_error_controller.h" | |
16 #include "components/signin/core/common/profile_management_switches.h" | |
17 #include "content/public/browser/render_widget_host_view.h" | |
18 #include "content/public/browser/web_contents.h" | |
19 #include "ui/views/controls/webview/webview.h" | |
20 #include "ui/views/widget/widget.h" | |
21 #include "ui/views/widget/widget_delegate.h" | |
22 #include "ui/views/window/dialog_delegate.h" | |
23 | |
24 const int kPasswordCombinedFixedGaiaViewHeight = 440; | |
25 const int kPasswordCombinedFixedGaiaViewWidth = 360; | |
26 const int kFixedGaiaViewHeight = 512; | |
27 const int kFixedGaiaViewWidth = 448; | |
28 | |
29 class SigninViewControllerImpl { | |
sky
2015/11/30 23:54:23
Why do you need this implementation class? Can't t
anthonyvd
2015/12/01 16:37:08
I wasn't too sure about leaving it in because I li
| |
30 public: | |
31 class Observer { | |
32 public: | |
33 virtual void OnCloseRequested() = 0; | |
34 }; | |
35 | |
36 SigninViewControllerImpl(); | |
37 virtual ~SigninViewControllerImpl(); | |
38 void ShowModalSignin(views::WebView* content, Browser* browser); | |
39 void CloseModalSignin(); | |
40 void AddObserver(Observer* observer); | |
41 void RemoveObserver(Observer* observer); | |
42 | |
43 private: | |
44 base::ObserverList<Observer> observers_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(SigninViewControllerImpl); | |
47 }; | |
48 | |
49 class ModalSigninDelegate : public views::DialogDelegateView, | |
50 public content::WebContentsDelegate, | |
51 public SigninViewControllerImpl::Observer { | |
52 public: | |
53 explicit ModalSigninDelegate(SigninViewControllerImpl* signin_view_controller, | |
sky
2015/11/30 23:54:23
no explicit.
anthonyvd
2015/12/01 16:37:08
Done.
| |
54 views::WebView* content_view, | |
55 Browser* browser) | |
56 : content_view_(content_view), | |
57 signin_view_controller_(signin_view_controller) { | |
58 signin_view_controller_->AddObserver(this); | |
59 content_view_->GetWebContents()->SetDelegate(this); | |
60 modal_signin_widget_ = constrained_window::ShowWebModalDialogViews( | |
61 this, browser->tab_strip_model()->GetActiveWebContents()); | |
62 } | |
63 | |
64 views::View* GetContentsView() override { | |
sky
2015/11/30 23:54:23
Prefix and group sections that are implementations
anthonyvd
2015/12/01 16:37:08
Done.
| |
65 return content_view_; | |
66 } | |
67 | |
68 views::Widget* GetWidget() override { | |
69 return content_view_->GetWidget(); | |
70 } | |
71 | |
72 const views::Widget* GetWidget() const override { | |
73 return content_view_->GetWidget(); | |
74 } | |
75 | |
76 void DeleteDelegate() override { | |
77 signin_view_controller_->RemoveObserver(this); | |
78 delete this; | |
79 } | |
80 | |
81 ui::ModalType GetModalType() const override { | |
82 return ui::MODAL_TYPE_CHILD; | |
83 } | |
84 | |
85 bool ShouldShowCloseButton() const override { | |
86 return false; | |
87 } | |
88 | |
89 int GetDialogButtons() const override { | |
90 return ui::DIALOG_BUTTON_NONE; | |
91 } | |
92 | |
93 void CloseModalSignin() { | |
94 modal_signin_widget_->Close(); | |
95 } | |
96 | |
97 void OnCloseRequested() override { | |
98 signin_view_controller_->RemoveObserver(this); | |
99 CloseModalSignin(); | |
100 } | |
101 | |
102 private: | |
103 views::WebView* content_view_; | |
104 SigninViewControllerImpl* signin_view_controller_; // Not owned. | |
105 views::Widget* modal_signin_widget_; // Not owned. | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(ModalSigninDelegate); | |
108 }; | |
109 | |
110 SigninViewControllerImpl::SigninViewControllerImpl() {} | |
111 SigninViewControllerImpl::~SigninViewControllerImpl() { | |
112 CloseModalSignin(); | |
113 } | |
114 | |
115 void SigninViewControllerImpl::ShowModalSignin( | |
116 views::WebView* content, Browser* browser) { | |
117 CloseModalSignin(); | |
118 // The delegate will delete itself on request of the views code when the | |
119 // widget is closed. | |
120 new ModalSigninDelegate(this, content, browser); | |
121 } | |
122 | |
123 void SigninViewControllerImpl::CloseModalSignin() { | |
124 FOR_EACH_OBSERVER(Observer, observers_, OnCloseRequested()); | |
125 } | |
126 | |
127 void SigninViewControllerImpl::AddObserver(Observer* observer) { | |
128 observers_.AddObserver(observer); | |
129 } | |
130 | |
131 void SigninViewControllerImpl::RemoveObserver(Observer* observer) { | |
132 observers_.RemoveObserver(observer); | |
133 } | |
134 | |
135 SigninViewController::SigninViewController() | |
136 : impl_(new SigninViewControllerImpl) {} | |
137 | |
138 SigninViewController::~SigninViewController() { | |
139 CloseModalSignin(); | |
140 delete impl_; | |
141 } | |
142 | |
143 // static | |
144 views::WebView* SigninViewController::CreateGaiaWebView( | |
145 WebContentsDelegate* delegate, | |
146 profiles::BubbleViewMode mode, | |
147 Profile* profile) { | |
148 GURL url = signin::GetSigninURLFromBubbleViewMode(profile, mode); | |
149 | |
150 // Adds Gaia signin webview. | |
151 const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow() | |
152 ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight) | |
153 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth, | |
154 kPasswordCombinedFixedGaiaViewHeight); | |
155 views::WebView* web_view = new views::WebView(profile); | |
156 web_view->LoadInitialURL(url); | |
157 web_view->GetWebContents()->SetDelegate(delegate); | |
158 web_view->SetPreferredSize(pref_size); | |
159 content::RenderWidgetHostView* rwhv = | |
160 web_view->GetWebContents()->GetRenderWidgetHostView(); | |
161 if (rwhv) | |
162 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); | |
163 | |
164 return web_view; | |
165 } | |
166 | |
167 void SigninViewController::ShowModalSignin( | |
168 profiles::BubbleViewMode mode, Browser* browser) { | |
169 impl_->ShowModalSignin( | |
170 CreateGaiaWebView(this, mode, browser->profile()), browser); | |
171 } | |
172 | |
173 void SigninViewController::CloseModalSignin() { | |
174 impl_->CloseModalSignin(); | |
175 } | |
176 | |
177 // static | |
178 bool SigninViewController::ShouldShowModalSigninForMode( | |
179 profiles::BubbleViewMode mode) { | |
180 return switches::UsePasswordSeparatedSigninFlow() && | |
181 (mode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN || | |
182 mode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || | |
183 mode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH); | |
184 } | |
OLD | NEW |