summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/content.c6
-rw-r--r--content/content.h33
-rw-r--r--content/content_type.h51
-rw-r--r--render/box.c15
-rw-r--r--render/html.c50
-rw-r--r--render/html.h7
6 files changed, 112 insertions, 50 deletions
diff --git a/content/content.c b/content/content.c
index 61b8cd1c9..927269441 100644
--- a/content/content.c
+++ b/content/content.c
@@ -109,15 +109,13 @@ static const struct handler_entry handler_map[] = {
html_add_instance, html_remove_instance, html_reshape_instance},
{textplain_create, textplain_process_data, textplain_convert,
textplain_revive, textplain_reformat, textplain_destroy, 0, 0, 0, 0},
+ {css_create, css_process_data, css_convert, css_revive,
+ css_reformat, css_destroy, 0, 0, 0, 0},
#ifdef riscos
#ifdef WITH_JPEG
{jpeg_create, jpeg_process_data, jpeg_convert, jpeg_revive,
jpeg_reformat, jpeg_destroy, jpeg_redraw, 0, 0, 0},
#endif
-#endif
- {css_create, css_process_data, css_convert, css_revive,
- css_reformat, css_destroy, 0, 0, 0, 0},
-#ifdef riscos
#ifdef WITH_PNG
{nspng_create, nspng_process_data, nspng_convert, nspng_revive,
nspng_reformat, nspng_destroy, nspng_redraw, 0, 0, 0},
diff --git a/content/content.h b/content/content.h
index d5adf1a6f..7235011a4 100644
--- a/content/content.h
+++ b/content/content.h
@@ -28,6 +28,7 @@
#include "libxml/HTMLparser.h"
#include "netsurf/utils/config.h"
#include "netsurf/content/cache.h"
+#include "netsurf/content/content_type.h"
#include "netsurf/content/fetch.h"
#include "netsurf/content/other.h"
#include "netsurf/css/css.h"
@@ -56,38 +57,6 @@
#endif
-/** The type of a content. */
-typedef enum {
- CONTENT_HTML,
- CONTENT_TEXTPLAIN,
-#ifdef riscos
-#ifdef WITH_JPEG
- CONTENT_JPEG,
-#endif
-#endif
- CONTENT_CSS,
-#ifdef riscos
-#ifdef WITH_PNG
- CONTENT_PNG,
-#endif
-#ifdef WITH_GIF
- CONTENT_GIF,
-#endif
-#ifdef WITH_SPRITE
- CONTENT_SPRITE,
-#endif
-#ifdef WITH_DRAW
- CONTENT_DRAW,
-#endif
-#ifdef WITH_PLUGIN
- CONTENT_PLUGIN,
-#endif
-#endif
- CONTENT_OTHER,
- CONTENT_UNKNOWN /**< content-type not received yet */
-} content_type;
-
-
/** Used in callbacks to indicate what has occurred. */
typedef enum {
CONTENT_MSG_LOADING, /**< fetching or converting */
diff --git a/content/content_type.h b/content/content_type.h
new file mode 100644
index 000000000..fbafe9e6b
--- /dev/null
+++ b/content/content_type.h
@@ -0,0 +1,51 @@
+/*
+ * This file is part of NetSurf, http://netsurf.sourceforge.net/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
+ */
+
+/** \file
+ * Declaration of content_type enum.
+ *
+ * The content_type enum is defined here to prevent cyclic dependencies.
+ */
+
+#ifndef _NETSURF_DESKTOP_CONTENT_TYPE_H_
+#define _NETSURF_DESKTOP_CONTENT_TYPE_H_
+
+#include "netsurf/utils/config.h"
+
+
+/** The type of a content. */
+typedef enum {
+ CONTENT_HTML,
+ CONTENT_TEXTPLAIN,
+ CONTENT_CSS,
+#ifdef riscos
+#ifdef WITH_JPEG
+ CONTENT_JPEG,
+#endif
+#ifdef WITH_PNG
+ CONTENT_PNG,
+#endif
+#ifdef WITH_GIF
+ CONTENT_GIF,
+#endif
+#ifdef WITH_SPRITE
+ CONTENT_SPRITE,
+#endif
+#ifdef WITH_DRAW
+ CONTENT_DRAW,
+#endif
+#ifdef WITH_PLUGIN
+ CONTENT_PLUGIN,
+#endif
+#endif
+ /* these must be the last two */
+ CONTENT_OTHER,
+ CONTENT_UNKNOWN /**< content-type not received yet */
+} content_type;
+
+
+#endif
diff --git a/render/box.c b/render/box.c
index 11fa0b07e..63747004b 100644
--- a/render/box.c
+++ b/render/box.c
@@ -676,7 +676,7 @@ struct css_style * box_get_style(struct content ** stylesheet,
}
-/**
+/*
* Special case elements
*
* These functions are called by convert_xml_to_box when an element is being
@@ -714,6 +714,12 @@ struct result box_body(xmlNode *n, struct status *status,
return (struct result) {box, 1};
}
+static const content_type image_types[] = {
+#ifdef riscos
+ CONTENT_JPEG, CONTENT_PNG, CONTENT_GIF, CONTENT_SPRITE, CONTENT_DRAW,
+#endif
+ CONTENT_UNKNOWN };
+
struct result box_image(xmlNode *n, struct status *status,
struct css_style *style)
{
@@ -747,7 +753,7 @@ struct result box_image(xmlNode *n, struct status *status,
xmlFree(s);
/* start fetch */
- html_fetch_object(status->content, url, box);
+ html_fetch_object(status->content, url, box, image_types);
return (struct result) {box, 0};
}
@@ -1062,7 +1068,8 @@ struct result box_input(xmlNode *n, struct status *status,
if ((s = (char *) xmlGetProp(n, (const xmlChar*) "src"))) {
url = url_join(s, status->content->data.html.base_url);
if (url)
- html_fetch_object(status->content, url, box);
+ html_fetch_object(status->content, url, box,
+ image_types);
xmlFree(s);
}
}
@@ -2158,7 +2165,7 @@ bool plugin_decode(struct content* content, char* url, struct box* box,
* when we fetch it (if the type was not specified or is different to that
* given in the attributes).
*/
- html_fetch_object(content, url, box);
+ html_fetch_object(content, url, box, 0);
return true;
}
diff --git a/render/html.c b/render/html.c
index 9e447e4ae..476c8b6f2 100644
--- a/render/html.c
+++ b/render/html.c
@@ -28,6 +28,8 @@ static void html_head(struct content *c, xmlNode *head);
static void html_find_stylesheets(struct content *c, xmlNode *head);
static void html_object_callback(content_msg msg, struct content *object,
void *p1, void *p2, const char *error);
+static bool html_object_type_permitted(const content_type type,
+ const content_type *permitted_types);
void html_create(struct content *c, const char *params[])
@@ -427,7 +429,8 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
}
-void html_fetch_object(struct content *c, char *url, struct box *box)
+void html_fetch_object(struct content *c, char *url, struct box *box,
+ const content_type *permitted_types)
{
unsigned int i = c->data.html.object_count;
@@ -436,6 +439,7 @@ void html_fetch_object(struct content *c, char *url, struct box *box)
(i + 1) * sizeof(*c->data.html.object));
c->data.html.object[i].url = url;
c->data.html.object[i].box = box;
+ c->data.html.object[i].permitted_types = permitted_types;
/* start fetch */
c->data.html.object[i].content = fetchcache(url, c->url,
@@ -467,16 +471,21 @@ void html_object_callback(content_msg msg, struct content *object,
struct content *c = p1;
unsigned int i = (unsigned int) p2;
struct box *box = c->data.html.object[i].box;
+
switch (msg) {
case CONTENT_MSG_LOADING:
- if (CONTENT_OTHER <= c->type) {
- c->data.html.object[i].content = 0;
- c->active--;
- c->error = 1;
- sprintf(c->status_message, "Warning: bad object type");
- content_broadcast(c, CONTENT_MSG_STATUS, 0);
- content_remove_user(object, html_object_callback, c, (void*)i);
- }
+ /* check if the type is acceptable for this object */
+ if (html_object_type_permitted(object->type,
+ c->data.html.object[i].permitted_types))
+ break;
+
+ /* not acceptable */
+ c->data.html.object[i].content = 0;
+ c->active--;
+ c->error = 1;
+ sprintf(c->status_message, "Warning: bad object type");
+ content_broadcast(c, CONTENT_MSG_STATUS, 0);
+ content_remove_user(object, html_object_callback, c, (void*)i);
break;
case CONTENT_MSG_READY:
@@ -582,6 +591,29 @@ void html_object_callback(content_msg msg, struct content *object,
}
+/**
+ * Check if a type is in a list.
+ *
+ * \param type the content_type to search for
+ * \param permitted_types array of types, terminated by CONTENT_UNKNOWN,
+ * or 0 if all types except OTHER and UNKNOWN acceptable
+ * \return the type is in the list or acceptable
+ */
+
+bool html_object_type_permitted(const content_type type,
+ const content_type *permitted_types)
+{
+ if (permitted_types) {
+ for (; *permitted_types != CONTENT_UNKNOWN; permitted_types++)
+ if (*permitted_types == type)
+ return true;
+ } else if (type < CONTENT_OTHER) {
+ return true;
+ }
+ return false;
+}
+
+
void html_revive(struct content *c, unsigned int width, unsigned int height)
{
unsigned int i;
diff --git a/render/html.h b/render/html.h
index 33385a78d..f57f36ca5 100644
--- a/render/html.h
+++ b/render/html.h
@@ -8,6 +8,7 @@
#ifndef _NETSURF_RENDER_HTML_H_
#define _NETSURF_RENDER_HTML_H_
+#include "netsurf/content/content_type.h"
#include "netsurf/css/css.h"
#include "netsurf/render/box.h"
#include "netsurf/utils/pool.h"
@@ -49,6 +50,9 @@ struct content_html_data {
char *url;
struct content *content;
struct box *box;
+ /** Pointer to array of permitted content_type, terminated by
+ * CONTENT_UNKNOWN, or 0 if any type is acceptable. */
+ const content_type *permitted_types;
} *object;
pool box_pool; /**< Memory pool for box tree. */
pool string_pool; /**< Memory pool for strings. */
@@ -60,7 +64,8 @@ int html_convert(struct content *c, unsigned int width, unsigned int height);
void html_revive(struct content *c, unsigned int width, unsigned int height);
void html_reformat(struct content *c, unsigned int width, unsigned int height);
void html_destroy(struct content *c);
-void html_fetch_object(struct content *c, char *url, struct box *box);
+void html_fetch_object(struct content *c, char *url, struct box *box,
+ const content_type *permitted_types);
/* in riscos/htmlinstance.c */
void html_add_instance(struct content *c, struct browser_window *bw,