| 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/chrome_notification_types.h" |
| 13 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" | 14 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 16 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 18 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
| 20 #include "chrome/browser/profiles/profile_window.h" | 21 #include "chrome/browser/profiles/profile_window.h" |
| 21 #include "chrome/browser/profiles/profiles_state.h" | 22 #include "chrome/browser/profiles/profiles_state.h" |
| 22 #include "chrome/browser/signin/local_auth.h" | 23 #include "chrome/browser/signin/local_auth.h" |
| 23 #include "chrome/browser/ui/browser_dialogs.h" | 24 #include "chrome/browser/ui/browser_dialogs.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/chrome_pages.h" |
| 25 #include "chrome/browser/ui/singleton_tabs.h" | 28 #include "chrome/browser/ui/singleton_tabs.h" |
| 29 #include "chrome/browser/ui/user_manager.h" |
| 26 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/grit/chromium_strings.h" | 32 #include "chrome/grit/chromium_strings.h" |
| 29 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| 34 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_ui.h" | 36 #include "content/public/browser/web_ui.h" |
| 32 #include "google_apis/gaia/gaia_auth_fetcher.h" | 37 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 33 #include "google_apis/gaia/gaia_constants.h" | 38 #include "google_apis/gaia/gaia_constants.h" |
| 34 #include "third_party/skia/include/core/SkBitmap.h" | 39 #include "third_party/skia/include/core/SkBitmap.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/base/webui/web_ui_util.h" | 42 #include "ui/base/webui/web_ui_util.h" |
| 38 #include "ui/gfx/image/image.h" | 43 #include "ui/gfx/image/image.h" |
| 39 #include "ui/gfx/image/image_skia.h" | 44 #include "ui/gfx/image/image_skia.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (status != Profile::CREATE_STATUS_INITIALIZED) | 82 if (status != Profile::CREATE_STATUS_INITIALIZED) |
| 78 return; | 83 return; |
| 79 profiles::FindOrCreateNewWindowForProfile( | 84 profiles::FindOrCreateNewWindowForProfile( |
| 80 profile, | 85 profile, |
| 81 chrome::startup::IS_PROCESS_STARTUP, | 86 chrome::startup::IS_PROCESS_STARTUP, |
| 82 chrome::startup::IS_FIRST_RUN, | 87 chrome::startup::IS_FIRST_RUN, |
| 83 desktop_type, | 88 desktop_type, |
| 84 false); | 89 false); |
| 85 } | 90 } |
| 86 | 91 |
| 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( | 92 std::string GetAvatarImageAtIndex( |
| 100 size_t index, const ProfileInfoCache& info_cache) { | 93 size_t index, const ProfileInfoCache& info_cache) { |
| 101 bool is_gaia_picture = | 94 bool is_gaia_picture = |
| 102 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && | 95 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && |
| 103 info_cache.GetGAIAPictureOfProfileAtIndex(index); | 96 info_cache.GetGAIAPictureOfProfileAtIndex(index); |
| 104 | 97 |
| 105 // If the avatar is too small (i.e. the old-style low resolution avatar), | 98 // 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 | 99 // it will be pixelated when displayed in the User Manager, so we should |
| 107 // return the placeholder avatar instead. | 100 // return the placeholder avatar instead. |
| 108 gfx::Image avatar_image = info_cache.GetAvatarIconOfProfileAtIndex(index); | 101 gfx::Image avatar_image = info_cache.GetAvatarIconOfProfileAtIndex(index); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 ProfileManager* profile_manager_; | 203 ProfileManager* profile_manager_; |
| 211 | 204 |
| 212 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us. | 205 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us. |
| 213 | 206 |
| 214 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); | 207 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); |
| 215 }; | 208 }; |
| 216 | 209 |
| 217 // UserManagerScreenHandler --------------------------------------------------- | 210 // UserManagerScreenHandler --------------------------------------------------- |
| 218 | 211 |
| 219 UserManagerScreenHandler::UserManagerScreenHandler() | 212 UserManagerScreenHandler::UserManagerScreenHandler() |
| 220 : desktop_type_(chrome::GetActiveDesktop()) { | 213 : desktop_type_(chrome::GetActiveDesktop()), |
| 214 weak_ptr_factory_(this) { |
| 221 profileInfoCacheObserver_.reset( | 215 profileInfoCacheObserver_.reset( |
| 222 new UserManagerScreenHandler::ProfileUpdateObserver( | 216 new UserManagerScreenHandler::ProfileUpdateObserver( |
| 223 g_browser_process->profile_manager(), this)); | 217 g_browser_process->profile_manager(), this)); |
| 224 } | 218 } |
| 225 | 219 |
| 226 UserManagerScreenHandler::~UserManagerScreenHandler() { | 220 UserManagerScreenHandler::~UserManagerScreenHandler() { |
| 227 ScreenlockBridge::Get()->SetLockHandler(NULL); | 221 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 228 } | 222 } |
| 229 | 223 |
| 230 void UserManagerScreenHandler::ShowBannerMessage( | 224 void UserManagerScreenHandler::ShowBannerMessage( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 g_browser_process->profile_manager()->GetProfileInfoCache(); | 280 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 287 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 281 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
| 288 info_cache, base::UTF8ToUTF16(user_email), base::string16()); | 282 info_cache, base::UTF8ToUTF16(user_email), base::string16()); |
| 289 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); | 283 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); |
| 290 | 284 |
| 291 authenticating_profile_index_ = profile_index; | 285 authenticating_profile_index_ = profile_index; |
| 292 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 286 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
| 293 } | 287 } |
| 294 | 288 |
| 295 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 289 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
| 290 // If the URL has a hash parameter, store it for later. |
| 291 args->GetString(0, &url_hash_); |
| 292 |
| 296 SendUserList(); | 293 SendUserList(); |
| 297 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", | 294 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
| 298 base::FundamentalValue(IsGuestModeEnabled()), | 295 base::FundamentalValue(IsGuestModeEnabled()), |
| 299 base::FundamentalValue(IsAddPersonEnabled())); | 296 base::FundamentalValue(IsAddPersonEnabled())); |
| 300 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 297 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
| 301 web_ui()->GetWebContents()->GetNativeView()); | 298 web_ui()->GetWebContents()->GetNativeView()); |
| 302 | 299 |
| 303 ScreenlockBridge::Get()->SetLockHandler(this); | 300 ScreenlockBridge::Get()->SetLockHandler(this); |
| 304 } | 301 } |
| 305 | 302 |
| 306 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 303 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
| 307 if (!IsAddPersonEnabled()) { | 304 if (!IsAddPersonEnabled()) { |
| 308 // The 'Add User' UI should not be showing. | 305 // The 'Add User' UI should not be showing. |
| 309 NOTREACHED(); | 306 NOTREACHED(); |
| 310 return; | 307 return; |
| 311 } | 308 } |
| 312 profiles::CreateAndSwitchToNewProfile( | 309 profiles::CreateAndSwitchToNewProfile( |
| 313 desktop_type_, | 310 desktop_type_, |
| 314 base::Bind(&OnSwitchToProfileComplete), | 311 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 312 weak_ptr_factory_.GetWeakPtr()), |
| 315 ProfileMetrics::ADD_NEW_USER_MANAGER); | 313 ProfileMetrics::ADD_NEW_USER_MANAGER); |
| 316 } | 314 } |
| 317 | 315 |
| 318 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 316 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
| 319 const base::ListValue* args) { | 317 const base::ListValue* args) { |
| 320 base::string16 email_address; | 318 base::string16 email_address; |
| 321 if (!args->GetString(0, &email_address)) | 319 if (!args->GetString(0, &email_address)) |
| 322 return; | 320 return; |
| 323 | 321 |
| 324 base::string16 display_name; | 322 base::string16 display_name; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 382 |
| 385 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 383 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
| 386 profile_path, | 384 profile_path, |
| 387 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 385 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
| 388 ProfileMetrics::LogProfileDeleteUser( | 386 ProfileMetrics::LogProfileDeleteUser( |
| 389 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 387 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
| 390 } | 388 } |
| 391 | 389 |
| 392 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 390 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
| 393 if (IsGuestModeEnabled()) { | 391 if (IsGuestModeEnabled()) { |
| 394 profiles::SwitchToGuestProfile(desktop_type_, | |
| 395 base::Bind(&OnSwitchToProfileComplete)); | |
| 396 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | 392 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); |
| 393 profiles::SwitchToGuestProfile( |
| 394 desktop_type_, |
| 395 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 396 weak_ptr_factory_.GetWeakPtr())); |
| 397 } else { | 397 } else { |
| 398 // The UI should have prevented the user from allowing the selection of | 398 // The UI should have prevented the user from allowing the selection of |
| 399 // guest mode. | 399 // guest mode. |
| 400 NOTREACHED(); | 400 NOTREACHED(); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 | 403 |
| 404 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 404 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
| 405 base::string16 email_address; | 405 base::string16 email_address; |
| 406 base::string16 display_name; | 406 base::string16 display_name; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 424 // It's possible that a user breaks into the user-manager page using the | 424 // It's possible that a user breaks into the user-manager page using the |
| 425 // JavaScript Inspector and causes a "locked" profile to call this | 425 // JavaScript Inspector and causes a "locked" profile to call this |
| 426 // unauthenticated version of "launch" instead of the proper one. Thus, | 426 // unauthenticated version of "launch" instead of the proper one. Thus, |
| 427 // we have to validate in (secure) C++ code that it really is a profile | 427 // we have to validate in (secure) C++ code that it really is a profile |
| 428 // not needing authentication. If it is, just ignore the "launch" request. | 428 // not needing authentication. If it is, just ignore the "launch" request. |
| 429 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 429 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
| 430 return; | 430 return; |
| 431 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 431 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
| 432 | 432 |
| 433 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 433 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
| 434 profiles::SwitchToProfile(path, | 434 profiles::SwitchToProfile( |
| 435 desktop_type_, | 435 path, |
| 436 false, /* reuse any existing windows */ | 436 desktop_type_, |
| 437 base::Bind(&OnSwitchToProfileComplete), | 437 false, /* reuse any existing windows */ |
| 438 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 438 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 439 weak_ptr_factory_.GetWeakPtr()), |
| 440 ProfileMetrics::SWITCH_PROFILE_MANAGER); |
| 439 } | 441 } |
| 440 | 442 |
| 441 void UserManagerScreenHandler::HandleAttemptUnlock( | 443 void UserManagerScreenHandler::HandleAttemptUnlock( |
| 442 const base::ListValue* args) { | 444 const base::ListValue* args) { |
| 443 std::string email; | 445 std::string email; |
| 444 CHECK(args->GetString(0, &email)); | 446 CHECK(args->GetString(0, &email)); |
| 445 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); | 447 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); |
| 446 } | 448 } |
| 447 | 449 |
| 448 void UserManagerScreenHandler::HandleHardlockUserPod( | 450 void UserManagerScreenHandler::HandleHardlockUserPod( |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 ProfileMetrics::LogProfileAuthResult(auth); | 679 ProfileMetrics::LogProfileAuthResult(auth); |
| 678 password_attempt_.clear(); | 680 password_attempt_.clear(); |
| 679 | 681 |
| 680 if (success) { | 682 if (success) { |
| 681 ProfileInfoCache& info_cache = | 683 ProfileInfoCache& info_cache = |
| 682 g_browser_process->profile_manager()->GetProfileInfoCache(); | 684 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 683 info_cache.SetProfileSigninRequiredAtIndex( | 685 info_cache.SetProfileSigninRequiredAtIndex( |
| 684 authenticating_profile_index_, false); | 686 authenticating_profile_index_, false); |
| 685 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 687 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
| 686 authenticating_profile_index_); | 688 authenticating_profile_index_); |
| 687 profiles::SwitchToProfile(path, desktop_type_, true, | 689 profiles::SwitchToProfile( |
| 688 base::Bind(&OnSwitchToProfileComplete), | 690 path, |
| 689 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 691 desktop_type_, |
| 692 true, |
| 693 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 694 weak_ptr_factory_.GetWeakPtr()), |
| 695 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| 690 } else { | 696 } else { |
| 691 web_ui()->CallJavascriptFunction( | 697 web_ui()->CallJavascriptFunction( |
| 692 "cr.ui.Oobe.showSignInError", | 698 "cr.ui.Oobe.showSignInError", |
| 693 base::FundamentalValue(0), | 699 base::FundamentalValue(0), |
| 694 base::StringValue(l10n_util::GetStringUTF8( | 700 base::StringValue(l10n_util::GetStringUTF8( |
| 695 auth == ProfileMetrics::AUTH_FAILED_OFFLINE ? | 701 auth == ProfileMetrics::AUTH_FAILED_OFFLINE ? |
| 696 IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE : | 702 IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE : |
| 697 IDS_LOGIN_ERROR_AUTHENTICATING)), | 703 IDS_LOGIN_ERROR_AUTHENTICATING)), |
| 698 base::StringValue(""), | 704 base::StringValue(""), |
| 699 base::FundamentalValue(0)); | 705 base::FundamentalValue(0)); |
| 700 } | 706 } |
| 701 } | 707 } |
| 708 |
| 709 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { |
| 710 DCHECK(browser); |
| 711 DCHECK(browser->window()); |
| 712 if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) { |
| 713 base::MessageLoop::current()->PostTask( |
| 714 FROM_HERE, base::Bind(&chrome::ShowTaskManager, browser)); |
| 715 } else if (url_hash_ == profiles::kUserManagerSelectProfileAboutChrome) { |
| 716 base::MessageLoop::current()->PostTask( |
| 717 FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser)); |
| 718 } |
| 719 |
| 720 // This call is last as it deletes this object. |
| 721 UserManager::Hide(); |
| 722 } |
| 723 |
| 724 void UserManagerScreenHandler::Observe( |
| 725 int type, |
| 726 const content::NotificationSource& source, |
| 727 const content::NotificationDetails& details) { |
| 728 switch (type) { |
| 729 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: |
| 730 // Only respond to one Browser Window Ready event. |
| 731 registrar_.Remove(this, |
| 732 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 733 content::NotificationService::AllSources()); |
| 734 OnBrowserWindowReady(content::Source<Browser>(source).ptr()); |
| 735 break; |
| 736 default: |
| 737 NOTREACHED(); |
| 738 } |
| 739 } |
| 740 |
| 741 // This callback is run after switching to a new profile has finished. This |
| 742 // means either a new browser has been created (but not the window), or an |
| 743 // existing one has been found. The HideUserManager task needs to be posted |
| 744 // since closing the User Manager before the window is created can flakily |
| 745 // cause Chrome to close. |
| 746 void UserManagerScreenHandler::OnSwitchToProfileComplete( |
| 747 Profile* profile, Profile::CreateStatus profile_create_status) { |
| 748 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
| 749 if (browser && browser->window()) { |
| 750 OnBrowserWindowReady(browser); |
| 751 } else { |
| 752 registrar_.Add(this, |
| 753 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 754 content::NotificationService::AllSources()); |
| 755 } |
| 756 } |
| OLD | NEW |