2003-06-25 03:22:00 +04:00
|
|
|
/*
|
2007-01-13 03:21:15 +03:00
|
|
|
* Copyright 2005-2007 James Bursa <bursa@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
|
2010-03-28 20:00:54 +04:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2007-08-08 20:16:03 +04:00
|
|
|
* 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 (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>
|
2005-08-21 16:04:18 +04:00
|
|
|
#include <inttypes.h>
|
2004-06-05 19:03:59 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <stdlib.h>
|
2004-06-05 19:03:59 +04:00
|
|
|
#include <string.h>
|
2007-01-30 01:27:15 +03:00
|
|
|
#include <strings.h>
|
2007-01-13 03:21:15 +03:00
|
|
|
#include <time.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/content_protected.h"
|
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "css/css.h"
|
|
|
|
#include "image/bitmap.h"
|
2010-06-04 13:35:08 +04:00
|
|
|
#include "desktop/browser.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "render/html.h"
|
|
|
|
#include "render/textplain.h"
|
2011-03-05 12:49:15 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "utils/http.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/talloc.h"
|
|
|
|
#include "utils/utils.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
|
2008-07-30 04:54:43 +04:00
|
|
|
const char * const content_status_name[] = {
|
2004-06-11 00:41:26 +04:00
|
|
|
"LOADING",
|
|
|
|
"READY",
|
|
|
|
"DONE",
|
|
|
|
"ERROR"
|
|
|
|
};
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
static nserror content_llcache_callback(llcache_handle *llcache,
|
|
|
|
const llcache_event *event, void *pw);
|
2010-03-30 02:33:21 +04:00
|
|
|
static void content_convert(struct content *c);
|
2007-01-13 03:21:15 +03:00
|
|
|
static void content_update_status(struct content *c);
|
2004-06-21 03:09:52 +04:00
|
|
|
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
/**
|
2011-05-07 00:40:09 +04:00
|
|
|
* Initialise a new content structure.
|
2003-09-08 01:08:13 +04:00
|
|
|
*
|
2011-05-07 00:40:09 +04:00
|
|
|
* \param c Content to initialise (allocated with talloc)
|
|
|
|
* \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
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror content__init(struct content *c, const content_handler *handler,
|
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content_user *user_sentinel;
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror error;
|
|
|
|
|
|
|
|
LOG(("url %s -> %p", llcache_handle_get_url(llcache), c));
|
2007-03-18 20:04:18 +03:00
|
|
|
|
2005-04-03 14:58:49 +04:00
|
|
|
user_sentinel = talloc(c, struct content_user);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (user_sentinel == NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_NOMEM;
|
2004-06-11 00:41:26 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
c->fallback_charset = talloc_strdup(c, fallback_charset);
|
|
|
|
if (fallback_charset != NULL && c->fallback_charset == NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_NOMEM;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
c->llcache = llcache;
|
2011-05-07 00:40:09 +04:00
|
|
|
c->mime_type = lwc_string_ref(imime_type);
|
|
|
|
c->handler = handler;
|
2010-03-28 16:56:39 +04:00
|
|
|
c->status = CONTENT_STATUS_LOADING;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->width = 0;
|
|
|
|
c->height = 0;
|
|
|
|
c->available_width = 0;
|
2010-03-28 16:56:39 +04:00
|
|
|
c->quirks = quirks;
|
2006-01-25 09:52:38 +03:00
|
|
|
c->refresh = 0;
|
2007-01-30 18:32:31 +03:00
|
|
|
c->time = wallclock();
|
2006-12-04 01:34:26 +03:00
|
|
|
c->size = 0;
|
2010-03-28 16:56:39 +04:00
|
|
|
c->title = NULL;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->active = 0;
|
2010-03-28 16:56:39 +04:00
|
|
|
user_sentinel->callback = NULL;
|
|
|
|
user_sentinel->pw = NULL;
|
|
|
|
user_sentinel->next = NULL;
|
2003-06-17 23:24:21 +04:00
|
|
|
c->user_list = user_sentinel;
|
2007-01-13 03:21:15 +03:00
|
|
|
c->sub_status[0] = 0;
|
2005-07-06 02:43:38 +04:00
|
|
|
c->locked = false;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->total_size = 0;
|
2007-01-13 03:21:15 +03:00
|
|
|
c->http_code = 0;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->error_count = 0;
|
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
content_set_status(c, messages_get("Loading"));
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/* Finally, claim low-level cache events */
|
2011-05-07 00:40:09 +04:00
|
|
|
error = llcache_handle_change_callback(llcache,
|
|
|
|
content_llcache_callback, c);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
lwc_string_unref(c->mime_type);
|
|
|
|
return error;
|
2004-06-21 19:09:59 +04:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_OK;
|
2004-06-21 19:09:59 +04:00
|
|
|
}
|
|
|
|
|
2006-02-06 03:10:09 +03:00
|
|
|
/**
|
2010-03-28 16:56:39 +04:00
|
|
|
* Handler for low-level cache events
|
2006-02-06 03:10:09 +03:00
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* \param llcache Low-level cache handle
|
2010-03-28 20:00:54 +04:00
|
|
|
* \param event Event details
|
|
|
|
* \param pw Pointer to our context
|
2010-03-28 16:56:39 +04:00
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
2006-02-06 03:10:09 +03:00
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror content_llcache_callback(llcache_handle *llcache,
|
|
|
|
const llcache_event *event, void *pw)
|
2006-02-06 03:10:09 +03:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
struct content *c = pw;
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
nserror error = NSERROR_OK;
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case LLCACHE_EVENT_HAD_HEADERS:
|
|
|
|
/* Will never happen: handled in hlcache */
|
|
|
|
break;
|
|
|
|
case LLCACHE_EVENT_HAD_DATA:
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->process_data != NULL) {
|
|
|
|
if (c->handler->process_data(c,
|
2010-04-03 20:37:36 +04:00
|
|
|
(const char *) event->data.data.buf,
|
2010-03-28 16:56:39 +04:00
|
|
|
event->data.data.len) == false) {
|
2010-04-08 11:09:09 +04:00
|
|
|
llcache_handle_abort(c->llcache);
|
2010-03-28 16:56:39 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
/** \todo It's not clear what error this is */
|
|
|
|
error = NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LLCACHE_EVENT_DONE:
|
|
|
|
{
|
|
|
|
size_t source_size;
|
|
|
|
|
2011-05-17 01:49:21 +04:00
|
|
|
(void) llcache_handle_get_source_data(llcache, &source_size);
|
2006-02-06 03:10:09 +03:00
|
|
|
|
2011-05-08 23:11:34 +04:00
|
|
|
content_set_status(c, messages_get("Processing"), source_size);
|
2010-03-28 16:56:39 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
|
|
|
|
2010-03-30 02:33:21 +04:00
|
|
|
content_convert(c);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LLCACHE_EVENT_ERROR:
|
|
|
|
/** \todo Error page? */
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
msg_data.error = event->data.msg;
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
break;
|
|
|
|
case LLCACHE_EVENT_PROGRESS:
|
|
|
|
content_set_status(c, "%s", event->data.msg);
|
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
|
|
|
break;
|
2006-02-06 03:10:09 +03:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
return error;
|
2006-02-06 03:10:09 +03:00
|
|
|
}
|
|
|
|
|
2007-03-03 22:46:20 +03:00
|
|
|
/**
|
|
|
|
* Get whether a content can reformat
|
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* \param h content to check
|
2007-03-03 22:46:20 +03:00
|
|
|
* \return whether the content can reformat
|
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
bool content_can_reformat(hlcache_handle *h)
|
2007-08-07 07:55:18 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
2007-03-03 22:46:20 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (c == NULL)
|
2004-06-11 00:41:26 +04:00
|
|
|
return false;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return (c->handler->reformat != NULL);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-05 19:03:59 +04:00
|
|
|
/**
|
|
|
|
* Updates content with new status.
|
|
|
|
*
|
|
|
|
* The textual status contained in the content is updated with given string.
|
|
|
|
*
|
|
|
|
* \param status_message new textual status
|
|
|
|
*/
|
2004-06-21 19:09:59 +04:00
|
|
|
|
2004-06-05 19:03:59 +04:00
|
|
|
void content_set_status(struct content *c, const char *status_message, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
va_start(ap, status_message);
|
2007-01-13 03:21:15 +03:00
|
|
|
if ((len = vsnprintf(c->sub_status, sizeof (c->sub_status),
|
2005-07-06 02:43:38 +04:00
|
|
|
status_message, ap)) < 0 ||
|
2007-01-13 03:21:15 +03:00
|
|
|
(int)sizeof (c->sub_status) <= len)
|
|
|
|
c->sub_status[sizeof (c->sub_status) - 1] = '\0';
|
2004-06-05 19:03:59 +04:00
|
|
|
va_end(ap);
|
2007-01-13 03:21:15 +03:00
|
|
|
|
|
|
|
content_update_status(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void content_update_status(struct content *c)
|
|
|
|
{
|
2011-02-28 23:38:23 +03:00
|
|
|
if (c->status == CONTENT_STATUS_LOADING ||
|
2011-05-08 23:11:34 +04:00
|
|
|
c->status == CONTENT_STATUS_READY) {
|
|
|
|
/* Not done yet */
|
|
|
|
snprintf(c->status_message, sizeof (c->status_message),
|
|
|
|
"%s%s%s", messages_get("Fetching"),
|
|
|
|
c->sub_status ? ", " : " ", c->sub_status);
|
|
|
|
} else {
|
|
|
|
unsigned int time = c->time;
|
|
|
|
snprintf(c->status_message, sizeof (c->status_message),
|
2011-05-09 11:59:27 +04:00
|
|
|
"%s (%.1fs)", messages_get("Done"),
|
|
|
|
(float) time / 100);
|
2011-05-08 23:11:34 +04:00
|
|
|
}
|
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
/* LOG(("%s", c->status_message)); */
|
2004-06-05 19:03:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
2004-06-11 00:41:26 +04:00
|
|
|
* - If the conversion fails, CONTENT_MSG_ERROR is sent. The content will soon
|
|
|
|
* be destroyed and must no longer be used.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2010-03-30 02:33:21 +04:00
|
|
|
void content_convert(struct content *c)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2004-06-11 00:41:26 +04:00
|
|
|
assert(c);
|
2010-04-18 15:04:13 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_LOADING ||
|
|
|
|
c->status == CONTENT_STATUS_ERROR);
|
|
|
|
|
|
|
|
if (c->status != CONTENT_STATUS_LOADING)
|
|
|
|
return;
|
|
|
|
|
2010-03-28 20:00:54 +04:00
|
|
|
if (c->locked == true)
|
|
|
|
return;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("content %s (%p)", llcache_handle_get_url(c->llcache), c));
|
2005-04-05 06:36:33 +04:00
|
|
|
|
2011-05-09 19:32:34 +04:00
|
|
|
if (c->handler->data_complete != NULL) {
|
2011-02-27 23:11:39 +03:00
|
|
|
c->locked = true;
|
2011-05-09 19:32:34 +04:00
|
|
|
if (c->handler->data_complete(c) == false) {
|
2011-07-21 01:39:51 +04:00
|
|
|
content_set_error(c);
|
2004-03-11 05:19:14 +03:00
|
|
|
}
|
2011-02-28 22:58:08 +03:00
|
|
|
/* Conversion to the READY state will unlock the content */
|
2004-03-11 05:19:14 +03:00
|
|
|
} else {
|
2010-04-11 14:52:18 +04:00
|
|
|
content_set_ready(c);
|
2007-01-13 03:21:15 +03:00
|
|
|
content_set_done(c);
|
2010-04-11 14:52:18 +04:00
|
|
|
}
|
2007-01-13 03:21:15 +03:00
|
|
|
}
|
|
|
|
|
2010-04-09 22:52:44 +04:00
|
|
|
/**
|
2011-02-28 22:58:08 +03:00
|
|
|
* Put a content in status CONTENT_STATUS_READY and unlock the content.
|
2010-04-09 22:52:44 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_set_ready(struct content *c)
|
|
|
|
{
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
2011-02-28 22:58:08 +03:00
|
|
|
/* The content must be locked at this point, as it can only
|
|
|
|
* become READY after conversion. */
|
|
|
|
assert(c->locked);
|
|
|
|
c->locked = false;
|
|
|
|
|
2010-04-09 22:52:44 +04:00
|
|
|
c->status = CONTENT_STATUS_READY;
|
|
|
|
content_update_status(c);
|
|
|
|
content_broadcast(c, CONTENT_MSG_READY, msg_data);
|
|
|
|
}
|
2007-01-13 03:21:15 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Put a content in status CONTENT_STATUS_DONE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void content_set_done(struct content *c)
|
|
|
|
{
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2007-01-30 18:32:31 +03:00
|
|
|
c->time = wallclock() - c->time;
|
2007-01-13 03:21:15 +03:00
|
|
|
content_update_status(c);
|
|
|
|
content_broadcast(c, CONTENT_MSG_DONE, msg_data);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
2011-07-21 01:39:51 +04:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
c->locked = false;
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
|
|
|
|
2011-06-24 13:30:33 +04:00
|
|
|
void content_reformat(hlcache_handle *h, bool background,
|
|
|
|
int width, int height)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2011-06-24 13:30:33 +04:00
|
|
|
content__reformat(hlcache_handle_get_content(h), background,
|
|
|
|
width, height);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2011-06-24 13:30:33 +04:00
|
|
|
void content__reformat(struct content *c, bool background,
|
|
|
|
int width, int 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->status == CONTENT_STATUS_READY ||
|
|
|
|
c->status == CONTENT_STATUS_DONE);
|
2011-02-28 22:58:08 +03:00
|
|
|
assert(c->locked == false);
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("%p %s", c, llcache_handle_get_url(c->llcache)));
|
2003-04-15 21:53:00 +04:00
|
|
|
c->available_width = width;
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->reformat != NULL) {
|
2011-09-17 18:35:54 +04:00
|
|
|
|
|
|
|
c->locked = true;
|
2011-05-07 00:40:09 +04:00
|
|
|
c->handler->reformat(c, width, height);
|
2011-09-17 18:35:54 +04:00
|
|
|
c->locked = false;
|
|
|
|
|
2011-06-24 13:30:33 +04:00
|
|
|
data.background = background;
|
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)
|
|
|
|
{
|
2004-01-26 17:16:23 +03:00
|
|
|
assert(c);
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("content %p %s", c, llcache_handle_get_url(c->llcache)));
|
2011-02-28 22:58:08 +03:00
|
|
|
assert(c->locked == false);
|
2004-01-26 17:16:23 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->destroy != NULL)
|
|
|
|
c->handler->destroy(c);
|
2010-04-12 00:58:50 +04:00
|
|
|
|
|
|
|
llcache_handle_release(c->llcache);
|
|
|
|
c->llcache = NULL;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
lwc_string_unref(c->mime_type);
|
|
|
|
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_free(c);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->mouse_track != NULL)
|
|
|
|
c->handler->mouse_track(c, bw, mouse, x, y);
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->mouse_action != NULL)
|
|
|
|
c->handler->mouse_action(c, bw, mouse, x, y);
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-23 23:46:29 +03:00
|
|
|
/**
|
2010-03-28 16:56:39 +04:00
|
|
|
* Request a redraw of an area of a content
|
2004-01-23 23:46:29 +03:00
|
|
|
*
|
2011-06-28 01:37:37 +04:00
|
|
|
* \param h high-level cache handle
|
2010-03-28 20:00:54 +04:00
|
|
|
* \param x x co-ord of left edge
|
|
|
|
* \param y y co-ord of top edge
|
|
|
|
* \param width Width of rectangle
|
2010-03-28 16:56:39 +04:00
|
|
|
* \param height Height of rectangle
|
2004-01-23 23:46:29 +03:00
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
void content_request_redraw(struct hlcache_handle *h,
|
|
|
|
int x, int y, int width, int height)
|
2004-01-23 23:46:29 +03:00
|
|
|
{
|
2011-06-28 01:37:37 +04:00
|
|
|
content__request_redraw(hlcache_handle_get_content(h),
|
|
|
|
x, y, width, 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)
|
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
union content_msg_data data;
|
2004-01-23 23:46:29 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (c == NULL)
|
|
|
|
return;
|
2004-01-23 23:46:29 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
data.redraw.x = x;
|
|
|
|
data.redraw.y = y;
|
|
|
|
data.redraw.width = width;
|
|
|
|
data.redraw.height = height;
|
2004-07-30 20:16:07 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
data.redraw.full_redraw = true;
|
2004-07-30 20:16:07 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
data.redraw.object = c;
|
|
|
|
data.redraw.object_x = 0;
|
|
|
|
data.redraw.object_y = 0;
|
|
|
|
data.redraw.object_width = c->width;
|
|
|
|
data.redraw.object_height = c->height;
|
2004-07-30 20:16:07 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_REDRAW, data);
|
|
|
|
}
|
2004-07-30 20:16:07 +04:00
|
|
|
|
2003-05-10 15:15:49 +04:00
|
|
|
/**
|
2011-05-08 23:54:35 +04:00
|
|
|
* Display content on screen with optional tiling.
|
2011-02-11 13:55:46 +03:00
|
|
|
*
|
2011-05-08 23:54:35 +04:00
|
|
|
* Calls the redraw_tile function for the content, or emulates it with the
|
|
|
|
* redraw function if it doesn't exist.
|
2003-05-10 15:15:49 +04:00
|
|
|
*/
|
|
|
|
|
2011-06-29 00:17:39 +04:00
|
|
|
bool content_redraw(hlcache_handle *h, struct content_redraw_data *data,
|
2011-06-30 19:48:07 +04:00
|
|
|
const struct rect *clip, const struct redraw_context *ctx)
|
2003-05-10 15:15:49 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
2011-05-08 23:54:35 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
2011-02-11 01:35:41 +03:00
|
|
|
|
|
|
|
if (c->locked) {
|
2005-07-06 02:43:38 +04:00
|
|
|
/* not safe to attempt redraw */
|
|
|
|
return true;
|
2011-02-11 01:35:41 +03:00
|
|
|
}
|
|
|
|
|
2011-05-08 23:54:35 +04:00
|
|
|
/* ensure we have a redrawable content */
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->redraw == NULL) {
|
2011-02-11 01:35:41 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
return c->handler->redraw(c, data, clip, ctx);
|
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.
|
|
|
|
*
|
2006-02-21 23:49:12 +03:00
|
|
|
* \param c the content to register
|
2005-01-14 01:42:39 +03:00
|
|
|
* \param callback the callback function
|
2010-03-28 20:00:54 +04:00
|
|
|
* \param pw callback private data
|
2005-01-14 01:42:39 +03:00
|
|
|
* \return true on success, false otherwise on memory exhaustion
|
2005-01-02 06:58:21 +03:00
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* The callback will be called when content_broadcast() is
|
2003-09-08 01:08:13 +04:00
|
|
|
* called with the content.
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
bool content_add_user(struct content *c,
|
2010-03-28 16:56:39 +04:00
|
|
|
void (*callback)(struct content *c, content_msg msg,
|
|
|
|
union content_msg_data data, void *pw),
|
|
|
|
void *pw)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user;
|
2005-01-02 06:58:21 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("content %s (%p), user %p %p",
|
|
|
|
llcache_handle_get_url(c->llcache), c, callback, pw));
|
2005-04-03 14:58:49 +04:00
|
|
|
user = talloc(c, struct content_user);
|
2005-01-14 01:42:39 +03:00
|
|
|
if (!user)
|
2005-01-02 06:58:21 +03:00
|
|
|
return false;
|
2003-06-17 23:24:21 +04:00
|
|
|
user->callback = callback;
|
2010-03-28 16:56:39 +04:00
|
|
|
user->pw = pw;
|
2003-06-17 23:24:21 +04:00
|
|
|
user->next = c->user_list->next;
|
|
|
|
c->user_list->next = user;
|
2005-01-02 06:58:21 +03:00
|
|
|
|
|
|
|
return true;
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Remove a callback user.
|
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* The callback function and pw must be identical to those passed to
|
2003-09-08 01:08:13 +04:00
|
|
|
* content_add_user().
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_remove_user(struct content *c,
|
2010-03-28 16:56:39 +04:00
|
|
|
void (*callback)(struct content *c, content_msg msg,
|
|
|
|
union content_msg_data data, void *pw),
|
|
|
|
void *pw)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user, *next;
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("content %s (%p), user %p %p",
|
|
|
|
llcache_handle_get_url(c->llcache), c, callback, pw));
|
2003-06-17 23:24:21 +04:00
|
|
|
|
|
|
|
/* user_list starts with a sentinel */
|
|
|
|
for (user = c->user_list; user->next != 0 &&
|
|
|
|
!(user->next->callback == callback &&
|
2010-03-28 16:56:39 +04:00
|
|
|
user->next->pw == pw); user = user->next)
|
2003-06-17 23:24:21 +04:00
|
|
|
;
|
|
|
|
if (user->next == 0) {
|
|
|
|
LOG(("user not found in list"));
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
next = user->next;
|
|
|
|
user->next = next->next;
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_free(next);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
2010-04-04 16:41:19 +04:00
|
|
|
/**
|
|
|
|
* Count users for the content.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t content_count_users(struct content *c)
|
|
|
|
{
|
|
|
|
struct content_user *user;
|
|
|
|
uint32_t counter = 0;
|
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
|
|
|
for (user = c->user_list; user != NULL; user = user->next)
|
|
|
|
counter += 1;
|
|
|
|
|
|
|
|
return counter - 1; /* Subtract 1 for the sentinel */
|
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2010-04-11 20:34:23 +04:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->matches_quirks == NULL)
|
2010-04-11 20:34:23 +04:00
|
|
|
return true;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->handler->matches_quirks(c, quirks);
|
2010-04-11 20:34:23 +04:00
|
|
|
}
|
|
|
|
|
2010-04-11 20:37:39 +04:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->handler->no_share == false;
|
2010-04-11 20:37:39 +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;
|
2005-01-13 23:26:16 +03:00
|
|
|
assert(c);
|
2007-03-19 02:48:12 +03:00
|
|
|
// LOG(("%p %s -> %d", c, c->url, msg));
|
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)
|
2010-03-28 16:56:39 +04:00
|
|
|
user->callback(c, msg, data, user->pw);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-15 02:57:45 +04:00
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/**
|
2004-08-12 02:08:26 +04:00
|
|
|
* A window containing the content has been opened.
|
2003-09-08 01:08:13 +04:00
|
|
|
*
|
2006-02-21 23:49:12 +03:00
|
|
|
* \param c content that has been opened
|
|
|
|
* \param bw browser window containing the content
|
|
|
|
* \param page content of type CONTENT_HTML containing c, or 0 if not an
|
|
|
|
* object within a page
|
|
|
|
* \param box box containing c, or 0 if not an object
|
2005-10-31 00:22:19 +03:00
|
|
|
* \param params object parameters, or 0 if not an object
|
|
|
|
*
|
2004-08-12 02:08:26 +04:00
|
|
|
* Calls the open function for the content.
|
2003-09-08 01:08:13 +04:00
|
|
|
*/
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
void content_open(hlcache_handle *h, struct browser_window *bw,
|
2011-03-11 02:13:03 +03:00
|
|
|
struct content *page, struct box *box,
|
2004-08-12 02:08:26 +04:00
|
|
|
struct object_params *params)
|
2003-07-15 02:57:45 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
2003-07-15 02:57:45 +04:00
|
|
|
assert(c != 0);
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("content %p %s", c, llcache_handle_get_url(c->llcache)));
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->open != NULL)
|
|
|
|
c->handler->open(c, bw, page, box, params);
|
2003-07-15 02:57:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/**
|
2004-08-12 02:08:26 +04:00
|
|
|
* The window containing the content has been closed.
|
2003-09-08 01:08:13 +04:00
|
|
|
*
|
2004-08-12 02:08:26 +04:00
|
|
|
* Calls the close function for the content.
|
2003-09-08 01:08:13 +04:00
|
|
|
*/
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
void content_close(hlcache_handle *h)
|
2003-07-15 02:57:45 +04:00
|
|
|
{
|
2010-03-28 16:56:39 +04:00
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
2003-07-15 02:57:45 +04:00
|
|
|
assert(c != 0);
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("content %p %s", c, llcache_handle_get_url(c->llcache)));
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->handler->close != NULL)
|
|
|
|
c->handler->close(c);
|
2003-07-15 02:57:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/**
|
|
|
|
* Find this content's selection context, if it has one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct selection *content_get_selection(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
|
|
|
assert(c != 0);
|
|
|
|
|
|
|
|
if (c->handler->get_selection != NULL)
|
|
|
|
return c->handler->get_selection(c);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 22:07:30 +04:00
|
|
|
void content_get_contextual_content(struct hlcache_handle *h,
|
|
|
|
int x, int y, struct contextual_content *data)
|
|
|
|
{
|
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
|
|
|
assert(c != 0);
|
|
|
|
|
|
|
|
if (c->handler->get_contextual_content != NULL) {
|
|
|
|
c->handler->get_contextual_content(c, x, y, data);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
data->object = h;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
void content_add_error(struct content *c, const char *token,
|
|
|
|
unsigned int line)
|
|
|
|
{
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2010-04-03 15:55:28 +04:00
|
|
|
bool content__set_title(struct content *c, const char *title)
|
|
|
|
{
|
|
|
|
char *new_title = talloc_strdup(c, title);
|
|
|
|
if (new_title == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (c->title != NULL)
|
|
|
|
talloc_free(c->title);
|
|
|
|
|
|
|
|
c->title = new_title;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
2011-05-07 00:40:09 +04:00
|
|
|
* Retrieve computed type of content
|
2010-03-28 16:56:39 +04:00
|
|
|
*
|
|
|
|
* \param c Content to retrieve type of
|
2011-05-07 00:40:09 +04:00
|
|
|
* \return Computed content type
|
2010-03-28 16:56:39 +04:00
|
|
|
*/
|
|
|
|
content_type content_get_type(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
if (c == NULL)
|
2011-05-07 00:40:09 +04:00
|
|
|
return CONTENT_NONE;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-09-03 13:27:42 +04:00
|
|
|
return c->handler->type();
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2010-04-07 13:12:09 +04:00
|
|
|
/**
|
|
|
|
* Retrieve mime-type of content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve mime-type of
|
2011-05-07 00:40:09 +04:00
|
|
|
* \return Pointer to referenced mime-type, or NULL if not found.
|
2010-04-07 13:12:09 +04:00
|
|
|
*/
|
2011-05-07 00:40:09 +04:00
|
|
|
lwc_string *content_get_mime_type(hlcache_handle *h)
|
2010-04-07 13:12:09 +04:00
|
|
|
{
|
|
|
|
return content__get_mime_type(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
lwc_string *content__get_mime_type(struct content *c)
|
2010-04-07 13:12:09 +04:00
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return lwc_string_ref(c->mime_type);
|
2010-04-07 13:12:09 +04:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
|
|
|
* Retrieve URL associated with content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve URL from
|
|
|
|
* \return Pointer to URL, or NULL if not found.
|
|
|
|
*/
|
|
|
|
const char *content_get_url(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_url(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *content__get_url(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return llcache_handle_get_url(c->llcache);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve title associated with content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve title from
|
|
|
|
* \return Pointer to title, or NULL if not found.
|
|
|
|
*/
|
|
|
|
const char *content_get_title(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_title(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *content__get_title(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return c->title != NULL ? c->title : llcache_handle_get_url(c->llcache);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve status of content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve status of
|
|
|
|
* \return Content status
|
|
|
|
*/
|
|
|
|
content_status content_get_status(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_status(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
content_status content__get_status(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
2011-02-28 23:38:23 +03:00
|
|
|
return CONTENT_STATUS_ERROR;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
return c->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve status message associated with content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve status message from
|
|
|
|
* \return Pointer to status message, or NULL if not found.
|
|
|
|
*/
|
|
|
|
const char *content_get_status_message(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_status_message(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *content__get_status_message(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return c->status_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve width of content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve width of
|
|
|
|
* \return Content width
|
|
|
|
*/
|
|
|
|
int content_get_width(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_width(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
int content__get_width(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return c->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve height of content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve height of
|
|
|
|
* \return Content height
|
|
|
|
*/
|
|
|
|
int content_get_height(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_height(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
int content__get_height(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return c->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve available width of content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve available width of
|
|
|
|
* \return Available width of content
|
|
|
|
*/
|
|
|
|
int content_get_available_width(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_available_width(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
int content__get_available_width(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return c->available_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve source of content
|
|
|
|
*
|
2010-03-28 20:00:54 +04:00
|
|
|
* \param c Content to retrieve source of
|
|
|
|
* \param size Pointer to location to receive byte size of source
|
2010-03-28 16:56:39 +04:00
|
|
|
* \return Pointer to source data
|
|
|
|
*/
|
|
|
|
const char *content_get_source_data(hlcache_handle *h, unsigned long *size)
|
|
|
|
{
|
|
|
|
return content__get_source_data(hlcache_handle_get_content(h), size);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *content__get_source_data(struct content *c, unsigned long *size)
|
|
|
|
{
|
|
|
|
const uint8_t *data;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
assert(size != NULL);
|
|
|
|
|
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
data = llcache_handle_get_source_data(c->llcache, &len);
|
|
|
|
|
|
|
|
*size = (unsigned long) len;
|
|
|
|
|
|
|
|
return (const char *) data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidate content reuse data: causes subsequent requests for content URL
|
|
|
|
* to query server to determine if content can be reused. This is required
|
|
|
|
* behaviour for forced reloads etc.
|
|
|
|
*
|
|
|
|
* \param c Content to invalidate
|
|
|
|
*/
|
|
|
|
void content_invalidate_reuse_data(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
content__invalidate_reuse_data(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
void content__invalidate_reuse_data(struct content *c)
|
|
|
|
{
|
2010-04-17 00:43:36 +04:00
|
|
|
if (c == NULL || c->llcache == NULL)
|
2010-03-28 16:56:39 +04:00
|
|
|
return;
|
|
|
|
|
2010-04-17 00:43:36 +04:00
|
|
|
/* Invalidate low-level cache data */
|
|
|
|
llcache_handle_invalidate_cache_data(c->llcache);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the refresh URL for a content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve refresh URL from
|
|
|
|
* \return Pointer to URL, or NULL if none
|
|
|
|
*/
|
|
|
|
const char *content_get_refresh_url(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_refresh_url(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *content__get_refresh_url(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return c->refresh;
|
|
|
|
}
|
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the bitmap contained in an image content
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve bitmap from
|
|
|
|
* \return Pointer to bitmap, or NULL if none.
|
|
|
|
*/
|
|
|
|
struct bitmap *content_get_bitmap(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_bitmap(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bitmap *content__get_bitmap(struct content *c)
|
|
|
|
{
|
2011-08-31 16:12:41 +04:00
|
|
|
struct bitmap *bitmap = NULL;
|
|
|
|
|
|
|
|
if ((c != NULL) &&
|
|
|
|
(c->handler != NULL) &&
|
|
|
|
(c->handler->type != NULL) &&
|
2011-09-03 13:27:42 +04:00
|
|
|
(c->handler->type() == CONTENT_IMAGE) &&
|
2011-08-31 16:12:41 +04:00
|
|
|
(c->handler->get_internal != NULL) ) {
|
|
|
|
bitmap = c->handler->get_internal(c, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a content is opaque from handle
|
|
|
|
*
|
|
|
|
* \param h high level cache handle to retrieve opacity from.
|
|
|
|
* \return false if the content is not opaque or information is not
|
|
|
|
* known else true.
|
|
|
|
*/
|
|
|
|
bool content_get_opaque(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__get_opaque(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a content is opaque
|
|
|
|
*
|
|
|
|
* \param c Content to retrieve opacity from
|
|
|
|
* \return false if the content is not opaque or information is not
|
|
|
|
* known else true.
|
|
|
|
*/
|
|
|
|
bool content__get_opaque(struct content *c)
|
|
|
|
{
|
|
|
|
bool opaque = false;
|
|
|
|
|
|
|
|
if ((c != NULL) &&
|
|
|
|
(c->handler != NULL) &&
|
|
|
|
(c->handler->type != NULL) &&
|
2011-09-03 13:27:42 +04:00
|
|
|
(c->handler->type() == CONTENT_IMAGE) &&
|
2011-08-31 16:12:41 +04:00
|
|
|
(c->handler->get_internal != NULL) ) {
|
|
|
|
struct bitmap *bitmap = NULL;
|
|
|
|
bitmap = c->handler->get_internal(c, NULL);
|
|
|
|
if (bitmap != NULL) {
|
|
|
|
opaque = bitmap_get_opaque(bitmap);
|
|
|
|
}
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
return opaque;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2010-04-17 00:54:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve quirkiness of a content
|
|
|
|
*
|
|
|
|
* \param h Content to examine
|
|
|
|
* \return True if content is quirky, false otherwise
|
|
|
|
*/
|
|
|
|
bool content_get_quirks(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
struct content *c = hlcache_handle_get_content(h);
|
|
|
|
|
|
|
|
if (c == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return c->quirks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-07 22:50:18 +04:00
|
|
|
/**
|
|
|
|
* Return whether a content is currently locked
|
|
|
|
*
|
|
|
|
* \param c Content to test
|
|
|
|
* \return true iff locked, else false
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool content_is_locked(hlcache_handle *h)
|
|
|
|
{
|
|
|
|
return content__is_locked(hlcache_handle_get_content(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool content__is_locked(struct content *c)
|
|
|
|
{
|
|
|
|
return c->locked;
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the low-level cache handle for a content
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve from
|
|
|
|
* \return Low-level cache handle
|
|
|
|
*/
|
|
|
|
const llcache_handle *content_get_llcache_handle(struct content *c)
|
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return c->llcache;
|
|
|
|
}
|
|
|
|
|
2010-04-04 16:41:19 +04:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
struct content *nc;
|
|
|
|
nserror error;
|
2010-04-04 16:41:19 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
error = c->handler->clone(c, &nc);
|
|
|
|
if (error != NSERROR_OK)
|
2010-04-04 16:41:19 +04:00
|
|
|
return NULL;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
return nc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clone a content's data members
|
|
|
|
*
|
|
|
|
* \param c Content to clone
|
|
|
|
* \param nc Content to populate (allocated with talloc)
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise
|
|
|
|
*/
|
|
|
|
nserror content__clone(const struct content *c, struct content *nc)
|
|
|
|
{
|
2011-09-18 04:49:34 +04:00
|
|
|
struct content_user *user_sentinel;
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror error;
|
|
|
|
|
2011-09-18 04:49:34 +04:00
|
|
|
user_sentinel = talloc_zero(c, struct content_user);
|
|
|
|
if (user_sentinel == NULL) {
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
error = llcache_handle_clone(c->llcache, &(nc->llcache));
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
return error;
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
llcache_handle_change_callback(nc->llcache,
|
|
|
|
content_llcache_callback, nc);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nc->mime_type = lwc_string_ref(c->mime_type);
|
|
|
|
nc->handler = c->handler;
|
2010-04-04 16:41:19 +04:00
|
|
|
|
|
|
|
nc->status = c->status;
|
|
|
|
|
|
|
|
nc->width = c->width;
|
|
|
|
nc->height = c->height;
|
|
|
|
nc->available_width = c->available_width;
|
|
|
|
nc->quirks = c->quirks;
|
|
|
|
|
|
|
|
if (c->fallback_charset != NULL) {
|
|
|
|
nc->fallback_charset = talloc_strdup(nc, c->fallback_charset);
|
|
|
|
if (nc->fallback_charset == NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_NOMEM;
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->refresh != NULL) {
|
|
|
|
nc->refresh = talloc_strdup(nc, c->refresh);
|
|
|
|
if (nc->refresh == NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_NOMEM;
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nc->time = c->time;
|
|
|
|
nc->reformat_time = c->reformat_time;
|
|
|
|
nc->size = c->size;
|
|
|
|
nc->talloc_size = c->talloc_size;
|
|
|
|
|
|
|
|
if (c->title != NULL) {
|
|
|
|
nc->title = talloc_strdup(nc, c->title);
|
|
|
|
if (nc->title == NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_NOMEM;
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nc->active = c->active;
|
2011-09-18 04:49:34 +04:00
|
|
|
|
|
|
|
nc->user_list = user_sentinel;
|
2010-04-04 16:41:19 +04:00
|
|
|
|
|
|
|
memcpy(&(nc->status_message), &(c->status_message), 120);
|
|
|
|
memcpy(&(nc->sub_status), &(c->sub_status), 80);
|
|
|
|
|
|
|
|
nc->locked = c->locked;
|
|
|
|
nc->total_size = c->total_size;
|
|
|
|
nc->http_code = c->http_code;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_OK;
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
LOG(("Aborting %p", c));
|
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
if (c->handler->stop != NULL)
|
|
|
|
c->handler->stop(c);
|
2010-04-04 16:41:19 +04:00
|
|
|
|
|
|
|
/* And for now, abort our llcache object */
|
|
|
|
return llcache_handle_abort(c->llcache);
|
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|