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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
7 #include "base/values.h"
8 #include "chrome/browser/chromeos/login/help_app_launcher.h"
9 #include "chrome/browser/chromeos/login/login_utils.h"
10 #include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
11 #include "chrome/browser/signin/screenlock_bridge.h"
12 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "components/user_manager/user_manager.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/web_ui.h"
17 #include "ui/base/l10n/l10n_util.h"
21 user_manager::UserManager* AppLaunchSigninScreen::test_user_manager_ = NULL;
23 AppLaunchSigninScreen::AppLaunchSigninScreen(
24 OobeUI* oobe_ui, Delegate* delegate)
27 webui_handler_(NULL) {
30 AppLaunchSigninScreen::~AppLaunchSigninScreen() {
31 oobe_ui_->ResetSigninScreenHandlerDelegate();
34 void AppLaunchSigninScreen::Show() {
36 oobe_ui_->web_ui()->CallJavascriptFunction(
37 "login.AccountPickerScreen.setShouldShowApps",
38 base::FundamentalValue(false));
39 oobe_ui_->ShowSigninScreen(LoginScreenContext(), this, NULL);
42 void AppLaunchSigninScreen::InitOwnerUserList() {
43 user_manager::UserManager* user_manager = GetUserManager();
44 const std::string& owner_email = user_manager->GetOwnerEmail();
45 const user_manager::UserList& all_users = user_manager->GetUsers();
47 owner_user_list_.clear();
48 for (user_manager::UserList::const_iterator it = all_users.begin();
49 it != all_users.end();
51 user_manager::User* user = *it;
52 if (user->email() == owner_email) {
53 owner_user_list_.push_back(user);
60 void AppLaunchSigninScreen::SetUserManagerForTesting(
61 user_manager::UserManager* user_manager) {
62 test_user_manager_ = user_manager;
65 user_manager::UserManager* AppLaunchSigninScreen::GetUserManager() {
66 return test_user_manager_ ? test_user_manager_
67 : user_manager::UserManager::Get();
70 void AppLaunchSigninScreen::CancelPasswordChangedFlow() {
74 void AppLaunchSigninScreen::CancelUserAdding() {
78 void AppLaunchSigninScreen::CreateAccount() {
82 void AppLaunchSigninScreen::CompleteLogin(const UserContext& user_context) {
86 void AppLaunchSigninScreen::Login(const UserContext& user_context,
87 const SigninSpecifics& specifics) {
88 // Note: LoginUtils::CreateAuthenticator doesn't necessarily create
89 // a new Authenticator object, and could reuse an existing one.
90 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
91 content::BrowserThread::PostTask(
92 content::BrowserThread::UI, FROM_HERE,
93 base::Bind(&Authenticator::AuthenticateToUnlock,
98 void AppLaunchSigninScreen::MigrateUserData(const std::string& old_password) {
102 void AppLaunchSigninScreen::LoadWallpaper(const std::string& username) {
105 void AppLaunchSigninScreen::LoadSigninWallpaper() {
108 void AppLaunchSigninScreen::OnSigninScreenReady() {
111 void AppLaunchSigninScreen::RemoveUser(const std::string& username) {
115 void AppLaunchSigninScreen::ResyncUserData() {
119 void AppLaunchSigninScreen::ShowEnterpriseEnrollmentScreen() {
123 void AppLaunchSigninScreen::ShowKioskEnableScreen() {
127 void AppLaunchSigninScreen::ShowKioskAutolaunchScreen() {
131 void AppLaunchSigninScreen::ShowWrongHWIDScreen() {
135 void AppLaunchSigninScreen::SetWebUIHandler(
136 LoginDisplayWebUIHandler* webui_handler) {
137 webui_handler_ = webui_handler;
140 void AppLaunchSigninScreen::ShowSigninScreenForCreds(
141 const std::string& username,
142 const std::string& password) {
146 const user_manager::UserList& AppLaunchSigninScreen::GetUsers() const {
147 if (test_user_manager_) {
148 return test_user_manager_->GetUsers();
150 return owner_user_list_;
153 bool AppLaunchSigninScreen::IsShowGuest() const {
157 bool AppLaunchSigninScreen::IsShowUsers() const {
161 bool AppLaunchSigninScreen::IsSigninInProgress() const {
162 // Return true to suppress network processing in the signin screen.
166 bool AppLaunchSigninScreen::IsUserSigninCompleted() const {
170 void AppLaunchSigninScreen::SetDisplayEmail(const std::string& email) {
174 void AppLaunchSigninScreen::Signout() {
178 void AppLaunchSigninScreen::OnAuthFailure(const AuthFailure& error) {
179 LOG(ERROR) << "Unlock failure: " << error.reason();
180 webui_handler_->ClearAndEnablePassword();
181 webui_handler_->ShowError(
183 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING_KIOSK),
185 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT_OFFLINE);
188 void AppLaunchSigninScreen::OnAuthSuccess(const UserContext& user_context) {
189 delegate_->OnOwnerSigninSuccess();
192 void AppLaunchSigninScreen::HandleGetUsers() {
193 base::ListValue users_list;
194 const user_manager::UserList& users = GetUsers();
196 for (user_manager::UserList::const_iterator it = users.begin();
199 ScreenlockBridge::LockHandler::AuthType initial_auth_type =
200 UserSelectionScreen::ShouldForceOnlineSignIn(*it)
201 ? ScreenlockBridge::LockHandler::ONLINE_SIGN_IN
202 : ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
203 base::DictionaryValue* user_dict = new base::DictionaryValue();
204 UserSelectionScreen::FillUserDictionary(
207 false, /* is_signin_to_add */
209 NULL, /* public_session_recommended_locales */
211 users_list.Append(user_dict);
214 webui_handler_->LoadUsers(users_list, false);
217 void AppLaunchSigninScreen::SetAuthType(
218 const std::string& username,
219 ScreenlockBridge::LockHandler::AuthType auth_type) {
223 ScreenlockBridge::LockHandler::AuthType AppLaunchSigninScreen::GetAuthType(
224 const std::string& username) const {
225 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
228 } // namespace chromeos