From 63ff2e3dc786c97d74c7c2e6ee96a26f826abca8 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Fri, 22 Jun 2012 11:17:20 +0200 Subject: embed: Move about handlers to a new file Leaving in ephy-request-about only the code specific to the soup feature implementation. --- embed/Makefile.am | 2 + embed/ephy-about-handler.c | 204 +++++++++++++++++++++++++++++++++++++++++++++ embed/ephy-about-handler.h | 16 ++++ embed/ephy-embed-utils.c | 2 +- embed/ephy-request-about.c | 160 +---------------------------------- embed/ephy-request-about.h | 3 - embed/ephy-web-view.c | 2 +- 7 files changed, 227 insertions(+), 162 deletions(-) create mode 100644 embed/ephy-about-handler.c create mode 100644 embed/ephy-about-handler.h (limited to 'embed') diff --git a/embed/Makefile.am b/embed/Makefile.am index ea7f3c28d..db2123e3b 100644 --- a/embed/Makefile.am +++ b/embed/Makefile.am @@ -8,6 +8,7 @@ header_DATA = \ $(INST_H_FILES) NOINST_H_FILES = \ + ephy-about-handler.h \ ephy-embed-dialog.h \ ephy-embed-private.h \ ephy-encodings.h \ @@ -33,6 +34,7 @@ BUILT_SOURCES = \ ephy-embed-type-builtins.h libephyembed_la_SOURCES = \ + ephy-about-handler.c \ ephy-adblock.c \ ephy-adblock-manager.c \ ephy-download.c \ diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c new file mode 100644 index 000000000..c8d0bc697 --- /dev/null +++ b/embed/ephy-about-handler.c @@ -0,0 +1,204 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Copyright © 2012 Igalia S.L. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" +#include "ephy-about-handler.h" + +#include "ephy-file-helpers.h" +#include "ephy-smaps.h" +#include "ephy-web-app-utils.h" + +#include +#include +#ifdef HAVE_WEBKIT2 +#include +#else +#include +#endif + +static gchar *css_style = NULL; + +static void +read_css_style () +{ + GError *error = NULL; + const gchar *file; + + if (css_style) + return; + + file = ephy_file ("about.css"); + if (file && !g_file_get_contents (file, &css_style, NULL, &error)) { + g_debug ("%s", error->message); + g_error_free (error); + } +} + +static void +ephy_about_handler_handle_plugins (GString *data_str) +{ +#ifdef HAVE_WEBKIT2 + /* TODO: Plugins */ +#else + WebKitWebPluginDatabase* database = webkit_get_web_plugin_database (); + GSList *plugin_list, *p; + + g_string_append_printf (data_str, "%s" \ + "", + _("Installed plugins"), + css_style); + + g_string_append_printf (data_str, "

%s

", _("Installed plugins")); + plugin_list = webkit_web_plugin_database_get_plugins (database); + + for (p = plugin_list; p; p = p->next) { + WebKitWebPlugin *plugin = WEBKIT_WEB_PLUGIN (p->data); + GSList *m, *mime_types; + + g_string_append_printf (data_str, "

%s

%s
%s: %s" \ + "" \ + " ", + webkit_web_plugin_get_name (plugin), + webkit_web_plugin_get_description (plugin), + _("Enabled"), webkit_web_plugin_get_enabled (plugin) ? _("Yes") : _("No"), + _("MIME type"), _("Description"), _("Suffixes")); + + mime_types = webkit_web_plugin_get_mimetypes (plugin); + + for (m = mime_types; m; m = m->next) { + WebKitWebPluginMIMEType *mime_type = (WebKitWebPluginMIMEType*) m->data; + guint i; + + g_string_append_printf (data_str, ""); + } + + g_string_append (data_str, "
%s%s%s
%s%s", + mime_type->name, mime_type->description); + + for (i = 0; mime_type->extensions[i] != NULL; i++) + g_string_append_printf (data_str, "%s%c", mime_type->extensions[i], + mime_type->extensions[i + 1] ? ',' : ' '); + + g_string_append (data_str, "
"); + } + + webkit_web_plugin_database_plugins_list_free (plugin_list); +#endif + g_string_append (data_str, ""); +} + +static void +ephy_about_handler_handle_memory (GString *data_str) +{ + char *memory; + static EphySMaps *smaps = NULL; + if (!smaps) + smaps = ephy_smaps_new (); + + memory = ephy_smaps_to_html (smaps); + + if (memory) { + g_string_append_printf (data_str, "%s" \ + "", + _("Memory usage"), + css_style); + + g_string_append_printf (data_str, "

%s

", _("Memory usage")); + g_string_append (data_str, memory); + g_free (memory); + } +} + +static void +ephy_about_handler_handle_epiphany (GString *data_str) +{ + g_string_append_printf (data_str, "Epiphany" \ + "" \ + "", + css_style); + + g_string_append (data_str, "
" \ + "Il semble que la perfection soit atteinte non quand il n'y a plus rien à" \ + " ajouter, mais quand il n'y a plus rien à retrancher." \ + "
" \ + "
" \ + "" \ + "Antoine de Saint-Exupéry" \ + "
"); +} + +static void +ephy_about_handler_handle_applications (GString *data_str) +{ + GList *applications, *p; + + g_string_append_printf (data_str, "%s" \ + "" \ + "

%s

" \ + "

%s

", + _("Applications"), + css_style, + _("Applications"), + _("List of installed web applications")); + + g_string_append (data_str, "
"); + + applications = ephy_web_application_get_application_list (); + for (p = applications; p; p = p->next) { + char *img_data = NULL, *img_data_base64 = NULL; + gsize data_length; + EphyWebApplication *app = (EphyWebApplication*)p->data; + + if (g_file_get_contents (app->icon_url, &img_data, &data_length, NULL)) + img_data_base64 = g_base64_encode ((guchar*)img_data, data_length); + g_string_append_printf (data_str, "", + img_data_base64, app->name, app->url, app->name, + /* Note for translators: this refers to the installation date. */ + _("Installed on:"), app->install_date); + g_free (img_data_base64); + g_free (img_data); + } + + g_string_append (data_str, "
" \ + "
%s
%s
%s
%s
"); + + ephy_web_application_free_application_list (applications); +} + +GString * +ephy_about_handler_handle (const char *about) +{ + GString *data_str = g_string_new(""); + + read_css_style (); + + if (!g_strcmp0 (about, "plugins")) + ephy_about_handler_handle_plugins (data_str); + else if (!g_strcmp0 (about, "memory")) + ephy_about_handler_handle_memory (data_str); + else if (!g_strcmp0 (about, "epiphany")) + ephy_about_handler_handle_epiphany (data_str); + else if (!g_strcmp0 (about, "applications")) + ephy_about_handler_handle_applications (data_str); + + g_string_append (data_str, ""); + + return data_str; +} diff --git a/embed/ephy-about-handler.h b/embed/ephy-about-handler.h new file mode 100644 index 000000000..2bc5bd823 --- /dev/null +++ b/embed/ephy-about-handler.h @@ -0,0 +1,16 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Copyright (C) 2012, Igalia S.L. + */ + +#ifndef EPHY_ABOUT_HANDLER_H +#define EPHY_ABOUT_HANDLER_H + +#include + +#define EPHY_ABOUT_SCHEME "ephy-about" +#define EPHY_ABOUT_SCHEME_LEN 10 + +GString *ephy_about_handler_handle (const char *about); + +#endif /* EPHY_ABOUT_HANDLER_H */ diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c index 86599c5fe..cdfd09097 100644 --- a/embed/ephy-embed-utils.c +++ b/embed/ephy-embed-utils.c @@ -30,7 +30,7 @@ #include "ephy-string.h" #include "ephy-embed-utils.h" -#include "ephy-request-about.h" +#include "ephy-about-handler.h" char * ephy_embed_utils_link_message_parse (const char *message) diff --git a/embed/ephy-request-about.c b/embed/ephy-request-about.c index cddb9d135..9a0bcafd5 100644 --- a/embed/ephy-request-about.c +++ b/embed/ephy-request-about.c @@ -23,45 +23,22 @@ #endif #include "ephy-request-about.h" -#include "ephy-file-helpers.h" -#include "ephy-smaps.h" -#include "ephy-web-app-utils.h" +#include "ephy-about-handler.h" #include #include #include -#ifdef HAVE_WEBKIT2 -#include -#else -#include -#endif G_DEFINE_TYPE (EphyRequestAbout, ephy_request_about, SOUP_TYPE_REQUEST) struct _EphyRequestAboutPrivate { gssize content_length; - gchar *css_style; - EphySMaps *smaps; }; static void ephy_request_about_init (EphyRequestAbout *about) { about->priv = G_TYPE_INSTANCE_GET_PRIVATE (about, EPHY_TYPE_REQUEST_ABOUT, EphyRequestAboutPrivate); - about->priv->content_length = 0; - about->priv->css_style = NULL; - about->priv->smaps = ephy_smaps_new (); -} - -static void -ephy_request_about_finalize (GObject *obj) -{ - EphyRequestAboutPrivate *priv = EPHY_REQUEST_ABOUT (obj)->priv; - - g_object_unref (priv->smaps); - g_free (priv->css_style); - - G_OBJECT_CLASS (ephy_request_about_parent_class)->finalize (obj); } static gboolean @@ -72,18 +49,6 @@ ephy_request_about_check_uri (SoupRequest *request, return uri->host == NULL; } -static void -read_css_style (EphyRequestAbout *about) -{ - GError *error = NULL; - const gchar *file = ephy_file ("about.css"); - - if (file && !g_file_get_contents (file, &about->priv->css_style, NULL, &error)) { - g_debug ("%s", error->message); - g_error_free (error); - } -} - static GInputStream * ephy_request_about_send (SoupRequest *request, GCancellable *cancellable, @@ -91,126 +56,10 @@ ephy_request_about_send (SoupRequest *request, { EphyRequestAbout *about = EPHY_REQUEST_ABOUT (request); SoupURI *uri = soup_request_get_uri (request); - GString *data_str = g_string_new(""); - - if (!about->priv->css_style) - read_css_style (about); - - if (!g_strcmp0 (uri->path, "plugins")) { -#ifdef HAVE_WEBKIT2 - /* TODO: SoupRequest and Plugins */ -#else - WebKitWebPluginDatabase* database = webkit_get_web_plugin_database (); - GSList *plugin_list, *p; - - g_string_append_printf (data_str, "%s" \ - "", - _("Installed plugins"), - about->priv->css_style); - - g_string_append_printf (data_str, "

%s

", _("Installed plugins")); - plugin_list = webkit_web_plugin_database_get_plugins (database); - - for (p = plugin_list; p; p = p->next) { - WebKitWebPlugin *plugin = WEBKIT_WEB_PLUGIN (p->data); - GSList *m, *mime_types; - - g_string_append_printf (data_str, "

%s

%s
%s: %s"\ - "" \ - " ", - webkit_web_plugin_get_name (plugin), - webkit_web_plugin_get_description (plugin), - _("Enabled"), webkit_web_plugin_get_enabled (plugin) ? _("Yes") : _("No"), - _("MIME type"), _("Description"), _("Suffixes")); - - mime_types = webkit_web_plugin_get_mimetypes (plugin); + GString *data_str = ephy_about_handler_handle (uri->path); - for (m = mime_types; m; m = m->next) { - WebKitWebPluginMIMEType *mime_type = (WebKitWebPluginMIMEType*) m->data; - guint i; - - g_string_append_printf (data_str, ""); - } - - g_string_append (data_str, "
%s%s%s
%s%s", - mime_type->name, mime_type->description); - - for (i = 0; mime_type->extensions[i] != NULL; i++) - g_string_append_printf (data_str, "%s%c", mime_type->extensions[i], - mime_type->extensions[i + 1] ? ',' : ' '); - - g_string_append (data_str, "
"); - } - - webkit_web_plugin_database_plugins_list_free (plugin_list); -#endif - g_string_append (data_str, ""); - } else if (!g_strcmp0 (uri->path, "memory")) { - char *memory = ephy_smaps_to_html (EPHY_REQUEST_ABOUT (request)->priv->smaps); - - if (memory) { - g_string_append_printf (data_str, "%s" \ - "", - _("Memory usage"), - about->priv->css_style); - - g_string_append_printf (data_str, "

%s

", _("Memory usage")); - g_string_append (data_str, memory); - g_free (memory); - } - - } else if (!g_strcmp0 (uri->path, "epiphany")) { - g_string_append_printf (data_str, "Epiphany" \ - "" \ - "", - about->priv->css_style); - - g_string_append (data_str, "
" \ - "Il semble que la perfection soit atteinte non quand il n'y a plus rien à" \ - " ajouter, mais quand il n'y a plus rien à retrancher." \ - "
" \ - "
" \ - "" \ - "Antoine de Saint-Exupéry" \ - "
"); - } else if (!g_strcmp0 (uri->path, "applications")) { - GList *applications, *p; - - g_string_append_printf (data_str, "%s" \ - "" \ - "

%s

" \ - "

%s

", - _("Applications"), - about->priv->css_style, - _("Applications"), - _("List of installed web applications")); - - - g_string_append (data_str, "
"); - - applications = ephy_web_application_get_application_list (); - for (p = applications; p; p = p->next) { - char *icon_uri; - EphyWebApplication *app = (EphyWebApplication*)p->data; - - icon_uri = ephy_file_create_data_uri_for_filename (app->icon_url, "image/png"); - g_string_append_printf (data_str, "", - icon_uri ? icon_uri : "", - app->name, app->url, app->name, - /* Note for translators: this refers to the installation date. */ - _("Installed on:"), app->install_date); - g_free (icon_uri); - } - - g_string_append (data_str, "
" \ - "
%s
%s
%s
%s
"); - - ephy_web_application_free_application_list (applications); - } - - g_string_append (data_str, ""); about->priv->content_length = data_str->len; - return g_memory_input_stream_new_from_data (g_string_free (data_str, false), about->priv->content_length, g_free); + return g_memory_input_stream_new_from_data (g_string_free (data_str, FALSE), about->priv->content_length, g_free); } static goffset @@ -230,11 +79,8 @@ static const char *about_schemes[] = { EPHY_ABOUT_SCHEME, NULL }; static void ephy_request_about_class_init (EphyRequestAboutClass *request_about_class) { - GObjectClass *gobject_class = G_OBJECT_CLASS (request_about_class); SoupRequestClass *request_class = SOUP_REQUEST_CLASS (request_about_class); - gobject_class->finalize = ephy_request_about_finalize; - request_class->schemes = about_schemes; request_class->check_uri = ephy_request_about_check_uri; request_class->send = ephy_request_about_send; diff --git a/embed/ephy-request-about.h b/embed/ephy-request-about.h index cc441a7a3..f8e3e2343 100644 --- a/embed/ephy-request-about.h +++ b/embed/ephy-request-about.h @@ -16,9 +16,6 @@ #define EPHY_IS_REQUEST_ABOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_REQUEST_ABOUT)) #define EPHY_REQUEST_ABOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_REQUEST_ABOUT, EphyRequestAboutClass)) -#define EPHY_ABOUT_SCHEME "ephy-about" -#define EPHY_ABOUT_SCHEME_LEN 10 - typedef struct _EphyRequestAboutPrivate EphyRequestAboutPrivate; typedef struct { diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index 2f5ae2b7d..cfc185a52 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -37,7 +37,7 @@ #include "ephy-permission-manager.h" #include "ephy-prefs.h" #include "ephy-profile-utils.h" -#include "ephy-request-about.h" +#include "ephy-about-handler.h" #include "ephy-settings.h" #include "ephy-string.h" #include "ephy-web-app-utils.h" -- cgit