/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * Copyright © 2012 Igalia S.L. * * This file is part of Epiphany. * * Epiphany 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 3 of the License, or * (at your option) any later version. * * Epiphany 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 Epiphany. If not, see . */ #include "config.h" #include "ephy-about-handler.h" #include "ephy-embed-shell.h" #include "ephy-embed-prefs.h" #include "ephy-embed-utils.h" #include "ephy-file-helpers.h" #include "ephy-flatpak-utils.h" #include "ephy-history-service.h" #include "ephy-prefs.h" #include "ephy-settings.h" #include "ephy-smaps.h" #include "ephy-snapshot-service.h" #include "ephy-web-app-utils.h" #include #include #include struct _EphyAboutHandler { GObject parent_instance; EphySMaps *smaps; }; G_DEFINE_TYPE (EphyAboutHandler, ephy_about_handler, G_TYPE_OBJECT) #define EPHY_ABOUT_OVERVIEW_MAX_ITEMS 9 #define EPHY_PAGE_TEMPLATE_ABOUT_CSS "ephy-resource:///org/gnome/epiphany/page-templates/about.css" static void ephy_about_handler_finalize (GObject *object) { EphyAboutHandler *handler = EPHY_ABOUT_HANDLER (object); g_clear_object (&handler->smaps); G_OBJECT_CLASS (ephy_about_handler_parent_class)->finalize (object); } static void ephy_about_handler_init (EphyAboutHandler *handler) { } static void ephy_about_handler_class_init (EphyAboutHandlerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = ephy_about_handler_finalize; } static EphySMaps * ephy_about_handler_get_smaps (EphyAboutHandler *handler) { if (!handler->smaps) handler->smaps = ephy_smaps_new (); return handler->smaps; } static void ephy_about_handler_finish_request (WebKitURISchemeRequest *request, gchar *data, gssize data_length) { GInputStream *stream; data_length = data_length != -1 ? data_length : (gssize)strlen (data); 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 handle_memory_finished_cb (EphyAboutHandler *handler, GAsyncResult *result, WebKitURISchemeRequest *request) { GString *data_str; gsize data_length; char *memory; data_str = g_string_new (""); memory = g_task_propagate_pointer (G_TASK (result), NULL); if (memory) { g_string_append_printf (data_str, "%s" "" "" "" "
", _("Memory usage")); g_string_append_printf (data_str, "

%s

", _("Memory usage")); g_string_append (data_str, memory); g_free (memory); g_string_append (data_str, "
"); } g_string_append (data_str, ""); data_length = data_str->len; ephy_about_handler_finish_request (request, g_string_free (data_str, FALSE), data_length); g_object_unref (request); } static void handle_memory_sync (GTask *task, gpointer source_object, gpointer task_data, 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 ephy_about_handler_handle_memory (EphyAboutHandler *handler, 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); return TRUE; } static gboolean ephy_about_handler_handle_about (EphyAboutHandler *handler, WebKitURISchemeRequest *request) { char *data; char *version; GtkIconInfo *icon_info; version = g_strdup_printf (_("Version %s"), VERSION); icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), APPLICATION_ID, 256, GTK_ICON_LOOKUP_FORCE_SVG); data = g_strdup_printf ("%s" "" "" "" "
" "
" "" "

%s

" "

%s

" "

%s

" "" "" "
%s%d.%d.%d
" "
", _("About Web"), icon_info ? gtk_icon_info_get_filename (icon_info) : "", #if !TECH_PREVIEW _("Web"), #else _("Epiphany Technology Preview"), #endif version, _("A simple, clean, beautiful view of the web"), "WebKitGTK", webkit_get_major_version (), webkit_get_minor_version (), webkit_get_micro_version ()); g_free (version); if (icon_info) g_object_unref (icon_info); ephy_about_handler_finish_request (request, data, -1); return TRUE; } static gboolean ephy_about_handler_handle_epiphany (EphyAboutHandler *handler, WebKitURISchemeRequest *request) { char *data; data = g_strdup_printf ("%s" "" "" "" "
" "« 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" "
", _("Web")); ephy_about_handler_finish_request (request, data, -1); return TRUE; } static void handle_applications_finished_cb (EphyAboutHandler *handler, GAsyncResult *result, WebKitURISchemeRequest *request) { GString *data_str; gsize data_length; GList *applications, *p; data_str = g_string_new (NULL); applications = g_task_propagate_pointer (G_TASK (result), NULL); if (g_list_length (applications) > 0) { g_string_append_printf (data_str, "%s" "" "" "" "

%s

" "

%s

", _("Applications"), _("Applications"), _("List of installed web applications")); g_string_append (data_str, ""); for (p = applications; p; p = p->next) { EphyWebApplication *app = (EphyWebApplication *)p->data; if (ephy_web_application_is_system (app)) continue; g_string_append_printf (data_str, "" "" "" "" "", app->id, app->icon_url, app->name, app->url, _("Delete"), app->id, /* Note for translators: this refers to the installation date. */ _("Installed on:"), app->install_date); } g_string_append (data_str, "
%s
%s
%s
%s
"); } else { g_autoptr (GtkIconInfo) icon_info = NULL; g_autofree gchar *icon = g_strconcat ("application-x-addon-symbolic", NULL); g_string_append_printf (data_str, "%s" "" "" "", _("Applications")); icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), icon, 128, 0); g_string_append_printf (data_str, "
\n" " \n" "

%s

\n" "

%s

\n" "
\n" "\n", icon_info ? gtk_icon_info_get_filename (icon_info) : "", /* Displayed when opening applications without any installed web apps. */ _("Applications"), _("You can add your favorite website by clicking Install Site as Web Application… within the page menu.")); } ephy_web_application_free_application_list (applications); data_length = data_str->len; ephy_about_handler_finish_request (request, g_string_free (data_str, FALSE), data_length); g_object_unref (request); } static void handle_applications_sync (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { g_task_return_pointer (task, ephy_web_application_get_application_list (), (GDestroyNotify)ephy_web_application_free_application_list); } static gboolean ephy_about_handler_handle_applications (EphyAboutHandler *handler, 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); return TRUE; } static void history_service_query_urls_cb (EphyHistoryService *history, gboolean success, GList *urls, WebKitURISchemeRequest *request) { EphySnapshotService *snapshot_service; EphyEmbedShell *shell; GString *data_str; gsize data_length; char *lang; GList *l; guint list_length; snapshot_service = ephy_snapshot_service_get_default (); shell = ephy_embed_shell_get_default (); data_str = g_string_new (NULL); lang = g_strdup (pango_language_to_string (gtk_get_default_language ())); g_strdelimit (lang, "_-@", '\0'); g_string_append_printf (data_str, "\n" "\n" " %s\n" " \n" " " " \n" " \n" "\n" "\n", lang, lang, ((gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) ? "rtl" : "ltr"), _(OVERVIEW_PAGE_TITLE)); g_free (lang); list_length = g_list_length (urls); if (list_length == 0 || !success) { GtkIconInfo *icon_info; g_autofree gchar *icon = g_strconcat (APPLICATION_ID, "-symbolic", NULL); icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), icon, 128, 0); g_string_append_printf (data_str, "
\n" " \n" "

%s

\n" "

%s

\n" "
\n" "\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, "
\n"); g_string_append (data_str, "
\n"); for (l = urls; l; l = g_list_next (l)) { EphyHistoryURL *url = (EphyHistoryURL *)l->data; const char *snapshot; g_autofree char *thumbnail_style = NULL; g_autofree char *markup = NULL; snapshot = ephy_snapshot_service_lookup_cached_snapshot_path (snapshot_service, url->url); if (snapshot) thumbnail_style = g_strdup_printf (" style=\"background: url(file://%s) no-repeat; background-size: 100%%;\"", snapshot); else ephy_embed_shell_schedule_thumbnail_update (shell, url); markup = g_markup_escape_text (url->title, -1); g_string_append_printf (data_str, "" "
" " " " %s" "
", markup, url->url, _("Remove from overview"), thumbnail_style ? thumbnail_style : "", url->title); } data_str = g_string_append (data_str, "
\n" "
\n" "\n"); out: data_length = data_str->len; ephy_about_handler_finish_request (request, g_string_free (data_str, FALSE), data_length); g_object_unref (request); } EphyHistoryQuery * ephy_history_query_new_for_overview (void) { 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; query->ignore_local = TRUE; return query; } static gboolean ephy_about_handler_handle_html_overview (EphyAboutHandler *handler, WebKitURISchemeRequest *request) { EphyHistoryService *history; EphyHistoryQuery *query; history = ephy_embed_shell_get_global_history_service (ephy_embed_shell_get_default ()); query = ephy_history_query_new_for_overview (); ephy_history_service_query_urls (history, query, NULL, (EphyHistoryJobCallback)history_service_query_urls_cb, g_object_ref (request)); ephy_history_query_free (query); return TRUE; } static gboolean ephy_about_handler_handle_incognito (EphyAboutHandler *handler, WebKitURISchemeRequest *request) { char *data; if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) != EPHY_EMBED_SHELL_MODE_INCOGNITO) return FALSE; data = g_strdup_printf ("\n" "
\n" "\n" "%s\n" "" "\n" "\n" "\n" " \n" \ "
\n" "

%s

\n" "

%s

\n" "

%s %s

\n" "\n" "
\n" "\n", gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ? "rtl" : "ltr", _("Private Browsing"), _("Private Browsing"), _("You are currently browsing incognito. 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. Files you " "download will be kept."), _("Incognito mode hides your activity only from people using this " "computer."), _("It will not hide your activity from your employer if you are at " "work. Your internet service provider, your government, other " "governments, the websites that you visit, and advertisers on " "these websites may still be tracking you.")); ephy_about_handler_finish_request (request, data, -1); return TRUE; } static void ephy_about_handler_handle_blank (EphyAboutHandler *handler, WebKitURISchemeRequest *request) { ephy_about_handler_finish_request (request, g_strdup (""), -1); } EphyAboutHandler * ephy_about_handler_new (void) { return EPHY_ABOUT_HANDLER (g_object_new (EPHY_TYPE_ABOUT_HANDLER, NULL)); } void ephy_about_handler_handle_request (EphyAboutHandler *handler, WebKitURISchemeRequest *request) { const char *path; gboolean handled = FALSE; path = webkit_uri_scheme_request_get_path (request); if (!g_strcmp0 (path, "memory")) handled = ephy_about_handler_handle_memory (handler, request); else if (!g_strcmp0 (path, "epiphany")) handled = ephy_about_handler_handle_epiphany (handler, request); else if (!g_strcmp0 (path, "applications") && !ephy_is_running_inside_flatpak ()) handled = ephy_about_handler_handle_applications (handler, request); else if (!g_strcmp0 (path, "overview")) handled = ephy_about_handler_handle_html_overview (handler, request); else if (!g_strcmp0 (path, "incognito")) handled = ephy_about_handler_handle_incognito (handler, request); else if (path == NULL || path[0] == '\0' || !g_strcmp0 (path, "Web") || !g_strcmp0 (path, "web")) handled = ephy_about_handler_handle_about (handler, request); if (!handled) ephy_about_handler_handle_blank (handler, request); }