diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 01:59:32 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 01:59:32 +0000 |
commit | 6639f5c6328b64ea800693b343d789b32c050cab (patch) | |
tree | c91de0b9bcf09d56c1ab02baef710a6f836d1098 /chrome/browser/renderer_host | |
parent | 380ab46417433097d6fc3a0c92236e46b4ea1d40 (diff) | |
download | chromium_src-6639f5c6328b64ea800693b343d789b32c050cab.zip chromium_src-6639f5c6328b64ea800693b343d789b32c050cab.tar.gz chromium_src-6639f5c6328b64ea800693b343d789b32c050cab.tar.bz2 |
Linux: use opaque NativeViewIds
Currently we are still passing GtkWidget* into the renderer and
trusting the value on the way out. With this patch we switch to using
opaque values.
These opaque values are handled by a GtkNativeViewIdManger, a
singleton object which maintains the list of currently valid ids and
their current X window ids.
We don't pass the X window ids directly to the renderer because they
are a) guessable and b) possibly variable for a GtkWidget. From a
patch size point of view, the X window isn't current created at the
point where we need it so significant work would be needed to reorder
operations to fix that as well.
This patch also removes the GTK accesses from the BACKGROUND_X11
thread which were a temporary hack.
http://codereview.chromium.org/92110
BUG=9014,9869,10787
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter_gtk.cc | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter_gtk.cc b/chrome/browser/renderer_host/resource_message_filter_gtk.cc index 750356a..70173ad 100644 --- a/chrome/browser/renderer_host/resource_message_filter_gtk.cc +++ b/chrome/browser/renderer_host/resource_message_filter_gtk.cc @@ -4,8 +4,7 @@ #include "chrome/browser/renderer_host/resource_message_filter.h" -#include <gtk/gtk.h> - +#include "base/gfx/gtk_native_view_id_manager.h" #include "chrome/browser/chrome_thread.h" #include "chrome/common/render_messages.h" #include "chrome/common/x11_util.h" @@ -40,16 +39,18 @@ void ResourceMessageFilter::DoOnGetScreenInfo(gfx::NativeViewId view, // Called on the BACKGROUND_X11 thread. void ResourceMessageFilter::DoOnGetWindowRect(gfx::NativeViewId view, IPC::Message* reply_msg) { + // This is called to get the x, y offset (in screen coordinates) of the given + // view and its width and height. gfx::Rect rect; - - if (view) { - XID window = x11_util::GetX11WindowFromGtkWidget( - gfx::NativeViewFromId(view)); - - int x, y; - unsigned width, height; - x11_util::GetWindowGeometry(&x, &y, &width, &height, window); - rect = gfx::Rect(x, y, width, height); + XID window; + + if (Singleton<GtkNativeViewManager>()->GetXIDForId(&window, view)) { + if (window) { + int x, y; + unsigned width, height; + if (x11_util::GetWindowGeometry(&x, &y, &width, &height, window)) + rect = gfx::Rect(x, y, width, height); + } } ViewHostMsg_GetWindowRect::WriteReplyParams(reply_msg, rect); @@ -59,24 +60,36 @@ void ResourceMessageFilter::DoOnGetWindowRect(gfx::NativeViewId view, this, &ResourceMessageFilter::SendBackgroundX11Reply, reply_msg)); } +// Return the top-level parent of the given window. Called on the +// BACKGROUND_X11 thread. +static XID GetTopLevelWindow(XID window) { + bool parent_is_root; + XID parent_window; + + if (!x11_util::GetWindowParent(&parent_window, &parent_is_root, window)) + return 0; + if (parent_is_root) + return window; + + return GetTopLevelWindow(parent_window); +} + // Called on the BACKGROUND_X11 thread. void ResourceMessageFilter::DoOnGetRootWindowRect(gfx::NativeViewId view, IPC::Message* reply_msg) { + // This is called to get the screen coordinates and size of the browser + // window itself. gfx::Rect rect; - - if (view && gfx::NativeViewFromId(view)->window) { - // Windows uses GetAncestor(window, GA_ROOT) here which probably means - // we want the top level window. - // TODO(agl): calling GTK from this thread is not safe. However, we still - // have to solve the issue where we pass GtkWidget* into the renderer and - // the solution to that should also fix this problem. - GdkWindow* gdk_window = - gdk_window_get_toplevel(gfx::NativeViewFromId(view)->window); - XID window = x11_util::GetX11WindowFromGdkWindow(gdk_window); - int x, y; - unsigned width, height; - x11_util::GetWindowGeometry(&x, &y, &width, &height, window); - rect = gfx::Rect(x, y, width, height); + XID window; + + if (Singleton<GtkNativeViewManager>()->GetXIDForId(&window, view)) { + if (window) { + const XID toplevel = GetTopLevelWindow(toplevel); + int x, y; + unsigned width, height; + if (x11_util::GetWindowGeometry(&x, &y, &width, &height, window)) + rect = gfx::Rect(x, y, width, height); + } } ViewHostMsg_GetRootWindowRect::WriteReplyParams(reply_msg, rect); |