clean up content headers and documentation comments

pure formatting and documentation changes, no code difference
This commit is contained in:
Vincent Sanders 2020-05-06 23:38:50 +01:00
parent c2f9bcac19
commit 5f8b1497e1
11 changed files with 672 additions and 455 deletions

View File

@ -49,84 +49,48 @@ const char * const content_status_name[] = {
"ERROR"
};
static nserror content_llcache_callback(llcache_handle *llcache,
const llcache_event *event, void *pw);
static void content_convert(struct content *c);
/**
* Initialise a new content structure.
* All data has arrived, convert for display.
*
* \param c Content to initialise
* \param handler Content handler
* \param imime_type MIME type of content
* \param params HTTP parameters
* \param llcache Source data handle
* \param fallback_charset Fallback charset
* \param quirks Quirkiness of content
* \return NSERROR_OK on success, appropriate error otherwise
* 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
* CONTENT_STATUS_DONE, and CONTENT_MSG_READY then CONTENT_MSG_DONE are sent.
* - If the conversion fails, CONTENT_MSG_ERROR is sent. The content will soon
* be destroyed and must no longer be used.
*/
nserror content__init(struct content *c, const content_handler *handler,
lwc_string *imime_type, const struct http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
bool quirks)
static void content_convert(struct content *c)
{
struct content_user *user_sentinel;
nserror error;
assert(c);
assert(c->status == CONTENT_STATUS_LOADING ||
c->status == CONTENT_STATUS_ERROR);
NSLOG(netsurf, INFO, "url "URL_FMT_SPC" -> %p",
nsurl_access_log(llcache_handle_get_url(llcache)), c);
if (c->status != CONTENT_STATUS_LOADING)
return;
user_sentinel = calloc(1, sizeof(struct content_user));
if (user_sentinel == NULL) {
return NSERROR_NOMEM;
if (c->locked == true)
return;
NSLOG(netsurf, INFO, "content "URL_FMT_SPC" (%p)",
nsurl_access_log(llcache_handle_get_url(c->llcache)), c);
if (c->handler->data_complete != NULL) {
c->locked = true;
if (c->handler->data_complete(c) == false) {
content_set_error(c);
}
if (fallback_charset != NULL) {
c->fallback_charset = strdup(fallback_charset);
if (c->fallback_charset == NULL) {
free(user_sentinel);
return NSERROR_NOMEM;
/* Conversion to the READY state will unlock the content */
} else {
content_set_ready(c);
content_set_done(c);
}
}
c->llcache = llcache;
c->mime_type = lwc_string_ref(imime_type);
c->handler = handler;
c->status = CONTENT_STATUS_LOADING;
c->width = 0;
c->height = 0;
c->available_width = 0;
c->available_height = 0;
c->quirks = quirks;
c->refresh = 0;
nsu_getmonotonic_ms(&c->time);
c->size = 0;
c->title = NULL;
c->active = 0;
user_sentinel->callback = NULL;
user_sentinel->pw = NULL;
user_sentinel->next = NULL;
c->user_list = user_sentinel;
c->sub_status[0] = 0;
c->locked = false;
c->total_size = 0;
c->http_code = 0;
content_set_status(c, messages_get("Loading"));
/* Finally, claim low-level cache events */
error = llcache_handle_change_callback(llcache,
content_llcache_callback, c);
if (error != NSERROR_OK) {
lwc_string_unref(c->mime_type);
return error;
}
return NSERROR_OK;
}
/**
* Handler for low-level cache events
*
@ -135,7 +99,8 @@ nserror content__init(struct content *c, const content_handler *handler,
* \param pw Pointer to our context
* \return NSERROR_OK on success, appropriate error otherwise
*/
nserror content_llcache_callback(llcache_handle *llcache,
static nserror
content_llcache_callback(llcache_handle *llcache,
const llcache_event *event, void *pw)
{
struct content *c = pw;
@ -196,23 +161,12 @@ nserror content_llcache_callback(llcache_handle *llcache,
return error;
}
/**
* Get whether a content can reformat
* update content status message
*
* \param h content to check
* \return whether the content can reformat
* \param c the content to update.
*/
bool content_can_reformat(hlcache_handle *h)
{
struct content *c = hlcache_handle_get_content(h);
if (c == NULL)
return false;
return (c->handler->reformat != NULL);
}
static void content_update_status(struct content *c)
{
if (c->status == CONTENT_STATUS_LOADING ||
@ -230,15 +184,85 @@ static void content_update_status(struct content *c)
}
/**
* Updates content with new status.
*
* The textual status contained in the content is updated with given string.
*
* \param c The content to set status in.
* \param status_message new textual status
*/
/* exported interface documented in content/protected.h */
nserror
content__init(struct content *c,
const content_handler *handler,
lwc_string *imime_type,
const struct http_parameter *params,
llcache_handle *llcache,
const char *fallback_charset,
bool quirks)
{
struct content_user *user_sentinel;
nserror error;
NSLOG(netsurf, INFO, "url "URL_FMT_SPC" -> %p",
nsurl_access_log(llcache_handle_get_url(llcache)), c);
user_sentinel = calloc(1, sizeof(struct content_user));
if (user_sentinel == NULL) {
return NSERROR_NOMEM;
}
if (fallback_charset != NULL) {
c->fallback_charset = strdup(fallback_charset);
if (c->fallback_charset == NULL) {
free(user_sentinel);
return NSERROR_NOMEM;
}
}
c->llcache = llcache;
c->mime_type = lwc_string_ref(imime_type);
c->handler = handler;
c->status = CONTENT_STATUS_LOADING;
c->width = 0;
c->height = 0;
c->available_width = 0;
c->available_height = 0;
c->quirks = quirks;
c->refresh = 0;
nsu_getmonotonic_ms(&c->time);
c->size = 0;
c->title = NULL;
c->active = 0;
user_sentinel->callback = NULL;
user_sentinel->pw = NULL;
user_sentinel->next = NULL;
c->user_list = user_sentinel;
c->sub_status[0] = 0;
c->locked = false;
c->total_size = 0;
c->http_code = 0;
content_set_status(c, messages_get("Loading"));
/* Finally, claim low-level cache events */
error = llcache_handle_change_callback(llcache,
content_llcache_callback, c);
if (error != NSERROR_OK) {
lwc_string_unref(c->mime_type);
return error;
}
return NSERROR_OK;
}
/* exported interface documented in content/content.h */
bool content_can_reformat(hlcache_handle *h)
{
struct content *c = hlcache_handle_get_content(h);
if (c == NULL)
return false;
return (c->handler->reformat != NULL);
}
/* exported interface documented in content/protected.h */
void content_set_status(struct content *c, const char *status_message)
{
size_t len = strlen(status_message);
@ -253,51 +277,7 @@ void content_set_status(struct content *c, const char *status_message)
}
/**
* 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
* CONTENT_STATUS_DONE, and CONTENT_MSG_READY then CONTENT_MSG_DONE are sent.
* - If the conversion fails, CONTENT_MSG_ERROR is sent. The content will soon
* be destroyed and must no longer be used.
*/
void content_convert(struct content *c)
{
assert(c);
assert(c->status == CONTENT_STATUS_LOADING ||
c->status == CONTENT_STATUS_ERROR);
if (c->status != CONTENT_STATUS_LOADING)
return;
if (c->locked == true)
return;
NSLOG(netsurf, INFO, "content "URL_FMT_SPC" (%p)",
nsurl_access_log(llcache_handle_get_url(c->llcache)), c);
if (c->handler->data_complete != NULL) {
c->locked = true;
if (c->handler->data_complete(c) == false) {
content_set_error(c);
}
/* Conversion to the READY state will unlock the content */
} else {
content_set_ready(c);
content_set_done(c);
}
}
/**
* Put a content in status CONTENT_STATUS_READY and unlock the content.
*/
/* exported interface documented in content/protected.h */
void content_set_ready(struct content *c)
{
/* The content must be locked at this point, as it can only
@ -310,10 +290,8 @@ void content_set_ready(struct content *c)
content_broadcast(c, CONTENT_MSG_READY, NULL);
}
/**
* Put a content in status CONTENT_STATUS_DONE.
*/
/* exported interface documented in content/protected.h */
void content_set_done(struct content *c)
{
uint64_t now_ms;
@ -326,24 +304,16 @@ void content_set_done(struct content *c)
content_broadcast(c, CONTENT_MSG_DONE, NULL);
}
/**
* Put a content in status CONTENT_STATUS_ERROR and unlock the content.
*
* \note We expect the caller to broadcast an error report if needed.
*/
/* exported interface documented in content/protected.h */
void content_set_error(struct content *c)
{
c->locked = false;
c->status = CONTENT_STATUS_ERROR;
}
/**
* Reformat to new size.
*
* Calls the reformat function for the content.
*/
/* exported interface documented in content/content.h */
void content_reformat(hlcache_handle *h, bool background,
int width, int height)
{
@ -351,8 +321,10 @@ void content_reformat(hlcache_handle *h, bool background,
width, height);
}
void content__reformat(struct content *c, bool background,
int width, int height)
/* exported interface documented in content/protected.h */
void
content__reformat(struct content *c, bool background, int width, int height)
{
union content_msg_data data;
assert(c != 0);
@ -374,12 +346,7 @@ void content__reformat(struct content *c, bool background,
}
/**
* Destroy and free a content.
*
* Calls the destroy function for the content, and frees the structure.
*/
/* exported interface documented in content/content.h */
void content_destroy(struct content *c)
{
struct content_rfc5988_link *link;
@ -422,18 +389,12 @@ void content_destroy(struct content *c)
}
/**
* Handle mouse movements in a content window.
*
* \param h Content handle
* \param bw browser window
* \param mouse state of mouse buttons and modifier keys
* \param x coordinate of mouse
* \param y coordinate of mouse
*/
void content_mouse_track(hlcache_handle *h, struct browser_window *bw,
browser_mouse_state mouse, int x, int y)
/* exported interface documented in content/content.h */
void
content_mouse_track(hlcache_handle *h,
struct browser_window *bw,
browser_mouse_state mouse,
int x, int y)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != NULL);
@ -451,24 +412,12 @@ void content_mouse_track(hlcache_handle *h, struct browser_window *bw,
}
/**
* Handle mouse clicks and movements in a content window.
*
* \param h Content handle
* \param bw browser window
* \param mouse state of mouse buttons and modifier keys
* \param x coordinate of mouse
* \param y coordinate of mouse
*
* This function handles both hovering and clicking. It is important that the
* code path is identical (except that hovering doesn't carry out the action),
* so that the status bar reflects exactly what will happen. Having separate
* code paths opens the possibility that an attacker will make the status bar
* show some harmless action where clicking will be harmful.
*/
void content_mouse_action(hlcache_handle *h, struct browser_window *bw,
browser_mouse_state mouse, int x, int y)
/* exported interface documented in content/content.h */
void
content_mouse_action(hlcache_handle *h,
struct browser_window *bw,
browser_mouse_state mouse,
int x, int y)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != NULL);
@ -480,14 +429,7 @@ void content_mouse_action(hlcache_handle *h, struct browser_window *bw,
}
/**
* Handle keypresses.
*
* \param h Content handle
* \param key The UCS4 character codepoint
* \return true if key handled, false otherwise
*/
/* exported interface documented in content/content.h */
bool content_keypress(struct hlcache_handle *h, uint32_t key)
{
struct content *c = hlcache_handle_get_content(h);
@ -500,15 +442,7 @@ bool content_keypress(struct hlcache_handle *h, uint32_t key)
}
/**
* Request a redraw of an area of a content
*
* \param h high-level cache handle
* \param x x co-ord of left edge
* \param y y co-ord of top edge
* \param width Width of rectangle
* \param height Height of rectangle
*/
/* exported interface documented in content/content.h */
void content_request_redraw(struct hlcache_handle *h,
int x, int y, int width, int height)
{
@ -517,15 +451,7 @@ void content_request_redraw(struct hlcache_handle *h,
}
/**
* Request a redraw of an area of a content
*
* \param c Content
* \param x x co-ord of left edge
* \param y y co-ord of top edge
* \param width Width of rectangle
* \param height Height of rectangle
*/
/* exported interface, documented in content/protected.h */
void content__request_redraw(struct content *c,
int x, int y, int width, int height)
{
@ -542,6 +468,7 @@ void content__request_redraw(struct content *c,
content_broadcast(c, CONTENT_MSG_REDRAW, &data);
}
/* exported interface, documented in content/content.h */
bool content_exec(struct hlcache_handle *h, const char *src, size_t srclen)
{
@ -564,6 +491,7 @@ bool content_exec(struct hlcache_handle *h, const char *src, size_t srclen)
return c->handler->exec(c, src, srclen);
}
/* exported interface, documented in content/content.h */
bool content_saw_insecure_objects(struct hlcache_handle *h)
{
@ -620,9 +548,13 @@ bool content_saw_insecure_objects(struct hlcache_handle *h)
return false;
}
/* exported interface, documented in content/content.h */
bool content_redraw(hlcache_handle *h, struct content_redraw_data *data,
const struct rect *clip, const struct redraw_context *ctx)
bool
content_redraw(hlcache_handle *h,
struct content_redraw_data *data,
const struct rect *clip,
const struct redraw_context *ctx)
{
struct content *c = hlcache_handle_get_content(h);
@ -643,8 +575,10 @@ bool content_redraw(hlcache_handle *h, struct content_redraw_data *data,
/* exported interface, documented in content/content.h */
bool content_scaled_redraw(struct hlcache_handle *h,
int width, int height, const struct redraw_context *ctx)
bool
content_scaled_redraw(struct hlcache_handle *h,
int width, int height,
const struct redraw_context *ctx)
{
struct content *c = hlcache_handle_get_content(h);
struct redraw_context new_ctx = *ctx;
@ -710,20 +644,10 @@ bool content_scaled_redraw(struct hlcache_handle *h,
return plot_ok;
}
/**
* Register a user for callbacks.
*
* \param c the content to register
* \param callback the callback function
* \param pw callback private data
* \return true on success, false otherwise on memory exhaustion
*
* The callback will be called when content_broadcast() is
* called with the content.
*/
bool content_add_user(
struct content *c,
/* exported interface documented in content/content.h */
bool
content_add_user(struct content *c,
void (*callback)(
struct content *c,
content_msg msg,
@ -751,15 +675,9 @@ bool content_add_user(
}
/**
* Remove a callback user.
*
* The callback function and pw must be identical to those passed to
* content_add_user().
*/
void content_remove_user(
struct content *c,
/* exported interface documented in content/content.h */
void
content_remove_user(struct content *c,
void (*callback)(
struct content *c,
content_msg msg,
@ -791,10 +709,8 @@ void content_remove_user(
free(next);
}
/**
* Count users for the content.
*/
/* exported interface documented in content/content.h */
uint32_t content_count_users(struct content *c)
{
struct content_user *user;
@ -810,13 +726,8 @@ uint32_t content_count_users(struct content *c)
return counter - 1; /* Subtract 1 for the sentinel */
}
/**
* Determine if quirks mode matches
*
* \param c Content to consider
* \param quirks Quirks mode to match
* \return True if quirks match, false otherwise
*/
/* exported interface documented in content/content.h */
bool content_matches_quirks(struct content *c, bool quirks)
{
if (c->handler->matches_quirks == NULL)
@ -825,21 +736,15 @@ bool content_matches_quirks(struct content *c, bool quirks)
return c->handler->matches_quirks(c, quirks);
}
/**
* Determine if a content is shareable
*
* \param c Content to consider
* \return True if content is shareable, false otherwise
*/
/* exported interface documented in content/content.h */
bool content_is_shareable(struct content *c)
{
return c->handler->no_share == false;
}
/**
* Send a message to all users.
*/
/* exported interface documented in content/protected.h */
void content_broadcast(struct content *c, content_msg msg,
const union content_msg_data *data)
{
@ -854,8 +759,10 @@ void content_broadcast(struct content *c, content_msg msg,
}
}
/* exported interface documented in content_protected.h */
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
void
content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
{
struct content_user *user, *next;
union content_msg_data data;
@ -875,18 +782,7 @@ void content_broadcast_error(struct content *c, nserror errorcode, const char *m
}
/**
* A window containing the content has been opened.
*
* \param h handle to content that has been opened
* \param bw browser window containing the content
* \param page content of type CONTENT_HTML containing h, or NULL if not an
* object within a page
* \param params object parameters, or NULL if not an object
*
* Calls the open function for the content.
*/
/* exported interface, documented in content/content.h */
nserror
content_open(hlcache_handle *h,
struct browser_window *bw,
@ -909,12 +805,7 @@ content_open(hlcache_handle *h,
}
/**
* The window containing the content has been closed.
*
* Calls the close function for the content.
*/
/* exported interface, documented in content/content.h */
nserror content_close(hlcache_handle *h)
{
struct content *c;
@ -942,11 +833,7 @@ nserror content_close(hlcache_handle *h)
}
/**
* Tell a content that any selection it has, or one of its objects has, must be
* cleared.
*/
/* exported interface, documented in content/content.h */
void content_clear_selection(hlcache_handle *h)
{
struct content *c = hlcache_handle_get_content(h);
@ -957,11 +844,7 @@ void content_clear_selection(hlcache_handle *h)
}
/**
* Get a text selection from a content. Ownership is passed to the caller,
* who must free() it.
*/
/* exported interface, documented in content/content.h */
char * content_get_selection(hlcache_handle *h)
{
struct content *c = hlcache_handle_get_content(h);
@ -973,9 +856,12 @@ char * content_get_selection(hlcache_handle *h)
return NULL;
}
/* exported interface documented in content/content.h */
nserror content_get_contextual_content(struct hlcache_handle *h,
int x, int y, struct browser_window_features *data)
nserror
content_get_contextual_content(struct hlcache_handle *h,
int x, int y,
struct browser_window_features *data)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != 0);
@ -989,8 +875,11 @@ nserror content_get_contextual_content(struct hlcache_handle *h,
}
bool content_scroll_at_point(struct hlcache_handle *h,
int x, int y, int scrx, int scry)
/* exported interface, documented in content/content.h */
bool
content_scroll_at_point(struct hlcache_handle *h,
int x, int y,
int scrx, int scry)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != 0);
@ -1002,8 +891,11 @@ bool content_scroll_at_point(struct hlcache_handle *h,
}
bool content_drop_file_at_point(struct hlcache_handle *h,
int x, int y, char *file)
/* exported interface, documented in content/content.h */
bool
content_drop_file_at_point(struct hlcache_handle *h,
int x, int y,
char *file)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != 0);
@ -1015,8 +907,12 @@ bool content_drop_file_at_point(struct hlcache_handle *h,
}
void content_search(struct hlcache_handle *h, void *context,
search_flags_t flags, const char *string)
/* exported interface, documented in content/content.h */
void
content_search(struct hlcache_handle *h,
void *context,
search_flags_t flags,
const char *string)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != 0);
@ -1027,6 +923,7 @@ void content_search(struct hlcache_handle *h, void *context,
}
/* exported interface, documented in content/content.h */
void content_search_clear(struct hlcache_handle *h)
{
struct content *c = hlcache_handle_get_content(h);
@ -1037,8 +934,10 @@ void content_search_clear(struct hlcache_handle *h)
}
}
/* exported interface documented in content/content.h */
nserror content_debug_dump(struct hlcache_handle *h, FILE *f, enum content_debug op)
nserror
content_debug_dump(struct hlcache_handle *h, FILE *f, enum content_debug op)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != 0);
@ -1050,6 +949,7 @@ nserror content_debug_dump(struct hlcache_handle *h, FILE *f, enum content_debug
return c->handler->debug_dump(c, f, op);
}
/* exported interface documented in content/content.h */
nserror content_debug(struct hlcache_handle *h, enum content_debug op)
{
@ -1085,6 +985,8 @@ content_find_rfc5988_link(hlcache_handle *h, lwc_string *rel)
return link;
}
/* exported interface documented in content/protected.h */
struct content_rfc5988_link *
content__free_rfc5988_link(struct content_rfc5988_link *link)
{
@ -1111,7 +1013,10 @@ content__free_rfc5988_link(struct content_rfc5988_link *link)
return next;
}
bool content__add_rfc5988_link(struct content *c,
/* exported interface documented in content/protected.h */
bool
content__add_rfc5988_link(struct content *c,
const struct content_rfc5988_link *link)
{
struct content_rfc5988_link *newlink;
@ -1160,7 +1065,6 @@ bool content__add_rfc5988_link(struct content *c,
}
/* exported interface documented in content/content.h */
nsurl *content_get_url(struct content *c)
{
@ -1189,6 +1093,7 @@ lwc_string *content_get_mime_type(hlcache_handle *h)
return content__get_mime_type(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
lwc_string *content__get_mime_type(struct content *c)
{
@ -1221,6 +1126,7 @@ const char *content_get_title(hlcache_handle *h)
return content__get_title(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
const char *content__get_title(struct content *c)
{
@ -1238,6 +1144,7 @@ content_status content_get_status(hlcache_handle *h)
return content__get_status(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
content_status content__get_status(struct content *c)
{
@ -1254,6 +1161,7 @@ const char *content_get_status_message(hlcache_handle *h)
return content__get_status_message(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
const char *content__get_status_message(struct content *c)
{
@ -1270,6 +1178,7 @@ int content_get_width(hlcache_handle *h)
return content__get_width(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
int content__get_width(struct content *c)
{
@ -1286,6 +1195,7 @@ int content_get_height(hlcache_handle *h)
return content__get_height(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
int content__get_height(struct content *c)
{
@ -1302,6 +1212,7 @@ int content_get_available_width(hlcache_handle *h)
return content__get_available_width(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
int content__get_available_width(struct content *c)
{
@ -1318,6 +1229,7 @@ const uint8_t *content_get_source_data(hlcache_handle *h, size_t *size)
return content__get_source_data(hlcache_handle_get_content(h), size);
}
/* exported interface documented in content/content_protected.h */
const uint8_t *content__get_source_data(struct content *c, size_t *size)
{
@ -1330,12 +1242,14 @@ const uint8_t *content__get_source_data(struct content *c, size_t *size)
return llcache_handle_get_source_data(c->llcache, size);
}
/* exported interface documented in content/content.h */
void content_invalidate_reuse_data(hlcache_handle *h)
{
content__invalidate_reuse_data(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
void content__invalidate_reuse_data(struct content *c)
{
@ -1346,12 +1260,14 @@ void content__invalidate_reuse_data(struct content *c)
llcache_handle_invalidate_cache_data(c->llcache);
}
/* exported interface documented in content/content.h */
nsurl *content_get_refresh_url(hlcache_handle *h)
{
return content__get_refresh_url(hlcache_handle_get_content(h));
}
/* exported interface documented in content/content_protected.h */
nsurl *content__get_refresh_url(struct content *c)
{
@ -1427,14 +1343,16 @@ bool content_get_quirks(hlcache_handle *h)
/* exported interface documented in content/content.h */
const char *content_get_encoding(hlcache_handle *h, enum content_encoding_type op)
const char *
content_get_encoding(hlcache_handle *h, enum content_encoding_type op)
{
return content__get_encoding(hlcache_handle_get_content(h), op);
}
/* exported interface documented in content/content_protected.h */
const char *content__get_encoding(struct content *c, enum content_encoding_type op)
const char *
content__get_encoding(struct content *c, enum content_encoding_type op)
{
const char *encoding = NULL;
@ -1461,12 +1379,8 @@ bool content__is_locked(struct content *c)
return c->locked;
}
/**
* Retrieve the low-level cache handle for a content
*
* \param c Content to retrieve from
* \return Low-level cache handle
*/
/* exported interface documented in content/content.h */
const llcache_handle *content_get_llcache_handle(struct content *c)
{
if (c == NULL)
@ -1475,12 +1389,8 @@ const llcache_handle *content_get_llcache_handle(struct content *c)
return c->llcache;
}
/**
* Clone a content object in its current state.
*
* \param c Content to clone
* \return Clone of \a c
*/
/* exported interface documented in content/protected.h */
struct content *content_clone(struct content *c)
{
struct content *nc;
@ -1493,13 +1403,8 @@ struct content *content_clone(struct content *c)
return nc;
};
/**
* Clone a content's data members
*
* \param c Content to clone
* \param nc Content to populate
* \return NSERROR_OK on success, appropriate error otherwise
*/
/* exported interface documented in content/protected.h */
nserror content__clone(const struct content *c, struct content *nc)
{
nserror error;
@ -1564,12 +1469,8 @@ nserror content__clone(const struct content *c, struct content *nc)
return NSERROR_OK;
}
/**
* Abort a content object
*
* \param c The content object to abort
* \return NSERROR_OK on success, otherwise appropriate error
*/
/* exported interface documented in content/content.h */
nserror content_abort(struct content *c)
{
NSLOG(netsurf, INFO, "Aborting %p", c);

View File

@ -287,11 +287,26 @@ union content_msg_data {
/* The following are for hlcache */
/**
* Destroy and free a content.
*
* Calls the destroy function for the content, and frees the structure.
*/
void content_destroy(struct content *c);
bool content_add_user(
struct content *h,
/**
* Register a user for callbacks.
*
* \param c the content to register
* \param callback the user callback function
* \param pw callback private data
* \return true on success, false otherwise on memory exhaustion
*
* The callback will be called when content_broadcast() is
* called with the content.
*/
bool content_add_user(struct content *h,
void (*callback)(
struct content *c,
content_msg msg,
@ -299,29 +314,60 @@ bool content_add_user(
void *pw),
void *pw);
void content_remove_user(
struct content *c,
/**
* Remove a callback user.
*
* The callback function and pw must be identical to those passed to
* content_add_user().
*
* \param c Content to remove user from
* \param callback passed when added
* \param ctx Context passed when added
*/
void content_remove_user(struct content *c,
void (*callback)(
struct content *c,
content_msg msg,
const union content_msg_data *data,
void *pw),
void *pw);
void *ctx);
/**
* Count users for the content.
*
* \param c Content to consider
*/
uint32_t content_count_users(struct content *c);
/**
* Determine if quirks mode matches
*
* \param c Content to consider
* \param quirks Quirks mode to match
* \return True if quirks match, false otherwise
*/
bool content_matches_quirks(struct content *c, bool quirks);
/**
* Determine if a content is shareable
*
* \param c Content to consider
* \return True if content is shareable, false otherwise
*/
bool content_is_shareable(struct content *c);
/* only used by cocoa apple image handling and for getting nsurl of content */
/**
* Retrieve the low-level cache handle for a content
*
* \note only used by hlcache
*
* \param c Content to retrieve from
* \return Low-level cache handle
*/
const struct llcache_handle *content_get_llcache_handle(struct content *c);
/**
* Retrieve URL associated with content
*
@ -330,35 +376,123 @@ const struct llcache_handle *content_get_llcache_handle(struct content *c);
*/
struct nsurl *content_get_url(struct content *c);
/**
* Clone a content object in its current state.
*
* \param c Content to clone
* \return Clone of \a c
*/
struct content *content_clone(struct content *c);
/**
* Abort a content object
*
* \param c The content object to abort
* \return NSERROR_OK on success, otherwise appropriate error
*/
nserror content_abort(struct content *c);
/* Client functions */
/**
* Get whether a content can reformat
*
* \param h content to check
* \return whether the content can reformat
*/
bool content_can_reformat(struct hlcache_handle *h);
/**
* Reformat to new size.
*
* Calls the reformat function for the content.
*/
void content_reformat(struct hlcache_handle *h, bool background,
int width, int height);
/**
* Request a redraw of an area of a content
*
* \param h high-level cache handle
* \param x x co-ord of left edge
* \param y y co-ord of top edge
* \param width Width of rectangle
* \param height Height of rectangle
*/
void content_request_redraw(struct hlcache_handle *h,
int x, int y, int width, int height);
/**
* Handle mouse movements in a content window.
*
* \param h Content handle
* \param bw browser window
* \param mouse state of mouse buttons and modifier keys
* \param x coordinate of mouse
* \param y coordinate of mouse
*/
void content_mouse_track(struct hlcache_handle *h, struct browser_window *bw,
browser_mouse_state mouse, int x, int y);
/**
* Handle mouse clicks and movements in a content window.
*
* \param h Content handle
* \param bw browser window
* \param mouse state of mouse buttons and modifier keys
* \param x coordinate of mouse
* \param y coordinate of mouse
*
* This function handles both hovering and clicking. It is important that the
* code path is identical (except that hovering doesn't carry out the action),
* so that the status bar reflects exactly what will happen. Having separate
* code paths opens the possibility that an attacker will make the status bar
* show some harmless action where clicking will be harmful.
*/
void content_mouse_action(struct hlcache_handle *h, struct browser_window *bw,
browser_mouse_state mouse, int x, int y);
/**
* Handle keypresses.
*
* \param h Content handle
* \param key The UCS4 character codepoint
* \return true if key handled, false otherwise
*/
bool content_keypress(struct hlcache_handle *h, uint32_t key);
/**
* A window containing the content has been opened.
*
* \param h handle to content that has been opened
* \param bw browser window containing the content
* \param page content of type CONTENT_HTML containing h, or NULL if not an
* object within a page
* \param params object parameters, or NULL if not an object
*
* Calls the open function for the content.
*/
nserror content_open(struct hlcache_handle *h, struct browser_window *bw,
struct content *page, struct object_params *params);
/**
* The window containing the content has been closed.
*
* Calls the close function for the content.
*/
nserror content_close(struct hlcache_handle *h);
/**
* Tell a content that any selection it has, or one of its objects
* has, must be cleared.
*/
void content_clear_selection(struct hlcache_handle *h);
/**
* Get a text selection from a content. Ownership is passed to the caller,
* who must free() it.
*/
char * content_get_selection(struct hlcache_handle *h);
/**
@ -372,15 +506,39 @@ char * content_get_selection(struct hlcache_handle *h);
nserror content_get_contextual_content(struct hlcache_handle *h,
int x, int y, struct browser_window_features *data);
/**
* scroll content at coordnate
*
* \param[in] h Handle to content to examine.
* \param[in] x The x coordinate to examine.
* \param[in] y The y coordinate to examine.
*/
bool content_scroll_at_point(struct hlcache_handle *h,
int x, int y, int scrx, int scry);
/**
* Drag and drop a file at coordinate
*
* \param[in] h Handle to content to examine.
* \param[in] x The x coordinate to examine.
* \param[in] y The y coordinate to examine.
*/
bool content_drop_file_at_point(struct hlcache_handle *h,
int x, int y, char *file);
/**
* Search a content
*
* \param[in] h Handle to content to search.
*/
void content_search(struct hlcache_handle *h, void *context,
search_flags_t flags, const char *string);
/**
* Clear a search
*
* \param[in] h Handle to content to clear search from.
*/
void content_search_clear(struct hlcache_handle *h);

View File

@ -24,18 +24,25 @@
* The content functions manipulate struct contents, which correspond to URLs.
*/
#ifndef _NETSURF_CONTENT_CONTENT_PROTECTED_H_
#define _NETSURF_CONTENT_CONTENT_PROTECTED_H_
#ifndef NETSURF_CONTENT_CONTENT_PROTECTED_H_
#define NETSURF_CONTENT_CONTENT_PROTECTED_H_
#include <stdio.h>
#include "utils/nsurl.h"
#include "netsurf/content_type.h"
#include "content/content.h"
struct nsurl;
struct content_redraw_data;
struct http_parameter;
struct llcache_handle;
struct object_params;
/**
* Content operation function table
*
* function table implementing a content type.
*/
struct content_handler {
void (*fini)(void);
@ -85,14 +92,20 @@ struct content_handler {
bool (*exec)(struct content *c, const char *src, size_t srclen);
bool (*saw_insecure_objects)(struct content *c);
/** handler dependant content sensitive internal data interface. */
/**
* handler dependant content sensitive internal data interface.
*/
void * (*get_internal)(const struct content *c, void *context);
/** There must be one content per user for this type. */
/**
* There must be one content per user for this type.
*/
bool no_share;
};
/** Linked list of users of a content. */
/**
* Linked list of users of a content.
*/
struct content_user
{
void (*callback)(
@ -105,68 +118,180 @@ struct content_user
struct content_user *next;
};
/** Corresponds to a single URL. */
/**
* Content which corresponds to a single URL.
*/
struct content {
struct llcache_handle *llcache; /**< Low-level cache object */
/**
* Low-level cache object
*/
struct llcache_handle *llcache;
lwc_string *mime_type; /**< Original MIME type of data */
/**
* Original MIME type of data
*/
lwc_string *mime_type;
const struct content_handler *handler; /**< Handler for content */
/**
* Handler for content
*/
const struct content_handler *handler;
content_status status; /**< Current status. */
/**
* Current status.
*/
content_status status;
int width, height; /**< Dimensions, if applicable. */
int available_width; /**< Viewport width. */
int available_height; /**< Viewport height. */
/**
* Width dimension, if applicable.
*/
int width;
/**
* Height dimension, if applicable.
*/
int height;
/**
* Viewport width.
*/
int available_width;
/**
* Viewport height.
*/
int available_height;
bool quirks; /**< Content is in quirks mode */
char *fallback_charset; /**< Fallback charset, or NULL */
/**
* Content is in quirks mode
*/
bool quirks;
/**
* Fallback charset, or NULL
*/
char *fallback_charset;
nsurl *refresh; /**< URL for refresh request */
/**
* URL for refresh request
*/
struct nsurl *refresh;
struct content_rfc5988_link *links; /**< list of metadata links */
/**
* list of metadata links
*/
struct content_rfc5988_link *links;
/** Creation timestamp when LOADING or READY.
* Total time in ms when DONE.
/**
* Creation timestamp when LOADING or READY. Total time in ms
* when DONE.
*/
uint64_t time;
uint64_t reformat_time; /**< Earliest time to attempt a period
* reflow while fetching a page's objects.
/**
* Earliest time to attempt a period reflow while fetching a
* page's objects.
*/
uint64_t reformat_time;
unsigned int size; /**< Estimated size of all data
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[120]; /**< Full text for status bar. */
char sub_status[80]; /**< Status of content. */
/** Content is being processed: data structures may be inconsistent
* and content must not be redrawn or modified. */
/**
* Estimated size of all data associated with this content
*/
unsigned int size;
/**
* Title for browser window.
*/
char *title;
/**
* Number of child fetches or conversions currently in progress.
*/
unsigned int active;
/**
* List of users.
*/
struct content_user *user_list;
/**
* Full text for status bar.
*/
char status_message[120];
/**
* Status of content.
*/
char sub_status[80];
/**
* Content is being processed: data structures may be
* inconsistent and content must not be redrawn or modified.
*/
bool locked;
unsigned long total_size; /**< Total data size, 0 if unknown. */
long http_code; /**< HTTP status code, 0 if not HTTP. */
/**
* Total data size, 0 if unknown.
*/
unsigned long total_size;
/**
* HTTP status code, 0 if not HTTP.
*/
long http_code;
};
extern const char * const content_type_name[];
extern const char * const content_status_name[];
/**
* Initialise a new base content structure.
*
* \param c Content to initialise
* \param handler Content handler
* \param imime_type MIME type of content
* \param params HTTP parameters
* \param llcache Source data handle
* \param fallback_charset Fallback charset
* \param quirks Quirkiness of content
* \return NSERROR_OK on success, appropriate error otherwise
*/
nserror content__init(struct content *c, const struct content_handler *handler,
lwc_string *imime_type, const struct http_parameter *params,
struct llcache_handle *llcache, const char *fallback_charset,
bool quirks);
/**
* Clone a content's data members
*
* \param c Content to clone
* \param nc Content to populate
* \return NSERROR_OK on success, appropriate error otherwise
*/
nserror content__clone(const struct content *c, struct content *nc);
/**
* Put a content in status CONTENT_STATUS_READY and unlock the content.
*/
void content_set_ready(struct content *c);
/**
* Put a content in status CONTENT_STATUS_DONE.
*/
void content_set_done(struct content *c);
/**
* Put a content in status CONTENT_STATUS_ERROR and unlock the content.
*
* \note We expect the caller to broadcast an error report if needed.
*/
void content_set_error(struct content *c);
/**
* Updates content with new status.
*
* The textual status contained in the content is updated with given string.
*
* \param c The content to set status in.
* \param status_message new textual status
*/
void content_set_status(struct content *c, const char *status_message);
void content_broadcast(struct content *c, content_msg msg,
const union content_msg_data *data);
/**
* Send a message to all users.
*/
void content_broadcast(struct content *c, content_msg msg, const union content_msg_data *data);
/**
* Send an error message to all users.
*
@ -176,16 +301,42 @@ void content_broadcast(struct content *c, content_msg msg,
*/
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg);
bool content__add_rfc5988_link(struct content *c,
const struct content_rfc5988_link *link);
struct content_rfc5988_link *content__free_rfc5988_link(
struct content_rfc5988_link *link);
/**
* associate a metadata link with a content.
*
* \param c content to add link to
* \param link The rfc5988 link to add
*/
bool content__add_rfc5988_link(struct content *c, const struct content_rfc5988_link *link);
void content__reformat(struct content *c, bool background,
int width, int height);
void content__request_redraw(struct content *c,
int x, int y, int width, int height);
/**
* free a rfc5988 link
*
* \param link The link to free
* \return The next link in the chain
*/
struct content_rfc5988_link *content__free_rfc5988_link(struct content_rfc5988_link *link);
/**
* cause a content to be reformatted.
*
* \param c content to be reformatted
* \param background perform reformat in background
* \param width The available width to reformat content in
* \param height The available height to reformat content in
*/
void content__reformat(struct content *c, bool background, int width, int height);
/**
* Request a redraw of an area of a content
*
* \param c Content
* \param x x co-ord of left edge
* \param y y co-ord of top edge
* \param width Width of rectangle
* \param height Height of rectangle
*/
void content__request_redraw(struct content *c, int x, int y, int width, int height);
/**
* Retrieve mime-type of content
@ -270,7 +421,7 @@ void content__invalidate_reuse_data(struct content *c);
* \param c Content to retrieve refresh URL from
* \return Pointer to URL or NULL if none
*/
nsurl *content__get_refresh_url(struct content *c);
struct nsurl *content__get_refresh_url(struct content *c);
/**
* Retrieve the bitmap contained in an image content

View File

@ -33,6 +33,7 @@
#include "utils/talloc.h"
#include "utils/string.h"
#include "utils/ascii.h"
#include "utils/nsurl.h"
#include "netsurf/misc.h"
#include "css/select.h"
#include "desktop/gui_internal.h"
@ -68,7 +69,7 @@ struct box_construct_props {
/** Style from which to inherit, or NULL if none */
const css_computed_style *parent_style;
/** Current link target, or NULL if none */
nsurl *href;
struct nsurl *href;
/** Current frame target, or NULL if none */
const char *target;
/** Current title attribute, or NULL if none */

View File

@ -28,6 +28,7 @@
#include "utils/errors.h"
#include "utils/talloc.h"
#include "utils/nsurl.h"
#include "netsurf/types.h"
#include "netsurf/mouse.h"
#include "desktop/scrollbar.h"

View File

@ -36,6 +36,7 @@
#include "utils/talloc.h"
#include "utils/string.h"
#include "utils/ascii.h"
#include "utils/nsurl.h"
#include "netsurf/plot_style.h"
#include "css/hints.h"
#include "desktop/frame_types.h"

View File

@ -27,6 +27,7 @@
#include "utils/log.h"
#include "utils/ascii.h"
#include "utils/string.h"
#include "utils/nsurl.h"
#include "javascript/js.h"
#include "html/private.h"

View File

@ -47,6 +47,7 @@
#include "utils/talloc.h"
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "utils/nsurl.h"
#include "netsurf/inttypes.h"
#include "netsurf/content.h"
#include "netsurf/browser_window.h"

View File

@ -27,6 +27,7 @@
struct html_content;
struct browser_window;
struct box;
struct nsurl;
/**
* Start a fetch for an object required by a page.
@ -42,7 +43,7 @@ struct box;
* \param background this is a background image
* \return true on success, false on memory exhaustion
*/
bool html_fetch_object(struct html_content *c, nsurl *url, struct box *box, content_type permitted_types, bool background);
bool html_fetch_object(struct html_content *c, struct nsurl *url, struct box *box, content_type permitted_types, bool background);
/**
* release memory of content objects associated with a HTML content

View File

@ -107,7 +107,7 @@ typedef struct html_content {
dom_hubbub_encoding_source encoding_source;
/** Base URL (may be a copy of content->url). */
nsurl *base_url;
struct nsurl *base_url;
/** Base target */
char *base_target;
@ -341,7 +341,7 @@ struct form_control *html_forms_get_control_for_node(struct form *forms,
* \return NSERROR_OK on successful registration or error code on failure.
*/
nserror html_css_fetcher_register(void);
nserror html_css_fetcher_add_item(dom_string *data, nsurl *base_url,
nserror html_css_fetcher_add_item(dom_string *data, struct nsurl *base_url,
uint32_t *key);

View File

@ -30,6 +30,7 @@
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/nsurl.h"
#include "netsurf/plotters.h"
#include "netsurf/content.h"
#include "content/content_protected.h"