| 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 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 new UserManagerScreenHandler::ProfileUpdateObserver( | 288 new UserManagerScreenHandler::ProfileUpdateObserver( |
| 289 g_browser_process->profile_manager(), this)); | 289 g_browser_process->profile_manager(), this)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 UserManagerScreenHandler::~UserManagerScreenHandler() { | 292 UserManagerScreenHandler::~UserManagerScreenHandler() { |
| 293 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); | 293 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void UserManagerScreenHandler::ShowBannerMessage( | 296 void UserManagerScreenHandler::ShowBannerMessage( |
| 297 const base::string16& message) { | 297 const base::string16& message) { |
| 298 web_ui()->CallJavascriptFunction( | 298 web_ui()->CallJavascriptFunctionUnsafe( |
| 299 "login.AccountPickerScreen.showBannerMessage", | 299 "login.AccountPickerScreen.showBannerMessage", |
| 300 base::StringValue(message)); | 300 base::StringValue(message)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void UserManagerScreenHandler::ShowUserPodCustomIcon( | 303 void UserManagerScreenHandler::ShowUserPodCustomIcon( |
| 304 const AccountId& account_id, | 304 const AccountId& account_id, |
| 305 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& | 305 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& |
| 306 icon_options) { | 306 icon_options) { |
| 307 std::unique_ptr<base::DictionaryValue> icon = | 307 std::unique_ptr<base::DictionaryValue> icon = |
| 308 icon_options.ToDictionaryValue(); | 308 icon_options.ToDictionaryValue(); |
| 309 if (!icon || icon->empty()) | 309 if (!icon || icon->empty()) |
| 310 return; | 310 return; |
| 311 web_ui()->CallJavascriptFunction( | 311 web_ui()->CallJavascriptFunctionUnsafe( |
| 312 "login.AccountPickerScreen.showUserPodCustomIcon", | 312 "login.AccountPickerScreen.showUserPodCustomIcon", |
| 313 base::StringValue(account_id.GetUserEmail()), *icon); | 313 base::StringValue(account_id.GetUserEmail()), *icon); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void UserManagerScreenHandler::HideUserPodCustomIcon( | 316 void UserManagerScreenHandler::HideUserPodCustomIcon( |
| 317 const AccountId& account_id) { | 317 const AccountId& account_id) { |
| 318 web_ui()->CallJavascriptFunction( | 318 web_ui()->CallJavascriptFunctionUnsafe( |
| 319 "login.AccountPickerScreen.hideUserPodCustomIcon", | 319 "login.AccountPickerScreen.hideUserPodCustomIcon", |
| 320 base::StringValue(account_id.GetUserEmail())); | 320 base::StringValue(account_id.GetUserEmail())); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void UserManagerScreenHandler::EnableInput() { | 323 void UserManagerScreenHandler::EnableInput() { |
| 324 // Nothing here because UI is not disabled when starting to authenticate. | 324 // Nothing here because UI is not disabled when starting to authenticate. |
| 325 } | 325 } |
| 326 | 326 |
| 327 void UserManagerScreenHandler::SetAuthType( | 327 void UserManagerScreenHandler::SetAuthType( |
| 328 const AccountId& account_id, | 328 const AccountId& account_id, |
| 329 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type, | 329 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type, |
| 330 const base::string16& auth_value) { | 330 const base::string16& auth_value) { |
| 331 if (GetAuthType(account_id) == | 331 if (GetAuthType(account_id) == |
| 332 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) | 332 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) |
| 333 return; | 333 return; |
| 334 | 334 |
| 335 user_auth_type_map_[account_id.GetUserEmail()] = auth_type; | 335 user_auth_type_map_[account_id.GetUserEmail()] = auth_type; |
| 336 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.setAuthType", | 336 web_ui()->CallJavascriptFunctionUnsafe( |
| 337 base::StringValue(account_id.GetUserEmail()), | 337 "login.AccountPickerScreen.setAuthType", |
| 338 base::FundamentalValue(auth_type), | 338 base::StringValue(account_id.GetUserEmail()), |
| 339 base::StringValue(auth_value)); | 339 base::FundamentalValue(auth_type), base::StringValue(auth_value)); |
| 340 } | 340 } |
| 341 | 341 |
| 342 proximity_auth::ScreenlockBridge::LockHandler::AuthType | 342 proximity_auth::ScreenlockBridge::LockHandler::AuthType |
| 343 UserManagerScreenHandler::GetAuthType(const AccountId& account_id) const { | 343 UserManagerScreenHandler::GetAuthType(const AccountId& account_id) const { |
| 344 const auto it = user_auth_type_map_.find(account_id.GetUserEmail()); | 344 const auto it = user_auth_type_map_.find(account_id.GetUserEmail()); |
| 345 if (it == user_auth_type_map_.end()) | 345 if (it == user_auth_type_map_.end()) |
| 346 return proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | 346 return proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; |
| 347 return it->second; | 347 return it->second; |
| 348 } | 348 } |
| 349 | 349 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 365 const std::string& secret, | 365 const std::string& secret, |
| 366 const std::string& key_label) { | 366 const std::string& key_label) { |
| 367 NOTREACHED(); | 367 NOTREACHED(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 370 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
| 371 // If the URL has a hash parameter, store it for later. | 371 // If the URL has a hash parameter, store it for later. |
| 372 args->GetString(0, &url_hash_); | 372 args->GetString(0, &url_hash_); |
| 373 | 373 |
| 374 SendUserList(); | 374 SendUserList(); |
| 375 web_ui()->CallJavascriptFunction("cr.ui.UserManager.showUserManagerScreen", | 375 web_ui()->CallJavascriptFunctionUnsafe( |
| 376 "cr.ui.UserManager.showUserManagerScreen", |
| 376 base::FundamentalValue(IsGuestModeEnabled()), | 377 base::FundamentalValue(IsGuestModeEnabled()), |
| 377 base::FundamentalValue(IsAddPersonEnabled())); | 378 base::FundamentalValue(IsAddPersonEnabled())); |
| 378 | 379 |
| 379 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(this); | 380 proximity_auth::ScreenlockBridge::Get()->SetLockHandler(this); |
| 380 } | 381 } |
| 381 | 382 |
| 382 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 383 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
| 383 if (!IsAddPersonEnabled()) { | 384 if (!IsAddPersonEnabled()) { |
| 384 // The 'Add User' UI should not be showing. | 385 // The 'Add User' UI should not be showing. |
| 385 NOTREACHED(); | 386 NOTREACHED(); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 profile_path); | 569 profile_path); |
| 569 bool stats_success = true; | 570 bool stats_success = true; |
| 570 for (const auto& item : stats) { | 571 for (const auto& item : stats) { |
| 571 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); | 572 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); |
| 572 stat->SetIntegerWithoutPathExpansion("count", item.count); | 573 stat->SetIntegerWithoutPathExpansion("count", item.count); |
| 573 stat->SetBooleanWithoutPathExpansion("success", item.success); | 574 stat->SetBooleanWithoutPathExpansion("success", item.success); |
| 574 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); | 575 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); |
| 575 stats_success &= item.success; | 576 stats_success &= item.success; |
| 576 } | 577 } |
| 577 if (stats_success) { | 578 if (stats_success) { |
| 578 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", | 579 web_ui()->CallJavascriptFunctionUnsafe( |
| 579 base::StringValue(profile_path.value()), | 580 "updateRemoveWarningDialog", base::StringValue(profile_path.value()), |
| 580 return_value); | 581 return_value); |
| 581 return; | 582 return; |
| 582 } | 583 } |
| 583 } | 584 } |
| 584 | 585 |
| 585 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( | 586 ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( |
| 586 base::Bind( | 587 base::Bind( |
| 587 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, | 588 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, |
| 588 weak_ptr_factory_.GetWeakPtr(), profile_path)); | 589 weak_ptr_factory_.GetWeakPtr(), profile_path)); |
| 589 } | 590 } |
| 590 | 591 |
| 591 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( | 592 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( |
| 592 base::FilePath profile_path, | 593 base::FilePath profile_path, |
| 593 profiles::ProfileCategoryStats result) { | 594 profiles::ProfileCategoryStats result) { |
| 594 // Copy result into return_value. | 595 // Copy result into return_value. |
| 595 base::DictionaryValue return_value; | 596 base::DictionaryValue return_value; |
| 596 for (const auto& item : result) { | 597 for (const auto& item : result) { |
| 597 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); | 598 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); |
| 598 stat->SetIntegerWithoutPathExpansion("count", item.count); | 599 stat->SetIntegerWithoutPathExpansion("count", item.count); |
| 599 stat->SetBooleanWithoutPathExpansion("success", item.success); | 600 stat->SetBooleanWithoutPathExpansion("success", item.success); |
| 600 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); | 601 return_value.SetWithoutPathExpansion(item.category, std::move(stat)); |
| 601 } | 602 } |
| 602 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", | 603 web_ui()->CallJavascriptFunctionUnsafe( |
| 603 base::StringValue(profile_path.value()), | 604 "updateRemoveWarningDialog", base::StringValue(profile_path.value()), |
| 604 return_value); | 605 return_value); |
| 605 } | 606 } |
| 606 | 607 |
| 607 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( | 608 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( |
| 608 const base::ListValue* args) { | 609 const base::ListValue* args) { |
| 609 const base::DictionaryValue* arg; | 610 const base::DictionaryValue* arg; |
| 610 if (!args->GetDictionary(0, &arg)) | 611 if (!args->GetDictionary(0, &arg)) |
| 611 return; | 612 return; |
| 612 | 613 |
| 613 std::string profile_path(""); | 614 std::string profile_path(""); |
| 614 bool is_synced_user = false; | 615 bool is_synced_user = false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 625 | 626 |
| 626 int message_id = is_synced_user ? | 627 int message_id = is_synced_user ? |
| 627 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_WITH_ERRORS : | 628 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_WITH_ERRORS : |
| 628 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC) : | 629 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC) : |
| 629 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_WITH_ERRORS : | 630 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_WITH_ERRORS : |
| 630 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC); | 631 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC); |
| 631 | 632 |
| 632 base::StringValue message = base::StringValue( | 633 base::StringValue message = base::StringValue( |
| 633 l10n_util::GetPluralStringFUTF16(message_id, total_count)); | 634 l10n_util::GetPluralStringFUTF16(message_id, total_count)); |
| 634 | 635 |
| 635 web_ui()->CallJavascriptFunction("updateRemoveWarningDialogSetMessage", | 636 web_ui()->CallJavascriptFunctionUnsafe( |
| 636 base::StringValue(profile_path), | 637 "updateRemoveWarningDialogSetMessage", base::StringValue(profile_path), |
| 637 message, | 638 message, base::FundamentalValue(total_count)); |
| 638 base::FundamentalValue(total_count)); | |
| 639 } | 639 } |
| 640 | 640 |
| 641 void UserManagerScreenHandler::OnGetTokenInfoResponse( | 641 void UserManagerScreenHandler::OnGetTokenInfoResponse( |
| 642 std::unique_ptr<base::DictionaryValue> token_info) { | 642 std::unique_ptr<base::DictionaryValue> token_info) { |
| 643 // Password is unchanged so user just mistyped it. Ask again. | 643 // Password is unchanged so user just mistyped it. Ask again. |
| 644 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); | 644 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); |
| 645 } | 645 } |
| 646 | 646 |
| 647 void UserManagerScreenHandler::OnOAuthError() { | 647 void UserManagerScreenHandler::OnOAuthError() { |
| 648 // Password has changed. Go through online signin flow. | 648 // Password has changed. Go through online signin flow. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 884 |
| 885 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL | 885 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL |
| 886 // otherwise. | 886 // otherwise. |
| 887 Profile* profile = | 887 Profile* profile = |
| 888 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | 888 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
| 889 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); | 889 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); |
| 890 | 890 |
| 891 users_list.Append(profile_value); | 891 users_list.Append(profile_value); |
| 892 } | 892 } |
| 893 | 893 |
| 894 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 894 web_ui()->CallJavascriptFunctionUnsafe( |
| 895 users_list, base::FundamentalValue(IsGuestModeEnabled())); | 895 "login.AccountPickerScreen.loadUsers", users_list, |
| 896 base::FundamentalValue(IsGuestModeEnabled())); |
| 896 | 897 |
| 897 // This is the latest C++ code we have in the flow to show the UserManager. | 898 // This is the latest C++ code we have in the flow to show the UserManager. |
| 898 // This may be invoked more than once per UserManager lifetime; the | 899 // This may be invoked more than once per UserManager lifetime; the |
| 899 // UserManager will ensure all relevant logging only happens once. | 900 // UserManager will ensure all relevant logging only happens once. |
| 900 UserManager::OnUserManagerShown(); | 901 UserManager::OnUserManagerShown(); |
| 901 } | 902 } |
| 902 | 903 |
| 903 void UserManagerScreenHandler::ReportAuthenticationResult( | 904 void UserManagerScreenHandler::ReportAuthenticationResult( |
| 904 bool success, | 905 bool success, |
| 905 ProfileMetrics::ProfileAuth auth) { | 906 ProfileMetrics::ProfileAuth auth) { |
| 906 ProfileMetrics::LogProfileAuthResult(auth); | 907 ProfileMetrics::LogProfileAuthResult(auth); |
| 907 email_address_.clear(); | 908 email_address_.clear(); |
| 908 | 909 |
| 909 if (success) { | 910 if (success) { |
| 910 profiles::SwitchToProfile( | 911 profiles::SwitchToProfile( |
| 911 authenticating_profile_path_, true, | 912 authenticating_profile_path_, true, |
| 912 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 913 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 913 weak_ptr_factory_.GetWeakPtr()), | 914 weak_ptr_factory_.GetWeakPtr()), |
| 914 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 915 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| 915 } else { | 916 } else { |
| 916 web_ui()->CallJavascriptFunction( | 917 web_ui()->CallJavascriptFunctionUnsafe( |
| 917 "cr.ui.UserManager.showSignInError", | 918 "cr.ui.UserManager.showSignInError", base::FundamentalValue(0), |
| 918 base::FundamentalValue(0), | |
| 919 base::StringValue(l10n_util::GetStringUTF8( | 919 base::StringValue(l10n_util::GetStringUTF8( |
| 920 auth == ProfileMetrics::AUTH_FAILED_OFFLINE ? | 920 auth == ProfileMetrics::AUTH_FAILED_OFFLINE |
| 921 IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE : | 921 ? IDS_LOGIN_ERROR_AUTHENTICATING_OFFLINE |
| 922 IDS_LOGIN_ERROR_AUTHENTICATING)), | 922 : IDS_LOGIN_ERROR_AUTHENTICATING)), |
| 923 base::StringValue(""), | 923 base::StringValue(""), base::FundamentalValue(0)); |
| 924 base::FundamentalValue(0)); | |
| 925 } | 924 } |
| 926 } | 925 } |
| 927 | 926 |
| 928 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { | 927 void UserManagerScreenHandler::OnBrowserWindowReady(Browser* browser) { |
| 929 DCHECK(browser); | 928 DCHECK(browser); |
| 930 DCHECK(browser->window()); | 929 DCHECK(browser->window()); |
| 931 | 930 |
| 932 // Unlock the profile after browser opens so startup can read the lock bit. | 931 // Unlock the profile after browser opens so startup can read the lock bit. |
| 933 // Any necessary authentication must have been successful to reach this point. | 932 // Any necessary authentication must have been successful to reach this point. |
| 934 if (!browser->profile()->IsGuestSession()) { | 933 if (!browser->profile()->IsGuestSession()) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 Profile* profile, Profile::CreateStatus profile_create_status) { | 976 Profile* profile, Profile::CreateStatus profile_create_status) { |
| 978 Browser* browser = chrome::FindAnyBrowser(profile, false); | 977 Browser* browser = chrome::FindAnyBrowser(profile, false); |
| 979 if (browser && browser->window()) { | 978 if (browser && browser->window()) { |
| 980 OnBrowserWindowReady(browser); | 979 OnBrowserWindowReady(browser); |
| 981 } else { | 980 } else { |
| 982 registrar_.Add(this, | 981 registrar_.Add(this, |
| 983 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 982 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 984 content::NotificationService::AllSources()); | 983 content::NotificationService::AllSources()); |
| 985 } | 984 } |
| 986 } | 985 } |
| OLD | NEW |