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

Side by Side Diff: webkit/glue/plugins/gtk_plugin_container.cc

Issue 146009: linux plugins: eliminate GtkWidget* from plugin process (Closed)
Patch Set: retry Created 11 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/plugin/webplugin_proxy.cc ('k') | webkit/glue/plugins/plugin_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/glue/plugins/gtk_plugin_container.h" 5 #include "webkit/glue/plugins/gtk_plugin_container.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 10
11 namespace { 11 namespace {
12 12
13 // NOTE: This class doesn't have constructors/destructors, it is created 13 // NOTE: This class doesn't have constructors/destructors, it is created
14 // through GLib's object management. 14 // through GLib's object management.
15 class GtkPluginContainer : public GtkSocket { 15 class GtkPluginContainer : public GtkSocket {
16 public: 16 public:
17 static GtkWidget* CreateNewWidget() {
18 GtkWidget* container = GTK_WIDGET(g_object_new(GetType(), NULL));
19 g_signal_connect(GTK_SOCKET(container), "plug-removed",
20 G_CALLBACK(OnPlugRemoved), NULL);
21 return container;
22 }
23
24 // Sets the requested size of the widget. 17 // Sets the requested size of the widget.
25 void set_size(int width, int height) { 18 void set_size(int width, int height) {
26 width_ = width; 19 width_ = width;
27 height_ = height; 20 height_ = height;
28 } 21 }
29 22
30 // Casts a widget into a GtkPluginContainer, after checking the type. 23 // Casts a widget into a GtkPluginContainer, after checking the type.
31 template <class T> 24 template <class T>
32 static GtkPluginContainer *CastChecked(T *instance) { 25 static GtkPluginContainer *CastChecked(T *instance) {
33 return G_TYPE_CHECK_INSTANCE_CAST(instance, GetType(), GtkPluginContainer); 26 return G_TYPE_CHECK_INSTANCE_CAST(instance, GetType(), GtkPluginContainer);
34 } 27 }
35 28
36 private:
37 // Create and register our custom container type with GTK. 29 // Create and register our custom container type with GTK.
38 static GType GetType() { 30 static GType GetType() {
39 static GType type = 0; // We only want to register our type once. 31 static GType type = 0; // We only want to register our type once.
40 if (!type) { 32 if (!type) {
41 static const GTypeInfo info = { 33 static const GTypeInfo info = {
42 sizeof(GtkSocketClass), 34 sizeof(GtkSocketClass),
43 NULL, NULL, 35 NULL, NULL,
44 static_cast<GClassInitFunc>(&ClassInit), 36 static_cast<GClassInitFunc>(&ClassInit),
45 NULL, NULL, 37 NULL, NULL,
46 sizeof(GtkSocket), // We are identical to a GtkSocket. 38 sizeof(GtkSocket), // We are identical to a GtkSocket.
(...skipping 20 matching lines...) Expand all
67 } 59 }
68 60
69 // Report our allocation size during size requisition. 61 // Report our allocation size during size requisition.
70 static void HandleSizeRequest(GtkWidget* widget, 62 static void HandleSizeRequest(GtkWidget* widget,
71 GtkRequisition* requisition) { 63 GtkRequisition* requisition) {
72 GtkPluginContainer *container = CastChecked(widget); 64 GtkPluginContainer *container = CastChecked(widget);
73 requisition->width = container->width_; 65 requisition->width = container->width_;
74 requisition->height = container->height_; 66 requisition->height = container->height_;
75 } 67 }
76 68
77 static gboolean OnPlugRemoved(GtkSocket* socket) {
78 // This is called when the other side of the socket goes away.
79 // We return TRUE to indicate that we don't want to destroy our side.
80 return TRUE;
81 }
82
83 int width_; 69 int width_;
84 int height_; 70 int height_;
85 DISALLOW_IMPLICIT_CONSTRUCTORS(GtkPluginContainer); 71 DISALLOW_IMPLICIT_CONSTRUCTORS(GtkPluginContainer);
86 }; 72 };
87 73
88 } // anonymous namespace 74 } // anonymous namespace
89 75
90 // Create a new instance of our GTK widget object. 76 // Create a new instance of our GTK widget object.
91 GtkWidget* gtk_plugin_container_new() { 77 GtkWidget* gtk_plugin_container_new() {
92 return GtkPluginContainer::CreateNewWidget(); 78 return GTK_WIDGET(g_object_new(GtkPluginContainer::GetType(), NULL));
93 } 79 }
94 80
95 void gtk_plugin_container_set_size(GtkWidget *widget, int width, int height) { 81 void gtk_plugin_container_set_size(GtkWidget *widget, int width, int height) {
96 GtkPluginContainer::CastChecked(widget)->set_size(width, height); 82 GtkPluginContainer::CastChecked(widget)->set_size(width, height);
97 // Signal the parent that the size request has changed. 83 // Signal the parent that the size request has changed.
98 gtk_widget_queue_resize_no_redraw(widget); 84 gtk_widget_queue_resize_no_redraw(widget);
99 } 85 }
OLDNEW
« no previous file with comments | « chrome/plugin/webplugin_proxy.cc ('k') | webkit/glue/plugins/plugin_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698