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