NetSurf
Typedefs | Functions
script.c File Reference

implementation of content handling for text/html scripts. More...

#include <assert.h>
#include <ctype.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "utils/config.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "netsurf/content.h"
#include "javascript/js.h"
#include "content/content_protected.h"
#include "content/content_factory.h"
#include "content/fetch.h"
#include "content/hlcache.h"
#include "html/html.h"
#include "html/private.h"
Include dependency graph for script.c:

Go to the source code of this file.

Typedefs

typedef bool() script_handler_t(struct jsthread *jsthread, const uint8_t *data, size_t size, const char *name)
 

Functions

static script_handler_tselect_script_handler (content_type ctype)
 
nserror html_script_exec (html_content *c, bool allow_defer)
 Attempt script execution for defer and async scripts. More...
 
static struct html_scripthtml_process_new_script (html_content *c, dom_string *mimetype, enum html_script_type type)
 
static nserror convert_script_async_cb (hlcache_handle *script, const hlcache_event *event, void *pw)
 Callback for asyncronous scripts. More...
 
static nserror convert_script_defer_cb (hlcache_handle *script, const hlcache_event *event, void *pw)
 Callback for defer scripts. More...
 
static nserror convert_script_sync_cb (hlcache_handle *script, const hlcache_event *event, void *pw)
 Callback for syncronous scripts. More...
 
static dom_hubbub_error exec_src_script (html_content *c, dom_node *node, dom_string *mimetype, dom_string *src)
 process a script with a src tag More...
 
static dom_hubbub_error exec_inline_script (html_content *c, dom_node *node, dom_string *mimetype)
 
dom_hubbub_error html_process_script (void *ctx, dom_node *node)
 process script node parser callback More...
 
bool html_saw_insecure_scripts (html_content *htmlc)
 Check if any of the scripts loaded were insecure. More...
 
nserror html_script_free (html_content *html)
 Free all script resources and references for a html content. More...
 

Detailed Description

implementation of content handling for text/html scripts.

Definition in file script.c.

Typedef Documentation

◆ script_handler_t

typedef bool() script_handler_t(struct jsthread *jsthread, const uint8_t *data, size_t size, const char *name)

Definition at line 46 of file script.c.

Function Documentation

◆ convert_script_async_cb()

static nserror convert_script_async_cb ( hlcache_handle script,
const hlcache_event event,
void *  pw 
)
static

Callback for asyncronous scripts.

Definition at line 159 of file script.c.

References CONTENT_MSG_DONE, CONTENT_MSG_ERROR, CONTENT_MSG_LOADING, CONTENT_MSG_READY, html_script::data, hlcache_event::data, content_msg_data::errordata, content_msg_data::errormsg, html_script::handle, hlcache_handle_get_url(), hlcache_handle_release(), html_begin_conversion(), html_can_begin_conversion(), html_script::HTML_SCRIPT_ASYNC, html_script_exec(), NSERROR_OK, NSLOG, nsurl_access(), parent, html_script::type, and hlcache_event::type.

Referenced by exec_src_script().

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

◆ convert_script_defer_cb()

static nserror convert_script_defer_cb ( hlcache_handle script,
const hlcache_event event,
void *  pw 
)
static

Callback for defer scripts.

Definition at line 227 of file script.c.

References CONTENT_MSG_DONE, CONTENT_MSG_ERROR, html_script::data, hlcache_event::data, content_msg_data::errordata, content_msg_data::errormsg, html_script::handle, hlcache_handle_get_url(), hlcache_handle_release(), html_begin_conversion(), html_can_begin_conversion(), html_script::HTML_SCRIPT_DEFER, NSERROR_OK, NSLOG, nsurl_access(), parent, html_script::type, and hlcache_event::type.

Referenced by exec_src_script().

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

◆ convert_script_sync_cb()

static nserror convert_script_sync_cb ( hlcache_handle script,
const hlcache_event event,
void *  pw 
)
static

Callback for syncronous scripts.

Definition at line 283 of file script.c.

References html_script::already_started, content_get_source_data(), content_get_type(), CONTENT_MSG_DONE, CONTENT_MSG_ERROR, html_script::data, hlcache_event::data, content_msg_data::errordata, content_msg_data::errormsg, html_script::handle, hlcache_handle_get_url(), hlcache_handle_release(), html_begin_conversion(), html_can_begin_conversion(), html_script::HTML_SCRIPT_SYNC, NSERROR_OK, NSLOG, nsurl_access(), parent, select_script_handler(), html_script::type, and hlcache_event::type.

Referenced by exec_src_script().

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

◆ exec_inline_script()

static dom_hubbub_error exec_inline_script ( html_content c,
dom_node *  node,
dom_string *  mimetype 
)
static

Definition at line 515 of file script.c.

References html_script::already_started, html_content::base, content_broadcast_error(), content_factory_type_from_mime_type(), html_script::data, html_process_new_script(), html_script::HTML_SCRIPT_INLINE, html_content::jsthread, html_script::mimetype, NSERROR_NOMEM, select_script_handler(), and html_script::string.

Referenced by html_process_script().

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

◆ exec_src_script()

static dom_hubbub_error exec_src_script ( html_content c,
dom_node *  node,
dom_string *  mimetype,
dom_string *  src 
)
static

◆ html_process_new_script()

static struct html_script * html_process_new_script ( html_content c,
dom_string *  mimetype,
enum html_script_type  type 
)
static

Definition at line 123 of file script.c.

References html_script::already_started, html_script::async, html_script::defer, html_script::force_async, html_script::mimetype, html_script::parser_inserted, html_script::ready_exec, html_content::scripts, html_content::scripts_count, html_script::type, and type.

Referenced by exec_inline_script(), and exec_src_script().

Here is the caller graph for this function:

◆ html_process_script()

dom_hubbub_error html_process_script ( void *  ctx,
dom_node *  node 
)

process script node parser callback

Definition at line 566 of file script.c.

References html_content::base, content_broadcast(), CONTENT_MSG_GETTHREAD, exec_inline_script(), exec_src_script(), content_msg_data::jsthread, html_content::jsthread, html_script::mimetype, NSLOG, html_content::parser, and content_msg_data::src.

Referenced by dom_SCRIPT_showed_up(), html_create_html_data(), and html_process_encoding_change().

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

◆ html_saw_insecure_scripts()

bool html_saw_insecure_scripts ( html_content htmlc)

Check if any of the scripts loaded were insecure.

Definition at line 611 of file script.c.

References content_saw_insecure_objects(), html_script::data, html_script::handle, html_script::HTML_SCRIPT_INLINE, html_content::scripts, html_content::scripts_count, and html_script::type.

Referenced by html_saw_insecure_objects().

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

◆ html_script_exec()

nserror html_script_exec ( html_content htmlc,
bool  allow_defer 
)

Attempt script execution for defer and async scripts.

execute scripts using algorithm found in: http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element

Parameters
htmlchtml content.
allow_deferallow deferred execution, if not, only async scripts.
Returns
NSERROR_OK error code.

Definition at line 59 of file script.c.

References html_script::already_started, content_get_source_data(), content_get_status(), content_get_type(), CONTENT_STATUS_DONE, CONTENT_STATUS_ERROR, html_script::data, html_script::handle, hlcache_handle_get_url(), html_proceed_to_done(), html_script::HTML_SCRIPT_ASYNC, html_script::HTML_SCRIPT_DEFER, html_content::jsthread, NSERROR_BAD_PARAMETER, NSERROR_OK, nsurl_access(), html_content::scripts, html_content::scripts_count, select_script_handler(), and html_script::type.

Referenced by convert_script_async_cb(), and html_begin_conversion().

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

◆ html_script_free()

nserror html_script_free ( html_content htmlc)

Free all script resources and references for a html content.

Parameters
htmlchtml content.
Returns
NSERROR_OK or error code.

Definition at line 636 of file script.c.

References html_script::data, html_script::handle, hlcache_handle_release(), html_script::HTML_SCRIPT_ASYNC, html_script::HTML_SCRIPT_DEFER, html_script::HTML_SCRIPT_INLINE, html_script::HTML_SCRIPT_SYNC, html_script::mimetype, NSERROR_OK, html_content::scripts, html_content::scripts_count, html_script::string, and html_script::type.

Referenced by html_destroy().

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

◆ select_script_handler()

static script_handler_t * select_script_handler ( content_type  ctype)
static

Definition at line 49 of file script.c.

References CONTENT_JS, and js_exec().

Referenced by convert_script_sync_cb(), exec_inline_script(), and html_script_exec().

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