[epiphany/tgt: 7/10] Add automatic redirection from error page to requested url when available



commit 4319a4dbfd3e441e9c8974923903434d8b881add
Author: Lorenzo Tilve Álvaro <ltilve igalia com>
Date:   Wed Jul 31 00:10:25 2013 +0200

    Add automatic redirection from error page to requested url when available
    
    A new setting has been added to determine the periodic delay in
    seconds that the Epiphany error page will wait to try to send a
    message to the requested URL, and if the request is succesful
    a redirection to the address will be done.

 data/org.gnome.epiphany.gschema.xml |    5 +++++
 embed/ephy-web-view.c               |   34 ++++++++++++++++++++++++++++++++++
 lib/ephy-prefs.h                    |    1 +
 3 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index 5326a3a..71c2643 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -74,6 +74,11 @@
                        <summary>Home page</summary>
                        <description>Address of the user's home page.</description>
                </key>
+               <key type="i" name="redirect-on-error-delay">
+                       <default>0</default>
+                       <summary>Seconds to automatic redirect after error.</summary>
+                       <description>Delay in seconds to redirect from error page to requested URL. Set to 0 
to disable the redirection.</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 11b3175..23c6001 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2431,6 +2431,35 @@ ephy_web_view_set_placeholder (EphyWebView *view,
   ephy_web_view_set_address (view, uri);
 }
 
+static gboolean
+redirect_on_soup_status_successful (EphyWebView *view)
+{
+  const gchar *url;
+  gint status_code;
+  gboolean result = TRUE;
+  url = ephy_web_view_get_address (view);
+
+  SoupMessage *message;
+  SoupSession *session;
+
+  session = soup_session_new ();
+  message = soup_message_new (SOUP_METHOD_HEAD, url);
+
+  if (message != NULL) {
+    status_code = soup_session_send_message (session, message);
+    if (SOUP_STATUS_IS_SUCCESSFUL (status_code)) {
+      ephy_web_view_load_url (view, url);
+      result = FALSE;
+    }
+  }
+
+  g_object_unref (message);
+  g_object_unref (session);
+
+  return result;
+}
+
+
 /**
  * ephy_web_view_load_error_page:
  * @view: an #EphyWebView
@@ -2577,6 +2606,11 @@ ephy_web_view_load_error_page (EphyWebView *view,
                    image_data ? image_data : "",
                    msg_title, msg, button_reload, button_home, button_back);
 
+  if (g_settings_get_int (EPHY_SETTINGS_MAIN, EPHY_PREFS_REDIRECT_ON_ERROR_DELAY) != 0) {
+    g_timeout_add_seconds (g_settings_get_int (EPHY_SETTINGS_MAIN, EPHY_PREFS_REDIRECT_ON_ERROR_DELAY),
+                           (GSourceFunc) redirect_on_soup_status_successful, WEBKIT_WEB_VIEW (view));
+  }
+
   g_free (template);
   g_free (lang);
   g_free (page_title);
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index 660eb9d..d0b09e0 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -127,6 +127,7 @@ typedef enum
 #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_HOMEPAGE_URL                   "homepage-url"
+#define EPHY_PREFS_REDIRECT_ON_ERROR_DELAY        "redirect-on-error-delay"
 
 #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]