remove parser binding layer

This commit is contained in:
Vincent Sanders 2012-07-13 17:33:15 -06:00
parent 019be7616c
commit d7289f6701
11 changed files with 142 additions and 1632 deletions

View File

@ -14,7 +14,7 @@ S_CSS := css.c dump.c internal.c select.c utils.c
S_RENDER := box.c box_construct.c box_normalise.c \
font.c form.c \
html.c html_script.c html_interaction.c html_redraw.c \
libdom_binding.c imagemap.c layout.c list.c search.c table.c \
imagemap.c layout.c list.c search.c table.c \
textinput.c textplain.c
S_UTILS := base64.c filename.c hashtable.c locale.c messages.c nsurl.c \

View File

@ -28,7 +28,6 @@
#include "css/utils.h"
#include "desktop/gui.h"
#include "desktop/options.h"
#include "render/parser_binding.h"
#include "utils/log.h"
#include "utils/url.h"
#include "utils/utils.h"

View File

@ -56,9 +56,9 @@ static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
JSString_to_char(u16_txt, txt, length);
LOG(("content %p parser %p writing %s",htmlc, htmlc->parser_binding, txt));
if (htmlc->parser_binding != NULL) {
dom_hubbub_parser_insert_chunk(htmlc->parser_binding, (uint8_t *)txt, length);
LOG(("content %p parser %p writing %s",htmlc, htmlc->parser, txt));
if (htmlc->parser != NULL) {
dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)txt, length);
}
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);

View File

@ -146,6 +146,25 @@ static const struct element_entry element_table[] = {
};
#define ELEMENT_TABLE_COUNT (sizeof(element_table) / sizeof(element_table[0]))
static struct form_control *binding_get_control_for_node(void *ctx, dom_node *node)
{
/** \todo implement properly */
struct form_control *ctl = form_new_control(node, GADGET_HIDDEN);
if (ctl != NULL) {
ctl->value = strdup("");
ctl->initial_value = strdup("");
ctl->name = strdup("foo");
if (ctl->value == NULL || ctl->initial_value == NULL ||
ctl->name == NULL) {
form_free_control(ctl);
ctl = NULL;
}
}
return ctl;
}
/**
* Construct a box tree from an xml tree and stylesheets.
*
@ -2471,7 +2490,7 @@ bool box_input(BOX_SPECIAL_PARAMS)
dom_element_get_attribute(n, kstr_type, &type);
gadget = binding_get_control_for_node(content->parser_binding, n);
gadget = binding_get_control_for_node(content->parser, n);
if (gadget == NULL)
goto no_memory;
box->gadget = gadget;
@ -2638,7 +2657,7 @@ bool box_button(BOX_SPECIAL_PARAMS)
{
struct form_control *gadget;
gadget = binding_get_control_for_node(content->parser_binding, n);
gadget = binding_get_control_for_node(content->parser, n);
if (!gadget)
return false;
@ -2666,7 +2685,7 @@ bool box_select(BOX_SPECIAL_PARAMS)
dom_node *next, *next2;
dom_exception err;
gadget = binding_get_control_for_node(content->parser_binding, n);
gadget = binding_get_control_for_node(content->parser, n);
if (gadget == NULL)
return false;
@ -2879,7 +2898,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
size_t len;
box->type = BOX_INLINE_BLOCK;
box->gadget = binding_get_control_for_node(content->parser_binding, n);
box->gadget = binding_get_control_for_node(content->parser, n);
if (box->gadget == NULL)
return false;
box->gadget->box = box;

View File

@ -28,8 +28,6 @@
#include <strings.h>
#include <stdlib.h>
#include <dom/dom.h>
#include "utils/config.h"
#include "content/content_protected.h"
#include "content/fetch.h"
@ -191,8 +189,8 @@ static void html_box_convert_done(html_content *c, bool success)
/*imagemap_dump(c);*/
/* Destroy the parser binding */
binding_destroy_tree(c->parser_binding);
c->parser_binding = NULL;
dom_hubbub_parser_destroy(c->parser);
c->parser = NULL;
content_set_ready(&c->base);
@ -304,10 +302,9 @@ html_create_html_data(html_content *c, const http_parameter *params)
{
lwc_string *charset;
union content_msg_data msg_data;
binding_error error;
nserror nerror;
c->parser_binding = NULL;
c->parser = NULL;
c->document = NULL;
c->quirks = BINDING_QUIRKS_MODE_NONE;
c->encoding = NULL;
@ -336,8 +333,10 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->jscontext = NULL;
if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
error = BINDING_NOMEM;
goto error;
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
return NSERROR_NOMEM;
}
selection_prepare(&c->sel, (struct content *)c, true);
@ -349,60 +348,56 @@ html_create_html_data(html_content *c, const http_parameter *params)
lwc_string_unref(charset);
if (c->encoding == NULL) {
error = BINDING_NOMEM;
goto error;
lwc_string_unref(c->universal);
c->universal = NULL;
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
return NSERROR_NOMEM;
}
c->encoding_source = ENCODING_SOURCE_HEADER;
c->encoding_source = DOM_HUBBUB_ENCODING_SOURCE_HEADER;
}
/* Create the parser binding */
error = binding_create_tree(&c->parser_binding,
c->encoding,
nsoption_bool(enable_javascript),
html_process_script,
c);
if (error == BINDING_BADENCODING && c->encoding != NULL) {
c->parser = dom_hubbub_parser_create(c->encoding,
true,
nsoption_bool(enable_javascript),
NULL,
html_process_script,
c);
if ((c->parser == NULL) && (c->encoding != NULL)) {
/* Ok, we don't support the declared encoding. Bailing out
* isn't exactly user-friendly, so fall back to autodetect */
talloc_free(c->encoding);
c->encoding = NULL;
error = binding_create_tree(&c->parser_binding,
c->encoding,
nsoption_bool(enable_javascript),
html_process_script,
c);
c->parser = dom_hubbub_parser_create(c->encoding,
true,
nsoption_bool(enable_javascript),
NULL,
html_process_script,
c);
}
if (error != BINDING_OK)
goto error;
if (c->parser == NULL) {
nsurl_unref(c->base_url);
c->base_url = NULL;
lwc_string_unref(c->universal);
c->universal = NULL;
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
return NSERROR_NOMEM;
}
return NSERROR_OK;
error:
if (error == BINDING_BADENCODING) {
LOG(("Bad encoding: %s", c->encoding ? c->encoding : ""));
msg_data.error = messages_get("ParsingFail");
nerror = NSERROR_BAD_ENCODING;
} else {
msg_data.error = messages_get("NoMemory");
nerror = NSERROR_NOMEM;
}
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
if (c->universal != NULL) {
lwc_string_unref(c->universal);
c->universal = NULL;
}
if (c->base_url != NULL) {
nsurl_unref(c->base_url);
c->base_url = NULL;
}
return nerror;
}
/**
@ -456,14 +451,16 @@ static bool
html_process_data(struct content *c, const char *data, unsigned int size)
{
html_content *html = (html_content *) c;
binding_error err;
dom_hubbub_error error;
const char *encoding;
const char *source_data;
unsigned long source_size;
err = binding_parse_chunk(html->parser_binding,
(const uint8_t *) data, size);
if (err == BINDING_ENCODINGCHANGE) {
error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
goto encoding_change;
} else if (err != BINDING_OK) {
} else if (error != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
msg_data.error = messages_get("NoMemory");
@ -477,9 +474,8 @@ html_process_data(struct content *c, const char *data, unsigned int size)
encoding_change:
/* Retrieve new encoding */
encoding = binding_get_encoding(
html->parser_binding,
&html->encoding_source);
encoding = dom_hubbub_parser_get_encoding(html->parser,
&html->encoding_source);
if (html->encoding != NULL)
talloc_free(html->encoding);
@ -494,16 +490,17 @@ encoding_change:
}
/* Destroy binding */
binding_destroy_tree(html->parser_binding);
html->parser_binding = NULL;
dom_hubbub_parser_destroy(html->parser);
html->parser = NULL;
/* Create new binding, using the new encoding */
err = binding_create_tree(&html->parser_binding,
html->encoding,
nsoption_bool(enable_javascript),
html_process_script,
html);
if (err == BINDING_BADENCODING) {
html->parser = dom_hubbub_parser_create(html->encoding,
true,
nsoption_bool(enable_javascript),
NULL,
html_process_script,
html);
if (html->parser == NULL) {
/* Ok, we don't support the declared encoding. Bailing out
* isn't exactly user-friendly, so fall back to Windows-1252 */
talloc_free(html->encoding);
@ -516,37 +513,35 @@ encoding_change:
return false;
}
err = binding_create_tree(&html->parser_binding,
html->encoding,
nsoption_bool(enable_javascript),
html_process_script,
html);
}
html->parser = dom_hubbub_parser_create(html->encoding,
true,
nsoption_bool(enable_javascript),
NULL,
html_process_script,
html);
if (err != BINDING_OK) {
union content_msg_data msg_data;
if (html->parser == NULL) {
union content_msg_data msg_data;
/** @todo add a message callback function and pass the
* parser errors back instead of everything being
* OOM
*/
if (err == BINDING_BADENCODING) {
LOG(("Bad encoding: %s", html->encoding
? html->encoding : ""));
msg_data.error = messages_get("ParsingFail");
} else
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
}
}
{
const char *source_data;
unsigned long source_size;
source_data = content__get_source_data(c, &source_size);
source_data = content__get_source_data(c, &source_size);
/* Recurse to reprocess all the data. This is safe because
* the encoding is now specified at parser start which means
* it cannot be changed again. */
return html_process_data(c, source_data, source_size);
}
/* Recurse to reprocess all the data. This is safe because
* the encoding is now specified at parser start which means
* it cannot be changed again. */
return html_process_data(c, source_data, source_size);
}
@ -1923,7 +1918,7 @@ html_find_stylesheets_no_memory:
static bool html_convert(struct content *c)
{
html_content *htmlc = (html_content *) c;
binding_error err;
dom_hubbub_error err;
dom_node *html, *head;
union content_msg_data msg_data;
unsigned long size;
@ -1934,18 +1929,19 @@ static bool html_convert(struct content *c)
/* finish parsing */
content__get_source_data(c, &size);
err = binding_parse_completed(htmlc->parser_binding);
if (err != BINDING_OK) {
err = dom_hubbub_parser_completed(htmlc->parser);
if (err != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
/** @todo Improve precessing of errors */
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
}
htmlc->document = binding_get_document(htmlc->parser_binding,
&htmlc->quirks);
/** @todo quirks used to be set here too */
htmlc->document = dom_hubbub_parser_get_document(htmlc->parser);
if (htmlc->document == NULL) {
LOG(("Parsing failed"));
@ -1955,9 +1951,9 @@ static bool html_convert(struct content *c)
}
if (htmlc->encoding == NULL) {
const char *encoding = binding_get_encoding(
htmlc->parser_binding,
&htmlc->encoding_source);
const char *encoding;
encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
&htmlc->encoding_source);
htmlc->encoding = talloc_strdup(c, encoding);
if (htmlc->encoding == NULL) {
@ -2047,7 +2043,7 @@ static bool html_convert(struct content *c)
}
/* Retrieve forms from parser */
htmlc->forms = binding_get_forms(htmlc->parser_binding);
htmlc->forms = NULL; /*binding_get_forms(htmlc->parser);*/
for (f = htmlc->forms; f != NULL; f = f->prev) {
char *action;
url_func_result res;
@ -2366,13 +2362,14 @@ static void html_destroy(struct content *c)
if (html->base_url)
nsurl_unref(html->base_url);
if (html->parser_binding != NULL) {
binding_destroy_tree(html->parser_binding);
html->parser_binding = NULL;
if (html->parser != NULL) {
dom_hubbub_parser_destroy(html->parser);
html->parser = NULL;
}
if (html->document != NULL)
binding_destroy_document(html->document);
if (html->document != NULL) {
dom_node_unref(html->document);
}
/* Free base target */
if (html->base_target != NULL) {
@ -2943,7 +2940,7 @@ const char *html_get_encoding(hlcache_handle *h)
* \param h Content to retrieve charset from
* \return Pointer to charset, or NULL
*/
binding_encoding_source html_get_encoding_source(hlcache_handle *h)
dom_hubbub_encoding_source html_get_encoding_source(hlcache_handle *h)
{
html_content *c = (html_content *) hlcache_handle_get_content(h);

View File

@ -26,11 +26,14 @@
#define _NETSURF_RENDER_HTML_H_
#include <stdbool.h>
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
#include "content/content_type.h"
#include "css/css.h"
#include "desktop/mouse.h"
#include "desktop/plot_style.h"
#include "render/parser_binding.h"
#include "desktop/frame_types.h"
struct fetch_multipart_data;
@ -46,6 +49,12 @@ struct plotters;
struct scrollbar;
struct scrollbar_msg_data;
typedef enum binding_quirks_mode {
BINDING_QUIRKS_MODE_NONE,
BINDING_QUIRKS_MODE_LIMITED,
BINDING_QUIRKS_MODE_FULL
} binding_quirks_mode;
/**
* Container for stylesheets used by an HTML document
*/
@ -167,7 +176,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
dom_document *html_get_document(struct hlcache_handle *h);
struct box *html_get_box_tree(struct hlcache_handle *h);
const char *html_get_encoding(struct hlcache_handle *h);
binding_encoding_source html_get_encoding_source(struct hlcache_handle *h);
dom_hubbub_encoding_source html_get_encoding_source(struct hlcache_handle *h);
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);

View File

@ -31,8 +31,8 @@
typedef struct html_content {
struct content base;
/** Parser object handle */
void *parser_binding;
dom_hubbub_parser *parser; /**< Parser object handle */
/** Document tree */
dom_document *document;
/** Quirkyness of document */
@ -41,7 +41,7 @@ typedef struct html_content {
/** Encoding of source, NULL if unknown. */
char *encoding;
/** Source of encoding information. */
binding_encoding_source encoding_source;
dom_hubbub_encoding_source encoding_source;
/** Base URL (may be a copy of content->url). */
nsurl *base_url;

View File

@ -234,7 +234,7 @@ html_process_script(void *ctx, dom_node *node)
}
}
LOG(("content %p parser %p node %p",c,c->parser_binding, node));
LOG(("content %p parser %p node %p",c,c->parser, node));
exc = dom_element_get_attribute(node, html_dom_string_type, &mimetype);
if (exc != DOM_NO_ERR || mimetype == NULL) {

File diff suppressed because it is too large Load Diff

View File

@ -1,126 +0,0 @@
/*
* Copyright 2011 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
#include "render/form.h"
#include "render/parser_binding.h"
#include "utils/log.h"
binding_error binding_create_tree(void **ctx, const char *charset, bool enable_script, dom_script script, void *context)
{
dom_hubbub_parser *parser = NULL;
parser = dom_hubbub_parser_create(charset, true, enable_script, NULL, script, context);
if (parser == NULL) {
LOG(("Can't create Hubbub Parser\n"));
return BINDING_NOMEM;
}
*ctx = parser;
return BINDING_OK;
}
binding_error binding_destroy_tree(void *ctx)
{
dom_hubbub_parser_destroy(ctx);
return BINDING_OK;
}
binding_error binding_parse_chunk(void *ctx, const uint8_t *data, size_t len)
{
dom_hubbub_error error;
error = dom_hubbub_parser_parse_chunk(ctx, data, len);
if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
return BINDING_ENCODINGCHANGE;
} else if (error != DOM_HUBBUB_OK) {
return BINDING_NOMEM;
}
return BINDING_OK;
}
binding_error binding_parse_completed(void *ctx)
{
dom_hubbub_error error;
error = dom_hubbub_parser_completed(ctx);
if (error != DOM_HUBBUB_OK) {
return BINDING_NOMEM;
}
return BINDING_OK;
}
const char *binding_get_encoding(void *ctx, binding_encoding_source *source)
{
dom_hubbub_encoding_source hubbub_src;
const char *encoding;
encoding = dom_hubbub_parser_get_encoding(ctx, &hubbub_src);
switch (hubbub_src) {
case DOM_HUBBUB_ENCODING_SOURCE_HEADER:
*source = ENCODING_SOURCE_HEADER;
break;
case DOM_HUBBUB_ENCODING_SOURCE_DETECTED:
*source = ENCODING_SOURCE_DETECTED;
break;
case DOM_HUBBUB_ENCODING_SOURCE_META:
*source = ENCODING_SOURCE_META;
break;
}
return encoding;
}
dom_document *binding_get_document(void *ctx, binding_quirks_mode *quirks)
{
return dom_hubbub_parser_get_document(ctx);
}
struct form *binding_get_forms(void *ctx)
{
return NULL;
}
struct form_control *binding_get_control_for_node(void *ctx, dom_node *node)
{
/** \todo implement properly */
struct form_control *ctl = form_new_control(node, GADGET_HIDDEN);
if (ctl != NULL) {
ctl->value = strdup("");
ctl->initial_value = strdup("");
ctl->name = strdup("foo");
if (ctl->value == NULL || ctl->initial_value == NULL ||
ctl->name == NULL) {
form_free_control(ctl);
ctl = NULL;
}
}
return ctl;
}
void binding_destroy_document(dom_document *doc)
{
dom_node_unref(doc);
}

View File

@ -1,63 +0,0 @@
/*
* Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _NETSURF_RENDER_PARSER_BINDING_H_
#define _NETSURF_RENDER_PARSER_BINDING_H_
#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>
struct box;
struct form;
struct form_control;
typedef enum binding_error {
BINDING_OK,
BINDING_NOMEM,
BINDING_BADENCODING,
BINDING_ENCODINGCHANGE
} binding_error;
typedef enum binding_encoding_source {
ENCODING_SOURCE_HEADER,
ENCODING_SOURCE_DETECTED,
ENCODING_SOURCE_META
} binding_encoding_source;
typedef enum binding_quirks_mode {
BINDING_QUIRKS_MODE_NONE,
BINDING_QUIRKS_MODE_LIMITED,
BINDING_QUIRKS_MODE_FULL
} binding_quirks_mode;
binding_error binding_create_tree(void **ctx, const char *charset, bool enable_script, dom_script script, void *context);
binding_error binding_destroy_tree(void *ctx);
binding_error binding_parse_chunk(void *ctx, const uint8_t *data, size_t len);
binding_error binding_parse_completed(void *ctx);
const char *binding_get_encoding(void *ctx, binding_encoding_source *source);
dom_document *binding_get_document(void *ctx, binding_quirks_mode *quirks);
struct form *binding_get_forms(void *ctx);
struct form_control *binding_get_control_for_node(void *ctx, dom_node *node);
void binding_destroy_document(dom_document *doc);
#endif