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 "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_ui.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
20 UserManager* AppLaunchSigninScreen::test_user_manager_ = NULL;
22 AppLaunchSigninScreen::AppLaunchSigninScreen(
23 OobeUI* oobe_ui, Delegate* delegate)
26 webui_handler_(NULL) {
29 AppLaunchSigninScreen::~AppLaunchSigninScreen() {
30 oobe_ui_->ResetSigninScreenHandlerDelegate();
33 void AppLaunchSigninScreen::Show() {
35 oobe_ui_->web_ui()->CallJavascriptFunction(
36 "login.AccountPickerScreen.setShouldShowApps",
37 base::FundamentalValue(false));
38 oobe_ui_->ShowSigninScreen(LoginScreenContext(), this, NULL);
41 void AppLaunchSigninScreen::InitOwnerUserList() {
42 UserManager* user_manager = GetUserManager();
43 const std::string& owner_email = user_manager->GetOwnerEmail();
44 const UserList& all_users = user_manager->GetUsers();
46 owner_user_list_.clear();
47 for (UserList::const_iterator it = all_users.begin();
48 it != all_users.end();
51 if (user->email() == owner_email) {
52 owner_user_list_.push_back(user);
59 void AppLaunchSigninScreen::SetUserManagerForTesting(
60 UserManager* user_manager) {
61 test_user_manager_ = user_manager;
64 UserManager* AppLaunchSigninScreen::GetUserManager() {
65 return test_user_manager_ ? test_user_manager_ : UserManager::Get();
68 void AppLaunchSigninScreen::CancelPasswordChangedFlow() {
72 void AppLaunchSigninScreen::CancelUserAdding() {
76 void AppLaunchSigninScreen::CreateAccount() {
80 void AppLaunchSigninScreen::CompleteLogin(const UserContext& user_context) {
84 void AppLaunchSigninScreen::Login(const UserContext& user_context) {
85 // Note: LoginUtils::CreateAuthenticator doesn't necessarily create
86 // a new Authenticator object, and could reuse an existing one.
87 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
88 content::BrowserThread::PostTask(
89 content::BrowserThread::UI, FROM_HERE,
90 base::Bind(&Authenticator::AuthenticateToUnlock,
95 void AppLaunchSigninScreen::LoginAsRetailModeUser() {
99 void AppLaunchSigninScreen::LoginAsGuest() {
103 void AppLaunchSigninScreen::MigrateUserData(const std::string& old_password) {
107 void AppLaunchSigninScreen::LoginAsPublicAccount(const std::string& username) {
111 void AppLaunchSigninScreen::LoadWallpaper(const std::string& username) {
114 void AppLaunchSigninScreen::LoadSigninWallpaper() {
117 void AppLaunchSigninScreen::OnSigninScreenReady() {
120 void AppLaunchSigninScreen::RemoveUser(const std::string& username) {
124 void AppLaunchSigninScreen::ResyncUserData() {
128 void AppLaunchSigninScreen::ShowEnterpriseEnrollmentScreen() {
132 void AppLaunchSigninScreen::ShowKioskEnableScreen() {
136 void AppLaunchSigninScreen::ShowKioskAutolaunchScreen() {
140 void AppLaunchSigninScreen::ShowWrongHWIDScreen() {
144 void AppLaunchSigninScreen::SetWebUIHandler(
145 LoginDisplayWebUIHandler* webui_handler) {
146 webui_handler_ = webui_handler;
149 void AppLaunchSigninScreen::ShowSigninScreenForCreds(
150 const std::string& username,
151 const std::string& password) {
155 const UserList& AppLaunchSigninScreen::GetUsers() const {
156 if (test_user_manager_) {
157 return test_user_manager_->GetUsers();
159 return owner_user_list_;
162 bool AppLaunchSigninScreen::IsShowGuest() const {
166 bool AppLaunchSigninScreen::IsShowUsers() const {
170 bool AppLaunchSigninScreen::IsSigninInProgress() const {
171 // Return true to suppress network processing in the signin screen.
175 bool AppLaunchSigninScreen::IsUserSigninCompleted() const {
179 void AppLaunchSigninScreen::SetDisplayEmail(const std::string& email) {
183 void AppLaunchSigninScreen::Signout() {
187 void AppLaunchSigninScreen::LoginAsKioskApp(const std::string& app_id,
188 bool diagnostic_mode) {
192 void AppLaunchSigninScreen::OnLoginFailure(const LoginFailure& error) {
193 LOG(ERROR) << "Unlock failure: " << error.reason();
194 webui_handler_->ClearAndEnablePassword();
195 webui_handler_->ShowError(
197 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING_KIOSK),
199 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT_OFFLINE);
202 void AppLaunchSigninScreen::OnLoginSuccess(const UserContext& user_context) {
203 delegate_->OnOwnerSigninSuccess();
206 void AppLaunchSigninScreen::HandleGetUsers() {
207 base::ListValue users_list;
208 const UserList& users = GetUsers();
210 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
211 ScreenlockBridge::LockHandler::AuthType initial_auth_type =
212 UserSelectionScreen::ShouldForceOnlineSignIn(*it)
213 ? ScreenlockBridge::LockHandler::ONLINE_SIGN_IN
214 : ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
215 base::DictionaryValue* user_dict = new base::DictionaryValue();
216 UserSelectionScreen::FillUserDictionary(
217 *it, true, false, initial_auth_type, user_dict);
218 users_list.Append(user_dict);
221 webui_handler_->LoadUsers(users_list, false, false);
224 void AppLaunchSigninScreen::SetAuthType(
225 const std::string& username,
226 ScreenlockBridge::LockHandler::AuthType auth_type) {
230 ScreenlockBridge::LockHandler::AuthType AppLaunchSigninScreen::GetAuthType(
231 const std::string& username) const {
232 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
235 } // namespace chromeos