summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2004-01-24 17:08:16 +0000
committerJames Bursa <james@netsurf-browser.org>2004-01-24 17:08:16 +0000
commit1bdcb446392b9fd67d45df22d360dd72d7c353cc (patch)
tree5a23f86b3ee9b77728dbe4cde6915d54bbed2cc9 /render
parentb116f20cd4d75f539164a0e858272145d99e4e6d (diff)
downloadnetsurf-1bdcb446392b9fd67d45df22d360dd72d7c353cc.tar.gz
netsurf-1bdcb446392b9fd67d45df22d360dd72d7c353cc.tar.bz2
[project @ 2004-01-24 17:08:15 by bursa]
Add permitted_types to html_fetch_object(). svn path=/import/netsurf/; revision=500
Diffstat (limited to 'render')
-rw-r--r--render/box.c15
-rw-r--r--render/html.c50
-rw-r--r--render/html.h7
3 files changed, 58 insertions, 14 deletions
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,