Upstream version 7.36.149.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/user.h"
11 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_ui.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
16
17 namespace chromeos {
18
19 UserManager* AppLaunchSigninScreen::test_user_manager_ = NULL;
20
21 AppLaunchSigninScreen::AppLaunchSigninScreen(
22     OobeUI* oobe_ui, Delegate* delegate)
23     : oobe_ui_(oobe_ui),
24       delegate_(delegate),
25       webui_handler_(NULL) {
26 }
27
28 AppLaunchSigninScreen::~AppLaunchSigninScreen() {
29   oobe_ui_->ResetSigninScreenHandlerDelegate();
30 }
31
32 void AppLaunchSigninScreen::Show() {
33   InitOwnerUserList();
34   oobe_ui_->web_ui()->CallJavascriptFunction(
35       "login.AccountPickerScreen.setShouldShowApps",
36       base::FundamentalValue(false));
37   oobe_ui_->ShowSigninScreen(LoginScreenContext(), this, NULL);
38 }
39
40 void AppLaunchSigninScreen::InitOwnerUserList() {
41   UserManager* user_manager = GetUserManager();
42   const std::string& owner_email = user_manager->GetOwnerEmail();
43   const UserList& all_users = user_manager->GetUsers();
44
45   owner_user_list_.clear();
46   for (UserList::const_iterator it = all_users.begin();
47        it != all_users.end();
48        ++it) {
49     User* user = *it;
50     if (user->email() == owner_email) {
51       owner_user_list_.push_back(user);
52       break;
53     }
54   }
55 }
56
57 // static
58 void AppLaunchSigninScreen::SetUserManagerForTesting(
59     UserManager* user_manager) {
60   test_user_manager_ = user_manager;
61 }
62
63 UserManager* AppLaunchSigninScreen::GetUserManager() {
64   return test_user_manager_ ? test_user_manager_ : UserManager::Get();
65 }
66
67 void AppLaunchSigninScreen::CancelPasswordChangedFlow() {
68   NOTREACHED();
69 }
70
71 void AppLaunchSigninScreen::CancelUserAdding() {
72   NOTREACHED();
73 }
74
75 void AppLaunchSigninScreen::CreateAccount() {
76   NOTREACHED();
77 }
78
79 void AppLaunchSigninScreen::CompleteLogin(const UserContext& user_context) {
80   NOTREACHED();
81 }
82
83 void AppLaunchSigninScreen::Login(const UserContext& user_context) {
84   // Note: LoginUtils::CreateAuthenticator doesn't necessarily create
85   // a new Authenticator object, and could reuse an existing one.
86   authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
87   content::BrowserThread::PostTask(
88       content::BrowserThread::UI, FROM_HERE,
89       base::Bind(&Authenticator::AuthenticateToUnlock,
90                  authenticator_.get(),
91                  user_context));
92 }
93
94 void AppLaunchSigninScreen::LoginAsRetailModeUser() {
95   NOTREACHED();
96 }
97
98 void AppLaunchSigninScreen::LoginAsGuest() {
99   NOTREACHED();
100 }
101
102 void AppLaunchSigninScreen::MigrateUserData(const std::string& old_password) {
103   NOTREACHED();
104 }
105
106 void AppLaunchSigninScreen::LoginAsPublicAccount(const std::string& username) {
107   NOTREACHED();
108 }
109
110 void AppLaunchSigninScreen::LoadWallpaper(const std::string& username) {
111 }
112
113 void AppLaunchSigninScreen::LoadSigninWallpaper() {
114 }
115
116 void AppLaunchSigninScreen::OnSigninScreenReady() {
117 }
118
119 void AppLaunchSigninScreen::RemoveUser(const std::string& username) {
120   NOTREACHED();
121 }
122
123 void AppLaunchSigninScreen::ResyncUserData() {
124   NOTREACHED();
125 }
126
127 void AppLaunchSigninScreen::ShowEnterpriseEnrollmentScreen() {
128   NOTREACHED();
129 }
130
131 void AppLaunchSigninScreen::ShowKioskEnableScreen() {
132   NOTREACHED();
133 }
134
135 void AppLaunchSigninScreen::ShowKioskAutolaunchScreen() {
136   NOTREACHED();
137 }
138
139 void AppLaunchSigninScreen::ShowWrongHWIDScreen() {
140   NOTREACHED();
141 }
142
143 void AppLaunchSigninScreen::SetWebUIHandler(
144     LoginDisplayWebUIHandler* webui_handler) {
145   webui_handler_ = webui_handler;
146 }
147
148 void AppLaunchSigninScreen::ShowSigninScreenForCreds(
149     const std::string& username,
150     const std::string& password) {
151   NOTREACHED();
152 }
153
154 const UserList& AppLaunchSigninScreen::GetUsers() const {
155   return owner_user_list_;
156 }
157
158 bool AppLaunchSigninScreen::IsShowGuest() const {
159   return false;
160 }
161
162 bool AppLaunchSigninScreen::IsShowUsers() const {
163   return true;
164 }
165
166 bool AppLaunchSigninScreen::IsShowNewUser() const {
167   return false;
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 }  // namespace chromeos