| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_views.h" | 5 #include "chrome/browser/chromeos/login/screen_locker_views.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XTest.h> | 7 #include <X11/extensions/XTest.h> |
| 8 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
| 9 #include <gdk/gdkkeysyms.h> | 9 #include <gdk/gdkkeysyms.h> |
| 10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| 11 | 11 |
| 12 // Evil hack to undo X11 evil #define. | 12 // Evil hack to undo X11 evil #define. |
| 13 #undef None | 13 #undef None |
| 14 #undef Status | 14 #undef Status |
| 15 | 15 |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/chromeos/login/background_view.h" | 18 #include "chrome/browser/chromeos/login/background_view.h" |
| 19 #include "chrome/browser/chromeos/login/login_performer.h" | 19 #include "chrome/browser/chromeos/login/login_performer.h" |
| 20 #include "chrome/browser/chromeos/login/message_bubble.h" | 20 #include "chrome/browser/chromeos/login/message_bubble.h" |
| 21 #include "chrome/browser/chromeos/login/screen_lock_view.h" | 21 #include "chrome/browser/chromeos/login/screen_lock_view.h" |
| 22 #include "chrome/browser/chromeos/login/screen_locker.h" | 22 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 23 #include "chrome/browser/chromeos/login/shutdown_button.h" | 23 #include "chrome/browser/chromeos/login/shutdown_button.h" |
| 24 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" | 24 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" |
| 25 #include "chrome/browser/chromeos/view_ids.h" | 25 #include "chrome/browser/chromeos/view_ids.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/ui/views/window.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 29 #include "content/browser/user_metrics.h" | 30 #include "content/browser/user_metrics.h" |
| 30 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/base/x/x11_util.h" | 33 #include "ui/base/x/x11_util.h" |
| 33 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 35 #include "ui/views/controls/textfield/textfield.h" |
| 34 | 36 |
| 35 #if defined(TOOLKIT_USES_GTK) | 37 #if defined(TOOLKIT_USES_GTK) |
| 36 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" | 38 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" |
| 39 #include "ui/views/widget/native_widget_gtk.h" |
| 37 #endif | 40 #endif |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| 40 | 43 |
| 41 // The active ScreenLockerDelegate. | 44 // The active ScreenLockerDelegate. |
| 42 chromeos::ScreenLockerViews* screen_locker_view_ = NULL; | 45 chromeos::ScreenLockerViews* screen_locker_view_ = NULL; |
| 43 | 46 |
| 44 // The maximum duration for which locker should try to grab the keyboard and | 47 // The maximum duration for which locker should try to grab the keyboard and |
| 45 // mouse and its interval for regrabbing on failure. | 48 // mouse and its interval for regrabbing on failure. |
| 46 const int kMaxGrabFailureSec = 30; | 49 const int kMaxGrabFailureSec = 30; |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 screen_lock_view_->SetVisible(false); | 789 screen_lock_view_->SetVisible(false); |
| 787 grab_container_->SetScreenLockView(captcha_view_); | 790 grab_container_->SetScreenLockView(captcha_view_); |
| 788 background_container_->SetScreenLockView(captcha_view_); | 791 background_container_->SetScreenLockView(captcha_view_); |
| 789 captcha_view_->SetVisible(true); | 792 captcha_view_->SetVisible(true); |
| 790 // Take ScreenLockView ownership now that it's removed from grab_container_. | 793 // Take ScreenLockView ownership now that it's removed from grab_container_. |
| 791 secondary_view_.reset(screen_lock_view_); | 794 secondary_view_.reset(screen_lock_view_); |
| 792 } | 795 } |
| 793 | 796 |
| 794 void ScreenLockerViews::ClearErrors() { | 797 void ScreenLockerViews::ClearErrors() { |
| 795 if (error_info_) { | 798 if (error_info_) { |
| 796 error_info_->Close(); | 799 error_info_->GetWidget()->Close(); |
| 797 error_info_ = NULL; | 800 error_info_ = NULL; |
| 798 } | 801 } |
| 799 } | 802 } |
| 800 | 803 |
| 801 void ScreenLockerViews::BubbleClosing(Bubble* bubble, bool closed_by_escape) { | 804 void ScreenLockerViews::OnWidgetClosing(views::Widget* widget) { |
| 805 if (!error_info_ || error_info_->GetWidget() != widget) |
| 806 return; |
| 807 |
| 802 error_info_ = NULL; | 808 error_info_ = NULL; |
| 803 SetSignoutEnabled(true); | 809 SetSignoutEnabled(true); |
| 804 if (mouse_event_relay_.get()) { | 810 if (mouse_event_relay_.get()) { |
| 805 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); | 811 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); |
| 806 mouse_event_relay_.reset(); | 812 mouse_event_relay_.reset(); |
| 807 } | 813 } |
| 808 } | 814 } |
| 809 | 815 |
| 810 bool ScreenLockerViews::CloseOnEscape() { | |
| 811 return true; | |
| 812 } | |
| 813 | |
| 814 bool ScreenLockerViews::FadeInOnShow() { | |
| 815 return false; | |
| 816 } | |
| 817 | |
| 818 void ScreenLockerViews::OnLinkActivated(size_t index) { | |
| 819 } | |
| 820 | |
| 821 void ScreenLockerViews::OnCaptchaEntered(const std::string& captcha) { | 816 void ScreenLockerViews::OnCaptchaEntered(const std::string& captcha) { |
| 822 // Captcha dialog is only shown when LoginPerformer instance exists, | 817 // Captcha dialog is only shown when LoginPerformer instance exists, |
| 823 // i.e. blocking UI after password change is in place. | 818 // i.e. blocking UI after password change is in place. |
| 824 DCHECK(LoginPerformer::default_performer()); | 819 DCHECK(LoginPerformer::default_performer()); |
| 825 LoginPerformer::default_performer()->set_captcha(captcha); | 820 LoginPerformer::default_performer()->set_captcha(captcha); |
| 826 | 821 |
| 827 // ScreenLockView ownership is passed to grab_container_. | 822 // ScreenLockView ownership is passed to grab_container_. |
| 828 // Need to save return value here so that compile | 823 // Need to save return value here so that compile |
| 829 // doesn't fail with "unused result" warning. | 824 // doesn't fail with "unused result" warning. |
| 830 ignore_result(secondary_view_.release()); | 825 ignore_result(secondary_view_.release()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 void ScreenLockerViews::OnWindowManagerReady() { | 858 void ScreenLockerViews::OnWindowManagerReady() { |
| 864 DVLOG(1) << "OnClientEvent: drawn for lock"; | 859 DVLOG(1) << "OnClientEvent: drawn for lock"; |
| 865 drawn_ = true; | 860 drawn_ = true; |
| 866 if (input_grabbed_) | 861 if (input_grabbed_) |
| 867 ScreenLockReady(); | 862 ScreenLockReady(); |
| 868 } | 863 } |
| 869 | 864 |
| 870 void ScreenLockerViews::ShowErrorBubble( | 865 void ScreenLockerViews::ShowErrorBubble( |
| 871 const string16& message, | 866 const string16& message, |
| 872 views::BubbleBorder::ArrowLocation arrow_location) { | 867 views::BubbleBorder::ArrowLocation arrow_location) { |
| 873 if (error_info_) | 868 ClearErrors(); |
| 874 error_info_->Close(); | |
| 875 | 869 |
| 876 gfx::Rect rect = screen_lock_view_->GetPasswordBoundsRelativeTo( | 870 // TODO(nkostylev): Add help link. |
| 877 lock_widget_->GetRootView()); | 871 std::vector<string16> help_links; |
| 878 gfx::Rect lock_widget_bounds = lock_widget_->GetClientAreaScreenBounds(); | 872 error_info_ = new MessageBubble( |
| 879 rect.Offset(lock_widget_bounds.x(), lock_widget_bounds.y()); | 873 screen_lock_view_->password_field(), |
| 880 error_info_ = MessageBubble::ShowNoGrab( | |
| 881 lock_window_, | |
| 882 rect, | |
| 883 arrow_location, | 874 arrow_location, |
| 884 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), | 875 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), |
| 885 UTF16ToWide(message), | 876 message, |
| 886 UTF16ToWide(string16()), // TODO(nkostylev): Add help link. | 877 help_links); |
| 887 this); | 878 browser::CreateViewsBubbleAboveLockScreen(error_info_); |
| 879 error_info_->Show(); |
| 880 error_info_->GetWidget()->AddObserver(this); |
| 888 | 881 |
| 889 if (mouse_event_relay_.get()) | 882 if (mouse_event_relay_.get()) |
| 890 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); | 883 MessageLoopForUI::current()->RemoveObserver(mouse_event_relay_.get()); |
| 884 // TODO(oshima|msw): Investigate MouseEventRelay problems: crosbug.com/23324. |
| 891 mouse_event_relay_.reset( | 885 mouse_event_relay_.reset( |
| 892 new MouseEventRelay(lock_widget_->GetNativeView()->window, | 886 new MouseEventRelay(lock_widget_->GetNativeView()->window, |
| 893 error_info_->GetNativeView()->window)); | 887 error_info_->GetWidget()->GetNativeView()->window)); |
| 894 MessageLoopForUI::current()->AddObserver(mouse_event_relay_.get()); | 888 MessageLoopForUI::current()->AddObserver(mouse_event_relay_.get()); |
| 895 } | 889 } |
| 896 | 890 |
| 897 bool ScreenLockerViews::AcceleratorPressed( | 891 bool ScreenLockerViews::AcceleratorPressed( |
| 898 const ui::Accelerator& accelerator) { | 892 const ui::Accelerator& accelerator) { |
| 899 if (!background_view_->IsScreenSaverVisible()) { | 893 if (!background_view_->IsScreenSaverVisible()) { |
| 900 screen_locker_view_->StartScreenSaver(); | 894 screen_locker_view_->StartScreenSaver(); |
| 901 return true; | 895 return true; |
| 902 } | 896 } |
| 903 return false; | 897 return false; |
| 904 } | 898 } |
| 905 | 899 |
| 906 void ScreenLockerViews::OnClientEvent(GtkWidget* widge, GdkEventClient* event) { | 900 void ScreenLockerViews::OnClientEvent(GtkWidget* widge, GdkEventClient* event) { |
| 907 #if defined(TOOLKIT_USES_GTK) | 901 #if defined(TOOLKIT_USES_GTK) |
| 908 WmIpc::Message msg; | 902 WmIpc::Message msg; |
| 909 WmIpc::instance()->DecodeMessage(*event, &msg); | 903 WmIpc::instance()->DecodeMessage(*event, &msg); |
| 910 if (msg.type() == WM_IPC_MESSAGE_CHROME_NOTIFY_SCREEN_REDRAWN_FOR_LOCK) { | 904 if (msg.type() == WM_IPC_MESSAGE_CHROME_NOTIFY_SCREEN_REDRAWN_FOR_LOCK) { |
| 911 OnWindowManagerReady(); | 905 OnWindowManagerReady(); |
| 912 } | 906 } |
| 913 #endif | 907 #endif |
| 914 } | 908 } |
| 915 | 909 |
| 916 } // namespace chromeos | 910 } // namespace chromeos |
| OLD | NEW |