From e9d80d39ad48993df7140269ace8ce0cf4ac4585 Mon Sep 17 00:00:00 2001 From: Gustavo Noronha Silva Date: Tue, 8 Sep 2009 16:08:26 -0300 Subject: Delay obtaining suggested filename for dialogs Most downloads will only have proper suggested filenames after the request has been sent, and a reply was received, so delay getting the suggested filename to when that has happened. Bug #577797 --- embed/ephy-embed.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'embed') diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 98c6d089c..dec2a3251 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -711,6 +711,34 @@ confirm_action_from_mime (WebKitWebView *web_view, gtk_window_present (GTK_WINDOW (dialog)); } +static void +download_status_changed_cb (GObject *object, + GParamSpec *pspec, + WebKitWebView *web_view) +{ + WebKitDownload *download = WEBKIT_DOWNLOAD (object); + + g_return_if_fail (webkit_download_get_status (download) == WEBKIT_DOWNLOAD_STATUS_STARTED); + + g_signal_handlers_disconnect_by_func (download, + download_status_changed_cb, + web_view); + + /* Is auto-download enabled? */ + if (eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS)) { + perform_auto_download (download); + 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); +} + static gboolean download_requested_cb (WebKitWebView *web_view, WebKitDownload *download) @@ -719,11 +747,11 @@ download_requested_cb (WebKitWebView *web_view, if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) return FALSE; - /* Is auto-download enabled? */ - if (eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS)) { - perform_auto_download (download); - return TRUE; - } + /* Wait for the request to be sent in all cases, so that we have a + * response which may contain a suggested filename */ + g_signal_connect (download, "notify::status", + G_CALLBACK (download_status_changed_cb), + web_view); /* If we are not performing an auto-download, we will ask the user * where they want the file to go to; we will start downloading to a @@ -732,14 +760,6 @@ download_requested_cb (WebKitWebView *web_view, if (!define_destination_uri (download, TRUE)) return FALSE; - /* 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); - return TRUE; } -- cgit v1.2.3