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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/user_manager_mac.mm

Issue 2552473002: Display error message when user try to open a locked supervised user profile when force-sign-in is … (Closed)
Patch Set: refactor 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/cocoa/profiles/user_manager_mac.h" 5 #include "chrome/browser/ui/cocoa/profiles/user_manager_mac.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #import "chrome/browser/app_controller_mac.h" 10 #import "chrome/browser/app_controller_mac.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
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 UserManagerMac* instance_ = nullptr; // Weak. 53 UserManagerMac* instance_ = nullptr; // Weak.
54 std::vector<base::Closure>* user_manager_shown_callbacks_for_testing_ = nullptr; 54 std::vector<base::Closure>* user_manager_shown_callbacks_for_testing_ = nullptr;
55 BOOL instance_under_construction_ = NO; 55 BOOL instance_under_construction_ = NO;
56 56
57 void CloseInstanceReauthDialog() { 57 void CloseInstanceReauthDialog() {
58 DCHECK(instance_); 58 DCHECK(instance_);
59 instance_->CloseReauthDialog(); 59 instance_->CloseDialog();
60 } 60 }
61 61
62 // The modal dialog host the User Manager uses to display the reauth dialog. 62 // The modal dialog host the User Manager uses to display the reauth dialog.
63 class UserManagerModalHost : public web_modal::WebContentsModalDialogHost { 63 class UserManagerModalHost : public web_modal::WebContentsModalDialogHost {
64 public: 64 public:
65 UserManagerModalHost(gfx::NativeView host_view) 65 UserManagerModalHost(gfx::NativeView host_view)
66 : host_view_(host_view) {} 66 : host_view_(host_view) {}
67 67
68 gfx::Size GetMaximumDialogSize() override { 68 gfx::Size GetMaximumDialogSize() override {
69 return switches::UsePasswordSeparatedSigninFlow() ? 69 return switches::UsePasswordSeparatedSigninFlow() ?
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 DISALLOW_COPY_AND_ASSIGN(ReauthDialogDelegate); 170 DISALLOW_COPY_AND_ASSIGN(ReauthDialogDelegate);
171 }; 171 };
172 172
173 } // namespace 173 } // namespace
174 174
175 // WindowController for the reauth dialog. 175 // WindowController for the reauth dialog.
176 @interface ReauthDialogWindowController 176 @interface ReauthDialogWindowController
177 : NSWindowController <NSWindowDelegate> { 177 : NSWindowController <NSWindowDelegate> {
178 @private 178 @private
179 std::string emailAddress_; 179 std::string emailAddress_;
180 GURL url_;
180 content::WebContents* webContents_; 181 content::WebContents* webContents_;
181 signin_metrics::Reason reason_;
182 std::unique_ptr<ReauthDialogDelegate> webContentsDelegate_; 182 std::unique_ptr<ReauthDialogDelegate> webContentsDelegate_;
183 std::unique_ptr<ConstrainedWindowMac> constrained_window_; 183 std::unique_ptr<ConstrainedWindowMac> constrained_window_;
184 std::unique_ptr<content::WebContents> reauthWebContents_; 184 std::unique_ptr<content::WebContents> reauthWebContents_;
185 } 185 }
186 - (id)initWithProfile:(Profile*)profile 186 - (id)initWithProfile:(Profile*)profile
187 email:(std::string)email 187 email:(std::string)email
188 reason:(signin_metrics::Reason)reason 188 url:(GURL)url
189 webContents:(content::WebContents*)webContents; 189 webContents:(content::WebContents*)webContents;
190 - (void)showURL:(const GURL&)url; 190 - (void)showURL:(const GURL&)url;
191 - (void)close; 191 - (void)close;
192 @end 192 @end
193 193
194 @implementation ReauthDialogWindowController 194 @implementation ReauthDialogWindowController
195 195
196 - (id)initWithProfile:(Profile*)profile 196 - (id)initWithProfile:(Profile*)profile
197 email:(std::string)email 197 email:(std::string)email
198 reason:(signin_metrics::Reason)reason 198 url:(GURL)url
199 webContents:(content::WebContents*)webContents { 199 webContents:(content::WebContents*)webContents {
200 webContents_ = webContents; 200 webContents_ = webContents;
201 emailAddress_ = email; 201 emailAddress_ = email;
202 reason_ = reason; 202 url_ = url;
203 203
204 NSRect frame = NSMakeRect( 204 NSRect frame = NSMakeRect(
205 0, 0, UserManager::kReauthDialogWidth, UserManager::kReauthDialogHeight); 205 0, 0, UserManager::kReauthDialogWidth, UserManager::kReauthDialogHeight);
206 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( 206 base::scoped_nsobject<ConstrainedWindowCustomWindow> window(
207 [[ConstrainedWindowCustomWindow alloc] 207 [[ConstrainedWindowCustomWindow alloc]
208 initWithContentRect:frame 208 initWithContentRect:frame
209 styleMask:NSTitledWindowMask | NSClosableWindowMask]); 209 styleMask:NSTitledWindowMask | NSClosableWindowMask]);
210 if ((self = [super initWithWindow:window])) { 210 if ((self = [super initWithWindow:window])) {
211 webContents_ = webContents; 211 webContents_ = webContents;
212 212
(...skipping 22 matching lines...) Expand all
235 return self; 235 return self;
236 } 236 }
237 237
238 - (void)showURL:(const GURL&)url { 238 - (void)showURL:(const GURL&)url {
239 reauthWebContents_->GetController().LoadURL(url, content::Referrer(), 239 reauthWebContents_->GetController().LoadURL(url, content::Referrer(),
240 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 240 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
241 std::string()); 241 std::string());
242 } 242 }
243 243
244 - (void)show { 244 - (void)show {
245 GURL url = signin::GetReauthURLWithEmail( 245 [self showURL:url_];
246 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason_,
247 emailAddress_);
248 [self showURL:url];
249 } 246 }
250 247
251 - (void)closeButtonClicked:(NSButton*)button { 248 - (void)closeButtonClicked:(NSButton*)button {
252 [self close]; 249 [self close];
253 } 250 }
254 251
255 - (void)close { 252 - (void)close {
256 constrained_window_->CloseWebContentsModalDialog(); 253 constrained_window_->CloseWebContentsModalDialog();
257 } 254 }
258 255
(...skipping 15 matching lines...) Expand all
274 base::scoped_nsobject<ReauthDialogWindowController> reauth_window_controller_; 271 base::scoped_nsobject<ReauthDialogWindowController> reauth_window_controller_;
275 } 272 }
276 - (void)windowWillClose:(NSNotification*)notification; 273 - (void)windowWillClose:(NSNotification*)notification;
277 - (void)dealloc; 274 - (void)dealloc;
278 - (id)initWithProfile:(Profile*)profile 275 - (id)initWithProfile:(Profile*)profile
279 withObserver:(UserManagerMac*)userManagerObserver; 276 withObserver:(UserManagerMac*)userManagerObserver;
280 - (void)showURL:(const GURL&)url; 277 - (void)showURL:(const GURL&)url;
281 - (void)show; 278 - (void)show;
282 - (void)close; 279 - (void)close;
283 - (BOOL)isVisible; 280 - (BOOL)isVisible;
284 - (void)showReauthDialogWithProfile:(Profile*)profile 281 - (void)showDialogWithProfile:(Profile*)profile
285 email:(std::string)email 282 email:(std::string)email
286 reason:(signin_metrics::Reason)reason; 283 url:(GURL)url;
287 - (void)displayErrorMessage; 284 - (void)displayErrorMessage;
288 - (void)closeReauthDialog; 285 - (void)closeDialog;
289 @end 286 @end
290 287
291 @implementation UserManagerWindowController 288 @implementation UserManagerWindowController
292 289
293 - (id)initWithProfile:(Profile*)profile 290 - (id)initWithProfile:(Profile*)profile
294 withObserver:(UserManagerMac*)userManagerObserver { 291 withObserver:(UserManagerMac*)userManagerObserver {
295 // Center the window on the screen that currently has focus. 292 // Center the window on the screen that currently has focus.
296 NSScreen* mainScreen = [NSScreen mainScreen]; 293 NSScreen* mainScreen = [NSScreen mainScreen];
297 CGFloat screenHeight = [mainScreen frame].size.height; 294 CGFloat screenHeight = [mainScreen frame].size.height;
298 CGFloat screenWidth = [mainScreen frame].size.width; 295 CGFloat screenWidth = [mainScreen frame].size.width;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 -(BOOL)isVisible { 380 -(BOOL)isVisible {
384 return [[self window] isVisible]; 381 return [[self window] isVisible];
385 } 382 }
386 383
387 - (void)windowWillClose:(NSNotification*)notification { 384 - (void)windowWillClose:(NSNotification*)notification {
388 [[NSNotificationCenter defaultCenter] removeObserver:self]; 385 [[NSNotificationCenter defaultCenter] removeObserver:self];
389 DCHECK(userManagerObserver_); 386 DCHECK(userManagerObserver_);
390 userManagerObserver_->WindowWasClosed(); 387 userManagerObserver_->WindowWasClosed();
391 } 388 }
392 389
393 - (void)showReauthDialogWithProfile:(Profile*)profile 390 - (void)showDialogWithProfile:(Profile*)profile
394 email:(std::string)email 391 email:(std::string)email
395 reason:(signin_metrics::Reason)reason { 392 url:(GURL)url {
396 reauth_window_controller_.reset([[ReauthDialogWindowController alloc] 393 reauth_window_controller_.reset([[ReauthDialogWindowController alloc]
397 initWithProfile:profile 394 initWithProfile:profile
398 email:email 395 email:email
399 reason:reason 396 url:url
400 webContents:webContents_.get()]); 397 webContents:webContents_.get()]);
401 } 398 }
402 399
403 - (void)displayErrorMessage { 400 - (void)displayErrorMessage {
404 [reauth_window_controller_ showURL:GURL(chrome::kChromeUISigninErrorURL)]; 401 [reauth_window_controller_ showURL:GURL(chrome::kChromeUISigninErrorURL)];
405 } 402 }
406 403
407 - (void)closeReauthDialog { 404 - (void)closeDialog {
408 [reauth_window_controller_ close]; 405 [reauth_window_controller_ close];
409 } 406 }
410 407
411 @end 408 @end
412 409
413 410
414 // static 411 // static
415 void UserManager::Show( 412 void UserManager::Show(
416 const base::FilePath& profile_path_to_focus, 413 const base::FilePath& profile_path_to_focus,
417 profiles::UserManagerTutorialMode tutorial_mode, 414 profiles::UserManagerTutorialMode tutorial_mode,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 467 }
471 } 468 }
472 469
473 // static 470 // static
474 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, 471 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context,
475 const std::string& email, 472 const std::string& email,
476 signin_metrics::Reason reason) { 473 signin_metrics::Reason reason) {
477 // This method should only be called if the user manager is already showing. 474 // This method should only be called if the user manager is already showing.
478 if (!IsShowing()) 475 if (!IsShowing())
479 return; 476 return;
477 GURL url = signin::GetReauthURLWithEmail(
478 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, email);
479 instance_->ShowDialog(browser_context, email, url);
480 }
481
482 // static
483 void UserManager::HideDialog() {
484 // This method should only be called if the user manager is already showing.
485 if (!IsShowing())
486 return;
480 487
481 instance_->ShowReauthDialog(browser_context, email, reason); 488 instance_->CloseDialog();
482 } 489 }
483 490
484 // static 491 // static
485 void UserManager::HideReauthDialog() {
486 // This method should only be called if the user manager is already showing.
487 if (!IsShowing())
488 return;
489
490 instance_->CloseReauthDialog();
491 }
492
493 // static
494 void UserManager::AddOnUserManagerShownCallbackForTesting( 492 void UserManager::AddOnUserManagerShownCallbackForTesting(
495 const base::Closure& callback) { 493 const base::Closure& callback) {
496 if (!user_manager_shown_callbacks_for_testing_) 494 if (!user_manager_shown_callbacks_for_testing_)
497 user_manager_shown_callbacks_for_testing_ = new std::vector<base::Closure>; 495 user_manager_shown_callbacks_for_testing_ = new std::vector<base::Closure>;
498 user_manager_shown_callbacks_for_testing_->push_back(callback); 496 user_manager_shown_callbacks_for_testing_->push_back(callback);
499 } 497 }
500 498
501 // static 499 // static
502 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, 500 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context,
503 const base::FilePath& profile_path) { 501 const base::FilePath& profile_path) {
504 if (!IsShowing()) 502 if (!IsShowing())
505 return; 503 return;
506 instance_->SetSigninProfilePath(profile_path); 504 instance_->SetSigninProfilePath(profile_path);
507 ShowReauthDialog(browser_context, std::string(), 505 GURL url = signin::GetPromoURL(
508 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT); 506 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER,
507 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, true, true);
508 instance_->ShowDialog(browser_context, std::string(), url);
509 } 509 }
510 510
511 // static 511 // static
512 void UserManager::DisplayErrorMessage() { 512 void UserManager::DisplayErrorMessage() {
513 DCHECK(instance_); 513 DCHECK(instance_);
514 instance_->DisplayErrorMessage(); 514 instance_->DisplayErrorMessage();
515 } 515 }
516 516
517 // static 517 // static
518 void UserManager::ShowDialogAndDisplayErrorMessage(
519 content::BrowserContext* browser_context) {
520 DCHECK(instance_);
521 instance_->ShowDialog(browser_context, std::string(),
522 GURL(chrome::kChromeUISigninErrorURL));
523 }
524
525 // static
518 base::FilePath UserManager::GetSigninProfilePath() { 526 base::FilePath UserManager::GetSigninProfilePath() {
519 return instance_->GetSigninProfilePath(); 527 return instance_->GetSigninProfilePath();
520 } 528 }
521 529
522 void UserManagerMac::ShowReauthDialog(content::BrowserContext* browser_context, 530 void UserManagerMac::ShowDialog(content::BrowserContext* browser_context,
523 const std::string& email, 531 const std::string& email,
524 signin_metrics::Reason reason) { 532 const GURL& url) {
525 [window_controller_ 533 [window_controller_
526 showReauthDialogWithProfile:Profile::FromBrowserContext(browser_context) 534 showDialogWithProfile:Profile::FromBrowserContext(browser_context)
527 email:email 535 email:email
528 reason:reason]; 536 url:url];
529 } 537 }
530 538
531 void UserManagerMac::CloseReauthDialog() { 539 void UserManagerMac::CloseDialog() {
532 [window_controller_ closeReauthDialog]; 540 [window_controller_ closeDialog];
533 } 541 }
534 542
535 UserManagerMac::UserManagerMac(Profile* profile) { 543 UserManagerMac::UserManagerMac(Profile* profile) {
536 window_controller_.reset([[UserManagerWindowController alloc] 544 window_controller_.reset([[UserManagerWindowController alloc]
537 initWithProfile:profile withObserver:this]); 545 initWithProfile:profile withObserver:this]);
538 } 546 }
539 547
540 UserManagerMac::~UserManagerMac() { 548 UserManagerMac::~UserManagerMac() {
541 } 549 }
542 550
(...skipping 11 matching lines...) Expand all
554 void UserManagerMac::LogTimeToOpen() { 562 void UserManagerMac::LogTimeToOpen() {
555 if (user_manager_started_showing_ == base::Time()) 563 if (user_manager_started_showing_ == base::Time())
556 return; 564 return;
557 565
558 ProfileMetrics::LogTimeToOpenUserManager( 566 ProfileMetrics::LogTimeToOpenUserManager(
559 base::Time::Now() - user_manager_started_showing_); 567 base::Time::Now() - user_manager_started_showing_);
560 user_manager_started_showing_ = base::Time(); 568 user_manager_started_showing_ = base::Time();
561 } 569 }
562 570
563 void UserManagerMac::WindowWasClosed() { 571 void UserManagerMac::WindowWasClosed() {
564 CloseReauthDialog(); 572 CloseDialog();
565 instance_ = NULL; 573 instance_ = NULL;
566 delete this; 574 delete this;
567 } 575 }
568 576
569 void UserManagerMac::DisplayErrorMessage() { 577 void UserManagerMac::DisplayErrorMessage() {
570 [window_controller_ displayErrorMessage]; 578 [window_controller_ displayErrorMessage];
571 } 579 }
572 580
573 void UserManagerMac::SetSigninProfilePath(const base::FilePath& profile_path) { 581 void UserManagerMac::SetSigninProfilePath(const base::FilePath& profile_path) {
574 signin_profile_path_ = profile_path; 582 signin_profile_path_ = profile_path;
575 } 583 }
576 584
577 base::FilePath UserManagerMac::GetSigninProfilePath() { 585 base::FilePath UserManagerMac::GetSigninProfilePath() {
578 return signin_profile_path_; 586 return signin_profile_path_;
579 } 587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698