Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / app_launch_signin_screen.cc
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.
4
5 #include "chrome/browser/chromeos/login/app_launch_signin_screen.h"
6
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"
18
19 namespace chromeos {
20
21 user_manager::UserManager* AppLaunchSigninScreen::test_user_manager_ = NULL;
22
23 AppLaunchSigninScreen::AppLaunchSigninScreen(
24     OobeUI* oobe_ui, Delegate* delegate)
25     : oobe_ui_(oobe_ui),
26       delegate_(delegate),
27       webui_handler_(NULL) {
28 }
29
30 AppLaunchSigninScreen::~AppLaunchSigninScreen() {
31   oobe_ui_->ResetSigninScreenHandlerDelegate();
32 }
33
34 void AppLaunchSigninScreen::Show() {
35   InitOwnerUserList();
36   oobe_ui_->web_ui()->CallJavascriptFunction(
37       "login.AccountPickerScreen.setShouldShowApps",
38       base::FundamentalValue(false));
39   oobe_ui_->ShowSigninScreen(LoginScreenContext(), this, NULL);
40 }
41
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();
46
47   owner_user_list_.clear();
48   for (user_manager::UserList::const_iterator it = all_users.begin();
49        it != all_users.end();
50        ++it) {
51     user_manager::User* user = *it;
52     if (user->email() == owner_email) {
53       owner_user_list_.push_back(user);
54       break;
55     }
56   }
57 }
58
59 // static
60 void AppLaunchSigninScreen::SetUserManagerForTesting(
61     user_manager::UserManager* user_manager) {
62   test_user_manager_ = user_manager;
63 }
64
65 user_manager::UserManager* AppLaunchSigninScreen::GetUserManager() {
66   return test_user_manager_ ? test_user_manager_
67                             : user_manager::UserManager::Get();
68 }
69
70 void AppLaunchSigninScreen::CancelPasswordChangedFlow() {
71   NOTREACHED();
72 }
73
74 void AppLaunchSigninScreen::CancelUserAdding() {
75   NOTREACHED();
76 }
77
78 void AppLaunchSigninScreen::CreateAccount() {
79   NOTREACHED();
80 }
81
82 void AppLaunchSigninScreen::CompleteLogin(const UserContext& user_context) {
83   NOTREACHED();
84 }
85
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,
94                  authenticator_.get(),
95                  user_context));
96 }
97
98 void AppLaunchSigninScreen::MigrateUserData(const std::string& old_password) {
99   NOTREACHED();
100 }
101
102 void AppLaunchSigninScreen::LoadWallpaper(const std::string& username) {
103 }
104
105 void AppLaunchSigninScreen::LoadSigninWallpaper() {
106 }
107
108 void AppLaunchSigninScreen::OnSigninScreenReady() {
109 }
110
111 void AppLaunchSigninScreen::RemoveUser(const std::string& username) {
112   NOTREACHED();
113 }
114
115 void AppLaunchSigninScreen::ResyncUserData() {
116   NOTREACHED();
117 }
118
119 void AppLaunchSigninScreen::ShowEnterpriseEnrollmentScreen() {
120   NOTREACHED();
121 }
122
123 void AppLaunchSigninScreen::ShowKioskEnableScreen() {
124   NOTREACHED();
125 }
126
127 void AppLaunchSigninScreen::ShowKioskAutolaunchScreen() {
128   NOTREACHED();
129 }
130
131 void AppLaunchSigninScreen::ShowWrongHWIDScreen() {
132   NOTREACHED();
133 }
134
135 void AppLaunchSigninScreen::SetWebUIHandler(
136     LoginDisplayWebUIHandler* webui_handler) {
137   webui_handler_ = webui_handler;
138 }
139
140 void AppLaunchSigninScreen::ShowSigninScreenForCreds(
141     const std::string& username,
142     const std::string& password) {
143   NOTREACHED();
144 }
145
146 const user_manager::UserList& AppLaunchSigninScreen::GetUsers() const {
147   if (test_user_manager_) {
148     return test_user_manager_->GetUsers();
149   }
150   return owner_user_list_;
151 }
152
153 bool AppLaunchSigninScreen::IsShowGuest() const {
154   return false;
155 }
156
157 bool AppLaunchSigninScreen::IsShowUsers() const {
158   return true;
159 }
160
161 bool AppLaunchSigninScreen::IsSigninInProgress() const {
162   // Return true to suppress network processing in the signin screen.
163   return true;
164 }
165
166 bool AppLaunchSigninScreen::IsUserSigninCompleted() const {
167   return false;
168 }
169
170 void AppLaunchSigninScreen::SetDisplayEmail(const std::string& email) {
171   return;
172 }
173
174 void AppLaunchSigninScreen::Signout() {
175   NOTREACHED();
176 }
177
178 void AppLaunchSigninScreen::OnAuthFailure(const AuthFailure& error) {
179   LOG(ERROR) << "Unlock failure: " << error.reason();
180   webui_handler_->ClearAndEnablePassword();
181   webui_handler_->ShowError(
182      0,
183      l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING_KIOSK),
184      std::string(),
185      HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT_OFFLINE);
186 }
187
188 void AppLaunchSigninScreen::OnAuthSuccess(const UserContext& user_context) {
189   delegate_->OnOwnerSigninSuccess();
190 }
191
192 void AppLaunchSigninScreen::HandleGetUsers() {
193   base::ListValue users_list;
194   const user_manager::UserList& users = GetUsers();
195
196   for (user_manager::UserList::const_iterator it = users.begin();
197        it != users.end();
198        ++it) {
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(
205         *it,
206         true,   /* is_owner */
207         false,  /* is_signin_to_add */
208         initial_auth_type,
209         NULL,   /* public_session_recommended_locales */
210         user_dict);
211     users_list.Append(user_dict);
212   }
213
214   webui_handler_->LoadUsers(users_list, false);
215 }
216
217 void AppLaunchSigninScreen::SetAuthType(
218     const std::string& username,
219     ScreenlockBridge::LockHandler::AuthType auth_type) {
220   return;
221 }
222
223 ScreenlockBridge::LockHandler::AuthType AppLaunchSigninScreen::GetAuthType(
224     const std::string& username) const {
225   return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
226 }
227
228 }  // namespace chromeos