diff options
Diffstat (limited to 'embed')
-rw-r--r-- | embed/ephy-request-about.c | 39 | ||||
-rw-r--r-- | embed/ephy-web-app-utils.c | 63 | ||||
-rw-r--r-- | embed/ephy-web-app-utils.h | 9 | ||||
-rw-r--r-- | embed/ephy-web-view.c | 40 |
4 files changed, 147 insertions, 4 deletions
diff --git a/embed/ephy-request-about.c b/embed/ephy-request-about.c index 4601e4787..1203d1a7e 100644 --- a/embed/ephy-request-about.c +++ b/embed/ephy-request-about.c @@ -21,16 +21,17 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif +#include "ephy-request-about.h" + +#include "ephy-file-helpers.h" +#include "ephy-smaps.h" +#include "ephy-web-app-utils.h" #include <gio/gio.h> #include <glib/gi18n.h> #include <libsoup/soup-uri.h> #include <webkit/webkit.h> -#include "ephy-file-helpers.h" -#include "ephy-request-about.h" -#include "ephy-smaps.h" - G_DEFINE_TYPE (EphyRequestAbout, ephy_request_about, SOUP_TYPE_REQUEST) struct _EphyRequestAboutPrivate { @@ -160,6 +161,36 @@ ephy_request_about_send (SoupRequest *request, "<!-- Terre des Hommes, III: L'Avion, p. 60 -->" \ "Antoine de Saint-Exupéry" \ "</div></body>"); + } else if (!g_strcmp0 (uri->path, "applications")) { + GList *applications, *p; + + g_string_append_printf (data_str, "<head><title>%s</title>" \ + "<style type=\"text/css\">%s</style></head>" \ + "<body>", + _("Web Applications"), + about->priv->css_style); + + g_string_append_printf (data_str, "<form><table><thead><tr><th>%s</th><th>%s</th><th>%s</th></tr></thead>", + _("Icon"), _("Name"), _("Delete?")); + + 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, "<tbody><tr><td><img width=64 height=64 src=\"data:image/png;base64,%s\">" \ + " </img></td><td>%s</td><td><input type=\"submit\" value=\"Delete\" id=\"%s\"></td></tr>", + img_data_base64, app->name, app->name); + g_free (img_data_base64); + g_free (img_data); + } + + g_string_append (data_str, "</form></table></body>"); + + ephy_web_application_free_application_list (applications); } g_string_append (data_str, "</html>"); diff --git a/embed/ephy-web-app-utils.c b/embed/ephy-web-app-utils.c index f2da66adb..293ec6318 100644 --- a/embed/ephy-web-app-utils.c +++ b/embed/ephy-web-app-utils.c @@ -278,3 +278,66 @@ out: return desktop_file_path; } +GList * +ephy_web_application_get_application_list () +{ + GFileEnumerator *children = NULL; + GFileInfo *info; + GList *applications = NULL; + GFile *dot_dir; + + dot_dir = g_file_new_for_path (ephy_dot_dir ()); + children = g_file_enumerate_children (dot_dir, + "standard::name", + 0, NULL, NULL); + g_object_unref (dot_dir); + + info = g_file_enumerator_next_file (children, NULL, NULL); + while (info) { + EphyWebApplication *app; + const char *name; + glong prefix_length = g_utf8_strlen (EPHY_WEB_APP_PREFIX, -1); + + name = g_file_info_get_name (info); + if (g_str_has_prefix (name, EPHY_WEB_APP_PREFIX)) { + char *profile_dir; + + app = g_slice_new0 (EphyWebApplication); + app->name = g_strdup (name + prefix_length); + + profile_dir = ephy_web_application_get_profile_directory (app->name); + app->icon_url = g_build_filename (profile_dir, "app-icon.png", NULL); + g_free (profile_dir); + + applications = g_list_append (applications, app); + + } + + g_object_unref (info); + + info = g_file_enumerator_next_file (children, NULL, NULL); + } + + g_object_unref (children); + + return applications; +} + +static void +ephy_web_application_free (EphyWebApplication *app) +{ + g_free (app->name); + g_free (app->icon_url); + g_slice_free (EphyWebApplication, app); +} + +void +ephy_web_application_free_application_list (GList *list) +{ + GList *p; + + for (p = list; p; p = p->next) + ephy_web_application_free ((EphyWebApplication*)p->data); + + g_list_free (list); +} diff --git a/embed/ephy-web-app-utils.h b/embed/ephy-web-app-utils.h index d6f7be516..06b3284ad 100644 --- a/embed/ephy-web-app-utils.h +++ b/embed/ephy-web-app-utils.h @@ -31,6 +31,11 @@ G_BEGIN_DECLS +typedef struct { + char *name; + char *icon_url; +} EphyWebApplication; + #define EPHY_WEB_APP_PREFIX "app-" char *ephy_web_application_create (EphyWebView *view, const char *title, GdkPixbuf *icon); @@ -39,6 +44,10 @@ gboolean ephy_web_application_delete (const char *name); char *ephy_web_application_get_profile_directory (const char *app_name); +GList *ephy_web_application_get_application_list (void); + +void ephy_web_application_free_application_list (GList *list); + G_END_DECLS #endif diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index 798946c3e..80f336871 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -48,6 +48,7 @@ #include "ephy-request-about.h" #include "ephy-settings.h" #include "ephy-string.h" +#include "ephy-web-app-utils.h" #include "ephy-web-view.h" #include "ephy-zoom.h" @@ -1787,6 +1788,22 @@ update_navigation_flags (EphyWebView *view) } } +static gboolean +delete_web_app_cb (WebKitDOMHTMLElement *button, + WebKitDOMEvent *dom_event, + EphyWebView *web_view) +{ + char *id = NULL; + + id = webkit_dom_html_element_get_id (button); + if (id) + ephy_web_application_delete (id); + + g_free (id); + + return FALSE; +} + static void load_status_cb (WebKitWebView *web_view, GParamSpec *pspec, @@ -1885,6 +1902,29 @@ load_status_cb (WebKitWebView *web_view, _ephy_web_view_hook_into_forms (view); _ephy_web_view_hook_into_links (view); + + /* FIXME: It sucks to do this here, but it's not really possible + * to hook the DOM actions nicely in the about: generator. */ + if (g_str_equal (webkit_web_view_get_uri (web_view), "ephy-about:applications")) { + WebKitDOMDocument *document; + WebKitDOMNodeList *buttons; + gulong buttons_n; + int i; + + document = webkit_web_view_get_dom_document (web_view); + buttons = webkit_dom_document_get_elements_by_tag_name (document, "input"); + buttons_n = webkit_dom_node_list_get_length (buttons); + + for (i = 0; i < buttons_n; i++) { + WebKitDOMNode *button; + + button = webkit_dom_node_list_item (buttons, i); + webkit_dom_event_target_add_event_listener (WEBKIT_DOM_EVENT_TARGET (button), "click", + G_CALLBACK (delete_web_app_cb), false, + NULL); + } + } + break; case WEBKIT_LOAD_FAILED: ephy_web_view_set_link_message (view, NULL); |