[epiphany] downloads: Prefer the content type returned by the server
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] downloads: Prefer the content type returned by the server
- Date: Wed, 8 Jan 2014 11:58:11 +0000 (UTC)
commit b8347fa31225f200cd1f6ae1a0ab48a68e6819d8
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Wed Jan 8 12:46:54 2014 +0100
downloads: Prefer the content type returned by the server
Instead of using the destination file. g_file_query_info() does
synchronous I/O, so use it only as fallback when the server response
doesn't include a content type header.
https://bugzilla.gnome.org/show_bug.cgi?id=721781
embed/ephy-download.c | 57 +++++++++++++++++++++++-------------------------
1 files changed, 27 insertions(+), 30 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 355834d..77e4e8f 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -138,9 +138,8 @@ ephy_download_set_property (GObject *object,
* ephy_download_get_content_type:
* @download: an #EphyDownload
*
- * Gets content-type information for @download. If the file is already
- * present on the filesystem and readable, uses GIO to get the
- * content-type. Otherwise it uses WebKit and Soup.
+ * Gets content-type information for @download. If the server didn't
+ * provide a content type, the destination file is queried.
*
* Returns: content-type for @download, must be freed with g_free()
**/
@@ -148,40 +147,38 @@ char *
ephy_download_get_content_type (EphyDownload *download)
{
WebKitURIResponse *response;
+ GFile *destination;
+ GFileInfo *info;
char *content_type = NULL;
GError *error = NULL;
- if (download->priv->destination) {
- GFile *destination;
- GFileInfo *info;
-
- destination = g_file_new_for_uri (download->priv->destination);
- info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- G_FILE_QUERY_INFO_NONE, NULL, &error);
- if (info) {
- content_type = g_strdup (g_file_info_get_content_type (info));
- LOG ("ephy_download_get_content_type: GIO: %s", content_type);
- g_object_unref (info);
- } else {
- LOG ("ephy_download_get_content_type: error getting file "
- "content-type: %s", error->message);
- g_error_free (error);
- }
+ response = webkit_download_get_response (download->priv->download);
+ if (response) {
+ content_type = g_strdup (webkit_uri_response_get_mime_type (response));
- g_object_unref (destination);
- }
+ LOG ("ephy_download_get_content_type: WebKit: %s", content_type);
- if (content_type)
- return content_type;
+ if (content_type)
+ return content_type;
+ }
- /* Fallback to Soup */
- response = webkit_download_get_response (download->priv->download);
- if (response)
- content_type = g_strdup (webkit_uri_response_get_mime_type (response));
+ if (!download->priv->destination)
+ return NULL;
- LOG ("ephy_download_get_content_type: Soup: %s", content_type);
+ destination = g_file_new_for_uri (download->priv->destination);
+ info = g_file_query_info (destination, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (info) {
+ content_type = g_strdup (g_file_info_get_content_type (info));
+ LOG ("ephy_download_get_content_type: GIO: %s", content_type);
+ g_object_unref (info);
+ } else {
+ LOG ("ephy_download_get_content_type: error getting file "
+ "content-type: %s", error->message);
+ g_error_free (error);
+ }
- LOG ("ephy_download_get_content_type: %s", content_type);
+ g_object_unref (destination);
return content_type;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]