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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "base/value_conversions.h" | 10 #include "base/value_conversions.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #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" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 15 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
15 #include "chrome/browser/profiles/profile_info_cache.h" | 16 #include "chrome/browser/profiles/profile_info_cache.h" |
16 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 17 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/profiles/profile_window.h" | 19 #include "chrome/browser/profiles/profile_window.h" |
19 #include "chrome/browser/profiles/profiles_state.h" | 20 #include "chrome/browser/profiles/profiles_state.h" |
20 #include "chrome/browser/signin/local_auth.h" | 21 #include "chrome/browser/signin/local_auth.h" |
21 #include "chrome/browser/ui/browser_dialogs.h" | 22 #include "chrome/browser/ui/browser_dialogs.h" |
22 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/singleton_tabs.h" | 24 #include "chrome/browser/ui/singleton_tabs.h" |
| 25 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
27 #include "google_apis/gaia/gaia_auth_fetcher.h" | 29 #include "google_apis/gaia/gaia_auth_fetcher.h" |
28 #include "google_apis/gaia/gaia_constants.h" | 30 #include "google_apis/gaia/gaia_constants.h" |
29 #include "grit/browser_resources.h" | 31 #include "grit/browser_resources.h" |
30 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
31 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
32 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
33 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 ProfileInfoCache& info_cache = | 138 ProfileInfoCache& info_cache = |
137 g_browser_process->profile_manager()->GetProfileInfoCache(); | 139 g_browser_process->profile_manager()->GetProfileInfoCache(); |
138 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 140 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
139 info_cache, base::UTF8ToUTF16(email), base::string16()); | 141 info_cache, base::UTF8ToUTF16(email), base::string16()); |
140 Profile* profile = g_browser_process->profile_manager() | 142 Profile* profile = g_browser_process->profile_manager() |
141 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); | 143 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); |
142 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | 144 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( |
143 profile); | 145 profile); |
144 } | 146 } |
145 | 147 |
| 148 bool IsGuestModeEnabled() { |
| 149 PrefService* service = g_browser_process->local_state(); |
| 150 DCHECK(service); |
| 151 return service->GetBoolean(prefs::kBrowserGuestModeEnabled); |
| 152 } |
| 153 |
146 } // namespace | 154 } // namespace |
147 | 155 |
148 // ProfileUpdateObserver ------------------------------------------------------ | 156 // ProfileUpdateObserver ------------------------------------------------------ |
149 | 157 |
150 class UserManagerScreenHandler::ProfileUpdateObserver | 158 class UserManagerScreenHandler::ProfileUpdateObserver |
151 : public ProfileInfoCacheObserver { | 159 : public ProfileInfoCacheObserver { |
152 public: | 160 public: |
153 ProfileUpdateObserver( | 161 ProfileUpdateObserver( |
154 ProfileManager* profile_manager, UserManagerScreenHandler* handler) | 162 ProfileManager* profile_manager, UserManagerScreenHandler* handler) |
155 : profile_manager_(profile_manager), | 163 : profile_manager_(profile_manager), |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 284 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
277 info_cache, base::UTF8ToUTF16(user_email), base::string16()); | 285 info_cache, base::UTF8ToUTF16(user_email), base::string16()); |
278 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); | 286 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); |
279 | 287 |
280 authenticating_profile_index_ = profile_index; | 288 authenticating_profile_index_ = profile_index; |
281 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 289 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
282 } | 290 } |
283 | 291 |
284 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 292 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
285 SendUserList(); | 293 SendUserList(); |
286 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); | 294 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen", |
| 295 base::FundamentalValue(IsGuestModeEnabled())); |
287 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 296 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
288 web_ui()->GetWebContents()->GetNativeView()); | 297 web_ui()->GetWebContents()->GetNativeView()); |
289 | 298 |
290 ScreenlockBridge::Get()->SetLockHandler(this); | 299 ScreenlockBridge::Get()->SetLockHandler(this); |
291 } | 300 } |
292 | 301 |
293 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 302 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
294 profiles::CreateAndSwitchToNewProfile(desktop_type_, | 303 profiles::CreateAndSwitchToNewProfile(desktop_type_, |
295 base::Bind(&OnSwitchToProfileComplete), | 304 base::Bind(&OnSwitchToProfileComplete), |
296 ProfileMetrics::ADD_NEW_USER_MANAGER); | 305 ProfileMetrics::ADD_NEW_USER_MANAGER); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 if (!profiles::IsMultipleProfilesEnabled()) | 372 if (!profiles::IsMultipleProfilesEnabled()) |
364 return; | 373 return; |
365 | 374 |
366 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 375 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
367 profile_path, | 376 profile_path, |
368 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 377 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
369 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); | 378 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); |
370 } | 379 } |
371 | 380 |
372 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 381 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
373 profiles::SwitchToGuestProfile(desktop_type_, | 382 if (IsGuestModeEnabled()) { |
374 base::Bind(&OnSwitchToProfileComplete)); | 383 profiles::SwitchToGuestProfile(desktop_type_, |
375 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | 384 base::Bind(&OnSwitchToProfileComplete)); |
| 385 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); |
| 386 } else { |
| 387 // The UI should have prevented the user from allowing the selection of |
| 388 // guest mode. |
| 389 NOTREACHED(); |
| 390 } |
376 } | 391 } |
377 | 392 |
378 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 393 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
379 base::string16 email_address; | 394 base::string16 email_address; |
380 base::string16 display_name; | 395 base::string16 display_name; |
381 | 396 |
382 if (!args->GetString(0, &email_address) || | 397 if (!args->GetString(0, &email_address) || |
383 !args->GetString(1, &display_name)) { | 398 !args->GetString(1, &display_name)) { |
384 NOTREACHED(); | 399 NOTREACHED(); |
385 return; | 400 return; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 632 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
618 | 633 |
619 // The row of user pods should display the active user first. | 634 // The row of user pods should display the active user first. |
620 if (is_active_user) | 635 if (is_active_user) |
621 users_list.Insert(0, profile_value); | 636 users_list.Insert(0, profile_value); |
622 else | 637 else |
623 users_list.Append(profile_value); | 638 users_list.Append(profile_value); |
624 } | 639 } |
625 | 640 |
626 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 641 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
627 users_list, base::FundamentalValue(true)); | 642 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
628 } | 643 } |
629 | 644 |
630 void UserManagerScreenHandler::ReportAuthenticationResult( | 645 void UserManagerScreenHandler::ReportAuthenticationResult( |
631 bool success, | 646 bool success, |
632 ProfileMetrics::ProfileAuth auth) { | 647 ProfileMetrics::ProfileAuth auth) { |
633 ProfileMetrics::LogProfileAuthResult(auth); | 648 ProfileMetrics::LogProfileAuthResult(auth); |
634 password_attempt_.clear(); | 649 password_attempt_.clear(); |
635 | 650 |
636 if (success) { | 651 if (success) { |
637 ProfileInfoCache& info_cache = | 652 ProfileInfoCache& info_cache = |
638 g_browser_process->profile_manager()->GetProfileInfoCache(); | 653 g_browser_process->profile_manager()->GetProfileInfoCache(); |
639 info_cache.SetProfileSigninRequiredAtIndex( | 654 info_cache.SetProfileSigninRequiredAtIndex( |
640 authenticating_profile_index_, false); | 655 authenticating_profile_index_, false); |
641 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 656 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
642 authenticating_profile_index_); | 657 authenticating_profile_index_); |
643 profiles::SwitchToProfile(path, desktop_type_, true, | 658 profiles::SwitchToProfile(path, desktop_type_, true, |
644 base::Bind(&OnSwitchToProfileComplete), | 659 base::Bind(&OnSwitchToProfileComplete), |
645 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 660 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
646 } else { | 661 } else { |
647 web_ui()->CallJavascriptFunction( | 662 web_ui()->CallJavascriptFunction( |
648 "cr.ui.Oobe.showSignInError", | 663 "cr.ui.Oobe.showSignInError", |
649 base::FundamentalValue(0), | 664 base::FundamentalValue(0), |
650 base::StringValue( | 665 base::StringValue( |
651 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 666 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
652 base::StringValue(""), | 667 base::StringValue(""), |
653 base::FundamentalValue(0)); | 668 base::FundamentalValue(0)); |
654 } | 669 } |
655 } | 670 } |
OLD | NEW |