[project @ 2003-07-09 21:33:01 by bursa]

More work on <object> and plugins.

svn path=/import/netsurf/; revision=213
This commit is contained in:
James Bursa 2003-07-09 21:33:01 +00:00
parent 80013c7a71
commit 9317e33d0b
14 changed files with 252 additions and 270 deletions

View File

@ -28,10 +28,6 @@ struct mime_entry {
};
static const struct mime_entry mime_map[] = {
#ifdef riscos
{"application/java-vm", CONTENT_PLUGIN},
{"application/x-shockwave-flash", CONTENT_PLUGIN},
{"audio/midi", CONTENT_PLUGIN},
{"audio/x-midi", CONTENT_PLUGIN},
{"image/gif", CONTENT_GIF},
{"image/jpeg", CONTENT_JPEG},
{"image/png", CONTENT_PNG},
@ -52,27 +48,31 @@ struct handler_entry {
void (*destroy)(struct content *c);
void (*redraw)(struct content *c, long x, long y,
unsigned long width, unsigned long height);
void (*add_user)(struct content *c, struct object_params *params);
void (*remove_user)(struct content *c, struct object_params *params);
};
static const struct handler_entry handler_map[] = {
{html_create, html_process_data, html_convert, html_revive,
html_reformat, html_destroy, 0},
html_reformat, html_destroy, 0, 0, 0},
{textplain_create, textplain_process_data, textplain_convert,
textplain_revive, textplain_reformat, textplain_destroy, 0},
textplain_revive, textplain_reformat, textplain_destroy, 0, 0, 0},
#ifdef riscos
{jpeg_create, jpeg_process_data, jpeg_convert, jpeg_revive,
jpeg_reformat, jpeg_destroy, jpeg_redraw},
jpeg_reformat, jpeg_destroy, jpeg_redraw, 0, 0},
#endif
{css_create, css_process_data, css_convert, css_revive, css_reformat, css_destroy, 0},
{css_create, css_process_data, css_convert, css_revive,
css_reformat, css_destroy, 0, 0, 0},
#ifdef riscos
{nspng_create, nspng_process_data, nspng_convert, nspng_revive,
nspng_reformat, nspng_destroy, nspng_redraw},
nspng_reformat, nspng_destroy, nspng_redraw, 0, 0},
{nsgif_create, nsgif_process_data, nsgif_convert, nsgif_revive,
nsgif_reformat, nsgif_destroy, nsgif_redraw},
nsgif_reformat, nsgif_destroy, nsgif_redraw, 0, 0},
{plugin_create, plugin_process_data, plugin_convert, plugin_revive,
plugin_reformat, plugin_destroy, plugin_redraw},
plugin_reformat, plugin_destroy, plugin_redraw,
plugin_add_user, plugin_remove_user},
#endif
{other_create, other_process_data, other_convert, other_revive,
other_reformat, other_destroy, 0}
other_reformat, other_destroy, 0, 0, 0}
};
#define HANDLER_MAP_COUNT (sizeof(handler_map) / sizeof(handler_map[0]))
@ -86,8 +86,11 @@ content_type content_lookup(const char *mime_type)
struct mime_entry *m;
m = bsearch(mime_type, mime_map, MIME_MAP_COUNT, sizeof(mime_map[0]),
(int (*)(const void *, const void *)) strcmp);
if (m == 0)
if (m == 0) {
if (plugin_handleable(mime_type))
return CONTENT_PLUGIN;
return CONTENT_OTHER;
}
return m->type;
}
@ -126,6 +129,7 @@ void content_set_type(struct content *c, content_type type, char* mime_type)
assert(c->status == CONTENT_STATUS_TYPE_UNKNOWN);
assert(type < CONTENT_UNKNOWN);
LOG(("content %s, type %i", c->url, type));
/* TODO: call add_user on each existing user */
c->type = type;
c->mime_type = mime_type;
c->status = CONTENT_STATUS_LOADING;
@ -241,7 +245,7 @@ void content_redraw(struct content *c, long x, long y,
void content_add_user(struct content *c,
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, const char *error),
void *p1, void *p2)
void *p1, void *p2, struct object_params *params)
{
struct content_user *user;
LOG(("content %s, user %p %p %p", c->url, callback, p1, p2));
@ -251,6 +255,8 @@ void content_add_user(struct content *c,
user->p2 = p2;
user->next = c->user_list->next;
c->user_list->next = user;
if (c->type != CONTENT_UNKNOWN && handler_map[c->type].add_user != 0)
handler_map[c->type].add_user(c, params);
}
@ -261,11 +267,14 @@ void content_add_user(struct content *c,
void content_remove_user(struct content *c,
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, const char *error),
void *p1, void *p2)
void *p1, void *p2, struct object_params *params)
{
struct content_user *user, *next;
LOG(("content %s, user %p %p %p", c->url, callback, p1, p2));
if (c->type != CONTENT_UNKNOWN && handler_map[c->type].remove_user != 0)
handler_map[c->type].remove_user(c, params);
/* user_list starts with a sentinel */
for (user = c->user_list; user->next != 0 &&
!(user->next->callback == callback &&

View File

@ -201,11 +201,11 @@ void content_redraw(struct content *c, long x, long y,
void content_add_user(struct content *c,
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, const char *error),
void *p1, void *p2);
void *p1, void *p2, struct object_params *params);
void content_remove_user(struct content *c,
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, const char *error),
void *p1, void *p2);
void *p1, void *p2, struct object_params *params);
void content_broadcast(struct content *c, content_msg msg, char *error);
#endif

View File

@ -21,7 +21,8 @@ static void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned lon
struct content * fetchcache(const char *url0, char *referer,
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, const char *error),
void *p1, void *p2, unsigned long width, unsigned long height)
void *p1, void *p2, unsigned long width, unsigned long height,
struct object_params *object_params)
{
struct content *c;
char *url = xstrdup(url0);
@ -35,12 +36,12 @@ struct content * fetchcache(const char *url0, char *referer,
c = cache_get(url);
if (c != 0) {
content_add_user(c, callback, p1, p2);
content_add_user(c, callback, p1, p2, object_params);
return c;
}
c = content_create(url);
content_add_user(c, callback, p1, p2);
content_add_user(c, callback, p1, p2, object_params);
cache_put(c);
c->fetch_size = 0;
c->width = width;

View File

@ -10,9 +10,12 @@
#include "netsurf/content/content.h"
struct object_params;
struct content * fetchcache(const char *url, char *referer,
void (*callback)(content_msg msg, struct content *c, void *p1,
void *p2, const char *error),
void *p1, void *p2, unsigned long width, unsigned long height);
void *p1, void *p2, unsigned long width, unsigned long height,
struct object_params *object_params);
#endif

View File

@ -146,7 +146,7 @@ void css_revive(struct content *c, unsigned int width, unsigned int height)
c->data.css.import_content[i] = fetchcache(
c->data.css.import_url[i], c->url,
css_atimport_callback, c, i,
c->width, c->height);
c->width, c->height, 0);
if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
c->active++;
}
@ -179,7 +179,7 @@ void css_destroy(struct content *c)
if (c->data.css.import_content[i] != 0) {
free(c->data.css.import_url[i]);
content_remove_user(c->data.css.import_content[i],
css_atimport_callback, c, i);
css_atimport_callback, c, i, 0);
}
xfree(c->data.css.import_url);
xfree(c->data.css.import_content);
@ -295,7 +295,7 @@ void css_atimport(struct content *c, struct node *node)
c->data.css.import_url[i] = url_join(url, c->url);
c->data.css.import_content[i] = fetchcache(
c->data.css.import_url[i], c->url, css_atimport_callback,
c, i, c->width, c->height);
c, i, c->width, c->height, 0);
if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
c->active++;
@ -311,7 +311,7 @@ void css_atimport_callback(content_msg msg, struct content *css,
switch (msg) {
case CONTENT_MSG_LOADING:
if (css->type != CONTENT_CSS) {
content_remove_user(css, css_atimport_callback, c, i);
content_remove_user(css, css_atimport_callback, c, i, 0);
c->data.css.import_content[i] = 0;
c->active--;
c->error = 1;
@ -342,7 +342,7 @@ void css_atimport_callback(content_msg msg, struct content *css,
c->data.css.import_url[i] = xstrdup(error);
c->data.css.import_content[i] = fetchcache(
c->data.css.import_url[i], c->url, css_atimport_callback,
c, i, css->width, css->height);
c, i, css->width, css->height, 0);
if (c->data.css.import_content[i]->status != CONTENT_STATUS_DONE)
c->active++;
break;
@ -662,6 +662,27 @@ unsigned int css_hash(const char *s)
}
/**
* convert a struct css_length to pixels
*/
signed long len(struct css_length * length, struct css_style * style)
{
assert(!((length->unit == CSS_UNIT_EM || length->unit == CSS_UNIT_EX) && style == 0));
switch (length->unit) {
case CSS_UNIT_EM: return length->value * len(&style->font_size.value.length, 0);
case CSS_UNIT_EX: return length->value * len(&style->font_size.value.length, 0) * 0.6;
case CSS_UNIT_PX: return length->value;
case CSS_UNIT_IN: return length->value * 90.0;
case CSS_UNIT_CM: return length->value * 35.0;
case CSS_UNIT_MM: return length->value * 3.5;
case CSS_UNIT_PT: return length->value * 90.0 / 72.0;
case CSS_UNIT_PC: return length->value * 90.0 / 6.0;
default: break;
}
return 0;
}
#ifdef DEBUG

View File

@ -196,5 +196,6 @@ void css_parse_property_list(struct css_style * style, char * str);
colour named_colour(const char *name);
void css_dump_style(const struct css_style * const style);
signed long len(struct css_length * length, struct css_style * style);
#endif

View File

@ -183,7 +183,7 @@ void browser_window_destroy(struct browser_window* bw)
assert(bw != 0);
if (bw->current_content != NULL)
content_remove_user(bw->current_content, browser_window_callback, bw, 0);
content_remove_user(bw->current_content, browser_window_callback, bw, 0, 0);
if (bw->history != NULL)
{
@ -226,7 +226,7 @@ void browser_window_open_location_historical(struct browser_window* bw, const ch
browser_window_start_throbber(bw);
bw->time0 = clock();
bw->loading_content = fetchcache(url, 0, browser_window_callback, bw, 0,
gui_window_get_width(bw->window), 0);
gui_window_get_width(bw->window), 0, 0);
if (bw->loading_content->status == CONTENT_STATUS_READY)
browser_window_callback(CONTENT_MSG_READY, bw->loading_content, bw, 0, 0);
else if (bw->loading_content->status == CONTENT_STATUS_DONE)
@ -294,7 +294,7 @@ void browser_window_callback(content_msg msg, struct content *c,
gui_remove_gadget(bw->current_content->data.html.elements.gadgets[gc]);
}
}
content_remove_user(bw->current_content, browser_window_callback, bw, 0);
content_remove_user(bw->current_content, browser_window_callback, bw, 0, 0);
}
bw->current_content = c;
bw->loading_content = 0;

View File

@ -22,10 +22,10 @@ VPATH = content:css:desktop:render:riscos:utils:debug
WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wbad-function-cast -Wcast-qual \
-Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes \
-Wmissing-prototypes -Wmissing-declarations -Wredundant-decls \
-Wnested-externs -Winline -Wno-unused-parameter
CFLAGS = $(WARNFLAGS) -I.. -I/usr/local/riscoslibs/include \
-Wnested-externs -Winline -Wno-unused-parameter -Wuninitialized
CFLAGS = -O $(WARNFLAGS) -I.. -I/usr/local/riscoslibs/include \
-Dfd_set=long -mpoke-function-name
CFLAGS_DEBUG = $(WARNFLAGS) -I.. -I/usr/include/libxml2 \
CFLAGS_DEBUG = -O $(WARNFLAGS) -I.. -I/usr/include/libxml2 \
-Dfd_set=long -g
LDFLAGS = \
/usr/local/riscoslibs/libungif/libungif.ro \

View File

@ -84,6 +84,8 @@ static struct result box_applet(xmlNode *n, struct status *status,
static struct form* create_form(xmlNode* n);
static void add_form_element(struct page_elements* pe, struct form* f);
static void add_gadget_element(struct page_elements* pe, struct gui_gadget* g);
static bool plugin_decode(struct content* content, char* url, struct box* box,
struct object_params* po);
/* element_table must be sorted by name */
struct element_entry {
@ -156,6 +158,8 @@ struct box * box_create(struct css_style * style,
box->font = 0;
box->gadget = 0;
box->object = 0;
box->object_params = 0;
box->plugin_state = 0;
#endif
return box;
}
@ -1344,6 +1348,8 @@ void box_free_box(struct box *box)
else if (box->parent->href != box->href)
xmlFree(box->href);
}
/* TODO: free object_params and plugin_state */
}
@ -1394,7 +1400,7 @@ struct result box_object(xmlNode *n, struct status *status,
struct css_style *style)
{
struct box *box;
struct plugin_object *po;
struct object_params *po;
char *s, *url;
box = box_create(style, status->href, 0);
@ -1453,25 +1459,23 @@ struct result box_object(xmlNode *n, struct status *status,
}
/* object width */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "width"))) {
po->width = (unsigned int)atoi(s);
LOG(("width: %u", (unsigned int)atoi(s)));
xmlFree(s);
}
if (style->width.width == CSS_WIDTH_LENGTH)
po->width = len(&style->width.value.length, style);
/* object height */
if ((s = (char *) xmlGetProp(n, (const xmlChar *) "height"))) {
if (style->height.height == CSS_HEIGHT_LENGTH)
po->height = len(&style->height.length, style);
po->height = (unsigned int)atoi(s);
LOG(("height: %u", (unsigned int)atoi(s)));
xmlFree(s);
}
/* TODO: go through children looking for <param>, and add
* somewhere in po */
box->object_params = po;
/* start fetch */
plugin_decode(status->content, url, box, po);
if (plugin_decode(status->content, url, box, po))
return (struct result) {box, 0};
return (struct result) {box, 0};
return (struct result) {box, 1};
}
/**
@ -1482,7 +1486,7 @@ struct result box_embed(xmlNode *n, struct status *status,
struct css_style *style)
{
struct box *box;
struct plugin_object *po;
struct object_params *po;
char *s, *url;
box = box_create(style, status->href, 0);
@ -1508,6 +1512,8 @@ struct result box_embed(xmlNode *n, struct status *status,
xmlFree(s);
}
box->object_params = po;
/* start fetch */
plugin_decode(status->content, url, box, po);
@ -1540,3 +1546,79 @@ struct result box_applet(xmlNode *n, struct status *status,
return (struct result) {box,0};
}
/**
* plugin_decode
* This function checks that the contents of the plugin_object struct
* are valid. If they are, it initiates the fetch process. If they are
* not, it exits, leaving the box structure as it was on entry. This is
* necessary as there are multiple ways of declaring an object's attributes.
*
* Returns false if the object could not be handled.
*
* TODO: alt html
* params - create parameters file and put the filename string
* somewhere such that it is accessible from plugin_create.
*/
bool plugin_decode(struct content* content, char* url, struct box* box,
struct object_params* po)
{
os_error *e;
unsigned int *fv;
/* Check if the codebase attribute is defined.
* If it is not, set it to the codebase of the current document.
*/
if(po->codebase == 0)
po->codebase = strdup(content->url);
else
po->codebase = url_join(po->codebase, content->url);
/* Check that we have some data specified.
* First, check the data attribute.
* Second, check the classid attribute.
* The data attribute takes precedence.
* If neither are specified or if classid begins "clsid:",
* we can't handle this object.
*/
if(po->data == 0 && po->classid == 0) {
return false;
}
if(po->data == 0 && po->classid != 0) {
if(strnicmp(po->classid, "clsid:", 6) == 0) {
LOG(("ActiveX object - n0"));
return false;
}
else {
url = url_join(po->classid, po->codebase);
}
}
else {
url = url_join(po->data, po->codebase);
}
/* Check if the declared mime type is understandable.
* Checks type and codetype attributes.
*/
if(po->type != 0) {
if (content_lookup(po->type) == CONTENT_OTHER)
return false;
}
if(po->codetype != 0) {
if (content_lookup(po->codetype) == CONTENT_OTHER)
return false;
}
/* If we've got to here, the object declaration has provided us with
* enough data to enable us to have a go at downloading and displaying it.
*
* We may still find that the object has a MIME type that we can't handle
* 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);
return true;
}

View File

@ -81,6 +81,23 @@ struct gui_gadget {
} data;
};
/* state of a plugin handling this box, platform dependent */
struct plugin_state;
/* parameters for <object> and related elements */
struct object_params {
char* data;
char* type;
char* codetype;
char* codebase;
char* classid;
char* paramds; /* very likely to change */
unsigned int* width;
unsigned int* height;
/* not a parameter, but stored here for convenience */
struct plugin_state *plugin_state;
};
struct box {
box_type type;
struct css_style * style;
@ -105,6 +122,7 @@ struct box {
struct font_data *font;
struct gui_gadget* gadget;
struct content* object; /* usually an image */
struct object_params *object_params;
};
struct form

View File

@ -96,6 +96,8 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
/* convert xml tree to box tree */
LOG(("XML to box"));
sprintf(c->status_message, "Processing document");
content_broadcast(c, CONTENT_MSG_STATUS, 0);
xml_to_box(html, c);
/*box_dump(c->data.html.layout->children, 0);*/
@ -103,18 +105,18 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
xmlFreeDoc(document);
content_remove_user(c->data.html.stylesheet_content[0],
html_convert_css_callback, c, 0);
html_convert_css_callback, c, 0, 0);
if (c->data.html.stylesheet_content[1] != 0)
content_destroy(c->data.html.stylesheet_content[1]);
for (i = 2; i != c->data.html.stylesheet_count; i++)
if (c->data.html.stylesheet_content[i] != 0)
content_remove_user(c->data.html.stylesheet_content[i],
html_convert_css_callback, c, i);
html_convert_css_callback, c, i, 0);
xfree(c->data.html.stylesheet_content);
/* layout the box tree */
sprintf(c->status_message, "Formatting document");
content_broadcast(c, CONTENT_MSG_STATUS, 0);
sprintf(c->status_message, "Formatting document");
content_broadcast(c, CONTENT_MSG_STATUS, 0);
LOG(("Layout document"));
layout_document(c->data.html.layout->children, width);
/*box_dump(c->data.html.layout->children, 0);*/
@ -145,7 +147,7 @@ void html_convert_css_callback(content_msg msg, struct content *css,
c->error = 1;
sprintf(c->status_message, "Warning: stylesheet is not CSS");
content_broadcast(c, CONTENT_MSG_STATUS, 0);
content_remove_user(css, html_convert_css_callback, c, i);
content_remove_user(css, html_convert_css_callback, c, i, 0);
}
break;
@ -173,7 +175,7 @@ void html_convert_css_callback(content_msg msg, struct content *css,
c->active--;
c->data.html.stylesheet_content[i] = fetchcache(
error, c->url, html_convert_css_callback,
c, i, css->width, css->height);
c, i, css->width, css->height, 0);
if (c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
c->active++;
break;
@ -225,7 +227,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
#endif
c->url,
html_convert_css_callback,
c, 0, c->width, c->height);
c, 0, c->width, c->height, 0);
if (c->data.html.stylesheet_content[0]->status != CONTENT_STATUS_DONE)
c->active++;
@ -275,7 +277,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
(i + 1) * sizeof(*c->data.html.stylesheet_content));
c->data.html.stylesheet_content[i] = fetchcache(url, c->url,
html_convert_css_callback, c, i,
c->width, c->height);
c->width, c->height, 0);
if (c->data.html.stylesheet_content[i]->status != CONTENT_STATUS_DONE)
c->active++;
free(url);
@ -356,7 +358,7 @@ void html_fetch_object(struct content *c, char *url, struct box *box)
/* start fetch */
c->data.html.object[i].content = fetchcache(url, c->url,
html_object_callback,
c, i, 0, 0);
c, i, 0, 0, box->object_params);
c->active++;
if (c->data.html.object[i].content->status == CONTENT_STATUS_DONE)
html_object_callback(CONTENT_MSG_DONE,
@ -379,7 +381,7 @@ void html_object_callback(content_msg msg, struct content *object,
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, i);
content_remove_user(object, html_object_callback, c, i, 0);
}
break;
@ -447,7 +449,8 @@ void html_object_callback(content_msg msg, struct content *object,
c->data.html.object[i].url = xstrdup(error);
c->data.html.object[i].content = fetchcache(
error, c->url, html_object_callback,
c, i, 0, 0);
c, i, 0, 0,
c->data.html.object[i].box->object_params);
if (c->data.html.object[i].content->status != CONTENT_STATUS_DONE)
c->active++;
break;
@ -479,7 +482,8 @@ void html_revive(struct content *c, unsigned int width, unsigned int height)
c->data.html.object[i].content = fetchcache(
c->data.html.object[i].url, c->url,
html_object_callback,
c, i, 0, 0);
c, i, 0, 0,
c->data.html.object[i].box->object_params);
if (c->data.html.object[i].content->status != CONTENT_STATUS_DONE)
c->active++;
}
@ -507,6 +511,16 @@ void html_destroy(struct content *c)
unsigned int i;
LOG(("content %p", c));
for (i = 0; i != c->data.html.object_count; i++) {
LOG(("object %i %p", i, c->data.html.object[i].content));
if (c->data.html.object[i].content != 0)
content_remove_user(c->data.html.object[i].content,
html_object_callback, c, i,
c->data.html.object[i].box->object_params);
free(c->data.html.object[i].url);
}
free(c->data.html.object);
LOG(("layout %p", c->data.html.layout));
if (c->data.html.layout != 0)
box_free(c->data.html.layout);
@ -516,14 +530,5 @@ void html_destroy(struct content *c)
LOG(("title %p", c->title));
if (c->title != 0)
xfree(c->title);
for (i = 0; i != c->data.html.object_count; i++) {
LOG(("object %i %p", i, c->data.html.object[i].content));
if (c->data.html.object[i].content != 0)
content_remove_user(c->data.html.object[i].content,
html_object_callback, c, i);
free(c->data.html.object[i].url);
}
free(c->data.html.object);
}

View File

@ -32,8 +32,6 @@
* internal functions
*/
static signed long len(struct css_length * length, struct css_style * style);
static void layout_node(struct box * box, unsigned long width, struct box * cont,
unsigned long cx, unsigned long cy);
static void layout_block(struct box * box, unsigned long width, struct box * cont,
@ -54,26 +52,6 @@ static void calculate_widths(struct box *box);
static void calculate_inline_container_widths(struct box *box);
static void calculate_table_widths(struct box *table);
/**
* convert a struct css_length to pixels
*/
signed long len(struct css_length * length, struct css_style * style)
{
assert(!((length->unit == CSS_UNIT_EM || length->unit == CSS_UNIT_EX) && style == 0));
switch (length->unit) {
case CSS_UNIT_EM: return length->value * len(&style->font_size.value.length, 0);
case CSS_UNIT_EX: return length->value * len(&style->font_size.value.length, 0) * 0.6;
case CSS_UNIT_PX: return length->value;
case CSS_UNIT_IN: return length->value * 90.0;
case CSS_UNIT_CM: return length->value * 35.0;
case CSS_UNIT_MM: return length->value * 3.5;
case CSS_UNIT_PT: return length->value * 90.0 / 72.0;
case CSS_UNIT_PC: return length->value * 90.0 / 6.0;
default: break;
}
return 0;
}
/**
* layout algorithm
@ -196,7 +174,7 @@ void layout_block(struct box * box, unsigned long width, struct box * cont,
switch (style->width.width) {
case CSS_WIDTH_LENGTH:
box->width = len(&style->width.value.length, box->style);
box->width = len(&style->width.value.length, style);
break;
case CSS_WIDTH_PERCENT:
box->width = width * style->width.value.percent / 100;
@ -210,7 +188,7 @@ void layout_block(struct box * box, unsigned long width, struct box * cont,
box->height = layout_block_children(box, box->width, cont, cx, cy);
switch (style->height.height) {
case CSS_HEIGHT_LENGTH:
box->height = len(&style->height.length, box->style);
box->height = len(&style->height.length, style);
break;
case CSS_HEIGHT_AUTO:
default:

View File

@ -19,152 +19,30 @@
#include "oslib/mimemap.h"
bool plugin_handleable(struct content* c);
/**
* plugin_decode
* This function checks that the contents of the plugin_object struct
* are valid. If they are, it initiates the fetch process. If they are
* not, it exits, leaving the box structure as it was on entry. This is
* necessary as there are multiple ways of declaring an object's attributes.
*
* TODO: alt html
* params - create parameters file and put the filename string
* somewhere such that it is accessible from plugin_create.
*/
void plugin_decode(struct content* content, char* url, struct box* box,
struct plugin_object* po)
{
os_error *e;
unsigned int *fv;
/* Check if the codebase attribute is defined.
* If it is not, set it to the codebase of the current document.
*/
if(po->codebase == 0)
po->codebase = strdup(content->url);
else
po->codebase = url_join(po->codebase, content->url);
/* Check that we have some data specified.
* First, check the data attribute.
* Second, check the classid attribute.
* The data attribute takes precedence.
* If neither are specified or if classid begins "clsid:",
* we can't handle this object.
*/
if(po->data == 0 && po->classid == 0) {
xfree(po);
return;
}
if(po->data == 0 && po->classid != 0) {
if(strnicmp(po->classid, "clsid:", 6) == 0) {
LOG(("ActiveX object - n0"));
xfree(po);
return;
}
else {
url = url_join(po->classid, po->codebase);
}
}
else {
url = url_join(po->data, po->codebase);
}
/* Check if the declared mime type is understandable.
* ie. is it referenced in the mimemap file?
* Checks type and codetype attributes.
*/
if(po->type != 0) {
e = xmimemaptranslate_mime_type_to_filetype((const char*)po->type,
(unsigned int*)&fv);
LOG(("fv: &%x", (int) fv));
if(e != NULL) {
xfree(po);
return;
}
/* If a filetype of &ffd (Data) is returned,
* one of the following mime types is possible :
* application/octet-stream
* multipart/x-mixed-replace
* unknown mime type (* / *)
* we assume it to be the last one as the other two
* are unlikely to occur in an <object> definition.
*/
if((int)fv == 0xffd) {
xfree(po);
return;
}
/* TODO: implement GUI for iframes/frames
* For now, we just discard the data and
* render the alternative html
*/
if((int)fv == 0xfaf) {
xfree(po);
return;
}
}
if(po->codetype != 0) {
e = xmimemaptranslate_mime_type_to_filetype((const char*)po->codetype,
(unsigned int*)&fv);
if(e != NULL) {
xfree(po);
return;
}
/* If a filetype of &ffd (Data) is returned,
* one of the following mime types is possible :
* application/octet-stream
* multipart/x-mixed-replace
* unknown mime type (* / *)
* we assume it to be the last one as the other two
* are unlikely to occur in an <object> definition.
*/
if((int)fv == 0xffd) {
xfree(po);
return;
}
/* TODO: implement GUI for iframes/frames
* For now, we just discard the data and
* render the alternative html
*/
if((int)fv == 0xfaf) {
xfree(po);
return;
}
}
/* If we've got to here, the object declaration has provided us with
* enough data to enable us to have a go at downloading and displaying it.
*/
xfree(po);
html_fetch_object(content, url, box);
}
/**
* plugin_create
* initialises plugin system in readiness for recieving object data
*
* TODO: implement aborting the fetch
* get parameter filename from wherever it was put by plugin_decode
* launch plugin system
*/
void plugin_create(struct content *c)
{
bool can_handle = TRUE; /* we assume we can handle all types */
/* we can't create the plugin here, because this is only called
* once, even if the object appears several times */
}
LOG(("mime type: %s", c->mime_type));
/* check if we can handle this type */
can_handle = plugin_handleable(c);
LOG(("can_handle = %s", can_handle ? "TRUE" : "FALSE"));
LOG(("sysvar: %s", can_handle ? c->data.plugin.sysvar : "not set"));
if(!can_handle) {
/* TODO: need to find a way of stopping the fetch
* if we can't handle this type
*/
}
/**
* plugin_add_user
*
* The content has been added to a page somewhere: launch the plugin.
* This may be called anytime after plugin_create any number of times.
* Each must launch a new plugin.
*/
void plugin_add_user(struct content *c, struct object_params *params)
{
assert(params != 0);
/* ok, it looks like we can handle this object.
* Broadcast Message_PlugIn_Open (&4D540) and listen for response
* Message_PlugIn_Opening (&4D541). If no response, try to launch
@ -175,18 +53,22 @@ void plugin_create(struct content *c)
* values outside the area displayed. This is corrected when
* plugin_redraw is called.
*/
/* Recheck if can_handle is false. If it is, stop fetch and exit .*/
if(!can_handle) {
/* TODO: need to find a way of stopping the fetch
* if we can't handle this type
*/
}
}
/**
* plugin_remove_user
*
* A plugin is no longer required, eg. the page containing it has
* been closed.
*/
void plugin_remove_user(struct content *c, struct object_params *params)
{
assert(params != 0);
}
static const char * const ALIAS_PREFIX = "Alias$@PlugInType_";
/**
@ -194,35 +76,21 @@ static const char * const ALIAS_PREFIX = "Alias$@PlugInType_";
* Tests whether we can handle an object using a browser plugin
* returns TRUE if we can handle it, FALSE if we can't.
*/
bool plugin_handleable(struct content* c)
bool plugin_handleable(const char *mime_type)
{
bool ret = TRUE;
char *sysvar;
unsigned int *fv;
int used;
os_error *e;
/* prefix + 3 for file type + 1 for terminating \0 */
sysvar = xcalloc(strlen(ALIAS_PREFIX)+4, sizeof(char));
e = xmimemaptranslate_mime_type_to_filetype((const char*)c->mime_type,
(unsigned int*)&fv);
e = xmimemaptranslate_mime_type_to_filetype(mime_type, (bits *) &fv);
sprintf(sysvar, "%s%x", ALIAS_PREFIX, e == NULL ? (int)fv : 0 );
xos_read_var_val_size((const char*)sysvar,0, os_VARTYPE_STRING,
&used, 0, os_VARTYPE_STRING);
if(used == 0)
/* No system variable set => no plugin available */
ret = FALSE;
if(ret)
c->data.plugin.sysvar = strdup(sysvar);
xfree(sysvar);
return ret;
sprintf(sysvar, "%s%x", ALIAS_PREFIX, e == NULL ? fv : 0 );
if (getenv(sysvar) == 0)
return false;
return true;
}
/**
@ -244,6 +112,8 @@ void plugin_process_data(struct content *c, char *data, unsigned long size)
* Therefore, we need to stop the fetch and exit.
*/
/* I think we should just buffer the data here, in case the
* plugin requests it sometime in the future. - James */
}
/**

View File

@ -8,24 +8,16 @@
#ifndef _NETSURF_RISCOS_PLUGIN_H_
#define _NETSURF_RISCOS_PLUGIN_H_
#include <stdbool.h>
#include "netsurf/content/content.h"
#include "netsurf/render/box.h"
struct plugin_object {
char* data;
char* type;
char* codetype;
char* codebase;
char* classid;
char* paramds; /* very likely to change */
unsigned int* width;
unsigned int* height;
struct plugin_state {
int dummy;
};
/* function definitions */
void plugin_decode(struct content* content, char* url, struct box* box,
struct plugin_object* po);
bool plugin_handleable(const char *mime_type);
void plugin_create(struct content *c);
void plugin_process_data(struct content *c, char *data, unsigned long size);
int plugin_convert(struct content *c, unsigned int width, unsigned int height);
@ -34,5 +26,7 @@ void plugin_reformat(struct content *c, unsigned int width, unsigned int height)
void plugin_destroy(struct content *c);
void plugin_redraw(struct content *c, long x, long y,
unsigned long width, unsigned long height);
void plugin_add_user(struct content *c, struct object_params *params);
void plugin_remove_user(struct content *c, struct object_params *params);
#endif