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/screens/user_selection_screen.h"
10 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
11 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "chromeos/login/auth/user_context.h"
14 #include "components/proximity_auth/screenlock_bridge.h"
15 #include "components/user_manager/user_manager.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/web_ui.h"
18 #include "ui/base/l10n/l10n_util.h"
22 user_manager::UserManager
* AppLaunchSigninScreen::test_user_manager_
= NULL
;
24 AppLaunchSigninScreen::AppLaunchSigninScreen(
25 OobeUI
* oobe_ui
, Delegate
* delegate
)
28 webui_handler_(NULL
) {
31 AppLaunchSigninScreen::~AppLaunchSigninScreen() {
32 oobe_ui_
->ResetSigninScreenHandlerDelegate();
35 void AppLaunchSigninScreen::Show() {
37 oobe_ui_
->web_ui()->CallJavascriptFunction(
38 "login.AccountPickerScreen.setShouldShowApps",
39 base::FundamentalValue(false));
40 oobe_ui_
->ShowSigninScreen(LoginScreenContext(), this, NULL
);
43 void AppLaunchSigninScreen::InitOwnerUserList() {
44 user_manager::UserManager
* user_manager
= GetUserManager();
45 const std::string
& owner_email
= user_manager
->GetOwnerEmail();
46 const user_manager::UserList
& all_users
= user_manager
->GetUsers();
48 owner_user_list_
.clear();
49 for (user_manager::UserList::const_iterator it
= all_users
.begin();
50 it
!= all_users
.end();
52 user_manager::User
* user
= *it
;
53 if (user
->email() == owner_email
) {
54 owner_user_list_
.push_back(user
);
61 void AppLaunchSigninScreen::SetUserManagerForTesting(
62 user_manager::UserManager
* user_manager
) {
63 test_user_manager_
= user_manager
;
66 user_manager::UserManager
* AppLaunchSigninScreen::GetUserManager() {
67 return test_user_manager_
? test_user_manager_
68 : user_manager::UserManager::Get();
71 void AppLaunchSigninScreen::CancelPasswordChangedFlow() {
75 void AppLaunchSigninScreen::CancelUserAdding() {
79 void AppLaunchSigninScreen::CreateAccount() {
83 void AppLaunchSigninScreen::CompleteLogin(const UserContext
& user_context
) {
87 void AppLaunchSigninScreen::Login(const UserContext
& user_context
,
88 const SigninSpecifics
& specifics
) {
89 // Note: CreateAuthenticator doesn't necessarily create
90 // a new Authenticator object, and could reuse an existing one.
91 authenticator_
= UserSessionManager::GetInstance()->CreateAuthenticator(this);
92 content::BrowserThread::PostTask(
93 content::BrowserThread::UI
, FROM_HERE
,
94 base::Bind(&Authenticator::AuthenticateToUnlock
,
99 void AppLaunchSigninScreen::MigrateUserData(const std::string
& old_password
) {
103 void AppLaunchSigninScreen::LoadWallpaper(const std::string
& username
) {
106 void AppLaunchSigninScreen::LoadSigninWallpaper() {
109 void AppLaunchSigninScreen::OnSigninScreenReady() {
112 void AppLaunchSigninScreen::RemoveUser(const std::string
& username
) {
116 void AppLaunchSigninScreen::ResyncUserData() {
120 void AppLaunchSigninScreen::ShowEnterpriseEnrollmentScreen() {
124 void AppLaunchSigninScreen::ShowEnableDebuggingScreen() {
128 void AppLaunchSigninScreen::ShowKioskEnableScreen() {
132 void AppLaunchSigninScreen::ShowKioskAutolaunchScreen() {
136 void AppLaunchSigninScreen::ShowWrongHWIDScreen() {
140 void AppLaunchSigninScreen::SetWebUIHandler(
141 LoginDisplayWebUIHandler
* webui_handler
) {
142 webui_handler_
= webui_handler
;
145 void AppLaunchSigninScreen::ShowSigninScreenForCreds(
146 const std::string
& username
,
147 const std::string
& password
) {
151 const user_manager::UserList
& AppLaunchSigninScreen::GetUsers() const {
152 if (test_user_manager_
) {
153 return test_user_manager_
->GetUsers();
155 return owner_user_list_
;
158 bool AppLaunchSigninScreen::IsShowGuest() const {
162 bool AppLaunchSigninScreen::IsShowUsers() const {
166 bool AppLaunchSigninScreen::IsSigninInProgress() const {
167 // Return true to suppress network processing in the signin screen.
171 bool AppLaunchSigninScreen::IsUserSigninCompleted() const {
175 void AppLaunchSigninScreen::SetDisplayEmail(const std::string
& email
) {
179 void AppLaunchSigninScreen::Signout() {
183 void AppLaunchSigninScreen::OnAuthFailure(const AuthFailure
& error
) {
184 LOG(ERROR
) << "Unlock failure: " << error
.reason();
185 webui_handler_
->ClearAndEnablePassword();
186 webui_handler_
->ShowError(
187 0, l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING_KIOSK
),
188 std::string(), HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT
);
191 void AppLaunchSigninScreen::OnAuthSuccess(const UserContext
& user_context
) {
192 delegate_
->OnOwnerSigninSuccess();
195 void AppLaunchSigninScreen::HandleGetUsers() {
196 base::ListValue users_list
;
197 const user_manager::UserList
& users
= GetUsers();
199 for (user_manager::UserList::const_iterator it
= users
.begin();
202 proximity_auth::ScreenlockBridge::LockHandler::AuthType initial_auth_type
=
203 UserSelectionScreen::ShouldForceOnlineSignIn(*it
)
204 ? proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN
205 : proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
;
206 base::DictionaryValue
* user_dict
= new base::DictionaryValue();
207 UserSelectionScreen::FillUserDictionary(
210 false, /* is_signin_to_add */
212 NULL
, /* public_session_recommended_locales */
214 users_list
.Append(user_dict
);
217 webui_handler_
->LoadUsers(users_list
, false);
220 void AppLaunchSigninScreen::CheckUserStatus(const std::string
& user_id
) {
223 bool AppLaunchSigninScreen::IsUserWhitelisted(const std::string
& user_id
) {
228 } // namespace chromeos