aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-08-16 16:46:42 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-08-17 19:58:51 +0800
commitcf9c1a366b1424ee55e621302c5cba02803832a8 (patch)
treeb9ea2e48243f6e18728e43501f1027f24b522f5e /embed
parent12b8cab14f3cb4c09e5ee8afb9b438113b5bd72e (diff)
downloadgsoc2013-epiphany-cf9c1a366b1424ee55e621302c5cba02803832a8.tar
gsoc2013-epiphany-cf9c1a366b1424ee55e621302c5cba02803832a8.tar.gz
gsoc2013-epiphany-cf9c1a366b1424ee55e621302c5cba02803832a8.tar.bz2
gsoc2013-epiphany-cf9c1a366b1424ee55e621302c5cba02803832a8.tar.lz
gsoc2013-epiphany-cf9c1a366b1424ee55e621302c5cba02803832a8.tar.xz
gsoc2013-epiphany-cf9c1a366b1424ee55e621302c5cba02803832a8.tar.zst
gsoc2013-epiphany-cf9c1a366b1424ee55e621302c5cba02803832a8.zip
Port save as to WebKit2
Use webkit_web_view_save() API for HTML pages that saves the web page into a MHTML file. For any other MIME types supported by the web view, save the main resource data to a file. https://bugzilla.gnome.org/show_bug.cgi?id=679368
Diffstat (limited to 'embed')
-rw-r--r--embed/ephy-web-view.c73
1 files changed, 68 insertions, 5 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 5caa27a58..ae99cf137 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -3749,7 +3749,56 @@ ephy_web_view_get_title_composite (EphyWebView *view)
}
#ifdef HAVE_WEBKIT2
-/* TODO: webkit_web_view_save() */
+static void
+web_resource_get_data_cb (WebKitWebResource *resource,
+ GAsyncResult *result,
+ GOutputStream *output_stream)
+{
+ guchar *data;
+ gsize data_length;
+ GInputStream *input_stream;
+ GError *error = NULL;
+
+ data = webkit_web_resource_get_data_finish (resource, result, &data_length, &error);
+ if (!data) {
+ g_printerr ("Failed to save page: %s", error->message);
+ g_error_free (error);
+ g_object_unref (output_stream);
+
+ return;
+ }
+
+ input_stream = g_memory_input_stream_new_from_data (data, data_length, g_free);
+ g_output_stream_splice_async (output_stream, input_stream,
+ G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+ G_PRIORITY_DEFAULT,
+ NULL, NULL, NULL);
+ g_object_unref (input_stream);
+ g_object_unref (output_stream);
+}
+
+static void
+ephy_web_view_save_main_resource_cb (GFile *file,
+ GAsyncResult *result,
+ WebKitWebView *view)
+{
+ GFileOutputStream *output_stream;
+ WebKitWebResource *resource;
+ GError *error = NULL;
+
+ output_stream = g_file_replace_finish (file, result, &error);
+ if (!output_stream) {
+ g_printerr ("Failed to save page: %s", error->message);
+ g_error_free (error);
+
+ return;
+ }
+
+ resource = webkit_web_view_get_main_resource (view);
+ webkit_web_resource_get_data (resource, NULL,
+ (GAsyncReadyCallback)web_resource_get_data_cb,
+ output_stream);
+}
#else
static void
ephy_web_view_save_sub_resource_start (GList *subresources, char *destination_uri);
@@ -3972,6 +4021,7 @@ ephy_web_view_save_sub_resources (EphyWebView *view, const char *uri, GList *sub
ephy_web_view_save_sub_resource_start (subresources, destination_uri);
}
#endif
+
/**
* ephy_web_view_save:
* @view: an #EphyWebView
@@ -3982,15 +4032,28 @@ ephy_web_view_save_sub_resources (EphyWebView *view, const char *uri, GList *sub
void
ephy_web_view_save (EphyWebView *view, const char *uri)
{
-#ifdef HAVE_WEBKIT2
- /* TODO: webkit_web_view_save() */
-#else
+ GFile *file;
+#ifndef HAVE_WEBKIT2
WebKitWebFrame *frame;
WebKitWebDataSource *data_source;
GList *subresources;
const GString *data;
- GFile *file;
+#endif
+
+ file = g_file_new_for_uri (uri);
+#ifdef HAVE_WEBKIT2
+ if (g_str_has_suffix (uri, ".mhtml"))
+ webkit_web_view_save_to_file (WEBKIT_WEB_VIEW (view), file, WEBKIT_SAVE_MODE_MHTML,
+ NULL, NULL, NULL);
+ else
+ g_file_replace_async (file, NULL, FALSE,
+ G_FILE_CREATE_REPLACE_DESTINATION | G_FILE_CREATE_PRIVATE,
+ G_PRIORITY_DEFAULT, NULL,
+ (GAsyncReadyCallback)ephy_web_view_save_main_resource_cb,
+ view);
+ g_object_unref (file);
+#else
/* Save main resource */
frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW(view));
data_source = webkit_web_frame_get_data_source (frame);