20 #include <libwapcaplet/libwapcaplet.h> 38 #undef NSCSS_IMPORT_TRACE 90 const char *url,
const char *
charset,
bool quirks,
126 lwc_string *imime_type,
129 const char *fallback_charset,
135 const char *xnsbase = NULL;
136 lwc_string *charset_value = NULL;
144 params, llcache, fallback_charset, quirks);
153 if (error !=
NSERROR_OK || lwc_string_length(charset_value) == 0) {
156 charset = fallback_charset;
158 charset = lwc_string_data(charset_value);
163 if (xnsbase == NULL) {
172 if (charset_value != NULL)
173 lwc_string_unref(charset_value);
178 if (charset_value != NULL)
179 lwc_string_unref(charset_value);
181 *c = (
struct content *) result;
202 css_stylesheet_params params;
214 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
215 params.level = CSS_LEVEL_DEFAULT;
219 params.allow_quirks =
quirks;
220 params.inline_style =
false;
222 params.resolve_pw = NULL;
224 params.import_pw = c;
226 params.color_pw = NULL;
228 params.font_pw = NULL;
230 error = css_stylesheet_create(¶ms, &c->
sheet);
231 if (error != CSS_OK) {
253 if (error != CSS_OK && error != CSS_NEEDDATA) {
257 return (error == CSS_OK || error == CSS_NEEDDATA);
269 const char *data,
unsigned int size)
271 return css_stylesheet_append_data(c->
sheet,
272 (
const uint8_t *) data, size);
287 if (error != CSS_OK) {
305 error = css_stylesheet_data_done(c->
sheet);
308 if (error == CSS_IMPORTS_PENDING) {
316 }
else if (error == CSS_OK) {
322 if (css_stylesheet_get_url(c->
sheet, &url) == CSS_OK) {
323 NSLOG(netsurf, INFO,
"Failed converting %p %s (%d)",
326 NSLOG(netsurf, INFO,
"Failed converting %p (%d)", c,
364 if (c->
sheet != NULL) {
365 css_stylesheet_destroy(c->
sheet);
406 (
unsigned int)size) ==
false) {
420 *newc = (
struct content *) new_css;
481 error = css_stylesheet_size(css->
sheet, &size);
482 if (error != CSS_OK) {
495 if (
import != NULL) {
496 c->
size +=
import->size;
533 assert(parent == c->
sheet);
535 error = css_stylesheet_get_url(c->
sheet, &referer);
536 if (error != CSS_OK) {
540 ctx = malloc(
sizeof(*ctx));
550 if (imports == NULL) {
558 error = css_stylesheet_quirks_allowed(c->
sheet, &child.
quirks);
559 if (error != CSS_OK) {
601 #ifdef NSCSS_IMPORT_TRACE 602 NSLOG(netsurf, INFO,
"Import %d '%s' -> (handle: %p ctx: %p)",
624 css_error error = CSS_OK;
626 #ifdef NSCSS_IMPORT_TRACE 627 NSLOG(netsurf, INFO,
"Event %d for %p (%p)", event->
type, handle, ctx);
632 switch (event->
type) {
660 css_error error = CSS_OK;
666 #ifdef NSCSS_IMPORT_TRACE 667 NSLOG(netsurf, INFO,
"Destroying import context %p for %d", ctx,
734 css_stylesheet *
sheet;
737 if (
import != NULL) {
744 css_stylesheet_params params;
746 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
747 params.level = CSS_LEVEL_DEFAULT;
748 params.charset = NULL;
751 params.allow_quirks =
false;
752 params.inline_style =
false;
754 params.resolve_pw = NULL;
755 params.import = NULL;
756 params.import_pw = NULL;
758 params.color_pw = NULL;
760 params.font_pw = NULL;
763 if (error != CSS_OK) {
768 if (error != CSS_OK) {
777 error = css_stylesheet_register_import(c->
sheet, sheet);
778 if (error != CSS_OK) {
815 &css_content_handler);
uint32_t index
Index into parent sheet's imports array.
bool quirks
Whether parent is quirky.
static void nscss_fini(void)
Clean up after the CSS content handler.
css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs)
URL resolution callback for libcss.
struct nscss_import * imports
Array of imported sheets.
css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
css callback to obtain named system colour.
char * charset
Character set of stylesheet.
static void nscss_destroy(struct content *c)
Clean up a CSS content.
static css_error nscss_convert_css_data(struct content_css_data *c)
Convert CSS data ready for use.
static void nscss_content_done(struct content_css_data *css, void *pw)
Handle notification that a CSS object is done.
nserror nscss_init(void)
Initialise the CSS content handler.
nserror http_parameter_list_find_item(const http_parameter *list, lwc_string *name, lwc_string **value)
Find a named item in an HTTP parameter list.
bool nsurl_compare(const nsurl *url1, const nsurl *url2, nsurl_component parts)
Compare two URLs.
Localised message support (interface).
content_msg type
Event type.
struct content base
Underlying content object.
nserror css_hint_init(void)
static css_error nscss_register_import(struct content_css_data *c, const hlcache_handle *import)
Register an import with a stylesheet.
bool quirks
Content is in quirks mode.
Context for retrieving a child object.
struct nscss_import * nscss_get_imports(hlcache_handle *h, uint32_t *n)
Retrieve imported stylesheets.
nscss_done_callback done
Completion callback.
struct content_css_data data
CSS data.
struct content_css_data * css
Object containing import.
void(* nscss_done_callback)(struct content_css_data *css, void *pw)
Type of callback called when a CSS object has finished.
static css_error nscss_process_css_data(struct content_css_data *c, const char *data, unsigned int size)
Process CSS data.
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
Send an error message to all users.
High-level resource cache interface.
void content_destroy(struct content *c)
Destroy and free a content.
static css_error nscss_import_complete(nscss_import_ctx *ctx)
Handle an imported stylesheet completing.
nserror content__clone(const struct content *c, struct content *nc)
Clone a content's data members.
static content_type nscss_content_type(void)
Compute the type of a content.
void content_set_error(struct content *c)
Put a content in status CONTENT_STATUS_ERROR and unlock the content.
nserror
Enumeration of error codes.
nsurl * content_get_url(struct content *c)
Retrieve URL associated with content.
uint32_t next_to_register
Index of next import to register.
static nserror nscss_clone(const struct content *old, struct content **newc)
Representation of an HTTP parameter.
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
Useful interned string pointers (interface).
Corresponds to a single URL.
HTTP header parsing functions.
unsigned int size
Estimated size of all data associated with this content.
content_type
The type of a content.
const uint8_t * content__get_source_data(struct content *c, size_t *size)
Retrieve source of content.
static bool nscss_process_data(struct content *c, const char *data, unsigned int size)
Process CSS source data.
const char * charset
Charset of parent.
const char * llcache_handle_get_header(const llcache_handle *handle, const char *key)
Retrieve a header value associated with a low-level cache object.
static struct llcache_s * llcache
low level cache state
#define NSLOG(catname, level, logmsg, args...)
Handle to low-level cache object.
static css_error nscss_register_imports(struct content_css_data *c)
Register imports with a stylesheet.
content_status content_get_status(hlcache_handle *h)
Retrieve status of content.
static nserror nscss_import(hlcache_handle *handle, const hlcache_event *event, void *pw)
Handler for imported stylesheet events.
static css_error nscss_handle_import(void *pw, css_stylesheet *parent, lwc_string *url)
Handle notification of the need for an imported stylesheet.
struct content * hlcache_handle_get_content(const hlcache_handle *handle)
Retrieve a content object from a cache handle.
uint32_t import_count
Number of sheets imported.
Some parts of content still being loaded, but can be displayed.
content_status status
Current status.
static const content_handler css_content_handler
nserror content_factory_register_handler(const char *mime_type, const content_handler *handler)
Register a handler with the content factory.
void content_set_done(struct content *c)
Put a content in status CONTENT_STATUS_DONE.
Imported stylesheet record.
Context for import fetches.
Interface to system colour values.
static bool nscss_convert(struct content *c)
Convert a CSS content ready for use.
struct nscss_content nscss_content
CSS content data.
static void nscss_destroy_css_data(struct content_css_data *c)
Clean up CSS data.
static bool nscss_matches_quirks(const struct content *c, bool quirks)
Interface to a number of general purpose functionality.
static css_stylesheet * blank_import
nserror hlcache_handle_retrieve(nsurl *url, uint32_t flags, nsurl *referer, llcache_post_data *post, hlcache_handle_callback cb, void *pw, hlcache_child_context *child, content_type accepted_types, hlcache_handle **result)
Retrieve a high-level cache handle for an object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
Fetching of data from a URL (interface).
struct hlcache_handle * c
Content containing sheet.
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)
Initialise a new content structure.
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
static nserror nscss_create_css_data(struct content_css_data *c, const char *url, const char *charset, bool quirks, nscss_done_callback done, void *pw)
Create a struct content_css_data, creating a stylesheet object.
struct nsurl nsurl
NetSurf URL object.
Protected interface to Content handling.
css_stylesheet * sheet
Stylesheet object.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
css_stylesheet * nscss_get_stylesheet(struct hlcache_handle *h)
Retrieve the stylesheet object associated with a CSS content.
static nserror nscss_create(const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
Initialise a CSS content.