summaryrefslogtreecommitdiff
path: root/embed
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2020-07-04 17:20:59 +0200
committerMichael Catanzaro <mcatanzaro@gnome.org>2020-07-05 01:53:07 +0000
commit5f2185b6b9e29bc12a7f98ade1740646e1df5ecf (patch)
tree6612d7046c088297b80f3fdd75219ba376a5dab7 /embed
parentfdd243c1d3661bf7e556286074e747e76b364007 (diff)
downloadepiphany-5f2185b6b9e29bc12a7f98ade1740646e1df5ecf.tar.gz
ephy-pdf-handler: Use server suggested filename for download
Remove decide-destination from internal downloads as their purpose is to change the destination on their own and not let the user/webkit decide where to store the download. In turn PDF handler registers it's own decide-destination handler to retrieve the correct server suggested filename. Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1235
Diffstat (limited to 'embed')
-rw-r--r--embed/ephy-download.c7
-rw-r--r--embed/ephy-pdf-handler.c26
2 files changed, 17 insertions, 16 deletions
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 2a451bb51..926fa6555 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -886,9 +886,6 @@ ephy_download_new_internal (WebKitDownload *download)
g_signal_connect_object (download, "notify::response",
G_CALLBACK (download_response_changed_cb),
ephy_download, 0);
- g_signal_connect_object (download, "decide-destination",
- G_CALLBACK (download_decide_destination_cb),
- ephy_download, 0);
g_signal_connect_object (download, "created-destination",
G_CALLBACK (download_created_destination_cb),
ephy_download, 0);
@@ -920,6 +917,10 @@ ephy_download_new (WebKitDownload *download)
ephy_download = ephy_download_new_internal (download);
+ g_signal_connect_object (download, "decide-destination",
+ G_CALLBACK (download_decide_destination_cb),
+ ephy_download, 0);
+
if (!ephy_is_running_inside_flatpak () && g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ASK_ON_DOWNLOAD)) {
g_signal_connect (ephy_download, "filename-suggested",
G_CALLBACK (filename_suggested_cb),
diff --git a/embed/ephy-pdf-handler.c b/embed/ephy-pdf-handler.c
index 995b1934d..56ab04a1f 100644
--- a/embed/ephy-pdf-handler.c
+++ b/embed/ephy-pdf-handler.c
@@ -192,25 +192,29 @@ download_errored_cb (EphyDownload *download,
g_clear_object (&self->download);
}
-static void
-created_destination_cb (WebKitDownload *download,
- gchar *destination,
- gpointer user_data)
+static gboolean
+decide_destination_cb (WebKitDownload *wk_download,
+ const gchar *suggested_filename,
+ gpointer user_data)
{
EphyPdfRequest *request = user_data;
+ g_autofree gchar *tmp_file = NULL;
+ g_autofree gchar *file_uri = NULL;
- g_signal_handlers_disconnect_by_data (download, request);
+ tmp_file = g_strdup_printf ("%s/%s", g_get_tmp_dir (), g_path_get_basename (suggested_filename));
+ file_uri = g_filename_to_uri (tmp_file, NULL, NULL);
+ ephy_download_set_destination_uri (request->download, file_uri);
g_clear_pointer (&request->file_name, g_free);
- request->file_name = g_path_get_basename (destination);
+ request->file_name = g_path_get_basename (suggested_filename);
+
+ return TRUE;
}
static void
ephy_pdf_request_start (EphyPdfRequest *request)
{
g_autoptr (SoupURI) soup_uri = NULL;
- g_autofree gchar *tmp_file = NULL;
- g_autofree gchar *file_uri = NULL;
const char *modified_uri;
const char *original_uri;
@@ -234,17 +238,13 @@ ephy_pdf_request_start (EphyPdfRequest *request)
modified_uri = soup_uri_get_path (soup_uri);
g_assert (modified_uri);
- tmp_file = g_strdup_printf ("%s/%s", g_get_tmp_dir (), g_path_get_basename (modified_uri));
- file_uri = g_filename_to_uri (tmp_file, NULL, NULL);
-
request->download = ephy_download_new_for_uri_internal (modified_uri);
- ephy_download_set_destination_uri (request->download, file_uri);
ephy_download_disable_desktop_notification (request->download);
webkit_download_set_allow_overwrite (ephy_download_get_webkit_download (request->download), TRUE);
g_signal_connect (request->download, "completed", G_CALLBACK (download_completed_cb), request);
g_signal_connect (request->download, "error", G_CALLBACK (download_errored_cb), request);
- g_signal_connect (ephy_download_get_webkit_download (request->download), "created-destination", G_CALLBACK (created_destination_cb), request);
+ g_signal_connect (ephy_download_get_webkit_download (request->download), "decide-destination", G_CALLBACK (decide_destination_cb), request);
}
static void