Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/profiles/profile_metrics.h" | 14 #include "chrome/browser/profiles/profile_metrics.h" |
| 15 #include "chrome/browser/profiles/profiles_state.h" | 15 #include "chrome/browser/profiles/profiles_state.h" |
| 16 #include "chrome/browser/signin/signin_promo.h" | 16 #include "chrome/browser/signin/signin_promo.h" |
| 17 #include "chrome/browser/ui/browser_dialogs.h" | 17 #include "chrome/browser/ui/browser_dialogs.h" |
| 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 19 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 19 #include "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" | 20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" |
| 21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" | 21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" |
| 22 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 22 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
| 23 #include "chrome/browser/ui/user_manager.h" | 23 #include "chrome/browser/ui/user_manager.h" |
| 24 #include "chrome/common/url_constants.h" | |
| 24 #include "chrome/grit/chromium_strings.h" | 25 #include "chrome/grit/chromium_strings.h" |
| 25 #include "components/signin/core/common/profile_management_switches.h" | 26 #include "components/signin/core/common/profile_management_switches.h" |
| 26 #include "components/web_modal/web_contents_modal_dialog_host.h" | 27 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 27 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 28 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 28 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 29 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 29 #include "content/public/browser/native_web_keyboard_event.h" | 30 #include "content/public/browser/native_web_keyboard_event.h" |
| 30 #include "content/public/browser/render_widget_host_view.h" | 31 #include "content/public/browser/render_widget_host_view.h" |
| 31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/browser/web_contents_delegate.h" | 33 #include "content/public/browser/web_contents_delegate.h" |
| 33 #include "ui/base/l10n/l10n_util_mac.h" | 34 #include "ui/base/l10n/l10n_util_mac.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 44 AppController* controller = | 45 AppController* controller = |
| 45 base::mac::ObjCCast<AppController>([NSApp delegate]); | 46 base::mac::ObjCCast<AppController>([NSApp delegate]); |
| 46 [controller windowChangedToProfile:profile]; | 47 [controller windowChangedToProfile:profile]; |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 } // namespace | 51 } // namespace |
| 51 | 52 |
| 52 // An open User Manager window. There can only be one open at a time. This | 53 // An open User Manager window. There can only be one open at a time. This |
| 53 // is reset to NULL when the window is closed. | 54 // is reset to NULL when the window is closed. |
| 54 UserManagerMac* instance_ = nullptr; // Weak. | 55 UserManagerMac* instance_ = nullptr; // Weak. |
|
tapted
2016/10/17 05:28:20
eep! This was very confusing - these are not insta
| |
| 55 std::vector<base::Closure>* user_manager_shown_callbacks_for_testing_ = nullptr; | 56 std::vector<base::Closure>* user_manager_shown_callbacks_for_testing_ = nullptr; |
| 56 BOOL instance_under_construction_ = NO; | 57 BOOL instance_under_construction_ = NO; |
| 57 | 58 |
| 58 void CloseInstanceReauthDialog() { | 59 void CloseInstanceReauthDialog() { |
| 59 DCHECK(instance_); | 60 DCHECK(instance_); |
| 60 instance_->CloseReauthDialog(); | 61 instance_->CloseReauthDialog(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // The modal dialog host the User Manager uses to display the reauth dialog. | 64 // The modal dialog host the User Manager uses to display the reauth dialog. |
| 64 class UserManagerModalHost : public web_modal::WebContentsModalDialogHost { | 65 class UserManagerModalHost : public web_modal::WebContentsModalDialogHost { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 content::WebContents* source, | 159 content::WebContents* source, |
| 159 const content::NativeWebKeyboardEvent& event) override { | 160 const content::NativeWebKeyboardEvent& event) override { |
| 160 hotKeysWebContentsDelegate_->HandleKeyboardEvent(source, event); | 161 hotKeysWebContentsDelegate_->HandleKeyboardEvent(source, event); |
| 161 } | 162 } |
| 162 | 163 |
| 163 // ConstrainedWindowMacDelegate: | 164 // ConstrainedWindowMacDelegate: |
| 164 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { | 165 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { |
| 165 CloseReauthDialog(); | 166 CloseReauthDialog(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 private: | 169 private: |
| 169 std::unique_ptr<UserManagerWebContentsDelegate> hotKeysWebContentsDelegate_; | 170 std::unique_ptr<UserManagerWebContentsDelegate> hotKeysWebContentsDelegate_; |
| 170 | 171 |
| 171 DISALLOW_COPY_AND_ASSIGN(ReauthDialogDelegate); | 172 DISALLOW_COPY_AND_ASSIGN(ReauthDialogDelegate); |
| 172 }; | 173 }; |
| 173 | 174 |
| 174 // WindowController for the reauth dialog. | 175 // WindowController for the reauth dialog. |
| 175 @interface ReauthDialogWindowController | 176 @interface ReauthDialogWindowController |
| 176 : NSWindowController <NSWindowDelegate> { | 177 : NSWindowController <NSWindowDelegate> { |
| 177 @private | 178 @private |
| 178 std::string emailAddress_; | 179 std::string emailAddress_; |
| 179 content::WebContents* webContents_; | 180 content::WebContents* webContents_; |
| 180 signin_metrics::Reason reason_; | 181 signin_metrics::Reason reason_; |
| 181 std::unique_ptr<ReauthDialogDelegate> webContentsDelegate_; | 182 std::unique_ptr<ReauthDialogDelegate> webContentsDelegate_; |
| 182 std::unique_ptr<ConstrainedWindowMac> constrained_window_; | 183 std::unique_ptr<ConstrainedWindowMac> constrained_window_; |
| 183 std::unique_ptr<content::WebContents> reauthWebContents_; | 184 std::unique_ptr<content::WebContents> reauthWebContents_; |
| 184 } | 185 } |
| 185 - (id)initWithProfile:(Profile*)profile | 186 - (id)initWithProfile:(Profile*)profile |
| 186 email:(std::string)email | 187 email:(std::string)email |
| 187 reason:(signin_metrics::Reason)reason | 188 reason:(signin_metrics::Reason)reason |
| 188 webContents:(content::WebContents*)webContents; | 189 webContents:(content::WebContents*)webContents; |
| 190 - (void)showURL:(const GURL&)url; | |
| 189 - (void)close; | 191 - (void)close; |
| 190 @end | 192 @end |
| 191 | 193 |
| 192 @implementation ReauthDialogWindowController | 194 @implementation ReauthDialogWindowController |
| 193 | 195 |
| 194 - (id)initWithProfile:(Profile*)profile | 196 - (id)initWithProfile:(Profile*)profile |
| 195 email:(std::string)email | 197 email:(std::string)email |
| 196 reason:(signin_metrics::Reason)reason | 198 reason:(signin_metrics::Reason)reason |
| 197 webContents:(content::WebContents*)webContents { | 199 webContents:(content::WebContents*)webContents { |
| 198 webContents_ = webContents; | 200 webContents_ = webContents; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 226 // it in the title bar and change its action. | 228 // it in the title bar and change its action. |
| 227 auto closeButton = [window standardWindowButton:NSWindowCloseButton]; | 229 auto closeButton = [window standardWindowButton:NSWindowCloseButton]; |
| 228 [closeButton setTarget:self]; | 230 [closeButton setTarget:self]; |
| 229 [closeButton setAction:@selector(closeButtonClicked:)]; | 231 [closeButton setAction:@selector(closeButtonClicked:)]; |
| 230 [self show]; | 232 [self show]; |
| 231 } | 233 } |
| 232 | 234 |
| 233 return self; | 235 return self; |
| 234 } | 236 } |
| 235 | 237 |
| 238 - (void)showURL:(const GURL&)url { | |
| 239 reauthWebContents_->GetController().LoadURL(url, content::Referrer(), | |
| 240 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 241 std::string()); | |
| 242 } | |
| 243 | |
| 236 - (void)show { | 244 - (void)show { |
| 237 GURL url = signin::GetReauthURLWithEmail( | 245 GURL url = signin::GetReauthURLWithEmail( |
| 238 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason_, | 246 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason_, |
| 239 emailAddress_); | 247 emailAddress_); |
| 240 reauthWebContents_->GetController().LoadURL(url, content::Referrer(), | 248 [self showURL:url]; |
| 241 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 242 std::string()); | |
| 243 } | 249 } |
| 244 | 250 |
| 245 - (void)closeButtonClicked:(NSButton*)button { | 251 - (void)closeButtonClicked:(NSButton*)button { |
| 246 [self close]; | 252 [self close]; |
| 247 } | 253 } |
| 248 | 254 |
| 249 - (void)close { | 255 - (void)close { |
| 250 constrained_window_->CloseWebContentsModalDialog(); | 256 constrained_window_->CloseWebContentsModalDialog(); |
| 251 } | 257 } |
| 252 | 258 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 271 - (void)dealloc; | 277 - (void)dealloc; |
| 272 - (id)initWithProfile:(Profile*)profile | 278 - (id)initWithProfile:(Profile*)profile |
| 273 withObserver:(UserManagerMac*)userManagerObserver; | 279 withObserver:(UserManagerMac*)userManagerObserver; |
| 274 - (void)showURL:(const GURL&)url; | 280 - (void)showURL:(const GURL&)url; |
| 275 - (void)show; | 281 - (void)show; |
| 276 - (void)close; | 282 - (void)close; |
| 277 - (BOOL)isVisible; | 283 - (BOOL)isVisible; |
| 278 - (void)showReauthDialogWithProfile:(Profile*)profile | 284 - (void)showReauthDialogWithProfile:(Profile*)profile |
| 279 email:(std::string)email | 285 email:(std::string)email |
| 280 reason:(signin_metrics::Reason)reason; | 286 reason:(signin_metrics::Reason)reason; |
| 287 - (void)displayErrorMessage; | |
| 281 - (void)closeReauthDialog; | 288 - (void)closeReauthDialog; |
| 282 @end | 289 @end |
| 283 | 290 |
| 284 @implementation UserManagerWindowController | 291 @implementation UserManagerWindowController |
| 285 | 292 |
| 286 - (id)initWithProfile:(Profile*)profile | 293 - (id)initWithProfile:(Profile*)profile |
| 287 withObserver:(UserManagerMac*)userManagerObserver { | 294 withObserver:(UserManagerMac*)userManagerObserver { |
| 288 // Center the window on the screen that currently has focus. | 295 // Center the window on the screen that currently has focus. |
| 289 NSScreen* mainScreen = [NSScreen mainScreen]; | 296 NSScreen* mainScreen = [NSScreen mainScreen]; |
| 290 CGFloat screenHeight = [mainScreen frame].size.height; | 297 CGFloat screenHeight = [mainScreen frame].size.height; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 - (void)showReauthDialogWithProfile:(Profile*)profile | 393 - (void)showReauthDialogWithProfile:(Profile*)profile |
| 387 email:(std::string)email | 394 email:(std::string)email |
| 388 reason:(signin_metrics::Reason)reason { | 395 reason:(signin_metrics::Reason)reason { |
| 389 reauth_window_controller_.reset([[ReauthDialogWindowController alloc] | 396 reauth_window_controller_.reset([[ReauthDialogWindowController alloc] |
| 390 initWithProfile:profile | 397 initWithProfile:profile |
| 391 email:email | 398 email:email |
| 392 reason:reason | 399 reason:reason |
| 393 webContents:webContents_.get()]); | 400 webContents:webContents_.get()]); |
| 394 } | 401 } |
| 395 | 402 |
| 403 - (void)displayErrorMessage { | |
| 404 [reauth_window_controller_ showURL:GURL(chrome::kChromeUISigninErrorURL)]; | |
| 405 } | |
| 406 | |
| 396 - (void)closeReauthDialog { | 407 - (void)closeReauthDialog { |
| 397 [reauth_window_controller_ close]; | 408 [reauth_window_controller_ close]; |
| 398 } | 409 } |
| 399 | 410 |
| 400 @end | 411 @end |
| 401 | 412 |
| 402 | 413 |
| 403 // static | 414 // static |
| 404 void UserManager::Show( | 415 void UserManager::Show( |
| 405 const base::FilePath& profile_path_to_focus, | 416 const base::FilePath& profile_path_to_focus, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 } | 491 } |
| 481 | 492 |
| 482 // static | 493 // static |
| 483 void UserManager::AddOnUserManagerShownCallbackForTesting( | 494 void UserManager::AddOnUserManagerShownCallbackForTesting( |
| 484 const base::Closure& callback) { | 495 const base::Closure& callback) { |
| 485 if (!user_manager_shown_callbacks_for_testing_) | 496 if (!user_manager_shown_callbacks_for_testing_) |
| 486 user_manager_shown_callbacks_for_testing_ = new std::vector<base::Closure>; | 497 user_manager_shown_callbacks_for_testing_ = new std::vector<base::Closure>; |
| 487 user_manager_shown_callbacks_for_testing_->push_back(callback); | 498 user_manager_shown_callbacks_for_testing_->push_back(callback); |
| 488 } | 499 } |
| 489 | 500 |
| 501 // static | |
| 502 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, | |
|
tapted
2016/10/17 05:28:20
It's a bit sad that these look identical to the im
| |
| 503 const base::FilePath& profile_path) { | |
| 504 if (!IsShowing()) | |
| 505 return; | |
| 506 instance_->SetSigninProfilePath(profile_path); | |
| 507 ShowReauthDialog(browser_context, std::string(), | |
| 508 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT); | |
| 509 } | |
| 510 | |
| 511 // static | |
| 512 void UserManager::DisplayErrorMessage() { | |
| 513 DCHECK(instance_); | |
| 514 instance_->DisplayErrorMessage(); | |
| 515 } | |
| 516 | |
| 517 // static | |
| 518 base::FilePath UserManager::GetSigninProfilePath() { | |
| 519 return instance_->GetSigninProfilePath(); | |
| 520 } | |
| 521 | |
| 490 void UserManagerMac::ShowReauthDialog(content::BrowserContext* browser_context, | 522 void UserManagerMac::ShowReauthDialog(content::BrowserContext* browser_context, |
| 491 const std::string& email, | 523 const std::string& email, |
| 492 signin_metrics::Reason reason) { | 524 signin_metrics::Reason reason) { |
| 493 [window_controller_ | 525 [window_controller_ |
| 494 showReauthDialogWithProfile:Profile::FromBrowserContext(browser_context) | 526 showReauthDialogWithProfile:Profile::FromBrowserContext(browser_context) |
| 495 email:email | 527 email:email |
| 496 reason:reason]; | 528 reason:reason]; |
| 497 } | 529 } |
| 498 | 530 |
| 499 void UserManagerMac::CloseReauthDialog() { | 531 void UserManagerMac::CloseReauthDialog() { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 526 ProfileMetrics::LogTimeToOpenUserManager( | 558 ProfileMetrics::LogTimeToOpenUserManager( |
| 527 base::Time::Now() - user_manager_started_showing_); | 559 base::Time::Now() - user_manager_started_showing_); |
| 528 user_manager_started_showing_ = base::Time(); | 560 user_manager_started_showing_ = base::Time(); |
| 529 } | 561 } |
| 530 | 562 |
| 531 void UserManagerMac::WindowWasClosed() { | 563 void UserManagerMac::WindowWasClosed() { |
| 532 CloseReauthDialog(); | 564 CloseReauthDialog(); |
| 533 instance_ = NULL; | 565 instance_ = NULL; |
| 534 delete this; | 566 delete this; |
| 535 } | 567 } |
| 568 | |
| 569 void UserManagerMac::DisplayErrorMessage() { | |
| 570 [window_controller_ displayErrorMessage]; | |
| 571 } | |
| 572 | |
| 573 void UserManagerMac::SetSigninProfilePath(const base::FilePath& profile_path) { | |
| 574 signin_profile_path_ = profile_path; | |
| 575 } | |
| 576 | |
| 577 base::FilePath UserManagerMac::GetSigninProfilePath() { | |
| 578 return signin_profile_path_; | |
| 579 } | |
| OLD | NEW |