evolution-3.6.4/modules/web-inspector/evolution-web-inspector.c

No issues found

  1 /*
  2  * evolution-web-inspector.c
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #include <config.h>
 20 #include <glib/gi18n-lib.h>
 21 
 22 #include <misc/e-web-view.h>
 23 #include <libebackend/libebackend.h>
 24 
 25 /* Standard GObject macros */
 26 #define E_TYPE_WEB_INSPECTOR \
 27 	(e_web_inspector_get_type ())
 28 #define E_WEB_INSPECTOR(obj) \
 29 	(G_TYPE_CHECK_INSTANCE_CAST \
 30 	((obj), E_TYPE_WEB_INSPECTOR, EWebInspector))
 31 
 32 typedef struct _EWebInspector EWebInspector;
 33 typedef struct _EWebInspectorClass EWebInspectorClass;
 34 
 35 struct _EWebInspector {
 36 	EExtension parent;
 37 };
 38 
 39 struct _EWebInspectorClass {
 40 	EExtensionClass parent_class;
 41 };
 42 
 43 static const gchar *ui =
 44 "<ui>"
 45 "  <popup name='context'>"
 46 "    <placeholder name='inspect-menu' >"
 47 "      <menuitem action='inspect'/>"
 48 "    </placeholder>"
 49 "  </popup>"
 50 "</ui>";
 51 
 52 /* Module Entry Points */
 53 void e_module_load (GTypeModule *type_module);
 54 void e_module_unload (GTypeModule *type_module);
 55 
 56 /* Forward Declarations */
 57 GType e_web_inspector_get_type (void);
 58 
 59 G_DEFINE_DYNAMIC_TYPE (EWebInspector, e_web_inspector, E_TYPE_EXTENSION)
 60 
 61 static EWebView *
 62 web_inspector_get_web_view (EWebInspector *extension)
 63 {
 64 	EExtensible *extensible;
 65 
 66 	extensible = e_extension_get_extensible (E_EXTENSION (extension));
 67 
 68 	return E_WEB_VIEW (extensible);
 69 }
 70 
 71 static void
 72 web_inspector_action_inspect_cb (GtkAction *action,
 73                                  EWebInspector *extension)
 74 {
 75 	WebKitWebInspector *inspector;
 76 	EWebView *web_view;
 77 
 78 	web_view = web_inspector_get_web_view (extension);
 79 	inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (web_view));
 80 
 81 	webkit_web_inspector_show (inspector);
 82 }
 83 
 84 static GtkActionEntry inspect_entries[] = {
 85 
 86 	{ "inspect",
 87 	  NULL,
 88 	  N_("_Inspect..."),
 89 	  NULL,
 90 	  N_("Inspect the HTML content (debugging feature)"),
 91 	  G_CALLBACK (web_inspector_action_inspect_cb) }
 92 };
 93 
 94 static WebKitWebView *
 95 web_inspector_inspect_web_view_cb (WebKitWebInspector *inspector,
 96                                    EWebInspector *extension)
 97 {
 98 	GtkWidget *web_view;
 99 	GtkWidget *window;
100 	const gchar *title;
101 
102 	title = _("Evolution Web Inspector");
103 	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
104 	gtk_window_set_title (GTK_WINDOW (window), title);
105 	gtk_widget_set_size_request (window, 600, 400);
106 	gtk_widget_show (window);
107 
108 	web_view = webkit_web_view_new ();
109 	gtk_container_add (GTK_CONTAINER (window), web_view);
110 	gtk_widget_show (web_view);
111 
112 	return WEBKIT_WEB_VIEW (web_view);
113 }
114 
115 static void
116 web_inspector_constructed (GObject *object)
117 {
118 	EWebInspector *extension;
119 	WebKitWebSettings *settings;
120 	WebKitWebInspector *inspector;
121 	GtkActionGroup *action_group;
122 	GtkUIManager *ui_manager;
123 	EWebView *web_view;
124 	GError *error = NULL;
125 
126 	extension = E_WEB_INSPECTOR (object);
127 	web_view = web_inspector_get_web_view (extension);
128 
129 	ui_manager = e_web_view_get_ui_manager (web_view);
130 	action_group = e_web_view_get_action_group (web_view, "standard");
131 
132 	settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (web_view));
133 	g_object_set (settings, "enable-developer-extras", TRUE, NULL);
134 
135 	inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (web_view));
136 
137 	g_signal_connect (
138 		inspector, "inspect-web-view",
139 		G_CALLBACK (web_inspector_inspect_web_view_cb), extension);
140 
141 	gtk_action_group_add_actions (
142 		action_group, inspect_entries,
143 		G_N_ELEMENTS (inspect_entries), extension);
144 
145 	/* Because we are loading from a hard-coded string, there is
146 	 * no chance of I/O errors.  Failure here implies a malformed
147 	 * UI definition.  Full stop. */
148 	gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error);
149 	if (error != NULL)
150 		g_error ("%s", error->message);
151 }
152 
153 static void
154 e_web_inspector_class_init (EWebInspectorClass *class)
155 {
156 	GObjectClass *object_class;
157 	EExtensionClass *extension_class;
158 
159 	object_class = G_OBJECT_CLASS (class);
160 	object_class->constructed = web_inspector_constructed;
161 
162 	extension_class = E_EXTENSION_CLASS (class);
163 	extension_class->extensible_type = E_TYPE_WEB_VIEW;
164 }
165 
166 static void
167 e_web_inspector_class_finalize (EWebInspectorClass *class)
168 {
169 }
170 
171 static void
172 e_web_inspector_init (EWebInspector *extension)
173 {
174 }
175 
176 G_MODULE_EXPORT void
177 e_module_load (GTypeModule *type_module)
178 {
179 	e_web_inspector_register_type (type_module);
180 }
181 
182 G_MODULE_EXPORT void
183 e_module_unload (GTypeModule *type_module)
184 {
185 }