| 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 13 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 13 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
| 14 #include "chrome/browser/chromeos/login/authenticator.h" | 14 #include "chrome/browser/chromeos/login/authenticator.h" |
| 15 #include "chrome/browser/chromeos/login/background_view.h" | 15 #include "chrome/browser/chromeos/login/background_view.h" |
| 16 #include "chrome/browser/chromeos/login/login_utils.h" | 16 #include "chrome/browser/chromeos/login/login_utils.h" |
| 17 #include "chrome/browser/chromeos/login/message_bubble.h" | 17 #include "chrome/browser/chromeos/login/message_bubble.h" |
| 18 #include "chrome/browser/chromeos/login/screen_lock_view.h" | 18 #include "chrome/browser/chromeos/login/screen_lock_view.h" |
| 19 #include "chrome/browser/chromeos/wm_ipc.h" |
| 19 #include "chrome/browser/metrics/user_metrics.h" | 20 #include "chrome/browser/metrics/user_metrics.h" |
| 20 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 22 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 24 #include "third_party/cros/chromeos_wm_ipc_enums.h" |
| 23 #include "views/screen.h" | 25 #include "views/screen.h" |
| 24 #include "views/widget/root_view.h" | 26 #include "views/widget/root_view.h" |
| 25 #include "views/widget/widget_gtk.h" | 27 #include "views/widget/widget_gtk.h" |
| 26 | 28 |
| 27 #include "chrome/browser/chromeos/wm_ipc.h" | |
| 28 #include "third_party/cros/chromeos_wm_ipc_enums.h" | |
| 29 | |
| 30 namespace { | 29 namespace { |
| 31 // The maxium times that the screen locker should try to grab input, | 30 // The maxium times that the screen locker should try to grab input, |
| 32 // and its interval. It has to be able to grab all inputs in 30 seconds, | 31 // and its interval. It has to be able to grab all inputs in 30 seconds, |
| 33 // otherwise chromium process fails and the session is terminated. | 32 // otherwise chromium process fails and the session is terminated. |
| 34 const int64 kRetryGrabIntervalMs = 500; | 33 const int64 kRetryGrabIntervalMs = 500; |
| 35 const int kGrabFailureLimit = 60; | 34 const int kGrabFailureLimit = 60; |
| 36 | 35 |
| 37 // Observer to start ScreenLocker when the screen lock | 36 // Observer to start ScreenLocker when the screen lock |
| 38 class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, | 37 class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, |
| 39 public NotificationObserver { | 38 public NotificationObserver { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD), | 80 : views::WidgetGtk(views::WidgetGtk::TYPE_CHILD), |
| 82 screen_locker_(screen_locker), | 81 screen_locker_(screen_locker), |
| 83 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 82 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
| 84 grab_failure_count_(0), | 83 grab_failure_count_(0), |
| 85 kbd_grab_status_(GDK_GRAB_INVALID_TIME), | 84 kbd_grab_status_(GDK_GRAB_INVALID_TIME), |
| 86 mouse_grab_status_(GDK_GRAB_INVALID_TIME) { | 85 mouse_grab_status_(GDK_GRAB_INVALID_TIME) { |
| 87 } | 86 } |
| 88 | 87 |
| 89 virtual void Show() { | 88 virtual void Show() { |
| 90 views::WidgetGtk::Show(); | 89 views::WidgetGtk::Show(); |
| 91 GtkWidget* current_grab_window = gtk_grab_get_current(); | 90 GtkWidget* current_grab_window; |
| 92 if (current_grab_window) | 91 // Make sure there is no grab widget so that gtk simply propagates |
| 92 // an event. This is necessary to allow message bubble and password |
| 93 // field, button to process events simultaneously. GTK |
| 94 // maintains grab widgets in a linked-list, so we need to remove |
| 95 // until it's empty. |
| 96 while ((current_grab_window = gtk_grab_get_current()) != NULL) |
| 93 gtk_grab_remove(current_grab_window); | 97 gtk_grab_remove(current_grab_window); |
| 94 | 98 |
| 95 gtk_grab_add(window_contents()); | |
| 96 | |
| 97 // Now steal all inputs. | 99 // Now steal all inputs. |
| 98 TryGrabAllInputs(); | 100 TryGrabAllInputs(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event) { | 103 virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event) { |
| 102 WidgetGtk::OnButtonPress(widget, event); | 104 WidgetGtk::OnButtonPress(widget, event); |
| 103 // Never propagate event to parent. | 105 // Never propagate event to parent. |
| 104 return true; | 106 return true; |
| 105 } | 107 } |
| 106 | 108 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 gdk_window_get_geometry(src_, &src_x, &src_y, &width, &height, &depth); | 185 gdk_window_get_geometry(src_, &src_x, &src_y, &width, &height, &depth); |
| 184 gdk_window_get_geometry(dest_, &dest_x, &dest_y, &width, &height, &depth); | 186 gdk_window_get_geometry(dest_, &dest_x, &dest_y, &width, &height, &depth); |
| 185 | 187 |
| 186 offset_.SetPoint(dest_x - src_x, dest_y - src_y); | 188 offset_.SetPoint(dest_x - src_x, dest_y - src_y); |
| 187 } | 189 } |
| 188 | 190 |
| 189 virtual void WillProcessEvent(GdkEvent* event) {} | 191 virtual void WillProcessEvent(GdkEvent* event) {} |
| 190 | 192 |
| 191 virtual void DidProcessEvent(GdkEvent* event) { | 193 virtual void DidProcessEvent(GdkEvent* event) { |
| 192 if (event->any.window != src_) { | 194 if (event->any.window != src_) { |
| 193 DLOG(INFO) << "ignore event src non grab window: " << event->type; | |
| 194 return; | 195 return; |
| 195 } | 196 } |
| 196 | 197 |
| 197 if (event->type == GDK_BUTTON_PRESS || | 198 if (event->type == GDK_BUTTON_PRESS || |
| 198 event->type == GDK_BUTTON_RELEASE) { | 199 event->type == GDK_BUTTON_RELEASE) { |
| 199 GdkEvent* copy = gdk_event_copy(event); | 200 GdkEvent* copy = gdk_event_copy(event); |
| 200 copy->button.window = dest_; | 201 copy->button.window = dest_; |
| 201 g_object_ref(copy->button.window); | 202 g_object_ref(copy->button.window); |
| 202 copy->button.x -= offset_.x(); | 203 copy->button.x -= offset_.x(); |
| 203 copy->button.y -= offset_.y(); | 204 copy->button.y -= offset_.y(); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } | 441 } |
| 441 | 442 |
| 442 void ScreenLocker::OnMap(GtkWidget* widget, GdkEvent* event) { | 443 void ScreenLocker::OnMap(GtkWidget* widget, GdkEvent* event) { |
| 443 DLOG(INFO) << "OnMap"; | 444 DLOG(INFO) << "OnMap"; |
| 444 mapped_ = true; | 445 mapped_ = true; |
| 445 if (input_grabbed_) | 446 if (input_grabbed_) |
| 446 ScreenLockReady(); | 447 ScreenLockReady(); |
| 447 } | 448 } |
| 448 | 449 |
| 449 } // namespace chromeos | 450 } // namespace chromeos |
| OLD | NEW |