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

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

Issue 2552473002: Display error message when user try to open a locked supervised user profile when force-sign-in is … (Closed)
Patch Set: sky's comments Created 4 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
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/user_manager_view.h" 5 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 namespace { 49 namespace {
50 50
51 // An open User Manager window. There can only be one open at a time. This 51 // An open User Manager window. There can only be one open at a time. This
52 // is reset to NULL when the window is closed. 52 // is reset to NULL when the window is closed.
53 UserManagerView* instance_ = nullptr; 53 UserManagerView* instance_ = nullptr;
54 base::Closure* user_manager_shown_callback_for_testing_ = nullptr; 54 base::Closure* user_manager_shown_callback_for_testing_ = nullptr;
55 bool instance_under_construction_ = false; 55 bool instance_under_construction_ = false;
56 } // namespace 56 } // namespace
57 57
58 // ReauthDelegate--------------------------------------------------------------- 58 // Delegate---------------------------------------------------------------
59 59
60 ReauthDelegate::ReauthDelegate(UserManagerView* parent, 60 UserManagerProfileDialogDelegate::UserManagerProfileDialogDelegate(
61 views::WebView* web_view, 61 UserManagerView* parent,
62 const std::string& email_address, 62 views::WebView* web_view,
63 signin_metrics::Reason reason) 63 const std::string& email_address,
64 : parent_(parent), 64 const GURL& url)
65 web_view_(web_view), 65 : parent_(parent), web_view_(web_view), email_address_(email_address) {
66 email_address_(email_address) {
67 AddChildView(web_view_); 66 AddChildView(web_view_);
68 SetLayoutManager(new views::FillLayout()); 67 SetLayoutManager(new views::FillLayout());
69 68
70 web_view_->GetWebContents()->SetDelegate(this); 69 web_view_->GetWebContents()->SetDelegate(this);
71
72 // Load the re-auth URL, prepopulated with the user's email address.
73 // Add the index of the profile to the URL so that the inline login page
74 // knows which profile to load and update the credentials.
75 GURL url = signin::GetReauthURLWithEmail(
76 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason,
77 email_address_);
78 web_view_->LoadInitialURL(url); 70 web_view_->LoadInitialURL(url);
79 } 71 }
80 72
81 ReauthDelegate::~ReauthDelegate() {} 73 UserManagerProfileDialogDelegate::~UserManagerProfileDialogDelegate() {}
82 74
83 gfx::Size ReauthDelegate::GetPreferredSize() const { 75 gfx::Size UserManagerProfileDialogDelegate::GetPreferredSize() const {
84 return switches::UsePasswordSeparatedSigninFlow() ? 76 return switches::UsePasswordSeparatedSigninFlow()
85 gfx::Size(UserManager::kReauthDialogWidth, 77 ? gfx::Size(UserManagerProfileDialog::kDialogWidth,
86 UserManager::kReauthDialogHeight) : 78 UserManagerProfileDialog::kDialogHeight)
87 gfx::Size(UserManager::kPasswordCombinedReauthDialogWidth, 79 : gfx::Size(
88 UserManager::kPasswordCombinedReauthDialogHeight); 80 UserManagerProfileDialog::kPasswordCombinedDialogWidth,
81 UserManagerProfileDialog::kPasswordCombinedDialogHeight);
89 } 82 }
90 83
91 void ReauthDelegate::DisplayErrorMessage() { 84 void UserManagerProfileDialogDelegate::DisplayErrorMessage() {
92 web_view_->LoadInitialURL(GURL(chrome::kChromeUISigninErrorURL)); 85 web_view_->LoadInitialURL(GURL(chrome::kChromeUISigninErrorURL));
93 } 86 }
94 87
95 bool ReauthDelegate::CanResize() const { 88 bool UserManagerProfileDialogDelegate::CanResize() const {
96 return true; 89 return true;
97 } 90 }
98 91
99 bool ReauthDelegate::CanMaximize() const { 92 bool UserManagerProfileDialogDelegate::CanMaximize() const {
100 return true; 93 return true;
101 } 94 }
102 95
103 bool ReauthDelegate::CanMinimize() const { 96 bool UserManagerProfileDialogDelegate::CanMinimize() const {
104 return true; 97 return true;
105 } 98 }
106 99
107 bool ReauthDelegate::ShouldUseCustomFrame() const { 100 bool UserManagerProfileDialogDelegate::ShouldUseCustomFrame() const {
108 return false; 101 return false;
109 } 102 }
110 103
111 ui::ModalType ReauthDelegate::GetModalType() const { 104 ui::ModalType UserManagerProfileDialogDelegate::GetModalType() const {
112 return ui::MODAL_TYPE_WINDOW; 105 return ui::MODAL_TYPE_WINDOW;
113 } 106 }
114 107
115 void ReauthDelegate::DeleteDelegate() { 108 void UserManagerProfileDialogDelegate::DeleteDelegate() {
116 OnReauthDialogDestroyed(); 109 OnDialogDestroyed();
117 delete this; 110 delete this;
118 } 111 }
119 112
120 base::string16 ReauthDelegate::GetWindowTitle() const { 113 base::string16 UserManagerProfileDialogDelegate::GetWindowTitle() const {
121 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE); 114 return l10n_util::GetStringUTF16(IDS_PROFILES_GAIA_SIGNIN_TITLE);
122 } 115 }
123 116
124 int ReauthDelegate::GetDialogButtons() const { 117 int UserManagerProfileDialogDelegate::GetDialogButtons() const {
125 return ui::DIALOG_BUTTON_NONE; 118 return ui::DIALOG_BUTTON_NONE;
126 } 119 }
127 120
128 views::View* ReauthDelegate::GetInitiallyFocusedView() { 121 views::View* UserManagerProfileDialogDelegate::GetInitiallyFocusedView() {
129 return static_cast<views::View*>(web_view_); 122 return static_cast<views::View*>(web_view_);
130 } 123 }
131 124
132 void ReauthDelegate::CloseReauthDialog() { 125 void UserManagerProfileDialogDelegate::CloseDialog() {
133 OnReauthDialogDestroyed(); 126 OnDialogDestroyed();
134 GetWidget()->Close(); 127 GetWidget()->Close();
135 } 128 }
136 129
137 void ReauthDelegate::OnReauthDialogDestroyed() { 130 void UserManagerProfileDialogDelegate::OnDialogDestroyed() {
138 if (parent_) { 131 if (parent_) {
139 parent_->OnReauthDialogDestroyed(); 132 parent_->OnDialogDestroyed();
140 parent_ = nullptr; 133 parent_ = nullptr;
141 } 134 }
142 } 135 }
143 136
144 // UserManager ----------------------------------------------------------------- 137 // UserManager -----------------------------------------------------------------
145 138
146 // static 139 // static
147 void UserManager::Show( 140 void UserManager::Show(
148 const base::FilePath& profile_path_to_focus, 141 const base::FilePath& profile_path_to_focus,
149 profiles::UserManagerTutorialMode tutorial_mode, 142 profiles::UserManagerTutorialMode tutorial_mode,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (!user_manager_shown_callback_for_testing_->is_null()) 195 if (!user_manager_shown_callback_for_testing_->is_null())
203 user_manager_shown_callback_for_testing_->Run(); 196 user_manager_shown_callback_for_testing_->Run();
204 197
205 delete user_manager_shown_callback_for_testing_; 198 delete user_manager_shown_callback_for_testing_;
206 user_manager_shown_callback_for_testing_ = nullptr; 199 user_manager_shown_callback_for_testing_ = nullptr;
207 } 200 }
208 } 201 }
209 } 202 }
210 203
211 // static 204 // static
212 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
213 const std::string& email,
214 signin_metrics::Reason reason) {
215 // This method should only be called if the user manager is already showing.
216 if (!IsShowing())
217 return;
218 instance_->ShowReauthDialog(browser_context, email, reason);
219 }
220
221 // static
222 void UserManager::HideReauthDialog() {
223 // This method should only be called if the user manager is already showing.
224 if (instance_ && instance_->GetWidget()->IsVisible())
225 instance_->HideReauthDialog();
226 }
227
228 // static
229 void UserManager::AddOnUserManagerShownCallbackForTesting( 205 void UserManager::AddOnUserManagerShownCallbackForTesting(
230 const base::Closure& callback) { 206 const base::Closure& callback) {
231 DCHECK(!user_manager_shown_callback_for_testing_); 207 DCHECK(!user_manager_shown_callback_for_testing_);
232 user_manager_shown_callback_for_testing_ = new base::Closure(callback); 208 user_manager_shown_callback_for_testing_ = new base::Closure(callback);
233 } 209 }
234 210
235 // static 211 // static
236 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, 212 base::FilePath UserManager::GetSigninProfilePath() {
237 const base::FilePath& profile_path) { 213 return instance_->GetSigninProfilePath();
238 if (!IsShowing()) 214 }
215
216 // UserManagerProfileDialog
217 // -------------------------------------------------------------
218
219 // static
220 void UserManagerProfileDialog::ShowReauthDialog(
221 content::BrowserContext* browser_context,
222 const std::string& email,
223 signin_metrics::Reason reason) {
224 // This method should only be called if the user manager is already showing.
225 if (!UserManager::IsShowing())
239 return; 226 return;
240 instance_->SetSigninProfilePath(profile_path); 227 // Load the re-auth URL, prepopulated with the user's email address.
241 ShowReauthDialog(browser_context, std::string(), 228 // Add the index of the profile to the URL so that the inline login page
242 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT); 229 // knows which profile to load and update the credentials.
230 GURL url = signin::GetReauthURLWithEmail(
231 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, email);
232 instance_->ShowDialog(browser_context, email, url);
243 } 233 }
244 234
245 // static 235 // static
246 void UserManager::DisplayErrorMessage() { 236 void UserManagerProfileDialog::ShowSigninDialog(
237 content::BrowserContext* browser_context,
238 const base::FilePath& profile_path) {
239 if (!UserManager::IsShowing())
240 return;
241 instance_->SetSigninProfilePath(profile_path);
242 GURL url = signin::GetPromoURL(
243 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
244 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, true, true);
245 instance_->ShowDialog(browser_context, std::string(), url);
246 }
247
248 void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage(
249 content::BrowserContext* browser_context) {
250 if (!UserManager::IsShowing())
251 return;
252 instance_->ShowDialog(browser_context, std::string(),
253 GURL(chrome::kChromeUISigninErrorURL));
254 }
255
256 // static
257 void UserManagerProfileDialog::DisplayErrorMessage() {
247 // This method should only be called if the user manager is already showing. 258 // This method should only be called if the user manager is already showing.
248 DCHECK(instance_); 259 DCHECK(instance_);
249 instance_->DisplayErrorMessage(); 260 instance_->DisplayErrorMessage();
250 } 261 }
251 262
252 // static 263 // static
253 base::FilePath UserManager::GetSigninProfilePath() { 264 void UserManagerProfileDialog::HideDialog() {
254 return instance_->GetSigninProfilePath(); 265 if (instance_ && instance_->GetWidget()->IsVisible())
266 instance_->HideDialog();
255 } 267 }
256 268
257 // UserManagerView ------------------------------------------------------------- 269 // UserManagerView -------------------------------------------------------------
258 270
259 UserManagerView::UserManagerView() 271 UserManagerView::UserManagerView()
260 : web_view_(nullptr), 272 : web_view_(nullptr),
261 delegate_(nullptr), 273 delegate_(nullptr),
262 user_manager_started_showing_(base::Time()) { 274 user_manager_started_showing_(base::Time()) {
263 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW, 275 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::USER_MANAGER_VIEW,
264 KeepAliveRestartOption::DISABLED)); 276 KeepAliveRestartOption::DISABLED));
265 } 277 }
266 278
267 UserManagerView::~UserManagerView() { 279 UserManagerView::~UserManagerView() {
268 HideReauthDialog(); 280 HideDialog();
269 } 281 }
270 282
271 // static 283 // static
272 void UserManagerView::OnSystemProfileCreated( 284 void UserManagerView::OnSystemProfileCreated(
273 std::unique_ptr<UserManagerView> instance, 285 std::unique_ptr<UserManagerView> instance,
274 base::AutoReset<bool>* pending, 286 base::AutoReset<bool>* pending,
275 Profile* system_profile, 287 Profile* system_profile,
276 const std::string& url) { 288 const std::string& url) {
277 // If we are showing the User Manager after locking a profile, change the 289 // If we are showing the User Manager after locking a profile, change the
278 // active profile to Guest. 290 // active profile to Guest.
279 profiles::SetActiveProfileToGuestIfLocked(); 291 profiles::SetActiveProfileToGuestIfLocked();
280 292
281 DCHECK(!instance_); 293 DCHECK(!instance_);
282 instance_ = instance.release(); // |instance_| takes over ownership. 294 instance_ = instance.release(); // |instance_| takes over ownership.
283 instance_->Init(system_profile, GURL(url)); 295 instance_->Init(system_profile, GURL(url));
284 } 296 }
285 297
286 void UserManagerView::ShowReauthDialog(content::BrowserContext* browser_context, 298 void UserManagerView::ShowDialog(content::BrowserContext* browser_context,
287 const std::string& email, 299 const std::string& email,
288 signin_metrics::Reason reason) { 300 const GURL& url) {
289 HideReauthDialog(); 301 HideDialog();
290 // The dialog delegate will be deleted when the widget closes. The created 302 // The dialog delegate will be deleted when the widget closes. The created
291 // WebView's lifetime is managed by the delegate. 303 // WebView's lifetime is managed by the delegate.
292 delegate_ = new ReauthDelegate(this, 304 delegate_ = new UserManagerProfileDialogDelegate(
293 new views::WebView(browser_context), 305 this, new views::WebView(browser_context), email, url);
294 email,
295 reason);
296 gfx::NativeView parent = instance_->GetWidget()->GetNativeView(); 306 gfx::NativeView parent = instance_->GetWidget()->GetNativeView();
297 views::DialogDelegate::CreateDialogWidget(delegate_, nullptr, parent); 307 views::DialogDelegate::CreateDialogWidget(delegate_, nullptr, parent);
298 delegate_->GetWidget()->Show(); 308 delegate_->GetWidget()->Show();
299 } 309 }
300 310
301 void UserManagerView::HideReauthDialog() { 311 void UserManagerView::HideDialog() {
302 if (delegate_) { 312 if (delegate_) {
303 delegate_->CloseReauthDialog(); 313 delegate_->CloseDialog();
304 DCHECK(!delegate_); 314 DCHECK(!delegate_);
305 } 315 }
306 } 316 }
307 317
308 void UserManagerView::OnReauthDialogDestroyed() { 318 void UserManagerView::OnDialogDestroyed() {
309 delegate_ = nullptr; 319 delegate_ = nullptr;
310 } 320 }
311 321
312 void UserManagerView::Init(Profile* system_profile, const GURL& url) { 322 void UserManagerView::Init(Profile* system_profile, const GURL& url) {
313 web_view_ = new views::WebView(system_profile); 323 web_view_ = new views::WebView(system_profile);
314 web_view_->set_allow_accelerators(true); 324 web_view_->set_allow_accelerators(true);
315 AddChildView(web_view_); 325 AddChildView(web_view_);
316 SetLayoutManager(new views::FillLayout); 326 SetLayoutManager(new views::FillLayout);
317 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); 327 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN));
318 AddAccelerator(ui::Accelerator(ui::VKEY_F4, ui::EF_ALT_DOWN)); 328 AddAccelerator(ui::Accelerator(ui::VKEY_F4, ui::EF_ALT_DOWN));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 delegate_->DisplayErrorMessage(); 448 delegate_->DisplayErrorMessage();
439 } 449 }
440 450
441 void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) { 451 void UserManagerView::SetSigninProfilePath(const base::FilePath& profile_path) {
442 signin_profile_path_ = profile_path; 452 signin_profile_path_ = profile_path;
443 } 453 }
444 454
445 base::FilePath UserManagerView::GetSigninProfilePath() { 455 base::FilePath UserManagerView::GetSigninProfilePath() {
446 return signin_profile_path_; 456 return signin_profile_path_;
447 } 457 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/user_manager_view.h ('k') | chrome/browser/ui/webui/profile_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698