aboutsummaryrefslogtreecommitdiffstats
path: root/embed/ephy-about-handler.c
blob: 31eb775c79e1a5c0d6fa7a08291b5b685982de1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/* -*- 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-embed-shell.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 <webkit2/webkit2.h>

static gchar *css_style = NULL;

static void
read_css_style (void)
{
  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);
  }
}

void
_ephy_about_handler_handle_plugins (GString *data_str, GList *plugin_list)
{
  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>");
}

static void
ephy_about_handler_handle_plugins (GString *data_str)
{
  g_string_append (data_str, "</body>");
}

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, "<head><title>%s</title>"         \
                            "<style type=\"text/css\">%s</style></head><body>",
                            _("Memory usage"),
                            css_style);

    g_string_append_printf (data_str, "<h1>%s</h1>", _("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, "<head><title>Epiphany</title>"     \
                          "<style type=\"text/css\">%s</style></head>"  \
                          "<body style=\"background: #3369FF; color: white; font-style: italic;\">",
                          css_style);

  g_string_append (data_str, "<div id=\"ephytext\">"                    \
                   "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." \
                   "</div>"                                             \
                   "<div id=\"from\">"                                  \
                   "<!-- Terre des Hommes, III: L'Avion, p. 60 -->"     \
                   "Antoine de Saint-Exupéry"                           \
                   "</div></body>");
}

static void
ephy_about_handler_handle_applications (GString *data_str)
{
  GList *applications, *p;

  g_string_append_printf (data_str, "<head><title>%s</title>"           \
                          "<style type=\"text/css\">%s</style></head>"  \
                          "<body class=\"applications-body\"><h1>%s</h1>" \
                          "<p>%s</p>",
                          _("Applications"),
                          css_style,
                          _("Applications"),
                          _("List of installed web applications"));

  g_string_append (data_str, "<table>");

  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,
                            "<form>" \
                            "<tbody><tr>" \
                            "<td class=\"icon\"><img width=64 height=64 src=\"data:image/png;base64,%s\"></img></td>" \
                            "<td class=\"data\"><div class=\"appname\">%s</div><div class=\"appurl\">%s</div></td>" \
                            "<td class=\"input\"><input type=\"hidden\" name=\"app_id\" value=\"%s\"><input type=\"submit\" value=\"Delete\" id=\"%s\">" \
                            "</td><td class=\"date\">%s <br /> %s</td></tr></tbody></form>",
                            img_data_base64, app->name, app->url, app->name, 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, "</table></body>");

  ephy_web_application_free_application_list (applications);
}

static void
ephy_about_handler_handle_incognito (GString *data_str)
{
  const char *filename;
  char *img_data = NULL, *img_data_base64 = NULL;
  gsize data_length;

  filename = ephy_file ("incognito.png");
  if (filename) {
    g_file_get_contents (filename, &img_data, &data_length, NULL);
    img_data_base64 = g_base64_encode ((guchar*)img_data, data_length);
  }
  g_string_append_printf (data_str,                                    \
                          "<head>\n"                                   \
                          "<title>%s</title>\n"                        \
                          "<style type=\"text/css\">%s</style>\n"      \
                          "</head>\n"                                  \
                          "<body class=\"incognito-body\">\n"          \
                          "  <div id=\"mainblock\">\n"                 \
                          "    <div style=\"background: transparent url(data:image/png;base64,%s) no-repeat 10px center;\">\n" \
                          "      <h1>%s</h1>\n"                        \
                          "      <p>%s</p>\n"                          \
                          "    </div>\n"                               \
                          "  </div>\n"                                 \
                          "</body>\n",
                          _("Private Browsing"),
                          css_style, img_data_base64 ? img_data_base64 : "",
                          _("Private Browsing"),
                          _("You are currently browsing <em>incognito</em>. Pages viewed in this "
                            "mode will not show up in your browsing history and all stored "
                            "information will be cleared when you close the window."));

  g_free (img_data_base64);
  g_free (img_data);

}

GString *
ephy_about_handler_handle (const char *about)
{
  GString *data_str = g_string_new("<html>");

  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);
  else if (!g_strcmp0 (about, "incognito") &&
           ephy_embed_shell_get_mode (ephy_embed_shell_get_default ())
           == EPHY_EMBED_SHELL_MODE_INCOGNITO)
    ephy_about_handler_handle_incognito (data_str);

  g_string_append (data_str, "</html>");

  return data_str;
}