64 bool have_run_something =
false;
89 if (script_handler == NULL)
101 have_run_something =
true;
114 if (have_run_something) {
131 if (nscript == NULL) {
145 nscript->
async =
false;
146 nscript->
defer =
false;
168 for (i = 0, s =
parent->scripts; i !=
parent->scripts_count; i++, s++) {
173 assert(i !=
parent->scripts_count);
175 switch (event->
type) {
183 NSLOG(netsurf, INFO,
"script %d done '%s'", i,
186 NSLOG(netsurf, INFO,
"%d fetches active",
parent->base.active);
191 NSLOG(netsurf, INFO,
"script %s failed: %s",
198 NSLOG(netsurf, INFO,
"%d fetches active",
parent->base.active);
216 else if (
parent->conversion_begun) {
236 for (i = 0, s =
parent->scripts; i !=
parent->scripts_count; i++, s++) {
241 assert(i !=
parent->scripts_count);
243 switch (event->
type) {
246 NSLOG(netsurf, INFO,
"script %d done '%s'", i,
249 NSLOG(netsurf, INFO,
"%d fetches active",
parent->base.active);
254 NSLOG(netsurf, INFO,
"script %s failed: %s",
261 NSLOG(netsurf, INFO,
"%d fetches active",
parent->base.active);
291 dom_hubbub_error err;
292 unsigned int active_sync_scripts = 0;
295 for (i = 0, s =
parent->scripts; i !=
parent->scripts_count; i++, s++) {
298 active_sync_scripts++;
303 for (i = 0, s =
parent->scripts; i !=
parent->scripts_count; i++, s++) {
308 assert(i !=
parent->scripts_count);
310 switch (event->
type) {
312 NSLOG(netsurf, INFO,
"script %d done '%s'", i,
315 NSLOG(netsurf, INFO,
"%d fetches active",
parent->base.active);
321 if (script_handler != NULL &&
parent->jsthread != NULL) {
331 if (
parent->parser != NULL && active_sync_scripts == 0) {
332 err = dom_hubbub_parser_pause(
parent->parser,
false);
333 if (err != DOM_HUBBUB_OK) {
334 NSLOG(netsurf, INFO,
"unpause returned 0x%x", err);
341 NSLOG(netsurf, INFO,
"script %s failed: %s",
349 NSLOG(netsurf, INFO,
"%d fetches active",
parent->base.active);
354 if (
parent->parser != NULL && active_sync_scripts == 0) {
355 err = dom_hubbub_parser_pause(
parent->parser,
false);
356 if (err != DOM_HUBBUB_OK) {
357 NSLOG(netsurf, INFO,
"unpause returned 0x%x", err);
380static dom_hubbub_error
394 dom_hubbub_error ret = DOM_HUBBUB_OK;
401 return DOM_HUBBUB_NOMEM;
425 exc = dom_element_has_attribute(node, corestring_dom_async, &
async);
426 if (exc != DOM_NO_ERR) {
427 return DOM_HUBBUB_OK;
442 exc = dom_element_has_attribute(node,
443 corestring_dom_defer, &
defer);
444 if (exc != DOM_NO_ERR) {
445 return DOM_HUBBUB_OK;
460 if (nscript == NULL) {
463 return DOM_HUBBUB_NOMEM;
489 NSLOG(netsurf, INFO,
"Fetch failed with error %d", ns_error);
495 switch (script_type) {
497 ret = DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED;
514static dom_hubbub_error
519 struct lwc_string_s *lwcmimetype;
524 exc = dom_node_get_text_content(node, &script);
525 if ((exc != DOM_NO_ERR) || (script == NULL)) {
526 return DOM_HUBBUB_OK;
530 if (nscript == NULL) {
531 dom_string_unref(script);
534 return DOM_HUBBUB_NOMEM;
542 exc = dom_string_intern(
mimetype, &lwcmimetype);
543 if (exc != DOM_NO_ERR) {
544 return DOM_HUBBUB_DOM;
548 lwc_string_unref(lwcmimetype);
550 if (script_handler != NULL) {
552 (
const uint8_t *)dom_string_data(script),
553 dom_string_byte_length(script),
556 return DOM_HUBBUB_OK;
571 dom_hubbub_error err = DOM_HUBBUB_OK;
585 return DOM_HUBBUB_OK;
589 NSLOG(netsurf, INFO,
"content %p parser %p node %p", c, c->
parser,
592 exc = dom_element_get_attribute(node, corestring_dom_type, &mimetype);
593 if (exc != DOM_NO_ERR || mimetype == NULL) {
594 mimetype = dom_string_ref(corestring_dom_text_javascript);
597 exc = dom_element_get_attribute(node, corestring_dom_src, &
src);
598 if (exc != DOM_NO_ERR ||
src == NULL) {
602 dom_string_unref(
src);
605 dom_string_unref(mimetype);
Fetching of data from a URL (interface).
void content_broadcast(struct content *c, content_msg msg, const union content_msg_data *data)
Send a message to all users.
bool content_saw_insecure_objects(struct hlcache_handle *h)
Determine if the content referred to any insecure objects.
nsurl * content_get_url(struct content *c)
Retrieve URL associated with content.
content_status content_get_status(hlcache_handle *h)
Retrieve status of content.
void content_broadcast_error(struct content *c, nserror errorcode, const char *msg)
Send an error message to all users.
content_type content_factory_type_from_mime_type(lwc_string *mime_type)
Compute the generic content type for a MIME type.
Protected interface to Content handling.
@ CONTENT_STATUS_DONE
Content has completed all processing.
@ CONTENT_STATUS_ERROR
Error occurred, content will be destroyed imminently.
content_type
The type of a content.
@ CONTENT_SCRIPT
All script types.
@ CONTENT_MSG_DONE
content has finished processing
@ CONTENT_MSG_LOADING
fetching or converting
@ CONTENT_MSG_ERROR
error occurred
@ CONTENT_MSG_GETTHREAD
Javascript thread.
@ CONTENT_MSG_READY
may be displayed
Useful interned string pointers (interface).
nserror
Enumeration of error codes.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_NOMEM
Memory exhaustion.
nserror hlcache_handle_release(hlcache_handle *handle)
Release a high-level cache handle.
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.
High-level resource cache interface.
nserror(* hlcache_handle_callback)(hlcache_handle *handle, const hlcache_event *event, void *pw)
Client callback for high-level cache events.
bool html_begin_conversion(html_content *htmlc)
Begin conversion of an HTML document.
nserror html_proceed_to_done(html_content *html)
Complete the HTML content state machine iff all scripts are finished.
bool html_can_begin_conversion(html_content *htmlc)
Test if an HTML content conversion can begin.
Interface to text/html content handler.
Public content interface.
struct nsurl * hlcache_handle_get_url(const struct hlcache_handle *handle)
Retrieve the URL associated with a high level cache handle.
const uint8_t * content_get_source_data(struct hlcache_handle *h, size_t *size)
Retrieve source of content.
content_type content_get_type(struct hlcache_handle *h)
Retrieve computed type of content.
Interface to javascript engine functions.
struct jsthread jsthread
JavaScript interpreter thread.
bool js_exec(jsthread *thread, const uint8_t *txt, size_t txtlen, const char *name)
execute some javascript in a context
#define NSLOG(catname, level, logmsg, args...)
Localised message support (interface).
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
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.
struct nsurl nsurl
NetSurf URL object.
Private data for text/html content.
dom_hubbub_error html_process_script(void *ctx, dom_node *node)
process script node parser callback
static script_handler_t * select_script_handler(content_type ctype)
bool html_saw_insecure_scripts(html_content *htmlc)
Check if any of the scripts loaded were insecure.
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
static struct html_script * html_process_new_script(html_content *c, dom_string *mimetype, enum html_script_type type)
static dom_hubbub_error exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
static nserror convert_script_sync_cb(hlcache_handle *script, const hlcache_event *event, void *pw)
Callback for syncronous scripts.
nserror html_script_free(html_content *html)
Free all script resources and references for a html content.
nserror html_script_exec(html_content *c, bool allow_defer)
Attempt script execution for defer and async scripts.
bool() script_handler_t(struct jsthread *jsthread, const uint8_t *data, size_t size, const char *name)
static nserror convert_script_defer_cb(hlcache_handle *script, const hlcache_event *event, void *pw)
Callback for defer scripts.
static nserror convert_script_async_cb(hlcache_handle *script, const hlcache_event *event, void *pw)
Callback for asyncronous scripts.
Interface to utility string handling.
bool quirks
Content is in quirks mode.
unsigned int active
Number of child fetches or conversions currently in progress.
Context for retrieving a child object.
bool quirks
Whether parent is quirky.
const char * charset
Charset of parent.
content_msg type
Event type.
union content_msg_data data
Event data.
Data specific to CONTENT_HTML.
dom_hubbub_parser * parser
Parser object handle.
char * encoding
Encoding of source, NULL if unknown.
struct nsurl * base_url
Base URL (may be a copy of content->url).
struct jsthread * jsthread
javascript thread in use
bool parse_completed
Whether the parse has been completed.
unsigned int scripts_count
Number of entries in scripts.
struct html_script * scripts
Scripts.
Container for scripts used by an HTML document.
struct dom_string * mimetype
union html_script::@136 data
Script data.
enum html_script::html_script_type type
html_script_type
Type of script.
struct dom_string * string
struct hlcache_handle * handle
Extra data for some content_msg messages.
struct content_msg_data::@99 errordata
CONTENT_MSG_ERROR - Error from content or underlying fetch.
const char * errormsg
The message.
struct jsthread ** jsthread
CONTENT_MSG_GETTHREAD - Javascript context (thread)
browser_window_console_source src
The source of the logging.