diff options
Diffstat (limited to 'render/html.c')
-rw-r--r-- | render/html.c | 143 |
1 files changed, 46 insertions, 97 deletions
diff --git a/render/html.c b/render/html.c index fc6084332..19ea5a9d0 100644 --- a/render/html.c +++ b/render/html.c @@ -43,6 +43,7 @@ #include "render/imagemap.h" #include "render/layout.h" #include "render/search.h" +#include "javascript/js.h" #include "utils/corestrings.h" #include "utils/http.h" #include "utils/libdom.h" @@ -111,60 +112,6 @@ static nserror css_error_to_nserror(css_error error) return NSERROR_CSS; } -static nserror -dom_hubbub_error_to_nserror(dom_hubbub_error error) -{ - switch (error) { - - /* HUBBUB_REPROCESS is not handled here because it can - * never occur outside the hubbub treebuilder - */ - - case DOM_HUBBUB_OK: - /* parsed ok */ - return NSERROR_OK; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED): - /* hubbub input paused */ - return NSERROR_OK; - - case DOM_HUBBUB_NOMEM: - /* out of memory error from DOM */ - return NSERROR_NOMEM; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE): - /* encoding changed */ - return NSERROR_ENCODING_CHANGE; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NOMEM): - /* out of memory error from parser */ - return NSERROR_NOMEM; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADPARM): - return NSERROR_BAD_PARAMETER; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_INVALID): - return NSERROR_INVALID; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_FILENOTFOUND): - return NSERROR_NOT_FOUND; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NEEDDATA): - return NSERROR_NEED_DATA; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADENCODING): - return NSERROR_BAD_ENCODING; - - case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN): - /* currently only generated by the libdom hubbub binding */ - return NSERROR_DOM; - default: - /* unknown error */ - /** @todo better error handling and reporting */ - return NSERROR_UNKNOWN; - } - return NSERROR_UNKNOWN; -} static void html_destroy_objects(html_content *html) { @@ -335,7 +282,7 @@ void html_finish_conversion(html_content *c) * object, but with its target set to the Document object (and * the currentTarget set to the Window object) */ - js_fire_event(c->jscontext, "load", NULL); + js_fire_event(c->jscontext, "load", c->document, NULL); /* convert dom tree to box tree */ LOG(("DOM to box (%p)", c)); @@ -370,6 +317,8 @@ html_create_html_data(html_content *c, const http_parameter *params) { lwc_string *charset; nserror nerror; + dom_hubbub_parser_params parse_params; + dom_hubbub_error error; c->parser = NULL; c->document = NULL; @@ -423,36 +372,38 @@ html_create_html_data(html_content *c, const http_parameter *params) } /* Create the parser binding */ - c->parser = dom_hubbub_parser_create(c->encoding, - true, - nsoption_bool(enable_javascript), - NULL, - html_process_script, - c, - &c->document); - if ((c->parser == NULL) && (c->encoding != NULL)) { + parse_params.enc = c->encoding; + parse_params.fix_enc = true; + parse_params.enable_script = nsoption_bool(enable_javascript); + parse_params.msg = NULL; + parse_params.script = html_process_script; + parse_params.ctx = c; + parse_params.daf = NULL; + + error = dom_hubbub_parser_create(&parse_params, + &c->parser, + &c->document); + if ((error != DOM_HUBBUB_OK) && (c->encoding != NULL)) { /* Ok, we don't support the declared encoding. Bailing out * isn't exactly user-friendly, so fall back to autodetect */ free(c->encoding); c->encoding = NULL; - c->parser = dom_hubbub_parser_create(c->encoding, - true, - nsoption_bool(enable_javascript), - NULL, - html_process_script, - c, - &c->document); + parse_params.enc = c->encoding; + + error = dom_hubbub_parser_create(&parse_params, + &c->parser, + &c->document); } - if (c->parser == NULL) { + if (error != DOM_HUBBUB_OK) { nsurl_unref(c->base_url); c->base_url = NULL; lwc_string_unref(c->universal); c->universal = NULL; - return NSERROR_NOMEM; + return libdom_hubbub_error_to_nserror(error); } return NSERROR_OK; @@ -509,6 +460,7 @@ html_process_encoding_change(struct content *c, unsigned int size) { html_content *html = (html_content *) c; + dom_hubbub_parser_params parse_params; dom_hubbub_error error; const char *encoding; const char *source_data; @@ -538,15 +490,19 @@ html_process_encoding_change(struct content *c, dom_node_unref(html->document); } + parse_params.enc = html->encoding; + parse_params.fix_enc = true; + parse_params.enable_script = nsoption_bool(enable_javascript); + parse_params.msg = NULL; + parse_params.script = html_process_script; + parse_params.ctx = html; + parse_params.daf = NULL; + /* Create new binding, using the new encoding */ - html->parser = dom_hubbub_parser_create(html->encoding, - true, - nsoption_bool(enable_javascript), - NULL, - html_process_script, - html, - &html->document); - if (html->parser == NULL) { + error = dom_hubbub_parser_create(&parse_params, + &html->parser, + &html->document); + if (error != DOM_HUBBUB_OK) { /* Ok, we don't support the declared encoding. Bailing out * isn't exactly user-friendly, so fall back to Windows-1252 */ free(html->encoding); @@ -554,21 +510,14 @@ html_process_encoding_change(struct content *c, if (html->encoding == NULL) { return NSERROR_NOMEM; } + parse_params.enc = html->encoding; - html->parser = dom_hubbub_parser_create(html->encoding, - true, - nsoption_bool(enable_javascript), - NULL, - html_process_script, - html, - &html->document); - - if (html->parser == NULL) { - /** @todo add a message callback function and pass the - * parser errors back instead of everything being - * OOM - */ - return NSERROR_NOMEM; + error = dom_hubbub_parser_create(&parse_params, + &html->parser, + &html->document); + + if (error != DOM_HUBBUB_OK) { + return libdom_hubbub_error_to_nserror(error); } } @@ -583,7 +532,7 @@ html_process_encoding_change(struct content *c, (const uint8_t *)source_data, source_size); - return dom_hubbub_error_to_nserror(error); + return libdom_hubbub_error_to_nserror(error); } @@ -602,7 +551,7 @@ html_process_data(struct content *c, const char *data, unsigned int size) (const uint8_t *) data, size); - err = dom_hubbub_error_to_nserror(dom_ret); + err = libdom_hubbub_error_to_nserror(dom_ret); /* deal with encoding change */ if (err == NSERROR_ENCODING_CHANGE) { @@ -1992,7 +1941,7 @@ html_begin_conversion(html_content *htmlc) LOG(("Parsing failed")); content_broadcast_errorcode(&htmlc->base, - dom_hubbub_error_to_nserror(error)); + libdom_hubbub_error_to_nserror(error)); return false; } |