diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2012-06-22 17:03:36 +0800 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2012-06-27 20:16:00 +0800 |
commit | 7e1964acdacd4bdf4e23e85ec733fe9e92688ca6 (patch) | |
tree | 6acf7bf26c7b8ddf0e4a5161122fccc3c2cd46c2 /src | |
parent | 39931fc51a3a668d04f938fa555bdf9a4abf3056 (diff) | |
download | gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar.gz gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.tar.zst gsoc2013-epiphany-7e1964acdacd4bdf4e23e85ec733fe9e92688ca6.zip |
Port downloads to WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=678612
Diffstat (limited to 'src')
-rw-r--r-- | src/ephy-shell.c | 31 | ||||
-rw-r--r-- | src/window-commands.c | 41 |
2 files changed, 68 insertions, 4 deletions
diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 07a646eb3..56c524dd3 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -544,6 +544,31 @@ impl_get_embed_single (EphyEmbedShell *embed_shell) return embed_single; } +#ifdef HAVE_WEBKIT2 +static void +download_started_cb (WebKitWebContext *web_context, + WebKitDownload *download, + EphyShell *shell) +{ + EphyDownload *ed; + EphySession *session; + EphyWindow *window; + + /* Is download locked down? */ + if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, + EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK)) { + webkit_download_cancel (download); + return; + } + + session = EPHY_SESSION (ephy_shell_get_session (shell)); + window = ephy_session_get_active_window (session); + + ed = ephy_download_new_for_download (download); + ephy_download_set_window (ed, GTK_WIDGET (window)); +} +#endif + static void ephy_shell_init (EphyShell *shell) { @@ -556,6 +581,12 @@ ephy_shell_init (EphyShell *shell) ephy_shell = shell; g_object_add_weak_pointer (G_OBJECT (ephy_shell), (gpointer *)ptr); + +#ifdef HAVE_WEBKIT2 + g_signal_connect (webkit_web_context_get_default (), "download-started", + G_CALLBACK (download_started_cb), + shell); +#endif } static void diff --git a/src/window-commands.c b/src/window-commands.c index 39432bd18..3a0c43b6f 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -380,7 +380,26 @@ take_page_snapshot_and_set_image (EphyApplicationDialogData *data) } #ifdef HAVE_WEBKIT2 -/* TODO: Downloads */ +static void +download_finished_cb (WebKitDownload *download, + EphyApplicationDialogData *data) +{ + char *filename; + + filename = g_filename_from_uri (webkit_download_get_destination (download), NULL, NULL); + gtk_image_set_from_file (GTK_IMAGE (data->image), filename); + g_free (filename); +} + +static void +download_failed_cb (WebKitDownload *download, + GError *error, + EphyApplicationDialogData *data) +{ + g_signal_handlers_disconnect_by_func (download, download_finished_cb, data); + /* Something happened, default to a page snapshot. */ + take_page_snapshot_and_set_image (data); +} #else static void download_status_changed_cb (WebKitDownload *download, @@ -412,25 +431,39 @@ download_status_changed_cb (WebKitDownload *download, static void download_icon_and_set_image (EphyApplicationDialogData *data) { -#ifdef HAVE_WEBKIT2 - /* TODO: Downloads */ -#else +#ifndef HAVE_WEBKIT2 WebKitNetworkRequest *request; +#endif WebKitDownload *download; char *destination, *destination_uri, *tmp_filename; +#ifdef HAVE_WEBKIT2 + download = webkit_web_context_download_uri (webkit_web_context_get_default (), + data->icon_href); +#else request = webkit_network_request_new (data->icon_href); download = webkit_download_new (request); g_object_unref (request); +#endif tmp_filename = ephy_file_tmp_filename ("ephy-download-XXXXXX", NULL); destination = g_build_filename (ephy_file_tmp_dir (), tmp_filename, NULL); destination_uri = g_filename_to_uri (destination, NULL, NULL); +#ifdef HAVE_WEBKIT2 + webkit_download_set_destination (download, destination_uri); +#else webkit_download_set_destination_uri (download, destination_uri); +#endif g_free (destination); g_free (destination_uri); g_free (tmp_filename); +#ifdef HAVE_WEBKIT2 + g_signal_connect (download, "finished", + G_CALLBACK (download_finished_cb), data); + g_signal_connect (download, "failed", + G_CALLBACK (download_failed_cb), data); +#else g_signal_connect (download, "notify::status", G_CALLBACK (download_status_changed_cb), data); |