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 "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 ModalSigninDelegate : public views::DialogDelegateView { | |
29 public: | |
30 ModalSigninDelegate(SigninViewController* signin_view_controller, | |
31 views::WebView* content_view, | |
32 Browser* browser) | |
33 : content_view_(content_view), | |
34 signin_view_controller_(signin_view_controller) { | |
35 modal_signin_widget_ = constrained_window::ShowWebModalDialogViews( | |
36 this, browser->tab_strip_model()->GetActiveWebContents()); | |
37 } | |
38 | |
39 void CloseModalSignin() { | |
40 ResetSigninViewControllerDelegate(); | |
41 modal_signin_widget_->Close(); | |
42 } | |
43 | |
44 void ResetSigninViewControllerDelegate() { | |
45 if (signin_view_controller_) { | |
46 signin_view_controller_->ResetModalSigninDelegate(); | |
47 signin_view_controller_ = nullptr; | |
48 } | |
49 } | |
50 | |
51 // views::DialogDelegateView: | |
52 views::View* GetContentsView() override { | |
53 return content_view_; | |
54 } | |
55 | |
56 views::Widget* GetWidget() override { | |
57 return content_view_->GetWidget(); | |
58 } | |
59 | |
60 const views::Widget* GetWidget() const override { | |
61 return content_view_->GetWidget(); | |
62 } | |
63 | |
64 void DeleteDelegate() override { | |
65 ResetSigninViewControllerDelegate(); | |
66 delete this; | |
67 } | |
68 | |
69 ui::ModalType GetModalType() const override { | |
70 return ui::MODAL_TYPE_CHILD; | |
71 } | |
72 | |
73 bool ShouldShowCloseButton() const override { | |
74 return false; | |
75 } | |
76 | |
77 int GetDialogButtons() const override { | |
78 return ui::DIALOG_BUTTON_NONE; | |
79 } | |
80 | |
81 private: | |
82 views::WebView* content_view_; | |
83 SigninViewController* signin_view_controller_; // Not owned. | |
84 views::Widget* modal_signin_widget_; // Not owned. | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(ModalSigninDelegate); | |
87 }; | |
88 | |
89 SigninViewController::SigninViewController() | |
90 : modal_signin_delegate_(nullptr) {} | |
91 | |
92 SigninViewController::~SigninViewController() { | |
93 CloseModalSignin(); | |
94 } | |
95 | |
96 // static | |
97 views::WebView* SigninViewController::CreateGaiaWebView( | |
98 content::WebContentsDelegate* delegate, | |
99 profiles::BubbleViewMode mode, | |
100 Profile* profile) { | |
101 GURL url = signin::GetSigninURLFromBubbleViewMode(profile, mode); | |
102 | |
103 // Adds Gaia signin webview. | |
104 const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow() | |
105 ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight) | |
106 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth, | |
107 kPasswordCombinedFixedGaiaViewHeight); | |
108 views::WebView* web_view = new views::WebView(profile); | |
109 web_view->LoadInitialURL(url); | |
110 | |
111 if (delegate) | |
112 web_view->GetWebContents()->SetDelegate(delegate); | |
113 | |
114 web_view->SetPreferredSize(pref_size); | |
115 content::RenderWidgetHostView* rwhv = | |
116 web_view->GetWebContents()->GetRenderWidgetHostView(); | |
117 if (rwhv) | |
118 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); | |
119 | |
120 return web_view; | |
121 } | |
122 | |
123 void SigninViewController::ShowModalSignin( | |
124 profiles::BubbleViewMode mode, Browser* browser) { | |
125 CloseModalSignin(); | |
126 // The delegate will delete itself on request of the views code when the | |
127 // widget is closed. | |
128 modal_signin_delegate_ = new ModalSigninDelegate( | |
129 this, CreateGaiaWebView(nullptr, mode, browser->profile()), browser); | |
130 } | |
131 | |
132 void SigninViewController::CloseModalSignin() { | |
133 if (modal_signin_delegate_) | |
134 modal_signin_delegate_->CloseModalSignin(); | |
sky
2015/12/01 23:34:52
null out modal_signin_delegate_ here, or a DCHECK
anthonyvd
2015/12/02 15:24:41
Done.
| |
135 } | |
136 | |
137 void SigninViewController::ResetModalSigninDelegate() { | |
138 modal_signin_delegate_ = nullptr; | |
139 } | |
140 | |
141 // static | |
142 bool SigninViewController::ShouldShowModalSigninForMode( | |
143 profiles::BubbleViewMode mode) { | |
144 return switches::UsePasswordSeparatedSigninFlow() && | |
145 (mode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN || | |
146 mode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || | |
147 mode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH); | |
148 } | |
OLD | NEW |