aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Escalante Urrelo <descalante@igalia.com>2009-09-01 13:05:36 +0800
committerDiego Escalante Urrelo <descalante@igalia.com>2010-12-11 00:53:50 +0800
commite435a10d44dfed0705a5703b406c854a1208821e (patch)
treec379fa7e3b59974f72813868a5cb504b378e1ff1
parent3a1e97fbd04ca466535da01e8fdd0bca95560aa4 (diff)
downloadgsoc2013-epiphany-e435a10d44dfed0705a5703b406c854a1208821e.tar
gsoc2013-epiphany-e435a10d44dfed0705a5703b406c854a1208821e.tar.gz
gsoc2013-epiphany-e435a10d44dfed0705a5703b406c854a1208821e.tar.bz2
gsoc2013-epiphany-e435a10d44dfed0705a5703b406c854a1208821e.tar.lz
gsoc2013-epiphany-e435a10d44dfed0705a5703b406c854a1208821e.tar.xz
gsoc2013-epiphany-e435a10d44dfed0705a5703b406c854a1208821e.tar.zst
gsoc2013-epiphany-e435a10d44dfed0705a5703b406c854a1208821e.zip
ephy-web-view: use custom error pages
Show nice error pages instead of WebKitGTK+'s defaults. Bug #592667
-rw-r--r--configure.ac1
-rw-r--r--data/Makefile.am2
-rw-r--r--data/pages/Makefile.am6
-rw-r--r--data/pages/error.html73
-rw-r--r--data/pages/recovery.html73
-rw-r--r--embed/ephy-web-view.c150
-rw-r--r--embed/ephy-web-view.h10
-rw-r--r--lib/ephy-file-helpers.c4
-rw-r--r--src/ephy-session.c81
9 files changed, 312 insertions, 88 deletions
diff --git a/configure.ac b/configure.ac
index 0ffef99c2..c081f4c95 100644
--- a/configure.ac
+++ b/configure.ac
@@ -432,6 +432,7 @@ data/bme.desktop.in
data/glade/Makefile
data/icons/Makefile
data/art/Makefile
+data/pages/Makefile
data/ui/Makefile
doc/Makefile
doc/reference/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index e6ab83e4a..6fcfa8144 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = art glade icons ui
+SUBDIRS = art glade icons pages ui
@INTLTOOL_SERVER_RULE@
@INTLTOOL_DESKTOP_RULE@
diff --git a/data/pages/Makefile.am b/data/pages/Makefile.am
new file mode 100644
index 000000000..f2b879a5f
--- /dev/null
+++ b/data/pages/Makefile.am
@@ -0,0 +1,6 @@
+errorpagesdir = $(pkgdatadir)/pages
+errorpages_DATA = \
+ recovery.html \
+ error.html
+
+EXTRA_DIST = $(errorpages_DATA)
diff --git a/data/pages/error.html b/data/pages/error.html
new file mode 100644
index 000000000..0c6db3be4
--- /dev/null
+++ b/data/pages/error.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ Copyright © 2010 Vinicius Depizzol
+
+ 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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%s" lang="%s">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title>%s</title>
+ <style type="text/css">
+ body {
+ margin: 0 auto;
+ padding: 7em;
+ font: message-box;
+ display: table;
+ direction: %s;
+ }
+ div#centeredContent {
+ display: table;
+ margin: 0 auto;
+ }
+ div#centeredContent h1 {
+ display: table-row;
+ }
+ div#centeredContent div {
+ display: table-row-group;
+ }
+ h1 {
+ font-size: 180%;
+ }
+ img {
+ vertical-align: middle;
+ float: left;
+ margin-right: 20px;
+ width: 50px;
+ height: 50px;
+ }
+ p.buttonbox {
+ text-align: right;
+ }
+ </style>
+ <script type="text/javascript">
+ function load_anyway()
+ {
+ window.location = '%s';
+ }
+ </script>
+</head>
+<body>
+<img src="%s"/>
+<div id="centeredContent">
+ <div>
+ <h1 style="text-align:left;">%s</h1>
+ <p class="message">%s</p>
+ <p class="buttonbox">
+ <button onclick="javascript:load_anyway()">%s</button></p>
+ </div>
+</div>
+</body>
+</html>
diff --git a/data/pages/recovery.html b/data/pages/recovery.html
new file mode 100644
index 000000000..0c6db3be4
--- /dev/null
+++ b/data/pages/recovery.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ Copyright © 2010 Vinicius Depizzol
+
+ 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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%s" lang="%s">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title>%s</title>
+ <style type="text/css">
+ body {
+ margin: 0 auto;
+ padding: 7em;
+ font: message-box;
+ display: table;
+ direction: %s;
+ }
+ div#centeredContent {
+ display: table;
+ margin: 0 auto;
+ }
+ div#centeredContent h1 {
+ display: table-row;
+ }
+ div#centeredContent div {
+ display: table-row-group;
+ }
+ h1 {
+ font-size: 180%;
+ }
+ img {
+ vertical-align: middle;
+ float: left;
+ margin-right: 20px;
+ width: 50px;
+ height: 50px;
+ }
+ p.buttonbox {
+ text-align: right;
+ }
+ </style>
+ <script type="text/javascript">
+ function load_anyway()
+ {
+ window.location = '%s';
+ }
+ </script>
+</head>
+<body>
+<img src="%s"/>
+<div id="centeredContent">
+ <div>
+ <h1 style="text-align:left;">%s</h1>
+ <p class="message">%s</p>
+ <p class="buttonbox">
+ <button onclick="javascript:load_anyway()">%s</button></p>
+ </div>
+</div>
+</body>
+</html>
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 4335f5995..134d4a979 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2,7 +2,7 @@
/* vim: set sw=2 ts=2 sts=2 et: */
/*
* Copyright © 2008, 2009 Gustavo Noronha Silva
- * Copyright © 2009 Igalia S.L.
+ * Copyright © 2009, 2010 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
@@ -1997,17 +1997,142 @@ load_status_cb (WebKitWebView *web_view,
g_object_thaw_notify (object);
}
-static void set_main_frame_load_error (EphyWebView *view,
- const char *uri)
+static char *
+get_file_content_as_base64 (const char *path)
{
- char *message;
+ GFile *file;
+ GFileInfo *file_info;
+ const char *image_type;
+ char *image_raw;
+ gsize len;
+ char *image_data;
+ char *image64;
- message = g_strdup_printf (_("A problem occurred while loading %s"),
- uri);
- ephy_web_view_set_title (view, message);
- g_free (message);
+ file = g_file_new_for_path (path);
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
+ image_type = g_file_info_get_content_type (file_info);
+
+ g_object_unref (file);
+ g_object_unref (file_info);
+
+ g_file_get_contents (path, &image_raw, &len, NULL);
+ image_data = g_base64_encode ((guchar *) image_raw, len);
+ image64 = g_strdup_printf ("data:%s;base64,%s", image_type, image_data);
+
+ g_free (image_raw);
+ g_free (image_data);
+
+ return image64;
+}
+
+/**
+ * ephy_web_view_load_error_page:
+ * @view: an #EphyWebView
+ * @uri: uri that caused the failure
+ * @page: one of #EphyWebViewErrorPage
+ * @error: a GError to inspect, or %NULL
+ *
+ * Loads an error page appropiate for @page in @view.
+ *
+ **/
+void
+ephy_web_view_load_error_page (EphyWebView *view,
+ const char *uri,
+ EphyWebViewErrorPage page,
+ GError *error)
+{
+ GString *html = g_string_new ("");
+ const char *reason;
+
+ char *hostname;
+ char *lang;
+
+ char *page_title;
+ char *msg_title;
+ char *msg;
+ char *button_label;
+ const char *html_file;
+ const char *stock_icon;
+
+ GtkIconInfo *icon_info;
+ char *image_data;
+
+ char *template;
+
+ if (error)
+ reason = error->message;
+ else
+ reason = _("None specified");
+ hostname = ephy_string_get_host_name (uri);
+
+ lang = g_strdup (pango_language_to_string (gtk_get_default_language ()));
+ g_strdelimit (lang, "_-@", '\0');
+
+ switch (page) {
+ case EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR:
+ page_title = g_strdup_printf (_("Oops! Error loading %s"), hostname);
+
+ msg_title = g_strdup (_("Oops! It was impossible to load this website"));
+ msg = g_strdup_printf (_("The website at <strong>%s</strong> is probably unavailable, the precise error was:<br/><br/><em>%s</em>.<br/><br/> If this persist you might want to check your internet connection or if the website at <strong>%s</strong> is working correctly."),
+ uri, reason, hostname);
+
+ button_label = g_strdup (_("Try again"));
+
+ html_file = ephy_file ("error.html");
+ stock_icon = GTK_STOCK_DIALOG_ERROR;
+ break;
+ case EPHY_WEB_VIEW_ERROR_PAGE_CRASH:
+ page_title = g_strdup_printf (_("Oops! Error loading %s"), hostname);
+
+ msg_title = g_strdup (_("Oops! This site might have caused Epiphany to close unexpectedly"));
+ msg = g_strdup_printf (_("This page was loading when the web browser closed unexpectedly.<br/> This might happen again if you reload the page. If it does, please report the problem to the <strong>%s</strong> developers."),
+ LSB_DISTRIBUTOR);
+
+ button_label = g_strdup (_("Load again anyway"));
+
+ html_file = ephy_file ("recovery.html");
+ stock_icon = GTK_STOCK_DIALOG_INFO;
+ break;
+ default:
+ return;
+ break;
+ }
+ g_free (hostname);
+
+ icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+ stock_icon,
+ 48,
+ GTK_ICON_LOOKUP_GENERIC_FALLBACK);
+
+ image_data = get_file_content_as_base64 (gtk_icon_info_get_filename (icon_info));
+
+ g_file_get_contents (html_file, &template, NULL, NULL);
+
+ ephy_web_view_set_title (view, page_title);
_ephy_web_view_set_icon_address (view, NULL);
+
+ g_string_printf (html, template, lang, lang,
+ page_title,
+ gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ? "rtl" : "ltr",
+ uri,
+ image_data,
+ msg_title, msg, button_label);
+
+ g_free (template);
+ g_free (lang);
+ g_free (page_title);
+ g_free (msg_title);
+ g_free (msg);
+ g_free (button_label);
+ g_free (image_data);
+
+ webkit_web_view_load_string (WEBKIT_WEB_VIEW (view),
+ html->str, "text/html", "utf8", uri);
+ g_string_free (html, TRUE);
}
static gboolean
@@ -2023,8 +2148,8 @@ load_error_cb (WebKitWebView *web_view,
return FALSE;
if (error->domain == SOUP_HTTP_ERROR) {
- set_main_frame_load_error (view, uri);
- return FALSE;
+ ephy_web_view_load_error_page (view, uri, EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR, error);
+ return TRUE;
}
g_return_val_if_fail ((error->domain == WEBKIT_NETWORK_ERROR) ||
@@ -2045,8 +2170,8 @@ load_error_cb (WebKitWebView *web_view,
case WEBKIT_PLUGIN_ERROR_CANNOT_LOAD_PLUGIN:
case WEBKIT_PLUGIN_ERROR_JAVA_UNAVAILABLE:
case WEBKIT_PLUGIN_ERROR_CONNECTION_CANCELLED:
- set_main_frame_load_error (view, uri);
- break;
+ ephy_web_view_load_error_page (view, uri, EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR, error);
+ return TRUE;
case WEBKIT_NETWORK_ERROR_CANCELLED:
{
EphyWebViewPrivate *priv = view->priv;
@@ -2093,6 +2218,7 @@ close_web_view_cb (WebKitWebView *web_view,
return TRUE;
}
+
static void
adj_changed_cb (GtkAdjustment *adj, EphyWebView *view)
{
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index f4e18a582..7b412bd74 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -86,6 +86,11 @@ typedef enum
EPHY_WEB_VIEW_DOCUMENT_OTHER
} EphyWebViewDocumentType;
+typedef enum {
+ EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR,
+ EPHY_WEB_VIEW_ERROR_PAGE_CRASH
+} EphyWebViewErrorPage;
+
struct _EphyWebView
{
WebKitWebView parent;
@@ -173,6 +178,11 @@ gboolean ephy_web_view_can_go_up (EphyWebView
const char * ephy_web_view_get_address (EphyWebView *view);
const char * ephy_web_view_get_title_composite (EphyWebView *view);
+void ephy_web_view_load_error_page (EphyWebView *view,
+ const char *uri,
+ EphyWebViewErrorPage page,
+ GError *error);
+
/* These should be private */
void ephy_web_view_set_address (EphyWebView *view,
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index b5a174b41..9e591365b 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -276,10 +276,12 @@ ephy_file (const char *filename)
SHARE_UNINSTALLED_DIR "/",
SHARE_UNINSTALLED_DIR "/glade/",
SHARE_UNINSTALLED_DIR "/art/",
+ SHARE_UNINSTALLED_DIR "/pages/",
#endif
SHARE_DIR "/",
SHARE_DIR "/glade/",
- SHARE_DIR "/art/"
+ SHARE_DIR "/art/",
+ SHARE_DIR "/pages/"
};
g_assert (files != NULL);
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 3688afc44..cee9e490e 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -1352,86 +1352,19 @@ out:
return ret >= 0 ? TRUE : FALSE;
}
-
-static void
+static void
confirm_before_recover (EphyWindow* window, char* url, char* title)
{
-
- GtkWidget *embed;
- GString *html = g_string_new ("");
- char *message = g_markup_printf_escaped
- /* Translators: %s refers to the LSB distributor ID, for instance MandrivaLinux */
- (_("This page was loading when the web browser closed unexpectedly. "
- "This might happen again if you reload the page. If it does, please report "
- "the problem to the %s developers."),
- LSB_DISTRIBUTOR);
-
- const char *format =
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
- "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
- "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">" /* language (twice) */
- "<head>"
- "<title>"
- "%s" /* web title */
- "</title>"
- "<style type=\"text/css\">"
- "div#body {"
- "top: 12px;"
- "right: 12px;"
- "bottom: 12px;"
- "left: 12px;"
- "overflow: auto;"
- "background-color:#dcdad5;"
- "font: message-box;"
- "border: 1px solid;"
- "background-repeat: no-repeat;"
- "background-position: center left;"
- "padding: 12px 12px 12px 72px;"
- "text-align:left;"
-
- "h1 {"
-
- "margin: 0;"
- "font-size: 1.2em;"
-
- "}"
- "</style>"
-
- "</head>"
-
- "<body dir=\"%s\">" /* rtl or ltr */
- "<div id=\"body\">"
-
- "<h1>"
- "%s" /* head of the message */
- "</h1>"
-
- "<p> %s </p>" /* message */
-
- "</div>"
- "</body>"
- "</html>";
-
- char *language = g_strdup (pango_language_to_string (gtk_get_default_language ()));
- g_strdelimit (language, "_-@", '\0');
-
- g_string_printf (html, format, language, language, title,
- gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ? "rtl" : "ltr",
- _("Blank page"), message);
+ EphyEmbed *embed;
- embed = (GtkWidget*) ephy_shell_new_tab (ephy_shell, window, NULL, NULL,
- EPHY_NEW_TAB_IN_EXISTING_WINDOW | EPHY_NEW_TAB_APPEND_LAST);
+ embed = ephy_shell_new_tab (ephy_shell, window, NULL, NULL,
+ EPHY_NEW_TAB_IN_EXISTING_WINDOW |
+ EPHY_NEW_TAB_APPEND_LAST);
- /* show generated html and put the original URL in the navigation bar */
- webkit_web_view_load_html_string (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (EPHY_EMBED (embed)),
- html->str,
- url);
- g_string_free (html, TRUE);
- g_free (message);
- g_free (language);
+ ephy_web_view_load_error_page (ephy_embed_get_web_view (embed), url,
+ EPHY_WEB_VIEW_ERROR_PAGE_CRASH, NULL);
}
-
static void
parse_embed (xmlNodePtr child,
EphyWindow *window,