r10046 jmb - in /branches/jmb/new-cache/content: content.c content.h
hlcache.c
netsurf at semichrome.net
netsurf at semichrome.net
Sun Feb 14 10:11:58 GMT 2010
Author: jmb
Date: Sun Feb 14 04:11:57 2010
New Revision: 10046
URL: http://source.netsurf-browser.org?rev=10046&view=rev
Log:
Merge content_create and content_set_type
Modified:
branches/jmb/new-cache/content/content.c
branches/jmb/new-cache/content/content.h
branches/jmb/new-cache/content/hlcache.c
Modified: branches/jmb/new-cache/content/content.c
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/content/content.c?rev=10046&r1=10045&r2=10046&view=diff
==============================================================================
--- branches/jmb/new-cache/content/content.c (original)
+++ branches/jmb/new-cache/content/content.c Sun Feb 14 04:11:57 2010
@@ -360,7 +360,7 @@
/**
* Convert a MIME type to a content_type.
*
- * The returned ::content_type will always be suitable for content_set_type().
+ * The returned ::content_type will always be suitable for content_create().
*/
content_type content_lookup(const char *mime_type)
@@ -394,6 +394,19 @@
{
struct content *c;
struct content_user *user_sentinel;
+ const char *mime_type;
+ content_type type;
+ const char *params[] = { NULL };
+
+ /** \todo This breaks if there are parameters. llcache should deal */
+ mime_type = llcache_handle_get_header(llcache, "Content-Type");
+ if (mime_type == NULL)
+ mime_type = "text/plain";
+
+ /** \todo Distinguish between unknown type and memory exhaustion */
+ type = content_lookup(mime_type);
+ if (type == CONTENT_OTHER)
+ return NULL;
c = talloc_zero(0, struct content);
if (!c)
@@ -413,21 +426,26 @@
return NULL;
}
+ c->mime_type = talloc_strdup(c, mime_type);
+ if (c->mime_type == NULL) {
+ talloc_free(c);
+ return NULL;
+ }
+
c->llcache = llcache;
c->dict = lwc_context_ref(dict);
- c->type = CONTENT_UNKNOWN;
- c->mime_type = 0;
- c->status = CONTENT_STATUS_TYPE_UNKNOWN;
+ c->type = type;
+ c->status = CONTENT_STATUS_LOADING;
c->width = 0;
c->height = 0;
c->available_width = 0;
c->quirks = quirks;
c->refresh = 0;
- c->bitmap = 0;
+ c->bitmap = NULL;
c->fresh = false;
c->time = wallclock();
c->size = 0;
- c->title = 0;
+ c->title = NULL;
c->active = 0;
user_sentinel->callback = NULL;
user_sentinel->pw = NULL;
@@ -441,6 +459,13 @@
content_set_status(c, messages_get("Loading"));
+ if (handler_map[type].create) {
+ if (handler_map[type].create(c, params) == false) {
+ talloc_free(c);
+ return NULL;
+ }
+ }
+
return c;
}
@@ -454,59 +479,6 @@
bool content_can_reformat(struct content *c)
{
return (handler_map[c->type].reformat != NULL);
-}
-
-
-/**
- * Initialise the content for the specified type.
- *
- * \param c content structure
- * \param type content_type to initialise to
- * \param mime_type MIME-type string for this content
- * \param params array of strings, ordered attribute, value, attribute, ..., 0
- * \return true on success, false on error and error broadcast to users and
- * possibly reported
- *
- * The type is updated to the given type, and a copy of mime_type is taken. The
- * status is changed to CONTENT_STATUS_LOADING. CONTENT_MSG_LOADING is sent to
- * all users. The create function for the type is called to initialise the type
- * specific parts of the content structure.
- */
-
-bool content_set_type(struct content *c, content_type type,
- const char *mime_type, const char *params[],
- struct content *parent)
-{
- union content_msg_data msg_data;
-
- assert(c != 0);
- assert(c->status == CONTENT_STATUS_TYPE_UNKNOWN);
- assert(type < CONTENT_UNKNOWN);
-
- LOG(("content %s (%p), type %i",
- llcache_handle_get_url(c->llcache), c, type));
-
- c->mime_type = talloc_strdup(c, mime_type);
- if (!c->mime_type) {
- c->status = CONTENT_STATUS_ERROR;
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- c->type = type;
- c->status = CONTENT_STATUS_LOADING;
-
- if (handler_map[type].create) {
- if (!handler_map[type].create(c, params)) {
- c->type = CONTENT_UNKNOWN;
- c->status = CONTENT_STATUS_ERROR;
- return false;
- }
- }
-
- content_broadcast(c, CONTENT_MSG_LOADING, msg_data);
- return true;
}
Modified: branches/jmb/new-cache/content/content.h
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/content/content.h?rev=10046&r1=10045&r2=10046&view=diff
==============================================================================
--- branches/jmb/new-cache/content/content.h (original)
+++ branches/jmb/new-cache/content/content.h Sun Feb 14 04:11:57 2010
@@ -103,9 +103,6 @@
lwc_context *dict, const char *fallback_charset, bool quirks);
void content_destroy(struct content *c);
bool content_can_reformat(struct content *c);
-bool content_set_type(struct content *c, content_type type,
- const char *mime_type, const char *params[],
- struct content *parent);
void content_set_status(struct content *c, const char *status_message, ...);
bool content_process_data(struct content *c, const char *data,
unsigned int size);
Modified: branches/jmb/new-cache/content/hlcache.c
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/content/hlcache.c?rev=10046&r1=10045&r2=10046&view=diff
==============================================================================
--- branches/jmb/new-cache/content/hlcache.c (original)
+++ branches/jmb/new-cache/content/hlcache.c Sun Feb 14 04:11:57 2010
@@ -318,6 +318,8 @@
/* Associate cache entry with handle */
ctx->handle->entry = entry;
+ /** \todo Catch new handle up with state of content */
+
return NSERROR_OK;
}
More information about the netsurf-commits
mailing list