[epiphany] ephy-download: Simplify decide_action_from_mime
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] ephy-download: Simplify decide_action_from_mime
- Date: Thu, 14 Jun 2012 11:45:32 +0000 (UTC)
commit 25c4b47c0630b758fd97a86d9c9b3944d193fe1d
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Tue Jun 5 09:15:03 2012 +0200
ephy-download: Simplify decide_action_from_mime
Remove unused variables and fix memory leaks
https://bugzilla.gnome.org/show_bug.cgi?id=676484
embed/ephy-download.c | 45 ++++++++++++++++-----------------------------
1 files changed, 16 insertions(+), 29 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index ceab333..85c03b2 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]