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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 UserManagerScreenHandler::~UserManagerScreenHandler() { | 318 UserManagerScreenHandler::~UserManagerScreenHandler() { |
319 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 319 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
320 } | 320 } |
321 | 321 |
322 void UserManagerScreenHandler::ShowBannerMessage( | 322 void UserManagerScreenHandler::ShowBannerMessage( |
323 const base::string16& message) { | 323 const base::string16& message) { |
324 web_ui()->CallJavascriptFunctionUnsafe( | 324 web_ui()->CallJavascriptFunctionUnsafe( |
325 "login.AccountPickerScreen.showBannerMessage", | 325 "login.AccountPickerScreen.showBannerMessage", base::Value(message)); |
326 base::StringValue(message)); | |
327 } | 326 } |
328 | 327 |
329 void UserManagerScreenHandler::ShowUserPodCustomIcon( | 328 void UserManagerScreenHandler::ShowUserPodCustomIcon( |
330 const AccountId& account_id, | 329 const AccountId& account_id, |
331 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& | 330 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& |
332 icon_options) { | 331 icon_options) { |
333 std::unique_ptr<base::DictionaryValue> icon = | 332 std::unique_ptr<base::DictionaryValue> icon = |
334 icon_options.ToDictionaryValue(); | 333 icon_options.ToDictionaryValue(); |
335 if (!icon || icon->empty()) | 334 if (!icon || icon->empty()) |
336 return; | 335 return; |
337 web_ui()->CallJavascriptFunctionUnsafe( | 336 web_ui()->CallJavascriptFunctionUnsafe( |
338 "login.AccountPickerScreen.showUserPodCustomIcon", | 337 "login.AccountPickerScreen.showUserPodCustomIcon", |
339 base::StringValue(account_id.GetUserEmail()), *icon); | 338 base::Value(account_id.GetUserEmail()), *icon); |
340 } | 339 } |
341 | 340 |
342 void UserManagerScreenHandler::HideUserPodCustomIcon( | 341 void UserManagerScreenHandler::HideUserPodCustomIcon( |
343 const AccountId& account_id) { | 342 const AccountId& account_id) { |
344 web_ui()->CallJavascriptFunctionUnsafe( | 343 web_ui()->CallJavascriptFunctionUnsafe( |
345 "login.AccountPickerScreen.hideUserPodCustomIcon", | 344 "login.AccountPickerScreen.hideUserPodCustomIcon", |
346 base::StringValue(account_id.GetUserEmail())); | 345 base::Value(account_id.GetUserEmail())); |
347 } | 346 } |
348 | 347 |
349 void UserManagerScreenHandler::EnableInput() { | 348 void UserManagerScreenHandler::EnableInput() { |
350 // Nothing here because UI is not disabled when starting to authenticate. | 349 // Nothing here because UI is not disabled when starting to authenticate. |
351 } | 350 } |
352 | 351 |
353 void UserManagerScreenHandler::SetAuthType( | 352 void UserManagerScreenHandler::SetAuthType( |
354 const AccountId& account_id, | 353 const AccountId& account_id, |
355 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type, | 354 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type, |
356 const base::string16& auth_value) { | 355 const base::string16& auth_value) { |
357 if (GetAuthType(account_id) == | 356 if (GetAuthType(account_id) == |
358 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) | 357 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) |
359 return; | 358 return; |
360 | 359 |
361 user_auth_type_map_[account_id.GetUserEmail()] = auth_type; | 360 user_auth_type_map_[account_id.GetUserEmail()] = auth_type; |
362 web_ui()->CallJavascriptFunctionUnsafe( | 361 web_ui()->CallJavascriptFunctionUnsafe( |
363 "login.AccountPickerScreen.setAuthType", | 362 "login.AccountPickerScreen.setAuthType", |
364 base::StringValue(account_id.GetUserEmail()), base::Value(auth_type), | 363 base::Value(account_id.GetUserEmail()), base::Value(auth_type), |
365 base::StringValue(auth_value)); | 364 base::Value(auth_value)); |
366 } | 365 } |
367 | 366 |
368 proximity_auth::ScreenlockBridge::LockHandler::AuthType | 367 proximity_auth::ScreenlockBridge::LockHandler::AuthType |
369 UserManagerScreenHandler::GetAuthType(const AccountId& account_id) const { | 368 UserManagerScreenHandler::GetAuthType(const AccountId& account_id) const { |
370 const auto it = user_auth_type_map_.find(account_id.GetUserEmail()); | 369 const auto it = user_auth_type_map_.find(account_id.GetUserEmail()); |
371 if (it == user_auth_type_map_.end()) | 370 if (it == user_auth_type_map_.end()) |
372 return proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | 371 return proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; |
373 return it->second; | 372 return it->second; |
374 } | 373 } |
375 | 374 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 base::FilePath profile_path; | 492 base::FilePath profile_path; |
494 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) { | 493 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) { |
495 NOTREACHED(); | 494 NOTREACHED(); |
496 return; | 495 return; |
497 } | 496 } |
498 | 497 |
499 DCHECK(profiles::IsMultipleProfilesEnabled()); | 498 DCHECK(profiles::IsMultipleProfilesEnabled()); |
500 | 499 |
501 if (profiles::AreAllNonChildNonSupervisedProfilesLocked()) { | 500 if (profiles::AreAllNonChildNonSupervisedProfilesLocked()) { |
502 web_ui()->CallJavascriptFunctionUnsafe( | 501 web_ui()->CallJavascriptFunctionUnsafe( |
503 "cr.webUIListenerCallback", | 502 "cr.webUIListenerCallback", base::Value("show-error-dialog"), |
504 base::StringValue("show-error-dialog"), | 503 base::Value(l10n_util::GetStringUTF8( |
505 base::StringValue(l10n_util::GetStringUTF8( | |
506 IDS_USER_MANAGER_REMOVE_PROFILE_PROFILES_LOCKED_ERROR))); | 504 IDS_USER_MANAGER_REMOVE_PROFILE_PROFILES_LOCKED_ERROR))); |
507 return; | 505 return; |
508 } | 506 } |
509 | 507 |
510 // The callback is run if the only profile has been deleted, and a new | 508 // The callback is run if the only profile has been deleted, and a new |
511 // profile has been created to replace it. | 509 // profile has been created to replace it. |
512 webui::DeleteProfileAtPath(profile_path, | 510 webui::DeleteProfileAtPath(profile_path, |
513 web_ui(), | 511 web_ui(), |
514 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 512 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
515 } | 513 } |
(...skipping 12 matching lines...) Expand all Loading... |
528 | 526 |
529 void UserManagerScreenHandler::HandleAreAllProfilesLocked( | 527 void UserManagerScreenHandler::HandleAreAllProfilesLocked( |
530 const base::ListValue* args) { | 528 const base::ListValue* args) { |
531 std::string webui_callback_id; | 529 std::string webui_callback_id; |
532 CHECK_EQ(1U, args->GetSize()); | 530 CHECK_EQ(1U, args->GetSize()); |
533 bool success = args->GetString(0, &webui_callback_id); | 531 bool success = args->GetString(0, &webui_callback_id); |
534 DCHECK(success); | 532 DCHECK(success); |
535 | 533 |
536 AllowJavascript(); | 534 AllowJavascript(); |
537 ResolveJavascriptCallback( | 535 ResolveJavascriptCallback( |
538 base::StringValue(webui_callback_id), | 536 base::Value(webui_callback_id), |
539 base::Value(profiles::AreAllNonChildNonSupervisedProfilesLocked())); | 537 base::Value(profiles::AreAllNonChildNonSupervisedProfilesLocked())); |
540 } | 538 } |
541 | 539 |
542 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 540 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
543 const base::Value* profile_path_value = NULL; | 541 const base::Value* profile_path_value = NULL; |
544 if (!args->Get(0, &profile_path_value)) | 542 if (!args->Get(0, &profile_path_value)) |
545 return; | 543 return; |
546 | 544 |
547 base::FilePath profile_path; | 545 base::FilePath profile_path; |
548 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | 546 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 const base::Value* profile_path_value; | 594 const base::Value* profile_path_value; |
597 | 595 |
598 if (!args->Get(0, &profile_path_value)) | 596 if (!args->Get(0, &profile_path_value)) |
599 return; | 597 return; |
600 | 598 |
601 base::FilePath profile_path; | 599 base::FilePath profile_path; |
602 | 600 |
603 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | 601 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
604 return; | 602 return; |
605 | 603 |
606 base::StringValue return_profile_path(profile_path.value()); | 604 base::Value return_profile_path(profile_path.value()); |
607 Profile* profile = g_browser_process->profile_manager()-> | 605 Profile* profile = g_browser_process->profile_manager()-> |
608 GetProfileByPath(profile_path); | 606 GetProfileByPath(profile_path); |
609 | 607 |
610 if (!profile) | 608 if (!profile) |
611 return; | 609 return; |
612 | 610 |
613 if (!chrome::FindAnyBrowser(profile, true)) { | 611 if (!chrome::FindAnyBrowser(profile, true)) { |
614 // If no windows are open for that profile, the statistics in | 612 // If no windows are open for that profile, the statistics in |
615 // ProfileAttributesStorage are up to date. The statistics in | 613 // ProfileAttributesStorage are up to date. The statistics in |
616 // ProfileAttributesStorage are returned because the copy in user_pod_row.js | 614 // ProfileAttributesStorage are returned because the copy in user_pod_row.js |
617 // may be outdated. However, if some statistics are missing in | 615 // may be outdated. However, if some statistics are missing in |
618 // ProfileAttributesStorage (i.e. |item.success| is false), then the actual | 616 // ProfileAttributesStorage (i.e. |item.success| is false), then the actual |
619 // statistics are queried instead. | 617 // statistics are queried instead. |
620 base::DictionaryValue return_value; | 618 base::DictionaryValue return_value; |
621 profiles::ProfileCategoryStats stats = | 619 profiles::ProfileCategoryStats stats = |
622 ProfileStatistics::GetProfileStatisticsFromAttributesStorage( | 620 ProfileStatistics::GetProfileStatisticsFromAttributesStorage( |
623 profile_path); | 621 profile_path); |
624 bool stats_success = true; | 622 bool stats_success = true; |
625 for (const auto& item : stats) { | 623 for (const auto& item : stats) { |
626 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); | 624 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); |
627 stat->SetIntegerWithoutPathExpansion("count", item.count); | 625 stat->SetIntegerWithoutPathExpansion("count", item.count); |
628 stat->SetBooleanWithoutPathExpansion("success", item.success); | 626 stat->SetBooleanWithoutPathExpansion("success", item.success); |
629 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); | 627 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); |
630 stats_success &= item.success; | 628 stats_success &= item.success; |
631 } | 629 } |
632 if (stats_success) { | 630 if (stats_success) { |
633 web_ui()->CallJavascriptFunctionUnsafe( | 631 web_ui()->CallJavascriptFunctionUnsafe("updateRemoveWarningDialog", |
634 "updateRemoveWarningDialog", base::StringValue(profile_path.value()), | 632 base::Value(profile_path.value()), |
635 return_value); | 633 return_value); |
636 return; | 634 return; |
637 } | 635 } |
638 } | 636 } |
639 | 637 |
640 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( | 638 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( |
641 base::Bind( | 639 base::Bind( |
642 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, | 640 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, |
643 weak_ptr_factory_.GetWeakPtr(), profile_path)); | 641 weak_ptr_factory_.GetWeakPtr(), profile_path)); |
644 } | 642 } |
645 | 643 |
646 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( | 644 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( |
647 base::FilePath profile_path, | 645 base::FilePath profile_path, |
648 profiles::ProfileCategoryStats result) { | 646 profiles::ProfileCategoryStats result) { |
649 // Copy result into return_value. | 647 // Copy result into return_value. |
650 base::DictionaryValue return_value; | 648 base::DictionaryValue return_value; |
651 for (const auto& item : result) { | 649 for (const auto& item : result) { |
652 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); | 650 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); |
653 stat->SetIntegerWithoutPathExpansion("count", item.count); | 651 stat->SetIntegerWithoutPathExpansion("count", item.count); |
654 stat->SetBooleanWithoutPathExpansion("success", item.success); | 652 stat->SetBooleanWithoutPathExpansion("success", item.success); |
655 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); | 653 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); |
656 } | 654 } |
657 web_ui()->CallJavascriptFunctionUnsafe( | 655 web_ui()->CallJavascriptFunctionUnsafe("updateRemoveWarningDialog", |
658 "updateRemoveWarningDialog", base::StringValue(profile_path.value()), | 656 base::Value(profile_path.value()), |
659 return_value); | 657 return_value); |
660 } | 658 } |
661 | 659 |
662 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( | 660 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( |
663 const base::ListValue* args) { | 661 const base::ListValue* args) { |
664 const base::DictionaryValue* arg; | 662 const base::DictionaryValue* arg; |
665 if (!args->GetDictionary(0, &arg)) | 663 if (!args->GetDictionary(0, &arg)) |
666 return; | 664 return; |
667 | 665 |
668 std::string profile_path(""); | 666 std::string profile_path(""); |
669 bool is_synced_user = false; | 667 bool is_synced_user = false; |
670 bool has_errors = false; | 668 bool has_errors = false; |
671 | 669 |
672 if (!arg->GetString("profilePath", &profile_path) || | 670 if (!arg->GetString("profilePath", &profile_path) || |
673 !arg->GetBoolean("isSyncedUser", &is_synced_user) || | 671 !arg->GetBoolean("isSyncedUser", &is_synced_user) || |
674 !arg->GetBoolean("hasErrors", &has_errors)) | 672 !arg->GetBoolean("hasErrors", &has_errors)) |
675 return; | 673 return; |
676 | 674 |
677 int total_count = 0; | 675 int total_count = 0; |
678 if (!arg->GetInteger("totalCount", &total_count)) | 676 if (!arg->GetInteger("totalCount", &total_count)) |
679 return; | 677 return; |
680 | 678 |
681 int message_id = is_synced_user ? | 679 int message_id = is_synced_user ? |
682 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_WITH_ERRORS : | 680 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_WITH_ERRORS : |
683 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC) : | 681 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC) : |
684 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_WITH_ERRORS : | 682 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_WITH_ERRORS : |
685 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC); | 683 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC); |
686 | 684 |
687 base::StringValue message = base::StringValue( | 685 base::Value message = |
688 l10n_util::GetPluralStringFUTF16(message_id, total_count)); | 686 base::Value(l10n_util::GetPluralStringFUTF16(message_id, total_count)); |
689 | 687 |
690 web_ui()->CallJavascriptFunctionUnsafe("updateRemoveWarningDialogSetMessage", | 688 web_ui()->CallJavascriptFunctionUnsafe("updateRemoveWarningDialogSetMessage", |
691 base::StringValue(profile_path), | 689 base::Value(profile_path), message, |
692 message, base::Value(total_count)); | 690 base::Value(total_count)); |
693 } | 691 } |
694 | 692 |
695 void UserManagerScreenHandler::OnGetTokenInfoResponse( | 693 void UserManagerScreenHandler::OnGetTokenInfoResponse( |
696 std::unique_ptr<base::DictionaryValue> token_info) { | 694 std::unique_ptr<base::DictionaryValue> token_info) { |
697 // Password is unchanged so user just mistyped it. Ask again. | 695 // Password is unchanged so user just mistyped it. Ask again. |
698 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); | 696 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); |
699 } | 697 } |
700 | 698 |
701 void UserManagerScreenHandler::OnOAuthError() { | 699 void UserManagerScreenHandler::OnOAuthError() { |
702 // Password has changed. Go through online signin flow. | 700 // Password has changed. Go through online signin flow. |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 | 989 |
992 if (success) { | 990 if (success) { |
993 profiles::SwitchToProfile( | 991 profiles::SwitchToProfile( |
994 authenticating_profile_path_, true, | 992 authenticating_profile_path_, true, |
995 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 993 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
996 weak_ptr_factory_.GetWeakPtr()), | 994 weak_ptr_factory_.GetWeakPtr()), |
997 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 995 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
998 } else { | 996 } else { |
999 web_ui()->CallJavascriptFunctionUnsafe( | 997 web_ui()->CallJavascriptFunctionUnsafe( |
1000 "cr.ui.UserManager.showSignInError", base::Value(0), | 998 "cr.ui.UserManager.showSignInError", base::Value(0), |
1001 base::StringValue(l10n_util::GetStringUTF8( | 999 base::Value(l10n_util::GetStringUTF8( |
1002 auth == ProfileMetrics::AUTH_FAILED_OFFLINE | 1000 auth == ProfileMetrics::AUTH_FAILED_OFFLINE |
1003 ? IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE | 1001 ? IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE |
1004 : IDS_LOGIN_ERROR_AUTHENTICATING)), | 1002 : IDS_LOGIN_ERROR_AUTHENTICATING)), |
1005 base::StringValue(""), base::Value(0)); | 1003 base::Value(""), base::Value(0)); |
1006 } | 1004 } |
1007 } | 1005 } |
1008 | 1006 |
1009 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { | 1007 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { |
1010 DCHECK(browser); | 1008 DCHECK(browser); |
1011 DCHECK(browser->window()); | 1009 DCHECK(browser->window()); |
1012 | 1010 |
1013 // Unlock the profile after browser opens so startup can read the lock bit. | 1011 // Unlock the profile after browser opens so startup can read the lock bit. |
1014 // Any necessary authentication must have been successful to reach this point. | 1012 // Any necessary authentication must have been successful to reach this point. |
1015 if (!browser->profile()->IsGuestSession()) { | 1013 if (!browser->profile()->IsGuestSession()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 Profile* profile, Profile::CreateStatus profile_create_status) { | 1051 Profile* profile, Profile::CreateStatus profile_create_status) { |
1054 Browser* browser = chrome::FindAnyBrowser(profile, false); | 1052 Browser* browser = chrome::FindAnyBrowser(profile, false); |
1055 if (browser && browser->window()) { | 1053 if (browser && browser->window()) { |
1056 OnBrowserWindowReady(browser); | 1054 OnBrowserWindowReady(browser); |
1057 } else { | 1055 } else { |
1058 registrar_.Add(this, | 1056 registrar_.Add(this, |
1059 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 1057 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
1060 content::NotificationService::AllSources()); | 1058 content::NotificationService::AllSources()); |
1061 } | 1059 } |
1062 } | 1060 } |
OLD | NEW |