[epiphany/webkit2: 14/17] Port plugins about handler to WebKit2
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/webkit2: 14/17] Port plugins about handler to WebKit2
- Date: Fri, 15 Jun 2012 11:15:19 +0000 (UTC)
commit 521ad8875228e36240eca031f7d34054e07f9ba3
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Fri Jun 8 10:24:05 2012 +0200
Port plugins about handler to WebKit2
embed/ephy-about-handler.c | 58 +++++++++++++++++++++++++++++++++++++++++--
embed/ephy-about-handler.h | 3 ++
embed/ephy-embed-single.c | 55 +++++++++++++++++++++++++++++++++++------
3 files changed, 105 insertions(+), 11 deletions(-)
---
diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c
index 8294192..b1d17e7 100644
--- a/embed/ephy-about-handler.c
+++ b/embed/ephy-about-handler.c
@@ -53,12 +53,64 @@ read_css_style ()
}
}
+void
+_ephy_about_handler_handle_plugins (GString *data_str, GList *plugin_list)
+{
+#ifdef HAVE_WEBKIT2
+ GList *p;
+
+ read_css_style ();
+
+ g_string_append_printf (data_str, "<head><title>%s</title>" \
+ "<style type=\"text/css\">%s</style></head><body>",
+ _("Installed plugins"),
+ css_style);
+
+ g_string_append_printf (data_str, "<h1>%s</h1>", _("Installed plugins"));
+
+ for (p = plugin_list; p; p = p->next) {
+ WebKitPlugin *plugin = WEBKIT_PLUGIN (p->data);
+ GList *m, *mime_types;
+
+ /* TODO: Enable/disable plugins in WebKit2 */
+ g_string_append_printf (data_str, "<h2>%s</h2>%s<br>%s: <b>%s</b>" \
+ "<table id=\"plugin-table\">" \
+ " <thead><tr><th>%s</th><th>%s</th><th>%s</th></tr></thead><tbody>",
+ webkit_plugin_get_name (plugin),
+ webkit_plugin_get_description (plugin),
+ _("Enabled"), /*webkit_plugin_get_enabled (plugin)*/ TRUE ? _("Yes") : _("No"),
+ _("MIME type"), _("Description"), _("Suffixes"));
+
+ mime_types = webkit_plugin_get_mime_info_list (plugin);
+
+ for (m = mime_types; m; m = m->next) {
+ WebKitMimeInfo *mime_info = (WebKitMimeInfo *) m->data;
+ const gchar * const *extensions;
+ guint i;
+
+ g_string_append_printf (data_str, "<tr><td>%s</td><td>%s</td><td>",
+ webkit_mime_info_get_mime_type (mime_info),
+ webkit_mime_info_get_description (mime_info));
+
+ extensions = webkit_mime_info_get_extensions (mime_info);
+ for (i = 0; extensions && extensions[i] != NULL; i++)
+ g_string_append_printf (data_str, "%s%c", extensions[i],
+ extensions[i + 1] ? ',' : ' ');
+
+ g_string_append (data_str, "</td></tr>");
+ }
+
+ g_string_append (data_str, "</tbody></table>");
+ }
+
+ g_string_append (data_str, "</body>");
+#endif
+}
+
static void
ephy_about_handler_handle_plugins (GString *data_str)
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Plugins */
-#else
+#ifndef HAVE_WEBKIT2
WebKitWebPluginDatabase* database = webkit_get_web_plugin_database ();
GSList *plugin_list, *p;
diff --git a/embed/ephy-about-handler.h b/embed/ephy-about-handler.h
index cc08f62..2c2a030 100644
--- a/embed/ephy-about-handler.h
+++ b/embed/ephy-about-handler.h
@@ -13,4 +13,7 @@
GString *ephy_about_handler_handle (const gchar *about);
+void _ephy_about_handler_handle_plugins (GString *data_str,
+ GList *plugin_list);
+
#endif /* EPHY_ABOUT_HANDLER_H */
diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c
index 926b362..c927ba8 100644
--- a/embed/ephy-embed-single.c
+++ b/embed/ephy-embed-single.c
@@ -340,19 +340,58 @@ cache_size_cb (GSettings *settings,
#ifdef HAVE_WEBKIT2
static void
-about_request_cb (WebKitURISchemeRequest *request,
- gpointer user_data)
+complete_about_request_for_contents (WebKitURISchemeRequest *request,
+ gchar *data,
+ gsize data_length)
{
- GString *contents;
GInputStream *stream;
- gint stream_length;
- contents = ephy_about_handler_handle (webkit_uri_scheme_request_get_path (request));
- stream_length = contents->len;
- stream = g_memory_input_stream_new_from_data (g_string_free (contents, FALSE), stream_length, g_free);
- webkit_uri_scheme_request_finish (request, stream, stream_length, "text/html");
+ stream = g_memory_input_stream_new_from_data (data, data_length, g_free);
+ webkit_uri_scheme_request_finish (request, stream, data_length, "text/html");
g_object_unref (stream);
}
+
+static void
+get_plugins_cb (WebKitWebContext *web_context,
+ GAsyncResult *result,
+ WebKitURISchemeRequest *request)
+{
+ GList *plugins;
+ GString *data_str;
+ gsize data_length;
+
+ data_str = g_string_new("<html>");
+ plugins = webkit_web_context_get_plugins_finish (web_context, result, NULL);
+ _ephy_about_handler_handle_plugins (data_str, plugins);
+ g_string_append (data_str, "</html>");
+
+ data_length = data_str->len;
+ complete_about_request_for_contents (request, g_string_free (data_str, FALSE), data_length);
+ g_object_unref (request);
+}
+
+static void
+about_request_cb (WebKitURISchemeRequest *request,
+ gpointer user_data)
+{
+ const gchar *path;
+
+ path = webkit_uri_scheme_request_get_path (request);
+ if (!g_strcmp0 (path, "plugins")) {
+ /* Plugins API is async in WebKit2 */
+ webkit_web_context_get_plugins (webkit_web_context_get_default (),
+ NULL,
+ (GAsyncReadyCallback) get_plugins_cb,
+ g_object_ref (request));
+ } else {
+ GString *contents;
+ gsize data_length;
+
+ contents = ephy_about_handler_handle (path);
+ data_length = contents->len;
+ complete_about_request_for_contents (request, g_string_free (contents, FALSE), data_length);
+ }
+}
#endif
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]