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 std::string url_hash; | |
292 if (args->GetString(0, &url_hash)) | |
Evan Stade
2014/09/15 21:07:21
args->GetString(0, &url_hash_)
should be sufficie
Mike Lerman
2014/09/17 18:31:46
Done.
| |
293 url_hash_ = url_hash; | |
294 | |
296 SendUserList(); | 295 SendUserList(); |
297 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", | 296 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
298 base::FundamentalValue(IsGuestModeEnabled()), | 297 base::FundamentalValue(IsGuestModeEnabled()), |
299 base::FundamentalValue(IsAddPersonEnabled())); | 298 base::FundamentalValue(IsAddPersonEnabled())); |
300 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 299 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
301 web_ui()->GetWebContents()->GetNativeView()); | 300 web_ui()->GetWebContents()->GetNativeView()); |
302 | 301 |
303 ScreenlockBridge::Get()->SetLockHandler(this); | 302 ScreenlockBridge::Get()->SetLockHandler(this); |
304 } | 303 } |
305 | 304 |
306 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 305 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
307 if (!IsAddPersonEnabled()) { | 306 if (!IsAddPersonEnabled()) { |
308 // The 'Add User' UI should not be showing. | 307 // The 'Add User' UI should not be showing. |
309 NOTREACHED(); | 308 NOTREACHED(); |
310 return; | 309 return; |
311 } | 310 } |
312 profiles::CreateAndSwitchToNewProfile( | 311 profiles::CreateAndSwitchToNewProfile( |
313 desktop_type_, | 312 desktop_type_, |
314 base::Bind(&OnSwitchToProfileComplete), | 313 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
314 weak_ptr_factory_.GetWeakPtr()), | |
315 ProfileMetrics::ADD_NEW_USER_MANAGER); | 315 ProfileMetrics::ADD_NEW_USER_MANAGER); |
316 } | 316 } |
317 | 317 |
318 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 318 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
319 const base::ListValue* args) { | 319 const base::ListValue* args) { |
320 base::string16 email_address; | 320 base::string16 email_address; |
321 if (!args->GetString(0, &email_address)) | 321 if (!args->GetString(0, &email_address)) |
322 return; | 322 return; |
323 | 323 |
324 base::string16 display_name; | 324 base::string16 display_name; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 | 384 |
385 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 385 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
386 profile_path, | 386 profile_path, |
387 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 387 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
388 ProfileMetrics::LogProfileDeleteUser( | 388 ProfileMetrics::LogProfileDeleteUser( |
389 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 389 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
390 } | 390 } |
391 | 391 |
392 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 392 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
393 if (IsGuestModeEnabled()) { | 393 if (IsGuestModeEnabled()) { |
394 profiles::SwitchToGuestProfile(desktop_type_, | |
395 base::Bind(&OnSwitchToProfileComplete)); | |
396 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | 394 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); |
395 profiles::SwitchToGuestProfile( | |
396 desktop_type_, | |
397 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | |
398 weak_ptr_factory_.GetWeakPtr())); | |
397 } else { | 399 } else { |
398 // The UI should have prevented the user from allowing the selection of | 400 // The UI should have prevented the user from allowing the selection of |
399 // guest mode. | 401 // guest mode. |
400 NOTREACHED(); | 402 NOTREACHED(); |
401 } | 403 } |
402 } | 404 } |
403 | 405 |
404 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 406 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
405 base::string16 email_address; | 407 base::string16 email_address; |
406 base::string16 display_name; | 408 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 | 426 // 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 | 427 // JavaScript Inspector and causes a "locked" profile to call this |
426 // unauthenticated version of "launch" instead of the proper one. Thus, | 428 // 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 | 429 // 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. | 430 // not needing authentication. If it is, just ignore the "launch" request. |
429 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 431 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
430 return; | 432 return; |
431 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 433 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
432 | 434 |
433 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 435 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
434 profiles::SwitchToProfile(path, | 436 profiles::SwitchToProfile( |
435 desktop_type_, | 437 path, |
436 false, /* reuse any existing windows */ | 438 desktop_type_, |
437 base::Bind(&OnSwitchToProfileComplete), | 439 false, /* reuse any existing windows */ |
438 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 440 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
441 weak_ptr_factory_.GetWeakPtr()), | |
442 ProfileMetrics::SWITCH_PROFILE_MANAGER); | |
439 } | 443 } |
440 | 444 |
441 void UserManagerScreenHandler::HandleAttemptUnlock( | 445 void UserManagerScreenHandler::HandleAttemptUnlock( |
442 const base::ListValue* args) { | 446 const base::ListValue* args) { |
443 std::string email; | 447 std::string email; |
444 CHECK(args->GetString(0, &email)); | 448 CHECK(args->GetString(0, &email)); |
445 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); | 449 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); |
446 } | 450 } |
447 | 451 |
448 void UserManagerScreenHandler::HandleHardlockUserPod( | 452 void UserManagerScreenHandler::HandleHardlockUserPod( |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 ProfileMetrics::LogProfileAuthResult(auth); | 676 ProfileMetrics::LogProfileAuthResult(auth); |
673 password_attempt_.clear(); | 677 password_attempt_.clear(); |
674 | 678 |
675 if (success) { | 679 if (success) { |
676 ProfileInfoCache& info_cache = | 680 ProfileInfoCache& info_cache = |
677 g_browser_process->profile_manager()->GetProfileInfoCache(); | 681 g_browser_process->profile_manager()->GetProfileInfoCache(); |
678 info_cache.SetProfileSigninRequiredAtIndex( | 682 info_cache.SetProfileSigninRequiredAtIndex( |
679 authenticating_profile_index_, false); | 683 authenticating_profile_index_, false); |
680 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 684 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
681 authenticating_profile_index_); | 685 authenticating_profile_index_); |
682 profiles::SwitchToProfile(path, desktop_type_, true, | 686 profiles::SwitchToProfile( |
683 base::Bind(&OnSwitchToProfileComplete), | 687 path, |
684 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 688 desktop_type_, |
689 true, | |
690 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | |
691 weak_ptr_factory_.GetWeakPtr()), | |
692 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | |
685 } else { | 693 } else { |
686 web_ui()->CallJavascriptFunction( | 694 web_ui()->CallJavascriptFunction( |
687 "cr.ui.Oobe.showSignInError", | 695 "cr.ui.Oobe.showSignInError", |
688 base::FundamentalValue(0), | 696 base::FundamentalValue(0), |
689 base::StringValue( | 697 base::StringValue( |
690 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 698 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
691 base::StringValue(""), | 699 base::StringValue(""), |
692 base::FundamentalValue(0)); | 700 base::FundamentalValue(0)); |
693 } | 701 } |
694 } | 702 } |
703 | |
704 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { | |
705 DCHECK(browser); | |
706 DCHECK(browser->window()); | |
707 if (url_hash_ == profiles::kUserManagerSelectProfileTaskManager) { | |
708 base::MessageLoop::current()->PostTask( | |
709 FROM_HERE, base::Bind(&chrome::ShowTaskManager, browser)); | |
Evan Stade
2014/09/15 21:07:21
this indent is too big
Mike Lerman
2014/09/17 18:31:46
Done.
| |
710 } else if (url_hash_ == profiles::kUserManagerSelectProfileAboutChrome) { | |
711 base::MessageLoop::current()->PostTask( | |
712 FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser)); | |
Evan Stade
2014/09/15 21:07:21
this indent is too little
Mike Lerman
2014/09/17 18:31:46
And this indent is juuust right, goldilocks!
Done
| |
713 } | |
714 | |
715 // This call is last as it deletes this object. | |
716 UserManager::Hide(); | |
717 } | |
718 | |
719 void UserManagerScreenHandler::Observe( | |
720 int type, | |
721 const content::NotificationSource& source, | |
722 const content::NotificationDetails& details) { | |
723 switch (type) { | |
724 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: | |
725 // Only respond to one Browser Window Ready event. | |
726 registrar_.Remove(this, | |
727 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
728 content::NotificationService::AllSources()); | |
729 OnBrowserWindowReady(content::Source<Browser>(source).ptr()); | |
730 break; | |
731 default: | |
732 NOTREACHED(); | |
733 } | |
734 } | |
735 | |
736 // This callback is run after switching to a new profile has finished. This | |
737 // means either a new browser has been created (but not the window), or an | |
738 // existing one has been found. The HideUserManager task needs to be posted | |
739 // since closing the User Manager before the window is created can flakily | |
740 // cause Chrome to close. | |
741 void UserManagerScreenHandler::OnSwitchToProfileComplete( | |
742 Profile* profile, Profile::CreateStatus profile_create_status) { | |
743 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | |
744 if (browser && browser->window()) { | |
745 OnBrowserWindowReady(browser); | |
746 } else { | |
747 registrar_.Add(this, | |
748 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
749 content::NotificationService::AllSources()); | |
750 } | |
751 } | |
OLD | NEW |