ephy-about-handler.c 24 KB
Newer Older
1
2
3
4
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 *  Copyright © 2012 Igalia S.L.
 *
Michael Catanzaro's avatar
Michael Catanzaro committed
5
6
7
 *  This file is part of Epiphany.
 *
 *  Epiphany is free software: you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
Michael Catanzaro's avatar
Michael Catanzaro committed
9
10
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
11
 *
Michael Catanzaro's avatar
Michael Catanzaro committed
12
 *  Epiphany is distributed in the hope that it will be useful,
13
14
15
16
17
 *  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
Michael Catanzaro's avatar
Michael Catanzaro committed
18
 *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
19
20
21
22
23
 */

#include "config.h"
#include "ephy-about-handler.h"

24
#include "ephy-embed-shell.h"
25
#include "ephy-embed-prefs.h"
26
#include "ephy-embed-utils.h"
27
#include "ephy-file-helpers.h"
28
#include "ephy-flatpak-utils.h"
29
#include "ephy-history-service.h"
30
#include "ephy-output-encoding.h"
31
32
#include "ephy-prefs.h"
#include "ephy-settings.h"
33
#include "ephy-smaps.h"
34
#include "ephy-snapshot-service.h"
35
36
37
#include "ephy-web-app-utils.h"

#include <gio/gio.h>
William Jon McCann's avatar
William Jon McCann committed
38
#include <gtk/gtk.h>
39
40
#include <glib/gi18n.h>

Michael Catanzaro's avatar
Michael Catanzaro committed
41
struct _EphyAboutHandler {
42
43
  GObject parent_instance;

44
45
46
47
48
  EphySMaps *smaps;
};

G_DEFINE_TYPE (EphyAboutHandler, ephy_about_handler, G_TYPE_OBJECT)

49
50
51
52
53

#define EPHY_ABOUT_OVERVIEW_MAX_ITEMS 9

#define EPHY_PAGE_TEMPLATE_ABOUT_CSS        "ephy-resource:///org/gnome/epiphany/page-templates/about.css"

54
55
56
57
58
static void
ephy_about_handler_finalize (GObject *object)
{
  EphyAboutHandler *handler = EPHY_ABOUT_HANDLER (object);

59
  g_clear_object (&handler->smaps);
60
61
62
63
64
65
66
67

  G_OBJECT_CLASS (ephy_about_handler_parent_class)->finalize (object);
}

static void
ephy_about_handler_init (EphyAboutHandler *handler)
{
}
68
69

static void
70
ephy_about_handler_class_init (EphyAboutHandlerClass *klass)
71
{
72
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
73

74
75
  object_class->finalize = ephy_about_handler_finalize;
}
76

77
78
static EphySMaps *
ephy_about_handler_get_smaps (EphyAboutHandler *handler)
79
{
80
81
  if (!handler->smaps)
    handler->smaps = ephy_smaps_new ();
82

83
  return handler->smaps;
84
}
85

86
87
static void
ephy_about_handler_finish_request (WebKitURISchemeRequest *request,
Michael Catanzaro's avatar
Michael Catanzaro committed
88
89
                                   gchar                  *data,
                                   gssize                  data_length)
90
91
92
{
  GInputStream *stream;

93
  data_length = data_length != -1 ? data_length : (gssize)strlen (data);
94
95
96
97
98
  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);
}

99
static void
Michael Catanzaro's avatar
Michael Catanzaro committed
100
101
handle_memory_finished_cb (EphyAboutHandler       *handler,
                           GAsyncResult           *result,
102
                           WebKitURISchemeRequest *request)
103
{
104
105
  GString *data_str;
  gsize data_length;
106
107
  char *memory;

108
  data_str = g_string_new ("<html>");
109

110
  memory = g_task_propagate_pointer (G_TASK (result), NULL);
111
  if (memory) {
112
113
    g_string_append_printf (data_str, "<head><title>%s</title>"
                            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
Michael Catanzaro's avatar
Michael Catanzaro committed
114
                            "<link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS "\" rel=\"stylesheet\" type=\"text/css\">"
115
116
                            "</head><body>"
                            "<div id='memory'>",
117
                            _("Memory usage"));
118
119
120
121

    g_string_append_printf (data_str, "<h1>%s</h1>", _("Memory usage"));
    g_string_append (data_str, memory);
    g_free (memory);
122
123

    g_string_append (data_str, "</div>");
124
  }
125
126
127
128
129

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

  data_length = data_str->len;
  ephy_about_handler_finish_request (request, g_string_free (data_str, FALSE), data_length);
130
131
132
133
  g_object_unref (request);
}

static void
Michael Catanzaro's avatar
Michael Catanzaro committed
134
135
136
handle_memory_sync (GTask        *task,
                    gpointer      source_object,
                    gpointer      task_data,
137
138
139
140
141
142
143
144
145
146
                    GCancellable *cancellable)
{
  EphyAboutHandler *handler = EPHY_ABOUT_HANDLER (source_object);

  g_task_return_pointer (task,
                         ephy_smaps_to_html (ephy_about_handler_get_smaps (handler)),
                         g_free);
}

static gboolean
Michael Catanzaro's avatar
Michael Catanzaro committed
147
ephy_about_handler_handle_memory (EphyAboutHandler       *handler,
148
149
150
151
152
153
154
155
156
                                  WebKitURISchemeRequest *request)
{
  GTask *task;

  task = g_task_new (handler, NULL,
                     (GAsyncReadyCallback)handle_memory_finished_cb,
                     g_object_ref (request));
  g_task_run_in_thread (task, handle_memory_sync);
  g_object_unref (task);
157
158

  return TRUE;
159
160
}

William Jon McCann's avatar
William Jon McCann committed
161
static gboolean
Michael Catanzaro's avatar
Michael Catanzaro committed
162
ephy_about_handler_handle_about (EphyAboutHandler       *handler,
William Jon McCann's avatar
William Jon McCann committed
163
164
165
166
167
168
                                 WebKitURISchemeRequest *request)
{
  char *data;
  char *version;
  GtkIconInfo *icon_info;

169
  version = g_strdup_printf (_("Version %s"), VERSION);
William Jon McCann's avatar
William Jon McCann committed
170
171

  icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
172
                                          APPLICATION_ID,
173
174
                                          256,
                                          GTK_ICON_LOOKUP_FORCE_SVG);
William Jon McCann's avatar
William Jon McCann committed
175
176
177

  data = g_strdup_printf ("<html><head><title>%s</title>"
                          "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
Michael Catanzaro's avatar
Michael Catanzaro committed
178
                          "<link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS "\" rel=\"stylesheet\" type=\"text/css\">"
179
                          "</head><body>"
180
                          "<div id=\"about-app\">"
William Jon McCann's avatar
William Jon McCann committed
181
                          "<div class=\"dialog\">"
182
                          "<img id=\"about-icon\" src=\"file://%s\"/>"
William Jon McCann's avatar
William Jon McCann committed
183
184
                          "<h1 id=\"about-title\">%s</h1>"
                          "<h2 id=\"about-subtitle\">%s</h2>"
185
                          "<p id=\"about-tagline\">%s</p>"
William Jon McCann's avatar
William Jon McCann committed
186
187
188
                          "<table class=\"properties\">"
                          "<tr><td class=\"prop-label\">%s</td><td class=\"prop-value\">%d.%d.%d</td></tr>"
                          "</table>"
189
                          "</div></div></body></html>",
William Jon McCann's avatar
William Jon McCann committed
190
                          _("About Web"),
191
                          icon_info ? gtk_icon_info_get_filename (icon_info) : "",
Michael Catanzaro's avatar
Michael Catanzaro committed
192
#if !TECH_PREVIEW
193
                          _("Web"),
Michael Catanzaro's avatar
Michael Catanzaro committed
194
#else
195
                          _("Epiphany Technology Preview"),
Michael Catanzaro's avatar
Michael Catanzaro committed
196
#endif
William Jon McCann's avatar
William Jon McCann committed
197
198
                          version,
                          _("A simple, clean, beautiful view of the web"),
Michael Catanzaro's avatar
Michael Catanzaro committed
199
                          "WebKitGTK", webkit_get_major_version (), webkit_get_minor_version (), webkit_get_micro_version ());
William Jon McCann's avatar
William Jon McCann committed
200
  g_free (version);
201
202
  if (icon_info)
    g_object_unref (icon_info);
William Jon McCann's avatar
William Jon McCann committed
203
204
205
206
207
208

  ephy_about_handler_finish_request (request, data, -1);

  return TRUE;
}

209
static gboolean
Michael Catanzaro's avatar
Michael Catanzaro committed
210
ephy_about_handler_handle_epiphany (EphyAboutHandler       *handler,
211
                                    WebKitURISchemeRequest *request)
212
{
213
214
  char *data;

215
  data = g_strdup_printf ("<html class=\"epiphany-html\"><head><title>%s</title>"
216
                          "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
Michael Catanzaro's avatar
Michael Catanzaro committed
217
                          "<link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS "\" rel=\"stylesheet\" type=\"text/css\">"
218
                          "</head><body class=\"epiphany-body\">"
219
                          "<div id=\"ephytext\">"
220
221
                          "« 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. »"
222
223
224
225
226
                          "</div>"
                          "<div id=\"from\">"
                          "<!-- Terre des Hommes, III: L'Avion, p. 60 -->"
                          "Antoine de Saint-Exupéry"
                          "</div></body></html>",
227
                          _("Web"));
228
229
230
231

  ephy_about_handler_finish_request (request, data, -1);

  return TRUE;
232
233
}

234
static void
Michael Catanzaro's avatar
Michael Catanzaro committed
235
236
handle_applications_finished_cb (EphyAboutHandler       *handler,
                                 GAsyncResult           *result,
237
                                 WebKitURISchemeRequest *request)
238
{
239
240
  GString *data_str;
  gsize data_length;
241
242
  GList *applications, *p;

243
  data_str = g_string_new (NULL);
244
  applications = g_task_propagate_pointer (G_TASK (result), NULL);
245

246
247
248
249
250
251
252
253
254
255
256
  if (g_list_length (applications) > 0) {
    g_string_append_printf (data_str, "<html><head><title>%s</title>"
                            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
                            "<link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS "\" rel=\"stylesheet\" type=\"text/css\">"
                            "<script>"
                            "  function deleteWebApp(appID) {"
                            "    window.webkit.messageHandlers.aboutApps.postMessage(appID);"
                            "    var row = document.getElementById(appID);"
                            "    row.parentNode.removeChild(row);"
                            "  }"
                            "</script>"
257
                            "</head><div id=\"applications\"><body class=\"applications-body\"><h1>%s</h1>"
258
259
260
261
262
263
264
265
266
                            "<p>%s</p>",
                            _("Applications"),
                            _("Applications"),
                            _("List of installed web applications"));

    g_string_append (data_str, "<table>");

    for (p = applications; p; p = p->next) {
      EphyWebApplication *app = (EphyWebApplication *)p->data;
267
268
      const char *icon_path = NULL;
      g_autofree char *encoded_icon_path = NULL;
269
270
271
      g_autofree char *encoded_name = NULL;
      g_autofree char *encoded_url = NULL;
      g_autofree char *js_encoded_id = NULL;
272
273
      g_autoptr (GDate) date = NULL;
      char install_date[128];
274

275
276
277
      if (ephy_web_application_is_system (app))
        continue;

278
279
280
281
      date = g_date_new ();
      g_date_set_time_t (date, (time_t)app->install_date_uint64);
      g_date_strftime (install_date, 127, "%x", date);

282
283
      /* In the sandbox we don't have access to the host side icon file */
      if (ephy_is_running_inside_sandbox ())
284
        icon_path = app->tmp_icon_path;
285
      else
286
        icon_path = app->icon_path;
287

288
289
      if (!icon_path) {
        g_warning ("Failed to get icon path for app %s", app->id);
290
291
292
        continue;
      }

293
294
295
296
297
298
      /* Most of these fields are at least semi-trusted. The app ID was chosen
       * by ephy so it's safe. The icon URL could be changed by the user to
       * something else after web app creation, though, so better not fully
       * trust it. Then the app name and the main URL could contain contain
       * anything at all, so those need to be encoded for sure. Install date
       * should be fine because it's constructed by Epiphany.
299
       */
300
      encoded_icon_path = ephy_encode_for_html_attribute (icon_path);
301
302
      encoded_name = ephy_encode_for_html_entity (app->name);
      encoded_url = ephy_encode_for_html_entity (app->url);
303
304
305
306
      g_string_append_printf (data_str,
                              "<tbody><tr id =\"%s\">"
                              "<td class=\"icon\"><img width=64 height=64 src=\"file://%s\"></img></td>"
                              "<td class=\"data\"><div class=\"appname\">%s</div><div class=\"appurl\">%s</div></td>"
307
308
                              "<td class=\"input\"><input type=\"button\" value=\"%s\" onclick=\"deleteWebApp('%s');\" "
                              "class=\"destructive-action\"></td>"
309
                              "<td class=\"date\">%s <br /> %s</td></tr></tbody>",
310
                              app->id, encoded_icon_path, encoded_name, encoded_url, _("Delete"), app->id,
311
                              /* Note for translators: this refers to the installation date. */
312
                              _("Installed on:"), install_date);
313
314
    }

315
    g_string_append (data_str, "</table></div></body></html>");
316
  } else {
317
    g_autoptr (GtkIconInfo) icon_info = NULL;
318
319
320
321
322
323
324
325
326
327
328
329
    g_autofree gchar *icon = g_strconcat ("application-x-addon-symbolic", NULL);

    g_string_append_printf (data_str, "<html><head><title>%s</title>"
                            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
                            "<link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS "\" rel=\"stylesheet\" type=\"text/css\">"
                            "</head><body class=\"applications-body\">",
                            _("Applications"));

    icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
                                            icon,
                                            128,
                                            0);
330
    g_string_append_printf (data_str,
331
332
333
334
335
336
337
338
                            "  <div id=\"overview\" class=\"overview-empty\">\n"
                            "    <img src=\"file://%s\"/>\n"
                            "    <div><h1>%s</h1></div>\n"
                            "    <div><p>%s</p></div>\n"
                            "  </div>\n"
                            "</body></html>\n",
                            icon_info ? gtk_icon_info_get_filename (icon_info) : "",
                            /* Displayed when opening applications without any installed web apps. */
339
                            _("Applications"), _("You can add your favorite website by clicking <b>Install Site as Web Application…</b> within the page menu."));
340
341
342
  }

  ephy_web_application_free_application_list (applications);
343
344
345

  data_length = data_str->len;
  ephy_about_handler_finish_request (request, g_string_free (data_str, FALSE), data_length);
346
347
348
349
  g_object_unref (request);
}

static void
Michael Catanzaro's avatar
Michael Catanzaro committed
350
351
352
handle_applications_sync (GTask        *task,
                          gpointer      source_object,
                          gpointer      task_data,
353
354
355
356
357
358
359
360
                          GCancellable *cancellable)
{
  g_task_return_pointer (task,
                         ephy_web_application_get_application_list (),
                         (GDestroyNotify)ephy_web_application_free_application_list);
}

static gboolean
Michael Catanzaro's avatar
Michael Catanzaro committed
361
ephy_about_handler_handle_applications (EphyAboutHandler       *handler,
362
363
364
365
366
367
368
369
370
                                        WebKitURISchemeRequest *request)
{
  GTask *task;

  task = g_task_new (handler, NULL,
                     (GAsyncReadyCallback)handle_applications_finished_cb,
                     g_object_ref (request));
  g_task_run_in_thread (task, handle_applications_sync);
  g_object_unref (task);
371
372

  return TRUE;
373
374
}

375
static void
Michael Catanzaro's avatar
Michael Catanzaro committed
376
377
378
history_service_query_urls_cb (EphyHistoryService     *history,
                               gboolean                success,
                               GList                  *urls,
379
                               WebKitURISchemeRequest *request)
380
{
381
382
  EphySnapshotService *snapshot_service;
  EphyEmbedShell *shell;
383
384
385
  GString *data_str;
  gsize data_length;
  char *lang;
386
  GList *l;
387
  guint list_length;
388

389
390
391
  snapshot_service = ephy_snapshot_service_get_default ();
  shell = ephy_embed_shell_get_default ();

392
  data_str = g_string_new (NULL);
393

394
395
396
397
398
399
400
401
  lang = g_strdup (pango_language_to_string (gtk_get_default_language ()));
  g_strdelimit (lang, "_-@", '\0');

  g_string_append_printf (data_str,
                          "<html xml:lang=\"%s\" lang=\"%s\" dir=\"%s\">\n"
                          "<head>\n"
                          "  <title>%s</title>\n"
                          "  <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n"
402
                          "  <meta name=\"viewport\" content=\"width=device-width\">"
Michael Catanzaro's avatar
Michael Catanzaro committed
403
                          "  <link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS "\" rel=\"stylesheet\" type=\"text/css\">\n"
404
                          "  <script> </script>\n"
405
                          "</head>\n"
406
407
                          "<body>\n",
                          lang, lang,
408
                          ((gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) ? "rtl" : "ltr"),
409
                          _(NEW_TAB_PAGE_TITLE));
410
411
  g_free (lang);

412
413
414
  list_length = g_list_length (urls);

  if (list_length == 0 || !success) {
415
    GtkIconInfo *icon_info;
416
    g_autofree gchar *icon = g_strconcat (APPLICATION_ID, "-symbolic", NULL);
417
418

    icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
419
                                            icon,
420
421
422
                                            128,
                                            0);
    g_string_append_printf (data_str,
423
                            "  <div id=\"overview\" class=\"overview-empty\">\n"
424
425
426
427
428
429
430
431
432
433
434
435
436
437
                            "    <img src=\"file://%s\"/>\n"
                            "    <div><h1>%s</h1></div>\n"
                            "    <div><p>%s</p></div>\n"
                            "  </div>\n"
                            "</body></html>\n",
                            icon_info ? gtk_icon_info_get_filename (icon_info) : "",
                            /* Displayed when opening the browser for the first time. */
                            _("Welcome to Web"), _("Start browsing and your most-visited sites will appear here."));
    if (icon_info)
      g_object_unref (icon_info);
    goto out;
  }

  g_string_append (data_str,
438
                   "<div id=\"overview\">\n");
439

440
  g_string_append (data_str,
441
                   "<div id=\"most-visited-grid\">\n");
442

443
444
445
  for (l = urls; l; l = g_list_next (l)) {
    EphyHistoryURL *url = (EphyHistoryURL *)l->data;
    const char *snapshot;
446
    g_autofree char *thumbnail_style = NULL;
447
448
    g_autofree char *entity_encoded_title = NULL;
    g_autofree char *attribute_encoded_title = NULL;
449
    g_autofree char *encoded_url = NULL;
450

451
    snapshot = ephy_snapshot_service_lookup_cached_snapshot_path (snapshot_service, url->url);
452
    if (snapshot)
453
      thumbnail_style = g_strdup_printf (" style=\"background: url(file://%s) no-repeat; background-size: 100%%;\"", snapshot);
454
455
    else
      ephy_embed_shell_schedule_thumbnail_update (shell, url);
456

457
    /* Title and URL are controlled by web content and could be malicious. */
458
459
    entity_encoded_title = ephy_encode_for_html_entity (url->title);
    attribute_encoded_title = ephy_encode_for_html_attribute (url->title);
460
    encoded_url = ephy_encode_for_html_attribute (url->url);
461
    g_string_append_printf (data_str,
462
                            "<a class=\"overview-item\" title=\"%s\" href=\"%s\">"
463
                            "  <div class=\"overview-close-button\" title=\"%s\"></div>"
464
465
466
                            "  <span class=\"overview-thumbnail\"%s></span>"
                            "  <span class=\"overview-title\">%s</span>"
                            "</a>",
467
468
469
                            attribute_encoded_title, encoded_url, _("Remove from overview"),
                            thumbnail_style ? thumbnail_style : "",
                            entity_encoded_title);
470
  }
471

472
  data_str = g_string_append (data_str,
473
                              "  </div>\n"
474
475
                              "  </div>\n"
                              "</body></html>\n");
476

477
out:
478
479
  data_length = data_str->len;
  ephy_about_handler_finish_request (request, g_string_free (data_str, FALSE), data_length);
480
481
482
  g_object_unref (request);
}

483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
static gboolean
ephy_about_handler_handle_newtab (EphyAboutHandler       *handler,
                                  WebKitURISchemeRequest *request)
{
  char *data;

  data = g_strdup_printf ("<html><head><title>%s</title>"
                          "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
                          "</head><body style=\"color-scheme: light dark;\">"
                          "</body></html>",
                          _(NEW_TAB_PAGE_TITLE));

  ephy_about_handler_finish_request (request, data, -1);

  return TRUE;
}

500
501
EphyHistoryQuery *
ephy_history_query_new_for_overview (void)
502
503
504
505
506
507
508
{
  EphyHistoryQuery *query;

  query = ephy_history_query_new ();
  query->sort_type = EPHY_HISTORY_SORT_MOST_VISITED;
  query->limit = EPHY_ABOUT_OVERVIEW_MAX_ITEMS;
  query->ignore_hidden = TRUE;
509
  query->ignore_local = TRUE;
510
511
512
513
514
515
516
517
518
519
520

  return query;
}

static gboolean
ephy_about_handler_handle_html_overview (EphyAboutHandler       *handler,
                                         WebKitURISchemeRequest *request)
{
  EphyHistoryService *history;
  EphyHistoryQuery *query;

521
  history = ephy_embed_shell_get_global_history_service (ephy_embed_shell_get_default ());
522
  query = ephy_history_query_new_for_overview ();
523
524
525
526
  ephy_history_service_query_urls (history, query, NULL,
                                   (EphyHistoryJobCallback)history_service_query_urls_cb,
                                   g_object_ref (request));
  ephy_history_query_free (query);
527
528
529
530

  return TRUE;
}

531
static gboolean
Michael Catanzaro's avatar
Michael Catanzaro committed
532
ephy_about_handler_handle_incognito (EphyAboutHandler       *handler,
533
                                     WebKitURISchemeRequest *request)
534
{
535
  char *data;
536

537
538
539
  if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) != EPHY_EMBED_SHELL_MODE_INCOGNITO)
    return FALSE;

540
541
542
543
544
  data = g_strdup_printf ("<html>\n"
                          "<div dir=\"%s\">\n"
                          "<head>\n"
                          "<title>%s</title>\n"
                          "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
Michael Catanzaro's avatar
Michael Catanzaro committed
545
                          "<link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS "\" rel=\"stylesheet\" type=\"text/css\">\n"
546
547
                          "</head>\n"
                          "<body class=\"incognito-body\">\n"
548
                          "  <img class=\"incognito-body-image\" src=\"ephy-resource:///org/gnome/epiphany/page-icons/private-mode.svg\">\n" \
549
550
551
552
                          "  <br/>\n"
                          "  <h1>%s</h1>\n"
                          "  <p>%s</p>\n"
                          "  <p><strong>%s</strong> %s</p>\n"
553
554
                          "</body>\n"
                          "</div>\n"
555
                          "</html>\n",
556
                          gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ? "rtl" : "ltr",
557
558
                          _("Private Browsing"),
                          _("Private Browsing"),
559
                          _("You are currently browsing incognito. Pages viewed in this "
560
                            "mode will not show up in your browsing history and all stored "
561
562
                            "information will be cleared when you close the window. Files you "
                            "download will be kept."),
563
564
                          _("Incognito mode hides your activity only from people using this "
                            "computer."),
Michael Catanzaro's avatar
Michael Catanzaro committed
565
                          _("It will not hide your activity from your employer if you are at "
566
567
568
                            "work. Your internet service provider, your government, other "
                            "governments, the websites that you visit, and advertisers on "
                            "these websites may still be tracking you."));
569

570
571
572
  ephy_about_handler_finish_request (request, data, -1);

  return TRUE;
573
574
}

575
static void
Michael Catanzaro's avatar
Michael Catanzaro committed
576
ephy_about_handler_handle_blank (EphyAboutHandler       *handler,
577
                                 WebKitURISchemeRequest *request)
578
{
579
580
  ephy_about_handler_finish_request (request, g_strdup ("<html></html>"), -1);
}
581

582
583
584
585
586
EphyAboutHandler *
ephy_about_handler_new (void)
{
  return EPHY_ABOUT_HANDLER (g_object_new (EPHY_TYPE_ABOUT_HANDLER, NULL));
}
587

588
void
Michael Catanzaro's avatar
Michael Catanzaro committed
589
ephy_about_handler_handle_request (EphyAboutHandler       *handler,
590
591
592
                                   WebKitURISchemeRequest *request)
{
  const char *path;
Michael Catanzaro's avatar
Michael Catanzaro committed
593
  gboolean handled = FALSE;
594
595
596

  path = webkit_uri_scheme_request_get_path (request);

Michael Catanzaro's avatar
Michael Catanzaro committed
597
  if (!g_strcmp0 (path, "memory"))
598
599
    handled = ephy_about_handler_handle_memory (handler, request);
  else if (!g_strcmp0 (path, "epiphany"))
Michael Catanzaro's avatar
Michael Catanzaro committed
600
    handled = ephy_about_handler_handle_epiphany (handler, request);
601
  else if (!g_strcmp0 (path, "applications"))
602
    handled = ephy_about_handler_handle_applications (handler, request);
603
604
  else if (!g_strcmp0 (path, "newtab"))
    handled = ephy_about_handler_handle_newtab (handler, request);
605
  else if (!g_strcmp0 (path, "overview"))
606
    handled = ephy_about_handler_handle_html_overview (handler, request);
607
608
  else if (!g_strcmp0 (path, "incognito"))
    handled = ephy_about_handler_handle_incognito (handler, request);
William Jon McCann's avatar
William Jon McCann committed
609
610
  else if (path == NULL || path[0] == '\0' || !g_strcmp0 (path, "Web") || !g_strcmp0 (path, "web"))
    handled = ephy_about_handler_handle_about (handler, request);
611
612
613

  if (!handled)
    ephy_about_handler_handle_blank (handler, request);
614
}