2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2007-01-13 03:21:15 +03:00
|
|
|
* Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
|
2003-06-30 16:44:03 +04:00
|
|
|
* Copyright 2003 Philip Pemberton <philpem@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
#ifndef _NETSURF_DESKTOP_CONTENT_H_
|
|
|
|
#define _NETSURF_DESKTOP_CONTENT_H_
|
|
|
|
|
2005-08-21 16:04:18 +04:00
|
|
|
#include <stdint.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "content/content_type.h"
|
|
|
|
#include "css/css.h"
|
|
|
|
#include "render/html.h"
|
|
|
|
#include "render/textplain.h"
|
2004-03-27 03:54:03 +03:00
|
|
|
#ifdef WITH_JPEG
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/jpeg.h"
|
2004-03-27 03:54:03 +03:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_GIF
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/gif.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/bmp.h"
|
|
|
|
#include "image/ico.h"
|
2006-02-25 21:51:51 +03:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PLUGIN
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/plugin.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-07-16 23:47:03 +04:00
|
|
|
#ifdef WITH_MNG
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/mng.h"
|
2004-07-16 23:47:03 +04:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_SPRITE
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/sprite.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/draw.h"
|
2003-09-08 01:08:13 +04:00
|
|
|
#endif
|
2005-12-10 17:31:33 +03:00
|
|
|
#ifdef WITH_ARTWORKS
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/artworks.h"
|
2005-12-10 17:31:33 +03:00
|
|
|
#endif
|
2007-07-18 18:49:26 +04:00
|
|
|
#ifdef WITH_NS_SVG
|
2007-07-13 07:54:47 +04:00
|
|
|
#include "image/svg.h"
|
2007-07-18 18:49:26 +04:00
|
|
|
#endif
|
2007-07-18 21:58:35 +04:00
|
|
|
#ifdef WITH_RSVG
|
|
|
|
#include "image/rsvg.h"
|
|
|
|
#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;
|
2006-02-06 03:10:09 +03:00
|
|
|
struct cache_data;
|
2004-08-11 23:02:32 +04:00
|
|
|
struct content;
|
2004-06-21 19:09:59 +04:00
|
|
|
struct fetch;
|
2004-08-11 23:02:32 +04:00
|
|
|
struct object_params;
|
2006-02-23 18:06:54 +03:00
|
|
|
struct ssl_cert_info;
|
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-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 */
|
2006-01-25 09:52:38 +03:00
|
|
|
CONTENT_MSG_REFRESH, /**< wants refresh */
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
2006-02-23 18:06:54 +03:00
|
|
|
CONTENT_MSG_AUTH, /**< authentication required */
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_SSL
|
|
|
|
CONTENT_MSG_SSL /**< SSL cert verify failed */
|
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;
|
2006-02-23 18:06:54 +03:00
|
|
|
const char *auth_realm; /**< Realm, for CONTENT_MSG_AUTH. */
|
2006-01-25 09:52:38 +03:00
|
|
|
int delay; /**< Minimum delay, for CONTENT_MSG_REFRESH */
|
2006-02-23 18:06:54 +03:00
|
|
|
struct {
|
|
|
|
/** Certificate chain (certs[0] == server) */
|
|
|
|
const struct ssl_cert_info *certs;
|
|
|
|
unsigned long num; /**< Number of certs in chain */
|
|
|
|
} ssl;
|
2004-04-25 03:42:32 +04:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
{
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c, intptr_t p1,
|
|
|
|
intptr_t p2, union content_msg_data data);
|
|
|
|
intptr_t p1;
|
|
|
|
intptr_t 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;
|
2006-02-13 02:07:28 +03:00
|
|
|
struct content_textplain_data textplain;
|
2003-09-08 01:08:13 +04:00
|
|
|
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
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
struct content_bmp_data bmp;
|
2006-02-26 05:25:19 +03:00
|
|
|
struct content_ico_data ico;
|
2006-02-25 21:51:51 +03:00
|
|
|
#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;
|
2005-12-10 17:31:33 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_ARTWORKS
|
|
|
|
struct content_artworks_data artworks;
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2007-07-18 18:49:26 +04:00
|
|
|
#ifdef WITH_NS_SVG
|
2007-07-13 07:54:47 +04:00
|
|
|
struct content_svg_data svg;
|
2007-07-18 21:58:35 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_RSVG
|
|
|
|
struct content_rsvg_data rsvg;
|
2007-07-18 18:49:26 +04:00
|
|
|
#endif
|
2003-09-08 01:08:13 +04:00
|
|
|
} data;
|
|
|
|
|
2006-01-25 09:52:38 +03:00
|
|
|
/**< URL for refresh request, in standard form as from url_join. */
|
|
|
|
char *refresh;
|
|
|
|
|
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;
|
2006-02-06 03:10:09 +03:00
|
|
|
struct cache_data *cache_data; /**< Cache control data */
|
2007-01-30 18:32:31 +03:00
|
|
|
unsigned int time; /**< Creation time, if TYPE_UNKNOWN,
|
2007-01-13 03:21:15 +03:00
|
|
|
LOADING or READY,
|
|
|
|
otherwise total time. */
|
2004-06-21 19:09:59 +04:00
|
|
|
|
|
|
|
unsigned int size; /**< Estimated size of all data
|
2006-12-04 01:34:26 +03:00
|
|
|
associated with this content, except
|
|
|
|
alloced as talloc children of this. */
|
2003-09-08 01:08:13 +04:00
|
|
|
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. */
|
2007-01-13 03:21:15 +03:00
|
|
|
char status_message[120]; /**< Full text for status bar. */
|
|
|
|
char sub_status[80]; /**< Status of content. */
|
2005-07-06 02:43:38 +04:00
|
|
|
/** Content is being processed: data structures may be inconsistent
|
|
|
|
* and content must not be redrawn or modified. */
|
|
|
|
bool locked;
|
2003-09-08 01:08:13 +04:00
|
|
|
|
|
|
|
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. */
|
2005-04-05 06:36:33 +04:00
|
|
|
unsigned long source_allocated; /**< Amount of space allocated so far. */
|
2003-09-08 01:08:13 +04:00
|
|
|
unsigned long total_size; /**< Total data size, 0 if unknown. */
|
2007-01-13 03:21:15 +03:00
|
|
|
long http_code; /**< HTTP status code, 0 if not HTTP. */
|
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(). */
|
Rework handling of HTTP redirects -- we now count the number of redirects followed for a given item and abort if a fixed limit is reached. This fixes sites which have pages that redirect to themselves.
Redirect handling is now transparent to clients of fetchcache.
The new scheme works as follows:
1) Request content for URL (fetchcache()
2) Start fetch of content (fetchcache_go()
3) If no redirect, continue through LOADING, READY, DONE etc. states as before
If redirect, receive NEWPTR for each redirect that occurs, then continue
through LOADING, READY, DONE etc. states as before.
The upshot of this is that redirects result in extra contents being created. It also means that, until LOADING has been received, the content (and thus the URL being fetched) may change. Therefore, fetchcache clients should expect to have to deal with transient data prior to LOADING occurring.
As a necessary side-effect of this, the HTML object URLs and CSS @import URLs are no longer stored alongside the relevant contents. These URLs can be accessed by interrogating the url member of struct content anyway, so it was a rather redundant scheme before.
svn path=/trunk/netsurf/; revision=3787
2008-01-28 04:35:00 +03:00
|
|
|
unsigned int redirect_count; /**< 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);
|
2006-02-06 03:10:09 +03:00
|
|
|
struct content * content_get_ready(const char *url);
|
2007-08-07 07:55:18 +04:00
|
|
|
bool content_can_reformat(struct content *c);
|
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);
|
2007-01-13 03:21:15 +03:00
|
|
|
void content_set_done(struct content *c);
|
2004-06-11 00:41:26 +04:00
|
|
|
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);
|
2006-02-21 23:49:12 +03:00
|
|
|
bool content_redraw_tiled(struct content *c, int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
|
|
|
float scale, unsigned long background_colour,
|
|
|
|
bool repeat_x, bool repeat_y);
|
2005-01-02 06:58:21 +03:00
|
|
|
bool content_add_user(struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t p2);
|
2004-06-23 19:41:50 +04:00
|
|
|
struct content_user * content_find_user(struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t p2);
|
2003-06-17 23:24:21 +04:00
|
|
|
void content_remove_user(struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t 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,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t p2);
|
2004-08-12 02:08:26 +04:00
|
|
|
void content_open(struct content *c, struct browser_window *bw,
|
2005-10-31 00:22:19 +03:00
|
|
|
struct content *page, unsigned int index, 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
|