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