2003-06-30 16:44:03 +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-06-30 16:44:03 +04:00
|
|
|
* Copyright 2003 Philip Pemberton <philpem@users.sourceforge.net>
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** \file
|
|
|
|
* Content handling (interface).
|
|
|
|
*
|
|
|
|
* The content functions manipulate struct contents, which correspond to URLs.
|
|
|
|
*
|
|
|
|
* Each content has a type. The type is used to call a specific implementation
|
|
|
|
* of functions such as content_process_data().
|
|
|
|
*
|
2004-06-11 00:41:26 +04:00
|
|
|
* The source data fetched from the URL is placed in the source_data buffer as
|
|
|
|
* it arrives.
|
|
|
|
*
|
2003-09-08 01:08:13 +04:00
|
|
|
* Contents have an associated set of users, which are informed by a callback
|
|
|
|
* when the state of the content changes or something interesting happens.
|
|
|
|
*
|
|
|
|
* Optionally, contents may have instances (depending on type). Instances
|
|
|
|
* represent copies of the same URL, for example if a page is open in two
|
|
|
|
* windows, or a page contains the same image twice.
|
2004-06-11 00:41:26 +04:00
|
|
|
*
|
|
|
|
* The status of a content follows a fixed order. Certain content functions
|
|
|
|
* change the state, and each change of state results in a message to all users
|
|
|
|
* of the content. The diagram below shows this:
|
|
|
|
* \dot
|
|
|
|
* digraph status {
|
|
|
|
* node [shape=plaintext, fontname=Helvetica, fontsize=9];
|
|
|
|
* edge [fontname=Helvetica, fontsize=9];
|
|
|
|
*
|
|
|
|
* content_create -> TYPE_UNKNOWN [style=bold];
|
|
|
|
* TYPE_UNKNOWN -> content_set_type [style=bold];
|
|
|
|
* content_set_type -> LOADING [label=MSG_LOADING, style=bold];
|
2004-08-12 02:08:26 +04:00
|
|
|
* content_set_type -> LOADING [label="MSG_NEWPTR\nMSG_LOADING"];
|
2004-06-11 00:41:26 +04:00
|
|
|
* content_set_type -> ERROR [label=MSG_ERROR];
|
|
|
|
* LOADING -> content_process_data [style=bold];
|
|
|
|
* content_process_data -> LOADING [style=bold];
|
|
|
|
* content_process_data -> ERROR [label=MSG_ERROR];
|
|
|
|
* LOADING -> content_convert [style=bold];
|
|
|
|
* content_convert -> READY [label=MSG_READY, style=bold];
|
|
|
|
* content_convert -> DONE [label="MSG_READY\nMSG_DONE", style=bold];
|
|
|
|
* content_convert -> ERROR [label=MSG_ERROR];
|
|
|
|
* READY -> READY [style=bold];
|
|
|
|
* READY -> DONE [label=MSG_DONE, style=bold];
|
2004-06-21 03:09:52 +04:00
|
|
|
* READY -> content_stop;
|
|
|
|
* content_stop -> DONE [label=MSG_DONE];
|
2004-06-11 00:41:26 +04:00
|
|
|
*
|
|
|
|
* TYPE_UNKNOWN [shape=ellipse];
|
|
|
|
* LOADING [shape=ellipse];
|
|
|
|
* READY [shape=ellipse];
|
|
|
|
* DONE [shape=ellipse];
|
|
|
|
* ERROR [shape=ellipse];
|
|
|
|
* }
|
|
|
|
* \enddot
|
|
|
|
*
|
|
|
|
* To implement a new content type, implement the following functions:
|
|
|
|
*
|
|
|
|
* - <i>type</i>_create(): called to initialise type-specific fields in the
|
|
|
|
* content structure. Optional.
|
|
|
|
*
|
|
|
|
* - <i>type</i>_process_data(): called when some data arrives. Optional.
|
|
|
|
*
|
|
|
|
* - <i>type</i>_convert(): called when data has finished arriving. The
|
|
|
|
* content needs to be converted for display. Must set the status to one of
|
|
|
|
* CONTENT_STATUS_READY or CONTENT_STATUS_DONE if no error occurs. Optional,
|
|
|
|
* but probably required for non-trivial types.
|
|
|
|
*
|
|
|
|
* - <i>type</i>_reformat(): called when, for example, the window has been
|
|
|
|
* resized, and the content needs reformatting for the new size. Optional.
|
|
|
|
*
|
|
|
|
* - <i>type</i>_destroy(): called when the content is being destroyed. Free all
|
|
|
|
* resources. Optional.
|
|
|
|
*
|
|
|
|
* - <i>type</i>_redraw(): called to plot the content to screen.
|
|
|
|
*
|
2004-06-21 03:09:52 +04:00
|
|
|
* - <i>type</i>_stop(): called when the user interrupts in status
|
|
|
|
* CONTENT_STATUS_READY. Must stop any processing and set the status to
|
|
|
|
* CONTENT_STATUS_DONE. Required iff the status can be CONTENT_STATUS_READY.
|
|
|
|
*
|
2004-08-12 02:08:26 +04:00
|
|
|
* - <i>type</i>_open(): called when a window containing the content is
|
|
|
|
* opened. Probably only makes sense if no_share is set for the content type
|
|
|
|
* in handler_map. Optional.
|
|
|
|
*
|
|
|
|
* - <i>type</i>_close(): called when the window containing the content is
|
|
|
|
* closed. Optional.
|
2004-06-11 00:41:26 +04:00
|
|
|
*
|
|
|
|
* - <i>type</i>_create(), <i>type</i>_process_data(), <i>type</i>_convert():
|
|
|
|
* if an error occurs, must broadcast CONTENT_MSG_ERROR and return false.
|
|
|
|
* Optionally use warn_user() for serious errors. The _destroy function will
|
|
|
|
* be called soon after.
|
2003-09-08 01:08:13 +04:00
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
#ifndef _NETSURF_DESKTOP_CONTENT_H_
|
|
|
|
#define _NETSURF_DESKTOP_CONTENT_H_
|
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2004-01-24 20:08:16 +03:00
|
|
|
#include "netsurf/content/content_type.h"
|
2003-04-04 19:19:32 +04:00
|
|
|
#include "netsurf/css/css.h"
|
2003-09-08 01:08:13 +04:00
|
|
|
#include "netsurf/render/html.h"
|
2004-03-27 03:54:03 +03:00
|
|
|
#ifdef WITH_JPEG
|
2004-09-04 02:44:48 +04:00
|
|
|
#include "netsurf/image/jpeg.h"
|
2004-03-27 03:54:03 +03:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_GIF
|
2004-10-05 03:54:42 +04:00
|
|
|
#include "netsurf/image/gif.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
2003-09-08 01:08:13 +04:00
|
|
|
#include "netsurf/riscos/plugin.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-07-16 23:47:03 +04:00
|
|
|
#ifdef WITH_MNG
|
2004-09-04 02:44:48 +04:00
|
|
|
#include "netsurf/image/mng.h"
|
2004-07-16 23:47:03 +04:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#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"
|
2003-09-08 01:08:13 +04:00
|
|
|
#endif
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
|
2004-09-04 02:44:48 +04:00
|
|
|
struct bitmap;
|
2004-08-11 23:02:32 +04:00
|
|
|
struct box;
|
|
|
|
struct browser_window;
|
|
|
|
struct content;
|
2004-06-21 19:09:59 +04:00
|
|
|
struct fetch;
|
2004-08-11 23:02:32 +04:00
|
|
|
struct object_params;
|
2004-06-21 19:09:59 +04:00
|
|
|
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** Used in callbacks to indicate what has occurred. */
|
2003-06-17 23:24:21 +04:00
|
|
|
typedef enum {
|
2003-09-08 01:08:13 +04:00
|
|
|
CONTENT_MSG_LOADING, /**< fetching or converting */
|
|
|
|
CONTENT_MSG_READY, /**< may be displayed */
|
|
|
|
CONTENT_MSG_DONE, /**< finished */
|
|
|
|
CONTENT_MSG_ERROR, /**< error occurred */
|
|
|
|
CONTENT_MSG_STATUS, /**< new status string */
|
2003-09-11 01:44:11 +04:00
|
|
|
CONTENT_MSG_REDIRECT, /**< replacement URL */
|
2003-10-25 23:20:13 +04:00
|
|
|
CONTENT_MSG_REFORMAT, /**< content_reformat done */
|
2004-03-21 15:50:10 +03:00
|
|
|
CONTENT_MSG_REDRAW, /**< needs redraw (eg. new animation frame) */
|
2004-08-11 23:02:32 +04:00
|
|
|
CONTENT_MSG_NEWPTR, /**< address of structure has changed */
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
2003-10-25 23:20:13 +04:00
|
|
|
CONTENT_MSG_AUTH /**< authentication required */
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-06-17 23:24:21 +04:00
|
|
|
} content_msg;
|
|
|
|
|
2004-04-25 03:42:32 +04:00
|
|
|
/** Extra data for some content_msg messages. */
|
|
|
|
union content_msg_data {
|
|
|
|
const char *error; /**< Error message, for CONTENT_MSG_ERROR. */
|
|
|
|
char *redirect; /**< Redirect URL, for CONTENT_MSG_REDIRECT. */
|
|
|
|
/** Area of content which needs redrawing, for CONTENT_MSG_REDRAW. */
|
|
|
|
struct {
|
2004-06-03 00:58:16 +04:00
|
|
|
float x, y, width, height;
|
2004-04-25 03:42:32 +04:00
|
|
|
/** Redraw the area fully. If false, object must be set,
|
|
|
|
* and only the object will be redrawn. */
|
|
|
|
bool full_redraw;
|
|
|
|
/** Object to redraw if full_redraw is false. */
|
|
|
|
struct content *object;
|
|
|
|
/** Coordinates to plot object at. */
|
2004-06-03 00:58:16 +04:00
|
|
|
float object_x, object_y;
|
2004-04-26 17:47:51 +04:00
|
|
|
/** Dimensions to plot object with. */
|
2004-06-03 00:58:16 +04:00
|
|
|
float object_width, object_height;
|
2004-04-25 03:42:32 +04:00
|
|
|
} redraw;
|
|
|
|
char *auth_realm; /**< Realm, for CONTENT_MSG_AUTH. */
|
|
|
|
};
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** Linked list of users of a content. */
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content_user
|
|
|
|
{
|
|
|
|
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-06-17 23:24:21 +04:00
|
|
|
void *p1;
|
|
|
|
void *p2;
|
2004-06-21 03:09:52 +04:00
|
|
|
bool stop;
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content_user *next;
|
|
|
|
};
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** Corresponds to a single URL. */
|
|
|
|
struct content {
|
|
|
|
char *url; /**< URL, in standard form as from url_join. */
|
|
|
|
content_type type; /**< Type of content. */
|
|
|
|
char *mime_type; /**< Original MIME type of data, or 0. */
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CONTENT_STATUS_TYPE_UNKNOWN, /**< Type not yet known. */
|
|
|
|
CONTENT_STATUS_LOADING, /**< Content is being fetched or
|
|
|
|
converted and is not safe to display. */
|
|
|
|
CONTENT_STATUS_READY, /**< Some parts of content still being
|
|
|
|
loaded, but can be displayed. */
|
2004-06-11 00:41:26 +04:00
|
|
|
CONTENT_STATUS_DONE, /**< All finished. */
|
|
|
|
CONTENT_STATUS_ERROR /**< Error occurred, content will be
|
|
|
|
destroyed imminently. */
|
2003-09-08 01:08:13 +04:00
|
|
|
} status; /**< Current status. */
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
int width, height; /**< Dimensions, if applicable. */
|
|
|
|
int available_width; /**< Available width (eg window width). */
|
2003-09-08 01:08:13 +04:00
|
|
|
|
|
|
|
/** Data dependent on type. */
|
|
|
|
union {
|
|
|
|
struct content_html_data html;
|
|
|
|
struct content_css_data css;
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_JPEG
|
2003-09-08 01:08:13 +04:00
|
|
|
struct content_jpeg_data jpeg;
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-04-25 03:42:32 +04:00
|
|
|
#ifdef WITH_GIF
|
|
|
|
struct content_gif_data gif;
|
|
|
|
#endif
|
2004-07-16 23:47:03 +04:00
|
|
|
#ifdef WITH_MNG
|
|
|
|
struct content_mng_data mng;
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_SPRITE
|
2003-09-11 02:27:15 +04:00
|
|
|
struct content_sprite_data sprite;
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
2003-09-11 02:27:15 +04:00
|
|
|
struct content_draw_data draw;
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
2003-09-08 01:08:13 +04:00
|
|
|
struct content_plugin_data plugin;
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2003-09-08 01:08:13 +04:00
|
|
|
} data;
|
|
|
|
|
2004-09-04 02:44:48 +04:00
|
|
|
/** Bitmap, for various image contents. */
|
|
|
|
struct bitmap *bitmap;
|
|
|
|
|
2004-06-21 19:09:59 +04:00
|
|
|
/** This content may be given to new users. Indicates that the content
|
|
|
|
* was fetched using a simple GET, has not expired, and may be
|
|
|
|
* shared between users. */
|
|
|
|
bool fresh;
|
|
|
|
|
|
|
|
unsigned int size; /**< Estimated size of all data
|
2003-09-08 01:08:13 +04:00
|
|
|
associated with this content. */
|
|
|
|
char *title; /**< Title for browser window. */
|
|
|
|
unsigned int active; /**< Number of child fetches or
|
|
|
|
conversions currently in progress. */
|
|
|
|
struct content_user *user_list; /**< List of users. */
|
|
|
|
char status_message[80]; /**< Text for status bar. */
|
|
|
|
|
|
|
|
struct fetch *fetch; /**< Associated fetch, or 0. */
|
2004-03-11 05:19:14 +03:00
|
|
|
char *source_data; /**< Source data, as received. */
|
|
|
|
unsigned long source_size; /**< Amount of data fetched so far. */
|
2003-09-08 01:08:13 +04:00
|
|
|
unsigned long total_size; /**< Total data size, 0 if unknown. */
|
2004-01-26 17:16:23 +03:00
|
|
|
|
|
|
|
bool no_error_pages; /**< Used by fetchcache(). */
|
2005-01-03 05:09:20 +03:00
|
|
|
bool download; /**< Used by fetchcache(). */
|
2004-06-11 00:41:26 +04:00
|
|
|
|
|
|
|
/** Array of first n rendering errors or warnings. */
|
|
|
|
struct {
|
|
|
|
const char *token;
|
|
|
|
unsigned int line; /**< Line no, 0 if not applicable. */
|
|
|
|
} error_list[40];
|
|
|
|
unsigned int error_count; /**< Number of valid error entries. */
|
|
|
|
|
|
|
|
struct content *prev; /**< Previous in global content list. */
|
|
|
|
struct content *next; /**< Next in global content list. */
|
2003-02-09 15:58:15 +03:00
|
|
|
};
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
extern struct content *content_list;
|
|
|
|
extern const char *content_type_name[];
|
|
|
|
extern const char *content_status_name[];
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
content_type content_lookup(const char *mime_type);
|
2004-06-11 00:41:26 +04:00
|
|
|
struct content * content_create(const char *url);
|
2004-06-21 19:09:59 +04:00
|
|
|
struct content * content_get(const char *url);
|
2004-06-11 00:41:26 +04:00
|
|
|
bool content_set_type(struct content *c, content_type type,
|
2004-05-05 20:33:15 +04:00
|
|
|
const char *mime_type, const char *params[]);
|
2004-06-05 19:03:59 +04:00
|
|
|
void content_set_status(struct content *c, const char *status_message, ...);
|
2004-06-22 21:37:51 +04:00
|
|
|
bool content_process_data(struct content *c, const char *data,
|
|
|
|
unsigned int size);
|
2004-06-11 00:41:26 +04:00
|
|
|
void content_convert(struct content *c, int width, int height);
|
|
|
|
void content_reformat(struct content *c, int width, int height);
|
|
|
|
void content_clean(void);
|
2004-01-23 23:46:29 +03:00
|
|
|
void content_reset(struct content *c);
|
2004-07-30 20:16:07 +04:00
|
|
|
void content_quit(void);
|
2004-08-11 20:26:13 +04:00
|
|
|
bool content_redraw(struct content *c, int x, int y,
|
2004-06-11 00:41:26 +04:00
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2004-08-15 23:06:24 +04:00
|
|
|
float scale, unsigned long background_colour);
|
2005-01-02 06:58:21 +03:00
|
|
|
bool content_add_user(struct content *c,
|
2003-06-17 23:24:21 +04:00
|
|
|
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);
|
2004-06-23 19:41:50 +04:00
|
|
|
struct content_user * content_find_user(struct content *c,
|
|
|
|
void (*callback)(content_msg msg, struct content *c, void *p1,
|
|
|
|
void *p2, union content_msg_data data),
|
|
|
|
void *p1, void *p2);
|
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);
|
2004-04-25 03:42:32 +04:00
|
|
|
void content_broadcast(struct content *c, content_msg msg,
|
|
|
|
union content_msg_data data);
|
2004-06-21 03:09:52 +04:00
|
|
|
void content_stop(struct content *c,
|
|
|
|
void (*callback)(content_msg msg, struct content *c, void *p1,
|
|
|
|
void *p2, union content_msg_data data),
|
|
|
|
void *p1, void *p2);
|
2004-08-12 02:08:26 +04:00
|
|
|
void content_open(struct content *c, struct browser_window *bw,
|
2003-07-15 02:57:45 +04:00
|
|
|
struct content *page, struct box *box,
|
2004-08-12 02:08:26 +04:00
|
|
|
struct object_params *params);
|
|
|
|
void content_close(struct content *c);
|
2004-06-11 00:41:26 +04:00
|
|
|
void content_add_error(struct content *c, const char *token,
|
|
|
|
unsigned int line);
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
#endif
|