summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/web-view.c38
-rw-r--r--src/web-view.h3
2 files changed, 41 insertions, 0 deletions
diff --git a/src/web-view.c b/src/web-view.c
index e677b9d..838fdcf 100644
--- a/src/web-view.c
+++ b/src/web-view.c
@@ -44,11 +44,14 @@ struct _MqWebView {
WebKitHitTestResult *mouse_target_hit_test_result;
GtkComboBox *save_type_combo_box;
GFile *save_file;
+ guchar *data;
+ gsize data_length;
};
enum {
PROP_TAB_PAGE = 1,
PROP_DISPLAY_URI,
+ PROP_DATA,
N_PROPERTIES
};
@@ -262,6 +265,10 @@ get_property(GObject *object, guint property_id, GValue *value,
case PROP_DISPLAY_URI:
g_value_set_string(value, web_view->uri);
break;
+ case PROP_DATA:
+ g_value_set_pointer(value,
+ mq_web_view_get_data(web_view, NULL));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
param_spec);
@@ -317,6 +324,12 @@ mq_web_view_class_init(MqWebViewClass *klass)
"",
G_PARAM_READWRITE |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
+ obj_properties[PROP_DATA] = g_param_spec_pointer(
+ "data",
+ "Resource data",
+ "The main resource's data",
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
g_object_class_install_properties(object_class, N_PROPERTIES,
obj_properties);
}
@@ -399,6 +412,31 @@ mq_web_view_load_uri(MqWebView *web_view, const gchar *uri)
obj_properties[PROP_DISPLAY_URI]);
}
+static void
+get_data_cb(WebKitWebResource *resource, GAsyncResult *result,
+ MqWebView *web_view)
+{
+ web_view->data = webkit_web_resource_get_data_finish(resource, result,
+ &web_view->data_length, NULL); /* TODO: Error handling? */
+
+ g_object_notify_by_pspec(G_OBJECT(web_view),
+ obj_properties[PROP_DATA]);
+}
+
+guchar *
+mq_web_view_get_data(MqWebView *web_view, gsize *length)
+{
+ if (!web_view->data) {
+ webkit_web_resource_get_data(webkit_web_view_get_main_resource(
+ WEBKIT_WEB_VIEW(web_view)),
+ NULL, (GAsyncReadyCallback) get_data_cb, web_view);
+ }
+ if (length) {
+ *length = web_view->data_length;
+ }
+ return web_view->data;
+}
+
void
mq_web_view_zoom_in(MqWebView *web_view)
{
diff --git a/src/web-view.h b/src/web-view.h
index 9bb8977..dc78a24 100644
--- a/src/web-view.h
+++ b/src/web-view.h
@@ -67,6 +67,9 @@ mq_web_view_get_uri(MqWebView *web_view);
void
mq_web_view_load_uri(MqWebView *web_view, const gchar *uri);
+guchar *
+mq_web_view_get_data(MqWebView *web_view, gsize *length);
+
void
mq_web_view_zoom_in(MqWebView *web_view);