[epiphany/gnome-3-22] Open ftp URIs in external application



commit 398bec459a20c49cd11a3420943a9293f177f854
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Sep 11 20:04:34 2016 -0500

    Open ftp URIs in external application
    
    Likely we're never going to support FTP, at least not unless a wild
    volunteer appears to implement it.
    
    So:
    
    First, try the default URI handler. It might be Firefox, which is odd
    but will work. Whatever gvfs-open picks on my computer fails with an
    error that the specified location is not mounted, so forcibly fall back
    to Nautilus if the default application did not work.

 embed/ephy-embed-shell.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index cd74f7d..2d86f32 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -499,6 +499,36 @@ ephy_resource_request_cb (WebKitURISchemeRequest *request)
 }
 
 static void
+ftp_request_cb (WebKitURISchemeRequest *request)
+{
+  GDesktopAppInfo *app_info;
+  const char *uri;
+  GList *list = NULL;
+  GError *error = NULL;
+
+  uri = webkit_uri_scheme_request_get_uri (request);
+  g_app_info_launch_default_for_uri (uri, NULL, &error);
+
+  if (!error) {
+    g_signal_emit_by_name (webkit_uri_scheme_request_get_web_view (request), "close", NULL);
+    return;
+  }
+
+  /* Default URI handler didn't work. Try nautilus before giving up. */
+  app_info = g_desktop_app_info_new ("org.gnome.Nautilus.desktop");
+  list = g_list_append (list, (gpointer)uri);
+
+  if (app_info && g_app_info_launch_uris (G_APP_INFO (app_info), list, NULL, NULL))
+    g_signal_emit_by_name (webkit_uri_scheme_request_get_web_view (request), "close", NULL);
+  else
+    webkit_uri_scheme_request_finish_error (request, error);
+
+  g_list_free (list);
+  g_error_free (error);
+  g_object_unref (app_info);
+}
+
+static void
 web_extension_destroyed (EphyEmbedShell *shell,
                          GObject        *web_extension)
 {
@@ -753,6 +783,11 @@ ephy_embed_shell_startup (GApplication *application)
                                           (WebKitURISchemeRequestCallback)ephy_resource_request_cb,
                                           NULL, NULL);
 
+  /* No support for FTP, try to open in nautilus instead of failing */
+  webkit_web_context_register_uri_scheme (priv->web_context, "ftp",
+                                          (WebKitURISchemeRequestCallback)ftp_request_cb,
+                                          NULL, NULL);
+
   /* Store cookies in moz-compatible SQLite format */
   cookie_manager = webkit_web_context_get_cookie_manager (priv->web_context);
   filename = g_build_filename (ephy_dot_dir (), "cookies.sqlite", NULL);


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