summaryrefslogtreecommitdiffstats
path: root/webkit/tools
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-06 20:32:41 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-06 20:32:41 +0000
commite4c0329c31debaec3b5fe8a1136321c143de7d97 (patch)
tree29609d0333ce7841305b942653085fb413e30b79 /webkit/tools
parent1ee61486ee0854be7b82d9fca66bb49d563ede4c (diff)
downloadchromium_src-e4c0329c31debaec3b5fe8a1136321c143de7d97.zip
chromium_src-e4c0329c31debaec3b5fe8a1136321c143de7d97.tar.gz
chromium_src-e4c0329c31debaec3b5fe8a1136321c143de7d97.tar.bz2
linux: OOP windowed plugins
There are still a few issues, but that's a start. - only windowed plugins - we can't currently create the gtksocket in background tabs, because their gtkwidgets are not yet in the hierarchy, so they can't be realized (that's what gives the XID). - the plugin process talks to the browser process through the renderer process to create/destroy the gtksockets, because the plugin doesn't know which renderer it's talking to. We need a bit more plumbing to be able to have direct IPC. - some code is duplicated between chrome and test_shell. We should probably factor it, but I'm not sure where the common part should live. Review URL: http://codereview.chromium.org/146078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19983 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools')
-rw-r--r--webkit/tools/test_shell/test_webview_delegate_gtk.cc60
-rw-r--r--webkit/tools/test_shell/webview_host.h28
-rw-r--r--webkit/tools/test_shell/webview_host_gtk.cc37
3 files changed, 16 insertions, 109 deletions
diff --git a/webkit/tools/test_shell/test_webview_delegate_gtk.cc b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
index 10ba40f..a05eefd 100644
--- a/webkit/tools/test_shell/test_webview_delegate_gtk.cc
+++ b/webkit/tools/test_shell/test_webview_delegate_gtk.cc
@@ -23,7 +23,7 @@
#include "webkit/glue/webplugin.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webview.h"
-#include "webkit/glue/plugins/gtk_plugin_container.h"
+#include "webkit/glue/plugins/gtk_plugin_container_manager.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/window_open_disposition.h"
#include "webkit/glue/plugins/webplugin_delegate_impl.h"
@@ -230,61 +230,9 @@ void TestWebViewDelegate::GetRootWindowResizerRect(WebWidget* webwidget,
void TestWebViewDelegate::DidMove(WebWidget* webwidget,
const WebPluginGeometry& move) {
WebWidgetHost* host = GetHostForWidget(webwidget);
-
- // The "window" on WebPluginGeometry is actually the XEmbed parent
- // X window id.
- GtkWidget* widget = ((WebViewHost*)host)->MapIDToWidget(move.window);
- // If we don't know about this plugin (maybe we're shutting down the
- // window?), ignore the message.
- if (!widget)
- return;
- DCHECK(!GTK_WIDGET_NO_WINDOW(widget));
- DCHECK(GTK_WIDGET_REALIZED(widget));
-
- if (!move.visible) {
- gtk_widget_hide(widget);
- return;
- } else {
- gtk_widget_show(widget);
- }
-
- // Update the clipping region on the GdkWindow.
- GdkRectangle clip_rect = move.clip_rect.ToGdkRectangle();
- GdkRegion* clip_region = gdk_region_rectangle(&clip_rect);
- gfx::SubtractRectanglesFromRegion(clip_region, move.cutout_rects);
- gdk_window_shape_combine_region(widget->window, clip_region, 0, 0);
- gdk_region_destroy(clip_region);
-
- // Update the window position. Resizing is handled by WebPluginDelegate.
- // TODO(deanm): Verify that we only need to move and not resize.
- // TODO(evanm): we should cache the last shape and position and skip all
- // of this business in the common case where nothing has changed.
- int current_x, current_y;
-
- // Until the above TODO is resolved, we can grab the last position
- // off of the GtkFixed with a bit of hackery.
- GValue value = {0};
- g_value_init(&value, G_TYPE_INT);
- gtk_container_child_get_property(GTK_CONTAINER(host->view_handle()), widget,
- "x", &value);
- current_x = g_value_get_int(&value);
- gtk_container_child_get_property(GTK_CONTAINER(host->view_handle()), widget,
- "y", &value);
- current_y = g_value_get_int(&value);
- g_value_unset(&value);
-
- if (move.window_rect.x() != current_x || move.window_rect.y() != current_y) {
- // Calling gtk_fixed_move unnecessarily is a no-no, as it causes the parent
- // window to repaint!
- gtk_fixed_move(GTK_FIXED(host->view_handle()),
- widget,
- move.window_rect.x(),
- move.window_rect.y());
- }
-
- gtk_plugin_container_set_size(widget,
- move.window_rect.width(),
- move.window_rect.height());
+ GtkPluginContainerManager* plugin_container_manager =
+ static_cast<WebViewHost*>(host)->plugin_container_manager();
+ plugin_container_manager->MovePluginContainer(move);
}
void TestWebViewDelegate::RunModal(WebWidget* webwidget) {
diff --git a/webkit/tools/test_shell/webview_host.h b/webkit/tools/test_shell/webview_host.h
index 9c7c489..962633b 100644
--- a/webkit/tools/test_shell/webview_host.h
+++ b/webkit/tools/test_shell/webview_host.h
@@ -11,15 +11,14 @@
#include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
#include "webkit/tools/test_shell/webwidget_host.h"
+#if defined(OS_LINUX)
+#include "webkit/glue/plugins/gtk_plugin_container_manager.h"
+#endif
struct WebPreferences;
class WebView;
class WebViewDelegate;
-#if defined(OS_LINUX)
-typedef struct _GtkSocket GtkSocket;
-#endif
-
// This class is a simple NativeView-based host for a WebView
class WebViewHost : public WebWidgetHost {
public:
@@ -37,13 +36,12 @@ class WebViewHost : public WebWidgetHost {
// embedders to use.
GdkNativeWindow CreatePluginContainer();
- // Map a GdkNativeWindow returned by CreatePluginContainer() back to
- // the GtkWidget hosting it. Used when we get a message back from the
- // renderer indicating a plugin needs to move.
- GtkWidget* MapIDToWidget(GdkNativeWindow id);
-
// Called when a plugin has been destroyed. Lets us clean up our side.
void OnPluginWindowDestroyed(GdkNativeWindow id);
+
+ GtkPluginContainerManager* plugin_container_manager() {
+ return &plugin_container_manager_;
+ }
#endif
protected:
@@ -54,16 +52,8 @@ class WebViewHost : public WebWidgetHost {
#endif
#if defined(OS_LINUX)
- // A map used for MapIDToWidget() above.
- typedef std::map<GdkNativeWindow, GtkWidget*> NativeWindowToWidgetMap;
- NativeWindowToWidgetMap native_window_to_widget_map_;
-
- // Callback for when one of our plugins goes away.
- static gboolean OnPlugRemovedThunk(GtkSocket* socket,
- WebViewHost* web_view_host) {
- return web_view_host->OnPlugRemoved(socket);
- }
- gboolean OnPlugRemoved(GtkSocket* socket);
+ // Helper class that creates and moves plugin containers.
+ GtkPluginContainerManager plugin_container_manager_;
#endif
};
diff --git a/webkit/tools/test_shell/webview_host_gtk.cc b/webkit/tools/test_shell/webview_host_gtk.cc
index e089052..53c42d9 100644
--- a/webkit/tools/test_shell/webview_host_gtk.cc
+++ b/webkit/tools/test_shell/webview_host_gtk.cc
@@ -20,6 +20,7 @@ WebViewHost* WebViewHost::Create(GtkWidget* parent_view,
WebViewHost* host = new WebViewHost();
host->view_ = WebWidgetHost::CreateWidget(parent_view, host);
+ host->plugin_container_manager_.set_host_widget(host->view_);
g_object_set_data(G_OBJECT(host->view_), "webwidgethost", host);
host->webwidget_ = WebView::Create(delegate, prefs);
@@ -33,41 +34,9 @@ WebView* WebViewHost::webview() const {
}
GdkNativeWindow WebViewHost::CreatePluginContainer() {
- GtkWidget* plugin_container = gtk_plugin_container_new();
- g_signal_connect(G_OBJECT(plugin_container), "plug-removed",
- G_CALLBACK(OnPlugRemovedThunk), this);
- gtk_container_add(GTK_CONTAINER(view_handle()), plugin_container);
- gtk_widget_show(plugin_container);
- gtk_widget_realize(plugin_container);
-
- GdkNativeWindow id = gtk_socket_get_id(GTK_SOCKET(plugin_container));
-
- native_window_to_widget_map_.insert(std::make_pair(id, plugin_container));
-
- return id;
-}
-
-GtkWidget* WebViewHost::MapIDToWidget(GdkNativeWindow id) {
- NativeWindowToWidgetMap::const_iterator i =
- native_window_to_widget_map_.find(id);
- if (i != native_window_to_widget_map_.end())
- return i->second;
-
- LOG(ERROR) << "Request for widget host for unknown window id " << id;
-
- return NULL;
+ return plugin_container_manager_.CreatePluginContainer();
}
void WebViewHost::OnPluginWindowDestroyed(GdkNativeWindow id) {
- GtkWidget* plugin_container = MapIDToWidget(id);
- if (!plugin_container)
- return;
-
- native_window_to_widget_map_.erase(id);
- gtk_widget_destroy(plugin_container);
+ plugin_container_manager_.DestroyPluginContainer(id);
}
-
-gboolean WebViewHost::OnPlugRemoved(GtkSocket* socket) {
- return TRUE; // Don't destroy our widget; we manage it ourselves.
-}
-