OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/screen_locker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/audio/sounds.h" | 11 #include "ash/audio/sounds.h" |
12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/wm/lock_state_controller.h" | 14 #include "ash/wm/lock_state_controller.h" |
15 #include "ash/wm/window_state.h" | 15 #include "ash/wm/window_state.h" |
16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/timer/timer.h" | 25 #include "base/timer/timer.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/chromeos/extensions/screenlock_private_api.h" |
27 #include "chrome/browser/chromeos/login/authenticator.h" | 28 #include "chrome/browser/chromeos/login/authenticator.h" |
28 #include "chrome/browser/chromeos/login/login_performer.h" | 29 #include "chrome/browser/chromeos/login/login_performer.h" |
29 #include "chrome/browser/chromeos/login/login_utils.h" | 30 #include "chrome/browser/chromeos/login/login_utils.h" |
30 #include "chrome/browser/chromeos/login/user_adding_screen.h" | 31 #include "chrome/browser/chromeos/login/user_adding_screen.h" |
31 #include "chrome/browser/chromeos/login/user_manager.h" | 32 #include "chrome/browser/chromeos/login/user_manager.h" |
32 #include "chrome/browser/chromeos/login/webui_screen_locker.h" | 33 #include "chrome/browser/chromeos/login/webui_screen_locker.h" |
33 #include "chrome/browser/lifetime/application_lifetime.h" | 34 #include "chrome/browser/lifetime/application_lifetime.h" |
34 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
35 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
36 #include "chrome/browser/signin/signin_manager.h" | 37 #include "chrome/browser/signin/signin_manager.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 authentication_capture_.reset(); | 250 authentication_capture_.reset(); |
250 weak_factory_.InvalidateWeakPtrs(); | 251 weak_factory_.InvalidateWeakPtrs(); |
251 | 252 |
252 VLOG(1) << "Hiding the lock screen."; | 253 VLOG(1) << "Hiding the lock screen."; |
253 chromeos::ScreenLocker::Hide(); | 254 chromeos::ScreenLocker::Hide(); |
254 } | 255 } |
255 | 256 |
256 void ScreenLocker::Authenticate(const UserContext& user_context) { | 257 void ScreenLocker::Authenticate(const UserContext& user_context) { |
257 LOG_ASSERT(IsUserLoggedIn(user_context.username)) | 258 LOG_ASSERT(IsUserLoggedIn(user_context.username)) |
258 << "Invalid user trying to unlock."; | 259 << "Invalid user trying to unlock."; |
| 260 |
259 authentication_start_time_ = base::Time::Now(); | 261 authentication_start_time_ = base::Time::Now(); |
260 delegate_->SetInputEnabled(false); | 262 delegate_->SetInputEnabled(false); |
261 delegate_->OnAuthenticate(); | 263 delegate_->OnAuthenticate(); |
262 | 264 |
| 265 // Send authentication request to app using chrome.screenlockPrivate API |
| 266 // if the authentication type is not the system password. |
| 267 LoginDisplay::AuthType auth_type = GetAuthType(user_context.username); |
| 268 if (auth_type != LoginDisplay::OFFLINE_PASSWORD) { |
| 269 // Find the user that is authenticating. |
| 270 const User* unlock_user = NULL; |
| 271 for (UserList::const_iterator it = users_.begin(); |
| 272 it != users_.end(); |
| 273 ++it) { |
| 274 if ((*it)->email() == user_context.username) { |
| 275 unlock_user = *it; |
| 276 break; |
| 277 } |
| 278 } |
| 279 LOG_ASSERT(unlock_user); |
| 280 |
| 281 // TODO(tengs): dispatch auth attempted event to the screenlockPrivate |
| 282 // API's event router. |
| 283 return; |
| 284 } |
| 285 |
263 BrowserThread::PostTask( | 286 BrowserThread::PostTask( |
264 BrowserThread::UI, FROM_HERE, | 287 BrowserThread::UI, FROM_HERE, |
265 base::Bind(&Authenticator::AuthenticateToUnlock, | 288 base::Bind(&Authenticator::AuthenticateToUnlock, |
266 authenticator_.get(), | 289 authenticator_.get(), |
267 user_context)); | 290 user_context)); |
268 } | 291 } |
269 | 292 |
270 void ScreenLocker::AuthenticateByPassword(const std::string& password) { | 293 void ScreenLocker::AuthenticateByPassword(const std::string& password) { |
271 LOG_ASSERT(users_.size() == 1); | 294 LOG_ASSERT(users_.size() == 1); |
272 Authenticate(UserContext(users_[0]->email(), password, "")); | 295 Authenticate(UserContext(users_[0]->email(), password, "")); |
(...skipping 23 matching lines...) Expand all Loading... |
296 } | 319 } |
297 | 320 |
298 void ScreenLocker::ShowUserPodButton(const std::string& username, | 321 void ScreenLocker::ShowUserPodButton(const std::string& username, |
299 const gfx::Image& icon, | 322 const gfx::Image& icon, |
300 const base::Closure& click_callback) { | 323 const base::Closure& click_callback) { |
301 if (!locked_) | 324 if (!locked_) |
302 return; | 325 return; |
303 | 326 |
304 screenlock_icon_provider_->AddIcon(username, icon); | 327 screenlock_icon_provider_->AddIcon(username, icon); |
305 | 328 |
306 // Append the current time to the URL so the image will not be cached. | 329 if (!username.empty()) { |
307 std::string icon_url = ScreenlockIconSource::GetIconURLForUser(username) | 330 // Append the current time to the URL so the image will not be cached. |
308 + "?" + base::Int64ToString(base::Time::Now().ToInternalValue()); | 331 std::string icon_url = |
309 delegate_->ShowUserPodButton(username, icon_url, click_callback); | 332 ScreenlockIconSource::GetIconURLForUser(username) + "?uniq=" + |
| 333 base::Int64ToString(base::Time::Now().ToInternalValue()); |
| 334 delegate_->ShowUserPodButton(username, icon_url, click_callback); |
| 335 } |
| 336 } |
| 337 |
| 338 void ScreenLocker::HideUserPodButton(const std::string& username) { |
| 339 if (!locked_) |
| 340 return; |
| 341 screenlock_icon_provider_->RemoveIcon(username); |
| 342 delegate_->HideUserPodButton(username); |
| 343 } |
| 344 |
| 345 void ScreenLocker::SetAuthType(const std::string& username, |
| 346 LoginDisplay::AuthType auth_type, |
| 347 const std::string& initial_value) { |
| 348 if (!locked_) |
| 349 return; |
| 350 delegate_->SetAuthType(username, auth_type, initial_value); |
| 351 } |
| 352 |
| 353 LoginDisplay::AuthType ScreenLocker::GetAuthType(const std::string& username) |
| 354 const { |
| 355 // Return default authentication type when not locked. |
| 356 if (!locked_) |
| 357 return LoginDisplay::OFFLINE_PASSWORD; |
| 358 return delegate_->GetAuthType(username); |
310 } | 359 } |
311 | 360 |
312 void ScreenLocker::ShowErrorMessage(int error_msg_id, | 361 void ScreenLocker::ShowErrorMessage(int error_msg_id, |
313 HelpAppLauncher::HelpTopic help_topic_id, | 362 HelpAppLauncher::HelpTopic help_topic_id, |
314 bool sign_out_only) { | 363 bool sign_out_only) { |
315 delegate_->SetInputEnabled(!sign_out_only); | 364 delegate_->SetInputEnabled(!sign_out_only); |
316 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | 365 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); |
317 } | 366 } |
318 | 367 |
319 void ScreenLocker::SetLoginStatusConsumer( | 368 void ScreenLocker::SetLoginStatusConsumer( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 523 |
475 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | 524 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { |
476 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 525 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
477 if ((*it)->email() == username) | 526 if ((*it)->email() == username) |
478 return true; | 527 return true; |
479 } | 528 } |
480 return false; | 529 return false; |
481 } | 530 } |
482 | 531 |
483 } // namespace chromeos | 532 } // namespace chromeos |
OLD | NEW |