summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--render/html.c16
-rw-r--r--render/html.h13
-rw-r--r--render/html_internal.h1
-rw-r--r--render/html_script.c67
4 files changed, 55 insertions, 42 deletions
diff --git a/render/html.c b/render/html.c
index 759c24433..236752942 100644
--- a/render/html.c
+++ b/render/html.c
@@ -2433,21 +2433,7 @@ static void html_destroy(struct content *c)
}
/* Free scripts */
- for (i = 0; i != html->scripts_count; i++) {
- if (html->scripts[i].mimetype != NULL) {
- dom_string_unref(html->scripts[i].mimetype);
- }
- if (html->scripts[i].type == HTML_SCRIPT_EXTERNAL &&
- html->scripts[i].data.external != NULL) {
- hlcache_handle_release(
- html->scripts[i].data.external);
- } else if (html->scripts[i].type ==
- HTML_SCRIPT_INTERNAL &&
- html->scripts[i].data.internal != NULL) {
- dom_string_unref(html->scripts[i].data.internal);
- }
- }
- free(html->scripts);
+ html_free_scripts(html);
/* Free objects */
html_destroy_objects(html);
diff --git a/render/html.h b/render/html.h
index 64548f810..dcbc1a3ba 100644
--- a/render/html.h
+++ b/render/html.h
@@ -66,10 +66,13 @@ struct html_stylesheet {
*/
struct html_script {
/** Type of script */
- enum html_script_type { HTML_SCRIPT_EXTERNAL, HTML_SCRIPT_INTERNAL } type;
+ enum html_script_type { HTML_SCRIPT_INLINE,
+ HTML_SCRIPT_SYNC,
+ HTML_SCRIPT_DEFER,
+ HTML_SCRIPT_ASYNC } type;
union {
- struct hlcache_handle *external;
- struct dom_string *internal;
+ struct hlcache_handle *handle;
+ struct dom_string *string;
} data; /**< Script data */
struct dom_string *mimetype;
struct dom_string *encoding;
@@ -175,9 +178,9 @@ struct content_html_frames *html_get_frameset(struct hlcache_handle *h);
struct content_html_iframe *html_get_iframe(struct hlcache_handle *h);
nsurl *html_get_base_url(struct hlcache_handle *h);
const char *html_get_base_target(struct hlcache_handle *h);
-struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
+struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
unsigned int *n);
-struct content_html_object *html_get_objects(struct hlcache_handle *h,
+struct content_html_object *html_get_objects(struct hlcache_handle *h,
unsigned int *n);
bool html_get_id_offset(struct hlcache_handle *h, lwc_string *frag_id,
int *x, int *y);
diff --git a/render/html_internal.h b/render/html_internal.h
index ad032f720..3eabe1cc6 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -149,6 +149,7 @@ void html_overflow_scroll_callback(void *client_data,
/* in render/html_script.c */
dom_hubbub_error html_process_script(void *ctx, dom_node *node);
+void html_free_scripts(html_content *html);
/* in render/html_forms.c */
struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
diff --git a/render/html_script.c b/render/html_script.c
index fb5125640..e3075f634 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -69,32 +69,32 @@ static bool html_scripts_exec(html_content *c)
continue;
}
- assert((s->type == HTML_SCRIPT_EXTERNAL) ||
- (s->type == HTML_SCRIPT_INTERNAL));
+ assert((s->type == HTML_SCRIPT_SYNC) ||
+ (s->type == HTML_SCRIPT_INLINE));
- if (s->type == HTML_SCRIPT_EXTERNAL) {
+ if (s->type == HTML_SCRIPT_SYNC) {
/* ensure script content is present */
- if (s->data.external == NULL)
+ if (s->data.handle == NULL)
continue;
/* ensure script content fetch status is not an error */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_ERROR)
continue;
/* ensure script handler for content type */
script_handler = select_script_handler(
- content_get_type(s->data.external));
+ content_get_type(s->data.handle));
if (script_handler == NULL)
continue; /* unsupported type */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_DONE) {
/* external script is now available */
const char *data;
unsigned long size;
data = content_get_source_data(
- s->data.external, &size );
+ s->data.handle, &size );
script_handler(c->jscontext, data, size);
s->already_started = true;
@@ -158,8 +158,7 @@ convert_script_async_cb(hlcache_handle *script,
/* Find script */
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
- if (s->type == HTML_SCRIPT_EXTERNAL &&
- s->data.external == script)
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
break;
}
@@ -187,7 +186,7 @@ convert_script_async_cb(hlcache_handle *script,
nsurl_access(hlcache_handle_get_url(script)),
event->data.error));
hlcache_handle_release(script);
- s->data.external = NULL;
+ s->data.handle = NULL;
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
@@ -213,13 +212,13 @@ convert_script_async_cb(hlcache_handle *script,
return NSERROR_OK;
}
-/**
- * process a script with a src tag
+/**
+ * process a script with a src tag
*/
static dom_hubbub_error
-exec_src_script(html_content *c,
- dom_node *node,
- dom_string *mimetype,
+exec_src_script(html_content *c,
+ dom_node *node,
+ dom_string *mimetype,
dom_string *src)
{
nserror ns_error;
@@ -230,7 +229,7 @@ exec_src_script(html_content *c,
//exc = dom_element_has_attribute(node, html_dom_string_async, &async);
- nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
+ nscript = html_process_new_script(c, HTML_SCRIPT_SYNC);
if (nscript == NULL) {
dom_string_unref(mimetype);
goto html_process_script_no_memory;
@@ -258,7 +257,7 @@ exec_src_script(html_content *c,
c,
&child,
CONTENT_SCRIPT,
- &nscript->data.external);
+ &nscript->data.handle);
nsurl_unref(joined);
@@ -297,7 +296,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
return DOM_HUBBUB_OK; /* no contents, skip */
}
- nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
+ nscript = html_process_new_script(c, HTML_SCRIPT_INLINE);
if (nscript == NULL) {
dom_string_unref(mimetype);
dom_string_unref(script);
@@ -308,7 +307,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
- nscript->data.internal = script;
+ nscript->data.string = script;
nscript->mimetype = mimetype;
nscript->already_started = true;
@@ -328,7 +327,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
-/**
+/**
* process script node parser callback
*
*
@@ -354,7 +353,7 @@ html_process_script(void *ctx, dom_node *node)
}
}
- LOG(("content %p parser %p node %p",c,c->parser, node));
+ LOG(("content %p parser %p node %p", c, c->parser, node));
exc = dom_element_get_attribute(node, corestring_dom_type, &mimetype);
if (exc != DOM_NO_ERR || mimetype == NULL) {
@@ -371,3 +370,27 @@ html_process_script(void *ctx, dom_node *node)
return err;
}
+
+void html_free_scripts(html_content *html)
+{
+ unsigned int i;
+
+ for (i = 0; i != html->scripts_count; i++) {
+ if (html->scripts[i].mimetype != NULL) {
+ dom_string_unref(html->scripts[i].mimetype);
+ }
+
+ if ((html->scripts[i].type == HTML_SCRIPT_INLINE) &&
+ (html->scripts[i].data.string != NULL)) {
+
+ dom_string_unref(html->scripts[i].data.string);
+
+ } else if ((html->scripts[i].type == HTML_SCRIPT_SYNC) &&
+ (html->scripts[i].data.handle != NULL)) {
+
+ hlcache_handle_release(html->scripts[i].data.handle);
+
+ }
+ }
+ free(html->scripts);
+}