summaryrefslogtreecommitdiff
path: root/content/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers')
-rw-r--r--content/handlers/image/svg.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/content/handlers/image/svg.c b/content/handlers/image/svg.c
index 94c485822..b81f510ef 100644
--- a/content/handlers/image/svg.c
+++ b/content/handlers/image/svg.c
@@ -27,11 +27,13 @@
#include <svgtiny.h>
+#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "netsurf/plotters.h"
#include "netsurf/content.h"
#include "content/content_protected.h"
+#include "content/hlcache.h"
#include "image/svg.h"
@@ -46,6 +48,57 @@ typedef struct svg_content {
+/** Callback for hlcache fetch */
+static nserror svg_fetch_hlcache_cb(hlcache_handle *handle,
+ const hlcache_event *event,
+ void *parser)
+{
+ switch (event->type) {
+ case CONTENT_MSG_DONE:
+ LOG("external entity '%s' retrieved", nsurl_access(hlcache_handle_get_url(handle)));
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG("external entity %s error: %s", nsurl_access(hlcache_handle_get_url(handle)), event->data.error);
+ hlcache_handle_release(handle);
+ break;
+
+ default:
+ break;
+ }
+
+ return NSERROR_OK;
+}
+
+/** Callback for libsvgtiny fetch */
+static int svg_fetch_cb(void *parser, const char *base, const char *uri)
+{
+ nsurl *x_ent;
+ nserror ret;
+ hlcache_handle *handle;
+
+ LOG("Fetching external entity reference %s", uri);
+
+ /* create url */
+ ret = nsurl_create(uri, &x_ent);
+ if (ret != NSERROR_OK) {
+ return false;
+ }
+
+ ret = hlcache_handle_retrieve(x_ent, 0, NULL, NULL,
+ svg_fetch_hlcache_cb,
+ parser, /* data */
+ NULL, CONTENT_ANY,
+ &handle);
+ nsurl_unref(x_ent);
+
+ if (ret != NSERROR_OK) {
+ return false;
+ }
+
+ return true;
+}
+
static nserror svg_create_svg_data(svg_content *c)
{
union content_msg_data msg_data;
@@ -139,7 +192,7 @@ static void svg_reformat(struct content *c, int width, int height)
svgtiny_parse(svg->diagram, source_data, source_size,
nsurl_access(content_get_url(c)),
- width, height);
+ width, height, svg_fetch_cb);
svg->current_width = width;
svg->current_height = height;