NetSurf
css.c
Go to the documentation of this file.
1 /*
2  * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
3  *
4  * This file is part of NetSurf, http://www.netsurf-browser.org/
5  *
6  * NetSurf is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * NetSurf is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <assert.h>
20 #include <libwapcaplet/libwapcaplet.h>
21 #include <dom/dom.h>
22 
24 #include "content/fetch.h"
25 #include "content/hlcache.h"
26 #include "desktop/system_colour.h"
27 #include "utils/corestrings.h"
28 #include "utils/utils.h"
29 #include "utils/http.h"
30 #include "utils/log.h"
31 #include "utils/messages.h"
32 
33 #include "css/css.h"
34 #include "css/hints.h"
35 #include "css/internal.h"
36 
37 /* Define to trace import fetches */
38 #undef NSCSS_IMPORT_TRACE
39 
40 struct content_css_data;
41 
42 /**
43  * Type of callback called when a CSS object has finished
44  *
45  * \param css CSS object that has completed
46  * \param pw Client-specific data
47  */
48 typedef void (*nscss_done_callback)(struct content_css_data *css, void *pw);
49 
50 /**
51  * CSS content data
52  */
54 {
55  css_stylesheet *sheet; /**< Stylesheet object */
56  char *charset; /**< Character set of stylesheet */
57  struct nscss_import *imports; /**< Array of imported sheets */
58  uint32_t import_count; /**< Number of sheets imported */
59  uint32_t next_to_register; /**< Index of next import to register */
60  nscss_done_callback done; /**< Completion callback */
61  void *pw; /**< Client data */
62 };
63 
64 /**
65  * CSS content data
66  */
67 typedef struct nscss_content
68 {
69  struct content base; /**< Underlying content object */
70 
71  struct content_css_data data; /**< CSS data */
73 
74 /**
75  * Context for import fetches
76  */
77 typedef struct {
78  struct content_css_data *css; /**< Object containing import */
79  uint32_t index; /**< Index into parent sheet's
80  * imports array */
82 
83 static bool nscss_convert(struct content *c);
84 static void nscss_destroy(struct content *c);
85 static nserror nscss_clone(const struct content *old, struct content **newc);
86 static bool nscss_matches_quirks(const struct content *c, bool quirks);
87 static content_type nscss_content_type(void);
88 
90  const char *url, const char *charset, bool quirks,
91  nscss_done_callback done, void *pw);
92 static css_error nscss_process_css_data(struct content_css_data *c, const char *data,
93  unsigned int size);
94 static css_error nscss_convert_css_data(struct content_css_data *c);
95 static void nscss_destroy_css_data(struct content_css_data *c);
96 
97 static void nscss_content_done(struct content_css_data *css, void *pw);
98 static css_error nscss_handle_import(void *pw, css_stylesheet *parent,
99  lwc_string *url);
100 static nserror nscss_import(hlcache_handle *handle,
101  const hlcache_event *event, void *pw);
102 static css_error nscss_import_complete(nscss_import_ctx *ctx);
103 
104 static css_error nscss_register_imports(struct content_css_data *c);
105 static css_error nscss_register_import(struct content_css_data *c,
106  const hlcache_handle *import);
107 
108 
109 static css_stylesheet *blank_import;
110 
111 
112 /**
113  * Initialise a CSS content
114  *
115  * \param handler content handler
116  * \param imime_type mime-type
117  * \param params Content-Type parameters
118  * \param llcache handle to content
119  * \param fallback_charset The character set to fallback to.
120  * \param quirks allow quirks
121  * \param c Content to initialise
122  * \return NSERROR_OK or error cod eon faliure
123  */
124 static nserror
126  lwc_string *imime_type,
127  const http_parameter *params,
129  const char *fallback_charset,
130  bool quirks,
131  struct content **c)
132 {
134  const char *charset = NULL;
135  const char *xnsbase = NULL;
136  lwc_string *charset_value = NULL;
137  nserror error;
138 
139  result = calloc(1, sizeof(nscss_content));
140  if (result == NULL)
141  return NSERROR_NOMEM;
142 
143  error = content__init(&result->base, handler, imime_type,
144  params, llcache, fallback_charset, quirks);
145  if (error != NSERROR_OK) {
146  free(result);
147  return error;
148  }
149 
150  /* Find charset specified on HTTP layer, if any */
151  error = http_parameter_list_find_item(params, corestring_lwc_charset,
152  &charset_value);
153  if (error != NSERROR_OK || lwc_string_length(charset_value) == 0) {
154  /* No charset specified, use fallback, if any */
155  /** \todo libcss will take this as gospel, which is wrong */
156  charset = fallback_charset;
157  } else {
158  charset = lwc_string_data(charset_value);
159  }
160 
161  /* Compute base URL for stylesheet */
162  xnsbase = llcache_handle_get_header(llcache, "X-NS-Base");
163  if (xnsbase == NULL) {
164  xnsbase = nsurl_access(content_get_url(&result->base));
165  }
166 
167  error = nscss_create_css_data(&result->data,
168  xnsbase, charset, result->base.quirks,
169  nscss_content_done, result);
170  if (error != NSERROR_OK) {
171  content_broadcast_error(&result->base, NSERROR_NOMEM, NULL);
172  if (charset_value != NULL)
173  lwc_string_unref(charset_value);
174  free(result);
175  return error;
176  }
177 
178  if (charset_value != NULL)
179  lwc_string_unref(charset_value);
180 
181  *c = (struct content *) result;
182 
183  return NSERROR_OK;
184 }
185 
186 /**
187  * Create a struct content_css_data, creating a stylesheet object
188  *
189  * \param c Struct to populate
190  * \param url URL of stylesheet
191  * \param charset Stylesheet charset
192  * \param quirks Stylesheet quirks mode
193  * \param done Callback to call when content has completed
194  * \param pw Client data for \a done
195  * \return NSERROR_OK on success, NSERROR_NOMEM on memory exhaustion
196  */
198  const char *url, const char *charset, bool quirks,
199  nscss_done_callback done, void *pw)
200 {
201  css_error error;
202  css_stylesheet_params params;
203 
204  c->pw = pw;
205  c->done = done;
206  c->next_to_register = (uint32_t) -1;
207  c->import_count = 0;
208  c->imports = NULL;
209  if (charset != NULL)
210  c->charset = strdup(charset);
211  else
212  c->charset = NULL;
213 
214  params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
215  params.level = CSS_LEVEL_DEFAULT;
216  params.charset = charset;
217  params.url = url;
218  params.title = NULL;
219  params.allow_quirks = quirks;
220  params.inline_style = false;
221  params.resolve = nscss_resolve_url;
222  params.resolve_pw = NULL;
223  params.import = nscss_handle_import;
224  params.import_pw = c;
225  params.color = ns_system_colour;
226  params.color_pw = NULL;
227  params.font = NULL;
228  params.font_pw = NULL;
229 
230  error = css_stylesheet_create(&params, &c->sheet);
231  if (error != CSS_OK) {
232  return NSERROR_NOMEM;
233  }
234 
235  return NSERROR_OK;
236 }
237 
238 /**
239  * Process CSS source data
240  *
241  * \param c Content structure
242  * \param data Data to process
243  * \param size Number of bytes to process
244  * \return true on success, false on failure
245  */
246 static bool
247 nscss_process_data(struct content *c, const char *data, unsigned int size)
248 {
249  nscss_content *css = (nscss_content *) c;
250  css_error error;
251 
252  error = nscss_process_css_data(&css->data, data, size);
253  if (error != CSS_OK && error != CSS_NEEDDATA) {
255  }
256 
257  return (error == CSS_OK || error == CSS_NEEDDATA);
258 }
259 
260 /**
261  * Process CSS data
262  *
263  * \param c CSS content object
264  * \param data Data to process
265  * \param size Number of bytes to process
266  * \return CSS_OK on success, appropriate error otherwise
267  */
268 static css_error nscss_process_css_data(struct content_css_data *c,
269  const char *data, unsigned int size)
270 {
271  return css_stylesheet_append_data(c->sheet,
272  (const uint8_t *) data, size);
273 }
274 
275 /**
276  * Convert a CSS content ready for use
277  *
278  * \param c Content to convert
279  * \return true on success, false on failure
280  */
281 bool nscss_convert(struct content *c)
282 {
283  nscss_content *css = (nscss_content *) c;
284  css_error error;
285 
286  error = nscss_convert_css_data(&css->data);
287  if (error != CSS_OK) {
289  return false;
290  }
291 
292  return true;
293 }
294 
295 /**
296  * Convert CSS data ready for use
297  *
298  * \param c CSS data to convert
299  * \return CSS error
300  */
301 static css_error nscss_convert_css_data(struct content_css_data *c)
302 {
303  css_error error;
304 
305  error = css_stylesheet_data_done(c->sheet);
306 
307  /* Process pending imports */
308  if (error == CSS_IMPORTS_PENDING) {
309  /* We must not have registered any imports yet */
310  assert(c->next_to_register == (uint32_t) -1);
311 
312  /* Start registering, until we find one that
313  * hasn't finished fetching */
314  c->next_to_register = 0;
315  error = nscss_register_imports(c);
316  } else if (error == CSS_OK) {
317  /* No imports, and no errors, so complete conversion */
318  c->done(c, c->pw);
319  } else {
320  const char *url;
321 
322  if (css_stylesheet_get_url(c->sheet, &url) == CSS_OK) {
323  NSLOG(netsurf, INFO, "Failed converting %p %s (%d)",
324  c, url, error);
325  } else {
326  NSLOG(netsurf, INFO, "Failed converting %p (%d)", c,
327  error);
328  }
329  }
330 
331  return error;
332 }
333 
334 /**
335  * Clean up a CSS content
336  *
337  * \param c Content to clean up
338  */
339 void nscss_destroy(struct content *c)
340 {
341  nscss_content *css = (nscss_content *) c;
342 
344 }
345 
346 /**
347  * Clean up CSS data
348  *
349  * \param c CSS data to clean up
350  */
352 {
353  uint32_t i;
354 
355  for (i = 0; i < c->import_count; i++) {
356  if (c->imports[i].c != NULL) {
358  }
359  c->imports[i].c = NULL;
360  }
361 
362  free(c->imports);
363 
364  if (c->sheet != NULL) {
365  css_stylesheet_destroy(c->sheet);
366  c->sheet = NULL;
367  }
368 
369  free(c->charset);
370 }
371 
372 nserror nscss_clone(const struct content *old, struct content **newc)
373 {
374  const nscss_content *old_css = (const nscss_content *) old;
375  nscss_content *new_css;
376  const uint8_t *data;
377  size_t size;
378  nserror error;
379 
380  new_css = calloc(1, sizeof(nscss_content));
381  if (new_css == NULL)
382  return NSERROR_NOMEM;
383 
384  /* Clone content */
385  error = content__clone(old, &new_css->base);
386  if (error != NSERROR_OK) {
387  content_destroy(&new_css->base);
388  return error;
389  }
390 
391  /* Simply replay create/process/convert */
392  error = nscss_create_css_data(&new_css->data,
393  nsurl_access(content_get_url(&new_css->base)),
394  old_css->data.charset,
395  new_css->base.quirks,
396  nscss_content_done, new_css);
397  if (error != NSERROR_OK) {
398  content_destroy(&new_css->base);
399  return error;
400  }
401 
402  data = content__get_source_data(&new_css->base, &size);
403  if (size > 0) {
404  if (nscss_process_data(&new_css->base,
405  (char *)data,
406  (unsigned int)size) == false) {
407  content_destroy(&new_css->base);
408  return NSERROR_CLONE_FAILED;
409  }
410  }
411 
412  if (old->status == CONTENT_STATUS_READY ||
413  old->status == CONTENT_STATUS_DONE) {
414  if (nscss_convert(&new_css->base) == false) {
415  content_destroy(&new_css->base);
416  return NSERROR_CLONE_FAILED;
417  }
418  }
419 
420  *newc = (struct content *) new_css;
421 
422  return NSERROR_OK;
423 }
424 
425 bool nscss_matches_quirks(const struct content *c, bool quirks)
426 {
427  return c->quirks == quirks;
428 }
429 
430 /* exported interface documented in netsurf/css.h */
431 css_stylesheet *nscss_get_stylesheet(struct hlcache_handle *h)
432 {
434 
435  assert(c != NULL);
436 
437  return c->data.sheet;
438 }
439 
440 /* exported interface documented in netsurf/css.h */
442 {
444 
445  assert(c != NULL);
446  assert(n != NULL);
447 
448  *n = c->data.import_count;
449 
450  return c->data.imports;
451 }
452 
453 /**
454  * Compute the type of a content
455  *
456  * \return CONTENT_CSS
457  */
459 {
460  return CONTENT_CSS;
461 }
462 
463 /*****************************************************************************
464  * Object completion *
465  *****************************************************************************/
466 
467 /**
468  * Handle notification that a CSS object is done
469  *
470  * \param css CSS object
471  * \param pw Private data
472  */
473 void nscss_content_done(struct content_css_data *css, void *pw)
474 {
475  struct content *c = pw;
476  uint32_t i;
477  size_t size;
478  css_error error;
479 
480  /* Retrieve the size of this sheet */
481  error = css_stylesheet_size(css->sheet, &size);
482  if (error != CSS_OK) {
485  return;
486  }
487  c->size += size;
488 
489  /* Add on the size of the imported sheets */
490  for (i = 0; i < css->import_count; i++) {
491  if (css->imports[i].c != NULL) {
492  struct content *import = hlcache_handle_get_content(
493  css->imports[i].c);
494 
495  if (import != NULL) {
496  c->size += import->size;
497  }
498  }
499  }
500 
501  /* Finally, catch the content's users up with reality */
503  content_set_done(c);
504 }
505 
506 /*****************************************************************************
507  * Import handling *
508  *****************************************************************************/
509 
510 /**
511  * Handle notification of the need for an imported stylesheet
512  *
513  * \param pw CSS object requesting the import
514  * \param parent Stylesheet requesting the import
515  * \param url URL of the imported sheet
516  * \return CSS_OK on success, appropriate error otherwise
517  */
518 css_error nscss_handle_import(void *pw, css_stylesheet *parent,
519  lwc_string *url)
520 {
521  content_type accept = CONTENT_CSS;
522  struct content_css_data *c = pw;
523  nscss_import_ctx *ctx;
524  hlcache_child_context child;
525  struct nscss_import *imports;
526  const char *referer;
527  css_error error;
528  nserror nerror;
529 
530  nsurl *ns_url;
531  nsurl *ns_ref;
532 
533  assert(parent == c->sheet);
534 
535  error = css_stylesheet_get_url(c->sheet, &referer);
536  if (error != CSS_OK) {
537  return error;
538  }
539 
540  ctx = malloc(sizeof(*ctx));
541  if (ctx == NULL)
542  return CSS_NOMEM;
543 
544  ctx->css = c;
545  ctx->index = c->import_count;
546 
547  /* Increase space in table */
548  imports = realloc(c->imports, (c->import_count + 1) *
549  sizeof(struct nscss_import));
550  if (imports == NULL) {
551  free(ctx);
552  return CSS_NOMEM;
553  }
554  c->imports = imports;
555 
556  /** \todo fallback charset */
557  child.charset = NULL;
558  error = css_stylesheet_quirks_allowed(c->sheet, &child.quirks);
559  if (error != CSS_OK) {
560  free(ctx);
561  return error;
562  }
563 
564  /* Create content */
565 
566  /** \todo Why aren't we getting a relative url part, to join? */
567  nerror = nsurl_create(lwc_string_data(url), &ns_url);
568  if (nerror != NSERROR_OK) {
569  free(ctx);
570  return CSS_NOMEM;
571  }
572 
573  /** \todo Constructing nsurl for referer here is silly, avoid */
574  nerror = nsurl_create(referer, &ns_ref);
575  if (nerror != NSERROR_OK) {
576  nsurl_unref(ns_url);
577  free(ctx);
578  return CSS_NOMEM;
579  }
580 
581  /* Avoid importing ourself */
582  if (nsurl_compare(ns_url, ns_ref, NSURL_COMPLETE)) {
583  c->imports[c->import_count].c = NULL;
584  /* No longer require context as we're not fetching anything */
585  free(ctx);
586  ctx = NULL;
587  } else {
588  nerror = hlcache_handle_retrieve(ns_url,
589  0, ns_ref, NULL, nscss_import, ctx,
590  &child, accept,
591  &c->imports[c->import_count].c);
592  if (nerror != NSERROR_OK) {
593  free(ctx);
594  return CSS_NOMEM;
595  }
596  }
597 
598  nsurl_unref(ns_url);
599  nsurl_unref(ns_ref);
600 
601 #ifdef NSCSS_IMPORT_TRACE
602  NSLOG(netsurf, INFO, "Import %d '%s' -> (handle: %p ctx: %p)",
603  c->import_count, lwc_string_data(url),
604  c->imports[c->import_count].c, ctx);
605 #endif
606 
607  c->import_count++;
608 
609  return CSS_OK;
610 }
611 
612 /**
613  * Handler for imported stylesheet events
614  *
615  * \param handle Handle for stylesheet
616  * \param event Event object
617  * \param pw Callback context
618  * \return NSERROR_OK on success, appropriate error otherwise
619  */
621  const hlcache_event *event, void *pw)
622 {
623  nscss_import_ctx *ctx = pw;
624  css_error error = CSS_OK;
625 
626 #ifdef NSCSS_IMPORT_TRACE
627  NSLOG(netsurf, INFO, "Event %d for %p (%p)", event->type, handle, ctx);
628 #endif
629 
630  assert(ctx->css->imports[ctx->index].c == handle);
631 
632  switch (event->type) {
633  case CONTENT_MSG_DONE:
634  error = nscss_import_complete(ctx);
635  break;
636 
637  case CONTENT_MSG_ERROR:
638  hlcache_handle_release(handle);
639  ctx->css->imports[ctx->index].c = NULL;
640 
641  error = nscss_import_complete(ctx);
642  /* Already released handle */
643  break;
644  default:
645  break;
646  }
647 
648  /* Preserve out-of-memory. Anything else is OK */
649  return error == CSS_NOMEM ? NSERROR_NOMEM : NSERROR_OK;
650 }
651 
652 /**
653  * Handle an imported stylesheet completing
654  *
655  * \param ctx Import context
656  * \return CSS_OK on success, appropriate error otherwise
657  */
659 {
660  css_error error = CSS_OK;
661 
662  /* If this import is the next to be registered, do so */
663  if (ctx->css->next_to_register == ctx->index)
664  error = nscss_register_imports(ctx->css);
665 
666 #ifdef NSCSS_IMPORT_TRACE
667  NSLOG(netsurf, INFO, "Destroying import context %p for %d", ctx,
668  ctx->index);
669 #endif
670 
671  /* No longer need import context */
672  free(ctx);
673 
674  return error;
675 }
676 
677 /*****************************************************************************
678  * Import registration *
679  *****************************************************************************/
680 
681 /**
682  * Register imports with a stylesheet
683  *
684  * \param c CSS object containing the imports
685  * \return CSS_OK on success, appropriate error otherwise
686  */
688 {
689  uint32_t index;
690  css_error error;
691 
692  assert(c->next_to_register != (uint32_t) -1);
693  assert(c->next_to_register < c->import_count);
694 
695  /* Register imported sheets */
696  for (index = c->next_to_register; index < c->import_count; index++) {
697  /* Stop registering if we encounter one whose fetch hasn't
698  * completed yet. We'll resume at this point when it has
699  * completed.
700  */
701  if (c->imports[index].c != NULL &&
702  content_get_status(c->imports[index].c) !=
704  break;
705  }
706 
707  error = nscss_register_import(c, c->imports[index].c);
708  if (error != CSS_OK)
709  return error;
710  }
711 
712  /* Record identity of the next import to register */
713  c->next_to_register = (uint32_t) index;
714 
715  if (c->next_to_register == c->import_count) {
716  /* No more imports: notify parent that we're DONE */
717  c->done(c, c->pw);
718  }
719 
720  return CSS_OK;
721 }
722 
723 
724 /**
725  * Register an import with a stylesheet
726  *
727  * \param c CSS object that requested the import
728  * \param import Cache handle of import, or NULL for blank
729  * \return CSS_OK on success, appropriate error otherwise
730  */
732  const hlcache_handle *import)
733 {
734  css_stylesheet *sheet;
735  css_error error;
736 
737  if (import != NULL) {
738  nscss_content *s =
740  sheet = s->data.sheet;
741  } else {
742  /* Create a blank sheet if needed. */
743  if (blank_import == NULL) {
744  css_stylesheet_params params;
745 
746  params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
747  params.level = CSS_LEVEL_DEFAULT;
748  params.charset = NULL;
749  params.url = "";
750  params.title = NULL;
751  params.allow_quirks = false;
752  params.inline_style = false;
753  params.resolve = nscss_resolve_url;
754  params.resolve_pw = NULL;
755  params.import = NULL;
756  params.import_pw = NULL;
757  params.color = ns_system_colour;
758  params.color_pw = NULL;
759  params.font = NULL;
760  params.font_pw = NULL;
761 
762  error = css_stylesheet_create(&params, &blank_import);
763  if (error != CSS_OK) {
764  return error;
765  }
766 
767  error = css_stylesheet_data_done(blank_import);
768  if (error != CSS_OK) {
769  css_stylesheet_destroy(blank_import);
770  return error;
771  }
772  }
773 
774  sheet = blank_import;
775  }
776 
777  error = css_stylesheet_register_import(c->sheet, sheet);
778  if (error != CSS_OK) {
779  return error;
780  }
781 
782  return error;
783 }
784 
785 /**
786  * Clean up after the CSS content handler
787  */
788 static void nscss_fini(void)
789 {
790  if (blank_import != NULL) {
791  css_stylesheet_destroy(blank_import);
792  blank_import = NULL;
793  }
794  css_hint_fini();
795 }
796 
798  .fini = nscss_fini,
799  .create = nscss_create,
800  .process_data = nscss_process_data,
801  .data_complete = nscss_convert,
802  .destroy = nscss_destroy,
803  .clone = nscss_clone,
804  .matches_quirks = nscss_matches_quirks,
805  .type = nscss_content_type,
806  .no_share = false,
807 };
808 
809 /* exported interface documented in netsurf/css.h */
811 {
812  nserror error;
813 
814  error = content_factory_register_handler("text/css",
815  &css_content_handler);
816  if (error != NSERROR_OK)
817  goto error;
818 
819  error = css_hint_init();
820  if (error != NSERROR_OK)
821  goto error;
822 
823  return NSERROR_OK;
824 
825 error:
826  nscss_fini();
827 
828  return error;
829 }
uint32_t index
Index into parent sheet&#39;s imports array.
Definition: css.c:79
bool quirks
Whether parent is quirky.
Definition: hlcache.h:39
static void nscss_fini(void)
Clean up after the CSS content handler.
Definition: css.c:788
css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs)
URL resolution callback for libcss.
Definition: internal.c:27
High-level cache event.
Definition: hlcache.h:43
struct nscss_import * imports
Array of imported sheets.
Definition: css.c:57
STATIC char result[100]
Definition: arexx.c:77
css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
css callback to obtain named system colour.
Definition: system_colour.c:95
char * charset
Character set of stylesheet.
Definition: css.c:56
void css_hint_fini(void)
Definition: hints.c:599
static void nscss_destroy(struct content *c)
Clean up a CSS content.
Definition: css.c:339
static css_error nscss_convert_css_data(struct content_css_data *c)
Convert CSS data ready for use.
Definition: css.c:301
static void nscss_content_done(struct content_css_data *css, void *pw)
Handle notification that a CSS object is done.
Definition: css.c:473
nserror nscss_init(void)
Initialise the CSS content handler.
Definition: css.c:810
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.
Definition: parameter.c:114
bool nsurl_compare(const nsurl *url1, const nsurl *url2, nsurl_component parts)
Compare two URLs.
Localised message support (interface).
content_msg type
Event type.
Definition: hlcache.h:44
struct content base
Underlying content object.
Definition: css.c:69
nserror css_hint_init(void)
Definition: hints.c:588
Memory exhaustion.
Definition: errors.h:32
static css_error nscss_register_import(struct content_css_data *c, const hlcache_handle *import)
Register an import with a stylesheet.
Definition: css.c:731
bool quirks
Content is in quirks mode.
Context for retrieving a child object.
Definition: hlcache.h:37
struct nscss_import * nscss_get_imports(hlcache_handle *h, uint32_t *n)
Retrieve imported stylesheets.
Definition: css.c:441
nscss_done_callback done
Completion callback.
Definition: css.c:60
struct content_css_data data
CSS data.
Definition: css.c:71
struct content_css_data * css
Object containing import.
Definition: css.c:78
void(* nscss_done_callback)(struct content_css_data *css, void *pw)
Type of callback called when a CSS object has finished.
Definition: css.c:48
static css_error nscss_process_css_data(struct content_css_data *c, const char *data, unsigned int size)
Process CSS data.
Definition: css.c:268
void content_set_ready(struct content *c)
Put a content in status CONTENT_STATUS_READY and unlock the content.
Definition: content.c:302
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
Send an error message to all users.
Definition: content.c:859
High-level resource cache interface.
void content_destroy(struct content *c)
Destroy and free a content.
Definition: content.c:384
static css_error nscss_import_complete(nscss_import_ctx *ctx)
Handle an imported stylesheet completing.
Definition: css.c:658
nserror content__clone(const struct content *c, struct content *nc)
Clone a content&#39;s data members.
Definition: content.c:1510
static content_type nscss_content_type(void)
Compute the type of a content.
Definition: css.c:458
void content_set_error(struct content *c)
Put a content in status CONTENT_STATUS_ERROR and unlock the content.
Definition: content.c:336
nserror
Enumeration of error codes.
Definition: errors.h:29
nsurl * content_get_url(struct content *c)
Retrieve URL associated with content.
Definition: content.c:1172
uint32_t next_to_register
Index of next import to register.
Definition: css.c:59
static nserror nscss_clone(const struct content *old, struct content **newc)
Definition: css.c:372
High-level cache handle.
Definition: hlcache.c:64
Representation of an HTTP parameter.
Definition: parameter.c:31
Failed to clone handle.
Definition: errors.h:37
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.
void(* fini)(void)
content_type
The type of a content.
Definition: content_type.h:43
const uint8_t * content__get_source_data(struct content *c, size_t *size)
Retrieve source of content.
Definition: content.c:1329
static bool nscss_process_data(struct content *c, const char *data, unsigned int size)
Process CSS source data.
Definition: css.c:247
const char * charset
Charset of parent.
Definition: hlcache.h:38
CSS call returned error.
Definition: errors.h:53
No error.
Definition: errors.h:30
All finished.
Definition: content.h:55
const char * llcache_handle_get_header(const llcache_handle *handle, const char *key)
Retrieve a header value associated with a low-level cache object.
Definition: llcache.c:4095
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:266
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:115
Handle to low-level cache object.
Definition: llcache.c:75
static css_error nscss_register_imports(struct content_css_data *c)
Register imports with a stylesheet.
Definition: css.c:687
content_status content_get_status(hlcache_handle *h)
Retrieve status of content.
Definition: content.c:1243
static nserror nscss_import(hlcache_handle *handle, const hlcache_event *event, void *pw)
Handler for imported stylesheet events.
Definition: css.c:620
static css_error nscss_handle_import(void *pw, css_stylesheet *parent, lwc_string *url)
Handle notification of the need for an imported stylesheet.
Definition: css.c:518
wimp_w parent
Definition: dialog.c:87
struct content * hlcache_handle_get_content(const hlcache_handle *handle)
Retrieve a content object from a cache handle.
Definition: hlcache.c:769
uint32_t import_count
Number of sheets imported.
Definition: css.c:58
finished
Definition: content.h:66
Some parts of content still being loaded, but can be displayed.
Definition: content.h:53
content_status status
Current status.
static const content_handler css_content_handler
Definition: css.c:797
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.
Definition: content.c:318
CSS content data.
Definition: css.c:67
Imported stylesheet record.
Definition: css.h:33
Context for import fetches.
Definition: css.c:77
error occurred
Definition: content.h:67
Interface to system colour values.
static bool nscss_convert(struct content *c)
Convert a CSS content ready for use.
Definition: css.c:281
struct nscss_content nscss_content
CSS content data.
static void nscss_destroy_css_data(struct content_css_data *c)
Clean up CSS data.
Definition: css.c:351
static bool nscss_matches_quirks(const struct content *c, bool quirks)
Definition: css.c:425
CSS content data.
Definition: css.c:53
Interface to a number of general purpose functionality.
void * pw
Client data.
Definition: css.c:61
static css_stylesheet * blank_import
Definition: css.c:109
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.
Definition: hlcache.c:675
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.
Definition: css.h:34
content is CSS
Definition: content_type.h:54
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.
Definition: content.c:70
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
Definition: hlcache.c:733
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.
Definition: css.c:197
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Protected interface to Content handling.
css_stylesheet * sheet
Stylesheet object.
Definition: css.c:55
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.
Definition: css.c:431
Definition: punycode.c:19
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.
Definition: css.c:125