From 6807fa854da64166e84efd0074b1e4dfeb5d8b17 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 4 Sep 2011 06:28:09 +0000 Subject: Sniff content types where appropriate. We never sniff for CSS, nor for non-page artefacts (e.g. treeview icons) svn path=/trunk/netsurf/; revision=12707 --- content/content_factory.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'content/content_factory.c') diff --git a/content/content_factory.c b/content/content_factory.c index d3a69c34d..8baa20f7a 100644 --- a/content/content_factory.c +++ b/content/content_factory.c @@ -147,42 +147,43 @@ content_type content_factory_type_from_mime_type(lwc_string *mime_type) * \param llcache Underlying source data handle * \param fallback_charset Character set to fall back to if none specified * \param quirks Quirkiness of containing document + * \param effective_type Effective MIME type of content * \return Pointer to content object, or NULL on failure */ struct content *content_factory_create_content(llcache_handle *llcache, - const char *fallback_charset, bool quirks) + const char *fallback_charset, bool quirks, + lwc_string *effective_type) { struct content *c; const char *content_type_header; const content_handler *handler; - http_content_type *ct; + http_content_type *ct = NULL; nserror error; - content_type_header = - llcache_handle_get_header(llcache, "Content-Type"); - if (content_type_header == NULL) - content_type_header = "text/plain"; - - error = http_parse_content_type(content_type_header, &ct); - if (error != NSERROR_OK) + handler = content_lookup(effective_type); + if (handler == NULL) return NULL; - handler = content_lookup(ct->media_type); - if (handler == NULL) { - http_content_type_destroy(ct); - return NULL; + assert(handler->create != NULL); + + /* Use the parameters from the declared Content-Type header */ + content_type_header = + llcache_handle_get_header(llcache, "Content-Type"); + if (content_type_header != NULL) { + /* We don't care if this fails */ + http_parse_content_type(content_type_header, &ct); } - assert(handler->create != NULL); + error = handler->create(handler, effective_type, + ct != NULL ? ct->parameters : NULL, + llcache, fallback_charset, quirks, + &c); - error = handler->create(handler, ct->media_type, ct->parameters, - llcache, fallback_charset, quirks, &c); - if (error != NSERROR_OK) { + if (ct != NULL) http_content_type_destroy(ct); - return NULL; - } - http_content_type_destroy(ct); + if (error != NSERROR_OK) + return NULL; return c; } -- cgit v1.2.3