summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 18:27:49 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 18:27:49 +0000
commit22e5a68ba753897fab769561986272b0d472a8c9 (patch)
treed6380509281872a8bfc39ba44d15562cef4db944 /webkit
parenteec14db8dd65f57aedea891a99b9fee6944d3f6a (diff)
downloadchromium_src-22e5a68ba753897fab769561986272b0d472a8c9.zip
chromium_src-22e5a68ba753897fab769561986272b0d472a8c9.tar.gz
chromium_src-22e5a68ba753897fab769561986272b0d472a8c9.tar.bz2
linux: refactor GtkFixedSocket into its own file.
It will be shared by both test_shell and the browser. I've also renamed it GtkPluginContainer to be more explicit about what it's for. TEST=windowed plugins continue to work in test_shell Review URL: http://codereview.chromium.org/141033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18920 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/plugins/gtk_plugin_container.cc67
-rw-r--r--webkit/glue/plugins/gtk_plugin_container.h24
-rw-r--r--webkit/glue/plugins/webplugin_delegate_impl_gtk.cc65
-rw-r--r--webkit/webkit.gyp5
4 files changed, 97 insertions, 64 deletions
diff --git a/webkit/glue/plugins/gtk_plugin_container.cc b/webkit/glue/plugins/gtk_plugin_container.cc
new file mode 100644
index 0000000..64b3dc3
--- /dev/null
+++ b/webkit/glue/plugins/gtk_plugin_container.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/glue/plugins/gtk_plugin_container.h"
+
+#include <gtk/gtk.h>
+
+namespace {
+
+// This class has no members/methods, and is only used for namespacing purposes.
+class GtkPluginContainer {
+ public:
+ static GtkWidget* CreateNewWidget() {
+ GtkWidget* container = GTK_WIDGET(g_object_new(GetType(), NULL));
+ g_signal_connect(GTK_SOCKET(container), "plug-removed",
+ G_CALLBACK(OnPlugRemoved), NULL);
+ return container;
+ }
+
+ private:
+ // Create and register our custom container type with GTK.
+ static GType GetType() {
+ static GType type = 0; // We only want to register our type once.
+ if (!type) {
+ static const GTypeInfo info = {
+ sizeof(GtkSocketClass),
+ NULL, NULL,
+ static_cast<GClassInitFunc>(&ClassInit),
+ NULL, NULL,
+ sizeof(GtkSocket), // We are identical to a GtkSocket.
+ 0, NULL,
+ };
+ type = g_type_register_static(GTK_TYPE_SOCKET,
+ "GtkPluginContainer",
+ &info,
+ static_cast<GTypeFlags>(0));
+ }
+ return type;
+ }
+
+ // Implementation of the class initializer.
+ static void ClassInit(gpointer klass, gpointer class_data_unusued) {
+ GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(klass);
+ widget_class->size_request = &HandleSizeRequest;
+ }
+
+ // Report our allocation size during size requisition.
+ static void HandleSizeRequest(GtkWidget* widget,
+ GtkRequisition* requisition) {
+ requisition->width = widget->allocation.width;
+ requisition->height = widget->allocation.height;
+ }
+
+ static gboolean OnPlugRemoved(GtkSocket* socket) {
+ // This is called when the other side of the socket goes away.
+ // We return TRUE to indicate that we don't want to destroy our side.
+ return TRUE;
+ }
+};
+
+} // anonymous namespace
+
+// Create a new instance of our GTK widget object.
+GtkWidget* gtk_plugin_container_new() {
+ return GtkPluginContainer::CreateNewWidget();
+}
diff --git a/webkit/glue/plugins/gtk_plugin_container.h b/webkit/glue/plugins/gtk_plugin_container.h
new file mode 100644
index 0000000..bde5db6
--- /dev/null
+++ b/webkit/glue/plugins/gtk_plugin_container.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_GLUE_PLUGINS_GTK_PLUGIN_CONTAINER_H_
+#define WEBKIT_GLUE_PLUGINS_GTK_PLUGIN_CONTAINER_H_
+
+// Windowed plugins are embedded via XEmbed, which is implemented by
+// GtkPlug/GtkSocket. But we want to control sizing and positioning
+// directly, so we need a subclass of GtkSocket that sidesteps the
+// size_request handler.
+//
+// The custom size_request handler just reports the allocation, so it's
+// the owner's responsibility to call gtk_widget_size_allocate() with the
+// proper size.
+
+typedef struct _GtkWidget GtkWidget;
+
+// Return a new GtkPluginContainer.
+// Intentionally GTK-style here since we're creating a custom GTK widget.
+// This is a GtkSocket subclass; see its documentation for available methods.
+GtkWidget* gtk_plugin_container_new();
+
+#endif // WEBKIT_GLUE_PLUGINS_GTK_PLUGIN_CONTAINER_H_
diff --git a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc
index 3ff1077..75390bf 100644
--- a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc
+++ b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc
@@ -20,6 +20,7 @@
// #include "webkit/default_plugin/plugin_impl.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/webplugin.h"
+#include "webkit/glue/plugins/gtk_plugin_container.h"
#include "webkit/glue/plugins/plugin_constants_win.h"
#include "webkit/glue/plugins/plugin_instance.h"
#include "webkit/glue/plugins/plugin_lib.h"
@@ -251,63 +252,6 @@ void WebPluginDelegateImpl::WindowedUpdateGeometry(
}
}
-namespace {
-
-// This is just a GtkSocket, with size_request overridden, so that we always
-// control the size of the widget.
-class GtkFixedSocket {
- public:
- // Create a new instance of our GTK widget object.
- static GtkWidget* CreateNewWidget() {
- return GTK_WIDGET(g_object_new(GetType(), NULL));
- }
-
- private:
- // Create and register our custom container type with GTK.
- static GType GetType() {
- static GType type = 0; // We only want to register our type once.
- if (!type) {
- static const GTypeInfo info = {
- sizeof(GtkSocketClass),
- NULL, NULL,
- static_cast<GClassInitFunc>(&ClassInit),
- NULL, NULL,
- sizeof(GtkSocket), // We are identical to a GtkSocket.
- 0, NULL,
- };
- type = g_type_register_static(GTK_TYPE_SOCKET,
- "GtkFixedSocket",
- &info,
- static_cast<GTypeFlags>(0));
- }
- return type;
- }
-
- // Implementation of the class initializer.
- static void ClassInit(gpointer klass, gpointer class_data_unusued) {
- GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(klass);
- widget_class->size_request = &HandleSizeRequest;
- }
-
- // Report our allocation size during size requisition. This means we control
- // the size, from calling gtk_widget_size_allocate in WindowedReposition().
- static void HandleSizeRequest(GtkWidget* widget,
- GtkRequisition* requisition) {
- requisition->width = widget->allocation.width;
- requisition->height = widget->allocation.height;
- }
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(GtkFixedSocket);
-};
-
-gboolean PlugRemovedCallback(GtkSocket* socket) {
- // This is called when the other side of the socket goes away.
- // We return TRUE to indicate that we don't want to destroy our side.
- return TRUE;
-}
-
-} // namespace
-
bool WebPluginDelegateImpl::WindowedCreatePlugin() {
DCHECK(!windowed_handle_);
@@ -319,13 +263,8 @@ bool WebPluginDelegateImpl::WindowedCreatePlugin() {
return false;
}
- windowed_handle_ = GtkFixedSocket::CreateNewWidget();
- g_signal_connect(GTK_SOCKET(windowed_handle_), "plug-removed",
- G_CALLBACK(PlugRemovedCallback), NULL);
+ windowed_handle_ = gtk_plugin_container_new();
gtk_container_add(GTK_CONTAINER(parent_), windowed_handle_);
- // TODO(evanm): connect to signals on the socket, like when the other side
- // goes away.
-
gtk_widget_show(windowed_handle_);
gtk_widget_realize(windowed_handle_);
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 208ed3b..8286806 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -4440,6 +4440,8 @@
'glue/plugins/mozilla_extensions.cc',
'glue/plugins/mozilla_extensions.h',
'glue/plugins/nphostapi.h',
+ 'glue/plugins/gtk_plugin_container.h',
+ 'glue/plugins/gtk_plugin_container.cc',
'glue/plugins/plugin_constants_win.h',
'glue/plugins/plugin_host.cc',
'glue/plugins/plugin_host.h',
@@ -4631,7 +4633,8 @@
'glue/plugins/plugin_stubs.cc',
],
}, { # else: OS!="linux"
- 'sources/': [['exclude', '_(linux|gtk)(_data)?\\.cc$']],
+ 'sources/': [['exclude', '_(linux|gtk)(_data)?\\.cc$'],
+ ['exclude', r'gtk_plugin_container\.(cc|h)']],
}],
['OS!="mac"', {
'sources/': [['exclude', '_mac\\.(cc|mm)$']]