OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/singleton.h" | 15 #include "base/singleton.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "chrome/browser/browser_list.h" | 19 #include "chrome/browser/browser_list.h" |
20 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
21 #include "chrome/browser/browser_window.h" | 21 #include "chrome/browser/browser_window.h" |
22 #include "chrome/browser/chromeos/cros/input_method_library.h" | 22 #include "chrome/browser/chromeos/cros/input_method_library.h" |
23 #include "chrome/browser/chromeos/cros/keyboard_library.h" | 23 #include "chrome/browser/chromeos/cros/keyboard_library.h" |
24 #include "chrome/browser/chromeos/cros/login_library.h" | 24 #include "chrome/browser/chromeos/cros/login_library.h" |
25 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 25 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
26 #include "chrome/browser/chromeos/language_preferences.h" | 26 #include "chrome/browser/chromeos/language_preferences.h" |
27 #include "chrome/browser/chromeos/login/authenticator.h" | 27 #include "chrome/browser/chromeos/login/authenticator.h" |
28 #include "chrome/browser/chromeos/login/background_view.h" | 28 #include "chrome/browser/chromeos/login/background_view.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/message_bubble.h" | 31 #include "chrome/browser/chromeos/login/message_bubble.h" |
31 #include "chrome/browser/chromeos/login/screen_lock_view.h" | 32 #include "chrome/browser/chromeos/login/screen_lock_view.h" |
32 #include "chrome/browser/chromeos/login/shutdown_button.h" | 33 #include "chrome/browser/chromeos/login/shutdown_button.h" |
33 #include "chrome/browser/chromeos/system_key_event_listener.h" | 34 #include "chrome/browser/chromeos/system_key_event_listener.h" |
34 #include "chrome/browser/chromeos/wm_ipc.h" | 35 #include "chrome/browser/chromeos/wm_ipc.h" |
35 #include "chrome/browser/metrics/user_metrics.h" | 36 #include "chrome/browser/metrics/user_metrics.h" |
36 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/notification_service.h" | 39 #include "chrome/common/notification_service.h" |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 LOG(ERROR) << "authentication_start_time_ is not set"; | 641 LOG(ERROR) << "authentication_start_time_ is not set"; |
641 } else { | 642 } else { |
642 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 643 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
643 VLOG(1) << "Authentication failure time: " << delta.InSecondsF(); | 644 VLOG(1) << "Authentication failure time: " << delta.InSecondsF(); |
644 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); | 645 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); |
645 } | 646 } |
646 | 647 |
647 EnableInput(); | 648 EnableInput(); |
648 // Don't enable signout button here as we're showing | 649 // Don't enable signout button here as we're showing |
649 // MessageBubble. | 650 // MessageBubble. |
650 gfx::Rect rect = screen_lock_view_->GetPasswordBoundsRelativeTo( | |
651 lock_widget_->GetRootView()); | |
652 gfx::Rect lock_widget_bounds; | |
653 lock_widget_->GetBounds(&lock_widget_bounds, false); | |
654 rect.Offset(lock_widget_bounds.x(), lock_widget_bounds.y()); | |
655 | 651 |
656 if (error_info_) | |
657 error_info_->Close(); | |
658 std::wstring msg = l10n_util::GetString(IDS_LOGIN_ERROR_AUTHENTICATING); | 652 std::wstring msg = l10n_util::GetString(IDS_LOGIN_ERROR_AUTHENTICATING); |
659 const std::string error_text = error.GetErrorString(); | 653 const std::string error_text = error.GetErrorString(); |
660 if (!error_text.empty()) | 654 if (!error_text.empty()) |
661 msg += L"\n" + ASCIIToWide(error_text); | 655 msg += L"\n" + ASCIIToWide(error_text); |
662 | 656 |
663 InputMethodLibrary* input_method_library = | 657 InputMethodLibrary* input_method_library = |
664 CrosLibrary::Get()->GetInputMethodLibrary(); | 658 CrosLibrary::Get()->GetInputMethodLibrary(); |
665 if (input_method_library->GetNumActiveInputMethods() > 1) | 659 if (input_method_library->GetNumActiveInputMethods() > 1) |
666 msg += L"\n" + l10n_util::GetString(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT); | 660 msg += L"\n" + l10n_util::GetString(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT); |
667 | 661 |
668 error_info_ = MessageBubble::ShowNoGrab( | 662 ShowErrorBubble(msg, BubbleBorder::BOTTOM_LEFT); |
669 lock_window_, | |
670 rect, | |
671 BubbleBorder::BOTTOM_LEFT, | |
672 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), | |
673 msg, | |
674 std::wstring(), // TODO: add help link | |
675 this); | |
676 if (mouse_event_relay_.get()) { | |
677 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); | |
678 } | |
679 mouse_event_relay_.reset( | |
680 new MouseEventRelay(lock_widget_->GetNativeView()->window, | |
681 error_info_->GetNativeView()->window)); | |
682 MessageLoopForUI::current()->AddObserver(mouse_event_relay_.get()); | |
683 } | 663 } |
684 | 664 |
685 void ScreenLocker::OnLoginSuccess( | 665 void ScreenLocker::OnLoginSuccess( |
686 const std::string& username, | 666 const std::string& username, |
687 const std::string& password, | 667 const std::string& password, |
688 const GaiaAuthConsumer::ClientLoginResult& unused, | 668 const GaiaAuthConsumer::ClientLoginResult& unused, |
689 bool pending_requests) { | 669 bool pending_requests) { |
690 VLOG(1) << "OnLoginSuccess: Sending Unlock request."; | 670 VLOG(1) << "OnLoginSuccess: Sending Unlock request."; |
691 if (authentication_start_time_.is_null()) { | 671 if (authentication_start_time_.is_null()) { |
692 LOG(ERROR) << "authentication_start_time_ is not set"; | 672 LOG(ERROR) << "authentication_start_time_ is not set"; |
(...skipping 14 matching lines...) Expand all Loading... |
707 if (mouse_event_relay_.get()) { | 687 if (mouse_event_relay_.get()) { |
708 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); | 688 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); |
709 mouse_event_relay_.reset(); | 689 mouse_event_relay_.reset(); |
710 } | 690 } |
711 } | 691 } |
712 | 692 |
713 void ScreenLocker::Authenticate(const string16& password) { | 693 void ScreenLocker::Authenticate(const string16& password) { |
714 authentication_start_time_ = base::Time::Now(); | 694 authentication_start_time_ = base::Time::Now(); |
715 screen_lock_view_->SetEnabled(false); | 695 screen_lock_view_->SetEnabled(false); |
716 screen_lock_view_->SetSignoutEnabled(false); | 696 screen_lock_view_->SetSignoutEnabled(false); |
717 BrowserThread::PostTask( | 697 |
718 BrowserThread::UI, FROM_HERE, | 698 // If LoginPerformer instance exists, |
719 NewRunnableMethod(authenticator_.get(), | 699 // initial online login phase is still active. |
720 &Authenticator::AuthenticateToUnlock, | 700 if (LoginPerformer::default_performer()) { |
721 user_.email(), | 701 DVLOG(1) << "Delegating authentication to LoginPerformer."; |
722 UTF16ToUTF8(password))); | 702 LoginPerformer::default_performer()->Login(user_.email(), |
| 703 UTF16ToUTF8(password)); |
| 704 } else { |
| 705 BrowserThread::PostTask( |
| 706 BrowserThread::UI, FROM_HERE, |
| 707 NewRunnableMethod(authenticator_.get(), |
| 708 &Authenticator::AuthenticateToUnlock, |
| 709 user_.email(), |
| 710 UTF16ToUTF8(password))); |
| 711 } |
723 } | 712 } |
724 | 713 |
725 void ScreenLocker::ClearErrors() { | 714 void ScreenLocker::ClearErrors() { |
726 if (error_info_) { | 715 if (error_info_) { |
727 error_info_->Close(); | 716 error_info_->Close(); |
728 error_info_ = NULL; | 717 error_info_ = NULL; |
729 } | 718 } |
730 } | 719 } |
731 | 720 |
732 void ScreenLocker::EnableInput() { | 721 void ScreenLocker::EnableInput() { |
733 if (screen_lock_view_) { | 722 if (screen_lock_view_) { |
734 screen_lock_view_->SetEnabled(true); | 723 screen_lock_view_->SetEnabled(true); |
735 screen_lock_view_->ClearAndSetFocusToPassword(); | 724 screen_lock_view_->ClearAndSetFocusToPassword(); |
736 } | 725 } |
737 } | 726 } |
738 | 727 |
739 void ScreenLocker::Signout() { | 728 void ScreenLocker::Signout() { |
740 if (!error_info_) { | 729 if (!error_info_) { |
741 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | 730 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
742 if (CrosLibrary::Get()->EnsureLoaded()) { | 731 if (CrosLibrary::Get()->EnsureLoaded()) { |
743 CrosLibrary::Get()->GetLoginLibrary()->StopSession(""); | 732 CrosLibrary::Get()->GetLoginLibrary()->StopSession(""); |
744 } | 733 } |
745 | 734 |
746 // Don't hide yet the locker because the chrome screen may become visible | 735 // Don't hide yet the locker because the chrome screen may become visible |
747 // briefly. | 736 // briefly. |
748 } | 737 } |
749 } | 738 } |
750 | 739 |
| 740 void ScreenLocker::ShowErrorMessage(const std::wstring& message, |
| 741 bool sign_out_only) { |
| 742 if (sign_out_only) { |
| 743 screen_lock_view_->SetEnabled(false); |
| 744 } else { |
| 745 EnableInput(); |
| 746 } |
| 747 screen_lock_view_->SetSignoutEnabled(sign_out_only); |
| 748 // Make sure that active Sign Out button is not hidden behind the bubble. |
| 749 ShowErrorBubble(message, sign_out_only ? |
| 750 BubbleBorder::BOTTOM_RIGHT : BubbleBorder::BOTTOM_LEFT); |
| 751 } |
| 752 |
751 void ScreenLocker::OnGrabInputs() { | 753 void ScreenLocker::OnGrabInputs() { |
752 DVLOG(1) << "OnGrabInputs"; | 754 DVLOG(1) << "OnGrabInputs"; |
753 input_grabbed_ = true; | 755 input_grabbed_ = true; |
754 if (drawn_) | 756 if (drawn_) |
755 ScreenLockReady(); | 757 ScreenLockReady(); |
756 } | 758 } |
757 | 759 |
758 // static | 760 // static |
759 void ScreenLocker::Show() { | 761 void ScreenLocker::Show() { |
760 VLOG(1) << "In ScreenLocker::Show"; | 762 VLOG(1) << "In ScreenLocker::Show"; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 } | 888 } |
887 } | 889 } |
888 | 890 |
889 void ScreenLocker::OnWindowManagerReady() { | 891 void ScreenLocker::OnWindowManagerReady() { |
890 DVLOG(1) << "OnClientEvent: drawn for lock"; | 892 DVLOG(1) << "OnClientEvent: drawn for lock"; |
891 drawn_ = true; | 893 drawn_ = true; |
892 if (input_grabbed_) | 894 if (input_grabbed_) |
893 ScreenLockReady(); | 895 ScreenLockReady(); |
894 } | 896 } |
895 | 897 |
| 898 void ScreenLocker::ShowErrorBubble(const std::wstring& message, |
| 899 BubbleBorder::ArrowLocation arrow_location) { |
| 900 if (error_info_) |
| 901 error_info_->Close(); |
| 902 |
| 903 gfx::Rect rect = screen_lock_view_->GetPasswordBoundsRelativeTo( |
| 904 lock_widget_->GetRootView()); |
| 905 gfx::Rect lock_widget_bounds; |
| 906 lock_widget_->GetBounds(&lock_widget_bounds, false); |
| 907 rect.Offset(lock_widget_bounds.x(), lock_widget_bounds.y()); |
| 908 |
| 909 error_info_ = MessageBubble::ShowNoGrab( |
| 910 lock_window_, |
| 911 rect, |
| 912 arrow_location, |
| 913 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), |
| 914 message, |
| 915 std::wstring(), // TODO(nkostylev): Add help link. |
| 916 this); |
| 917 |
| 918 if (mouse_event_relay_.get()) |
| 919 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); |
| 920 mouse_event_relay_.reset( |
| 921 new MouseEventRelay(lock_widget_->GetNativeView()->window, |
| 922 error_info_->GetNativeView()->window)); |
| 923 MessageLoopForUI::current()->AddObserver(mouse_event_relay_.get()); |
| 924 } |
| 925 |
896 void ScreenLocker::StopScreenSaver() { | 926 void ScreenLocker::StopScreenSaver() { |
897 if (background_view_->IsScreenSaverVisible()) { | 927 if (background_view_->IsScreenSaverVisible()) { |
898 VLOG(1) << "StopScreenSaver"; | 928 VLOG(1) << "StopScreenSaver"; |
899 background_view_->HideScreenSaver(); | 929 background_view_->HideScreenSaver(); |
900 if (screen_lock_view_) { | 930 if (screen_lock_view_) { |
901 screen_lock_view_->SetVisible(true); | 931 screen_lock_view_->SetVisible(true); |
902 screen_lock_view_->RequestFocus(); | 932 screen_lock_view_->RequestFocus(); |
903 } | 933 } |
904 EnableInput(); | 934 EnableInput(); |
905 } | 935 } |
(...skipping 15 matching lines...) Expand all Loading... |
921 | 951 |
922 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { | 952 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { |
923 if (!background_view_->IsScreenSaverVisible()) { | 953 if (!background_view_->IsScreenSaverVisible()) { |
924 StartScreenSaver(); | 954 StartScreenSaver(); |
925 return true; | 955 return true; |
926 } | 956 } |
927 return false; | 957 return false; |
928 } | 958 } |
929 | 959 |
930 } // namespace chromeos | 960 } // namespace chromeos |
OLD | NEW |