| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/value_conversions.h" | 9 #include "base/value_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const char kKeyAvatarUrl[] = "userImage"; | 54 const char kKeyAvatarUrl[] = "userImage"; |
| 55 const char kKeyNeedsSignin[] = "needsSignin"; | 55 const char kKeyNeedsSignin[] = "needsSignin"; |
| 56 | 56 |
| 57 // JS API callback names. | 57 // JS API callback names. |
| 58 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; | 58 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; |
| 59 const char kJsApiUserManagerAddUser[] = "addUser"; | 59 const char kJsApiUserManagerAddUser[] = "addUser"; |
| 60 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; | 60 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; |
| 61 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; | 61 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; |
| 62 const char kJsApiUserManagerLaunchUser[] = "launchUser"; | 62 const char kJsApiUserManagerLaunchUser[] = "launchUser"; |
| 63 const char kJsApiUserManagerRemoveUser[] = "removeUser"; | 63 const char kJsApiUserManagerRemoveUser[] = "removeUser"; |
| 64 const char kJsApiUserManagerCustomButtonClicked[] = "customButtonClicked"; | |
| 65 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; | 64 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; |
| 66 | 65 |
| 67 const size_t kAvatarIconSize = 180; | 66 const size_t kAvatarIconSize = 180; |
| 68 | 67 |
| 69 void HandleAndDoNothing(const base::ListValue* args) { | 68 void HandleAndDoNothing(const base::ListValue* args) { |
| 70 } | 69 } |
| 71 | 70 |
| 72 // This callback is run if the only profile has been deleted, and a new | 71 // This callback is run if the only profile has been deleted, and a new |
| 73 // profile has been created to replace it. | 72 // profile has been created to replace it. |
| 74 void OpenNewWindowForProfile( | 73 void OpenNewWindowForProfile( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ProfileInfoCache& info_cache = | 133 ProfileInfoCache& info_cache = |
| 135 g_browser_process->profile_manager()->GetProfileInfoCache(); | 134 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 136 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 135 const size_t profile_index = GetIndexOfProfileWithEmailAndName( |
| 137 info_cache, base::UTF8ToUTF16(email), base::string16()); | 136 info_cache, base::UTF8ToUTF16(email), base::string16()); |
| 138 Profile* profile = g_browser_process->profile_manager() | 137 Profile* profile = g_browser_process->profile_manager() |
| 139 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); | 138 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); |
| 140 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | 139 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( |
| 141 profile); | 140 profile); |
| 142 } | 141 } |
| 143 | 142 |
| 144 } // namespace | 143 } // namespace |
| 145 | 144 |
| 146 // ProfileUpdateObserver ------------------------------------------------------ | 145 // ProfileUpdateObserver ------------------------------------------------------ |
| 147 | 146 |
| 148 class UserManagerScreenHandler::ProfileUpdateObserver | 147 class UserManagerScreenHandler::ProfileUpdateObserver |
| 149 : public ProfileInfoCacheObserver { | 148 : public ProfileInfoCacheObserver { |
| 150 public: | 149 public: |
| 151 ProfileUpdateObserver( | 150 ProfileUpdateObserver( |
| 152 ProfileManager* profile_manager, UserManagerScreenHandler* handler) | 151 ProfileManager* profile_manager, UserManagerScreenHandler* handler) |
| 153 : profile_manager_(profile_manager), | 152 : profile_manager_(profile_manager), |
| 154 user_manager_handler_(handler) { | 153 user_manager_handler_(handler) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 UserManagerScreenHandler::~UserManagerScreenHandler() { | 212 UserManagerScreenHandler::~UserManagerScreenHandler() { |
| 214 ScreenlockBridge::Get()->SetLockHandler(NULL); | 213 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 215 } | 214 } |
| 216 | 215 |
| 217 void UserManagerScreenHandler::ShowBannerMessage(const std::string& message) { | 216 void UserManagerScreenHandler::ShowBannerMessage(const std::string& message) { |
| 218 web_ui()->CallJavascriptFunction( | 217 web_ui()->CallJavascriptFunction( |
| 219 "login.AccountPickerScreen.showBannerMessage", | 218 "login.AccountPickerScreen.showBannerMessage", |
| 220 base::StringValue(message)); | 219 base::StringValue(message)); |
| 221 } | 220 } |
| 222 | 221 |
| 223 void UserManagerScreenHandler::ShowUserPodButton( | 222 void UserManagerScreenHandler::ShowUserPodCustomIcon( |
| 224 const std::string& user_email, | 223 const std::string& user_email, |
| 225 const gfx::Image& icon, | 224 const gfx::Image& icon) { |
| 226 const base::Closure& callback) { | |
| 227 GURL icon_url(webui::GetBitmapDataUrl(icon.AsBitmap())); | 225 GURL icon_url(webui::GetBitmapDataUrl(icon.AsBitmap())); |
| 228 web_ui()->CallJavascriptFunction( | 226 web_ui()->CallJavascriptFunction( |
| 229 "login.AccountPickerScreen.showUserPodButton", | 227 "login.AccountPickerScreen.showUserPodCustomIcon", |
| 230 base::StringValue(user_email), | 228 base::StringValue(user_email), |
| 231 base::StringValue(icon_url.spec())); | 229 base::StringValue(icon_url.spec())); |
| 232 } | 230 } |
| 233 | 231 |
| 234 void UserManagerScreenHandler::HideUserPodButton( | 232 void UserManagerScreenHandler::HideUserPodCustomIcon( |
| 235 const std::string& user_email) { | 233 const std::string& user_email) { |
| 236 web_ui()->CallJavascriptFunction( | 234 web_ui()->CallJavascriptFunction( |
| 237 "login.AccountPickerScreen.hideUserPodButton", | 235 "login.AccountPickerScreen.hideUserPodCustomIcon", |
| 238 base::StringValue(user_email)); | 236 base::StringValue(user_email)); |
| 239 } | 237 } |
| 240 | 238 |
| 241 void UserManagerScreenHandler::EnableInput() { | 239 void UserManagerScreenHandler::EnableInput() { |
| 242 // Nothing here because UI is not disabled when starting to authenticate. | 240 // Nothing here because UI is not disabled when starting to authenticate. |
| 243 } | 241 } |
| 244 | 242 |
| 245 void UserManagerScreenHandler::SetAuthType( | 243 void UserManagerScreenHandler::SetAuthType( |
| 246 const std::string& user_email, | 244 const std::string& user_email, |
| 247 ScreenlockBridge::LockHandler::AuthType auth_type, | 245 ScreenlockBridge::LockHandler::AuthType auth_type, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 394 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
| 397 | 395 |
| 398 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 396 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
| 399 profiles::SwitchToProfile(path, | 397 profiles::SwitchToProfile(path, |
| 400 desktop_type_, | 398 desktop_type_, |
| 401 false, /* reuse any existing windows */ | 399 false, /* reuse any existing windows */ |
| 402 base::Bind(&OnSwitchToProfileComplete), | 400 base::Bind(&OnSwitchToProfileComplete), |
| 403 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 401 ProfileMetrics::SWITCH_PROFILE_MANAGER); |
| 404 } | 402 } |
| 405 | 403 |
| 406 void UserManagerScreenHandler::HandleCustomButtonClicked( | |
| 407 const base::ListValue* args) { | |
| 408 // TODO(xiyuan): Remove this. Deprecated now. | |
| 409 } | |
| 410 | |
| 411 void UserManagerScreenHandler::HandleAttemptUnlock( | 404 void UserManagerScreenHandler::HandleAttemptUnlock( |
| 412 const base::ListValue* args) { | 405 const base::ListValue* args) { |
| 413 std::string email; | 406 std::string email; |
| 414 CHECK(args->GetString(0, &email)); | 407 CHECK(args->GetString(0, &email)); |
| 415 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); | 408 GetScreenlockRouter(email)->OnAuthAttempted(GetAuthType(email), ""); |
| 416 } | 409 } |
| 417 | 410 |
| 418 void UserManagerScreenHandler::OnClientLoginSuccess( | 411 void UserManagerScreenHandler::OnClientLoginSuccess( |
| 419 const ClientLoginResult& result) { | 412 const ClientLoginResult& result) { |
| 420 chrome::SetLocalAuthCredentials(authenticating_profile_index_, | 413 chrome::SetLocalAuthCredentials(authenticating_profile_index_, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 450 base::Unretained(this))); | 443 base::Unretained(this))); |
| 451 web_ui()->RegisterMessageCallback(kJsApiUserManagerLaunchGuest, | 444 web_ui()->RegisterMessageCallback(kJsApiUserManagerLaunchGuest, |
| 452 base::Bind(&UserManagerScreenHandler::HandleLaunchGuest, | 445 base::Bind(&UserManagerScreenHandler::HandleLaunchGuest, |
| 453 base::Unretained(this))); | 446 base::Unretained(this))); |
| 454 web_ui()->RegisterMessageCallback(kJsApiUserManagerLaunchUser, | 447 web_ui()->RegisterMessageCallback(kJsApiUserManagerLaunchUser, |
| 455 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, | 448 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, |
| 456 base::Unretained(this))); | 449 base::Unretained(this))); |
| 457 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, | 450 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, |
| 458 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, | 451 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, |
| 459 base::Unretained(this))); | 452 base::Unretained(this))); |
| 460 web_ui()->RegisterMessageCallback(kJsApiUserManagerCustomButtonClicked, | |
| 461 base::Bind(&UserManagerScreenHandler::HandleCustomButtonClicked, | |
| 462 base::Unretained(this))); | |
| 463 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, | 453 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, |
| 464 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, | 454 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, |
| 465 base::Unretained(this))); | 455 base::Unretained(this))); |
| 466 | 456 |
| 467 const content::WebUI::MessageCallback& kDoNothingCallback = | 457 const content::WebUI::MessageCallback& kDoNothingCallback = |
| 468 base::Bind(&HandleAndDoNothing); | 458 base::Bind(&HandleAndDoNothing); |
| 469 | 459 |
| 470 // Unused callbacks from screen_account_picker.js | 460 // Unused callbacks from screen_account_picker.js |
| 471 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); | 461 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); |
| 472 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); | 462 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } else { | 631 } else { |
| 642 web_ui()->CallJavascriptFunction( | 632 web_ui()->CallJavascriptFunction( |
| 643 "cr.ui.Oobe.showSignInError", | 633 "cr.ui.Oobe.showSignInError", |
| 644 base::FundamentalValue(0), | 634 base::FundamentalValue(0), |
| 645 base::StringValue( | 635 base::StringValue( |
| 646 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 636 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
| 647 base::StringValue(""), | 637 base::StringValue(""), |
| 648 base::FundamentalValue(0)); | 638 base::FundamentalValue(0)); |
| 649 } | 639 } |
| 650 } | 640 } |
| OLD | NEW |