2003-06-25 03:22:00 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2004-02-25 18:12:58 +03:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** \file
|
|
|
|
* Content handling (implementation).
|
2003-09-11 02:27:15 +04:00
|
|
|
*
|
2003-09-08 01:08:13 +04:00
|
|
|
* This implementation is based on the ::handler_map array, which maps
|
|
|
|
* ::content_type to the functions which implement that type.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/content/content.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/css/css.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/render/html.h"
|
|
|
|
#include "netsurf/render/textplain.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_JPEG
|
2003-02-26 00:00:27 +03:00
|
|
|
#include "netsurf/riscos/jpeg.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-03-27 03:54:03 +03:00
|
|
|
#ifdef riscos
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PNG
|
2003-05-10 15:15:49 +04:00
|
|
|
#include "netsurf/riscos/png.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_GIF
|
2003-06-05 17:17:55 +04:00
|
|
|
#include "netsurf/riscos/gif.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_SPRITE
|
2003-09-11 02:27:15 +04:00
|
|
|
#include "netsurf/riscos/sprite.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
2003-09-11 02:27:15 +04:00
|
|
|
#include "netsurf/riscos/draw.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
2003-07-08 02:10:51 +04:00
|
|
|
#include "netsurf/riscos/plugin.h"
|
2003-07-15 02:57:45 +04:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-06-17 23:24:21 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
2004-02-27 20:45:19 +03:00
|
|
|
#include "netsurf/utils/messages.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** An entry in mime_map. */
|
2003-02-09 15:58:15 +03:00
|
|
|
struct mime_entry {
|
2003-07-08 02:10:51 +04:00
|
|
|
char mime_type[40];
|
2003-02-09 15:58:15 +03:00
|
|
|
content_type type;
|
|
|
|
};
|
2003-09-08 01:08:13 +04:00
|
|
|
/** A map from MIME type to ::content_type. Must be sorted by mime_type. */
|
2003-02-09 15:58:15 +03:00
|
|
|
static const struct mime_entry mime_map[] = {
|
2003-06-17 23:24:21 +04:00
|
|
|
#ifdef riscos
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_DRAW
|
2003-09-11 02:27:15 +04:00
|
|
|
{"application/drawfile", CONTENT_DRAW},
|
|
|
|
{"application/x-drawfile", CONTENT_DRAW},
|
|
|
|
{"image/drawfile", CONTENT_DRAW},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-04-25 03:42:32 +04:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_GIF
|
2003-06-05 17:17:55 +04:00
|
|
|
{"image/gif", CONTENT_GIF},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_JPEG
|
2003-02-26 00:00:27 +03:00
|
|
|
{"image/jpeg", CONTENT_JPEG},
|
2004-03-16 03:51:34 +03:00
|
|
|
{"image/pjpeg", CONTENT_JPEG},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-03-27 03:54:03 +03:00
|
|
|
#ifdef riscos
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PNG
|
2003-05-10 15:15:49 +04:00
|
|
|
{"image/png", CONTENT_PNG},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
2003-09-11 02:27:15 +04:00
|
|
|
{"image/x-drawfile", CONTENT_DRAW},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_SPRITE
|
2003-09-11 02:27:15 +04:00
|
|
|
{"image/x-riscos-sprite", CONTENT_SPRITE},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2003-04-04 19:19:32 +04:00
|
|
|
{"text/css", CONTENT_CSS},
|
2003-02-09 15:58:15 +03:00
|
|
|
{"text/html", CONTENT_HTML},
|
|
|
|
{"text/plain", CONTENT_TEXTPLAIN},
|
|
|
|
};
|
|
|
|
#define MIME_MAP_COUNT (sizeof(mime_map) / sizeof(mime_map[0]))
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** An entry in handler_map. */
|
2003-02-09 15:58:15 +03:00
|
|
|
struct handler_entry {
|
2003-12-27 23:15:23 +03:00
|
|
|
void (*create)(struct content *c, const char *params[]);
|
2003-02-09 15:58:15 +03:00
|
|
|
void (*process_data)(struct content *c, char *data, unsigned long size);
|
|
|
|
int (*convert)(struct content *c, unsigned int width, unsigned int height);
|
|
|
|
void (*revive)(struct content *c, unsigned int width, unsigned int height);
|
|
|
|
void (*reformat)(struct content *c, unsigned int width, unsigned int height);
|
|
|
|
void (*destroy)(struct content *c);
|
2003-05-10 15:15:49 +04:00
|
|
|
void (*redraw)(struct content *c, long x, long y,
|
2003-09-10 21:10:25 +04:00
|
|
|
unsigned long width, unsigned long height,
|
2004-02-25 18:12:58 +03:00
|
|
|
long clip_x0, long clip_y0, long clip_x1, long clip_y1,
|
|
|
|
float scale);
|
2003-07-15 02:57:45 +04:00
|
|
|
void (*add_instance)(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params, void **state);
|
|
|
|
void (*remove_instance)(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params, void **state);
|
|
|
|
void (*reshape_instance)(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params, void **state);
|
2003-02-09 15:58:15 +03:00
|
|
|
};
|
2003-09-08 01:08:13 +04:00
|
|
|
/** A table of handler functions, indexed by ::content_type.
|
|
|
|
* Must be ordered as enum ::content_type. */
|
2003-02-09 15:58:15 +03:00
|
|
|
static const struct handler_entry handler_map[] = {
|
2003-05-10 15:15:49 +04:00
|
|
|
{html_create, html_process_data, html_convert, html_revive,
|
2003-07-15 18:37:34 +04:00
|
|
|
html_reformat, html_destroy, html_redraw,
|
2003-09-04 01:58:54 +04:00
|
|
|
html_add_instance, html_remove_instance, html_reshape_instance},
|
2004-03-11 05:19:14 +03:00
|
|
|
{textplain_create, html_process_data, textplain_convert,
|
|
|
|
0, 0, 0, 0, 0, 0, 0},
|
2004-04-14 16:53:14 +04:00
|
|
|
{0, 0, css_convert, css_revive, 0, css_destroy, 0, 0, 0, 0},
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_JPEG
|
2004-03-11 05:19:14 +03:00
|
|
|
{nsjpeg_create, 0, nsjpeg_convert, 0,
|
|
|
|
0, nsjpeg_destroy, nsjpeg_redraw, 0, 0, 0},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-04-25 03:42:32 +04:00
|
|
|
#ifdef WITH_GIF
|
|
|
|
{nsgif_create, 0, nsgif_convert, 0,
|
|
|
|
0, nsgif_destroy, nsgif_redraw, 0, 0, 0},
|
|
|
|
#endif
|
2004-03-27 03:54:03 +03:00
|
|
|
#ifdef riscos
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PNG
|
2004-03-11 05:19:14 +03:00
|
|
|
{nspng_create, nspng_process_data, nspng_convert, 0,
|
|
|
|
0, nspng_destroy, nspng_redraw, 0, 0, 0},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_SPRITE
|
2003-09-11 02:27:15 +04:00
|
|
|
{sprite_create, sprite_process_data, sprite_convert, sprite_revive,
|
|
|
|
sprite_reformat, sprite_destroy, sprite_redraw, 0, 0, 0},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
2004-03-11 05:19:14 +03:00
|
|
|
{0, 0, draw_convert, 0,
|
|
|
|
0, draw_destroy, draw_redraw, 0, 0, 0},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
2003-07-08 02:10:51 +04:00
|
|
|
{plugin_create, plugin_process_data, plugin_convert, plugin_revive,
|
2003-07-10 01:33:01 +04:00
|
|
|
plugin_reformat, plugin_destroy, plugin_redraw,
|
2003-07-15 02:57:45 +04:00
|
|
|
plugin_add_instance, plugin_remove_instance,
|
|
|
|
plugin_reshape_instance},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2004-03-11 05:19:14 +03:00
|
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
2003-02-09 15:58:15 +03:00
|
|
|
};
|
2003-06-17 23:24:21 +04:00
|
|
|
#define HANDLER_MAP_COUNT (sizeof(handler_map) / sizeof(handler_map[0]))
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Convert a MIME type to a content_type.
|
|
|
|
*
|
|
|
|
* The returned ::content_type will always be suitable for content_set_type().
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
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]),
|
2004-04-20 22:27:46 +04:00
|
|
|
(int (*)(const void *, const void *)) strcasecmp);
|
2003-07-10 01:33:01 +04:00
|
|
|
if (m == 0) {
|
2003-07-15 02:57:45 +04:00
|
|
|
#ifdef riscos
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PLUGIN
|
2003-07-10 01:33:01 +04:00
|
|
|
if (plugin_handleable(mime_type))
|
|
|
|
return CONTENT_PLUGIN;
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-07-15 02:57:45 +04:00
|
|
|
#endif
|
2003-02-09 15:58:15 +03:00
|
|
|
return CONTENT_OTHER;
|
2003-07-10 01:33:01 +04:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
return m->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Create a new content structure.
|
|
|
|
*
|
|
|
|
* The type is initialised to CONTENT_UNKNOWN, and the status to
|
|
|
|
* CONTENT_STATUS_TYPE_UNKNOWN.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content * content_create(char *url)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
|
|
|
struct content *c;
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content_user *user_sentinel;
|
|
|
|
LOG(("url %s", url));
|
2003-02-09 15:58:15 +03:00
|
|
|
c = xcalloc(1, sizeof(struct content));
|
|
|
|
c->url = xstrdup(url);
|
2003-06-17 23:24:21 +04:00
|
|
|
c->type = CONTENT_UNKNOWN;
|
|
|
|
c->status = CONTENT_STATUS_TYPE_UNKNOWN;
|
2003-07-16 21:38:46 +04:00
|
|
|
c->cache = 0;
|
2003-02-09 15:58:15 +03:00
|
|
|
c->size = sizeof(struct content);
|
2003-06-17 23:24:21 +04:00
|
|
|
c->fetch = 0;
|
2004-03-11 05:19:14 +03:00
|
|
|
c->source_data = 0;
|
|
|
|
c->source_size = 0;
|
2003-09-08 01:08:13 +04:00
|
|
|
c->mime_type = 0;
|
2004-02-27 20:45:19 +03:00
|
|
|
strcpy(c->status_message, messages_get("Loading"));
|
2003-06-17 23:24:21 +04:00
|
|
|
user_sentinel = xcalloc(1, sizeof(*user_sentinel));
|
|
|
|
user_sentinel->callback = 0;
|
|
|
|
user_sentinel->p1 = user_sentinel->p2 = 0;
|
|
|
|
user_sentinel->next = 0;
|
|
|
|
c->user_list = user_sentinel;
|
2004-01-26 17:16:23 +03:00
|
|
|
c->lock = 0;
|
|
|
|
c->destroy_pending = false;
|
2003-02-09 15:58:15 +03:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Initialise the content for the specified type.
|
|
|
|
*
|
|
|
|
* The type is updated to the given type, and a copy of mime_type is taken. The
|
|
|
|
* status is changed to CONTENT_STATUS_LOADING. CONTENT_MSG_LOADING is sent to
|
|
|
|
* all users. The create function for the type is called to initialise the type
|
|
|
|
* specific parts of the content structure.
|
2003-12-27 23:15:23 +03:00
|
|
|
*
|
|
|
|
* \param c content structure
|
|
|
|
* \param type content_type to initialise to
|
|
|
|
* \param mime_type MIME-type string for this content
|
|
|
|
* \param params array of strings, ordered attribute, value, attribute, ..., 0
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
2004-05-05 20:33:15 +04:00
|
|
|
void content_set_type(struct content *c, content_type type,
|
|
|
|
const char *mime_type, const char *params[])
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data data;
|
2003-07-15 02:57:45 +04:00
|
|
|
assert(c != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_TYPE_UNKNOWN);
|
|
|
|
assert(type < CONTENT_UNKNOWN);
|
|
|
|
LOG(("content %s, type %i", c->url, type));
|
|
|
|
c->type = type;
|
2003-08-28 23:20:40 +04:00
|
|
|
c->mime_type = xstrdup(mime_type);
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_LOADING;
|
2004-03-11 05:19:14 +03:00
|
|
|
c->source_data = xcalloc(0, 1);
|
|
|
|
if (handler_map[type].create)
|
|
|
|
handler_map[type].create(c, params);
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_LOADING, data);
|
2003-09-17 16:56:43 +04:00
|
|
|
/* c may be destroyed at this point as a result of
|
|
|
|
* CONTENT_MSG_LOADING, so must not be accessed */
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Process a block of source data.
|
|
|
|
*
|
|
|
|
* Calls the process_data function for the content.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_process_data(struct content *c, char *data, unsigned long size)
|
|
|
|
{
|
|
|
|
assert(c != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_LOADING);
|
|
|
|
LOG(("content %s, size %lu", c->url, size));
|
2004-03-11 05:19:14 +03:00
|
|
|
c->source_data = xrealloc(c->source_data, c->source_size + size);
|
|
|
|
memcpy(c->source_data + c->source_size, data, size);
|
|
|
|
c->source_size += size;
|
|
|
|
c->size += size;
|
|
|
|
if (handler_map[c->type].process_data)
|
|
|
|
handler_map[c->type].process_data(c, data, size);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* All data has arrived, convert for display.
|
|
|
|
*
|
|
|
|
* Calls the convert function for the content.
|
|
|
|
*
|
|
|
|
* - If the conversion succeeds, but there is still some processing required
|
|
|
|
* (eg. loading images), the content gets status CONTENT_STATUS_READY, and a
|
|
|
|
* CONTENT_MSG_READY is sent to all users.
|
|
|
|
* - If the conversion succeeds and is complete, the content gets status
|
2004-02-25 18:12:58 +03:00
|
|
|
* CONTENT_STATUS_DONE, and CONTENT_MSG_READY then CONTENT_MSG_DONE are sent.
|
2003-09-08 01:08:13 +04:00
|
|
|
* - If the conversion fails, CONTENT_MSG_ERROR is sent. The content is then
|
|
|
|
* destroyed and must no longer be used.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
void content_convert(struct content *c, unsigned long width, unsigned long height)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data data;
|
2003-02-09 15:58:15 +03:00
|
|
|
assert(c != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->type < HANDLER_MAP_COUNT);
|
|
|
|
assert(c->status == CONTENT_STATUS_LOADING);
|
|
|
|
LOG(("content %s", c->url));
|
2003-04-15 21:53:00 +04:00
|
|
|
c->available_width = width;
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].convert) {
|
|
|
|
if (handler_map[c->type].convert(c, width, height)) {
|
|
|
|
/* convert failed, destroy content */
|
2004-04-25 03:42:32 +04:00
|
|
|
data.error = "Conversion failed";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, data);
|
2004-03-11 05:19:14 +03:00
|
|
|
if (c->cache)
|
|
|
|
cache_destroy(c);
|
|
|
|
content_destroy(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
assert(c->status == CONTENT_STATUS_READY ||
|
|
|
|
c->status == CONTENT_STATUS_DONE);
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_READY, data);
|
2004-02-25 18:12:58 +03:00
|
|
|
if (c->status == CONTENT_STATUS_DONE)
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_DONE, data);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Fix content that has been loaded from the cache.
|
|
|
|
*
|
|
|
|
* Calls the revive function for the content. The content will be processed for
|
|
|
|
* display, for example dependencies loaded or reformated to current width.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_revive(struct content *c, unsigned long width, unsigned long height)
|
|
|
|
{
|
2004-03-11 05:19:14 +03:00
|
|
|
assert(0); /* unmaintained */
|
2003-02-09 15:58:15 +03:00
|
|
|
assert(c != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
if (c->status != CONTENT_STATUS_DONE)
|
2003-04-18 01:35:02 +04:00
|
|
|
return;
|
2003-04-15 21:53:00 +04:00
|
|
|
c->available_width = width;
|
2003-02-09 15:58:15 +03:00
|
|
|
handler_map[c->type].revive(c, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Reformat to new size.
|
|
|
|
*
|
|
|
|
* Calls the reformat function for the content.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_reformat(struct content *c, unsigned long width, unsigned long height)
|
|
|
|
{
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data data;
|
2003-02-09 15:58:15 +03:00
|
|
|
assert(c != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_READY ||
|
|
|
|
c->status == CONTENT_STATUS_DONE);
|
2003-04-15 21:53:00 +04:00
|
|
|
c->available_width = width;
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].reformat) {
|
|
|
|
handler_map[c->type].reformat(c, width, height);
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_REFORMAT, data);
|
2004-03-11 05:19:14 +03:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Destroy and free a content.
|
|
|
|
*
|
|
|
|
* Calls the destroy function for the content, and frees the structure.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_destroy(struct content *c)
|
|
|
|
{
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content_user *user, *next;
|
2004-01-26 17:16:23 +03:00
|
|
|
assert(c);
|
2003-06-17 23:24:21 +04:00
|
|
|
LOG(("content %p %s", c, c->url));
|
2004-01-26 17:16:23 +03:00
|
|
|
assert(!c->fetch);
|
|
|
|
assert(!c->cache);
|
|
|
|
|
|
|
|
if (c->lock) {
|
|
|
|
c->destroy_pending = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-11 05:19:14 +03:00
|
|
|
if (c->type < HANDLER_MAP_COUNT && handler_map[c->type].destroy)
|
2003-06-17 23:24:21 +04:00
|
|
|
handler_map[c->type].destroy(c);
|
|
|
|
for (user = c->user_list; user != 0; user = next) {
|
|
|
|
next = user->next;
|
|
|
|
xfree(user);
|
|
|
|
}
|
2003-09-08 01:08:13 +04:00
|
|
|
free(c->mime_type);
|
2003-10-09 00:49:26 +04:00
|
|
|
xfree(c->url);
|
2004-03-11 05:19:14 +03:00
|
|
|
free(c->source_data);
|
2003-02-09 15:58:15 +03:00
|
|
|
xfree(c);
|
|
|
|
}
|
|
|
|
|
2003-05-10 15:15:49 +04:00
|
|
|
|
2004-01-23 23:46:29 +03:00
|
|
|
/**
|
|
|
|
* Reset a content.
|
|
|
|
*
|
|
|
|
* Calls the destroy function for the content, but does not free
|
|
|
|
* the structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void content_reset(struct content *c)
|
|
|
|
{
|
|
|
|
assert(c != 0);
|
|
|
|
LOG(("content %p %s", c, c->url));
|
2004-03-11 05:19:14 +03:00
|
|
|
if (c->type < HANDLER_MAP_COUNT && handler_map[c->type].destroy)
|
2004-01-23 23:46:29 +03:00
|
|
|
handler_map[c->type].destroy(c);
|
|
|
|
c->type = CONTENT_UNKNOWN;
|
|
|
|
c->status = CONTENT_STATUS_TYPE_UNKNOWN;
|
|
|
|
c->size = sizeof(struct content);
|
|
|
|
free(c->mime_type);
|
|
|
|
c->mime_type = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-10 15:15:49 +04:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Display content on screen.
|
|
|
|
*
|
|
|
|
* Calls the redraw function for the content, if it exists.
|
2003-05-10 15:15:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_redraw(struct content *c, long x, long y,
|
2003-09-10 21:10:25 +04:00
|
|
|
unsigned long width, unsigned long height,
|
2004-02-25 18:12:58 +03:00
|
|
|
long clip_x0, long clip_y0, long clip_x1, long clip_y1,
|
|
|
|
float scale)
|
2003-05-10 15:15:49 +04:00
|
|
|
{
|
|
|
|
assert(c != 0);
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].redraw)
|
2003-09-10 21:10:25 +04:00
|
|
|
handler_map[c->type].redraw(c, x, y, width, height,
|
2004-02-25 18:12:58 +03:00
|
|
|
clip_x0, clip_y0, clip_x1, clip_y1, scale);
|
2003-05-10 15:15:49 +04:00
|
|
|
}
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Register a user for callbacks.
|
|
|
|
*
|
|
|
|
* The callback will be called with p1 and p2 when content_broadcast() is
|
|
|
|
* called with the content.
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_add_user(struct content *c,
|
|
|
|
void (*callback)(content_msg msg, struct content *c, void *p1,
|
2004-04-25 03:42:32 +04:00
|
|
|
void *p2, union content_msg_data data),
|
2003-07-15 02:57:45 +04:00
|
|
|
void *p1, void *p2)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user;
|
|
|
|
LOG(("content %s, user %p %p %p", c->url, callback, p1, p2));
|
|
|
|
user = xcalloc(1, sizeof(*user));
|
|
|
|
user->callback = callback;
|
|
|
|
user->p1 = p1;
|
|
|
|
user->p2 = p2;
|
|
|
|
user->next = c->user_list->next;
|
|
|
|
c->user_list->next = user;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Remove a callback user.
|
|
|
|
*
|
|
|
|
* The callback function, p1, and p2 must be identical to those passed to
|
|
|
|
* content_add_user().
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_remove_user(struct content *c,
|
|
|
|
void (*callback)(content_msg msg, struct content *c, void *p1,
|
2004-04-25 03:42:32 +04:00
|
|
|
void *p2, union content_msg_data data),
|
2003-07-15 02:57:45 +04:00
|
|
|
void *p1, void *p2)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user, *next;
|
|
|
|
LOG(("content %s, user %p %p %p", c->url, callback, p1, p2));
|
|
|
|
|
|
|
|
/* user_list starts with a sentinel */
|
|
|
|
for (user = c->user_list; user->next != 0 &&
|
|
|
|
!(user->next->callback == callback &&
|
|
|
|
user->next->p1 == p1 &&
|
|
|
|
user->next->p2 == p2); user = user->next)
|
|
|
|
;
|
|
|
|
if (user->next == 0) {
|
|
|
|
LOG(("user not found in list"));
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
next = user->next;
|
|
|
|
user->next = next->next;
|
|
|
|
xfree(next);
|
|
|
|
|
|
|
|
/* if there are now no users, stop any loading in progress
|
|
|
|
* and destroy content structure if not in state READY or DONE */
|
|
|
|
if (c->user_list->next == 0) {
|
|
|
|
LOG(("no users for %p %s", c, c->url));
|
2004-01-26 17:16:23 +03:00
|
|
|
if (c->fetch != 0) {
|
2003-06-17 23:24:21 +04:00
|
|
|
fetch_abort(c->fetch);
|
2004-01-26 17:16:23 +03:00
|
|
|
c->fetch = 0;
|
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
if (c->status < CONTENT_STATUS_READY) {
|
2003-07-16 21:38:46 +04:00
|
|
|
if (c->cache)
|
|
|
|
cache_destroy(c);
|
2003-06-17 23:24:21 +04:00
|
|
|
content_destroy(c);
|
2003-07-16 21:38:46 +04:00
|
|
|
} else {
|
|
|
|
if (c->cache)
|
|
|
|
cache_freeable(c);
|
2004-01-26 17:16:23 +03:00
|
|
|
else
|
|
|
|
content_destroy(c);
|
2003-07-16 21:38:46 +04:00
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Send a message to all users.
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
2004-04-25 03:42:32 +04:00
|
|
|
void content_broadcast(struct content *c, content_msg msg,
|
|
|
|
union content_msg_data data)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user, *next;
|
2004-03-28 19:41:50 +04:00
|
|
|
c->lock++;
|
2003-06-17 23:24:21 +04:00
|
|
|
for (user = c->user_list->next; user != 0; user = next) {
|
|
|
|
next = user->next; /* user may be destroyed during callback */
|
|
|
|
if (user->callback != 0)
|
2004-04-25 03:42:32 +04:00
|
|
|
user->callback(msg, c, user->p1, user->p2, data);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
2004-01-26 17:16:23 +03:00
|
|
|
if (--(c->lock) == 0 && c->destroy_pending)
|
|
|
|
content_destroy(c);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
2003-07-15 02:57:45 +04:00
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/**
|
|
|
|
* Add an instance to a content.
|
|
|
|
*
|
|
|
|
* Calls the add_instance function for the content.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 02:57:45 +04:00
|
|
|
void content_add_instance(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params, void **state)
|
|
|
|
{
|
|
|
|
assert(c != 0);
|
|
|
|
assert(c->type < CONTENT_UNKNOWN);
|
|
|
|
LOG(("content %s", c->url));
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].add_instance)
|
2003-07-15 02:57:45 +04:00
|
|
|
handler_map[c->type].add_instance(c, bw, page, box, params, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/**
|
|
|
|
* Remove an instance from a content.
|
|
|
|
*
|
|
|
|
* Calls the remove_instance function for the content.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 02:57:45 +04:00
|
|
|
void content_remove_instance(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params, void **state)
|
|
|
|
{
|
|
|
|
assert(c != 0);
|
|
|
|
assert(c->type < CONTENT_UNKNOWN);
|
|
|
|
LOG(("content %s", c->url));
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].remove_instance)
|
2003-07-15 02:57:45 +04:00
|
|
|
handler_map[c->type].remove_instance(c, bw, page, box, params, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/**
|
|
|
|
* Reshape an instance of a content.
|
|
|
|
*
|
|
|
|
* Calls the reshape_instance function for the content.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 02:57:45 +04:00
|
|
|
void content_reshape_instance(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params, void **state)
|
|
|
|
{
|
|
|
|
assert(c != 0);
|
|
|
|
assert(c->type < CONTENT_UNKNOWN);
|
|
|
|
LOG(("content %s", c->url));
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].reshape_instance)
|
2003-07-15 02:57:45 +04:00
|
|
|
handler_map[c->type].reshape_instance(c, bw, page, box, params, state);
|
|
|
|
}
|
|
|
|
|