Bug 1045482: Wrap X11 calls for window lists and XQueryPointer in error trapping to avoid asserts on X11 errors r=karlt a=sylvestre
authorRandell Jesup <rjesup@jesup.org>
Wed, 06 Aug 2014 20:01:33 -0400
changeset 216303 c3ee282759eb68df2f7c00499cb2329a1bf869fe
parent 216302 396277e5792595100fede96c005155f9ac2f5463
child 216304 e4abfe41b9d568ab1dc92cb9a710225b1f3b70ae
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, sylvestre
bugs1045482
milestone33.0a2
Bug 1045482: Wrap X11 calls for window lists and XQueryPointer in error trapping to avoid asserts on X11 errors r=karlt a=sylvestre
media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc
@@ -12,28 +12,30 @@
 
 #include <X11/extensions/Xfixes.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
 #include "webrtc/modules/desktop_capture/desktop_frame.h"
 #include "webrtc/modules/desktop_capture/mouse_cursor.h"
+#include "webrtc/modules/desktop_capture/x11/x_error_trap.h"
 #include "webrtc/system_wrappers/interface/logging.h"
 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
 
 namespace {
 
 // WindowCapturer returns window IDs of X11 windows with WM_STATE attribute.
 // These windows may not be immediate children of the root window, because
 // window managers may re-parent them to add decorations. However,
 // XQueryPointer() expects to be passed children of the root. This function
 // searches up the list of the windows to find the root child that corresponds
 // to |window|.
 Window GetTopLevelWindow(Display* display, Window window) {
+  webrtc::XErrorTrap error_trap(display);
   while (true) {
     // If the window is in WithdrawnState then look at all of its children.
     ::Window root, parent;
     ::Window *children;
     unsigned int num_children;
     if (!XQueryTree(display, window, &root, &parent, &children,
                     &num_children)) {
       LOG(LS_ERROR) << "Failed to query for child windows although window"
@@ -112,16 +114,17 @@ void MouseCursorMonitorX11::Init(Callbac
   callback_ = callback;
   mode_ = mode;
 
   have_xfixes_ =
       XFixesQueryExtension(display(), &xfixes_event_base_, &xfixes_error_base_);
 
   if (have_xfixes_) {
     // Register for changes to the cursor shape.
+    XErrorTrap error_trap(display());
     XFixesSelectCursorInput(display(), window_, XFixesDisplayCursorNotifyMask);
     x_display_->AddEventHandler(xfixes_event_base_ + XFixesCursorNotify, this);
 
     CaptureCursor();
   } else {
     LOG(LS_INFO) << "X server does not support XFixes.";
   }
 }
@@ -140,20 +143,22 @@ void MouseCursorMonitorX11::Capture() {
   if (mode_ == SHAPE_AND_POSITION) {
     int root_x;
     int root_y;
     int win_x;
     int win_y;
     Window root_window;
     Window child_window;
     unsigned int mask;
+
+    XErrorTrap error_trap(display());
     Bool result = XQueryPointer(display(), window_, &root_window, &child_window,
                                 &root_x, &root_y, &win_x, &win_y, &mask);
     CursorState state;
-    if (!result) {
+    if (!result || error_trap.GetLastErrorAndDisable() != 0) {
       state = OUTSIDE;
     } else {
       // In screen mode (window_ == root_window) the mouse is always inside.
       // XQueryPointer() sets |child_window| to None if the cursor is outside
       // |window_|.
       state =
           (window_ == root_window || child_window != None) ? INSIDE : OUTSIDE;
     }