aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-06-05 15:15:03 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-06-14 19:45:02 +0800
commit25c4b47c0630b758fd97a86d9c9b3944d193fe1d (patch)
tree308550092011f0ff4ae9ff35ef8693ff49438f3e
parent2b5cfe828cef29dd20225540fdd2bf5fcbf6b8fc (diff)
downloadgsoc2013-epiphany-25c4b47c0630b758fd97a86d9c9b3944d193fe1d.tar.gz
gsoc2013-epiphany-25c4b47c0630b758fd97a86d9c9b3944d193fe1d.tar.zst
gsoc2013-epiphany-25c4b47c0630b758fd97a86d9c9b3944d193fe1d.zip
ephy-download: Simplify decide_action_from_mime
Remove unused variables and fix memory leaks https://bugzilla.gnome.org/show_bug.cgi?id=676484
-rw-r--r--embed/ephy-download.c45
1 files changed, 16 insertions, 29 deletions
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index ceab3339c..85c03b231 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -194,47 +194,34 @@ ephy_download_get_content_type (EphyDownload *download)
return content_type;
}
+
+/* Helper function to decide what EphyDownloadActionType should be the
+ * default for the download. This implies that you want something to
+ * happen, this function will never return EPHY_DOWNLOAD_ACTION_NONE.
+ */
static EphyDownloadActionType
decide_action_from_mime (EphyDownload *ephy_download)
{
- WebKitNetworkResponse *response;
- SoupMessage *message;
- char *mime_description = NULL;
+ char *content_type;
GAppInfo *helper_app = NULL;
EphyDownloadActionType action;
- WebKitDownload *download;
-
- download = ephy_download_get_webkit_download (ephy_download);
-
- response = webkit_download_get_network_response (download);
- message = webkit_network_response_get_message (response);
- if (message) {
- char *content_type = ephy_download_get_content_type (ephy_download);
+ content_type = ephy_download_get_content_type (ephy_download);
+ if (content_type) {
+ helper_app = g_app_info_get_default_for_type (content_type, FALSE);
+ if (helper_app)
+ action = EPHY_DOWNLOAD_ACTION_OPEN;
- 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 = EPHY_DOWNLOAD_ACTION_OPEN;
-
- g_free (content_type);
- }
- }
-
- if (mime_description == NULL) {
- mime_description = g_strdup (C_("file type", "Unknown"));
- action = EPHY_DOWNLOAD_ACTION_BROWSE_TO;
+ g_free (content_type);
}
- /* Sometimes downloads can have a mime_description but a NULL helper_app
- * in that case action is never changed so DOWNLOAD_ACTION_DOWNLOAD remains
- * as action value. This is the same response value as Save as...
- * button, which is wrong for the Download button.
+ /* Downloads that have no content_type, or no helper_app, are
+ * considered unsafe/unable to open. Default them to BROWSE_TO.
*/
if (helper_app == NULL)
action = EPHY_DOWNLOAD_ACTION_BROWSE_TO;
+ else
+ g_object_unref (helper_app);
return action;
}