| 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 <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <X11/extensions/XTest.h> | 10 #include <X11/extensions/XTest.h> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/browser_list.h" | 25 #include "chrome/browser/browser_list.h" |
| 26 #include "chrome/browser/browser_thread.h" | 26 #include "chrome/browser/browser_thread.h" |
| 27 #include "chrome/browser/browser_window.h" | 27 #include "chrome/browser/browser_window.h" |
| 28 #include "chrome/browser/chromeos/cros/input_method_library.h" | 28 #include "chrome/browser/chromeos/cros/input_method_library.h" |
| 29 #include "chrome/browser/chromeos/cros/keyboard_library.h" | 29 #include "chrome/browser/chromeos/cros/keyboard_library.h" |
| 30 #include "chrome/browser/chromeos/cros/login_library.h" | 30 #include "chrome/browser/chromeos/cros/login_library.h" |
| 31 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 31 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
| 32 #include "chrome/browser/chromeos/language_preferences.h" | 32 #include "chrome/browser/chromeos/language_preferences.h" |
| 33 #include "chrome/browser/chromeos/login/authenticator.h" | 33 #include "chrome/browser/chromeos/login/authenticator.h" |
| 34 #include "chrome/browser/chromeos/login/background_view.h" | 34 #include "chrome/browser/chromeos/login/background_view.h" |
| 35 #include "chrome/browser/chromeos/login/login_performer.h" |
| 35 #include "chrome/browser/chromeos/login/login_utils.h" | 36 #include "chrome/browser/chromeos/login/login_utils.h" |
| 36 #include "chrome/browser/chromeos/login/message_bubble.h" | 37 #include "chrome/browser/chromeos/login/message_bubble.h" |
| 37 #include "chrome/browser/chromeos/login/screen_lock_view.h" | 38 #include "chrome/browser/chromeos/login/screen_lock_view.h" |
| 38 #include "chrome/browser/chromeos/login/shutdown_button.h" | 39 #include "chrome/browser/chromeos/login/shutdown_button.h" |
| 39 #include "chrome/browser/chromeos/system_key_event_listener.h" | 40 #include "chrome/browser/chromeos/system_key_event_listener.h" |
| 40 #include "chrome/browser/chromeos/wm_ipc.h" | 41 #include "chrome/browser/chromeos/wm_ipc.h" |
| 41 #include "chrome/browser/metrics/user_metrics.h" | 42 #include "chrome/browser/metrics/user_metrics.h" |
| 42 #include "chrome/browser/profile_manager.h" | 43 #include "chrome/browser/profile_manager.h" |
| 43 #include "chrome/browser/sync/profile_sync_service.h" | 44 #include "chrome/browser/sync/profile_sync_service.h" |
| 44 #include "chrome/browser/ui/browser.h" | 45 #include "chrome/browser/ui/browser.h" |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 LOG(ERROR) << "authentication_start_time_ is not set"; | 719 LOG(ERROR) << "authentication_start_time_ is not set"; |
| 719 } else { | 720 } else { |
| 720 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; | 721 base::TimeDelta delta = base::Time::Now() - authentication_start_time_; |
| 721 VLOG(1) << "Authentication failure time: " << delta.InSecondsF(); | 722 VLOG(1) << "Authentication failure time: " << delta.InSecondsF(); |
| 722 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); | 723 UMA_HISTOGRAM_TIMES("ScreenLocker.AuthenticationFailureTime", delta); |
| 723 } | 724 } |
| 724 | 725 |
| 725 EnableInput(); | 726 EnableInput(); |
| 726 // Don't enable signout button here as we're showing | 727 // Don't enable signout button here as we're showing |
| 727 // MessageBubble. | 728 // MessageBubble. |
| 728 gfx::Rect rect = screen_lock_view_->GetPasswordBoundsRelativeTo( | |
| 729 lock_widget_->GetRootView()); | |
| 730 gfx::Rect lock_widget_bounds; | |
| 731 lock_widget_->GetBounds(&lock_widget_bounds, false); | |
| 732 rect.Offset(lock_widget_bounds.x(), lock_widget_bounds.y()); | |
| 733 | 729 |
| 734 if (error_info_) | |
| 735 error_info_->Close(); | |
| 736 std::wstring msg = l10n_util::GetString(IDS_LOGIN_ERROR_AUTHENTICATING); | 730 std::wstring msg = l10n_util::GetString(IDS_LOGIN_ERROR_AUTHENTICATING); |
| 737 const std::string error_text = error.GetErrorString(); | 731 const std::string error_text = error.GetErrorString(); |
| 738 if (!error_text.empty()) | 732 if (!error_text.empty()) |
| 739 msg += L"\n" + ASCIIToWide(error_text); | 733 msg += L"\n" + ASCIIToWide(error_text); |
| 740 | 734 |
| 741 InputMethodLibrary* input_method_library = | 735 InputMethodLibrary* input_method_library = |
| 742 CrosLibrary::Get()->GetInputMethodLibrary(); | 736 CrosLibrary::Get()->GetInputMethodLibrary(); |
| 743 if (input_method_library->GetNumActiveInputMethods() > 1) | 737 if (input_method_library->GetNumActiveInputMethods() > 1) |
| 744 msg += L"\n" + l10n_util::GetString(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT); | 738 msg += L"\n" + l10n_util::GetString(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT); |
| 745 | 739 |
| 746 error_info_ = MessageBubble::ShowNoGrab( | 740 ShowErrorBubble(msg, BubbleBorder::BOTTOM_LEFT); |
| 747 lock_window_, | |
| 748 rect, | |
| 749 BubbleBorder::BOTTOM_LEFT, | |
| 750 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), | |
| 751 msg, | |
| 752 std::wstring(), // TODO: add help link | |
| 753 this); | |
| 754 if (mouse_event_relay_.get()) { | |
| 755 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); | |
| 756 } | |
| 757 mouse_event_relay_.reset( | |
| 758 new MouseEventRelay(lock_widget_->GetNativeView()->window, | |
| 759 error_info_->GetNativeView()->window)); | |
| 760 MessageLoopForUI::current()->AddObserver(mouse_event_relay_.get()); | |
| 761 } | 741 } |
| 762 | 742 |
| 763 void ScreenLocker::OnLoginSuccess( | 743 void ScreenLocker::OnLoginSuccess( |
| 764 const std::string& username, | 744 const std::string& username, |
| 765 const std::string& password, | 745 const std::string& password, |
| 766 const GaiaAuthConsumer::ClientLoginResult& unused, | 746 const GaiaAuthConsumer::ClientLoginResult& unused, |
| 767 bool pending_requests) { | 747 bool pending_requests) { |
| 768 VLOG(1) << "OnLoginSuccess: Sending Unlock request."; | 748 VLOG(1) << "OnLoginSuccess: Sending Unlock request."; |
| 769 if (authentication_start_time_.is_null()) { | 749 if (authentication_start_time_.is_null()) { |
| 770 LOG(ERROR) << "authentication_start_time_ is not set"; | 750 LOG(ERROR) << "authentication_start_time_ is not set"; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 794 if (mouse_event_relay_.get()) { | 774 if (mouse_event_relay_.get()) { |
| 795 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); | 775 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); |
| 796 mouse_event_relay_.reset(); | 776 mouse_event_relay_.reset(); |
| 797 } | 777 } |
| 798 } | 778 } |
| 799 | 779 |
| 800 void ScreenLocker::Authenticate(const string16& password) { | 780 void ScreenLocker::Authenticate(const string16& password) { |
| 801 authentication_start_time_ = base::Time::Now(); | 781 authentication_start_time_ = base::Time::Now(); |
| 802 screen_lock_view_->SetEnabled(false); | 782 screen_lock_view_->SetEnabled(false); |
| 803 screen_lock_view_->SetSignoutEnabled(false); | 783 screen_lock_view_->SetSignoutEnabled(false); |
| 804 BrowserThread::PostTask( | 784 |
| 805 BrowserThread::UI, FROM_HERE, | 785 // If LoginPerformer instance exists, |
| 806 NewRunnableMethod(authenticator_.get(), | 786 // initial online login phase is still active. |
| 807 &Authenticator::AuthenticateToUnlock, | 787 if (LoginPerformer::default_performer()) { |
| 808 user_.email(), | 788 DVLOG(1) << "Delegating authentication to LoginPerformer."; |
| 809 UTF16ToUTF8(password))); | 789 LoginPerformer::default_performer()->Login(user_.email(), |
| 790 UTF16ToUTF8(password)); |
| 791 } else { |
| 792 BrowserThread::PostTask( |
| 793 BrowserThread::UI, FROM_HERE, |
| 794 NewRunnableMethod(authenticator_.get(), |
| 795 &Authenticator::AuthenticateToUnlock, |
| 796 user_.email(), |
| 797 UTF16ToUTF8(password))); |
| 798 } |
| 810 } | 799 } |
| 811 | 800 |
| 812 void ScreenLocker::ClearErrors() { | 801 void ScreenLocker::ClearErrors() { |
| 813 if (error_info_) { | 802 if (error_info_) { |
| 814 error_info_->Close(); | 803 error_info_->Close(); |
| 815 error_info_ = NULL; | 804 error_info_ = NULL; |
| 816 } | 805 } |
| 817 } | 806 } |
| 818 | 807 |
| 819 void ScreenLocker::EnableInput() { | 808 void ScreenLocker::EnableInput() { |
| 820 if (screen_lock_view_) { | 809 if (screen_lock_view_) { |
| 821 screen_lock_view_->SetEnabled(true); | 810 screen_lock_view_->SetEnabled(true); |
| 822 screen_lock_view_->ClearAndSetFocusToPassword(); | 811 screen_lock_view_->ClearAndSetFocusToPassword(); |
| 823 } | 812 } |
| 824 } | 813 } |
| 825 | 814 |
| 826 void ScreenLocker::Signout() { | 815 void ScreenLocker::Signout() { |
| 827 if (!error_info_) { | 816 if (!error_info_) { |
| 828 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | 817 UserMetrics::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
| 829 if (CrosLibrary::Get()->EnsureLoaded()) { | 818 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 830 CrosLibrary::Get()->GetLoginLibrary()->StopSession(""); | 819 CrosLibrary::Get()->GetLoginLibrary()->StopSession(""); |
| 831 } | 820 } |
| 832 | 821 |
| 833 // Don't hide yet the locker because the chrome screen may become visible | 822 // Don't hide yet the locker because the chrome screen may become visible |
| 834 // briefly. | 823 // briefly. |
| 835 } | 824 } |
| 836 } | 825 } |
| 837 | 826 |
| 827 void ScreenLocker::ShowErrorMessage(const std::wstring& message, |
| 828 bool sign_out_only) { |
| 829 if (sign_out_only) { |
| 830 screen_lock_view_->SetEnabled(false); |
| 831 } else { |
| 832 EnableInput(); |
| 833 } |
| 834 screen_lock_view_->SetSignoutEnabled(sign_out_only); |
| 835 // Make sure that active Sign Out button is not hidden behind the bubble. |
| 836 ShowErrorBubble(message, sign_out_only ? |
| 837 BubbleBorder::BOTTOM_RIGHT : BubbleBorder::BOTTOM_LEFT); |
| 838 } |
| 839 |
| 838 void ScreenLocker::OnGrabInputs() { | 840 void ScreenLocker::OnGrabInputs() { |
| 839 DVLOG(1) << "OnGrabInputs"; | 841 DVLOG(1) << "OnGrabInputs"; |
| 840 input_grabbed_ = true; | 842 input_grabbed_ = true; |
| 841 if (drawn_) | 843 if (drawn_) |
| 842 ScreenLockReady(); | 844 ScreenLockReady(); |
| 843 } | 845 } |
| 844 | 846 |
| 845 // static | 847 // static |
| 846 void ScreenLocker::Show() { | 848 void ScreenLocker::Show() { |
| 847 VLOG(1) << "In ScreenLocker::Show"; | 849 VLOG(1) << "In ScreenLocker::Show"; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 } | 975 } |
| 974 } | 976 } |
| 975 | 977 |
| 976 void ScreenLocker::OnWindowManagerReady() { | 978 void ScreenLocker::OnWindowManagerReady() { |
| 977 DVLOG(1) << "OnClientEvent: drawn for lock"; | 979 DVLOG(1) << "OnClientEvent: drawn for lock"; |
| 978 drawn_ = true; | 980 drawn_ = true; |
| 979 if (input_grabbed_) | 981 if (input_grabbed_) |
| 980 ScreenLockReady(); | 982 ScreenLockReady(); |
| 981 } | 983 } |
| 982 | 984 |
| 985 void ScreenLocker::ShowErrorBubble(const std::wstring& message, |
| 986 BubbleBorder::ArrowLocation arrow_location) { |
| 987 if (error_info_) |
| 988 error_info_->Close(); |
| 989 |
| 990 gfx::Rect rect = screen_lock_view_->GetPasswordBoundsRelativeTo( |
| 991 lock_widget_->GetRootView()); |
| 992 gfx::Rect lock_widget_bounds; |
| 993 lock_widget_->GetBounds(&lock_widget_bounds, false); |
| 994 rect.Offset(lock_widget_bounds.x(), lock_widget_bounds.y()); |
| 995 error_info_ = MessageBubble::ShowNoGrab( |
| 996 lock_window_, |
| 997 rect, |
| 998 arrow_location, |
| 999 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), |
| 1000 message, |
| 1001 std::wstring(), // TODO(nkostylev): Add help link. |
| 1002 this); |
| 1003 |
| 1004 if (mouse_event_relay_.get()) |
| 1005 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); |
| 1006 mouse_event_relay_.reset( |
| 1007 new MouseEventRelay(lock_widget_->GetNativeView()->window, |
| 1008 error_info_->GetNativeView()->window)); |
| 1009 MessageLoopForUI::current()->AddObserver(mouse_event_relay_.get()); |
| 1010 } |
| 1011 |
| 983 void ScreenLocker::StopScreenSaver() { | 1012 void ScreenLocker::StopScreenSaver() { |
| 984 if (background_view_->IsScreenSaverVisible()) { | 1013 if (background_view_->IsScreenSaverVisible()) { |
| 985 VLOG(1) << "StopScreenSaver"; | 1014 VLOG(1) << "StopScreenSaver"; |
| 986 background_view_->HideScreenSaver(); | 1015 background_view_->HideScreenSaver(); |
| 987 if (screen_lock_view_) { | 1016 if (screen_lock_view_) { |
| 988 screen_lock_view_->SetVisible(true); | 1017 screen_lock_view_->SetVisible(true); |
| 989 screen_lock_view_->RequestFocus(); | 1018 screen_lock_view_->RequestFocus(); |
| 990 } | 1019 } |
| 991 EnableInput(); | 1020 EnableInput(); |
| 992 } | 1021 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1008 | 1037 |
| 1009 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { | 1038 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { |
| 1010 if (!background_view_->IsScreenSaverVisible()) { | 1039 if (!background_view_->IsScreenSaverVisible()) { |
| 1011 StartScreenSaver(); | 1040 StartScreenSaver(); |
| 1012 return true; | 1041 return true; |
| 1013 } | 1042 } |
| 1014 return false; | 1043 return false; |
| 1015 } | 1044 } |
| 1016 | 1045 |
| 1017 } // namespace chromeos | 1046 } // namespace chromeos |
| OLD | NEW |