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); | |
221 return; | 234 return; |
222 } | 235 } |
223 | 236 |
224 info_cache.SetProfileSigninRequiredAtIndex(profile_index, false); | 237 ReportAuthenticationResult(true); |
225 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | |
226 profiles::SwitchToProfile(path, desktop_type_, true, | |
227 base::Bind(&chrome::HideUserManager)); | |
228 } | 238 } |
229 | 239 |
230 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { | 240 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { |
231 DCHECK(args); | 241 DCHECK(args); |
232 const base::Value* profile_path_value; | 242 const base::Value* profile_path_value; |
233 if (!args->Get(0, &profile_path_value)) | 243 if (!args->Get(0, &profile_path_value)) |
234 return; | 244 return; |
235 | 245 |
236 base::FilePath profile_path; | 246 base::FilePath profile_path; |
237 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | 247 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 | 291 // 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. | 292 // not needing authentication. If it is, just ignore the "launch" request. |
283 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 293 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
284 return; | 294 return; |
285 | 295 |
286 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 296 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
287 profiles::SwitchToProfile( | 297 profiles::SwitchToProfile( |
288 path, desktop_type_, true, base::Bind(&chrome::HideUserManager)); | 298 path, desktop_type_, true, base::Bind(&chrome::HideUserManager)); |
289 } | 299 } |
290 | 300 |
301 void UserManagerScreenHandler::OnClientLoginSuccess( | |
302 const ClientLoginResult& result) { | |
303 ReportAuthenticationResult(true); | |
Roger Tawa OOO till Jul 10th
2014/01/07 19:20:03
Should the code save the new password here so that
bcwhite
2014/01/07 19:36:41
Good idea. Done.
| |
304 } | |
305 | |
306 void UserManagerScreenHandler::OnClientLoginFailure( | |
307 const GoogleServiceAuthError& error) { | |
308 ReportAuthenticationResult(false); | |
309 } | |
310 | |
291 void UserManagerScreenHandler::RegisterMessages() { | 311 void UserManagerScreenHandler::RegisterMessages() { |
292 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, | 312 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, |
293 base::Bind(&UserManagerScreenHandler::HandleInitialize, | 313 base::Bind(&UserManagerScreenHandler::HandleInitialize, |
294 base::Unretained(this))); | 314 base::Unretained(this))); |
295 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, | 315 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, |
296 base::Bind(&UserManagerScreenHandler::HandleAddUser, | 316 base::Bind(&UserManagerScreenHandler::HandleAddUser, |
297 base::Unretained(this))); | 317 base::Unretained(this))); |
298 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, | 318 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, |
299 base::Bind(&UserManagerScreenHandler::HandleAuthenticatedLaunchUser, | 319 base::Bind(&UserManagerScreenHandler::HandleAuthenticatedLaunchUser, |
300 base::Unretained(this))); | 320 base::Unretained(this))); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 IDS_LOGIN_POD_USER_REMOVE_WARNING)); | 385 IDS_LOGIN_POD_USER_REMOVE_WARNING)); |
366 | 386 |
367 // Strings needed for the user_pod_template public account div, but not ever | 387 // Strings needed for the user_pod_template public account div, but not ever |
368 // actually displayed for desktop users. | 388 // actually displayed for desktop users. |
369 localized_strings->SetString("publicAccountReminder", base::string16()); | 389 localized_strings->SetString("publicAccountReminder", base::string16()); |
370 localized_strings->SetString("publicAccountEnter", base::string16()); | 390 localized_strings->SetString("publicAccountEnter", base::string16()); |
371 localized_strings->SetString("publicAccountEnterAccessibleName", | 391 localized_strings->SetString("publicAccountEnterAccessibleName", |
372 base::string16()); | 392 base::string16()); |
373 localized_strings->SetString("multiple-signin-banner-text", | 393 localized_strings->SetString("multiple-signin-banner-text", |
374 base::string16()); | 394 base::string16()); |
375 } | 395 } |
376 | 396 |
377 void UserManagerScreenHandler::SendUserList() { | 397 void UserManagerScreenHandler::SendUserList() { |
378 base::ListValue users_list; | 398 base::ListValue users_list; |
379 base::FilePath active_profile_path = | 399 base::FilePath active_profile_path = |
380 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | 400 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); |
381 const ProfileInfoCache& info_cache = | 401 const ProfileInfoCache& info_cache = |
382 g_browser_process->profile_manager()->GetProfileInfoCache(); | 402 g_browser_process->profile_manager()->GetProfileInfoCache(); |
383 | 403 |
384 // If the active user is a managed user, then they may not perform | 404 // If the active user is a managed user, then they may not perform |
385 // certain actions (i.e. delete another user). | 405 // 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. | 431 // The row of user pods should display the active user first. |
412 if (is_active_user) | 432 if (is_active_user) |
413 users_list.Insert(0, profile_value); | 433 users_list.Insert(0, profile_value); |
414 else | 434 else |
415 users_list.Append(profile_value); | 435 users_list.Append(profile_value); |
416 } | 436 } |
417 | 437 |
418 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 438 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
419 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); | 439 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); |
420 } | 440 } |
441 | |
442 void UserManagerScreenHandler::ReportAuthenticationResult(bool success) { | |
443 if (success) { | |
444 ProfileInfoCache& info_cache = | |
445 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
446 info_cache.SetProfileSigninRequiredAtIndex( | |
447 authenticating_profile_index_, false); | |
448 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | |
449 authenticating_profile_index_); | |
450 profiles::SwitchToProfile(path, desktop_type_, true, | |
451 base::Bind(&chrome::HideUserManager)); | |
452 } else { | |
453 web_ui()->CallJavascriptFunction( | |
454 "cr.ui.Oobe.showSignInError", | |
455 base::FundamentalValue(0), | |
456 base::StringValue( | |
457 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | |
458 base::StringValue(""), | |
459 base::FundamentalValue(0)); | |
460 } | |
461 } | |
OLD | NEW |