[epiphany/kiosk-mode] Add custom http errors support



commit 90909abb45223bd776b871667bebc16ccb409292
Author: Javier M. Mellid <jmunhoz igalia com>
Date:   Wed Jul 3 11:39:12 2013 +0200

    Add custom http errors support
    
    When custom-http-error-management enabled the browser takes control over
    pages displaying http errors.
    
    This option is useful to handle some use cases where user operates under
    a limited user experience and http error pages may need customization
    (e.g. kiosk mode configurations)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702436

 data/org.gnome.epiphany.gschema.xml |    5 +++
 embed/ephy-web-view.c               |   52 +++++++++++++++++++++++++++++++++++
 embed/ephy-web-view.h               |    3 +-
 lib/ephy-prefs.h                    |    1 +
 4 files changed, 60 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index b815635..5a32af1 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -59,6 +59,11 @@
                         <summary>Whether to delay loading of tabs that are not immediately visible on 
session restore</summary>
                         <description>When this option is set to true, tabs will not start loading until the 
user switches to them, upon session restore.</description>
                 </key>
+               <key type="b" name="custom-http-errors-management">
+                       <default>false</default>
+                       <summary>Custom HTTP errors management</summary>
+                       <description>Show a custom page when a HTTP error happens browsing the 
web.</description>
+               </key>
        </schema>
        <schema path="/org/gnome/epiphany/ui/" id="org.gnome.Epiphany.ui">
                <key type="b" name="show-toolbars">
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 66a6078..224bf78 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -77,6 +77,7 @@ struct _EphyWebViewPrivate {
   guint is_setting_zoom : 1;
   guint load_failed : 1;
   guint history_frozen : 1;
+  guint is_custom_http_errors_management : 1;
 
   char *address;
   char *typed_address;
@@ -2174,6 +2175,28 @@ load_changed_cb (WebKitWebView *web_view,
       g_free (history_uri);
     }
 
+    if (priv->is_custom_http_errors_management) {
+       WebKitWebResource *web_resource;
+       WebKitURIResponse *response;
+       guint status_code;
+
+       web_resource = webkit_web_view_get_main_resource (WEBKIT_WEB_VIEW (view));
+       response = webkit_web_resource_get_response (web_resource);
+       status_code = webkit_uri_response_get_status_code (response);
+
+       if (SOUP_STATUS_IS_CLIENT_ERROR (status_code) ||
+           SOUP_STATUS_IS_SERVER_ERROR (status_code)) {
+           GError *error = g_error_new (g_quark_from_static_string ("ephy-http-error"),
+                                        status_code,
+                                        "%d",
+                                        status_code);
+           ephy_web_view_load_error_page (EPHY_WEB_VIEW (view),
+                                          uri,
+                                          EPHY_WEB_VIEW_ERROR_PAGE_HTTP_ERROR,
+                                          error);
+           g_error_free (error);
+       }
+    }
     break;
   }
   case WEBKIT_LOAD_FINISHED:
@@ -2448,6 +2471,19 @@ ephy_web_view_load_error_page (EphyWebView *view,
       html_file = ephy_file ("error.html");
       stock_icon = "dialog-error";
       break;
+    case EPHY_WEB_VIEW_ERROR_PAGE_HTTP_ERROR:
+      page_title = g_strdup_printf (_("Oops! Error loading %s"), hostname);
+
+      msg_title = g_strdup (_("Oops! A HTTP error status code has been detected"));
+      msg = g_strdup_printf (_("<p>The website at <strong>%s</strong> has returned "
+                               "the following HTTP error status code: <em>%s</em>.</p>"),
+                             uri, reason);
+
+      button_label = g_strdup (_("Try again"));
+
+      html_file = ephy_file ("error.html");
+      stock_icon = "dialog-error";
+      break;
     case EPHY_WEB_VIEW_ERROR_PAGE_CRASH:
       page_title = g_strdup_printf (_("Oops! Error loading %s"), hostname);
 
@@ -2693,6 +2729,16 @@ do_not_track_setting_changed_cb (GSettings *settings,
 #endif
 
 static void
+custom_http_errors_management_cb (GSettings *settings,
+                                  char *key,
+                                  EphyWebView *view)
+{
+  EphyWebViewPrivate *priv = view->priv;
+  priv->is_custom_http_errors_management = g_settings_get_boolean (EPHY_SETTINGS_MAIN,
+                                                                   EPHY_PREFS_CUSTOM_HTTP_ERRORS_MANAGEMENT);
+}
+
+static void
 ephy_web_view_init (EphyWebView *web_view)
 {
   EphyWebViewPrivate *priv;
@@ -2827,6 +2873,12 @@ ephy_web_view_init (EphyWebView *web_view)
                     "changed::" EPHY_PREFS_WEB_DO_NOT_TRACK,
                     G_CALLBACK (do_not_track_setting_changed_cb), web_view);
 #endif
+
+  priv->is_custom_http_errors_management = g_settings_get_boolean (EPHY_SETTINGS_MAIN,
+                                                                   EPHY_PREFS_CUSTOM_HTTP_ERRORS_MANAGEMENT);
+  g_signal_connect (EPHY_SETTINGS_MAIN,
+                    "changed::" EPHY_PREFS_CUSTOM_HTTP_ERRORS_MANAGEMENT,
+                    G_CALLBACK (custom_http_errors_management_cb), web_view);
 }
 
 /**
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index 46c84f9..d3044bf 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -82,7 +82,8 @@ typedef enum
 typedef enum {
   EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR,
   EPHY_WEB_VIEW_ERROR_PAGE_CRASH,
-  EPHY_WEB_VIEW_ERROR_PROCESS_CRASH
+  EPHY_WEB_VIEW_ERROR_PROCESS_CRASH,
+  EPHY_WEB_VIEW_ERROR_PAGE_HTTP_ERROR
 } EphyWebViewErrorPage;
 
 struct _EphyWebView
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index 7fe2aee..17bc63c 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -124,6 +124,7 @@ typedef enum
 #define EPHY_PREFS_INTERNAL_VIEW_SOURCE           "internal-view-source"
 #define EPHY_PREFS_RESTORE_SESSION_POLICY         "restore-session-policy"
 #define EPHY_PREFS_RESTORE_SESSION_DELAYING_LOADS "restore-session-delaying-loads"
+#define EPHY_PREFS_CUSTOM_HTTP_ERRORS_MANAGEMENT  "custom-http-errors-management"
 
 #define EPHY_PREFS_LOCKDOWN_SCHEMA            "org.gnome.Epiphany.lockdown"
 #define EPHY_PREFS_LOCKDOWN_FULLSCREEN        "disable-fullscreen"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]