| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webui/signin/user_manager_screen_handler.h" | 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/value_conversions.h" | 10 #include "base/value_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" | 13 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 16 #include "chrome/browser/profiles/profile_info_cache.h" | 16 #include "chrome/browser/profiles/profile_info_cache.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 17 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/profiles/profile_metrics.h" | 19 #include "chrome/browser/profiles/profile_metrics.h" |
| 20 #include "chrome/browser/profiles/profile_window.h" | 20 #include "chrome/browser/profiles/profile_window.h" |
| 21 #include "chrome/browser/profiles/profiles_state.h" | 21 #include "chrome/browser/profiles/profiles_state.h" |
| 22 #include "chrome/browser/signin/local_auth.h" | 22 #include "chrome/browser/signin/local_auth.h" |
| 23 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
| 25 #include "chrome/browser/ui/browser_list.h" |
| 26 #include "chrome/browser/ui/chrome_pages.h" |
| 25 #include "chrome/browser/ui/singleton_tabs.h" | 27 #include "chrome/browser/ui/singleton_tabs.h" |
| 26 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/grit/chromium_strings.h" | 30 #include "chrome/grit/chromium_strings.h" |
| 29 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| 30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_ui.h" | 33 #include "content/public/browser/web_ui.h" |
| 32 #include "google_apis/gaia/gaia_auth_fetcher.h" | 34 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 33 #include "google_apis/gaia/gaia_constants.h" | 35 #include "google_apis/gaia/gaia_constants.h" |
| 34 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (status != Profile::CREATE_STATUS_INITIALIZED) | 79 if (status != Profile::CREATE_STATUS_INITIALIZED) |
| 78 return; | 80 return; |
| 79 profiles::FindOrCreateNewWindowForProfile( | 81 profiles::FindOrCreateNewWindowForProfile( |
| 80 profile, | 82 profile, |
| 81 chrome::startup::IS_PROCESS_STARTUP, | 83 chrome::startup::IS_PROCESS_STARTUP, |
| 82 chrome::startup::IS_FIRST_RUN, | 84 chrome::startup::IS_FIRST_RUN, |
| 83 desktop_type, | 85 desktop_type, |
| 84 false); | 86 false); |
| 85 } | 87 } |
| 86 | 88 |
| 87 // This callback is run after switching to a new profile has finished. This | |
| 88 // means either a new browser window has been opened, or an existing one | |
| 89 // has been found, which means we can safely close the User Manager without | |
| 90 // accidentally terminating the browser process. The task needs to be posted, | |
| 91 // as HideUserManager will end up destroying its WebContents, which will | |
| 92 // destruct the UserManagerScreenHandler as well. | |
| 93 void OnSwitchToProfileComplete() { | |
| 94 base::MessageLoop::current()->PostTask( | |
| 95 FROM_HERE, | |
| 96 base::Bind(&chrome::HideUserManager)); | |
| 97 } | |
| 98 | |
| 99 std::string GetAvatarImageAtIndex( | 89 std::string GetAvatarImageAtIndex( |
| 100 size_t index, const ProfileInfoCache& info_cache) { | 90 size_t index, const ProfileInfoCache& info_cache) { |
| 101 bool is_gaia_picture = | 91 bool is_gaia_picture = |
| 102 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && | 92 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && |
| 103 info_cache.GetGAIAPictureOfProfileAtIndex(index); | 93 info_cache.GetGAIAPictureOfProfileAtIndex(index); |
| 104 | 94 |
| 105 // If the avatar is too small (i.e. the old-style low resolution avatar), | 95 // If the avatar is too small (i.e. the old-style low resolution avatar), |
| 106 // it will be pixelated when displayed in the User Manager, so we should | 96 // it will be pixelated when displayed in the User Manager, so we should |
| 107 // return the placeholder avatar instead. | 97 // return the placeholder avatar instead. |
| 108 gfx::Image avatar_image = info_cache.GetAvatarIconOfProfileAtIndex(index); | 98 gfx::Image avatar_image = info_cache.GetAvatarIconOfProfileAtIndex(index); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 g_browser_process->profile_manager()->GetProfileInfoCache(); | 270 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 281 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 271 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
| 282 info_cache, base::UTF8ToUTF16(user_email), base::string16()); | 272 info_cache, base::UTF8ToUTF16(user_email), base::string16()); |
| 283 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); | 273 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); |
| 284 | 274 |
| 285 authenticating_profile_index_ = profile_index; | 275 authenticating_profile_index_ = profile_index; |
| 286 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 276 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
| 287 } | 277 } |
| 288 | 278 |
| 289 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 279 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
| 280 // If the URL has a hash parameter, store it for later. |
| 281 base::string16 url_hash; |
| 282 if (args->GetString(0, &url_hash)) |
| 283 url_hash_ = url_hash; |
| 284 |
| 290 SendUserList(); | 285 SendUserList(); |
| 291 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", | 286 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
| 292 base::FundamentalValue(IsGuestModeEnabled())); | 287 base::FundamentalValue(IsGuestModeEnabled())); |
| 293 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 288 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
| 294 web_ui()->GetWebContents()->GetNativeView()); | 289 web_ui()->GetWebContents()->GetNativeView()); |
| 295 | 290 |
| 296 ScreenlockBridge::Get()->SetLockHandler(this); | 291 ScreenlockBridge::Get()->SetLockHandler(this); |
| 297 } | 292 } |
| 298 | 293 |
| 299 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 294 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
| 300 profiles::CreateAndSwitchToNewProfile(desktop_type_, | 295 profiles::CreateAndSwitchToNewProfile( |
| 301 base::Bind(&OnSwitchToProfileComplete), | 296 desktop_type_, |
| 302 ProfileMetrics::ADD_NEW_USER_MANAGER); | 297 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 298 base::Unretained(this)), |
| 299 ProfileMetrics::ADD_NEW_USER_MANAGER); |
| 303 } | 300 } |
| 304 | 301 |
| 305 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 302 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
| 306 const base::ListValue* args) { | 303 const base::ListValue* args) { |
| 307 base::string16 email_address; | 304 base::string16 email_address; |
| 308 if (!args->GetString(0, &email_address)) | 305 if (!args->GetString(0, &email_address)) |
| 309 return; | 306 return; |
| 310 | 307 |
| 311 base::string16 display_name; | 308 base::string16 display_name; |
| 312 if (!args->GetString(1, &display_name)) | 309 if (!args->GetString(1, &display_name)) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 368 |
| 372 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 369 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
| 373 profile_path, | 370 profile_path, |
| 374 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 371 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
| 375 ProfileMetrics::LogProfileDeleteUser( | 372 ProfileMetrics::LogProfileDeleteUser( |
| 376 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 373 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
| 377 } | 374 } |
| 378 | 375 |
| 379 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 376 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
| 380 if (IsGuestModeEnabled()) { | 377 if (IsGuestModeEnabled()) { |
| 381 profiles::SwitchToGuestProfile(desktop_type_, | 378 profiles::SwitchToGuestProfile( |
| 382 base::Bind(&OnSwitchToProfileComplete)); | 379 desktop_type_, |
| 380 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 381 base::Unretained(this))); |
| 383 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | 382 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); |
| 384 } else { | 383 } else { |
| 385 // The UI should have prevented the user from allowing the selection of | 384 // The UI should have prevented the user from allowing the selection of |
| 386 // guest mode. | 385 // guest mode. |
| 387 NOTREACHED(); | 386 NOTREACHED(); |
| 388 } | 387 } |
| 389 } | 388 } |
| 390 | 389 |
| 391 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 390 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
| 392 base::string16 email_address; | 391 base::string16 email_address; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 411 // It's possible that a user breaks into the user-manager page using the | 410 // It's possible that a user breaks into the user-manager page using the |
| 412 // JavaScript Inspector and causes a "locked" profile to call this | 411 // JavaScript Inspector and causes a "locked" profile to call this |
| 413 // unauthenticated version of "launch" instead of the proper one. Thus, | 412 // unauthenticated version of "launch" instead of the proper one. Thus, |
| 414 // we have to validate in (secure) C++ code that it really is a profile | 413 // we have to validate in (secure) C++ code that it really is a profile |
| 415 // not needing authentication. If it is, just ignore the "launch" request. | 414 // not needing authentication. If it is, just ignore the "launch" request. |
| 416 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 415 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
| 417 return; | 416 return; |
| 418 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 417 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
| 419 | 418 |
| 420 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 419 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
| 421 profiles::SwitchToProfile(path, | 420 profiles::SwitchToProfile( |
| 422 desktop_type_, | 421 path, |
| 423 false, /* reuse any existing windows */ | 422 desktop_type_, |
| 424 base::Bind(&OnSwitchToProfileComplete), | 423 false, /* reuse any existing windows */ |
| 425 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 424 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 425 base::Unretained(this)), |
| 426 ProfileMetrics::SWITCH_PROFILE_MANAGER); |
| 426 } | 427 } |
| 427 | 428 |
| 428 void UserManagerScreenHandler::HandleAttemptUnlock( | 429 void UserManagerScreenHandler::HandleAttemptUnlock( |
| 429 const base::ListValue* args) { | 430 const base::ListValue* args) { |
| 430 std::string email; | 431 std::string email; |
| 431 CHECK(args->GetString(0, &email)); | 432 CHECK(args->GetString(0, &email)); |
| 432 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); | 433 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); |
| 433 } | 434 } |
| 434 | 435 |
| 435 void UserManagerScreenHandler::HandleHardlockUserPod( | 436 void UserManagerScreenHandler::HandleHardlockUserPod( |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 ProfileMetrics::LogProfileAuthResult(auth); | 660 ProfileMetrics::LogProfileAuthResult(auth); |
| 660 password_attempt_.clear(); | 661 password_attempt_.clear(); |
| 661 | 662 |
| 662 if (success) { | 663 if (success) { |
| 663 ProfileInfoCache& info_cache = | 664 ProfileInfoCache& info_cache = |
| 664 g_browser_process->profile_manager()->GetProfileInfoCache(); | 665 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 665 info_cache.SetProfileSigninRequiredAtIndex( | 666 info_cache.SetProfileSigninRequiredAtIndex( |
| 666 authenticating_profile_index_, false); | 667 authenticating_profile_index_, false); |
| 667 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 668 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
| 668 authenticating_profile_index_); | 669 authenticating_profile_index_); |
| 669 profiles::SwitchToProfile(path, desktop_type_, true, | 670 profiles::SwitchToProfile( |
| 670 base::Bind(&OnSwitchToProfileComplete), | 671 path, |
| 671 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 672 desktop_type_, |
| 673 true, |
| 674 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 675 base::Unretained(this)), |
| 676 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| 672 } else { | 677 } else { |
| 673 web_ui()->CallJavascriptFunction( | 678 web_ui()->CallJavascriptFunction( |
| 674 "cr.ui.Oobe.showSignInError", | 679 "cr.ui.Oobe.showSignInError", |
| 675 base::FundamentalValue(0), | 680 base::FundamentalValue(0), |
| 676 base::StringValue( | 681 base::StringValue( |
| 677 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 682 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
| 678 base::StringValue(""), | 683 base::StringValue(""), |
| 679 base::FundamentalValue(0)); | 684 base::FundamentalValue(0)); |
| 680 } | 685 } |
| 681 } | 686 } |
| 687 |
| 688 // This callback is run after switching to a new profile has finished. This |
| 689 // means either a new browser window has been opened, or an existing one |
| 690 // has been found, which means we can safely close the User Manager without |
| 691 // accidentally terminating the browser process. The task needs to be posted, |
| 692 // as HideUserManager will end up destroying its WebContents, which will |
| 693 // destruct the UserManagerScreenHandler as well. |
| 694 void UserManagerScreenHandler::OnSwitchToProfileComplete( |
| 695 Profile* profile, Profile::CreateStatus profile_create_status) { |
| 696 base::MessageLoop::current()->PostTask( |
| 697 FROM_HERE, |
| 698 base::Bind(&chrome::HideUserManager)); |
| 699 if (url_hash_ == |
| 700 base::UTF8ToUTF16(profiles::kUserManagerSelectProfileTaskManager)) { |
| 701 Browser* browser = BrowserList::GetInstance(desktop_type_)->get(0); |
| 702 base::MessageLoop::current()->PostTask( |
| 703 FROM_HERE, base::Bind(&chrome::ShowTaskManager, browser)); |
| 704 } else if (url_hash_ == |
| 705 base::UTF8ToUTF16(profiles::kUserManagerSelectProfileAboutChrome)) { |
| 706 // The new browser window may not have been created. Make a new one. |
| 707 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
| 708 if (browser) { |
| 709 base::MessageLoop::current()->PostTask( |
| 710 FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser)); |
| 711 } else { |
| 712 NOTREACHED(); |
| 713 } |
| 714 } |
| 715 } |
| OLD | NEW |