| 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/value_conversions.h" | 8 #include "base/value_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/profiles/avatar_menu.h" | 11 #include "chrome/browser/profiles/avatar_menu.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | 13 #include "chrome/browser/profiles/profile_info_cache.h" |
| 14 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 14 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 15 #include "chrome/browser/profiles/profile_info_util.h" | 15 #include "chrome/browser/profiles/profile_info_util.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/profiles/profile_window.h" | 17 #include "chrome/browser/profiles/profile_window.h" |
| 18 #include "chrome/browser/profiles/profiles_state.h" | 18 #include "chrome/browser/profiles/profiles_state.h" |
| 19 #include "chrome/browser/signin/local_auth.h" | 19 #include "chrome/browser/signin/local_auth.h" |
| 20 #include "chrome/browser/ui/browser_dialogs.h" | 20 #include "chrome/browser/ui/browser_dialogs.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/singleton_tabs.h" | 22 #include "chrome/browser/ui/singleton_tabs.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
| 25 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
| 26 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 27 #include "google_apis/gaia/gaia_constants.h" |
| 26 #include "grit/browser_resources.h" | 28 #include "grit/browser_resources.h" |
| 27 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 29 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/webui/web_ui_util.h" | 33 #include "ui/base/webui/web_ui_util.h" |
| 32 #include "ui/gfx/image/image_util.h" | 34 #include "ui/gfx/image/image_util.h" |
| 33 | 35 |
| 34 #if defined(ENABLE_MANAGED_USERS) | 36 #if defined(ENABLE_MANAGED_USERS) |
| 35 #include "chrome/browser/managed_mode/managed_user_service.h" | 37 #include "chrome/browser/managed_mode/managed_user_service.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return; | 205 return; |
| 204 | 206 |
| 205 ProfileInfoCache& info_cache = | 207 ProfileInfoCache& info_cache = |
| 206 g_browser_process->profile_manager()->GetProfileInfoCache(); | 208 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 207 size_t profile_index = GetIndexOfProfileWithEmailAndName( | 209 size_t profile_index = GetIndexOfProfileWithEmailAndName( |
| 208 info_cache, email_address, display_name); | 210 info_cache, email_address, display_name); |
| 209 if (profile_index >= info_cache.GetNumberOfProfiles()) { | 211 if (profile_index >= info_cache.GetNumberOfProfiles()) { |
| 210 NOTREACHED(); | 212 NOTREACHED(); |
| 211 return; | 213 return; |
| 212 } | 214 } |
| 215 |
| 216 authenticating_profile_index_ = profile_index; |
| 213 if (!chrome::ValidateLocalAuthCredentials(profile_index, password)) { | 217 if (!chrome::ValidateLocalAuthCredentials(profile_index, password)) { |
| 214 web_ui()->CallJavascriptFunction( | 218 // Make a second attempt via an on-line authentication call. This handles |
| 215 "cr.ui.Oobe.showSignInError", | 219 // profiles that are missing sign-in credentials and also cases where the |
| 216 base::FundamentalValue(0), | 220 // password has been changed externally. |
| 217 base::StringValue( | 221 client_login_.reset(new GaiaAuthFetcher( |
| 218 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 222 this, |
| 219 base::StringValue(""), | 223 GaiaConstants::kChromeSource, |
| 220 base::FundamentalValue(0)); | 224 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); |
| 225 std::string email_string; |
| 226 args->GetString(0, &email_string); |
| 227 client_login_->StartClientLogin( |
| 228 email_string, |
| 229 password, |
| 230 GaiaConstants::kSyncService, |
| 231 std::string(), |
| 232 std::string(), |
| 233 GaiaAuthFetcher::HostedAccountsAllowed); |
| 234 password_attempt_ = password; |
| 221 return; | 235 return; |
| 222 } | 236 } |
| 223 | 237 |
| 224 info_cache.SetProfileSigninRequiredAtIndex(profile_index, false); | 238 ReportAuthenticationResult(true); |
| 225 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | |
| 226 profiles::SwitchToProfile(path, desktop_type_, true, | |
| 227 base::Bind(&chrome::HideUserManager)); | |
| 228 } | 239 } |
| 229 | 240 |
| 230 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { | 241 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { |
| 231 DCHECK(args); | 242 DCHECK(args); |
| 232 const base::Value* profile_path_value; | 243 const base::Value* profile_path_value; |
| 233 if (!args->Get(0, &profile_path_value)) | 244 if (!args->Get(0, &profile_path_value)) |
| 234 return; | 245 return; |
| 235 | 246 |
| 236 base::FilePath profile_path; | 247 base::FilePath profile_path; |
| 237 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | 248 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // we have to validate in (secure) C++ code that it really is a profile | 292 // we have to validate in (secure) C++ code that it really is a profile |
| 282 // not needing authentication. If it is, just ignore the "launch" request. | 293 // not needing authentication. If it is, just ignore the "launch" request. |
| 283 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 294 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
| 284 return; | 295 return; |
| 285 | 296 |
| 286 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 297 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
| 287 profiles::SwitchToProfile( | 298 profiles::SwitchToProfile( |
| 288 path, desktop_type_, true, base::Bind(&chrome::HideUserManager)); | 299 path, desktop_type_, true, base::Bind(&chrome::HideUserManager)); |
| 289 } | 300 } |
| 290 | 301 |
| 302 void UserManagerScreenHandler::OnClientLoginSuccess( |
| 303 const ClientLoginResult& result) { |
| 304 chrome::SetLocalAuthCredentials(authenticating_profile_index_, |
| 305 password_attempt_); |
| 306 ReportAuthenticationResult(true); |
| 307 } |
| 308 |
| 309 void UserManagerScreenHandler::OnClientLoginFailure( |
| 310 const GoogleServiceAuthError& error) { |
| 311 ReportAuthenticationResult(false); |
| 312 } |
| 313 |
| 291 void UserManagerScreenHandler::RegisterMessages() { | 314 void UserManagerScreenHandler::RegisterMessages() { |
| 292 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, | 315 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, |
| 293 base::Bind(&UserManagerScreenHandler::HandleInitialize, | 316 base::Bind(&UserManagerScreenHandler::HandleInitialize, |
| 294 base::Unretained(this))); | 317 base::Unretained(this))); |
| 295 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, | 318 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, |
| 296 base::Bind(&UserManagerScreenHandler::HandleAddUser, | 319 base::Bind(&UserManagerScreenHandler::HandleAddUser, |
| 297 base::Unretained(this))); | 320 base::Unretained(this))); |
| 298 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, | 321 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, |
| 299 base::Bind(&UserManagerScreenHandler::HandleAuthenticatedLaunchUser, | 322 base::Bind(&UserManagerScreenHandler::HandleAuthenticatedLaunchUser, |
| 300 base::Unretained(this))); | 323 base::Unretained(this))); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 IDS_LOGIN_POD_USER_REMOVE_WARNING)); | 388 IDS_LOGIN_POD_USER_REMOVE_WARNING)); |
| 366 | 389 |
| 367 // Strings needed for the user_pod_template public account div, but not ever | 390 // Strings needed for the user_pod_template public account div, but not ever |
| 368 // actually displayed for desktop users. | 391 // actually displayed for desktop users. |
| 369 localized_strings->SetString("publicAccountReminder", base::string16()); | 392 localized_strings->SetString("publicAccountReminder", base::string16()); |
| 370 localized_strings->SetString("publicAccountEnter", base::string16()); | 393 localized_strings->SetString("publicAccountEnter", base::string16()); |
| 371 localized_strings->SetString("publicAccountEnterAccessibleName", | 394 localized_strings->SetString("publicAccountEnterAccessibleName", |
| 372 base::string16()); | 395 base::string16()); |
| 373 localized_strings->SetString("multiple-signin-banner-text", | 396 localized_strings->SetString("multiple-signin-banner-text", |
| 374 base::string16()); | 397 base::string16()); |
| 375 } | 398 } |
| 376 | 399 |
| 377 void UserManagerScreenHandler::SendUserList() { | 400 void UserManagerScreenHandler::SendUserList() { |
| 378 base::ListValue users_list; | 401 base::ListValue users_list; |
| 379 base::FilePath active_profile_path = | 402 base::FilePath active_profile_path = |
| 380 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | 403 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); |
| 381 const ProfileInfoCache& info_cache = | 404 const ProfileInfoCache& info_cache = |
| 382 g_browser_process->profile_manager()->GetProfileInfoCache(); | 405 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 383 | 406 |
| 384 // If the active user is a managed user, then they may not perform | 407 // If the active user is a managed user, then they may not perform |
| 385 // certain actions (i.e. delete another user). | 408 // certain actions (i.e. delete another user). |
| (...skipping 25 matching lines...) Expand all Loading... |
| 411 // The row of user pods should display the active user first. | 434 // The row of user pods should display the active user first. |
| 412 if (is_active_user) | 435 if (is_active_user) |
| 413 users_list.Insert(0, profile_value); | 436 users_list.Insert(0, profile_value); |
| 414 else | 437 else |
| 415 users_list.Append(profile_value); | 438 users_list.Append(profile_value); |
| 416 } | 439 } |
| 417 | 440 |
| 418 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 441 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
| 419 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); | 442 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); |
| 420 } | 443 } |
| 444 |
| 445 void UserManagerScreenHandler::ReportAuthenticationResult(bool success) { |
| 446 if (success) { |
| 447 ProfileInfoCache& info_cache = |
| 448 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 449 info_cache.SetProfileSigninRequiredAtIndex( |
| 450 authenticating_profile_index_, false); |
| 451 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
| 452 authenticating_profile_index_); |
| 453 profiles::SwitchToProfile(path, desktop_type_, true, |
| 454 base::Bind(&chrome::HideUserManager)); |
| 455 } else { |
| 456 web_ui()->CallJavascriptFunction( |
| 457 "cr.ui.Oobe.showSignInError", |
| 458 base::FundamentalValue(0), |
| 459 base::StringValue( |
| 460 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
| 461 base::StringValue(""), |
| 462 base::FundamentalValue(0)); |
| 463 } |
| 464 |
| 465 password_attempt_.clear(); |
| 466 } |
| OLD | NEW |