NetSurf
Functions | Variables
css.c File Reference

Processing for html content css operations. More...

#include "utils/config.h"
#include <assert.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "netsurf/inttypes.h"
#include "netsurf/misc.h"
#include "netsurf/content.h"
#include "content/hlcache.h"
#include "css/css.h"
#include "desktop/gui_internal.h"
#include "html/html.h"
#include "html/private.h"
#include "html/css.h"
Include dependency graph for css.c:

Go to the source code of this file.

Functions

static nserror css_error_to_nserror (css_error error)
 Convert css error to netsurf error. More...
 
static nserror html_convert_css_callback (hlcache_handle *css, const hlcache_event *event, void *pw)
 Callback for fetchcache() for stylesheets. More...
 
static nserror html_stylesheet_from_domnode (html_content *c, dom_node *node, hlcache_handle **sheet)
 
static struct html_stylesheethtml_create_style_element (html_content *c, dom_node *style)
 Process an inline stylesheet in the document. More...
 
static bool html_css_process_modified_style (html_content *c, struct html_stylesheet *s)
 
static void html_css_process_modified_styles (void *pw)
 process a stylesheet that has been modified. More...
 
bool html_css_update_style (html_content *c, dom_node *style)
 process a css style dom node update More...
 
bool html_css_process_style (html_content *c, dom_node *node)
 process a css style dom node More...
 
bool html_css_process_link (html_content *htmlc, dom_node *node)
 process a css stylesheet dom LINK node More...
 
struct html_stylesheethtml_get_stylesheets (hlcache_handle *h, unsigned int *n)
 Retrieve stylesheets used by HTML document. More...
 
bool html_css_saw_insecure_stylesheets (html_content *html)
 determine if any of the stylesheets were loaded insecurely More...
 
nserror html_css_free_stylesheets (html_content *html)
 Free all css stylesheets associated with an HTML content. More...
 
nserror html_css_quirks_stylesheets (html_content *c)
 Initialise quirk stylesheets for a content. More...
 
nserror html_css_new_stylesheets (html_content *c)
 Initialise core stylesheets for a content. More...
 
nserror html_css_new_selection_context (html_content *c, css_select_ctx **ret_select_ctx)
 create a new css selection context for an html content. More...
 
nserror html_css_init (void)
 Initialise html content css handling. More...
 
void html_css_fini (void)
 Finalise html content css handling. More...
 

Variables

static nsurlhtml_default_stylesheet_url
 
static nsurlhtml_adblock_stylesheet_url
 
static nsurlhtml_quirks_stylesheet_url
 
static nsurlhtml_user_stylesheet_url
 

Detailed Description

Processing for html content css operations.

Definition in file css.c.

Function Documentation

◆ css_error_to_nserror()

static nserror css_error_to_nserror ( css_error  error)
static

Convert css error to netsurf error.

Definition at line 55 of file css.c.

References NSERROR_BAD_ENCODING, NSERROR_BAD_PARAMETER, NSERROR_CSS, NSERROR_INVALID, NSERROR_NEED_DATA, NSERROR_NOMEM, NSERROR_NOT_FOUND, and NSERROR_OK.

Referenced by html_css_new_selection_context().

Here is the caller graph for this function:

◆ html_convert_css_callback()

static nserror html_convert_css_callback ( hlcache_handle css,
const hlcache_event event,
void *  pw 
)
static

Callback for fetchcache() for stylesheets.

Definition at line 93 of file css.c.

References CONTENT_MSG_DONE, CONTENT_MSG_ERROR, CONTENT_MSG_POINTER, hlcache_event::data, content_msg_data::errordata, content_msg_data::errormsg, hlcache_handle_get_url(), hlcache_handle_release(), html_begin_conversion(), html_can_begin_conversion(), NSERROR_OK, NSLOG, nsurl_access(), parent, html_stylesheet::sheet, and hlcache_event::type.

Referenced by html_css_new_stylesheets(), html_css_process_link(), html_css_quirks_stylesheets(), and html_stylesheet_from_domnode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_create_style_element()

static struct html_stylesheet * html_create_style_element ( html_content c,
dom_node *  style 
)
static

Process an inline stylesheet in the document.

Parameters
ccontent structure
stylexml node of style element
Returns
true on success, false if an error occurred

Definition at line 210 of file css.c.

References html_content::base, content_broadcast_error(), html_stylesheet::modified, html_stylesheet::node, NSERROR_NOMEM, html_stylesheet::sheet, strcasestr(), html_content::stylesheet_count, html_content::stylesheets, and html_stylesheet::unused.

Referenced by html_css_update_style().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_fini()

void html_css_fini ( void  )

Finalise html content css handling.

Definition at line 747 of file css.c.

References html_adblock_stylesheet_url, html_default_stylesheet_url, html_quirks_stylesheet_url, html_user_stylesheet_url, and nsurl_unref().

Referenced by html_fini().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_free_stylesheets()

nserror html_css_free_stylesheets ( struct html_content html)

Free all css stylesheets associated with an HTML content.

Parameters
htmlThe HTML content to free stylesheets from.
Returns
NSERROR_OK on success or error code.

Definition at line 531 of file css.c.

References guit, hlcache_handle_release(), html_css_process_modified_styles(), netsurf_table::misc, html_stylesheet::node, NSERROR_OK, gui_misc_table::schedule, html_stylesheet::sheet, html_content::stylesheet_count, and html_content::stylesheets.

Referenced by html_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_init()

nserror html_css_init ( void  )

Initialise html content css handling.

Returns
NSERROR_OK on success else error code

Definition at line 716 of file css.c.

References html_adblock_stylesheet_url, html_css_fetcher_register(), html_default_stylesheet_url, html_quirks_stylesheet_url, html_user_stylesheet_url, NSERROR_OK, and nsurl_create().

Referenced by html_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_new_selection_context()

nserror html_css_new_selection_context ( struct html_content c,
css_select_ctx **  select_ctx 
)

create a new css selection context for an html content.

Parameters
cThe html content to create css selction on.
select_ctxA pointer to receive the new context.
Returns
NSERROR_OK on success and select_ctx updated else error code

Definition at line 653 of file css.c.

References css_error_to_nserror(), nscss_get_stylesheet(), NSERROR_CSS_BASE, NSERROR_OK, html_stylesheet::sheet, STYLESHEET_BASE, html_content::stylesheet_count, STYLESHEET_START, STYLESHEET_USER, html_content::stylesheets, and html_stylesheet::unused.

Referenced by html_finish_conversion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_new_stylesheets()

nserror html_css_new_stylesheets ( struct html_content c)

Initialise core stylesheets for a content.

Parameters
ccontent structure to update
Returns
NSERROR_OK on success or error code

Definition at line 581 of file css.c.

References content::active, html_content::base, hlcache_child_context::charset, CONTENT_CSS, content_get_url(), html_content::encoding, hlcache_handle_retrieve(), html_adblock_stylesheet_url, html_convert_css_callback(), html_default_stylesheet_url, html_user_stylesheet_url, NSERROR_NOMEM, NSERROR_OK, NSLOG, nsoption_bool, content::quirks, hlcache_child_context::quirks, html_stylesheet::sheet, STYLESHEET_ADBLOCK, STYLESHEET_BASE, html_content::stylesheet_count, STYLESHEET_QUIRKS, STYLESHEET_START, STYLESHEET_USER, and html_content::stylesheets.

Referenced by html_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_process_link()

bool html_css_process_link ( struct html_content htmlc,
dom_node *  node 
)

process a css stylesheet dom LINK node

Parameters
htmlcThe HTML content.
nodethe DOM link node to process.
Returns
true on success else false.

Definition at line 385 of file css.c.

References content::active, html_content::base, html_content::base_url, hlcache_child_context::charset, content_broadcast_error(), CONTENT_CSS, content_get_url(), html_content::encoding, hlcache_handle_retrieve(), html_convert_css_callback(), html_stylesheet::modified, html_stylesheet::node, NSERROR_NOMEM, NSERROR_OK, NSLOG, nsoption_bool, nsurl_access(), nsurl_join(), nsurl_unref(), content::quirks, hlcache_child_context::quirks, html_stylesheet::sheet, strcasestr(), html_content::stylesheet_count, html_content::stylesheets, and html_stylesheet::unused.

Referenced by html_process_inserted_link().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_process_modified_style()

static bool html_css_process_modified_style ( html_content c,
struct html_stylesheet s 
)
static

Definition at line 262 of file css.c.

References content::active, html_content::base, content_broadcast_error(), content_get_status(), CONTENT_STATUS_DONE, hlcache_handle_abort(), hlcache_handle_release(), html_stylesheet_from_domnode(), html_stylesheet::modified, html_stylesheet::node, NSERROR_OK, NSLOG, and html_stylesheet::sheet.

Referenced by html_css_process_modified_styles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_process_modified_styles()

static void html_css_process_modified_styles ( void *  pw)
static

process a stylesheet that has been modified.

Definition at line 302 of file css.c.

References guit, html_css_process_modified_style(), html_css_process_modified_styles(), netsurf_table::misc, html_stylesheet::modified, gui_misc_table::schedule, html_content::stylesheet_count, and html_content::stylesheets.

Referenced by html_css_free_stylesheets(), html_css_process_modified_styles(), and html_css_update_style().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_process_style()

bool html_css_process_style ( struct html_content htmlc,
dom_node *  node 
)

process a css style dom node

Parameters
htmlcThe HTML content.
nodethe DOM node to process.
Returns
true on success else false.

Definition at line 352 of file css.c.

References html_stylesheet::node, strcasestr(), html_content::stylesheet_count, html_content::stylesheets, and html_stylesheet::unused.

Referenced by dom_default_action_DOMNodeInserted_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_quirks_stylesheets()

nserror html_css_quirks_stylesheets ( struct html_content c)

Initialise quirk stylesheets for a content.

Parameters
ccontent structure to update
Returns
NSERROR_OK on success or error code

Definition at line 552 of file css.c.

References content::active, html_content::base, hlcache_child_context::charset, CONTENT_CSS, content_get_url(), html_content::encoding, hlcache_handle_retrieve(), html_convert_css_callback(), html_quirks_stylesheet_url, NSERROR_OK, NSLOG, content::quirks, html_content::quirks, hlcache_child_context::quirks, html_stylesheet::sheet, STYLESHEET_QUIRKS, and html_content::stylesheets.

Referenced by html_convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_saw_insecure_stylesheets()

bool html_css_saw_insecure_stylesheets ( struct html_content htmlc)

determine if any of the stylesheets were loaded insecurely

Parameters
htmlcThe HTML content to check.
Returns
true if there were insecurely loadd stylesheets else false.

Definition at line 512 of file css.c.

References content_saw_insecure_objects(), html_stylesheet::sheet, and html_content::stylesheets.

Referenced by html_saw_insecure_objects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_css_update_style()

bool html_css_update_style ( struct html_content htmlc,
dom_node *  node 
)

process a css style dom node update

Parameters
htmlcThe HTML content.
nodethe DOM node to process.
Returns
true on success else false.

Definition at line 323 of file css.c.

References guit, html_create_style_element(), html_css_process_modified_styles(), netsurf_table::misc, html_stylesheet::modified, html_stylesheet::node, NSLOG, gui_misc_table::schedule, html_content::stylesheet_count, and html_content::stylesheets.

Referenced by dom_default_action_DOMSubtreeModified_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_get_stylesheets()

struct html_stylesheet * html_get_stylesheets ( struct hlcache_handle h,
unsigned int *  n 
)

Retrieve stylesheets used by HTML document.

Parameters
hContent to retrieve stylesheets from
nPointer to location to receive number of sheets
Returns
Pointer to array of stylesheets

Definition at line 498 of file css.c.

References hlcache_handle_get_content(), html_content::stylesheet_count, and html_content::stylesheets.

Referenced by browser_window_reload(), and save_complete_save_html_stylesheets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_stylesheet_from_domnode()

static nserror html_stylesheet_from_domnode ( html_content c,
dom_node *  node,
hlcache_handle **  sheet 
)
static

Definition at line 148 of file css.c.

References content::active, html_content::base, html_content::base_url, hlcache_child_context::charset, CONTENT_CSS, content_get_url(), html_content::encoding, hlcache_handle_retrieve(), html_convert_css_callback(), html_css_fetcher_add_item(), html_stylesheet::node, NSERROR_OK, NSLOG, nsurl_create(), nsurl_unref(), content::quirks, hlcache_child_context::quirks, and html_stylesheet::sheet.

Referenced by html_css_process_modified_style().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ html_adblock_stylesheet_url

nsurl* html_adblock_stylesheet_url
static

Definition at line 48 of file css.c.

Referenced by html_css_fini(), html_css_init(), and html_css_new_stylesheets().

◆ html_default_stylesheet_url

nsurl* html_default_stylesheet_url
static

Definition at line 47 of file css.c.

Referenced by html_css_fini(), html_css_init(), and html_css_new_stylesheets().

◆ html_quirks_stylesheet_url

nsurl* html_quirks_stylesheet_url
static

Definition at line 49 of file css.c.

Referenced by html_css_fini(), html_css_init(), and html_css_quirks_stylesheets().

◆ html_user_stylesheet_url

nsurl* html_user_stylesheet_url
static

Definition at line 50 of file css.c.

Referenced by html_css_fini(), html_css_init(), and html_css_new_stylesheets().