| 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> |
| 11 #include <X11/keysym.h> | 11 #include <X11/keysym.h> |
| 12 // Evil hack to undo X11 evil #define. See crosbug.com/ | 12 // Evil hack to undo X11 evil #define. See crosbug.com/ |
| 13 #undef Status | 13 #undef Status |
| 14 | 14 |
| 15 #include "app/l10n_util.h" | 15 #include "app/l10n_util.h" |
| 16 #include "app/resource_bundle.h" | 16 #include "app/resource_bundle.h" |
| 17 #include "app/x11_util.h" | |
| 18 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 19 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 20 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 21 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 22 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 23 #include "base/timer.h" | 22 #include "base/timer.h" |
| 24 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 25 #include "chrome/browser/browser_list.h" | 24 #include "chrome/browser/browser_list.h" |
| 26 #include "chrome/browser/browser_thread.h" | 25 #include "chrome/browser/browser_thread.h" |
| 27 #include "chrome/browser/browser_window.h" | 26 #include "chrome/browser/browser_window.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 #include "chrome/browser/metrics/user_metrics.h" | 41 #include "chrome/browser/metrics/user_metrics.h" |
| 43 #include "chrome/browser/profiles/profile_manager.h" | 42 #include "chrome/browser/profiles/profile_manager.h" |
| 44 #include "chrome/browser/sync/profile_sync_service.h" | 43 #include "chrome/browser/sync/profile_sync_service.h" |
| 45 #include "chrome/browser/ui/browser.h" | 44 #include "chrome/browser/ui/browser.h" |
| 46 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/common/notification_service.h" | 46 #include "chrome/common/notification_service.h" |
| 48 #include "googleurl/src/gurl.h" | 47 #include "googleurl/src/gurl.h" |
| 49 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
| 50 #include "grit/theme_resources.h" | 49 #include "grit/theme_resources.h" |
| 51 #include "third_party/cros/chromeos_wm_ipc_enums.h" | 50 #include "third_party/cros/chromeos_wm_ipc_enums.h" |
| 51 #include "ui/base/x/x11_util.h" |
| 52 #include "views/screen.h" | 52 #include "views/screen.h" |
| 53 #include "views/widget/root_view.h" | 53 #include "views/widget/root_view.h" |
| 54 #include "views/widget/widget_gtk.h" | 54 #include "views/widget/widget_gtk.h" |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 // The maximum duration for which locker should try to grab the keyboard and | 58 // The maximum duration for which locker should try to grab the keyboard and |
| 59 // mouse and its interval for regrabbing on failure. | 59 // mouse and its interval for regrabbing on failure. |
| 60 const int kMaxGrabFailureSec = 30; | 60 const int kMaxGrabFailureSec = 30; |
| 61 const int64 kRetryGrabIntervalMs = 500; | 61 const int64 kRetryGrabIntervalMs = 500; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 screen_locker_->OnGrabInputs(); | 398 screen_locker_->OnGrabInputs(); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 void GrabWidget::TryUngrabOtherClients() { | 402 void GrabWidget::TryUngrabOtherClients() { |
| 403 #if !defined(NDEBUG) | 403 #if !defined(NDEBUG) |
| 404 { | 404 { |
| 405 int event_base, error_base; | 405 int event_base, error_base; |
| 406 int major, minor; | 406 int major, minor; |
| 407 // Make sure we have XTest extension. | 407 // Make sure we have XTest extension. |
| 408 DCHECK(XTestQueryExtension(x11_util::GetXDisplay(), | 408 DCHECK(XTestQueryExtension(ui::GetXDisplay(), |
| 409 &event_base, &error_base, | 409 &event_base, &error_base, |
| 410 &major, &minor)); | 410 &major, &minor)); |
| 411 } | 411 } |
| 412 #endif | 412 #endif |
| 413 | 413 |
| 414 // The following code is an attempt to grab inputs by closing | 414 // The following code is an attempt to grab inputs by closing |
| 415 // supposedly opened menu. This happens when a plugin has a menu | 415 // supposedly opened menu. This happens when a plugin has a menu |
| 416 // opened. | 416 // opened. |
| 417 if (mouse_grab_status_ == GDK_GRAB_ALREADY_GRABBED || | 417 if (mouse_grab_status_ == GDK_GRAB_ALREADY_GRABBED || |
| 418 mouse_grab_status_ == GDK_GRAB_FROZEN) { | 418 mouse_grab_status_ == GDK_GRAB_FROZEN) { |
| 419 // Successfully grabbed the keyboard, but pointer is still | 419 // Successfully grabbed the keyboard, but pointer is still |
| 420 // grabbed by other client. Another attempt to close supposedly | 420 // grabbed by other client. Another attempt to close supposedly |
| 421 // opened menu by emulating keypress at the left top corner. | 421 // opened menu by emulating keypress at the left top corner. |
| 422 Display* display = x11_util::GetXDisplay(); | 422 Display* display = ui::GetXDisplay(); |
| 423 Window root, child; | 423 Window root, child; |
| 424 int root_x, root_y, win_x, winy; | 424 int root_x, root_y, win_x, winy; |
| 425 unsigned int mask; | 425 unsigned int mask; |
| 426 XQueryPointer(display, | 426 XQueryPointer(display, |
| 427 x11_util::GetX11WindowFromGtkWidget(window_contents()), | 427 ui::GetX11WindowFromGtkWidget(window_contents()), |
| 428 &root, &child, &root_x, &root_y, | 428 &root, &child, &root_x, &root_y, |
| 429 &win_x, &winy, &mask); | 429 &win_x, &winy, &mask); |
| 430 XTestFakeMotionEvent(display, -1, -10000, -10000, CurrentTime); | 430 XTestFakeMotionEvent(display, -1, -10000, -10000, CurrentTime); |
| 431 XTestFakeButtonEvent(display, 1, True, CurrentTime); | 431 XTestFakeButtonEvent(display, 1, True, CurrentTime); |
| 432 XTestFakeButtonEvent(display, 1, False, CurrentTime); | 432 XTestFakeButtonEvent(display, 1, False, CurrentTime); |
| 433 // Move the pointer back. | 433 // Move the pointer back. |
| 434 XTestFakeMotionEvent(display, -1, root_x, root_y, CurrentTime); | 434 XTestFakeMotionEvent(display, -1, root_x, root_y, CurrentTime); |
| 435 XFlush(display); | 435 XFlush(display); |
| 436 } else if (kbd_grab_status_ == GDK_GRAB_ALREADY_GRABBED || | 436 } else if (kbd_grab_status_ == GDK_GRAB_ALREADY_GRABBED || |
| 437 kbd_grab_status_ == GDK_GRAB_FROZEN) { | 437 kbd_grab_status_ == GDK_GRAB_FROZEN) { |
| 438 // Successfully grabbed the pointer, but keyboard is still grabbed | 438 // Successfully grabbed the pointer, but keyboard is still grabbed |
| 439 // by other client. Another attempt to close supposedly opened | 439 // by other client. Another attempt to close supposedly opened |
| 440 // menu by emulating escape key. Such situation must be very | 440 // menu by emulating escape key. Such situation must be very |
| 441 // rare, but handling this just in case | 441 // rare, but handling this just in case |
| 442 Display* display = x11_util::GetXDisplay(); | 442 Display* display = ui::GetXDisplay(); |
| 443 KeyCode escape = XKeysymToKeycode(display, XK_Escape); | 443 KeyCode escape = XKeysymToKeycode(display, XK_Escape); |
| 444 XTestFakeKeyEvent(display, escape, True, CurrentTime); | 444 XTestFakeKeyEvent(display, escape, True, CurrentTime); |
| 445 XTestFakeKeyEvent(display, escape, False, CurrentTime); | 445 XTestFakeKeyEvent(display, escape, False, CurrentTime); |
| 446 XFlush(display); | 446 XFlush(display); |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 | 449 |
| 450 // BackgroundView for ScreenLocker, which layouts a lock widget in | 450 // BackgroundView for ScreenLocker, which layouts a lock widget in |
| 451 // addition to other background components. | 451 // addition to other background components. |
| 452 class ScreenLockerBackgroundView | 452 class ScreenLockerBackgroundView |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 | 1117 |
| 1118 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { | 1118 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { |
| 1119 if (!background_view_->IsScreenSaverVisible()) { | 1119 if (!background_view_->IsScreenSaverVisible()) { |
| 1120 StartScreenSaver(); | 1120 StartScreenSaver(); |
| 1121 return true; | 1121 return true; |
| 1122 } | 1122 } |
| 1123 return false; | 1123 return false; |
| 1124 } | 1124 } |
| 1125 | 1125 |
| 1126 } // namespace chromeos | 1126 } // namespace chromeos |
| OLD | NEW |