2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2007-05-06 04:41:12 +04:00
|
|
|
* Copyright 2007 James Bursa <bursa@users.sourceforge.net>
|
2010-06-04 13:35:08 +04:00
|
|
|
* Copyright 2010 Michael Drake <tlsa@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2004-02-20 03:43:17 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Content for text/html (implementation).
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2004-07-06 00:19:52 +04:00
|
|
|
#include <ctype.h>
|
2005-08-21 16:04:18 +04:00
|
|
|
#include <stdint.h>
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <string.h>
|
2003-04-06 01:38:06 +04:00
|
|
|
#include <strings.h>
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <stdlib.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/content_protected.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/fetch.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/options.h"
|
2011-07-01 15:16:43 +04:00
|
|
|
#include "desktop/selection.h"
|
2008-10-14 04:12:31 +04:00
|
|
|
#include "image/bitmap.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/font.h"
|
2009-02-20 14:39:25 +03:00
|
|
|
#include "render/form.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "render/html_internal.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/imagemap.h"
|
|
|
|
#include "render/layout.h"
|
2011-08-24 16:29:30 +04:00
|
|
|
#include "render/search.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "utils/http.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
2011-03-14 01:50:54 +03:00
|
|
|
#include "utils/schedule.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/talloc.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
#define CHUNK 4096
|
|
|
|
|
2008-10-10 14:56:34 +04:00
|
|
|
/* Change these to 1 to cause a dump to stderr of the frameset or box
|
|
|
|
* when the trees have been built.
|
|
|
|
*/
|
|
|
|
#define ALWAYS_DUMP_FRAMESET 0
|
|
|
|
#define ALWAYS_DUMP_BOX 0
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2011-09-16 02:47:50 +04:00
|
|
|
static void html_fini(void);
|
2011-05-07 00:40:09 +04:00
|
|
|
static nserror html_create(const content_handler *handler,
|
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c);
|
|
|
|
static nserror html_create_html_data(html_content *c,
|
|
|
|
const http_parameter *params);
|
|
|
|
static bool html_process_data(struct content *c, const char *data,
|
|
|
|
unsigned int size);
|
|
|
|
static bool html_convert(struct content *c);
|
|
|
|
static void html_reformat(struct content *c, int width, int height);
|
|
|
|
static void html_destroy(struct content *c);
|
|
|
|
static void html_stop(struct content *c);
|
|
|
|
static void html_open(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params);
|
|
|
|
static void html_close(struct content *c);
|
2011-07-13 17:20:26 +04:00
|
|
|
struct selection *html_get_selection(struct content *c);
|
2011-09-06 22:08:18 +04:00
|
|
|
static void html_get_contextual_content(struct content *c,
|
|
|
|
int x, int y, struct contextual_content *data);
|
2011-08-24 16:29:30 +04:00
|
|
|
struct search_context *html_get_search(struct content *c);
|
2011-05-07 00:40:09 +04:00
|
|
|
static nserror html_clone(const struct content *old, struct content **newc);
|
2011-09-03 13:27:42 +04:00
|
|
|
static content_type html_content_type(void);
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
static void html_finish_conversion(html_content *c);
|
2011-09-29 23:15:54 +04:00
|
|
|
static void html_box_convert_done(html_content *c, bool success);
|
2010-03-28 16:56:39 +04:00
|
|
|
static nserror html_convert_css_callback(hlcache_handle *css,
|
|
|
|
const hlcache_event *event, void *pw);
|
2011-05-07 00:40:09 +04:00
|
|
|
static bool html_meta_refresh(html_content *c, xmlNode *head);
|
|
|
|
static bool html_head(html_content *c, xmlNode *head);
|
|
|
|
static bool html_find_stylesheets(html_content *c, xmlNode *html);
|
|
|
|
static bool html_process_style_element(html_content *c, unsigned int *index,
|
2009-07-24 03:05:34 +04:00
|
|
|
xmlNode *style);
|
2010-04-11 14:52:18 +04:00
|
|
|
static void html_inline_style_done(struct content_css_data *css, void *pw);
|
2011-09-29 23:15:54 +04:00
|
|
|
static bool html_fetch_objects(html_content *c);
|
2011-03-11 02:08:34 +03:00
|
|
|
static bool html_replace_object(struct content_html_object *object,
|
2010-03-28 16:56:39 +04:00
|
|
|
const char *url);
|
|
|
|
static nserror html_object_callback(hlcache_handle *object,
|
|
|
|
const hlcache_event *event, void *pw);
|
|
|
|
static void html_object_done(struct box *box, hlcache_handle *object,
|
2004-06-13 00:08:47 +04:00
|
|
|
bool background);
|
2011-05-07 00:40:09 +04:00
|
|
|
static void html_object_failed(struct box *box, html_content *content,
|
2005-04-14 01:58:28 +04:00
|
|
|
bool background);
|
2006-01-25 09:52:38 +03:00
|
|
|
static void html_object_refresh(void *p);
|
2011-08-20 05:13:51 +04:00
|
|
|
static void html_destroy_objects(html_content *html);
|
2006-09-02 19:52:41 +04:00
|
|
|
static void html_destroy_frameset(struct content_html_frames *frameset);
|
|
|
|
static void html_destroy_iframe(struct content_html_iframe *iframe);
|
2008-10-10 14:56:34 +04:00
|
|
|
#if ALWAYS_DUMP_FRAMESET
|
2007-01-25 02:16:02 +03:00
|
|
|
static void html_dump_frameset(struct content_html_frames *frame,
|
|
|
|
unsigned int depth);
|
2008-10-10 14:56:34 +04:00
|
|
|
#endif
|
2007-01-13 03:21:15 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
static const content_handler html_content_handler = {
|
2011-09-16 02:47:50 +04:00
|
|
|
.fini = html_fini,
|
2011-05-09 19:32:34 +04:00
|
|
|
.create = html_create,
|
|
|
|
.process_data = html_process_data,
|
|
|
|
.data_complete = html_convert,
|
|
|
|
.reformat = html_reformat,
|
|
|
|
.destroy = html_destroy,
|
|
|
|
.stop = html_stop,
|
|
|
|
.mouse_track = html_mouse_track,
|
|
|
|
.mouse_action = html_mouse_action,
|
|
|
|
.redraw = html_redraw,
|
|
|
|
.open = html_open,
|
|
|
|
.close = html_close,
|
2011-07-13 17:20:26 +04:00
|
|
|
.get_selection = html_get_selection,
|
2011-09-06 22:08:18 +04:00
|
|
|
.get_contextual_content = html_get_contextual_content,
|
2011-05-09 19:32:34 +04:00
|
|
|
.clone = html_clone,
|
|
|
|
.type = html_content_type,
|
|
|
|
.no_share = true,
|
2011-05-07 00:40:09 +04:00
|
|
|
};
|
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
static const char empty_document[] =
|
|
|
|
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
|
2007-04-01 20:41:22 +04:00
|
|
|
" \"http://www.w3.org/TR/html4/strict.dtd\">"
|
2007-01-13 03:21:15 +03:00
|
|
|
"<html>"
|
|
|
|
"<head>"
|
|
|
|
"<title>Empty document</title>"
|
|
|
|
"</head>"
|
|
|
|
"<body>"
|
|
|
|
"<h1>Empty document</h1>"
|
|
|
|
"<p>The document sent by the server is empty.</p>"
|
|
|
|
"</body>"
|
|
|
|
"</html>";
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
static const char *html_types[] = {
|
|
|
|
"application/xhtml+xml",
|
|
|
|
"text/html"
|
|
|
|
};
|
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
static lwc_string *html_charset;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
nserror html_init(void)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
lwc_error lerror;
|
|
|
|
nserror error;
|
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
lerror = lwc_intern_string("charset", SLEN("charset"), &html_charset);
|
|
|
|
if (lerror != lwc_error_ok) {
|
|
|
|
error = NSERROR_NOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-09-16 02:31:16 +04:00
|
|
|
for (i = 0; i < NOF_ELEMENTS(html_types); i++) {
|
|
|
|
error = content_factory_register_handler(html_types[i],
|
2011-05-07 00:40:09 +04:00
|
|
|
&html_content_handler);
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
|
|
|
|
error:
|
|
|
|
html_fini();
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void html_fini(void)
|
|
|
|
{
|
2011-09-16 02:31:16 +04:00
|
|
|
if (html_charset != NULL) {
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string_unref(html_charset);
|
2011-09-16 02:31:16 +04:00
|
|
|
html_charset = NULL;
|
|
|
|
}
|
2011-05-07 00:40:09 +04:00
|
|
|
}
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Create a CONTENT_HTML.
|
|
|
|
*
|
|
|
|
* The content_html_data structure is initialized and the HTML parser is
|
|
|
|
* created.
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror html_create(const content_handler *handler,
|
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c)
|
|
|
|
{
|
|
|
|
html_content *html;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
html = talloc_zero(0, html_content);
|
|
|
|
if (html == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__init(&html->base, handler, imime_type, params,
|
|
|
|
llcache, fallback_charset, quirks);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
talloc_free(html);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = html_create_html_data(html, params);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
talloc_free(html);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*c = (struct content *) html;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nserror html_create_html_data(html_content *c, const http_parameter *params)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string *charset;
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2008-11-09 22:04:30 +03:00
|
|
|
binding_error error;
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror nerror;
|
2004-02-20 03:43:17 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->parser_binding = NULL;
|
|
|
|
c->document = NULL;
|
|
|
|
c->quirks = BINDING_QUIRKS_MODE_NONE;
|
|
|
|
c->encoding = NULL;
|
|
|
|
c->base_url = (char *) content__get_url(&c->base);
|
|
|
|
c->base_target = NULL;
|
2011-07-20 00:23:59 +04:00
|
|
|
c->aborted = false;
|
2011-05-07 00:40:09 +04:00
|
|
|
c->layout = NULL;
|
|
|
|
c->background_colour = NS_TRANSPARENT;
|
|
|
|
c->stylesheet_count = 0;
|
|
|
|
c->stylesheets = NULL;
|
|
|
|
c->select_ctx = NULL;
|
|
|
|
c->num_objects = 0;
|
|
|
|
c->object_list = NULL;
|
|
|
|
c->forms = NULL;
|
|
|
|
c->imagemaps = NULL;
|
|
|
|
c->bw = NULL;
|
|
|
|
c->frameset = NULL;
|
|
|
|
c->iframe = NULL;
|
|
|
|
c->page = NULL;
|
|
|
|
c->box = NULL;
|
|
|
|
c->font_func = &nsfont;
|
2011-06-28 02:21:15 +04:00
|
|
|
c->scrollbar = NULL;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
selection_prepare(&c->sel, (struct content *)c, true);
|
2011-07-13 17:20:26 +04:00
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
nerror = http_parameter_list_find_item(params, html_charset, &charset);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (nerror == NSERROR_OK) {
|
2011-07-08 12:38:17 +04:00
|
|
|
c->encoding = talloc_strdup(c, lwc_string_data(charset));
|
|
|
|
|
|
|
|
lwc_string_unref(charset);
|
|
|
|
|
|
|
|
if (c->encoding == NULL) {
|
2010-03-28 16:56:39 +04:00
|
|
|
error = BINDING_NOMEM;
|
|
|
|
goto error;
|
2005-01-02 01:05:21 +03:00
|
|
|
}
|
2011-05-07 00:40:09 +04:00
|
|
|
c->encoding_source = ENCODING_SOURCE_HEADER;
|
2005-01-02 01:05:21 +03:00
|
|
|
}
|
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
/* Create the parser binding */
|
2011-05-07 00:40:09 +04:00
|
|
|
error = binding_create_tree(c, c->encoding, &c->parser_binding);
|
|
|
|
if (error == BINDING_BADENCODING && c->encoding != NULL) {
|
2009-01-07 01:06:14 +03:00
|
|
|
/* Ok, we don't support the declared encoding. Bailing out
|
|
|
|
* isn't exactly user-friendly, so fall back to autodetect */
|
2011-05-07 00:40:09 +04:00
|
|
|
talloc_free(c->encoding);
|
|
|
|
c->encoding = NULL;
|
2009-01-07 01:06:14 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
error = binding_create_tree(c, c->encoding, &c->parser_binding);
|
2009-01-07 01:06:14 +03:00
|
|
|
}
|
|
|
|
|
2008-11-09 22:04:30 +03:00
|
|
|
if (error != BINDING_OK)
|
|
|
|
goto error;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_OK;
|
2005-01-02 01:05:21 +03:00
|
|
|
|
2008-11-09 22:04:30 +03:00
|
|
|
error:
|
2008-11-09 22:17:36 +03:00
|
|
|
if (error == BINDING_BADENCODING) {
|
2011-05-07 00:40:09 +04:00
|
|
|
LOG(("Bad encoding: %s", c->encoding ? c->encoding : ""));
|
2008-11-09 22:17:36 +03:00
|
|
|
msg_data.error = messages_get("ParsingFail");
|
2011-05-07 00:40:09 +04:00
|
|
|
nerror = NSERROR_BAD_ENCODING;
|
|
|
|
} else {
|
2008-11-09 22:04:30 +03:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
nerror = NSERROR_NOMEM;
|
|
|
|
}
|
2008-11-09 22:04:30 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
|
|
|
|
return nerror;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Process data for CONTENT_HTML.
|
|
|
|
*/
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2010-04-03 20:37:36 +04:00
|
|
|
bool html_process_data(struct content *c, const char *data, unsigned int size)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *html = (html_content *) c;
|
2008-09-23 06:19:50 +04:00
|
|
|
binding_error err;
|
2008-09-26 03:33:13 +04:00
|
|
|
const char *encoding;
|
2004-04-17 20:00:16 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
err = binding_parse_chunk(html->parser_binding,
|
2011-09-21 04:25:09 +04:00
|
|
|
(const uint8_t *) data, size);
|
2008-09-23 06:19:50 +04:00
|
|
|
if (err == BINDING_ENCODINGCHANGE) {
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
goto encoding_change;
|
2009-04-15 15:28:07 +04:00
|
|
|
} else if (err != BINDING_OK) {
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
|
|
|
|
return false;
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
}
|
2007-02-11 00:34:22 +03:00
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
return true;
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
|
|
|
|
encoding_change:
|
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
/* Retrieve new encoding */
|
2008-09-26 03:33:13 +04:00
|
|
|
encoding = binding_get_encoding(
|
2011-05-07 00:40:09 +04:00
|
|
|
html->parser_binding,
|
|
|
|
&html->encoding_source);
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (html->encoding != NULL)
|
|
|
|
talloc_free(html->encoding);
|
2009-01-06 20:52:47 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
html->encoding = talloc_strdup(c, encoding);
|
|
|
|
if (html->encoding == NULL) {
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
/* Destroy binding */
|
2011-05-07 00:40:09 +04:00
|
|
|
binding_destroy_tree(html->parser_binding);
|
2008-08-11 12:40:58 +04:00
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
/* Create new binding, using the new encoding */
|
2011-05-07 00:40:09 +04:00
|
|
|
err = binding_create_tree(html, html->encoding, &html->parser_binding);
|
2009-01-07 01:06:14 +03:00
|
|
|
if (err == BINDING_BADENCODING) {
|
|
|
|
/* Ok, we don't support the declared encoding. Bailing out
|
|
|
|
* isn't exactly user-friendly, so fall back to Windows-1252 */
|
2011-05-07 00:40:09 +04:00
|
|
|
talloc_free(html->encoding);
|
|
|
|
html->encoding = talloc_strdup(c, "Windows-1252");
|
|
|
|
if (html->encoding == NULL) {
|
2009-01-07 01:06:14 +03:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
err = binding_create_tree(html, html->encoding,
|
|
|
|
&html->parser_binding);
|
2009-01-07 01:06:14 +03:00
|
|
|
}
|
|
|
|
|
2008-11-09 22:04:30 +03:00
|
|
|
if (err != BINDING_OK) {
|
2008-09-23 06:19:50 +04:00
|
|
|
union content_msg_data msg_data;
|
2005-01-02 01:05:21 +03:00
|
|
|
|
2008-11-09 22:17:36 +03:00
|
|
|
if (err == BINDING_BADENCODING) {
|
2011-05-07 00:40:09 +04:00
|
|
|
LOG(("Bad encoding: %s", html->encoding
|
|
|
|
? html->encoding : ""));
|
2008-11-09 22:17:36 +03:00
|
|
|
msg_data.error = messages_get("ParsingFail");
|
|
|
|
} else
|
2008-11-09 22:04:30 +03:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
2005-01-02 01:05:21 +03:00
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
|
|
|
const char *source_data;
|
|
|
|
unsigned long source_size;
|
|
|
|
|
|
|
|
source_data = content__get_source_data(c, &source_size);
|
|
|
|
|
2011-09-21 04:25:09 +04:00
|
|
|
/* Recurse to reprocess all the data. This is safe because
|
|
|
|
* the encoding is now specified at parser start which means
|
2010-03-28 16:56:39 +04:00
|
|
|
* it cannot be changed again. */
|
2010-04-03 20:37:36 +04:00
|
|
|
return html_process_data(c, source_data, source_size);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2005-01-02 01:05:21 +03:00
|
|
|
}
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Convert a CONTENT_HTML for display.
|
|
|
|
*
|
|
|
|
* The following steps are carried out in order:
|
|
|
|
*
|
|
|
|
* - parsing to an XML tree is completed
|
|
|
|
* - stylesheets are fetched
|
|
|
|
* - the XML tree is converted to a box tree and object fetches are started
|
|
|
|
*
|
|
|
|
* On exit, the content status will be either CONTENT_STATUS_DONE if the
|
|
|
|
* document is completely loaded or CONTENT_STATUS_READY if objects are still
|
|
|
|
* being fetched.
|
|
|
|
*/
|
|
|
|
|
2010-03-30 02:33:21 +04:00
|
|
|
bool html_convert(struct content *c)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *htmlc = (html_content *) c;
|
2009-04-15 15:28:07 +04:00
|
|
|
binding_error err;
|
2003-04-11 01:44:45 +04:00
|
|
|
xmlNode *html, *head;
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2010-03-28 16:56:39 +04:00
|
|
|
unsigned long size;
|
2009-02-20 14:39:25 +03:00
|
|
|
struct form *f;
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
/* finish parsing */
|
2010-03-28 16:56:39 +04:00
|
|
|
content__get_source_data(c, &size);
|
|
|
|
if (size == 0) {
|
2008-11-20 17:47:36 +03:00
|
|
|
/* Destroy current binding */
|
2011-05-07 00:40:09 +04:00
|
|
|
binding_destroy_tree(htmlc->parser_binding);
|
2008-11-20 17:47:36 +03:00
|
|
|
|
|
|
|
/* Also, any existing encoding information,
|
|
|
|
* as it's not guaranteed to match the error page.
|
|
|
|
*/
|
2011-05-07 00:40:09 +04:00
|
|
|
talloc_free(htmlc->encoding);
|
|
|
|
htmlc->encoding = NULL;
|
2008-11-20 17:47:36 +03:00
|
|
|
|
|
|
|
/* Create new binding, using default charset */
|
2011-05-07 00:40:09 +04:00
|
|
|
err = binding_create_tree(c, NULL, &htmlc->parser_binding);
|
2008-11-20 17:47:36 +03:00
|
|
|
if (err != BINDING_OK) {
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
if (err == BINDING_BADENCODING) {
|
2011-05-07 00:40:09 +04:00
|
|
|
LOG(("Bad encoding: %s", htmlc->encoding
|
|
|
|
? htmlc->encoding : ""));
|
2008-11-20 17:47:36 +03:00
|
|
|
msg_data.error = messages_get("ParsingFail");
|
|
|
|
} else
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process the error page */
|
|
|
|
if (html_process_data(c, (char *) empty_document,
|
|
|
|
SLEN(empty_document)) == false)
|
|
|
|
return false;
|
2008-09-23 06:19:50 +04:00
|
|
|
}
|
Merged revisions 4859-5013,5016-5018 via svnmerge from
svn://source.netsurf-browser.org/branches/takkaria/netsurf-hubbub
........
r4860 | takkaria | 2008-08-02 03:51:35 +0100 (Sat, 02 Aug 2008) | 2 lines
A really horribly rough first go at integrating hubbub with NetSurf. Segfaults, but I'm not sure what I've done wrong.
........
r4861 | jmb | 2008-08-02 05:01:19 +0100 (Sat, 02 Aug 2008) | 3 lines
Fix segfault caused by mismatched struct layout expectations.
Fix warnings, too.
........
r4862 | jmb | 2008-08-02 05:11:02 +0100 (Sat, 02 Aug 2008) | 2 lines
Destroy parser as soon as it's no longer needed, and flag this so that html_destroy doesn't cause things to trample all over the heap.
........
r4863 | takkaria | 2008-08-02 15:30:34 +0100 (Sat, 02 Aug 2008) | 2 lines
Remove deugging printf()s, add Aliases file, add script { display: none; } block.
........
r4868 | takkaria | 2008-08-02 22:14:55 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix a segfault bug.
........
r4869 | takkaria | 2008-08-02 22:17:58 +0100 (Sat, 02 Aug 2008) | 2 lines
Add gtk/res/Aliases as a symlink to the one in !NS/Resources
........
r4870 | takkaria | 2008-08-02 22:26:31 +0100 (Sat, 02 Aug 2008) | 2 lines
Fix symlink.
........
r4885 | jmb | 2008-08-03 23:26:54 +0100 (Sun, 03 Aug 2008) | 2 lines
Make multiple parallel parser instances work correctly.
........
r4886 | tlsa | 2008-08-04 00:21:29 +0100 (Mon, 04 Aug 2008) | 1 line
Don't display contents of STYLE.
........
r4891 | jmb | 2008-08-04 01:18:07 +0100 (Mon, 04 Aug 2008) | 5 lines
Fix reparent_children to actually work
Make get_parent_node pay attention to the element_only flag
Fixup node referencing when appending a text child
Make clone_node clone attributes and namespace information in the non-deep case
........
r4918 | jmb | 2008-08-05 15:27:03 +0100 (Tue, 05 Aug 2008) | 2 lines
Fix debug target
........
r4944 | takkaria | 2008-08-07 12:56:50 +0100 (Thu, 07 Aug 2008) | 2 lines
Use talloc to allocate space for Hubbub.
........
r4993 | takkaria | 2008-08-10 17:49:47 +0100 (Sun, 10 Aug 2008) | 2 lines
Stub out the encoding change callback so NS-hubbub compiles again.
........
r4994 | takkaria | 2008-08-10 18:02:33 +0100 (Sun, 10 Aug 2008) | 2 lines
Tell Hubbub the encoding that HTTP gives us, if we have one.
........
r5001 | takkaria | 2008-08-11 02:53:24 +0100 (Mon, 11 Aug 2008) | 2 lines
First go at implementing proper <meta charset> support in NetSurf, amongst some refactoring. Probably works, but I have no pages around to test it on.
........
r5002 | takkaria | 2008-08-11 02:56:35 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix (I hope) a 64-bit compiler warning.
........
r5012 | takkaria | 2008-08-11 08:40:28 +0100 (Mon, 11 Aug 2008) | 2 lines
Fix some nits from jmb. (Remove const from html->encoding, set encoding_source to something about right.)
........
r5013 | takkaria | 2008-08-11 08:48:50 +0100 (Mon, 11 Aug 2008) | 2 lines
Properly fix <meta charset> handling, by passing in the right thing as the context. No idea how this worked before. :) (credit: jmb)
........
r5017 | jmb | 2008-08-11 09:13:22 +0100 (Mon, 11 Aug 2008) | 7 lines
Pedantic typo fix.
Make Hubbub YES when building for RISC OS.
Make Hubbub AUTO when building for GTK
Ignore the presence of Hubbub on other platforms.
Remove the explicit libparserutils pkg-config stuff from the makefile (see r5016)
Add some logic that means Hubbub gets enabled correctly when building on RISC OS and when cross-compiling for it. (This is ugly and will go away when pkg-config is available on RO)
........
svn path=/trunk/netsurf/; revision=5019
2008-08-11 12:17:48 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
err = binding_parse_completed(htmlc->parser_binding);
|
2009-04-15 15:28:07 +04:00
|
|
|
if (err != BINDING_OK) {
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
htmlc->document = binding_get_document(htmlc->parser_binding,
|
2011-05-07 00:40:09 +04:00
|
|
|
&htmlc->quirks);
|
|
|
|
/*xmlDebugDumpDocument(stderr, htmlc->document);*/
|
2008-09-23 06:19:50 +04:00
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
if (htmlc->document == NULL) {
|
2003-04-11 01:44:45 +04:00
|
|
|
LOG(("Parsing failed"));
|
2004-06-11 00:41:26 +04:00
|
|
|
msg_data.error = messages_get("ParsingFail");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2005-01-02 01:05:21 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (htmlc->encoding == NULL) {
|
2009-02-20 15:50:34 +03:00
|
|
|
const char *encoding = binding_get_encoding(
|
2011-05-07 00:40:09 +04:00
|
|
|
htmlc->parser_binding,
|
|
|
|
&htmlc->encoding_source);
|
2009-02-20 15:50:34 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
htmlc->encoding = talloc_strdup(c, encoding);
|
|
|
|
if (htmlc->encoding == NULL) {
|
2009-02-20 15:50:34 +03:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
/* Give up processing if we've been aborted */
|
|
|
|
if (htmlc->aborted) {
|
|
|
|
msg_data.error = messages_get("Stopped");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
/* locate html and head elements */
|
2011-05-07 00:40:09 +04:00
|
|
|
html = xmlDocGetRootElement(htmlc->document);
|
2011-07-20 00:23:59 +04:00
|
|
|
if (html == NULL || strcmp((const char *) html->name, "html") != 0) {
|
2003-04-11 01:44:45 +04:00
|
|
|
LOG(("html element not found"));
|
2004-06-11 00:41:26 +04:00
|
|
|
msg_data.error = messages_get("ParsingFail");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-11 01:44:45 +04:00
|
|
|
for (head = html->children;
|
2011-07-20 00:23:59 +04:00
|
|
|
head != NULL && head->type != XML_ELEMENT_NODE;
|
2003-04-11 01:44:45 +04:00
|
|
|
head = head->next)
|
|
|
|
;
|
2005-05-15 21:37:00 +04:00
|
|
|
if (head && strcmp((const char *) head->name, "head") != 0) {
|
2011-07-20 00:23:59 +04:00
|
|
|
head = NULL;
|
2003-04-11 01:44:45 +04:00
|
|
|
LOG(("head element not found"));
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-11 01:44:45 +04:00
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
if (head != NULL) {
|
|
|
|
if (html_head(htmlc, head) == false) {
|
2005-01-02 01:05:21 +03:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-25 09:52:38 +03:00
|
|
|
|
|
|
|
/* handle meta refresh */
|
2011-07-20 00:23:59 +04:00
|
|
|
if (html_meta_refresh(htmlc, head) == false)
|
2006-01-25 09:52:38 +03:00
|
|
|
return false;
|
2005-01-02 01:05:21 +03:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
/* Retrieve forms from parser */
|
2011-05-07 00:40:09 +04:00
|
|
|
htmlc->forms = binding_get_forms(htmlc->parser_binding);
|
|
|
|
for (f = htmlc->forms; f != NULL; f = f->prev) {
|
2009-02-20 14:39:25 +03:00
|
|
|
char *action;
|
|
|
|
url_func_result res;
|
|
|
|
|
2009-02-20 15:50:34 +03:00
|
|
|
/* Make all actions absolute */
|
2011-02-25 22:56:28 +03:00
|
|
|
if (f->action == NULL || f->action[0] == '\0') {
|
|
|
|
/* HTML5 4.10.22.3 step 11 */
|
|
|
|
res = url_join(content__get_url(c),
|
2011-05-07 00:40:09 +04:00
|
|
|
htmlc->base_url, &action);
|
2011-02-25 22:56:28 +03:00
|
|
|
} else {
|
2011-05-07 00:40:09 +04:00
|
|
|
res = url_join(f->action, htmlc->base_url, &action);
|
2011-02-25 22:56:28 +03:00
|
|
|
}
|
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
if (res != URL_FUNC_OK) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(f->action);
|
|
|
|
f->action = action;
|
2009-02-20 15:50:34 +03:00
|
|
|
|
|
|
|
/* Ensure each form has a document encoding */
|
|
|
|
if (f->document_charset == NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
f->document_charset = strdup(htmlc->encoding);
|
2009-02-20 15:50:34 +03:00
|
|
|
if (f->document_charset == NULL) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-02-20 14:39:25 +03:00
|
|
|
}
|
|
|
|
|
2010-04-11 14:52:18 +04:00
|
|
|
/* get stylesheets */
|
2011-07-20 00:23:59 +04:00
|
|
|
if (html_find_stylesheets(htmlc, html) == false)
|
2010-04-11 14:52:18 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Complete conversion of an HTML document
|
|
|
|
*
|
|
|
|
* \param c Content to convert
|
|
|
|
*/
|
2011-05-07 00:40:09 +04:00
|
|
|
void html_finish_conversion(html_content *c)
|
2010-04-11 14:52:18 +04:00
|
|
|
{
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
xmlNode *html;
|
|
|
|
uint32_t i;
|
|
|
|
css_error error;
|
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
/* Bail out if we've been aborted */
|
|
|
|
if (c->aborted) {
|
|
|
|
msg_data.error = messages_get("Stopped");
|
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
2011-07-21 01:39:51 +04:00
|
|
|
content_set_error(&c->base);
|
2011-07-20 00:23:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
html = xmlDocGetRootElement(c->document);
|
2010-04-11 14:52:18 +04:00
|
|
|
assert(html != NULL);
|
|
|
|
|
|
|
|
/* check that the base stylesheet loaded; layout fails without it */
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->stylesheets[STYLESHEET_BASE].data.external == NULL) {
|
2010-04-11 14:52:18 +04:00
|
|
|
msg_data.error = "Base stylesheet failed to load";
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
2011-07-21 01:39:51 +04:00
|
|
|
content_set_error(&c->base);
|
2010-04-11 14:52:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create selection context */
|
2011-05-07 00:40:09 +04:00
|
|
|
error = css_select_ctx_create(ns_realloc, c, &c->select_ctx);
|
2010-04-11 14:52:18 +04:00
|
|
|
if (error != CSS_OK) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
2011-07-21 01:39:51 +04:00
|
|
|
content_set_error(&c->base);
|
2010-04-11 14:52:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add sheets to it */
|
2011-05-07 00:40:09 +04:00
|
|
|
for (i = STYLESHEET_BASE; i != c->stylesheet_count; i++) {
|
|
|
|
const struct html_stylesheet *hsheet = &c->stylesheets[i];
|
2010-04-11 14:52:18 +04:00
|
|
|
css_stylesheet *sheet;
|
|
|
|
css_origin origin = CSS_ORIGIN_AUTHOR;
|
|
|
|
|
|
|
|
if (i < STYLESHEET_START)
|
|
|
|
origin = CSS_ORIGIN_UA;
|
|
|
|
|
|
|
|
if (hsheet->type == HTML_STYLESHEET_EXTERNAL &&
|
|
|
|
hsheet->data.external != NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
sheet = nscss_get_stylesheet(hsheet->data.external);
|
2010-04-11 14:52:18 +04:00
|
|
|
} else if (hsheet->type == HTML_STYLESHEET_INTERNAL) {
|
|
|
|
sheet = hsheet->data.internal->sheet;
|
|
|
|
} else {
|
|
|
|
sheet = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sheet != NULL) {
|
|
|
|
error = css_select_ctx_append_sheet(
|
2011-05-07 00:40:09 +04:00
|
|
|
c->select_ctx, sheet,
|
2010-04-11 14:52:18 +04:00
|
|
|
origin, CSS_MEDIA_SCREEN);
|
|
|
|
if (error != CSS_OK) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR,
|
2010-04-11 14:52:18 +04:00
|
|
|
msg_data);
|
2011-07-21 01:39:51 +04:00
|
|
|
content_set_error(&c->base);
|
2010-04-11 14:52:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* convert xml tree to box tree */
|
2011-09-29 23:15:54 +04:00
|
|
|
LOG(("XML to box (%p)", c));
|
2011-05-07 00:40:09 +04:00
|
|
|
content_set_status(&c->base, messages_get("Processing"));
|
|
|
|
content_broadcast(&c->base, CONTENT_MSG_STATUS, msg_data);
|
2011-09-29 23:15:54 +04:00
|
|
|
if (xml_to_box(html, c, html_box_convert_done) == false) {
|
2011-08-20 05:13:51 +04:00
|
|
|
html_destroy_objects(c);
|
2004-12-14 01:17:43 +03:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
2011-07-21 01:39:51 +04:00
|
|
|
content_set_error(&c->base);
|
2010-04-11 14:52:18 +04:00
|
|
|
return;
|
2004-12-14 01:17:43 +03:00
|
|
|
}
|
2011-09-29 23:15:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform post-box-creation conversion of a document
|
|
|
|
*
|
|
|
|
* \param c HTML content to complete conversion of
|
|
|
|
* \param success Whether box tree construction was successful
|
|
|
|
*/
|
|
|
|
void html_box_convert_done(html_content *c, bool success)
|
|
|
|
{
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
xmlNode *html;
|
|
|
|
|
|
|
|
LOG(("Done XML to box (%p)", c));
|
|
|
|
|
|
|
|
/* Clean up and report error if unsuccessful or aborted */
|
|
|
|
if (success == false || c->aborted) {
|
|
|
|
html_destroy_objects(c);
|
|
|
|
if (success == false)
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
else
|
|
|
|
msg_data.error = messages_get("Stopped");
|
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
content_set_error(&c->base);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
html = xmlDocGetRootElement(c->document);
|
|
|
|
assert(html != NULL);
|
|
|
|
|
2008-10-10 14:56:34 +04:00
|
|
|
#if ALWAYS_DUMP_BOX
|
2011-05-07 00:40:09 +04:00
|
|
|
box_dump(stderr, c->layout->children, 0);
|
2008-10-10 14:56:34 +04:00
|
|
|
#endif
|
|
|
|
#if ALWAYS_DUMP_FRAMESET
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->frameset)
|
|
|
|
html_dump_frameset(c->frameset, 0);
|
2008-10-10 14:56:34 +04:00
|
|
|
#endif
|
2003-04-12 01:06:51 +04:00
|
|
|
|
2004-03-27 01:16:31 +03:00
|
|
|
/* extract image maps - can't do this sensibly in xml_to_box */
|
2011-08-20 05:13:51 +04:00
|
|
|
if (imagemap_extract(html, c) == false) {
|
2004-12-08 03:33:25 +03:00
|
|
|
LOG(("imagemap extraction failed"));
|
2011-08-20 05:13:51 +04:00
|
|
|
html_destroy_objects(c);
|
2004-12-08 03:33:25 +03:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
2011-07-21 01:39:51 +04:00
|
|
|
content_set_error(&c->base);
|
2010-04-11 14:52:18 +04:00
|
|
|
return;
|
2004-12-08 03:33:25 +03:00
|
|
|
}
|
2004-03-27 01:16:31 +03:00
|
|
|
/*imagemap_dump(c);*/
|
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
/* Destroy the parser binding */
|
2011-05-07 00:40:09 +04:00
|
|
|
binding_destroy_tree(c->parser_binding);
|
|
|
|
c->parser_binding = NULL;
|
2009-02-20 14:39:25 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
/* Spawn object fetches */
|
|
|
|
html_fetch_objects(c);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_set_ready(&c->base);
|
2010-04-11 14:52:18 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->base.active == 0)
|
|
|
|
content_set_done(&c->base);
|
2007-01-13 03:21:15 +03:00
|
|
|
|
2010-04-11 14:52:18 +04:00
|
|
|
html_set_status(c, "");
|
2007-01-13 03:21:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process elements in <head>.
|
|
|
|
*
|
|
|
|
* \param c content structure
|
|
|
|
* \param head xml node of head element
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*
|
|
|
|
* The title and base href are extracted if present.
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool html_head(html_content *c, xmlNode *head)
|
2007-01-13 03:21:15 +03:00
|
|
|
{
|
|
|
|
xmlNode *node;
|
|
|
|
xmlChar *s;
|
|
|
|
|
2010-09-17 01:03:16 +04:00
|
|
|
for (node = head->children; node != 0; node = node->next) {
|
|
|
|
if (node->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->base.title == NULL && strcmp((const char *) node->name,
|
2008-02-25 20:58:00 +03:00
|
|
|
"title") == 0) {
|
2007-01-13 03:21:15 +03:00
|
|
|
xmlChar *title = xmlNodeGetContent(node);
|
2008-08-12 03:32:16 +04:00
|
|
|
char *title2;
|
2007-01-13 03:21:15 +03:00
|
|
|
if (!title)
|
|
|
|
return false;
|
2008-08-12 03:32:16 +04:00
|
|
|
title2 = squash_whitespace((const char *) title);
|
2007-01-13 03:21:15 +03:00
|
|
|
xmlFree(title);
|
|
|
|
if (!title2)
|
|
|
|
return false;
|
2011-05-07 00:40:09 +04:00
|
|
|
if (content__set_title(&c->base, title2) == false) {
|
2010-04-03 15:55:28 +04:00
|
|
|
free(title2);
|
2007-01-13 03:21:15 +03:00
|
|
|
return false;
|
2010-04-03 15:55:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(title2);
|
2003-06-05 17:17:55 +04:00
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
} else if (strcmp((const char *) node->name, "base") == 0) {
|
2007-01-13 03:21:15 +03:00
|
|
|
char *href = (char *) xmlGetProp(node,
|
|
|
|
(const xmlChar *) "href");
|
|
|
|
if (href) {
|
|
|
|
char *url;
|
|
|
|
url_func_result res;
|
|
|
|
res = url_normalize(href, &url);
|
|
|
|
if (res == URL_FUNC_OK) {
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base_url = talloc_strdup(c, url);
|
2007-01-13 03:21:15 +03:00
|
|
|
free(url);
|
|
|
|
}
|
|
|
|
xmlFree(href);
|
|
|
|
}
|
|
|
|
/* don't use the central values to ease freeing later on */
|
|
|
|
if ((s = xmlGetProp(node, (const xmlChar *) "target"))) {
|
2008-02-25 20:58:00 +03:00
|
|
|
if ((!strcasecmp((const char *) s, "_blank")) ||
|
2008-03-01 02:03:26 +03:00
|
|
|
(!strcasecmp((const char *) s,
|
2008-02-25 20:58:00 +03:00
|
|
|
"_top")) ||
|
2008-03-01 02:03:26 +03:00
|
|
|
(!strcasecmp((const char *) s,
|
2008-02-25 20:58:00 +03:00
|
|
|
"_parent")) ||
|
2008-03-01 02:03:26 +03:00
|
|
|
(!strcasecmp((const char *) s,
|
2008-02-25 20:58:00 +03:00
|
|
|
"_self")) ||
|
2007-01-13 03:21:15 +03:00
|
|
|
('a' <= s[0] && s[0] <= 'z') ||
|
|
|
|
('A' <= s[0] && s[0] <= 'Z')) { /* [6.16] */
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base_target = talloc_strdup(c,
|
2008-02-25 20:58:00 +03:00
|
|
|
(const char *) s);
|
2011-05-07 00:40:09 +04:00
|
|
|
if (!c->base_target) {
|
2007-01-13 03:21:15 +03:00
|
|
|
xmlFree(s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFree(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-06-11 00:41:26 +04:00
|
|
|
return true;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
|
2006-01-25 09:52:38 +03:00
|
|
|
/**
|
|
|
|
* Search for meta refresh
|
|
|
|
*
|
2006-01-28 19:01:19 +03:00
|
|
|
* http://wp.netscape.com/assist/net_sites/pushpull.html
|
|
|
|
*
|
2006-01-25 09:52:38 +03:00
|
|
|
* \param c content structure
|
|
|
|
* \param head xml node of head element
|
|
|
|
* \return true on success, false otherwise (error reported)
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool html_meta_refresh(html_content *c, xmlNode *head)
|
2006-01-25 09:52:38 +03:00
|
|
|
{
|
|
|
|
xmlNode *n;
|
|
|
|
xmlChar *equiv, *content;
|
|
|
|
union content_msg_data msg_data;
|
2008-07-30 04:51:26 +04:00
|
|
|
char *url, *end, *refresh = NULL, quote = 0;
|
2006-01-25 09:52:38 +03:00
|
|
|
url_func_result res;
|
|
|
|
|
|
|
|
for (n = head == 0 ? 0 : head->children; n; n = n->next) {
|
|
|
|
if (n->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2008-01-28 05:43:06 +03:00
|
|
|
/* Recurse into noscript elements */
|
2008-02-25 20:58:00 +03:00
|
|
|
if (strcmp((const char *) n->name, "noscript") == 0) {
|
2008-01-28 05:43:06 +03:00
|
|
|
if (!html_meta_refresh(c, n)) {
|
|
|
|
/* Some error occurred */
|
|
|
|
return false;
|
2011-05-07 00:40:09 +04:00
|
|
|
} else if (c->base.refresh) {
|
2008-01-28 05:43:06 +03:00
|
|
|
/* Meta refresh found - stop */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
if (strcmp((const char *) n->name, "meta")) {
|
2006-01-25 09:52:38 +03:00
|
|
|
continue;
|
2008-01-28 05:43:06 +03:00
|
|
|
}
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
equiv = xmlGetProp(n, (const xmlChar *) "http-equiv");
|
2006-01-25 09:52:38 +03:00
|
|
|
if (!equiv)
|
|
|
|
continue;
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
if (strcasecmp((const char *) equiv, "refresh")) {
|
2006-01-25 09:52:38 +03:00
|
|
|
xmlFree(equiv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFree(equiv);
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
content = xmlGetProp(n, (const xmlChar *) "content");
|
2006-01-25 09:52:38 +03:00
|
|
|
if (!content)
|
|
|
|
continue;
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
end = (char *) content + strlen((const char *) content);
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-12-30 18:46:06 +03:00
|
|
|
/* content := *LWS intpart fracpart? *LWS [';' *LWS *1url *LWS]
|
|
|
|
* intpart := 1*DIGIT
|
|
|
|
* fracpart := 1*('.' | DIGIT)
|
2008-07-30 04:51:26 +04:00
|
|
|
* url := "url" *LWS '=' *LWS (url-nq | url-sq | url-dq)
|
|
|
|
* url-nq := *urlchar
|
2008-07-30 04:58:37 +04:00
|
|
|
* url-sq := "'" *(urlchar | '"') "'"
|
|
|
|
* url-dq := '"' *(urlchar | "'") '"'
|
2008-07-30 04:51:26 +04:00
|
|
|
* urlchar := [#x9#x21#x23-#x26#x28-#x7E] | nonascii
|
|
|
|
* nonascii := [#x80-#xD7FF#xE000-#xFFFD#x10000-#x10FFFF]
|
|
|
|
*/
|
|
|
|
|
2008-12-30 18:46:06 +03:00
|
|
|
/* *LWS intpart */
|
2006-01-25 09:52:38 +03:00
|
|
|
msg_data.delay = (int)strtol((char *) content, &url, 10);
|
2007-04-08 02:51:06 +04:00
|
|
|
/* a very small delay and self-referencing URL can cause a loop
|
|
|
|
* that grinds machines to a halt. To prevent this we set a
|
|
|
|
* minimum refresh delay of 1s. */
|
|
|
|
if (msg_data.delay < 1)
|
|
|
|
msg_data.delay = 1;
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-12-30 18:46:06 +03:00
|
|
|
/* fracpart? (ignored, as delay is integer only) */
|
|
|
|
while (url < end && (('0' <= *url && *url <= '9') ||
|
|
|
|
*url == '.')) {
|
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
/* *LWS */
|
|
|
|
while (url < end && isspace(*url)) {
|
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ';' */
|
|
|
|
if (url < end && *url == ';')
|
|
|
|
url++;
|
|
|
|
|
|
|
|
/* *LWS */
|
|
|
|
while (url < end && isspace(*url)) {
|
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
2006-01-28 19:01:19 +03:00
|
|
|
if (url == end) {
|
|
|
|
/* Just delay specified, so refresh current page */
|
|
|
|
xmlFree(content);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.refresh = talloc_strdup(c,
|
|
|
|
content__get_url(&c->base));
|
|
|
|
if (!c->base.refresh) {
|
2006-01-28 19:01:19 +03:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base,
|
2006-01-28 19:01:19 +03:00
|
|
|
CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_REFRESH,
|
|
|
|
msg_data);
|
2006-01-28 19:01:19 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-09-17 01:33:55 +04:00
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
/* "url" */
|
|
|
|
if (url <= end - 3) {
|
|
|
|
if (strncasecmp(url, "url", 3) == 0) {
|
|
|
|
url += 3;
|
|
|
|
} else {
|
|
|
|
/* Unexpected input, ignore this header */
|
|
|
|
continue;
|
2007-04-01 20:41:22 +04:00
|
|
|
}
|
2008-07-30 04:51:26 +04:00
|
|
|
} else {
|
|
|
|
/* Insufficient input, ignore this header */
|
|
|
|
continue;
|
2006-01-25 09:52:38 +03:00
|
|
|
}
|
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
/* *LWS */
|
|
|
|
while (url < end && isspace(*url)) {
|
|
|
|
url++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '=' */
|
|
|
|
if (url < end) {
|
|
|
|
if (*url == '=') {
|
2007-04-01 20:41:22 +04:00
|
|
|
url++;
|
2008-07-30 04:51:26 +04:00
|
|
|
} else {
|
|
|
|
/* Unexpected input, ignore this header */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Insufficient input, ignore this header */
|
|
|
|
continue;
|
2006-07-18 03:57:42 +04:00
|
|
|
}
|
2006-09-17 01:33:55 +04:00
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
/* *LWS */
|
|
|
|
while (url < end && isspace(*url)) {
|
|
|
|
url++;
|
2007-04-01 20:41:22 +04:00
|
|
|
}
|
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
/* '"' or "'" */
|
|
|
|
if (url < end && (*url == '"' || *url == '\'')) {
|
|
|
|
quote = *url;
|
|
|
|
url++;
|
|
|
|
}
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
/* Start of URL */
|
|
|
|
refresh = url;
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
if (quote != 0) {
|
|
|
|
/* url-sq | url-dq */
|
|
|
|
while (url < end && *url != quote)
|
|
|
|
url++;
|
|
|
|
} else {
|
|
|
|
/* url-nq */
|
|
|
|
while (url < end && !isspace(*url))
|
|
|
|
url++;
|
|
|
|
}
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
/* '"' or "'" or *LWS (we don't care) */
|
|
|
|
if (url < end)
|
|
|
|
*url = '\0';
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
res = url_join(refresh, c->base_url, &refresh);
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
xmlFree(content);
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
if (res == URL_FUNC_NOMEM) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
2008-07-30 04:51:26 +04:00
|
|
|
return false;
|
|
|
|
} else if (res == URL_FUNC_FAILED) {
|
|
|
|
/* This isn't fatal so carry on looking */
|
|
|
|
continue;
|
2006-01-25 09:52:38 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.refresh = talloc_strdup(c, refresh);
|
2008-07-30 04:51:26 +04:00
|
|
|
|
|
|
|
free(refresh);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (!c->base.refresh) {
|
2008-07-30 04:51:26 +04:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
2008-07-30 04:51:26 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
|
2006-01-25 09:52:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Process inline stylesheets and fetch linked stylesheets.
|
|
|
|
*
|
2008-09-23 14:44:10 +04:00
|
|
|
* Uses STYLE and LINK elements inside and outside HEAD
|
|
|
|
*
|
2004-02-20 03:43:17 +03:00
|
|
|
* \param c content structure
|
2009-12-18 02:55:02 +03:00
|
|
|
* \param html xml node of html element
|
2007-05-06 04:41:12 +04:00
|
|
|
* \return true on success, false if an error occurred
|
2004-02-20 03:43:17 +03:00
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool html_find_stylesheets(html_content *c, xmlNode *html)
|
2003-04-06 01:38:06 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
content_type accept = CONTENT_CSS;
|
2007-10-02 08:48:30 +04:00
|
|
|
xmlNode *node;
|
2009-02-10 21:35:56 +03:00
|
|
|
char *rel, *type, *media, *href, *url, *url2;
|
2004-07-31 03:40:01 +04:00
|
|
|
unsigned int i = STYLESHEET_START;
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data msg_data;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2010-03-28 16:56:39 +04:00
|
|
|
struct html_stylesheet *stylesheets;
|
|
|
|
hlcache_child_context child;
|
|
|
|
nserror ns_error;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
child.charset = c->encoding;
|
|
|
|
child.quirks = c->base.quirks;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2004-07-31 03:40:01 +04:00
|
|
|
/* stylesheet 0 is the base style sheet,
|
2009-07-24 03:05:34 +04:00
|
|
|
* stylesheet 1 is the quirks mode style sheet,
|
|
|
|
* stylesheet 2 is the adblocking stylesheet */
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheets = talloc_array(c, struct html_stylesheet,
|
2005-04-09 13:47:37 +04:00
|
|
|
STYLESHEET_START);
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->stylesheets == NULL)
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheets[STYLESHEET_BASE].type = HTML_STYLESHEET_EXTERNAL;
|
|
|
|
c->stylesheets[STYLESHEET_BASE].data.external = NULL;
|
|
|
|
c->stylesheets[STYLESHEET_QUIRKS].type = HTML_STYLESHEET_EXTERNAL;
|
|
|
|
c->stylesheets[STYLESHEET_QUIRKS].data.external = NULL;
|
|
|
|
c->stylesheets[STYLESHEET_ADBLOCK].type = HTML_STYLESHEET_EXTERNAL;
|
|
|
|
c->stylesheets[STYLESHEET_ADBLOCK].data.external = NULL;
|
|
|
|
c->stylesheet_count = STYLESHEET_START;
|
|
|
|
|
|
|
|
c->base.active = 0;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
ns_error = hlcache_handle_retrieve(default_stylesheet_url, 0,
|
2011-05-07 00:40:09 +04:00
|
|
|
content__get_url(&c->base), NULL,
|
2010-04-04 21:17:24 +04:00
|
|
|
html_convert_css_callback, c, &child, accept,
|
2011-05-07 00:40:09 +04:00
|
|
|
&c->stylesheets[STYLESHEET_BASE].data.external);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (ns_error != NSERROR_OK)
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active++;
|
2004-07-31 03:40:01 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->quirks == BINDING_QUIRKS_MODE_FULL) {
|
2010-03-28 16:56:39 +04:00
|
|
|
ns_error = hlcache_handle_retrieve(quirks_stylesheet_url, 0,
|
2011-05-07 00:40:09 +04:00
|
|
|
content__get_url(&c->base), NULL,
|
2010-04-04 21:17:24 +04:00
|
|
|
html_convert_css_callback, c, &child, accept,
|
2011-05-07 00:40:09 +04:00
|
|
|
&c->stylesheets[STYLESHEET_QUIRKS].
|
|
|
|
data.external);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (ns_error != NSERROR_OK)
|
2009-07-24 03:05:34 +04:00
|
|
|
goto no_memory;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active++;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2004-07-31 03:40:01 +04:00
|
|
|
if (option_block_ads) {
|
2010-03-28 16:56:39 +04:00
|
|
|
ns_error = hlcache_handle_retrieve(adblock_stylesheet_url, 0,
|
2011-05-07 00:40:09 +04:00
|
|
|
content__get_url(&c->base), NULL,
|
2010-04-04 21:17:24 +04:00
|
|
|
html_convert_css_callback, c, &child, accept,
|
2011-05-07 00:40:09 +04:00
|
|
|
&c->stylesheets[STYLESHEET_ADBLOCK].
|
|
|
|
data.external);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (ns_error != NSERROR_OK)
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active++;
|
2004-07-31 03:40:01 +04:00
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
node = html;
|
|
|
|
|
|
|
|
/* depth-first search the tree for link elements */
|
|
|
|
while (node) {
|
|
|
|
if (node->children) { /* 1. children */
|
|
|
|
node = node->children;
|
|
|
|
} else if (node->next) { /* 2. siblings */
|
|
|
|
node = node->next;
|
|
|
|
} else { /* 3. ancestor siblings */
|
|
|
|
while (node && !node->next)
|
|
|
|
node = node->parent;
|
|
|
|
if (!node)
|
|
|
|
break;
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(node);
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
if (node->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
if (strcmp((const char *) node->name, "link") == 0) {
|
|
|
|
/* rel=<space separated list, including 'stylesheet'> */
|
|
|
|
if ((rel = (char *) xmlGetProp(node,
|
|
|
|
(const xmlChar *) "rel")) == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcasestr(rel, "stylesheet") == 0) {
|
|
|
|
xmlFree(rel);
|
|
|
|
continue;
|
|
|
|
} else if (strcasestr(rel, "alternate")) {
|
|
|
|
/* Ignore alternate stylesheets */
|
|
|
|
xmlFree(rel);
|
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(rel);
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
/* type='text/css' or not present */
|
|
|
|
if ((type = (char *) xmlGetProp(node,
|
|
|
|
(const xmlChar *) "type")) != NULL) {
|
|
|
|
if (strcmp(type, "text/css") != 0) {
|
|
|
|
xmlFree(type);
|
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(type);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
/* media contains 'screen' or 'all' or not present */
|
|
|
|
if ((media = (char *) xmlGetProp(node,
|
|
|
|
(const xmlChar *) "media")) != NULL) {
|
2009-07-27 17:49:10 +04:00
|
|
|
if (strcasestr(media, "screen") == NULL &&
|
|
|
|
strcasestr(media, "all") ==
|
|
|
|
NULL) {
|
2008-09-23 14:44:10 +04:00
|
|
|
xmlFree(media);
|
|
|
|
continue;
|
|
|
|
}
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(media);
|
2007-10-02 08:48:30 +04:00
|
|
|
}
|
2003-12-26 03:17:55 +03:00
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
/* href='...' */
|
|
|
|
if ((href = (char *) xmlGetProp(node,
|
|
|
|
(const xmlChar *) "href")) == NULL)
|
|
|
|
continue;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
/* TODO: only the first preferred stylesheets (ie.
|
|
|
|
* those with a title attribute) should be loaded
|
|
|
|
* (see HTML4 14.3) */
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
res = url_join(href, c->base_url, &url);
|
2008-09-23 14:44:10 +04:00
|
|
|
xmlFree(href);
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
continue;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
LOG(("linked stylesheet %i '%s'", i, url));
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2009-02-10 21:35:56 +03:00
|
|
|
res = url_normalize(url, &url2);
|
2009-11-22 16:58:05 +03:00
|
|
|
|
|
|
|
free(url);
|
|
|
|
|
2009-02-10 21:35:56 +03:00
|
|
|
if (res != URL_FUNC_OK) {
|
|
|
|
if (res == URL_FUNC_NOMEM)
|
|
|
|
goto no_memory;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
/* start fetch */
|
2009-07-27 17:49:10 +04:00
|
|
|
stylesheets = talloc_realloc(c,
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheets,
|
2010-03-28 16:56:39 +04:00
|
|
|
struct html_stylesheet, i + 1);
|
2009-07-27 17:49:10 +04:00
|
|
|
if (stylesheets == NULL) {
|
2009-02-10 21:35:56 +03:00
|
|
|
free(url2);
|
2008-09-23 14:44:10 +04:00
|
|
|
goto no_memory;
|
2009-02-10 21:35:56 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheets = stylesheets;
|
|
|
|
c->stylesheet_count++;
|
|
|
|
c->stylesheets[i].type = HTML_STYLESHEET_EXTERNAL;
|
2010-03-28 16:56:39 +04:00
|
|
|
ns_error = hlcache_handle_retrieve(url2, 0,
|
2011-05-07 00:40:09 +04:00
|
|
|
content__get_url(&c->base), NULL,
|
2010-03-28 16:56:39 +04:00
|
|
|
html_convert_css_callback, c, &child,
|
2010-04-04 21:17:24 +04:00
|
|
|
accept,
|
2011-05-07 00:40:09 +04:00
|
|
|
&c->stylesheets[i].data.external);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2009-02-10 21:35:56 +03:00
|
|
|
free(url2);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
if (ns_error != NSERROR_OK)
|
2008-09-23 14:44:10 +04:00
|
|
|
goto no_memory;
|
2009-02-10 21:35:56 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active++;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2008-09-23 14:44:10 +04:00
|
|
|
i++;
|
|
|
|
} else if (strcmp((const char *) node->name, "style") == 0) {
|
2009-07-24 05:48:53 +04:00
|
|
|
if (!html_process_style_element(c, &i, node))
|
2008-09-23 14:44:10 +04:00
|
|
|
return false;
|
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
assert(c->stylesheet_count == i);
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2005-01-02 01:05:21 +03:00
|
|
|
return true;
|
2007-05-06 04:41:12 +04:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
2007-05-06 04:41:12 +04:00
|
|
|
return false;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
/**
|
|
|
|
* Process an inline stylesheet in the document.
|
|
|
|
*
|
|
|
|
* \param c content structure
|
2009-07-24 05:48:53 +04:00
|
|
|
* \param index Index of stylesheet in stylesheet_content array,
|
|
|
|
* updated if successful
|
2007-10-02 08:48:30 +04:00
|
|
|
* \param style xml node of style element
|
|
|
|
* \return true on success, false if an error occurred
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool html_process_style_element(html_content *c, unsigned int *index,
|
2009-07-24 03:05:34 +04:00
|
|
|
xmlNode *style)
|
2007-10-02 08:48:30 +04:00
|
|
|
{
|
|
|
|
xmlNode *child;
|
|
|
|
char *type, *media, *data;
|
|
|
|
union content_msg_data msg_data;
|
2010-03-28 16:56:39 +04:00
|
|
|
struct html_stylesheet *stylesheets;
|
|
|
|
struct content_css_data *sheet;
|
|
|
|
nserror error;
|
2007-10-02 08:48:30 +04:00
|
|
|
|
|
|
|
/* type='text/css', or not present (invalid but common) */
|
|
|
|
if ((type = (char *) xmlGetProp(style, (const xmlChar *) "type"))) {
|
|
|
|
if (strcmp(type, "text/css") != 0) {
|
|
|
|
xmlFree(type);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
xmlFree(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* media contains 'screen' or 'all' or not present */
|
|
|
|
if ((media = (char *) xmlGetProp(style, (const xmlChar *) "media"))) {
|
2009-07-27 17:49:10 +04:00
|
|
|
if (strcasestr(media, "screen") == NULL &&
|
|
|
|
strcasestr(media, "all") == NULL) {
|
2007-10-02 08:48:30 +04:00
|
|
|
xmlFree(media);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
xmlFree(media);
|
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Extend array */
|
2011-05-07 00:40:09 +04:00
|
|
|
stylesheets = talloc_realloc(c, c->stylesheets,
|
2010-03-28 16:56:39 +04:00
|
|
|
struct html_stylesheet, *index + 1);
|
2009-07-27 17:49:10 +04:00
|
|
|
if (stylesheets == NULL)
|
2009-07-24 03:05:34 +04:00
|
|
|
goto no_memory;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheets = stylesheets;
|
|
|
|
c->stylesheet_count++;
|
2009-07-24 03:05:34 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheets[(*index)].type = HTML_STYLESHEET_INTERNAL;
|
|
|
|
c->stylesheets[(*index)].data.internal = NULL;
|
2009-07-27 22:32:55 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/* create stylesheet */
|
|
|
|
sheet = talloc(c, struct content_css_data);
|
|
|
|
if (sheet == NULL) {
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheet_count--;
|
2009-07-24 03:05:34 +04:00
|
|
|
goto no_memory;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2009-07-24 05:48:53 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
error = nscss_create_css_data(sheet,
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base_url, NULL, c->quirks,
|
2011-02-26 03:58:54 +03:00
|
|
|
html_inline_style_done, c);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheet_count--;
|
2009-07-24 03:05:34 +04:00
|
|
|
goto no_memory;
|
2009-07-27 22:32:55 +04:00
|
|
|
}
|
2007-10-02 08:48:30 +04:00
|
|
|
|
|
|
|
/* can't just use xmlNodeGetContent(style), because that won't
|
|
|
|
* give the content of comments which may be used to 'hide'
|
|
|
|
* the content */
|
|
|
|
for (child = style->children; child != 0; child = child->next) {
|
2008-02-25 20:58:00 +03:00
|
|
|
data = (char *) xmlNodeGetContent(child);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (nscss_process_css_data(sheet, data, strlen(data)) ==
|
2009-07-27 22:32:55 +04:00
|
|
|
false) {
|
2007-10-02 08:48:30 +04:00
|
|
|
xmlFree(data);
|
2010-03-28 16:56:39 +04:00
|
|
|
nscss_destroy_css_data(sheet);
|
|
|
|
talloc_free(sheet);
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheet_count--;
|
2007-10-02 08:48:30 +04:00
|
|
|
/** \todo not necessarily caused by
|
|
|
|
* memory exhaustion */
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active++;
|
2010-04-11 14:52:18 +04:00
|
|
|
|
2009-07-27 22:32:55 +04:00
|
|
|
/* Convert the content -- manually, as we want the result */
|
2011-02-26 03:58:54 +03:00
|
|
|
if (nscss_convert_css_data(sheet) != CSS_OK) {
|
2009-07-24 03:05:34 +04:00
|
|
|
/* conversion failed */
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active--;
|
2010-03-28 16:56:39 +04:00
|
|
|
nscss_destroy_css_data(sheet);
|
|
|
|
talloc_free(sheet);
|
|
|
|
sheet = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 05:48:53 +04:00
|
|
|
/* Update index */
|
2011-05-07 00:40:09 +04:00
|
|
|
c->stylesheets[(*index)].data.internal = sheet;
|
2009-07-24 05:48:53 +04:00
|
|
|
(*index)++;
|
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
2007-10-02 08:48:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-11 14:52:18 +04:00
|
|
|
/**
|
|
|
|
* Handle notification of inline style completion
|
|
|
|
*
|
|
|
|
* \param css Inline style object
|
|
|
|
* \param pw Private data
|
|
|
|
*/
|
|
|
|
void html_inline_style_done(struct content_css_data *css, void *pw)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *html = pw;
|
2010-04-11 14:52:18 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (--html->base.active == 0)
|
2010-04-11 14:52:18 +04:00
|
|
|
html_finish_conversion(html);
|
|
|
|
}
|
2007-10-02 08:48:30 +04:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for linked stylesheets.
|
|
|
|
*/
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror html_convert_css_callback(hlcache_handle *css,
|
|
|
|
const hlcache_event *event, void *pw)
|
2004-02-20 03:43:17 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *parent = pw;
|
2010-03-28 16:56:39 +04:00
|
|
|
unsigned int i;
|
|
|
|
struct html_stylesheet *s;
|
|
|
|
|
|
|
|
/* Find sheet */
|
2011-05-07 00:40:09 +04:00
|
|
|
for (i = 0, s = parent->stylesheets;
|
|
|
|
i != parent->stylesheet_count; i++, s++) {
|
2010-03-28 16:56:39 +04:00
|
|
|
if (s->type == HTML_STYLESHEET_EXTERNAL &&
|
|
|
|
s->data.external == css)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
assert(i != parent->stylesheet_count);
|
2004-04-25 03:42:32 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
switch (event->type) {
|
2009-07-27 17:49:10 +04:00
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("got stylesheet '%s'", content_get_url(css)));
|
2011-05-07 00:40:09 +04:00
|
|
|
parent->base.active--;
|
2009-07-27 17:49:10 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
2010-03-28 16:56:39 +04:00
|
|
|
LOG(("stylesheet %s failed: %s",
|
|
|
|
content_get_url(css), event->data.error));
|
|
|
|
hlcache_handle_release(css);
|
|
|
|
s->data.external = NULL;
|
2011-05-07 00:40:09 +04:00
|
|
|
parent->base.active--;
|
|
|
|
content_add_error(&parent->base, "?", 0);
|
2009-07-27 17:49:10 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
2010-03-28 16:56:39 +04:00
|
|
|
html_set_status(parent, content_get_status_message(css));
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&parent->base, CONTENT_MSG_STATUS,
|
|
|
|
event->data);
|
2009-07-27 17:49:10 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
2004-02-20 03:43:17 +03:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (parent->base.active == 0)
|
2010-04-11 14:52:18 +04:00
|
|
|
html_finish_conversion(parent);
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
return NSERROR_OK;
|
2004-02-20 03:43:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-09-29 23:15:54 +04:00
|
|
|
* Queue a fetch for an object required by a page.
|
2004-02-20 03:43:17 +03:00
|
|
|
*
|
2005-10-31 00:23:03 +03:00
|
|
|
* \param c content of type CONTENT_HTML
|
2005-08-21 02:52:20 +04:00
|
|
|
* \param url URL of object to fetch (copied)
|
|
|
|
* \param box box that will contain the object
|
2011-05-07 00:40:09 +04:00
|
|
|
* \param permitted_types bitmap of acceptable types
|
2004-06-10 03:13:55 +04:00
|
|
|
* \param available_width estimate of width of object
|
|
|
|
* \param available_height estimate of height of object
|
2005-08-21 02:52:20 +04:00
|
|
|
* \param background this is a background image
|
2005-01-02 01:05:21 +03:00
|
|
|
* \return true on success, false on memory exhaustion
|
2004-02-20 03:43:17 +03:00
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool html_fetch_object(html_content *c, const char *url, struct box *box,
|
|
|
|
content_type permitted_types,
|
2004-06-10 03:13:55 +04:00
|
|
|
int available_width, int available_height,
|
2006-09-02 19:52:41 +04:00
|
|
|
bool background)
|
2003-04-15 21:53:00 +04:00
|
|
|
{
|
2005-01-02 01:05:21 +03:00
|
|
|
struct content_html_object *object;
|
2009-02-10 21:35:56 +03:00
|
|
|
char *url2;
|
|
|
|
url_func_result res;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-07-21 00:16:01 +04:00
|
|
|
/* If we've already been aborted, don't bother attempting the fetch */
|
|
|
|
if (c->aborted)
|
|
|
|
return true;
|
|
|
|
|
2009-02-10 21:35:56 +03:00
|
|
|
/* Normalize the URL */
|
|
|
|
res = url_normalize(url, &url2);
|
|
|
|
if (res != URL_FUNC_OK) {
|
|
|
|
LOG(("failed to normalize url '%s'", url));
|
|
|
|
return res != URL_FUNC_NOMEM;
|
|
|
|
}
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
object = talloc(c, struct content_html_object);
|
|
|
|
if (object == NULL) {
|
|
|
|
free(url2);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
object->parent = (struct content *) c;
|
2011-03-11 02:08:34 +03:00
|
|
|
object->next = NULL;
|
|
|
|
object->content = NULL;
|
|
|
|
object->box = box;
|
|
|
|
object->permitted_types = permitted_types;
|
|
|
|
object->background = background;
|
2011-09-29 23:15:54 +04:00
|
|
|
object->url = url2;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
|
|
|
/* add to object list */
|
2011-05-07 00:40:09 +04:00
|
|
|
object->next = c->object_list;
|
|
|
|
c->object_list = object;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->num_objects++;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start fetches for objects requested by a page
|
|
|
|
*
|
|
|
|
* \param c Content object
|
|
|
|
* \return true on success, false otherwise
|
|
|
|
*/
|
|
|
|
bool html_fetch_objects(html_content *c)
|
|
|
|
{
|
|
|
|
struct content_html_object *object;
|
|
|
|
hlcache_child_context child;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
child.charset = c->encoding;
|
|
|
|
child.quirks = c->base.quirks;
|
|
|
|
|
|
|
|
for (object = c->object_list; object != NULL; object = object->next) {
|
|
|
|
error = hlcache_handle_retrieve(object->url,
|
|
|
|
HLCACHE_RETRIEVE_SNIFF_TYPE,
|
|
|
|
content__get_url(&c->base), NULL,
|
|
|
|
html_object_callback, object, &child,
|
|
|
|
object->permitted_types, &object->content);
|
|
|
|
if (error == NSERROR_OK)
|
|
|
|
c->base.active++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return c->base.active == c->num_objects;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-31 00:23:03 +03:00
|
|
|
/**
|
|
|
|
* Start a fetch for an object required by a page, replacing an existing object.
|
|
|
|
*
|
2011-03-11 02:08:34 +03:00
|
|
|
* \param object Object to replace
|
2005-10-31 00:23:03 +03:00
|
|
|
* \param url URL of object to fetch (copied)
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
bool html_replace_object(struct content_html_object *object, const char *url)
|
2005-10-31 00:23:03 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c;
|
2010-03-28 16:56:39 +04:00
|
|
|
hlcache_child_context child;
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *page;
|
2009-02-10 21:35:56 +03:00
|
|
|
char *url2;
|
|
|
|
url_func_result res;
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror error;
|
2005-10-31 00:23:03 +03:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
assert(object != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c = (html_content *) object->parent;
|
2005-10-31 00:23:03 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
child.charset = c->encoding;
|
|
|
|
child.quirks = c->base.quirks;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
if (object->content != NULL) {
|
2005-10-31 00:23:03 +03:00
|
|
|
/* remove existing object */
|
2011-03-11 02:08:34 +03:00
|
|
|
if (content_get_status(object->content) != CONTENT_STATUS_DONE)
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active--;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
|
|
|
hlcache_handle_release(object->content);
|
|
|
|
object->content = NULL;
|
|
|
|
|
|
|
|
object->box->object = NULL;
|
2005-10-31 00:23:03 +03:00
|
|
|
}
|
|
|
|
|
2009-02-10 21:35:56 +03:00
|
|
|
res = url_normalize(url, &url2);
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
return res != URL_FUNC_NOMEM;
|
|
|
|
|
2005-10-31 00:23:03 +03:00
|
|
|
/* initialise fetch */
|
2011-09-04 10:28:09 +04:00
|
|
|
error = hlcache_handle_retrieve(url2, HLCACHE_RETRIEVE_SNIFF_TYPE,
|
|
|
|
content__get_url(&c->base), NULL,
|
|
|
|
html_object_callback, object, &child,
|
2011-03-11 02:08:34 +03:00
|
|
|
object->permitted_types,
|
|
|
|
&object->content);
|
2009-02-10 21:35:56 +03:00
|
|
|
|
|
|
|
free(url2);
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
if (error != NSERROR_OK)
|
2005-10-31 00:23:03 +03:00
|
|
|
return false;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
for (page = c; page != NULL; page = page->page) {
|
|
|
|
page->base.active++;
|
|
|
|
page->base.status = CONTENT_STATUS_READY;
|
2005-10-31 00:23:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
2010-04-25 15:35:26 +04:00
|
|
|
* Callback for hlcache_handle_retrieve() for objects.
|
2004-02-20 03:43:17 +03:00
|
|
|
*/
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror html_object_callback(hlcache_handle *object,
|
|
|
|
const hlcache_event *event, void *pw)
|
2003-04-15 21:53:00 +04:00
|
|
|
{
|
2011-03-11 02:08:34 +03:00
|
|
|
struct content_html_object *o = pw;
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) o->parent;
|
2004-04-25 03:42:32 +04:00
|
|
|
int x, y;
|
2010-03-28 16:56:39 +04:00
|
|
|
struct box *box;
|
2004-01-24 20:08:16 +03:00
|
|
|
|
2011-07-19 17:43:48 +04:00
|
|
|
assert(c->base.status == CONTENT_STATUS_READY ||
|
|
|
|
c->base.status == CONTENT_STATUS_DONE);
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
box = o->box;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
switch (event->type) {
|
|
|
|
case CONTENT_MSG_LOADING:
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->bw != NULL)
|
|
|
|
content_open(object,
|
|
|
|
c->bw, &c->base,
|
|
|
|
box,
|
|
|
|
box->object_params);
|
2010-03-28 16:56:39 +04:00
|
|
|
break;
|
2003-10-25 23:20:13 +04:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
if (content_get_type(object) == CONTENT_HTML) {
|
|
|
|
html_object_done(box, object, o->background);
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->base.status == CONTENT_STATUS_READY ||
|
|
|
|
c->base.status == CONTENT_STATUS_DONE)
|
2011-06-24 13:30:33 +04:00
|
|
|
content__reformat(&c->base, false,
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.available_width,
|
|
|
|
c->base.height);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active--;
|
|
|
|
html_object_done(box, object, o->background);
|
2011-04-27 17:50:49 +04:00
|
|
|
|
2011-07-19 17:43:48 +04:00
|
|
|
if (box->flags & REPLACE_DIM) {
|
2011-04-27 17:50:49 +04:00
|
|
|
union content_msg_data data;
|
|
|
|
|
|
|
|
if (!box_visible(box))
|
|
|
|
break;
|
|
|
|
|
|
|
|
box_coords(box, &x, &y);
|
|
|
|
|
|
|
|
data.redraw.x = x + box->padding[LEFT];
|
|
|
|
data.redraw.y = y + box->padding[TOP];
|
|
|
|
data.redraw.width = box->width;
|
|
|
|
data.redraw.height = box->height;
|
|
|
|
data.redraw.full_redraw = true;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_REDRAW, data);
|
2011-04-27 17:50:49 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_ERROR:
|
|
|
|
hlcache_handle_release(object);
|
|
|
|
|
|
|
|
o->content = NULL;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.active--;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_add_error(&c->base, "?", 0);
|
2010-03-28 16:56:39 +04:00
|
|
|
html_set_status(c, event->data.error);
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_STATUS, event->data);
|
2010-03-28 16:56:39 +04:00
|
|
|
html_object_failed(box, c, o->background);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
|
|
|
html_set_status(c, content_get_status_message(object));
|
2011-05-07 00:40:09 +04:00
|
|
|
/* content_broadcast(&c->base, CONTENT_MSG_STATUS, 0); */
|
2010-03-28 16:56:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_REFORMAT:
|
|
|
|
break;
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
case CONTENT_MSG_REDRAW:
|
|
|
|
{
|
|
|
|
union content_msg_data data = event->data;
|
|
|
|
|
|
|
|
if (!box_visible(box))
|
2006-01-25 09:52:38 +03:00
|
|
|
break;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
box_coords(box, &x, &y);
|
|
|
|
|
|
|
|
if (hlcache_handle_get_content(object) ==
|
|
|
|
event->data.redraw.object) {
|
|
|
|
data.redraw.x = data.redraw.x *
|
|
|
|
box->width / content_get_width(object);
|
|
|
|
data.redraw.y = data.redraw.y *
|
|
|
|
box->height /
|
|
|
|
content_get_height(object);
|
|
|
|
data.redraw.width = data.redraw.width *
|
|
|
|
box->width / content_get_width(object);
|
|
|
|
data.redraw.height = data.redraw.height *
|
|
|
|
box->height /
|
|
|
|
content_get_height(object);
|
|
|
|
data.redraw.object_width = box->width;
|
|
|
|
data.redraw.object_height = box->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.redraw.x += x + box->padding[LEFT];
|
|
|
|
data.redraw.y += y + box->padding[TOP];
|
|
|
|
data.redraw.object_x += x + box->padding[LEFT];
|
|
|
|
data.redraw.object_y += y + box->padding[TOP];
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_REDRAW, data);
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_REFRESH:
|
2011-03-11 02:08:34 +03:00
|
|
|
if (content_get_type(object) == CONTENT_HTML) {
|
2010-03-28 16:56:39 +04:00
|
|
|
/* only for HTML objects */
|
|
|
|
schedule(event->data.delay * 100,
|
2011-03-11 02:08:34 +03:00
|
|
|
html_object_refresh, o);
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->base.status == CONTENT_STATUS_READY && c->base.active == 0 &&
|
2010-03-28 16:56:39 +04:00
|
|
|
(event->type == CONTENT_MSG_LOADING ||
|
|
|
|
event->type == CONTENT_MSG_DONE ||
|
|
|
|
event->type == CONTENT_MSG_ERROR)) {
|
2003-06-17 23:24:21 +04:00
|
|
|
/* all objects have arrived */
|
2011-06-24 13:30:33 +04:00
|
|
|
content__reformat(&c->base, false, c->base.available_width,
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.height);
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, "");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_set_done(&c->base);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2008-03-01 02:03:26 +03:00
|
|
|
/* If 1) the configuration option to reflow pages while objects are
|
|
|
|
* fetched is set
|
|
|
|
* 2) an object is newly fetched & converted,
|
2011-04-27 17:50:49 +04:00
|
|
|
* 3) the box's dimensions need to change due to being replaced
|
|
|
|
* 4) the object's parent HTML is ready for reformat,
|
|
|
|
* 5) the time since the previous reformat is more than the
|
2008-03-01 02:03:26 +03:00
|
|
|
* configured minimum time between reformats
|
|
|
|
* then reformat the page to display newly fetched objects */
|
2010-03-28 16:56:39 +04:00
|
|
|
else if (option_incremental_reflow &&
|
|
|
|
event->type == CONTENT_MSG_DONE &&
|
2011-04-27 17:50:49 +04:00
|
|
|
!(box->flags & REPLACE_DIM) &&
|
2011-05-07 00:40:09 +04:00
|
|
|
(c->base.status == CONTENT_STATUS_READY ||
|
|
|
|
c->base.status == CONTENT_STATUS_DONE) &&
|
|
|
|
(wallclock() > c->base.reformat_time)) {
|
2011-06-24 13:30:33 +04:00
|
|
|
content__reformat(&c->base, false, c->base.available_width,
|
2011-05-07 00:40:09 +04:00
|
|
|
c->base.height);
|
2008-03-01 02:03:26 +03:00
|
|
|
}
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
/**
|
|
|
|
* Update a box whose content has completed rendering.
|
|
|
|
*/
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
void html_object_done(struct box *box, hlcache_handle *object,
|
2004-06-13 00:08:47 +04:00
|
|
|
bool background)
|
2004-05-21 18:26:59 +04:00
|
|
|
{
|
|
|
|
struct box *b;
|
|
|
|
|
2004-06-13 00:08:47 +04:00
|
|
|
if (background) {
|
|
|
|
box->background = object;
|
2004-06-25 03:29:31 +04:00
|
|
|
return;
|
2004-06-13 00:08:47 +04:00
|
|
|
}
|
2004-06-25 03:29:31 +04:00
|
|
|
|
2005-10-31 00:23:03 +03:00
|
|
|
box->object = object;
|
2004-05-21 18:26:59 +04:00
|
|
|
|
2011-04-27 17:50:49 +04:00
|
|
|
if (!(box->flags & REPLACE_DIM)) {
|
|
|
|
/* invalidate parent min, max widths */
|
|
|
|
for (b = box; b; b = b->parent)
|
|
|
|
b->max_width = UNKNOWN_MAX_WIDTH;
|
2004-05-21 18:26:59 +04:00
|
|
|
|
2011-04-27 17:50:49 +04:00
|
|
|
/* delete any clones of this box */
|
|
|
|
while (box->next && (box->next->flags & CLONE)) {
|
|
|
|
/* box_free_box(box->next); */
|
|
|
|
box->next = box->next->next;
|
|
|
|
}
|
2004-05-21 18:26:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-14 01:58:28 +04:00
|
|
|
/**
|
|
|
|
* Handle object fetching or loading failure.
|
|
|
|
*
|
|
|
|
* \param box box containing object which failed to load
|
|
|
|
* \param content document of type CONTENT_HTML
|
|
|
|
* \param background the object was the background image for the box
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
void html_object_failed(struct box *box, html_content *content,
|
2005-04-14 01:58:28 +04:00
|
|
|
bool background)
|
|
|
|
{
|
2011-02-25 22:14:38 +03:00
|
|
|
/* Nothing to do */
|
|
|
|
return;
|
2005-04-14 01:58:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-25 09:52:38 +03:00
|
|
|
/**
|
|
|
|
* schedule() callback for object refresh
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_object_refresh(void *p)
|
|
|
|
{
|
2011-03-11 02:08:34 +03:00
|
|
|
struct content_html_object *object = p;
|
2011-02-16 00:49:28 +03:00
|
|
|
const char *refresh_url;
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
assert(content_get_type(object->content) == CONTENT_HTML);
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
refresh_url = content_get_refresh_url(object->content);
|
2008-02-27 21:38:41 +03:00
|
|
|
|
|
|
|
/* Ignore if refresh URL has gone
|
|
|
|
* (may happen if fetch errored) */
|
2011-02-16 00:49:28 +03:00
|
|
|
if (refresh_url == NULL)
|
2008-02-27 21:38:41 +03:00
|
|
|
return;
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
content_invalidate_reuse_data(object->content);
|
2006-01-25 09:52:38 +03:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
if (!html_replace_object(object, refresh_url)) {
|
2006-01-25 09:52:38 +03:00
|
|
|
/** \todo handle memory exhaustion */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-21 03:09:52 +04:00
|
|
|
/**
|
2011-07-20 00:23:59 +04:00
|
|
|
* Stop loading a CONTENT_HTML.
|
2004-06-21 03:09:52 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void html_stop(struct content *c)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *htmlc = (html_content *) c;
|
2011-03-11 02:08:34 +03:00
|
|
|
struct content_html_object *object;
|
2004-06-21 03:09:52 +04:00
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
switch (c->status) {
|
|
|
|
case CONTENT_STATUS_LOADING:
|
|
|
|
/* Still loading; simply flag that we've been aborted
|
|
|
|
* html_convert/html_finish_conversion will do the rest */
|
|
|
|
htmlc->aborted = true;
|
|
|
|
break;
|
|
|
|
case CONTENT_STATUS_READY:
|
|
|
|
for (object = htmlc->object_list; object != NULL;
|
|
|
|
object = object->next) {
|
|
|
|
if (object->content == NULL)
|
|
|
|
continue;
|
2004-06-21 03:09:52 +04:00
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
if (content_get_status(object->content) ==
|
|
|
|
CONTENT_STATUS_DONE)
|
|
|
|
; /* already loaded: do nothing */
|
|
|
|
else if (content_get_status(object->content) ==
|
|
|
|
CONTENT_STATUS_READY)
|
|
|
|
hlcache_handle_abort(object->content);
|
2011-07-20 03:08:55 +04:00
|
|
|
/* Active count will be updated when
|
|
|
|
* html_object_callback receives
|
|
|
|
* CONTENT_MSG_DONE from this object */
|
2011-07-20 00:23:59 +04:00
|
|
|
else {
|
2011-07-20 03:08:55 +04:00
|
|
|
hlcache_handle_abort(object->content);
|
2011-07-20 00:23:59 +04:00
|
|
|
hlcache_handle_release(object->content);
|
|
|
|
object->content = NULL;
|
2011-07-20 03:08:55 +04:00
|
|
|
|
|
|
|
c->active--;
|
2011-07-20 00:23:59 +04:00
|
|
|
}
|
2004-06-21 03:09:52 +04:00
|
|
|
}
|
2011-07-20 03:08:55 +04:00
|
|
|
|
|
|
|
/* If there are no further active fetches and we're still
|
|
|
|
* in the READY state, transition to the DONE state. */
|
|
|
|
if (c->status == CONTENT_STATUS_READY && c->active == 0) {
|
|
|
|
html_set_status(htmlc, "");
|
|
|
|
content_set_done(c);
|
|
|
|
}
|
|
|
|
|
2011-07-20 00:23:59 +04:00
|
|
|
break;
|
|
|
|
case CONTENT_STATUS_DONE:
|
|
|
|
/* Nothing to do */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG(("Unexpected status %d", c->status));
|
|
|
|
assert(0);
|
2004-06-21 03:09:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Reformat a CONTENT_HTML to a new width.
|
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
void html_reformat(struct content *c, int width, int height)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *htmlc = (html_content *) c;
|
2006-09-17 01:33:55 +04:00
|
|
|
struct box *layout;
|
2010-03-30 02:33:21 +04:00
|
|
|
unsigned int time_before, time_taken;
|
|
|
|
|
|
|
|
time_before = wallclock();
|
2006-06-29 23:55:08 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
layout_document(htmlc, width, height);
|
|
|
|
layout = htmlc->layout;
|
2006-09-17 01:33:55 +04:00
|
|
|
|
|
|
|
/* width and height are at least margin box of document */
|
|
|
|
c->width = layout->x + layout->padding[LEFT] + layout->width +
|
2009-07-24 03:05:34 +04:00
|
|
|
layout->padding[RIGHT] + layout->border[RIGHT].width +
|
2006-09-17 01:33:55 +04:00
|
|
|
layout->margin[RIGHT];
|
|
|
|
c->height = layout->y + layout->padding[TOP] + layout->height +
|
2009-07-24 03:05:34 +04:00
|
|
|
layout->padding[BOTTOM] + layout->border[BOTTOM].width +
|
2006-09-17 01:33:55 +04:00
|
|
|
layout->margin[BOTTOM];
|
|
|
|
|
|
|
|
/* if boxes overflow right or bottom edge, expand to contain it */
|
|
|
|
if (c->width < layout->x + layout->descendant_x1)
|
|
|
|
c->width = layout->x + layout->descendant_x1;
|
|
|
|
if (c->height < layout->y + layout->descendant_y1)
|
|
|
|
c->height = layout->y + layout->descendant_y1;
|
2010-03-30 02:33:21 +04:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
selection_reinit(&htmlc->sel, htmlc->layout);
|
|
|
|
|
2010-03-30 02:33:21 +04:00
|
|
|
time_taken = wallclock() - time_before;
|
|
|
|
c->reformat_time = wallclock() +
|
2011-02-14 14:14:40 +03:00
|
|
|
((time_taken * 3 < option_min_reflow_period ?
|
|
|
|
option_min_reflow_period : time_taken * 3));
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
/**
|
|
|
|
* Redraw a box.
|
|
|
|
*
|
2010-11-03 18:44:01 +03:00
|
|
|
* \param h content containing the box, of type CONTENT_HTML
|
2010-06-04 13:35:08 +04:00
|
|
|
* \param box box to redraw
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_redraw_a_box(hlcache_handle *h, struct box *box)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
box_coords(box, &x, &y);
|
|
|
|
|
|
|
|
content_request_redraw(h, x, y,
|
|
|
|
box->padding[LEFT] + box->width + box->padding[RIGHT],
|
|
|
|
box->padding[TOP] + box->height + box->padding[BOTTOM]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-07 21:50:04 +04:00
|
|
|
/**
|
|
|
|
* Redraw a box.
|
|
|
|
*
|
|
|
|
* \param h content containing the box, of type CONTENT_HTML
|
|
|
|
* \param box box to redraw
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html__redraw_a_box(struct content *c, struct box *box)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
box_coords(box, &x, &y);
|
|
|
|
|
|
|
|
content__request_redraw(c, x, y,
|
|
|
|
box->padding[LEFT] + box->width + box->padding[RIGHT],
|
|
|
|
box->padding[TOP] + box->height + box->padding[BOTTOM]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_HTML and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
void html_destroy(struct content *c)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *html = (html_content *) c;
|
2003-04-15 21:53:00 +04:00
|
|
|
unsigned int i;
|
2009-02-20 14:39:25 +03:00
|
|
|
struct form *f, *g;
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
LOG(("content %p", c));
|
|
|
|
|
2009-02-20 14:39:25 +03:00
|
|
|
/* Destroy forms */
|
2010-04-11 21:20:07 +04:00
|
|
|
for (f = html->forms; f != NULL; f = g) {
|
2009-02-20 14:39:25 +03:00
|
|
|
g = f->prev;
|
|
|
|
|
|
|
|
form_free(f);
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
imagemap_destroy(html);
|
2004-03-27 01:16:31 +03:00
|
|
|
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->parser_binding != NULL)
|
|
|
|
binding_destroy_tree(html->parser_binding);
|
2004-02-20 03:43:17 +03:00
|
|
|
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->document != NULL)
|
2011-09-29 23:15:54 +04:00
|
|
|
binding_destroy_document(html->document);
|
2008-09-09 01:55:20 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* Free base target */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->base_target != NULL) {
|
|
|
|
talloc_free(html->base_target);
|
|
|
|
html->base_target = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free frameset */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->frameset != NULL) {
|
|
|
|
html_destroy_frameset(html->frameset);
|
|
|
|
talloc_free(html->frameset);
|
|
|
|
html->frameset = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free iframes */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->iframe != NULL) {
|
|
|
|
html_destroy_iframe(html->iframe);
|
|
|
|
html->iframe = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 03:05:34 +04:00
|
|
|
/* Destroy selection context */
|
2010-04-11 21:20:07 +04:00
|
|
|
if (html->select_ctx != NULL) {
|
|
|
|
css_select_ctx_destroy(html->select_ctx);
|
|
|
|
html->select_ctx = NULL;
|
2009-07-24 03:05:34 +04:00
|
|
|
}
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/* Free stylesheets */
|
2010-04-11 21:20:07 +04:00
|
|
|
for (i = 0; i != html->stylesheet_count; i++) {
|
|
|
|
if (html->stylesheets[i].type == HTML_STYLESHEET_EXTERNAL &&
|
|
|
|
html->stylesheets[i].data.external != NULL) {
|
|
|
|
hlcache_handle_release(
|
|
|
|
html->stylesheets[i].data.external);
|
|
|
|
} else if (html->stylesheets[i].type ==
|
|
|
|
HTML_STYLESHEET_INTERNAL &&
|
|
|
|
html->stylesheets[i].data.internal != NULL) {
|
|
|
|
nscss_destroy_css_data(
|
|
|
|
html->stylesheets[i].data.internal);
|
2004-06-21 19:09:59 +04:00
|
|
|
}
|
2004-02-20 03:43:17 +03:00
|
|
|
}
|
2005-01-17 00:32:10 +03:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/* Free objects */
|
2011-08-20 05:13:51 +04:00
|
|
|
html_destroy_objects(html);
|
|
|
|
}
|
|
|
|
|
|
|
|
void html_destroy_objects(html_content *html)
|
|
|
|
{
|
2011-03-11 02:08:34 +03:00
|
|
|
while (html->object_list != NULL) {
|
|
|
|
struct content_html_object *victim = html->object_list;
|
|
|
|
|
|
|
|
if (victim->content != NULL) {
|
2011-07-20 03:08:55 +04:00
|
|
|
LOG(("object %p", victim->content));
|
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
if (content_get_type(victim->content) == CONTENT_HTML)
|
|
|
|
schedule_remove(html_object_refresh, victim);
|
|
|
|
|
|
|
|
hlcache_handle_release(victim->content);
|
2006-01-25 11:25:38 +03:00
|
|
|
}
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2011-09-29 23:15:54 +04:00
|
|
|
free(victim->url);
|
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
html->object_list = victim->next;
|
|
|
|
talloc_free(victim);
|
2003-07-10 01:33:01 +04:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2004-08-12 02:08:26 +04:00
|
|
|
|
2011-08-20 05:13:51 +04:00
|
|
|
void html_destroy_frameset(struct content_html_frames *frameset)
|
|
|
|
{
|
2006-09-02 19:52:41 +04:00
|
|
|
int i;
|
2006-09-17 01:33:55 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
if (frameset->name) {
|
|
|
|
talloc_free(frameset->name);
|
|
|
|
frameset->name = NULL;
|
|
|
|
}
|
|
|
|
if (frameset->url) {
|
|
|
|
talloc_free(frameset->url);
|
|
|
|
frameset->url = NULL;
|
|
|
|
}
|
|
|
|
if (frameset->children) {
|
|
|
|
for (i = 0; i < (frameset->rows * frameset->cols); i++) {
|
|
|
|
if (frameset->children[i].name) {
|
|
|
|
talloc_free(frameset->children[i].name);
|
|
|
|
frameset->children[i].name = NULL;
|
|
|
|
}
|
|
|
|
if (frameset->children[i].url) {
|
|
|
|
talloc_free(frameset->children[i].url);
|
|
|
|
frameset->children[i].url = NULL;
|
|
|
|
}
|
|
|
|
if (frameset->children[i].children)
|
|
|
|
html_destroy_frameset(&frameset->children[i]);
|
|
|
|
}
|
|
|
|
talloc_free(frameset->children);
|
|
|
|
frameset->children = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-20 05:13:51 +04:00
|
|
|
void html_destroy_iframe(struct content_html_iframe *iframe)
|
|
|
|
{
|
2006-09-02 19:52:41 +04:00
|
|
|
struct content_html_iframe *next;
|
|
|
|
next = iframe;
|
|
|
|
while ((iframe = next) != NULL) {
|
|
|
|
next = iframe->next;
|
|
|
|
if (iframe->name)
|
|
|
|
talloc_free(iframe->name);
|
|
|
|
if (iframe->url)
|
|
|
|
talloc_free(iframe->url);
|
2006-09-17 01:33:55 +04:00
|
|
|
talloc_free(iframe);
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror html_clone(const struct content *old, struct content **newc)
|
2010-04-04 16:41:19 +04:00
|
|
|
{
|
|
|
|
/** \todo Clone HTML specifics */
|
2010-04-10 16:36:21 +04:00
|
|
|
|
|
|
|
/* In the meantime, we should never be called, as HTML contents
|
|
|
|
* cannot be shared and we're not intending to fix printing's
|
|
|
|
* cloning of documents. */
|
|
|
|
assert(0 && "html_clone should never be called");
|
|
|
|
|
2010-04-04 16:41:19 +04:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-12 02:08:26 +04:00
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
/**
|
|
|
|
* Set the content status.
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
void html_set_status(html_content *c, const char *extra)
|
2007-01-13 03:21:15 +03:00
|
|
|
{
|
2011-05-08 23:11:34 +04:00
|
|
|
content_set_status(&c->base, "%s", extra);
|
2007-01-13 03:21:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-12 02:08:26 +04:00
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_HTML being opened.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_open(struct content *c, struct browser_window *bw,
|
2011-03-11 02:13:03 +03:00
|
|
|
struct content *page, struct box *box,
|
2004-08-12 02:08:26 +04:00
|
|
|
struct object_params *params)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *html = (html_content *) c;
|
2011-03-11 02:08:34 +03:00
|
|
|
struct content_html_object *object, *next;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
html->bw = bw;
|
|
|
|
html->page = (html_content *) page;
|
|
|
|
html->box = box;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/* text selection */
|
|
|
|
selection_init(&html->sel, html->layout);
|
2011-07-01 15:16:43 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
for (object = html->object_list; object != NULL; object = next) {
|
2011-03-11 02:08:34 +03:00
|
|
|
next = object->next;
|
|
|
|
|
|
|
|
if (object->content == NULL)
|
2004-08-12 02:08:26 +04:00
|
|
|
continue;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (content_get_type(object->content) == CONTENT_NONE)
|
2004-08-12 02:08:26 +04:00
|
|
|
continue;
|
2011-03-11 02:08:34 +03:00
|
|
|
|
|
|
|
content_open(object->content,
|
2011-03-11 02:13:03 +03:00
|
|
|
bw, c,
|
2011-03-11 02:08:34 +03:00
|
|
|
object->box,
|
|
|
|
object->box->object_params);
|
2004-08-12 02:08:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_HTML being closed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_close(struct content *c)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *html = (html_content *) c;
|
2011-03-11 02:08:34 +03:00
|
|
|
struct content_html_object *object, *next;
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2011-08-24 16:29:30 +04:00
|
|
|
if (html->search != NULL)
|
|
|
|
search_destroy_context(html->search);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
html->bw = NULL;
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
for (object = html->object_list; object != NULL; object = next) {
|
2011-03-11 02:08:34 +03:00
|
|
|
next = object->next;
|
|
|
|
|
|
|
|
if (object->content == NULL)
|
2004-08-12 02:08:26 +04:00
|
|
|
continue;
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (content_get_type(object->content) == CONTENT_NONE)
|
2004-08-12 02:08:26 +04:00
|
|
|
continue;
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
if (content_get_type(object->content) == CONTENT_HTML)
|
|
|
|
schedule_remove(html_object_refresh, object);
|
2011-02-16 00:49:28 +03:00
|
|
|
|
2011-03-11 02:08:34 +03:00
|
|
|
content_close(object->content);
|
2004-08-12 02:08:26 +04:00
|
|
|
}
|
|
|
|
}
|
2007-01-25 02:16:02 +03:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an HTML content's selection context
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct selection *html_get_selection(struct content *c)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
return &html->sel;
|
|
|
|
}
|
|
|
|
|
2011-08-24 16:29:30 +04:00
|
|
|
|
2011-09-06 22:08:18 +04:00
|
|
|
/**
|
|
|
|
* Get access to any content, link URLs and objects (images) currently
|
|
|
|
* at the given (x, y) coordinates.
|
|
|
|
*
|
|
|
|
* \param c html content to look inside
|
|
|
|
* \param x x-coordinate of point of interest
|
|
|
|
* \param y y-coordinate of point of interest
|
|
|
|
* \param data pointer to contextual_content struct. Its fields are updated
|
|
|
|
* with pointers to any relevent content, or set to NULL if none.
|
|
|
|
*/
|
|
|
|
void html_get_contextual_content(struct content *c,
|
|
|
|
int x, int y, struct contextual_content *data)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
struct box *box = html->layout;
|
|
|
|
struct box *next;
|
|
|
|
int box_x = 0, box_y = 0;
|
|
|
|
hlcache_handle *containing_content = NULL;
|
|
|
|
|
|
|
|
while ((next = box_at_point(box, x, y, &box_x, &box_y,
|
|
|
|
&containing_content)) != NULL) {
|
|
|
|
box = next;
|
|
|
|
|
|
|
|
if (box->style && css_computed_visibility(box->style) ==
|
|
|
|
CSS_VISIBILITY_HIDDEN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (box->iframe)
|
|
|
|
browser_window_get_contextual_content(box->iframe,
|
|
|
|
x - box_x, y - box_y, data);
|
|
|
|
|
|
|
|
if (box->object)
|
|
|
|
data->object = box->object;
|
|
|
|
|
|
|
|
if (box->href)
|
|
|
|
data->link_url = box->href;
|
|
|
|
|
|
|
|
if (box->usemap) {
|
|
|
|
const char *target = NULL;
|
|
|
|
data->link_url = imagemap_get(html, box->usemap,
|
|
|
|
box_x, box_y, x, y, &target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 16:29:30 +04:00
|
|
|
/**
|
|
|
|
* Set an HTML content's search context
|
|
|
|
*
|
|
|
|
* \param c content of type html
|
|
|
|
* \param s search context, or NULL if none
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_set_search(struct content *c, struct search_context *s)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
html->search = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an HTML content's search context
|
|
|
|
*
|
|
|
|
* \param c content of type html
|
|
|
|
* \return content's search context, or NULL if none
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct search_context *html_get_search(struct content *c)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
return html->search;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 14:56:34 +04:00
|
|
|
#if ALWAYS_DUMP_FRAMESET
|
2007-01-25 02:16:02 +03:00
|
|
|
/**
|
|
|
|
* Print a frameset tree to stderr.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_dump_frameset(struct content_html_frames *frame,
|
|
|
|
unsigned int depth)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int row, col, index;
|
|
|
|
const char *unit[] = {"px", "%", "*"};
|
|
|
|
const char *scrolling[] = {"auto", "yes", "no"};
|
|
|
|
|
|
|
|
assert(frame);
|
|
|
|
|
|
|
|
fprintf(stderr, "%p ", frame);
|
|
|
|
|
|
|
|
fprintf(stderr, "(%i %i) ", frame->rows, frame->cols);
|
|
|
|
|
|
|
|
fprintf(stderr, "w%g%s ", frame->width.value, unit[frame->width.unit]);
|
|
|
|
fprintf(stderr, "h%g%s ", frame->height.value,unit[frame->height.unit]);
|
|
|
|
fprintf(stderr, "(margin w%i h%i) ",
|
|
|
|
frame->margin_width, frame->margin_height);
|
|
|
|
|
|
|
|
if (frame->name)
|
|
|
|
fprintf(stderr, "'%s' ", frame->name);
|
|
|
|
if (frame->url)
|
|
|
|
fprintf(stderr, "<%s> ", frame->url);
|
|
|
|
|
|
|
|
if (frame->no_resize)
|
|
|
|
fprintf(stderr, "noresize ");
|
|
|
|
fprintf(stderr, "(scrolling %s) ", scrolling[frame->scrolling]);
|
|
|
|
if (frame->border)
|
|
|
|
fprintf(stderr, "border %x ",
|
|
|
|
(unsigned int) frame->border_colour);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
if (frame->children) {
|
|
|
|
for (row = 0; row != frame->rows; row++) {
|
|
|
|
for (col = 0; col != frame->cols; col++) {
|
|
|
|
for (i = 0; i != depth; i++)
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
fprintf(stderr, "(%i %i): ", row, col);
|
|
|
|
index = (row * frame->cols) + col;
|
|
|
|
html_dump_frameset(&frame->children[index],
|
|
|
|
depth + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-10 14:56:34 +04:00
|
|
|
|
|
|
|
#endif
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve HTML document tree
|
|
|
|
*
|
|
|
|
* \param h HTML content to retrieve document tree from
|
|
|
|
* \return Pointer to document tree
|
|
|
|
*/
|
|
|
|
xmlDoc *html_get_document(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->document;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve box tree
|
|
|
|
*
|
|
|
|
* \param h HTML content to retrieve tree from
|
|
|
|
* \return Pointer to box tree
|
|
|
|
*
|
|
|
|
* \todo This API must die, as must all use of the box tree outside render/
|
|
|
|
*/
|
|
|
|
struct box *html_get_box_tree(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->layout;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the charset of an HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve charset from
|
|
|
|
* \return Pointer to charset, or NULL
|
|
|
|
*/
|
|
|
|
const char *html_get_encoding(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->encoding;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
2010-04-07 17:12:27 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the charset of an HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve charset from
|
|
|
|
* \return Pointer to charset, or NULL
|
|
|
|
*/
|
|
|
|
binding_encoding_source html_get_encoding_source(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-04-07 17:12:27 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->encoding_source;
|
2010-04-07 17:12:27 +04:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
|
|
|
* Retrieve framesets used in an HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to inspect
|
|
|
|
* \return Pointer to framesets, or NULL if none
|
|
|
|
*/
|
|
|
|
struct content_html_frames *html_get_frameset(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->frameset;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve iframes used in an HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to inspect
|
|
|
|
* \return Pointer to iframes, or NULL if none
|
|
|
|
*/
|
|
|
|
struct content_html_iframe *html_get_iframe(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->iframe;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve an HTML content's base URL
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve base target from
|
|
|
|
* \return Pointer to URL
|
|
|
|
*/
|
|
|
|
const char *html_get_base_url(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->base_url;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve an HTML content's base target
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve base target from
|
|
|
|
* \return Pointer to target, or NULL if none
|
|
|
|
*/
|
|
|
|
const char *html_get_base_target(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->base_target;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve stylesheets used by HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve stylesheets from
|
|
|
|
* \param n Pointer to location to receive number of sheets
|
|
|
|
* \return Pointer to array of stylesheets
|
|
|
|
*/
|
|
|
|
struct html_stylesheet *html_get_stylesheets(hlcache_handle *h, unsigned int *n)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
assert(n != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
*n = c->stylesheet_count;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->stylesheets;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve objects used by HTML document
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve objects from
|
|
|
|
* \param n Pointer to location to receive number of objects
|
2011-03-11 02:08:34 +03:00
|
|
|
* \return Pointer to list of objects
|
2010-03-28 16:56:39 +04:00
|
|
|
*/
|
|
|
|
struct content_html_object *html_get_objects(hlcache_handle *h, unsigned int *n)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
assert(n != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
*n = c->num_objects;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return c->object_list;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve favicon associated with an HTML document
|
|
|
|
*
|
|
|
|
* \param h HTML document to retrieve favicon from
|
|
|
|
* \return Pointer to favicon, or NULL if none
|
|
|
|
*/
|
|
|
|
hlcache_handle *html_get_favicon(hlcache_handle *h)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
html_content *c = (html_content *) hlcache_handle_get_content(h);
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return NULL;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2010-06-04 13:35:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve layout coordinates of box with given id
|
|
|
|
*
|
|
|
|
* \param h HTML document to search
|
|
|
|
* \param frag_id String containing an element id
|
|
|
|
* \param x Updated to global x coord iff id found
|
|
|
|
* \param y Updated to global y coord iff id found
|
|
|
|
* \return true iff id found
|
|
|
|
*/
|
2010-10-11 10:54:37 +04:00
|
|
|
bool html_get_id_offset(hlcache_handle *h, const char *frag_id, int *x, int *y)
|
2010-06-04 13:35:08 +04:00
|
|
|
{
|
|
|
|
struct box *pos;
|
2010-10-11 10:54:37 +04:00
|
|
|
struct box *layout;
|
2010-06-04 13:35:08 +04:00
|
|
|
|
|
|
|
if (content_get_type(h) != CONTENT_HTML)
|
|
|
|
return false;
|
|
|
|
|
2010-10-11 10:54:37 +04:00
|
|
|
layout = html_get_box_tree(h);
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
if ((pos = box_find_by_id(layout, frag_id)) != 0) {
|
|
|
|
box_coords(pos, x, y);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the type of a content
|
|
|
|
*
|
|
|
|
* \return CONTENT_HTML
|
|
|
|
*/
|
2011-09-03 13:27:42 +04:00
|
|
|
content_type html_content_type(void)
|
2011-05-07 00:40:09 +04:00
|
|
|
{
|
|
|
|
return CONTENT_HTML;
|
|
|
|
}
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
/**
|
|
|
|
* Get the browser window containing an HTML content
|
|
|
|
*
|
|
|
|
* \param c HTML content
|
|
|
|
* \return the browser window
|
|
|
|
*/
|
|
|
|
struct browser_window *html_get_browser_window(struct content *c)
|
|
|
|
{
|
|
|
|
html_content *html = (html_content *) c;
|
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
assert(c->handler == &html_content_handler);
|
|
|
|
|
|
|
|
return html->bw;
|
|
|
|
}
|
|
|
|
|