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