| 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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 [controller windowChangedToProfile:profile]; | 47 [controller windowChangedToProfile:profile]; |
| 48 } | 48 } |
| 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 CloseInstanceDialog() { |
| 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 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() |
| 70 gfx::Size(UserManager::kReauthDialogWidth, | 70 ? gfx::Size(UserManagerProfileDialog::kDialogWidth, |
| 71 UserManager::kReauthDialogHeight) : | 71 UserManagerProfileDialog::kDialogHeight) |
| 72 gfx::Size(UserManager::kPasswordCombinedReauthDialogWidth, | 72 : gfx::Size( |
| 73 UserManager::kPasswordCombinedReauthDialogHeight); | 73 UserManagerProfileDialog::kPasswordCombinedDialogWidth, |
| 74 UserManagerProfileDialog::kPasswordCombinedDialogHeight); |
| 74 } | 75 } |
| 75 | 76 |
| 76 ~UserManagerModalHost() override {} | 77 ~UserManagerModalHost() override {} |
| 77 | 78 |
| 78 gfx::NativeView GetHostView() const override { | 79 gfx::NativeView GetHostView() const override { |
| 79 return host_view_; | 80 return host_view_; |
| 80 } | 81 } |
| 81 | 82 |
| 82 gfx::Point GetDialogPosition(const gfx::Size& size) override { | 83 gfx::Point GetDialogPosition(const gfx::Size& size) override { |
| 83 return gfx::Point(0, 0); | 84 return gfx::Point(0, 0); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void AddObserver(web_modal::ModalDialogHostObserver* observer) override {} | 87 void AddObserver(web_modal::ModalDialogHostObserver* observer) override {} |
| 87 void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override {} | 88 void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override {} |
| 88 | 89 |
| 89 private: | 90 private: |
| 90 gfx::NativeView host_view_; | 91 gfx::NativeView host_view_; |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 // The modal manager delegate allowing the display of constrained windows for | 94 // The modal manager delegate allowing the display of constrained windows for |
| 94 // the reauth dialog. | 95 // the dialog. |
| 95 class UserManagerModalManagerDelegate : | 96 class UserManagerModalManagerDelegate : |
| 96 public web_modal::WebContentsModalDialogManagerDelegate { | 97 public web_modal::WebContentsModalDialogManagerDelegate { |
| 97 public: | 98 public: |
| 98 UserManagerModalManagerDelegate(gfx::NativeView host_view) { | 99 UserManagerModalManagerDelegate(gfx::NativeView host_view) { |
| 99 modal_host_.reset(new UserManagerModalHost(host_view)); | 100 modal_host_.reset(new UserManagerModalHost(host_view)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost() | 103 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost() |
| 103 override { | 104 override { |
| 104 return modal_host_.get(); | 105 return modal_host_.get(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 133 BOOL isTextEditingCommand = [BrowserWindowUtils isTextEditingEvent:event]; | 134 BOOL isTextEditingCommand = [BrowserWindowUtils isTextEditingEvent:event]; |
| 134 | 135 |
| 135 // Only handle close window Chrome accelerators and text editing ones. | 136 // Only handle close window Chrome accelerators and text editing ones. |
| 136 if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT || | 137 if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT || |
| 137 isTextEditingCommand) { | 138 isTextEditingCommand) { |
| 138 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | 139 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 }; | 142 }; |
| 142 | 143 |
| 143 class ReauthDialogDelegate : public UserManager::BaseReauthDialogDelegate, | 144 class UserManagerProfileDialogDelegate |
| 144 public ConstrainedWindowMacDelegate { | 145 : public UserManagerProfileDialog::BaseDialogDelegate, |
| 146 public ConstrainedWindowMacDelegate { |
| 145 public: | 147 public: |
| 146 ReauthDialogDelegate() { | 148 UserManagerProfileDialogDelegate() { |
| 147 hotKeysWebContentsDelegate_.reset(new UserManagerWebContentsDelegate()); | 149 hotKeysWebContentsDelegate_.reset(new UserManagerWebContentsDelegate()); |
| 148 } | 150 } |
| 149 | 151 |
| 150 // UserManager::BaseReauthDialogDelegate: | 152 // UserManagerProfileDialog::BaseDialogDelegate: |
| 151 void CloseReauthDialog() override { | 153 void CloseDialog() override { CloseInstanceDialog(); } |
| 152 CloseInstanceReauthDialog(); | |
| 153 } | |
| 154 | 154 |
| 155 // WebContentsDelegate::HandleKeyboardEvent: | 155 // WebContentsDelegate::HandleKeyboardEvent: |
| 156 void HandleKeyboardEvent( | 156 void HandleKeyboardEvent( |
| 157 content::WebContents* source, | 157 content::WebContents* source, |
| 158 const content::NativeWebKeyboardEvent& event) override { | 158 const content::NativeWebKeyboardEvent& event) override { |
| 159 hotKeysWebContentsDelegate_->HandleKeyboardEvent(source, event); | 159 hotKeysWebContentsDelegate_->HandleKeyboardEvent(source, event); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // ConstrainedWindowMacDelegate: | 162 // ConstrainedWindowMacDelegate: |
| 163 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { | 163 void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override { |
| 164 CloseReauthDialog(); | 164 CloseDialog(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 std::unique_ptr<UserManagerWebContentsDelegate> hotKeysWebContentsDelegate_; | 168 std::unique_ptr<UserManagerWebContentsDelegate> hotKeysWebContentsDelegate_; |
| 169 | 169 |
| 170 DISALLOW_COPY_AND_ASSIGN(ReauthDialogDelegate); | 170 DISALLOW_COPY_AND_ASSIGN(UserManagerProfileDialogDelegate); |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 } // namespace | 173 } // namespace |
| 174 | 174 |
| 175 // WindowController for the reauth dialog. | 175 // WindowController for the dialog. |
| 176 @interface ReauthDialogWindowController | 176 @interface DialogWindowController : NSWindowController<NSWindowDelegate> { |
| 177 : NSWindowController <NSWindowDelegate> { | |
| 178 @private | 177 @private |
| 179 std::string emailAddress_; | 178 std::string emailAddress_; |
| 179 GURL url_; |
| 180 content::WebContents* webContents_; | 180 content::WebContents* webContents_; |
| 181 signin_metrics::Reason reason_; | 181 std::unique_ptr<UserManagerProfileDialogDelegate> webContentsDelegate_; |
| 182 std::unique_ptr<ReauthDialogDelegate> webContentsDelegate_; | |
| 183 std::unique_ptr<ConstrainedWindowMac> constrained_window_; | 182 std::unique_ptr<ConstrainedWindowMac> constrained_window_; |
| 184 std::unique_ptr<content::WebContents> reauthWebContents_; | 183 std::unique_ptr<content::WebContents> dialogWebContents_; |
| 185 } | 184 } |
| 186 - (id)initWithProfile:(Profile*)profile | 185 - (id)initWithProfile:(Profile*)profile |
| 187 email:(std::string)email | 186 email:(std::string)email |
| 188 reason:(signin_metrics::Reason)reason | 187 url:(GURL)url |
| 189 webContents:(content::WebContents*)webContents; | 188 webContents:(content::WebContents*)webContents; |
| 190 - (void)showURL:(const GURL&)url; | 189 - (void)showURL:(const GURL&)url; |
| 191 - (void)close; | 190 - (void)close; |
| 192 @end | 191 @end |
| 193 | 192 |
| 194 @implementation ReauthDialogWindowController | 193 @implementation DialogWindowController |
| 195 | 194 |
| 196 - (id)initWithProfile:(Profile*)profile | 195 - (id)initWithProfile:(Profile*)profile |
| 197 email:(std::string)email | 196 email:(std::string)email |
| 198 reason:(signin_metrics::Reason)reason | 197 url:(GURL)url |
| 199 webContents:(content::WebContents*)webContents { | 198 webContents:(content::WebContents*)webContents { |
| 200 webContents_ = webContents; | 199 webContents_ = webContents; |
| 201 emailAddress_ = email; | 200 emailAddress_ = email; |
| 202 reason_ = reason; | 201 url_ = url; |
| 203 | 202 |
| 204 NSRect frame = NSMakeRect( | 203 NSRect frame = NSMakeRect(0, 0, UserManagerProfileDialog::kDialogWidth, |
| 205 0, 0, UserManager::kReauthDialogWidth, UserManager::kReauthDialogHeight); | 204 UserManagerProfileDialog::kDialogHeight); |
| 206 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( | 205 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( |
| 207 [[ConstrainedWindowCustomWindow alloc] | 206 [[ConstrainedWindowCustomWindow alloc] |
| 208 initWithContentRect:frame | 207 initWithContentRect:frame |
| 209 styleMask:NSTitledWindowMask | NSClosableWindowMask]); | 208 styleMask:NSTitledWindowMask | NSClosableWindowMask]); |
| 210 if ((self = [super initWithWindow:window])) { | 209 if ((self = [super initWithWindow:window])) { |
| 211 webContents_ = webContents; | 210 webContents_ = webContents; |
| 212 | 211 |
| 213 reauthWebContents_.reset(content::WebContents::Create( | 212 dialogWebContents_.reset(content::WebContents::Create( |
| 214 content::WebContents::CreateParams(profile))); | 213 content::WebContents::CreateParams(profile))); |
| 215 window.get().contentView = reauthWebContents_->GetNativeView(); | 214 window.get().contentView = dialogWebContents_->GetNativeView(); |
| 216 webContentsDelegate_.reset(new ReauthDialogDelegate()); | 215 webContentsDelegate_.reset(new UserManagerProfileDialogDelegate()); |
| 217 reauthWebContents_->SetDelegate(webContentsDelegate_.get()); | 216 dialogWebContents_->SetDelegate(webContentsDelegate_.get()); |
| 218 | 217 |
| 219 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 218 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| 220 [[CustomConstrainedWindowSheet alloc] | 219 [[CustomConstrainedWindowSheet alloc] |
| 221 initWithCustomWindow:[self window]]); | 220 initWithCustomWindow:[self window]]); |
| 222 constrained_window_ = | 221 constrained_window_ = |
| 223 CreateAndShowWebModalDialogMac( | 222 CreateAndShowWebModalDialogMac( |
| 224 webContentsDelegate_.get(), webContents_, sheet); | 223 webContentsDelegate_.get(), webContents_, sheet); |
| 225 | 224 |
| 226 // The close button needs to call CloseWebContentsModalDialog() on the | 225 // The close button needs to call CloseWebContentsModalDialog() on the |
| 227 // constrained window isntead of just [window close] so grab a reference to | 226 // constrained window isntead of just [window close] so grab a reference to |
| 228 // it in the title bar and change its action. | 227 // it in the title bar and change its action. |
| 229 auto closeButton = [window standardWindowButton:NSWindowCloseButton]; | 228 auto closeButton = [window standardWindowButton:NSWindowCloseButton]; |
| 230 [closeButton setTarget:self]; | 229 [closeButton setTarget:self]; |
| 231 [closeButton setAction:@selector(closeButtonClicked:)]; | 230 [closeButton setAction:@selector(closeButtonClicked:)]; |
| 232 [self show]; | 231 [self show]; |
| 233 } | 232 } |
| 234 | 233 |
| 235 return self; | 234 return self; |
| 236 } | 235 } |
| 237 | 236 |
| 238 - (void)showURL:(const GURL&)url { | 237 - (void)showURL:(const GURL&)url { |
| 239 reauthWebContents_->GetController().LoadURL(url, content::Referrer(), | 238 dialogWebContents_->GetController().LoadURL(url, content::Referrer(), |
| 240 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 239 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 241 std::string()); | 240 std::string()); |
| 242 } | 241 } |
| 243 | 242 |
| 244 - (void)show { | 243 - (void)show { |
| 245 GURL url = signin::GetReauthURLWithEmail( | 244 [self showURL:url_]; |
| 246 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason_, | |
| 247 emailAddress_); | |
| 248 [self showURL:url]; | |
| 249 } | 245 } |
| 250 | 246 |
| 251 - (void)closeButtonClicked:(NSButton*)button { | 247 - (void)closeButtonClicked:(NSButton*)button { |
| 252 [self close]; | 248 [self close]; |
| 253 } | 249 } |
| 254 | 250 |
| 255 - (void)close { | 251 - (void)close { |
| 256 constrained_window_->CloseWebContentsModalDialog(); | 252 constrained_window_->CloseWebContentsModalDialog(); |
| 257 } | 253 } |
| 258 | 254 |
| 259 - (void)dealloc { | 255 - (void)dealloc { |
| 260 constrained_window_->CloseWebContentsModalDialog(); | 256 constrained_window_->CloseWebContentsModalDialog(); |
| 261 | 257 |
| 262 [super dealloc]; | 258 [super dealloc]; |
| 263 } | 259 } |
| 264 | 260 |
| 265 @end | 261 @end |
| 266 | 262 |
| 267 // Window controller for the User Manager view. | 263 // Window controller for the User Manager view. |
| 268 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { | 264 @interface UserManagerWindowController : NSWindowController <NSWindowDelegate> { |
| 269 @private | 265 @private |
| 270 std::unique_ptr<content::WebContents> webContents_; | 266 std::unique_ptr<content::WebContents> webContents_; |
| 271 std::unique_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; | 267 std::unique_ptr<UserManagerWebContentsDelegate> webContentsDelegate_; |
| 272 UserManagerMac* userManagerObserver_; // Weak. | 268 UserManagerMac* userManagerObserver_; // Weak. |
| 273 std::unique_ptr<UserManagerModalManagerDelegate> modal_manager_delegate_; | 269 std::unique_ptr<UserManagerModalManagerDelegate> modal_manager_delegate_; |
| 274 base::scoped_nsobject<ReauthDialogWindowController> reauth_window_controller_; | 270 base::scoped_nsobject<DialogWindowController> dialog_window_controller_; |
| 275 } | 271 } |
| 276 - (void)windowWillClose:(NSNotification*)notification; | 272 - (void)windowWillClose:(NSNotification*)notification; |
| 277 - (void)dealloc; | 273 - (void)dealloc; |
| 278 - (id)initWithProfile:(Profile*)profile | 274 - (id)initWithProfile:(Profile*)profile |
| 279 withObserver:(UserManagerMac*)userManagerObserver; | 275 withObserver:(UserManagerMac*)userManagerObserver; |
| 280 - (void)showURL:(const GURL&)url; | 276 - (void)showURL:(const GURL&)url; |
| 281 - (void)show; | 277 - (void)show; |
| 282 - (void)close; | 278 - (void)close; |
| 283 - (BOOL)isVisible; | 279 - (BOOL)isVisible; |
| 284 - (void)showReauthDialogWithProfile:(Profile*)profile | 280 - (void)showDialogWithProfile:(Profile*)profile |
| 285 email:(std::string)email | 281 email:(std::string)email |
| 286 reason:(signin_metrics::Reason)reason; | 282 url:(GURL)url; |
| 287 - (void)displayErrorMessage; | 283 - (void)displayErrorMessage; |
| 288 - (void)closeReauthDialog; | 284 - (void)closeDialog; |
| 289 @end | 285 @end |
| 290 | 286 |
| 291 @implementation UserManagerWindowController | 287 @implementation UserManagerWindowController |
| 292 | 288 |
| 293 - (id)initWithProfile:(Profile*)profile | 289 - (id)initWithProfile:(Profile*)profile |
| 294 withObserver:(UserManagerMac*)userManagerObserver { | 290 withObserver:(UserManagerMac*)userManagerObserver { |
| 295 // Center the window on the screen that currently has focus. | 291 // Center the window on the screen that currently has focus. |
| 296 NSScreen* mainScreen = [NSScreen mainScreen]; | 292 NSScreen* mainScreen = [NSScreen mainScreen]; |
| 297 CGFloat screenHeight = [mainScreen frame].size.height; | 293 CGFloat screenHeight = [mainScreen frame].size.height; |
| 298 CGFloat screenWidth = [mainScreen frame].size.width; | 294 CGFloat screenWidth = [mainScreen frame].size.width; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 -(BOOL)isVisible { | 379 -(BOOL)isVisible { |
| 384 return [[self window] isVisible]; | 380 return [[self window] isVisible]; |
| 385 } | 381 } |
| 386 | 382 |
| 387 - (void)windowWillClose:(NSNotification*)notification { | 383 - (void)windowWillClose:(NSNotification*)notification { |
| 388 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 384 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 389 DCHECK(userManagerObserver_); | 385 DCHECK(userManagerObserver_); |
| 390 userManagerObserver_->WindowWasClosed(); | 386 userManagerObserver_->WindowWasClosed(); |
| 391 } | 387 } |
| 392 | 388 |
| 393 - (void)showReauthDialogWithProfile:(Profile*)profile | 389 - (void)showDialogWithProfile:(Profile*)profile |
| 394 email:(std::string)email | 390 email:(std::string)email |
| 395 reason:(signin_metrics::Reason)reason { | 391 url:(GURL)url { |
| 396 reauth_window_controller_.reset([[ReauthDialogWindowController alloc] | 392 dialog_window_controller_.reset([[DialogWindowController alloc] |
| 397 initWithProfile:profile | 393 initWithProfile:profile |
| 398 email:email | 394 email:email |
| 399 reason:reason | 395 url:url |
| 400 webContents:webContents_.get()]); | 396 webContents:webContents_.get()]); |
| 401 } | 397 } |
| 402 | 398 |
| 403 - (void)displayErrorMessage { | 399 - (void)displayErrorMessage { |
| 404 [reauth_window_controller_ showURL:GURL(chrome::kChromeUISigninErrorURL)]; | 400 [dialog_window_controller_ showURL:GURL(chrome::kChromeUISigninErrorURL)]; |
| 405 } | 401 } |
| 406 | 402 |
| 407 - (void)closeReauthDialog { | 403 - (void)closeDialog { |
| 408 [reauth_window_controller_ close]; | 404 [dialog_window_controller_ close]; |
| 409 } | 405 } |
| 410 | 406 |
| 411 @end | 407 @end |
| 412 | 408 |
| 413 | 409 |
| 414 // static | 410 // static |
| 415 void UserManager::Show( | 411 void UserManager::Show( |
| 416 const base::FilePath& profile_path_to_focus, | 412 const base::FilePath& profile_path_to_focus, |
| 417 profiles::UserManagerTutorialMode tutorial_mode, | 413 profiles::UserManagerTutorialMode tutorial_mode, |
| 418 profiles::UserManagerAction user_manager_action) { | 414 profiles::UserManagerAction user_manager_action) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 callback.Run(); | 460 callback.Run(); |
| 465 } | 461 } |
| 466 // Delete the callback list after calling. | 462 // Delete the callback list after calling. |
| 467 delete user_manager_shown_callbacks_for_testing_; | 463 delete user_manager_shown_callbacks_for_testing_; |
| 468 user_manager_shown_callbacks_for_testing_ = nullptr; | 464 user_manager_shown_callbacks_for_testing_ = nullptr; |
| 469 } | 465 } |
| 470 } | 466 } |
| 471 } | 467 } |
| 472 | 468 |
| 473 // static | 469 // static |
| 474 void UserManager::ShowReauthDialog(content::BrowserContext* browser_context, | |
| 475 const std::string& email, | |
| 476 signin_metrics::Reason reason) { | |
| 477 // This method should only be called if the user manager is already showing. | |
| 478 if (!IsShowing()) | |
| 479 return; | |
| 480 | |
| 481 instance_->ShowReauthDialog(browser_context, email, reason); | |
| 482 } | |
| 483 | |
| 484 // 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( | 470 void UserManager::AddOnUserManagerShownCallbackForTesting( |
| 495 const base::Closure& callback) { | 471 const base::Closure& callback) { |
| 496 if (!user_manager_shown_callbacks_for_testing_) | 472 if (!user_manager_shown_callbacks_for_testing_) |
| 497 user_manager_shown_callbacks_for_testing_ = new std::vector<base::Closure>; | 473 user_manager_shown_callbacks_for_testing_ = new std::vector<base::Closure>; |
| 498 user_manager_shown_callbacks_for_testing_->push_back(callback); | 474 user_manager_shown_callbacks_for_testing_->push_back(callback); |
| 499 } | 475 } |
| 500 | 476 |
| 501 // static | 477 // static |
| 502 void UserManager::ShowSigninDialog(content::BrowserContext* browser_context, | 478 base::FilePath UserManager::GetSigninProfilePath() { |
| 503 const base::FilePath& profile_path) { | 479 return instance_->GetSigninProfilePath(); |
| 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 } | 480 } |
| 510 | 481 |
| 511 // static | 482 // static |
| 512 void UserManager::DisplayErrorMessage() { | 483 void UserManagerProfileDialog::ShowReauthDialog( |
| 484 content::BrowserContext* browser_context, |
| 485 const std::string& email, |
| 486 signin_metrics::Reason reason) { |
| 487 // This method should only be called if the user manager is already showing. |
| 488 if (!UserManager::IsShowing()) |
| 489 return; |
| 490 GURL url = signin::GetReauthURLWithEmail( |
| 491 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, reason, email); |
| 492 instance_->ShowDialog(browser_context, email, url); |
| 493 } |
| 494 |
| 495 // static |
| 496 void UserManagerProfileDialog::ShowSigninDialog( |
| 497 content::BrowserContext* browser_context, |
| 498 const base::FilePath& profile_path) { |
| 499 if (!UserManager::IsShowing()) |
| 500 return; |
| 501 instance_->SetSigninProfilePath(profile_path); |
| 502 GURL url = signin::GetPromoURL( |
| 503 signin_metrics::AccessPoint::ACCESS_POINT_USER_MANAGER, |
| 504 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, true, true); |
| 505 instance_->ShowDialog(browser_context, std::string(), url); |
| 506 } |
| 507 |
| 508 // static |
| 509 void UserManagerProfileDialog::ShowDialogAndDisplayErrorMessage( |
| 510 content::BrowserContext* browser_context) { |
| 511 if (!UserManager::IsShowing()) |
| 512 return; |
| 513 instance_->ShowDialog(browser_context, std::string(), |
| 514 GURL(chrome::kChromeUISigninErrorURL)); |
| 515 } |
| 516 |
| 517 // static |
| 518 void UserManagerProfileDialog::DisplayErrorMessage() { |
| 513 DCHECK(instance_); | 519 DCHECK(instance_); |
| 514 instance_->DisplayErrorMessage(); | 520 instance_->DisplayErrorMessage(); |
| 515 } | 521 } |
| 516 | 522 |
| 517 // static | 523 // static |
| 518 base::FilePath UserManager::GetSigninProfilePath() { | 524 void UserManagerProfileDialog::HideDialog() { |
| 519 return instance_->GetSigninProfilePath(); | 525 // This method should only be called if the user manager is already showing. |
| 526 if (!UserManager::IsShowing()) |
| 527 return; |
| 528 |
| 529 instance_->CloseDialog(); |
| 520 } | 530 } |
| 521 | 531 |
| 522 void UserManagerMac::ShowReauthDialog(content::BrowserContext* browser_context, | 532 void UserManagerMac::ShowDialog(content::BrowserContext* browser_context, |
| 523 const std::string& email, | 533 const std::string& email, |
| 524 signin_metrics::Reason reason) { | 534 const GURL& url) { |
| 525 [window_controller_ | 535 [window_controller_ |
| 526 showReauthDialogWithProfile:Profile::FromBrowserContext(browser_context) | 536 showDialogWithProfile:Profile::FromBrowserContext(browser_context) |
| 527 email:email | 537 email:email |
| 528 reason:reason]; | 538 url:url]; |
| 529 } | 539 } |
| 530 | 540 |
| 531 void UserManagerMac::CloseReauthDialog() { | 541 void UserManagerMac::CloseDialog() { |
| 532 [window_controller_ closeReauthDialog]; | 542 [window_controller_ closeDialog]; |
| 533 } | 543 } |
| 534 | 544 |
| 535 UserManagerMac::UserManagerMac(Profile* profile) { | 545 UserManagerMac::UserManagerMac(Profile* profile) { |
| 536 window_controller_.reset([[UserManagerWindowController alloc] | 546 window_controller_.reset([[UserManagerWindowController alloc] |
| 537 initWithProfile:profile withObserver:this]); | 547 initWithProfile:profile withObserver:this]); |
| 538 } | 548 } |
| 539 | 549 |
| 540 UserManagerMac::~UserManagerMac() { | 550 UserManagerMac::~UserManagerMac() { |
| 541 } | 551 } |
| 542 | 552 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 554 void UserManagerMac::LogTimeToOpen() { | 564 void UserManagerMac::LogTimeToOpen() { |
| 555 if (user_manager_started_showing_ == base::Time()) | 565 if (user_manager_started_showing_ == base::Time()) |
| 556 return; | 566 return; |
| 557 | 567 |
| 558 ProfileMetrics::LogTimeToOpenUserManager( | 568 ProfileMetrics::LogTimeToOpenUserManager( |
| 559 base::Time::Now() - user_manager_started_showing_); | 569 base::Time::Now() - user_manager_started_showing_); |
| 560 user_manager_started_showing_ = base::Time(); | 570 user_manager_started_showing_ = base::Time(); |
| 561 } | 571 } |
| 562 | 572 |
| 563 void UserManagerMac::WindowWasClosed() { | 573 void UserManagerMac::WindowWasClosed() { |
| 564 CloseReauthDialog(); | 574 CloseDialog(); |
| 565 instance_ = NULL; | 575 instance_ = NULL; |
| 566 delete this; | 576 delete this; |
| 567 } | 577 } |
| 568 | 578 |
| 569 void UserManagerMac::DisplayErrorMessage() { | 579 void UserManagerMac::DisplayErrorMessage() { |
| 570 [window_controller_ displayErrorMessage]; | 580 [window_controller_ displayErrorMessage]; |
| 571 } | 581 } |
| 572 | 582 |
| 573 void UserManagerMac::SetSigninProfilePath(const base::FilePath& profile_path) { | 583 void UserManagerMac::SetSigninProfilePath(const base::FilePath& profile_path) { |
| 574 signin_profile_path_ = profile_path; | 584 signin_profile_path_ = profile_path; |
| 575 } | 585 } |
| 576 | 586 |
| 577 base::FilePath UserManagerMac::GetSigninProfilePath() { | 587 base::FilePath UserManagerMac::GetSigninProfilePath() { |
| 578 return signin_profile_path_; | 588 return signin_profile_path_; |
| 579 } | 589 } |
| OLD | NEW |