[epiphany] Reimplement content type checking



commit 009be331694b442dd859f49c7f02bdef498621ff
Author: Gustavo Noronha Silva <gns gnome org>
Date:   Sun Oct 25 18:22:46 2009 -0200

    Reimplement content type checking
    
    This brings back proper content type reporting, and the 'Open' button
    in the download dialog.
    
    Bug #598167

 configure.ac       |    2 +-
 embed/ephy-embed.c |   32 +++++++++++++++++++-------------
 2 files changed, 20 insertions(+), 14 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8dc78b4..6c77e82 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,7 +100,7 @@ LIBXSLT_REQUIRED=1.1.7
 LIBSTARTUP_NOTIFICATION_REQUIRED=0.5
 LIBNOTIFY_REQUIRED=0.4
 DBUS_GLIB_REQUIRED=0.35
-WEBKIT_GTK_REQUIRED=1.1.15
+WEBKIT_GTK_REQUIRED=1.1.16
 LIBSOUP_GNOME_REQUIRED=2.27.91
 GNOME_KEYRING_REQUIRED=2.26.0
 
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 5f338c5..39543ee 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -645,27 +645,38 @@ confirm_action_from_mime (WebKitWebView *web_view,
   GAppInfo *helper_app;
   const char *suggested_filename;
   int default_response;
+  WebKitNetworkResponse *response;
+  SoupMessage *message;
 
   parent_window = gtk_widget_get_toplevel (GTK_WIDGET(web_view));
   if (!gtk_widget_is_toplevel (parent_window))
     parent_window = NULL;
 
-  /* FIXME: we still have no way of getting the content type from
-   * webkit yet; we need to have a proper WebKitNetworkRequest
-   * implementation to do this here; see
-   * https://bugs.webkit.org/show_bug.cgi?id=18608
-   */
   helper_app = NULL;
   mime_description = NULL;
   mime_permission = EPHY_MIME_PERMISSION_SAFE;
+
+  response = webkit_download_get_network_response (download);
+  message = webkit_network_response_get_message (response);
+
+  if (message) {
+    const char *content_type = soup_message_headers_get_content_type (message->response_headers, NULL);
+
+    if (content_type) {
+      mime_description = g_content_type_get_description (content_type);
+      helper_app = g_app_info_get_default_for_type (content_type, FALSE);
+
+      if (helper_app) {
+        action = DOWNLOAD_ACTION_OPEN;
+      }
+    }
+  }
+
   if (mime_description == NULL) {
     mime_description = g_strdup (C_("file type", "Unknown"));
     action = DOWNLOAD_ACTION_OPEN_LOCATION;
   }
 
-  /* OPEN will never happen here, for now; see comment about
-   * WebKitNetworkRequest above!
-   */
   action_label = (action == DOWNLOAD_ACTION_OPEN) ? GTK_STOCK_OPEN : STOCK_DOWNLOAD;
   suggested_filename = webkit_download_get_suggested_filename (download);
 
@@ -757,11 +768,6 @@ download_status_changed_cb (GObject *object,
     return;
   }
 
-  /* FIXME: when we are able to obtain the MIME information from
-   * WebKit, we will want to decide earlier whether we want to open or
-   * open the location to where the file was downloaded. See
-   * perform_auto_download, too.
-   */
   g_object_ref (download); /* balanced in confirm_action_response_cb */
   confirm_action_from_mime (web_view, download, DOWNLOAD_ACTION_DOWNLOAD);
 }



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