[epiphany] Use new WebKit API to respect the Content-Disposition header



commit 1acaa540531f9ed3b33f87e10f0817b8c8ffd988
Author: Gustavo Noronha Silva <gns gnome org>
Date:   Tue Dec 8 14:08:15 2009 -0200

    Use new WebKit API to respect the Content-Disposition header
    
    This allows us to perform downloads when the server tells us to do so,
    even for types WebKit supports. This fixes downloading GMail attachments.
    
    Bug #598605

 configure.ac          |    2 +-
 embed/ephy-web-view.c |   30 +++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 869def4..20a3f78 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.17
+WEBKIT_GTK_REQUIRED=1.1.18
 LIBSOUP_GNOME_REQUIRED=2.27.91
 GNOME_KEYRING_REQUIRED=2.26.0
 
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index c525ab1..09172b4 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -969,6 +969,7 @@ mime_type_policy_decision_requested_cb (WebKitWebView *web_view,
                                         gpointer user_data)
 {
   EphyWebViewDocumentType type;
+  gboolean should_download;
 
   g_return_val_if_fail (mime_type, FALSE);
 
@@ -996,8 +997,35 @@ mime_type_policy_decision_requested_cb (WebKitWebView *web_view,
 
   /* If WebKit can't handle the mime type start the download
      process */
+  should_download = !webkit_web_view_can_show_mime_type (web_view, mime_type);
+
+  /* Make sure we respect the Content-Disposition header */
+  if (!should_download) {
+    WebKitNetworkResponse *response = webkit_web_frame_get_network_response (frame);
+    SoupMessage *message = NULL;
+
+    if (response) {
+      message = webkit_network_response_get_message (response);
+    }
+
+    if (message) {
+      char *disposition = NULL;
+
+      soup_message_headers_get_content_disposition (message->response_headers,
+                                                    &disposition,
+                                                    NULL);
+
+      if (disposition) {
+        should_download = g_str_equal (disposition, "attachment");
+        g_free (disposition);
+      }
+    }
+
+    g_object_unref (response);
+  }
+
   /* FIXME: need to use ephy_file_check_mime if auto-downloading */
-  if (!webkit_web_view_can_show_mime_type (web_view, mime_type)) {
+  if (should_download) {
     GObject *single;
     const char *uri;
     gboolean handled = FALSE;



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