diff options
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter_gtk.cc | 12 | ||||
-rw-r--r-- | gfx/gtk_native_view_id_manager.cc | 1 | ||||
-rw-r--r-- | gfx/gtk_native_view_id_manager.h | 16 |
3 files changed, 21 insertions, 8 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter_gtk.cc b/chrome/browser/renderer_host/resource_message_filter_gtk.cc index 56b53fe..97e1c14 100644 --- a/chrome/browser/renderer_host/resource_message_filter_gtk.cc +++ b/chrome/browser/renderer_host/resource_message_filter_gtk.cc @@ -70,6 +70,7 @@ void ResourceMessageFilter::DoOnGetWindowRect(gfx::NativeViewId view, gfx::Rect rect; XID window; + AutoLock lock(Singleton<GtkNativeViewManager>()->unrealize_lock()); if (Singleton<GtkNativeViewManager>()->GetXIDForId(&window, view)) { if (window) { int x, y; @@ -109,13 +110,16 @@ void ResourceMessageFilter::DoOnGetRootWindowRect(gfx::NativeViewId view, gfx::Rect rect; XID window; + AutoLock lock(Singleton<GtkNativeViewManager>()->unrealize_lock()); if (Singleton<GtkNativeViewManager>()->GetXIDForId(&window, view)) { if (window) { const XID toplevel = GetTopLevelWindow(window); - int x, y; - unsigned width, height; - if (x11_util::GetWindowGeometry(&x, &y, &width, &height, toplevel)) - rect = gfx::Rect(x, y, width, height); + if (toplevel) { + int x, y; + unsigned width, height; + if (x11_util::GetWindowGeometry(&x, &y, &width, &height, toplevel)) + rect = gfx::Rect(x, y, width, height); + } } } diff --git a/gfx/gtk_native_view_id_manager.cc b/gfx/gtk_native_view_id_manager.cc index 47dc2fb..91407283a 100644 --- a/gfx/gtk_native_view_id_manager.cc +++ b/gfx/gtk_native_view_id_manager.cc @@ -116,6 +116,7 @@ void GtkNativeViewManager::OnRealize(gfx::NativeView widget) { } void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) { + AutoLock unrealize_locked(unrealize_lock_); AutoLock locked(lock_); const gfx::NativeViewId id = GetWidgetId(widget); diff --git a/gfx/gtk_native_view_id_manager.h b/gfx/gtk_native_view_id_manager.h index 048cd2d..3a23942 100644 --- a/gfx/gtk_native_view_id_manager.h +++ b/gfx/gtk_native_view_id_manager.h @@ -63,6 +63,8 @@ class GtkNativeViewManager { void OnUnrealize(gfx::NativeView widget); void OnDestroy(gfx::NativeView widget); + Lock& unrealize_lock() { return unrealize_lock_; } + private: // This object is a singleton: GtkNativeViewManager(); @@ -78,12 +80,18 @@ class GtkNativeViewManager { gfx::NativeViewId GetWidgetId(gfx::NativeView id); + // This lock can be used to block GTK from unrealizing windows. This is needed + // when the BACKGROUND_X11 thread is using a window obtained via GetXIDForId, + // and can't allow the X11 resource to be deleted. + Lock unrealize_lock_; + // protects native_view_to_id_ and id_to_info_ Lock lock_; - // If asked for an id for the same widget twice, we want to return the same - // id. So this records the current mapping. - std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; - std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_; + + // If asked for an id for the same widget twice, we want to return the same + // id. So this records the current mapping. + std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; + std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_; DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); }; |