2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2009-07-24 03:05:34 +04:00
|
|
|
* Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-04-04 19:19:32 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2009-07-24 03:05:34 +04:00
|
|
|
|
|
|
|
#include <libwapcaplet/libwapcaplet.h>
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "content/fetchcache.h"
|
|
|
|
#include "css/css.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "css/internal.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/gui.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "render/html.h"
|
2009-07-26 01:42:27 +04:00
|
|
|
#include "utils/messages.h"
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
static void nscss_import(content_msg msg, struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data);
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2005-01-16 03:03:45 +03:00
|
|
|
/**
|
2009-07-24 03:05:34 +04:00
|
|
|
* Allocation callback for libcss
|
2005-01-16 03:03:45 +03:00
|
|
|
*
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param ptr Pointer to reallocate, or NULL for new allocation
|
|
|
|
* \param size Number of bytes requires
|
|
|
|
* \param pw Allocation context
|
|
|
|
* \return Pointer to allocated block, or NULL on failure
|
2005-01-16 03:03:45 +03:00
|
|
|
*/
|
2009-07-24 03:05:34 +04:00
|
|
|
static void *myrealloc(void *ptr, size_t size, void *pw)
|
2005-01-16 03:03:45 +03:00
|
|
|
{
|
2009-07-24 03:05:34 +04:00
|
|
|
return realloc(ptr, size);
|
2005-01-16 03:03:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-07-24 03:05:34 +04:00
|
|
|
* Initialise a CSS content
|
2005-01-16 03:03:45 +03:00
|
|
|
*
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param c Content to initialise
|
|
|
|
* \param parent Parent content, or NULL if top-level
|
|
|
|
* \param params Content-Type parameters
|
|
|
|
* \return true on success, false on failure
|
2005-01-16 03:03:45 +03:00
|
|
|
*/
|
2009-07-24 03:05:34 +04:00
|
|
|
bool nscss_create(struct content *c, struct content *parent,
|
|
|
|
const char *params[])
|
2005-01-16 03:03:45 +03:00
|
|
|
{
|
2009-07-27 17:56:05 +04:00
|
|
|
const char *charset = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_origin origin = CSS_ORIGIN_AUTHOR;
|
2009-07-27 17:49:10 +04:00
|
|
|
uint64_t media = CSS_MEDIA_ALL;
|
2009-07-24 03:05:34 +04:00
|
|
|
lwc_context *dict = NULL;
|
|
|
|
bool quirks = true;
|
2009-07-27 17:49:10 +04:00
|
|
|
uint32_t i;
|
2009-07-26 01:42:27 +04:00
|
|
|
union content_msg_data msg_data;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_error error;
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/** \todo what happens about the allocator? */
|
2009-07-26 01:42:27 +04:00
|
|
|
/** \todo proper error reporting */
|
2005-01-16 03:48:47 +03:00
|
|
|
|
2009-07-27 17:56:05 +04:00
|
|
|
/* Find charset specified on HTTP layer, if any */
|
|
|
|
/** \todo What happens if there isn't one and parent content exists? */
|
|
|
|
for (i = 0; params[i] != NULL; i += 2) {
|
2009-07-27 18:57:40 +04:00
|
|
|
if (strcasecmp(params[i], "charset") == 0) {
|
2009-07-27 17:56:05 +04:00
|
|
|
charset = params[i + 1];
|
2009-07-27 18:57:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-07-27 17:56:05 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (parent != NULL) {
|
|
|
|
assert(parent->type == CONTENT_HTML ||
|
|
|
|
parent->type == CONTENT_CSS);
|
2005-01-16 03:03:45 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (parent->type == CONTENT_HTML) {
|
|
|
|
assert(parent->data.html.dict != NULL);
|
2005-01-16 03:03:45 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (c == parent->data.html.
|
2009-07-27 17:49:10 +04:00
|
|
|
stylesheets[STYLESHEET_BASE].c ||
|
2009-07-24 03:05:34 +04:00
|
|
|
c == parent->data.html.
|
2009-07-27 17:49:10 +04:00
|
|
|
stylesheets[STYLESHEET_QUIRKS].c ||
|
2009-07-24 03:05:34 +04:00
|
|
|
c == parent->data.html.
|
2009-07-27 17:49:10 +04:00
|
|
|
stylesheets[STYLESHEET_ADBLOCK].c)
|
2009-07-24 03:05:34 +04:00
|
|
|
origin = CSS_ORIGIN_UA;
|
2005-01-17 00:39:21 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
quirks = (parent->data.html.quirks !=
|
|
|
|
BINDING_QUIRKS_MODE_NONE);
|
2005-01-17 00:39:21 +03:00
|
|
|
|
2009-07-27 17:49:10 +04:00
|
|
|
for (i = 0; i < parent->data.html.stylesheet_count;
|
|
|
|
i++) {
|
2009-07-27 18:57:40 +04:00
|
|
|
if (parent->data.html.stylesheets[i].c == c) {
|
2009-07-27 17:49:10 +04:00
|
|
|
media = parent->data.html.
|
|
|
|
stylesheets[i].media;
|
2009-07-27 18:57:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-07-27 17:49:10 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
dict = parent->data.html.dict;
|
|
|
|
} else {
|
|
|
|
assert(parent->data.css.sheet != NULL);
|
|
|
|
assert(parent->data.css.dict != NULL);
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
error = css_stylesheet_get_origin(
|
|
|
|
parent->data.css.sheet, &origin);
|
2009-07-26 01:42:27 +04:00
|
|
|
if (error != CSS_OK) {
|
|
|
|
msg_data.error = "?";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
return false;
|
2009-07-26 01:42:27 +04:00
|
|
|
}
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
error = css_stylesheet_quirks_allowed(
|
|
|
|
parent->data.css.sheet, &quirks);
|
2009-07-26 01:42:27 +04:00
|
|
|
if (error != CSS_OK) {
|
|
|
|
msg_data.error = "?";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
return false;
|
2009-07-26 01:42:27 +04:00
|
|
|
}
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2009-07-27 17:49:10 +04:00
|
|
|
for (i = 0; i < parent->data.css.import_count; i++) {
|
2009-07-27 18:57:40 +04:00
|
|
|
if (parent->data.css.imports[i].c == c) {
|
2009-07-27 17:49:10 +04:00
|
|
|
media = parent->data.css.
|
|
|
|
imports[i].media;
|
2009-07-27 18:57:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-07-27 17:49:10 +04:00
|
|
|
}
|
2005-01-17 00:39:21 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
dict = parent->data.css.dict;
|
2005-01-17 00:39:21 +03:00
|
|
|
}
|
|
|
|
}
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (dict == NULL) {
|
|
|
|
lwc_error lerror = lwc_create_context(myrealloc, NULL, &dict);
|
2005-01-17 00:39:21 +03:00
|
|
|
|
2009-07-26 01:42:27 +04:00
|
|
|
if (lerror != lwc_error_ok) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
return false;
|
2009-07-26 01:42:27 +04:00
|
|
|
}
|
2005-01-17 00:39:21 +03:00
|
|
|
}
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
c->data.css.dict = lwc_context_ref(dict);
|
|
|
|
c->data.css.import_count = 0;
|
|
|
|
c->data.css.imports = NULL;
|
|
|
|
|
2009-07-27 17:56:05 +04:00
|
|
|
error = css_stylesheet_create(CSS_LEVEL_21, charset,
|
2009-07-24 03:05:34 +04:00
|
|
|
c->url, NULL, origin, media, quirks, false,
|
|
|
|
c->data.css.dict,
|
|
|
|
myrealloc, NULL,
|
|
|
|
nscss_resolve_url, NULL,
|
|
|
|
&c->data.css.sheet);
|
|
|
|
if (error != CSS_OK) {
|
|
|
|
lwc_context_unref(c->data.css.dict);
|
|
|
|
c->data.css.dict = NULL;
|
2009-07-26 01:42:27 +04:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
2005-01-05 23:22:57 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return true;
|
2003-04-04 19:19:32 +04:00
|
|
|
}
|
|
|
|
|
2004-05-01 21:48:38 +04:00
|
|
|
/**
|
2009-07-24 03:05:34 +04:00
|
|
|
* Process CSS source data
|
2004-05-01 21:48:38 +04:00
|
|
|
*
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param c Content structure
|
|
|
|
* \param data Data to process
|
|
|
|
* \param size Number of bytes to process
|
|
|
|
* \return true on success, false on failure
|
2004-05-01 21:48:38 +04:00
|
|
|
*/
|
2009-07-24 03:05:34 +04:00
|
|
|
bool nscss_process_data(struct content *c, char *data, unsigned int size)
|
2003-04-04 19:19:32 +04:00
|
|
|
{
|
2009-07-26 01:42:27 +04:00
|
|
|
union content_msg_data msg_data;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_error error;
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
error = css_stylesheet_append_data(c->data.css.sheet,
|
|
|
|
(const uint8_t *) data, size);
|
2004-05-01 21:48:38 +04:00
|
|
|
|
2009-07-26 01:42:27 +04:00
|
|
|
if (error != CSS_OK && error != CSS_NEEDDATA) {
|
|
|
|
msg_data.error = "?";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return (error == CSS_OK || error == CSS_NEEDDATA);
|
2004-05-01 21:48:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-07-24 03:05:34 +04:00
|
|
|
* Convert a CSS content ready for use
|
2004-05-01 21:48:38 +04:00
|
|
|
*
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param c Content to convert
|
|
|
|
* \param w Width of area content will be displayed in
|
|
|
|
* \param h Height of area content will be displayed in
|
|
|
|
* \return true on success, false on failure
|
2004-05-01 21:48:38 +04:00
|
|
|
*/
|
2009-07-24 03:05:34 +04:00
|
|
|
bool nscss_convert(struct content *c, int w, int h)
|
2003-04-06 22:09:34 +04:00
|
|
|
{
|
2009-07-26 01:42:27 +04:00
|
|
|
union content_msg_data msg_data;
|
2009-07-24 03:05:34 +04:00
|
|
|
css_error error;
|
2003-04-06 22:09:34 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
error = css_stylesheet_data_done(c->data.css.sheet);
|
2003-04-06 22:09:34 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Process pending imports */
|
|
|
|
while (error == CSS_IMPORTS_PENDING) {
|
2009-07-27 17:49:10 +04:00
|
|
|
struct nscss_import *imports;
|
2009-07-24 03:05:34 +04:00
|
|
|
uint32_t i;
|
|
|
|
lwc_string *uri;
|
|
|
|
uint64_t media;
|
|
|
|
css_stylesheet *sheet;
|
|
|
|
|
|
|
|
error = css_stylesheet_next_pending_import(c->data.css.sheet,
|
|
|
|
&uri, &media);
|
|
|
|
if (error != CSS_OK && error != CSS_INVALID) {
|
2009-07-26 01:42:27 +04:00
|
|
|
msg_data.error = "?";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
2004-05-01 21:48:38 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Give up if there are no more imports */
|
|
|
|
if (error == CSS_INVALID) {
|
|
|
|
error = CSS_OK;
|
2003-04-06 22:09:34 +04:00
|
|
|
break;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
2003-04-06 22:09:34 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Increase space in table */
|
|
|
|
imports = realloc(c->data.css.imports,
|
|
|
|
(c->data.css.import_count + 1) *
|
2009-07-27 17:49:10 +04:00
|
|
|
sizeof(struct nscss_import));
|
2009-07-24 03:05:34 +04:00
|
|
|
if (imports == NULL) {
|
2009-07-26 01:42:27 +04:00
|
|
|
msg_data.error = "?";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
return false;
|
2003-04-06 22:09:34 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
c->data.css.imports = imports;
|
|
|
|
|
|
|
|
/* Create content */
|
|
|
|
i = c->data.css.import_count;
|
2009-07-27 17:49:10 +04:00
|
|
|
c->data.css.imports[c->data.css.import_count].media = media;
|
|
|
|
c->data.css.imports[c->data.css.import_count++].c =
|
2009-07-25 19:47:11 +04:00
|
|
|
fetchcache(lwc_string_data(uri),
|
2009-07-24 03:05:34 +04:00
|
|
|
nscss_import, (intptr_t) c, i,
|
|
|
|
c->width, c->height, true, NULL, NULL,
|
|
|
|
false, false);
|
2009-07-27 17:49:10 +04:00
|
|
|
if (c->data.css.imports[i].c == NULL) {
|
2009-07-26 01:42:27 +04:00
|
|
|
msg_data.error = "?";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
return false;
|
2003-04-06 22:09:34 +04:00
|
|
|
}
|
2009-02-10 21:35:56 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Fetch content */
|
2003-06-17 23:24:21 +04:00
|
|
|
c->active++;
|
2009-07-27 17:49:10 +04:00
|
|
|
fetchcache_go(c->data.css.imports[i].c, c->url,
|
2009-07-24 03:05:34 +04:00
|
|
|
nscss_import, (intptr_t) c, i,
|
|
|
|
c->width, c->height, NULL, NULL, false, c);
|
|
|
|
|
|
|
|
/* Wait for import to fetch + convert */
|
|
|
|
while (c->active > 0) {
|
|
|
|
fetch_poll();
|
|
|
|
gui_multitask();
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:49:10 +04:00
|
|
|
if (c->data.css.imports[i].c != NULL) {
|
|
|
|
sheet = c->data.css.imports[i].c->data.css.sheet;
|
|
|
|
c->data.css.imports[i].c->data.css.sheet = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
} else {
|
|
|
|
error = css_stylesheet_create(CSS_LEVEL_DEFAULT,
|
|
|
|
NULL, "", NULL, CSS_ORIGIN_AUTHOR,
|
|
|
|
media, false, false, c->data.css.dict,
|
|
|
|
myrealloc, NULL,
|
|
|
|
nscss_resolve_url, NULL,
|
|
|
|
&sheet);
|
|
|
|
if (error != CSS_OK) {
|
2009-07-26 01:42:27 +04:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
return false;
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
error = css_stylesheet_register_import(
|
|
|
|
c->data.css.sheet, sheet);
|
|
|
|
if (error != CSS_OK) {
|
2009-07-26 01:42:27 +04:00
|
|
|
msg_data.error = "?";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
2009-07-24 03:05:34 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-22 18:13:10 +03:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
error = CSS_IMPORTS_PENDING;
|
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Filthy hack to stop this content being reused
|
|
|
|
* when whatever is using it has finished with it. */
|
|
|
|
c->fresh = false;
|
2004-08-11 23:02:32 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
return error == CSS_OK;
|
2003-04-06 22:09:34 +04:00
|
|
|
}
|
|
|
|
|
2004-08-05 05:57:14 +04:00
|
|
|
/**
|
2009-07-24 03:05:34 +04:00
|
|
|
* Clean up a CSS content
|
2005-05-22 03:30:19 +04:00
|
|
|
*
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param c Content to clean up
|
2004-08-05 05:57:14 +04:00
|
|
|
*/
|
2009-07-24 03:05:34 +04:00
|
|
|
void nscss_destroy(struct content *c)
|
2004-08-05 05:57:14 +04:00
|
|
|
{
|
2009-07-24 03:05:34 +04:00
|
|
|
uint32_t i;
|
2005-05-22 03:30:19 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
for (i = 0; i < c->data.css.import_count; i++) {
|
2009-07-27 17:49:10 +04:00
|
|
|
if (c->data.css.imports[i].c != NULL) {
|
|
|
|
content_remove_user(c->data.css.imports[i].c,
|
2009-07-24 03:05:34 +04:00
|
|
|
nscss_import, (uintptr_t) c, i);
|
2005-05-22 03:30:19 +04:00
|
|
|
}
|
2009-07-27 17:49:10 +04:00
|
|
|
c->data.css.imports[i].c = NULL;
|
2004-08-05 05:57:14 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
free(c->data.css.imports);
|
2004-08-05 05:57:14 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (c->data.css.sheet != NULL) {
|
|
|
|
css_stylesheet_destroy(c->data.css.sheet);
|
|
|
|
c->data.css.sheet = NULL;
|
2005-05-22 03:30:19 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
if (c->data.css.dict != NULL) {
|
|
|
|
lwc_context_unref(c->data.css.dict);
|
|
|
|
c->data.css.dict = NULL;
|
2004-08-05 05:57:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 03:36:34 +04:00
|
|
|
/**
|
2009-07-24 03:05:34 +04:00
|
|
|
* Fetchcache handler for imported stylesheets
|
2004-05-01 21:48:38 +04:00
|
|
|
*
|
2009-07-24 03:05:34 +04:00
|
|
|
* \param msg Message type
|
|
|
|
* \param c Content being fetched
|
|
|
|
* \param p1 Parent content
|
|
|
|
* \param p2 Index into parent's imported stylesheet array
|
|
|
|
* \param data Message data
|
2003-09-28 03:36:34 +04:00
|
|
|
*/
|
2009-07-24 03:05:34 +04:00
|
|
|
void nscss_import(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data)
|
2003-09-28 03:36:34 +04:00
|
|
|
{
|
2009-07-24 03:05:34 +04:00
|
|
|
struct content *parent = (struct content *) p1;
|
|
|
|
uint32_t i = (uint32_t) p2;
|
2004-08-05 05:57:14 +04:00
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
switch (msg) {
|
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
if (c->type != CONTENT_CSS) {
|
|
|
|
content_remove_user(c, nscss_import, p1, p2);
|
|
|
|
if (c->user_list->next == NULL) {
|
|
|
|
fetch_abort(c->fetch);
|
|
|
|
c->fetch = NULL;
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
}
|
2004-08-05 05:57:14 +04:00
|
|
|
|
2009-07-27 17:49:10 +04:00
|
|
|
parent->data.css.imports[i].c = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
parent->active--;
|
|
|
|
content_add_error(parent, "NotCSS", 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
case CONTENT_MSG_DONE:
|
|
|
|
parent->active--;
|
|
|
|
break;
|
|
|
|
case CONTENT_MSG_AUTH:
|
|
|
|
case CONTENT_MSG_SSL:
|
|
|
|
case CONTENT_MSG_LAUNCH:
|
|
|
|
case CONTENT_MSG_ERROR:
|
2009-07-27 17:49:10 +04:00
|
|
|
if (parent->data.css.imports[i].c == c) {
|
|
|
|
parent->data.css.imports[i].c = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
parent->active--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONTENT_MSG_STATUS:
|
|
|
|
break;
|
|
|
|
case CONTENT_MSG_NEWPTR:
|
2009-07-27 17:49:10 +04:00
|
|
|
parent->data.css.imports[i].c = c;
|
2009-07-24 03:05:34 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2005-05-22 03:30:19 +04:00
|
|
|
}
|
2003-09-28 03:36:34 +04:00
|
|
|
}
|
2003-04-06 22:09:34 +04:00
|
|
|
|