Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2039)

Unified Diff: chrome/browser/renderer_host/resource_message_filter_gtk.cc

Issue 67145: Linux: move X operations from the IO to UI2 thread. (Closed)
Patch Set: ... Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/resource_message_filter_gtk.cc
diff --git a/chrome/browser/renderer_host/resource_message_filter_gtk.cc b/chrome/browser/renderer_host/resource_message_filter_gtk.cc
index 0616cd9ad17441fc4f07edbad693cc255fe372b9..750356a936e6a0e23aa362cb8afcc2794c40f42c 100644
--- a/chrome/browser/renderer_host/resource_message_filter_gtk.cc
+++ b/chrome/browser/renderer_host/resource_message_filter_gtk.cc
@@ -6,42 +6,106 @@
#include <gtk/gtk.h>
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/common/x11_util.h"
+
+#include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h"
+#include "third_party/WebKit/WebKit/chromium/public/x11/WebScreenInfoFactory.h"
+
+using WebKit::WebScreenInfo;
+using WebKit::WebScreenInfoFactory;
+
// We get null window_ids passed into the two functions below; please see
// http://crbug.com/9060 for more details.
-void ResourceMessageFilter::OnGetWindowRect(gfx::NativeViewId window_id,
- gfx::Rect* rect) {
- if (!window_id) {
- *rect = gfx::Rect();
- return;
+// Called on the IO thread.
+void ResourceMessageFilter::SendBackgroundX11Reply(IPC::Message* reply_msg) {
+ Send(reply_msg);
+}
+
+// Called on the BACKGROUND_X11 thread.
+void ResourceMessageFilter::DoOnGetScreenInfo(gfx::NativeViewId view,
+ IPC::Message* reply_msg) {
+ Display* display = x11_util::GetSecondaryDisplay();
+ int screen = x11_util::GetDefaultScreen(display);
+ WebScreenInfo results = WebScreenInfoFactory::screenInfo(display, screen);
+ ViewHostMsg_GetScreenInfo::WriteReplyParams(reply_msg, results);
+
+ ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::SendBackgroundX11Reply, reply_msg));
+}
+
+// Called on the BACKGROUND_X11 thread.
+void ResourceMessageFilter::DoOnGetWindowRect(gfx::NativeViewId view,
+ IPC::Message* reply_msg) {
+ 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);
}
- // Ideally this would be gtk_widget_get_window but that's only
- // from gtk 2.14 onwards. :(
- GdkWindow* window = gfx::NativeViewFromId(window_id)->window;
- DCHECK(window);
- gint x, y, width, height;
- // This is the "position of a window in root window coordinates".
- gdk_window_get_origin(window, &x, &y);
- gdk_window_get_size(window, &width, &height);
- *rect = gfx::Rect(x, y, width, height);
+ ViewHostMsg_GetWindowRect::WriteReplyParams(reply_msg, rect);
+
+ ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::SendBackgroundX11Reply, reply_msg));
}
-void ResourceMessageFilter::OnGetRootWindowRect(gfx::NativeViewId window_id,
- gfx::Rect* rect) {
- if (!window_id) {
- *rect = gfx::Rect();
- return;
+// Called on the BACKGROUND_X11 thread.
+void ResourceMessageFilter::DoOnGetRootWindowRect(gfx::NativeViewId view,
+ IPC::Message* reply_msg) {
+ 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);
}
- // Windows uses GetAncestor(window, GA_ROOT) here which probably means
- // we want the top level window.
- GdkWindow* window =
- gdk_window_get_toplevel(gfx::NativeViewFromId(window_id)->window);
- DCHECK(window);
- gint x, y, width, height;
- // This is the "position of a window in root window coordinates".
- gdk_window_get_origin(window, &x, &y);
- gdk_window_get_size(window, &width, &height);
- *rect = gfx::Rect(x, y, width, height);
+ ViewHostMsg_GetRootWindowRect::WriteReplyParams(reply_msg, rect);
+
+ ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::SendBackgroundX11Reply, reply_msg));
+}
+
+// Called on the IO thread.
+void ResourceMessageFilter::OnGetScreenInfo(gfx::NativeViewId view,
+ IPC::Message* reply_msg) {
+ ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnGetScreenInfo, view, reply_msg));
+}
+
+// Called on the IO thread.
+void ResourceMessageFilter::OnGetWindowRect(gfx::NativeViewId view,
+ IPC::Message* reply_msg) {
+ ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnGetWindowRect, view, reply_msg));
+}
+
+// Called on the IO thread.
+void ResourceMessageFilter::OnGetRootWindowRect(gfx::NativeViewId view,
+ IPC::Message* reply_msg) {
+ ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnGetRootWindowRect, view, reply_msg));
}
« no previous file with comments | « chrome/browser/renderer_host/resource_message_filter.cc ('k') | chrome/browser/renderer_host/resource_message_filter_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698