Enable dumping of DOM tree

svn path=/trunk/netsurf/; revision=5289
This commit is contained in:
John Mark Bell 2008-09-08 21:55:20 +00:00
parent 402f53f0a5
commit c6ac553d3d
4 changed files with 2736 additions and 1799 deletions

View File

@ -23,6 +23,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <libxml/debugXML.h>
#include "content/content.h"
#include "desktop/browser.h"
#include "desktop/history_core.h"
@ -176,6 +177,7 @@ MENUPROTO(downloads);
MENUPROTO(save_window_size);
MENUPROTO(toggle_debug_rendering);
MENUPROTO(save_box_tree);
MENUPROTO(save_dom_tree);
/* navigate menu */
MENUPROTO(back);
@ -228,6 +230,7 @@ static struct menu_events menu_events[] = {
MENUEVENT(save_window_size),
MENUEVENT(toggle_debug_rendering),
MENUEVENT(save_box_tree),
MENUEVENT(save_dom_tree),
/* navigate menu */
MENUEVENT(back),
@ -868,6 +871,55 @@ MENUHANDLER(save_box_tree)
gtk_widget_destroy(save_dialog);
}
MENUHANDLER(save_dom_tree)
{
GtkWidget *save_dialog;
struct gtk_scaffolding *gw = (struct gtk_scaffolding *)g;
save_dialog = gtk_file_chooser_dialog_new("Save File", gw->window,
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(save_dialog),
getenv("HOME") ? getenv("HOME") : "/");
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(save_dialog),
"domtree.txt");
if (gtk_dialog_run(GTK_DIALOG(save_dialog)) == GTK_RESPONSE_ACCEPT) {
char *filename = gtk_file_chooser_get_filename(
GTK_FILE_CHOOSER(save_dialog));
FILE *fh;
LOG(("Saving dom tree to %s...\n", filename));
fh = fopen(filename, "w");
if (fh == NULL) {
warn_user("Error saving box tree dump.",
"Unable to open file for writing.");
} else {
struct browser_window *bw;
bw = nsgtk_get_browser_window(gw->top_level);
if (bw->current_content &&
bw->current_content->type ==
CONTENT_HTML) {
xmlDebugDumpDocument(fh,
bw->current_content->
data.html.document);
}
fclose(fh);
}
g_free(filename);
}
gtk_widget_destroy(save_dialog);
}
MENUHANDLER(stop)
{
return nsgtk_window_stop_button_clicked(GTK_WIDGET(widget), g);

File diff suppressed because it is too large Load Diff

View File

@ -486,8 +486,8 @@ bool html_create(struct content *c, const char *params[])
union content_msg_data msg_data;
html->parser = 0;
#ifdef WITH_HUBBUB
html->document = 0;
#ifdef WITH_HUBBUB
html->has_ns = false;
memset(html->ns, 0, sizeof(html->ns));
#endif
@ -869,7 +869,6 @@ const char *html_detect_encoding(const char **data, unsigned int *size)
bool html_convert(struct content *c, int width, int height)
{
xmlDoc *document;
xmlNode *html, *head;
union content_msg_data msg_data;
unsigned int time_before, time_taken;
@ -887,18 +886,18 @@ bool html_convert(struct content *c, int width, int height)
#ifndef WITH_HUBBUB
htmlParseChunk(c->data.html.parser, "", 0, 1);
document = c->data.html.parser->myDoc;
/*xmlDebugDumpDocument(stderr, c->data.html.parser->myDoc);*/
c->data.html.document = c->data.html.parser->myDoc;
/*xmlDebugDumpDocument(stderr, c->data.html.document);*/
htmlFreeParserCtxt(c->data.html.parser);
c->data.html.parser = 0;
#else
hubbub_parser_completed(c->data.html.parser);
hubbub_parser_destroy(c->data.html.parser);
c->data.html.parser = 0;
document = c->data.html.document;
c->data.html.document = c->data.html.document;
/*xmlDebugDumpDocument(stderr, document);*/
#endif
if (!document) {
if (!c->data.html.document) {
LOG(("Parsing failed"));
msg_data.error = messages_get("ParsingFail");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
@ -906,10 +905,10 @@ bool html_convert(struct content *c, int width, int height)
}
/* locate html and head elements */
html = xmlDocGetRootElement(document);
html = xmlDocGetRootElement(c->data.html.document);
if (html == 0 || strcmp((const char *) html->name, "html") != 0) {
LOG(("html element not found"));
xmlFreeDoc(document);
xmlFreeDoc(c->data.html.document);
msg_data.error = messages_get("ParsingFail");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
@ -961,9 +960,6 @@ bool html_convert(struct content *c, int width, int height)
}
/*imagemap_dump(c);*/
/* XML tree not required past this point */
xmlFreeDoc(document);
/* layout the box tree */
html_set_status(c, messages_get("Formatting"));
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
@ -2218,6 +2214,9 @@ void html_destroy(struct content *c)
hubbub_parser_destroy(c->data.html.parser);
#endif
if (c->data.html.document)
xmlFreeDoc(c->data.html.document);
/* Free base target */
if (c->data.html.base_target) {
talloc_free(c->data.html.base_target);

View File

@ -126,11 +126,11 @@ struct content_html_data {
#else
hubbub_parser *parser; /**< HTML parser context. */
hubbub_tree_handler tree_handler;
xmlDoc *document;
bool has_ns;
xmlNs *ns[NUM_NAMESPACES];
#endif
xmlDoc *document;
/** HTML parser encoding handler. */
xmlCharEncodingHandler *encoding_handler;