63 bool have_run_something =
false;
88 if (script_handler == NULL)
98 script_handler(c->
jsthread, data, size,
100 have_run_something =
true;
113 if (have_run_something) {
130 if (nscript == NULL) {
144 nscript->
async =
false;
145 nscript->
defer =
false;
149 nscript->
mimetype = dom_string_ref(mimetype);
174 switch (event->
type) {
182 NSLOG(netsurf, INFO,
"script %d done '%s'", i,
190 NSLOG(netsurf, INFO,
"script %s failed: %s",
243 switch (event->
type) {
246 NSLOG(netsurf, INFO,
"script %d done '%s'", i,
254 NSLOG(netsurf, INFO,
"script %s failed: %s",
292 dom_hubbub_error err;
293 unsigned int active_sync_scripts = 0;
299 active_sync_scripts++;
311 switch (event->
type) {
313 NSLOG(netsurf, INFO,
"script %d done '%s'", i,
322 if (script_handler != NULL && parent->
jsthread != NULL) {
327 script_handler(parent->
jsthread, data, size,
332 if (parent->
parser != NULL && active_sync_scripts == 0) {
333 err = dom_hubbub_parser_pause(parent->
parser,
false);
334 if (err != DOM_HUBBUB_OK) {
335 NSLOG(netsurf, INFO,
"unpause returned 0x%x", err);
342 NSLOG(netsurf, INFO,
"script %s failed: %s",
356 if (parent->
parser != NULL && active_sync_scripts == 0) {
357 err = dom_hubbub_parser_pause(parent->
parser,
false);
358 if (err != DOM_HUBBUB_OK) {
359 NSLOG(netsurf, INFO,
"unpause returned 0x%x", err);
382 static dom_hubbub_error
396 dom_hubbub_error ret = DOM_HUBBUB_OK;
403 return DOM_HUBBUB_NOMEM;
427 exc = dom_element_has_attribute(node, corestring_dom_async, &async);
428 if (exc != DOM_NO_ERR) {
429 return DOM_HUBBUB_OK;
444 exc = dom_element_has_attribute(node,
445 corestring_dom_defer, &defer);
446 if (exc != DOM_NO_ERR) {
447 return DOM_HUBBUB_OK;
462 if (nscript == NULL) {
465 return DOM_HUBBUB_NOMEM;
491 NSLOG(netsurf, INFO,
"Fetch failed with error %d", ns_error);
497 switch (script_type) {
499 ret = DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED;
515 static dom_hubbub_error
520 struct lwc_string_s *lwcmimetype;
525 exc = dom_node_get_text_content(node, &script);
526 if ((exc != DOM_NO_ERR) || (script == NULL)) {
527 return DOM_HUBBUB_OK;
531 if (nscript == NULL) {
532 dom_string_unref(script);
535 return DOM_HUBBUB_NOMEM;
543 exc = dom_string_intern(mimetype, &lwcmimetype);
544 if (exc != DOM_NO_ERR) {
545 return DOM_HUBBUB_DOM;
549 lwc_string_unref(lwcmimetype);
551 if (script_handler != NULL) {
553 (
const uint8_t *)dom_string_data(script),
554 dom_string_byte_length(script),
557 return DOM_HUBBUB_OK;
572 dom_hubbub_error err = DOM_HUBBUB_OK;
586 return DOM_HUBBUB_OK;
590 NSLOG(netsurf, INFO,
"content %p parser %p node %p", c, c->
parser,
593 exc = dom_element_get_attribute(node, corestring_dom_type, &mimetype);
594 if (exc != DOM_NO_ERR || mimetype == NULL) {
595 mimetype = dom_string_ref(corestring_dom_text_javascript);
598 exc = dom_element_get_attribute(node, corestring_dom_src, &src);
599 if (exc != DOM_NO_ERR || src == NULL) {
603 dom_string_unref(src);
606 dom_string_unref(mimetype);
bool quirks
Whether parent is quirky.
static script_handler_t * select_script_handler(content_type ctype)
struct content_msg_data::@104 errordata
CONTENT_MSG_ERROR - Error from content or underlying fetch.
Interface to utility string handling.
union content_msg_data data
Event data.
enum html_script::html_script_type type
Localised message support (interface).
content_msg type
Event type.
Public content interface.
nserror html_proceed_to_done(html_content *html)
Complete the HTML content state machine iff all scripts are finished.
bool js_exec(jsthread *thread, const uint8_t *txt, size_t txtlen, const char *name)
execute some javascript in a context
Interface to text/html content handler.
bool quirks
Content is in quirks mode.
Context for retrieving a child object.
bool html_begin_conversion(html_content *htmlc)
Begin conversion of an HTML document.
bool conversion_begun
Whether or not the conversion has begun.
struct jsthread ** jsthread
CONTENT_MSG_GETTHREAD - Javascript context (thread)
struct jsthread * jsthread
javascript thread in use
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
Send an error message to all users.
High-level resource cache interface.
Error occurred, content will be destroyed imminently.
nserror html_script_free(html_content *html)
Free all script resources and references for a html content.
struct dom_string * string
nserror
Enumeration of error codes.
nsurl * content_get_url(struct content *c)
Retrieve URL associated with content.
struct jsthread jsthread
JavaScript interpreter thread.
struct dom_string * mimetype
nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
Join a base url to a relative link part, creating a new NetSurf URL object.
Useful interned string pointers (interface).
Private data for text/html content.
content_type
The type of a content.
nserror html_script_exec(html_content *c, bool allow_defer)
Attempt script execution for defer and async scripts.
const char * charset
Charset of parent.
static nserror convert_script_defer_cb(hlcache_handle *script, const hlcache_event *event, void *pw)
Callback for defer scripts.
union html_script::@137 data
Script data.
#define NSLOG(catname, level, logmsg, args...)
const uint8_t * content_get_source_data(struct hlcache_handle *h, size_t *size)
Retrieve source of content.
const char * errormsg
The message.
struct nsurl * hlcache_handle_get_url(const struct hlcache_handle *handle)
Retrieve the URL associated with a high level cache handle.
unsigned int active
Number of child fetches or conversions currently in progress.
struct hlcache_handle * handle
content_status content_get_status(hlcache_handle *h)
Retrieve status of content.
bool content_saw_insecure_objects(struct hlcache_handle *h)
Determine if the content referred to any insecure objects.
bool() script_handler_t(struct jsthread *jsthread, const uint8_t *data, size_t size, const char *name)
dom_hubbub_error html_process_script(void *ctx, dom_node *node)
process script node parser callback
Interface to javascript engine functions.
static dom_hubbub_error exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
static nserror convert_script_async_cb(hlcache_handle *script, const hlcache_event *event, void *pw)
Callback for asyncronous scripts.
void content_broadcast(struct content *c, content_msg msg, const union content_msg_data *data)
Send a message to all users.
nserror(* hlcache_handle_callback)(hlcache_handle *handle, const hlcache_event *event, void *pw)
Client callback for high-level cache events.
dom_hubbub_parser * parser
Parser object handle.
html_script_type
Type of script.
nsurl * base_url
Base URL (may be a copy of content->url).
content_type content_factory_type_from_mime_type(lwc_string *mime_type)
Compute the generic content type for a MIME type.
content_type content_get_type(struct hlcache_handle *h)
Retrieve computed type of content.
struct html_script * scripts
Scripts.
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).
bool html_saw_insecure_scripts(html_content *htmlc)
Check if any of the scripts loaded were insecure.
char * encoding
Encoding of source, NULL if unknown.
static nserror convert_script_sync_cb(hlcache_handle *script, const hlcache_event *event, void *pw)
Callback for syncronous scripts.
void content_add_error(struct content *c, const char *token, unsigned int line)
static struct html_script * html_process_new_script(html_content *c, dom_string *mimetype, enum html_script_type type)
Data specific to CONTENT_HTML.
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
unsigned int scripts_count
Number of entries in scripts.
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
Container for scripts used by an HTML document.
struct nsurl nsurl
NetSurf URL object.
Protected interface to Content handling.
bool html_can_begin_conversion(html_content *htmlc)
Test if an HTML content conversion can begin.
Extra data for some content_msg messages.
bool parse_completed
Whether the parse has been completed.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.