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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 ProfileManager* profile_manager_; | 196 ProfileManager* profile_manager_; |
205 | 197 |
206 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us. | 198 UserManagerScreenHandler* user_manager_handler_; // Weak; owns us. |
207 | 199 |
208 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); | 200 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); |
209 }; | 201 }; |
210 | 202 |
211 // UserManagerScreenHandler --------------------------------------------------- | 203 // UserManagerScreenHandler --------------------------------------------------- |
212 | 204 |
213 UserManagerScreenHandler::UserManagerScreenHandler() | 205 UserManagerScreenHandler::UserManagerScreenHandler() |
214 : desktop_type_(chrome::GetActiveDesktop()) { | 206 : desktop_type_(chrome::GetActiveDesktop()), |
207 weak_ptr_factory_(this) { | |
215 profileInfoCacheObserver_.reset( | 208 profileInfoCacheObserver_.reset( |
216 new UserManagerScreenHandler::ProfileUpdateObserver( | 209 new UserManagerScreenHandler::ProfileUpdateObserver( |
217 g_browser_process->profile_manager(), this)); | 210 g_browser_process->profile_manager(), this)); |
218 } | 211 } |
219 | 212 |
220 UserManagerScreenHandler::~UserManagerScreenHandler() { | 213 UserManagerScreenHandler::~UserManagerScreenHandler() { |
221 ScreenlockBridge::Get()->SetLockHandler(NULL); | 214 ScreenlockBridge::Get()->SetLockHandler(NULL); |
222 } | 215 } |
223 | 216 |
224 void UserManagerScreenHandler::ShowBannerMessage( | 217 void UserManagerScreenHandler::ShowBannerMessage( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 g_browser_process->profile_manager()->GetProfileInfoCache(); | 273 g_browser_process->profile_manager()->GetProfileInfoCache(); |
281 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 274 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
282 info_cache, base::UTF8ToUTF16(user_email), base::string16()); | 275 info_cache, base::UTF8ToUTF16(user_email), base::string16()); |
283 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); | 276 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); |
284 | 277 |
285 authenticating_profile_index_ = profile_index; | 278 authenticating_profile_index_ = profile_index; |
286 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 279 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
287 } | 280 } |
288 | 281 |
289 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 282 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
283 // If the URL has a hash parameter, store it for later. | |
284 base::string16 url_hash; | |
285 if (args->GetString(0, &url_hash)) | |
286 url_hash_ = url_hash; | |
287 | |
290 SendUserList(); | 288 SendUserList(); |
291 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", | 289 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
292 base::FundamentalValue(IsGuestModeEnabled())); | 290 base::FundamentalValue(IsGuestModeEnabled())); |
293 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 291 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
294 web_ui()->GetWebContents()->GetNativeView()); | 292 web_ui()->GetWebContents()->GetNativeView()); |
295 | 293 |
296 ScreenlockBridge::Get()->SetLockHandler(this); | 294 ScreenlockBridge::Get()->SetLockHandler(this); |
297 } | 295 } |
298 | 296 |
299 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 297 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
300 profiles::CreateAndSwitchToNewProfile(desktop_type_, | 298 profiles::CreateAndSwitchToNewProfile( |
301 base::Bind(&OnSwitchToProfileComplete), | 299 desktop_type_, |
302 ProfileMetrics::ADD_NEW_USER_MANAGER); | 300 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
301 weak_ptr_factory_.GetWeakPtr()), | |
302 ProfileMetrics::ADD_NEW_USER_MANAGER); | |
303 } | 303 } |
304 | 304 |
305 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 305 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
306 const base::ListValue* args) { | 306 const base::ListValue* args) { |
307 base::string16 email_address; | 307 base::string16 email_address; |
308 if (!args->GetString(0, &email_address)) | 308 if (!args->GetString(0, &email_address)) |
309 return; | 309 return; |
310 | 310 |
311 base::string16 display_name; | 311 base::string16 display_name; |
312 if (!args->GetString(1, &display_name)) | 312 if (!args->GetString(1, &display_name)) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 | 371 |
372 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 372 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
373 profile_path, | 373 profile_path, |
374 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 374 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
375 ProfileMetrics::LogProfileDeleteUser( | 375 ProfileMetrics::LogProfileDeleteUser( |
376 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 376 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
377 } | 377 } |
378 | 378 |
379 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 379 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
380 if (IsGuestModeEnabled()) { | 380 if (IsGuestModeEnabled()) { |
381 profiles::SwitchToGuestProfile(desktop_type_, | |
382 base::Bind(&OnSwitchToProfileComplete)); | |
383 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | 381 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); |
382 profiles::SwitchToGuestProfile( | |
383 desktop_type_, | |
384 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | |
385 weak_ptr_factory_.GetWeakPtr())); | |
384 } else { | 386 } else { |
385 // The UI should have prevented the user from allowing the selection of | 387 // The UI should have prevented the user from allowing the selection of |
386 // guest mode. | 388 // guest mode. |
387 NOTREACHED(); | 389 NOTREACHED(); |
388 } | 390 } |
389 } | 391 } |
390 | 392 |
391 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 393 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
392 base::string16 email_address; | 394 base::string16 email_address; |
393 base::string16 display_name; | 395 base::string16 display_name; |
(...skipping 17 matching lines...) Expand all Loading... | |
411 // It's possible that a user breaks into the user-manager page using the | 413 // 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 | 414 // JavaScript Inspector and causes a "locked" profile to call this |
413 // unauthenticated version of "launch" instead of the proper one. Thus, | 415 // 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 | 416 // 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. | 417 // not needing authentication. If it is, just ignore the "launch" request. |
416 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 418 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
417 return; | 419 return; |
418 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 420 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
419 | 421 |
420 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 422 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
421 profiles::SwitchToProfile(path, | 423 profiles::SwitchToProfile( |
422 desktop_type_, | 424 path, |
423 false, /* reuse any existing windows */ | 425 desktop_type_, |
424 base::Bind(&OnSwitchToProfileComplete), | 426 false, /* reuse any existing windows */ |
425 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 427 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
428 weak_ptr_factory_.GetWeakPtr()), | |
429 ProfileMetrics::SWITCH_PROFILE_MANAGER); | |
426 } | 430 } |
427 | 431 |
428 void UserManagerScreenHandler::HandleAttemptUnlock( | 432 void UserManagerScreenHandler::HandleAttemptUnlock( |
429 const base::ListValue* args) { | 433 const base::ListValue* args) { |
430 std::string email; | 434 std::string email; |
431 CHECK(args->GetString(0, &email)); | 435 CHECK(args->GetString(0, &email)); |
432 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); | 436 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); |
433 } | 437 } |
434 | 438 |
435 void UserManagerScreenHandler::HandleHardlockUserPod( | 439 void UserManagerScreenHandler::HandleHardlockUserPod( |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 ProfileMetrics::LogProfileAuthResult(auth); | 663 ProfileMetrics::LogProfileAuthResult(auth); |
660 password_attempt_.clear(); | 664 password_attempt_.clear(); |
661 | 665 |
662 if (success) { | 666 if (success) { |
663 ProfileInfoCache& info_cache = | 667 ProfileInfoCache& info_cache = |
664 g_browser_process->profile_manager()->GetProfileInfoCache(); | 668 g_browser_process->profile_manager()->GetProfileInfoCache(); |
665 info_cache.SetProfileSigninRequiredAtIndex( | 669 info_cache.SetProfileSigninRequiredAtIndex( |
666 authenticating_profile_index_, false); | 670 authenticating_profile_index_, false); |
667 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 671 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
668 authenticating_profile_index_); | 672 authenticating_profile_index_); |
669 profiles::SwitchToProfile(path, desktop_type_, true, | 673 profiles::SwitchToProfile( |
670 base::Bind(&OnSwitchToProfileComplete), | 674 path, |
671 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 675 desktop_type_, |
676 true, | |
677 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | |
678 weak_ptr_factory_.GetWeakPtr()), | |
679 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | |
672 } else { | 680 } else { |
673 web_ui()->CallJavascriptFunction( | 681 web_ui()->CallJavascriptFunction( |
674 "cr.ui.Oobe.showSignInError", | 682 "cr.ui.Oobe.showSignInError", |
675 base::FundamentalValue(0), | 683 base::FundamentalValue(0), |
676 base::StringValue( | 684 base::StringValue( |
677 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 685 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
678 base::StringValue(""), | 686 base::StringValue(""), |
679 base::FundamentalValue(0)); | 687 base::FundamentalValue(0)); |
680 } | 688 } |
681 } | 689 } |
690 | |
691 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { | |
692 chrome::HideUserManager(); | |
693 if (url_hash_ == | |
noms (inactive)
2014/09/12 14:44:16
Why don't you just save the hash as an std::string
Mike Lerman
2014/09/15 13:44:04
Because that's too easy!
Done.
| |
694 base::UTF8ToUTF16(profiles::kUserManagerSelectProfileTaskManager)) { | |
695 base::MessageLoop::current()->PostTask( | |
696 FROM_HERE, base::Bind(&chrome::ShowTaskManager, browser)); | |
697 } else if (url_hash_ == | |
698 base::UTF8ToUTF16(profiles::kUserManagerSelectProfileAboutChrome)) { | |
699 if (browser) { | |
700 base::MessageLoop::current()->PostTask( | |
701 FROM_HERE, base::Bind(&chrome::ShowAboutChrome, browser)); | |
702 } else { | |
703 NOTREACHED(); | |
704 } | |
705 } | |
706 } | |
707 | |
708 void UserManagerScreenHandler::Observe( | |
709 int type, | |
710 const content::NotificationSource& source, | |
711 const content::NotificationDetails& details) { | |
712 switch (type) { | |
713 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: | |
714 OnBrowserWindowReady(content::Source<Browser>(source).ptr()); | |
715 // Only respond to one Browser Window Ready event. | |
716 registrar_.Remove(this, | |
717 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
718 content::NotificationService::AllSources()); | |
719 break; | |
720 default: | |
721 NOTREACHED(); | |
722 } | |
723 } | |
724 | |
725 // This callback is run after switching to a new profile has finished. This | |
726 // means either a new browser has been created (but not the window), or an | |
727 // existing one has been found. The HideUserManager task needs to be posted | |
728 // since closing the User Manager before the window is created can flakily | |
729 // cause Chrome to close. | |
730 void UserManagerScreenHandler::OnSwitchToProfileComplete( | |
731 Profile* profile, Profile::CreateStatus profile_create_status) { | |
732 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | |
733 if (browser && browser->window()) { | |
734 OnBrowserWindowReady(browser); | |
735 } else { | |
736 registrar_.Add(this, | |
737 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
738 content::NotificationService::AllSources()); | |
739 } | |
740 } | |
OLD | NEW |