2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2007-05-06 04:41:12 +04:00
|
|
|
* Copyright 2007 James Bursa <bursa@users.sourceforge.net>
|
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
|
|
|
*/
|
|
|
|
|
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
|
|
|
#define _GNU_SOURCE /* for strndup() */
|
|
|
|
|
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"
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "content/fetchcache.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/font.h"
|
|
|
|
#include "render/html.h"
|
|
|
|
#include "render/imagemap.h"
|
|
|
|
#include "render/layout.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#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
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
static void html_convert_css_callback(content_msg msg, struct content *css,
|
2005-08-21 16:04:18 +04:00
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data);
|
2006-01-25 09:52:38 +03:00
|
|
|
static bool html_meta_refresh(struct content *c, xmlNode *head);
|
2005-01-02 01:05:21 +03:00
|
|
|
static bool html_head(struct content *c, xmlNode *head);
|
2007-10-02 08:48:30 +04:00
|
|
|
static bool html_find_stylesheets(struct content *c, xmlNode *html,
|
|
|
|
xmlNode *head);
|
|
|
|
static bool html_find_inline_stylesheets(struct content *c, xmlNode *html);
|
|
|
|
static bool html_process_style_element(struct content *c, xmlNode *style);
|
2003-06-17 23:24:21 +04:00
|
|
|
static void html_object_callback(content_msg msg, struct content *object,
|
2005-08-21 16:04:18 +04:00
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data);
|
2004-06-09 23:55:06 +04:00
|
|
|
static void html_object_done(struct box *box, struct content *object,
|
2004-06-13 00:08:47 +04:00
|
|
|
bool background);
|
2005-04-14 01:58:28 +04:00
|
|
|
static void html_object_failed(struct box *box, struct content *content,
|
|
|
|
bool background);
|
2004-01-24 20:08:16 +03:00
|
|
|
static bool html_object_type_permitted(const content_type type,
|
|
|
|
const content_type *permitted_types);
|
2006-01-25 09:52:38 +03:00
|
|
|
static void html_object_refresh(void *p);
|
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);
|
2007-01-13 03:21:15 +03:00
|
|
|
static void html_set_status(struct content *c, const char *extra);
|
2007-01-25 02:16:02 +03:00
|
|
|
static void html_dump_frameset(struct content_html_frames *frame,
|
|
|
|
unsigned int depth);
|
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
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool html_create(struct content *c, const char *params[])
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2003-12-27 23:15:23 +03:00
|
|
|
unsigned int i;
|
2004-02-20 03:43:17 +03:00
|
|
|
struct content_html_data *html = &c->data.html;
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2004-02-20 03:43:17 +03:00
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
html->parser_binding = 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
|
|
|
html->document = 0;
|
2005-01-02 01:05:21 +03:00
|
|
|
html->encoding = 0;
|
2005-04-09 13:47:37 +04:00
|
|
|
html->base_url = c->url;
|
2006-09-02 19:52:41 +04:00
|
|
|
html->base_target = NULL;
|
2004-02-20 03:43:17 +03:00
|
|
|
html->layout = 0;
|
|
|
|
html->background_colour = TRANSPARENT;
|
|
|
|
html->stylesheet_count = 0;
|
|
|
|
html->stylesheet_content = 0;
|
|
|
|
html->style = 0;
|
2005-05-22 23:09:43 +04:00
|
|
|
html->working_stylesheet = 0;
|
2004-02-20 03:43:17 +03:00
|
|
|
html->object_count = 0;
|
|
|
|
html->object = 0;
|
2005-04-09 13:47:37 +04:00
|
|
|
html->forms = 0;
|
2004-06-10 03:13:55 +04:00
|
|
|
html->imagemaps = 0;
|
2004-08-12 02:08:26 +04:00
|
|
|
html->bw = 0;
|
2006-09-02 19:52:41 +04:00
|
|
|
html->frameset = 0;
|
|
|
|
html->iframe = 0;
|
2005-10-31 00:23:03 +03:00
|
|
|
html->page = 0;
|
|
|
|
html->index = 0;
|
|
|
|
html->box = 0;
|
First merge of Adam Blokus' GSoC work from his branch 'branches/adamblokus/netsurf'.
Merged revisions 4212-4552,4554-4709,4711-4724 via svnmerge from
svn://svn.netsurf-browser.org/branches/adamblokus/netsurf
........
r4212 | adamblokus | 2008-05-26 19:42:31 +0200 (Mon, 26 May 2008) | 4 lines
Pdf plotting skeleton pinned on Print Preview in GTK.
Just creates a file and draws lines.
........
r4213 | adamblokus | 2008-05-27 00:11:03 +0200 (Tue, 27 May 2008) | 4 lines
Pdf plotter - added drawing some graphic primitives.
Still with limited functionality, but a snapshot of the
currently viewed page can be made and resembles the original.
........
r4214 | adamblokus | 2008-05-27 11:43:31 +0200 (Tue, 27 May 2008) | 2 lines
Corrected encoding name
........
r4215 | adamblokus | 2008-05-27 12:47:26 +0200 (Tue, 27 May 2008) | 3 lines
Colours and polygons added.
........
r4217 | adamblokus | 2008-05-27 21:39:35 +0200 (Tue, 27 May 2008) | 6 lines
Added rectangles, filled boxes and clipping.
Taken into consideration joty's comments.
Added a todo list for this part.
Added some debug stuff and checking boundaries.
........
r4218 | adamblokus | 2008-05-28 12:37:30 +0200 (Wed, 28 May 2008) | 2 lines
Added path ploting (not sure if valid argument order for bezier) and dashed/dotted line styles
........
r4221 | adamblokus | 2008-05-28 22:11:05 +0200 (Wed, 28 May 2008) | 3 lines
Some more options in graphic primitives and normalizing some parameters.
........
r4235 | adamblokus | 2008-05-31 22:54:56 +0200 (Sat, 31 May 2008) | 4 lines
Plotting changed as jmb suggested (is the least invasive one from the possible)
Added dummy bitmap plotting - way of plotting an image is determined by its type.
........
r4251 | adamblokus | 2008-06-03 17:12:15 +0200 (Tue, 03 Jun 2008) | 3 lines
Added plotting jpg and png images - quite a lot to improve in this code, but it seems to work ;)
........
r4263 | adamblokus | 2008-06-05 14:20:32 +0200 (Thu, 05 Jun 2008) | 3 lines
Added hadling images other than png and jpeg - with transparency.
........
r4267 | adamblokus | 2008-06-06 15:36:34 +0200 (Fri, 06 Jun 2008) | 5 lines
Added handling NULL-returns from all mallocs.
Added plot_bitmap_tile handling.
Changed code style a little.
........
r4327 | adamblokus | 2008-06-12 17:46:34 +0200 (Thu, 12 Jun 2008) | 5 lines
Added a first prototype of the paged-output organization.
Still not sure about naming, file locations etc.
Works with the same pdf plotting as before.
........
r4328 | adamblokus | 2008-06-13 13:52:15 +0200 (Fri, 13 Jun 2008) | 4 lines
Added primitive width adjustment and outputing the whole
website in multiple pages.
........
r4336 | joty | 2008-06-15 15:06:57 +0200 (Sun, 15 Jun 2008) | 1 line
Fix RISC OS build failure (change r4235 wasn't complete).
........
r4337 | joty | 2008-06-15 18:15:32 +0200 (Sun, 15 Jun 2008) | 16 lines
This enables "Export PDF" in RISC OS build:
- Docs/Doxyfile(PREDEFINED): Added WITH_PDF_EXPORT
- Makefile.sources(S_PDF): Add to RISC OS target as well.
- utils/config.h: Define WITH_PDF_EXPORT which controls if we want to have
PDF export functionality or not.
- riscos/save_pdf.c,riscos/save_pdf.h(save_as_pdf): Use PDF print API made
by Adam Blokus to write a PDF file under RISC OS.
- riscos/save.c: Call save_as_pdf added.
- riscos/menus.c: Add 'Export->PDF' menu entry.
- riscos/menus.h(menu_action): Added BROWSER_EXPORT_PDF.
- desktop/gui.h(gui_save_type): Added GUI_SAVE_PDF.
- desktop/print.c(print_run): Added return value.
- Makefile(CCACHE): Moved closed to the place where CC is set for the first time.
(LDFLAGS): Centralised adding all non-pkgconfig libraries and added Haru + PNG libs.
........
r4343 | adamblokus | 2008-06-16 01:08:52 +0200 (Mon, 16 Jun 2008) | 3 lines
Added margins and page size adjustment.
........
r4412 | adamblokus | 2008-06-21 20:22:07 +0200 (Sat, 21 Jun 2008) | 4 lines
Added 'fuzzy' margins on page bottom.
Disabled direct png embedding, because it is too unstable in Haru now.
........
r4421 | adamblokus | 2008-06-22 18:52:28 +0200 (Sun, 22 Jun 2008) | 2 lines
Added "Save as.." dialog and Export->PDF menu entry. Print preview still works with default path.
........
r4437 | adamblokus | 2008-06-25 02:44:46 +0200 (Wed, 25 Jun 2008) | 4 lines
Added skeleton of applying loose layout.
Minor code cleaning-up.
........
r4492 | adamblokus | 2008-07-02 09:02:42 +0200 (Wed, 02 Jul 2008) | 5 lines
Implemented the elementar ideas of the loose layout.
Added scaling in the printing routine.
Added some basic demonstrations.
........
r4493 | adamblokus | 2008-07-02 09:05:55 +0200 (Wed, 02 Jul 2008) | 3 lines
Cleaned up the loosing code - commited to much of leftover rubbish code.
........
r4507 | adamblokus | 2008-07-04 14:25:48 +0200 (Fri, 04 Jul 2008) | 4 lines
Added duplicating box tree and current content - window flickering during printing solved.
Minor error checking after new HPDF_Image_AddSMask call.
........
r4515 | adamblokus | 2008-07-06 22:28:16 +0200 (Sun, 06 Jul 2008) | 2 lines
Changes in loosen layout (image resizing).
........
r4517 | adamblokus | 2008-07-06 22:38:23 +0200 (Sun, 06 Jul 2008) | 2 lines
Added pdf font handling and rendering functions with the use of Haru functions.
........
r4555 | adamblokus | 2008-07-10 00:59:05 +0200 (Thu, 10 Jul 2008) | 2 lines
Added a very basic and still buggy GTK print implementation.
........
r4565 | adamblokus | 2008-07-10 14:50:16 +0200 (Thu, 10 Jul 2008) | 2 lines
Added gtk printing one more time - I have forgotten to add the main file.
........
r4566 | adamblokus | 2008-07-10 14:57:02 +0200 (Thu, 10 Jul 2008) | 2 lines
removed error with comment
........
r4569 | adamblokus | 2008-07-10 15:52:55 +0200 (Thu, 10 Jul 2008) | 5 lines
Major style improvements - added a lot of doxygen comments,
followed tlsa's style guide.
Added some more error checking, too.
........
r4575 | adamblokus | 2008-07-10 18:48:26 +0200 (Thu, 10 Jul 2008) | 2 lines
Cleaned up the code.
........
r4687 | adamblokus | 2008-07-17 14:17:19 +0200 (Thu, 17 Jul 2008) | 2 lines
Changed everything according to jmb's review plus some minor bug fixes to gtk_print.
........
r4688 | adamblokus | 2008-07-17 17:16:34 +0200 (Thu, 17 Jul 2008) | 2 lines
Solved the netsurf.glade clash from r4421.
........
r4693 | adamblokus | 2008-07-18 18:11:51 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug with wrong number of pages in gtk printing.
........
r4695 | adamblokus | 2008-07-18 19:59:24 +0200 (Fri, 18 Jul 2008) | 3 lines
- fixed uncommented line from the previous commit
- fixed bug with scale bigger than 1.0 (incorretly clipped page)
........
r4696 | adamblokus | 2008-07-18 23:28:00 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug in gtk_print_font_paint (and nsfont_paint).
........
r4697 | adamblokus | 2008-07-18 23:35:38 +0200 (Fri, 18 Jul 2008) | 2 lines
Bug fix in nsfont_paint.
........
r4711 | adamblokus | 2008-07-19 22:44:15 +0200 (Sat, 19 Jul 2008) | 2 lines
Added gtk_selection files.
........
r4712 | adamblokus | 2008-07-20 11:15:06 +0200 (Sun, 20 Jul 2008) | 2 lines
Addam missing glade files.
........
r4713 | joty | 2008-07-20 17:13:10 +0200 (Sun, 20 Jul 2008) | 1 line
Follow change r4517 for RISC OS and BeOS platforms : Added pdf font handling and rendering functions with the use of Haru functions.
........
r4714 | joty | 2008-07-20 18:19:50 +0200 (Sun, 20 Jul 2008) | 1 line
Declare haru_nsfont iso define an instance for each C source including the font_haru.h header. This fixes breakage of PDF export on RISC OS.
........
r4724 | adamblokus | 2008-07-23 03:30:08 +0200 (Wed, 23 Jul 2008) | 6 lines
Applied changes according to joty's review.
Added checking the dimensions of a plotted image to pdf plotter.
Commented out jpg embedding (it seems to cause some problems
I'll bring it back when I figure out what's wrong) .
Added back some files removed by mistake.
........
svn path=/trunk/netsurf/; revision=4741
2008-07-26 20:01:59 +04:00
|
|
|
html->font_func = &nsfont;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2005-01-02 01:05:21 +03:00
|
|
|
for (i = 0; params[i]; i += 2) {
|
|
|
|
if (strcasecmp(params[i], "charset") == 0) {
|
2005-04-09 13:47:37 +04:00
|
|
|
html->encoding = talloc_strdup(c, params[i + 1]);
|
2005-01-02 01:05:21 +03:00
|
|
|
if (!html->encoding)
|
|
|
|
goto no_memory;
|
|
|
|
html->encoding_source = ENCODING_SOURCE_HEADER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
/* Create the parser binding */
|
|
|
|
html->parser_binding = binding_create_tree(c, html->encoding);
|
|
|
|
if (!html->parser_binding)
|
2005-01-02 01:05:21 +03:00
|
|
|
goto no_memory;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
|
|
|
return true;
|
2005-01-02 01:05:21 +03:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Process data for CONTENT_HTML.
|
|
|
|
*
|
|
|
|
* The data is parsed in chunks of size CHUNK, multitasking in between.
|
|
|
|
*/
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool html_process_data(struct content *c, char *data, unsigned int size)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
|
|
|
unsigned long x;
|
2008-09-23 06:19:50 +04:00
|
|
|
binding_error err;
|
2004-04-17 20:00:16 +04:00
|
|
|
|
2003-02-26 21:22:24 +03:00
|
|
|
for (x = 0; x + CHUNK <= size; x += CHUNK) {
|
2008-08-15 15:17:28 +04:00
|
|
|
LOG(("Parsing %d bytes", CHUNK));
|
2008-09-23 06:19:50 +04:00
|
|
|
err = binding_parse_chunk(c->data.html.parser_binding,
|
2008-08-13 18:11:05 +04:00
|
|
|
(uint8_t *) data + x, CHUNK);
|
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;
|
|
|
|
}
|
2008-09-23 06:19:50 +04:00
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
gui_multitask();
|
|
|
|
}
|
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
|
|
|
|
2008-09-16 02:45:44 +04:00
|
|
|
LOG(("Parsing %lu bytes", (size - x)));
|
2008-09-23 06:19:50 +04:00
|
|
|
err = binding_parse_chunk(c->data.html.parser_binding,
|
2008-08-13 18:11:05 +04:00
|
|
|
(uint8_t *) data + x, (size - x));
|
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;
|
|
|
|
}
|
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-08-15 15:17:28 +04:00
|
|
|
LOG(("Changing encoding"));
|
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
/* Retrieve new encoding */
|
|
|
|
const char *encoding = binding_get_encoding(
|
|
|
|
c->data.html.parser_binding,
|
|
|
|
&c->data.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
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
c->data.html.encoding = strdup(encoding);
|
|
|
|
if (!c->data.html.encoding) {
|
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 */
|
|
|
|
binding_destroy_tree(c->data.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 */
|
|
|
|
c->data.html.parser_binding = binding_create_tree(c,
|
|
|
|
c->data.html.encoding);
|
|
|
|
if (!c->data.html.parser_binding) {
|
|
|
|
union content_msg_data msg_data;
|
2005-01-02 01:05:21 +03:00
|
|
|
|
2008-09-23 06:19:50 +04: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;
|
|
|
|
}
|
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
/* Recurse to reprocess all that data. This is safe because
|
|
|
|
* the encoding is now specified at parser-start which means
|
|
|
|
* it cannot be changed again. */
|
|
|
|
return html_process_data(c, c->source_data, c->source_size);
|
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
|
|
|
|
* - the box tree is laid out
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool html_convert(struct content *c, int width, int height)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
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;
|
2008-03-11 03:14:39 +03:00
|
|
|
unsigned int time_before, time_taken;
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
/* finish parsing */
|
2008-09-23 06:19:50 +04:00
|
|
|
if (c->source_size == 0) {
|
|
|
|
binding_parse_chunk(c->data.html.parser_binding,
|
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
|
|
|
(uint8_t *) empty_document,
|
|
|
|
sizeof empty_document);
|
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
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
binding_parse_completed(c->data.html.parser_binding);
|
|
|
|
c->data.html.document =
|
|
|
|
binding_get_document(c->data.html.parser_binding);
|
2008-09-09 01:55:20 +04:00
|
|
|
/*xmlDebugDumpDocument(stderr, c->data.html.document);*/
|
2008-09-23 06:19:50 +04:00
|
|
|
binding_destroy_tree(c->data.html.parser_binding);
|
|
|
|
c->data.html.parser_binding = NULL;
|
|
|
|
|
2008-09-09 01:55:20 +04:00
|
|
|
if (!c->data.html.document) {
|
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
|
|
|
|
2003-04-11 01:44:45 +04:00
|
|
|
/* locate html and head elements */
|
2008-09-09 01:55:20 +04:00
|
|
|
html = xmlDocGetRootElement(c->data.html.document);
|
2003-04-11 01:44:45 +04:00
|
|
|
if (html == 0 || strcmp((const char *) html->name, "html") != 0) {
|
|
|
|
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;
|
|
|
|
head != 0 && head->type != XML_ELEMENT_NODE;
|
|
|
|
head = head->next)
|
|
|
|
;
|
2005-05-15 21:37:00 +04:00
|
|
|
if (head && strcmp((const char *) head->name, "head") != 0) {
|
2003-04-12 01:06:51 +04:00
|
|
|
head = 0;
|
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
|
|
|
|
2005-01-02 01:05:21 +03:00
|
|
|
if (head) {
|
|
|
|
if (!html_head(c, head)) {
|
|
|
|
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 */
|
|
|
|
if (!html_meta_refresh(c, head))
|
|
|
|
return false;
|
2005-01-02 01:05:21 +03:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2003-04-06 01:38:06 +04:00
|
|
|
/* get stylesheets */
|
2007-10-02 08:48:30 +04:00
|
|
|
if (!html_find_stylesheets(c, html, head))
|
2005-01-02 01:05:21 +03:00
|
|
|
return false;
|
2003-04-04 19:19:32 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* convert xml tree to box tree */
|
2003-02-09 15:58:15 +03:00
|
|
|
LOG(("XML to box"));
|
2004-06-05 19:03:59 +04:00
|
|
|
content_set_status(c, messages_get("Processing"));
|
2004-06-11 00:41:26 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
2004-12-14 01:17:43 +03:00
|
|
|
if (!xml_to_box(html, c)) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2003-03-26 00:51:29 +03:00
|
|
|
/*box_dump(c->data.html.layout->children, 0);*/
|
2007-01-25 02:16:02 +03:00
|
|
|
/*if (c->data.html.frameset)
|
|
|
|
html_dump_frameset(c->data.html.frameset, 0);*/
|
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 */
|
2004-12-08 03:33:25 +03:00
|
|
|
if (!imagemap_extract(html, c)) {
|
|
|
|
LOG(("imagemap extraction failed"));
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-27 01:16:31 +03:00
|
|
|
/*imagemap_dump(c);*/
|
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* layout the box tree */
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, messages_get("Formatting"));
|
2004-06-11 00:41:26 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
2003-02-09 15:58:15 +03:00
|
|
|
LOG(("Layout document"));
|
2008-03-11 03:14:39 +03:00
|
|
|
time_before = wallclock();
|
2006-09-17 01:33:55 +04:00
|
|
|
html_reformat(c, width, height);
|
2008-03-11 03:14:39 +03:00
|
|
|
time_taken = wallclock() - time_before;
|
|
|
|
LOG(("Layout took %dcs", time_taken));
|
|
|
|
c->reformat_time = wallclock() +
|
|
|
|
((time_taken < option_min_reflow_period ?
|
|
|
|
option_min_reflow_period : time_taken * 1.25));
|
|
|
|
LOG(("Scheduling relayout no sooner than %dcs",
|
|
|
|
c->reformat_time - wallclock()));
|
2003-03-26 00:51:29 +03:00
|
|
|
/*box_dump(c->data.html.layout->children, 0);*/
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
if (c->active == 0)
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2007-01-13 03:21:15 +03:00
|
|
|
else
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_READY;
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, "");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool html_head(struct content *c, xmlNode *head)
|
|
|
|
{
|
|
|
|
xmlNode *node;
|
|
|
|
xmlChar *s;
|
|
|
|
|
|
|
|
c->title = 0;
|
|
|
|
|
|
|
|
for (node = head->children; node != 0; node = node->next) {
|
|
|
|
if (node->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LOG(("Node: %s", node->name));
|
2008-03-01 02:03:26 +03:00
|
|
|
if (!c->title && 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;
|
|
|
|
c->title = talloc_strdup(c, title2);
|
|
|
|
free(title2);
|
|
|
|
if (!c->title)
|
|
|
|
return false;
|
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) {
|
|
|
|
c->data.html.base_url =
|
|
|
|
talloc_strdup(c, url);
|
|
|
|
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] */
|
2008-03-01 02:03:26 +03:00
|
|
|
c->data.html.base_target =
|
|
|
|
talloc_strdup(c,
|
2008-02-25 20:58:00 +03:00
|
|
|
(const char *) s);
|
2007-01-13 03:21:15 +03:00
|
|
|
if (!c->data.html.base_target) {
|
|
|
|
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)
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool html_meta_refresh(struct content *c, xmlNode *head)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
} else if (c->refresh) {
|
|
|
|
/* 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-07-30 04:51:26 +04:00
|
|
|
/* content := *LWS 1*DIGIT *LWS [';' *LWS *1url *LWS]
|
|
|
|
* 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]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* *LWS 1*DIGIT */
|
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-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);
|
|
|
|
|
|
|
|
c->refresh = talloc_strdup(c, c->url);
|
|
|
|
if (!c->refresh) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c,
|
|
|
|
CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
content_broadcast(c, CONTENT_MSG_REFRESH, msg_data);
|
|
|
|
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
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
res = url_join(refresh, c->data.html.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");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-07-30 04:51:26 +04:00
|
|
|
c->refresh = talloc_strdup(c, refresh);
|
|
|
|
|
|
|
|
free(refresh);
|
|
|
|
|
|
|
|
if (!c->refresh) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
content_broadcast(c, 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.
|
|
|
|
*
|
|
|
|
* \param c content structure
|
2007-10-02 08:48:30 +04:00
|
|
|
* \param head xml node of html element
|
2004-02-20 03:43:17 +03:00
|
|
|
* \param head xml node of head element, or 0 if none
|
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
|
|
|
*/
|
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
bool html_find_stylesheets(struct content *c, xmlNode *html,
|
|
|
|
xmlNode *head)
|
2003-04-06 01:38:06 +04:00
|
|
|
{
|
2007-10-02 08:48:30 +04:00
|
|
|
xmlNode *node;
|
|
|
|
char *rel, *type, *media, *href, *url;
|
2004-07-31 03:40:01 +04:00
|
|
|
unsigned int i = STYLESHEET_START;
|
2003-06-17 23:24:21 +04:00
|
|
|
unsigned int last_active = 0;
|
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;
|
2005-01-02 01:05:21 +03:00
|
|
|
struct content **stylesheet_content;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2004-07-31 03:40:01 +04:00
|
|
|
/* stylesheet 0 is the base style sheet,
|
|
|
|
* stylesheet 1 is the adblocking stylesheet,
|
|
|
|
* stylesheet 2 is any <style> elements */
|
2005-04-09 13:47:37 +04:00
|
|
|
c->data.html.stylesheet_content = talloc_array(c, struct content *,
|
|
|
|
STYLESHEET_START);
|
2005-01-02 01:05:21 +03:00
|
|
|
if (!c->data.html.stylesheet_content)
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2004-07-31 03:40:01 +04:00
|
|
|
c->data.html.stylesheet_content[STYLESHEET_ADBLOCK] = 0;
|
|
|
|
c->data.html.stylesheet_content[STYLESHEET_STYLE] = 0;
|
|
|
|
c->data.html.stylesheet_count = STYLESHEET_START;
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
c->active = 0;
|
|
|
|
|
2004-07-31 03:40:01 +04:00
|
|
|
c->data.html.stylesheet_content[STYLESHEET_BASE] = fetchcache(
|
2004-10-18 02:13:35 +04:00
|
|
|
default_stylesheet_url,
|
2005-08-21 16:04:18 +04:00
|
|
|
html_convert_css_callback, (intptr_t) c,
|
|
|
|
STYLESHEET_BASE, c->width, c->height,
|
2005-01-03 05:09:20 +03:00
|
|
|
true, 0, 0, false, false);
|
2005-01-02 01:05:21 +03:00
|
|
|
if (!c->data.html.stylesheet_content[STYLESHEET_BASE])
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2004-06-11 03:55:23 +04:00
|
|
|
c->active++;
|
2007-02-03 02:08:13 +03:00
|
|
|
fetchcache_go(c->data.html.stylesheet_content[STYLESHEET_BASE],
|
|
|
|
c->url, html_convert_css_callback, (intptr_t) c,
|
2005-08-21 16:04:18 +04:00
|
|
|
STYLESHEET_BASE, c->width, c->height,
|
2007-02-03 02:08:13 +03:00
|
|
|
0, 0, false, 0);
|
2004-07-31 03:40:01 +04:00
|
|
|
|
|
|
|
if (option_block_ads) {
|
2005-01-02 01:05:21 +03:00
|
|
|
c->data.html.stylesheet_content[STYLESHEET_ADBLOCK] =
|
|
|
|
fetchcache(adblock_stylesheet_url,
|
2005-08-21 16:04:18 +04:00
|
|
|
html_convert_css_callback, (intptr_t) c,
|
|
|
|
STYLESHEET_ADBLOCK, c->width,
|
2005-01-03 05:09:20 +03:00
|
|
|
c->height, true, 0, 0, false, false);
|
2005-01-02 01:05:21 +03:00
|
|
|
if (!c->data.html.stylesheet_content[STYLESHEET_ADBLOCK])
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2005-01-02 01:05:21 +03:00
|
|
|
c->active++;
|
|
|
|
fetchcache_go(c->data.html.
|
|
|
|
stylesheet_content[STYLESHEET_ADBLOCK],
|
2007-02-03 02:08:13 +03:00
|
|
|
c->url, html_convert_css_callback,
|
|
|
|
(intptr_t) c, STYLESHEET_ADBLOCK, c->width,
|
|
|
|
c->height, 0, 0, false, 0);
|
2004-07-31 03:40:01 +04:00
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2005-01-02 01:05:21 +03:00
|
|
|
for (node = head == 0 ? 0 : head->children; node; node = node->next) {
|
2004-02-20 03:43:17 +03:00
|
|
|
if (node->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2008-02-25 20:58:00 +03:00
|
|
|
if (strcmp((const char *) node->name, "link") != 0)
|
2007-10-02 08:48:30 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* 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 */
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(rel);
|
2007-10-02 08:48:30 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
xmlFree(rel);
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
/* type='text/css' or not present */
|
|
|
|
if ((type = (char *) xmlGetProp(node, (const xmlChar *) "type")) != NULL) {
|
|
|
|
if (strcmp(type, "text/css") != 0) {
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(type);
|
2007-10-02 08:48:30 +04:00
|
|
|
continue;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2007-10-02 08:48:30 +04:00
|
|
|
xmlFree(type);
|
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
/* media contains 'screen' or 'all' or not present */
|
|
|
|
if ((media = (char *) xmlGetProp(node, (const xmlChar *) "media")) != NULL) {
|
|
|
|
if (strcasestr(media, "screen") == 0 &&
|
|
|
|
strcasestr(media, "all") == 0) {
|
2003-04-25 12:03:15 +04:00
|
|
|
xmlFree(media);
|
2003-12-26 03:17:55 +03:00
|
|
|
continue;
|
2007-10-02 08:48:30 +04:00
|
|
|
}
|
|
|
|
xmlFree(media);
|
|
|
|
}
|
2003-12-26 03:17:55 +03:00
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
/* href='...' */
|
|
|
|
if ((href = (char *) xmlGetProp(node, (const xmlChar *) "href")) == NULL)
|
|
|
|
continue;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2007-10-02 08:48:30 +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
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
res = url_join(href, c->data.html.base_url, &url);
|
|
|
|
xmlFree(href);
|
|
|
|
if (res != URL_FUNC_OK)
|
|
|
|
continue;
|
2003-04-13 16:50:10 +04:00
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
LOG(("linked stylesheet %i '%s'", i, url));
|
2003-04-15 21:53:00 +04:00
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
/* start fetch */
|
|
|
|
stylesheet_content = talloc_realloc(c,
|
|
|
|
c->data.html.stylesheet_content,
|
|
|
|
struct content *, i + 1);
|
|
|
|
if (!stylesheet_content)
|
|
|
|
goto no_memory;
|
|
|
|
c->data.html.stylesheet_content = stylesheet_content;
|
|
|
|
c->data.html.stylesheet_content[i] = fetchcache(url,
|
|
|
|
html_convert_css_callback,
|
|
|
|
(intptr_t) c, i, c->width, c->height,
|
|
|
|
true, 0, 0, false, false);
|
|
|
|
if (!c->data.html.stylesheet_content[i])
|
|
|
|
goto no_memory;
|
|
|
|
c->active++;
|
|
|
|
fetchcache_go(c->data.html.stylesheet_content[i],
|
|
|
|
c->url,
|
|
|
|
html_convert_css_callback,
|
|
|
|
(intptr_t) c, i, c->width, c->height,
|
|
|
|
0, 0, false, c->url);
|
|
|
|
free(url);
|
|
|
|
i++;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2003-04-06 01:38:06 +04:00
|
|
|
|
2003-04-13 16:50:10 +04:00
|
|
|
c->data.html.stylesheet_count = i;
|
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
if (!html_find_inline_stylesheets(c, html))
|
|
|
|
return false;
|
|
|
|
|
2004-07-31 03:40:01 +04:00
|
|
|
if (c->data.html.stylesheet_content[STYLESHEET_STYLE] != 0) {
|
|
|
|
if (css_convert(c->data.html.stylesheet_content[STYLESHEET_STYLE], c->width,
|
2003-10-17 21:39:29 +04:00
|
|
|
c->height)) {
|
2005-01-02 06:58:21 +03:00
|
|
|
if (!content_add_user(c->data.html.stylesheet_content[STYLESHEET_STYLE],
|
2004-06-11 03:55:23 +04:00
|
|
|
html_convert_css_callback,
|
2005-08-21 16:04:18 +04:00
|
|
|
(intptr_t) c, STYLESHEET_STYLE)) {
|
2005-01-02 06:58:21 +03:00
|
|
|
/* no memory */
|
|
|
|
c->data.html.stylesheet_content[STYLESHEET_STYLE] = 0;
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2005-01-02 06:58:21 +03:00
|
|
|
}
|
2004-06-11 03:55:23 +04:00
|
|
|
} else {
|
2003-10-17 21:39:29 +04:00
|
|
|
/* conversion failed */
|
2004-07-31 03:40:01 +04:00
|
|
|
c->data.html.stylesheet_content[STYLESHEET_STYLE] = 0;
|
2003-10-17 21:39:29 +04:00
|
|
|
}
|
|
|
|
}
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
/* complete the fetches */
|
|
|
|
while (c->active != 0) {
|
2003-06-17 23:24:21 +04:00
|
|
|
if (c->active != last_active) {
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, "");
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
|
2003-06-17 23:24:21 +04:00
|
|
|
last_active = c->active;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
fetch_poll();
|
|
|
|
gui_multitask();
|
|
|
|
}
|
|
|
|
|
2007-05-06 04:41:12 +04:00
|
|
|
/* check that the base stylesheet loaded; layout fails without it */
|
|
|
|
if (!c->data.html.stylesheet_content[STYLESHEET_BASE]) {
|
|
|
|
msg_data.error = "Base stylesheet failed to load";
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2005-01-02 01:05:21 +03:00
|
|
|
|
2007-05-06 04:41:12 +04:00
|
|
|
assert(c->data.html.stylesheet_content[STYLESHEET_BASE]);
|
|
|
|
css_set_origin(c->data.html.stylesheet_content[STYLESHEET_BASE],
|
2005-05-22 03:30:19 +04:00
|
|
|
CSS_ORIGIN_UA);
|
2007-05-06 04:41:12 +04:00
|
|
|
|
|
|
|
/* any of our other stylesheet pointers could be NULL at this point if
|
|
|
|
* the CSS file(s) failed to load/fetch */
|
2005-05-22 03:30:19 +04:00
|
|
|
if (c->data.html.stylesheet_content[STYLESHEET_ADBLOCK])
|
|
|
|
css_set_origin(c->data.html.stylesheet_content[
|
|
|
|
STYLESHEET_ADBLOCK], CSS_ORIGIN_UA);
|
|
|
|
if (c->data.html.stylesheet_content[STYLESHEET_STYLE])
|
|
|
|
css_set_origin(c->data.html.stylesheet_content[
|
|
|
|
STYLESHEET_STYLE], CSS_ORIGIN_AUTHOR);
|
|
|
|
for (i = STYLESHEET_START; i != c->data.html.stylesheet_count; i++)
|
2005-05-22 16:44:44 +04:00
|
|
|
if (c->data.html.stylesheet_content[i])
|
|
|
|
css_set_origin(c->data.html.stylesheet_content[i],
|
|
|
|
CSS_ORIGIN_AUTHOR);
|
2005-05-22 03:30:19 +04:00
|
|
|
|
|
|
|
c->data.html.working_stylesheet = css_make_working_stylesheet(
|
|
|
|
c->data.html.stylesheet_content,
|
|
|
|
c->data.html.stylesheet_count);
|
|
|
|
if (!c->data.html.working_stylesheet)
|
2007-05-06 04:41:12 +04:00
|
|
|
goto no_memory;
|
2005-05-22 03:30:19 +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");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
2003-04-15 21:53:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-02 08:48:30 +04:00
|
|
|
/**
|
|
|
|
* Process inline stylesheets in the document.
|
|
|
|
*
|
|
|
|
* \param c content structure
|
|
|
|
* \param head xml node of html element
|
|
|
|
* \return true on success, false if an error occurred
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool html_find_inline_stylesheets(struct content *c, xmlNode *html)
|
|
|
|
{
|
|
|
|
xmlNode *node = html;
|
|
|
|
|
|
|
|
/* depth-first search the tree for style 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);
|
|
|
|
|
|
|
|
if (node->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
2008-02-25 20:58:00 +03:00
|
|
|
if (strcmp((const char *) node->name, "style") != 0)
|
2007-10-02 08:48:30 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!html_process_style_element(c, node))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process an inline stylesheet in the document.
|
|
|
|
*
|
|
|
|
* \param c content structure
|
|
|
|
* \param style xml node of style element
|
|
|
|
* \return true on success, false if an error occurred
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool html_process_style_element(struct content *c, xmlNode *style)
|
|
|
|
{
|
|
|
|
xmlNode *child;
|
|
|
|
char *type, *media, *data;
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
/* 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"))) {
|
|
|
|
if (strcasestr(media, "screen") == 0 &&
|
|
|
|
strcasestr(media, "all") == 0) {
|
|
|
|
xmlFree(media);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
xmlFree(media);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create stylesheet */
|
|
|
|
if (c->data.html.stylesheet_content[STYLESHEET_STYLE] == 0) {
|
|
|
|
const char *params[] = { 0 };
|
|
|
|
c->data.html.stylesheet_content[STYLESHEET_STYLE] =
|
|
|
|
content_create(c->data.html.base_url);
|
|
|
|
if (!c->data.html.stylesheet_content[STYLESHEET_STYLE])
|
|
|
|
goto no_memory;
|
|
|
|
if (!content_set_type(c->data.html.
|
|
|
|
stylesheet_content[STYLESHEET_STYLE],
|
|
|
|
CONTENT_CSS, "text/css", params))
|
|
|
|
/** \todo not necessarily caused by
|
|
|
|
* memory exhaustion */
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
2007-10-02 08:48:30 +04:00
|
|
|
if (!content_process_data(c->data.html.
|
|
|
|
stylesheet_content[STYLESHEET_STYLE],
|
|
|
|
data, strlen(data))) {
|
|
|
|
xmlFree(data);
|
|
|
|
/** \todo not necessarily caused by
|
|
|
|
* memory exhaustion */
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for linked stylesheets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_convert_css_callback(content_msg msg, struct content *css,
|
2005-08-21 16:04:18 +04:00
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data)
|
2004-02-20 03:43:17 +03:00
|
|
|
{
|
2005-08-21 16:04:18 +04:00
|
|
|
struct content *c = (struct content *) p1;
|
|
|
|
unsigned int i = p2;
|
2004-04-25 03:42:32 +04:00
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
switch (msg) {
|
|
|
|
case CONTENT_MSG_LOADING:
|
|
|
|
/* check that the stylesheet is really CSS */
|
|
|
|
if (css->type != CONTENT_CSS) {
|
|
|
|
c->data.html.stylesheet_content[i] = 0;
|
|
|
|
c->active--;
|
2007-05-06 04:41:12 +04:00
|
|
|
LOG(("%s is not CSS", css->url));
|
2004-06-11 00:41:26 +04:00
|
|
|
content_add_error(c, "NotCSS", 0);
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, messages_get("NotCSS"));
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2005-08-21 16:04:18 +04:00
|
|
|
content_remove_user(css,
|
|
|
|
html_convert_css_callback,
|
|
|
|
(intptr_t) c, i);
|
2007-03-19 03:04:09 +03:00
|
|
|
if (!css->user_list->next) {
|
2005-07-28 02:49:53 +04:00
|
|
|
/* we were the only user and we
|
|
|
|
* don't want this content, so
|
|
|
|
* stop it fetching and mark it
|
|
|
|
* as having an error so it gets
|
|
|
|
* removed from the cache next time
|
|
|
|
* content_clean() gets called */
|
|
|
|
fetch_abort(css->fetch);
|
|
|
|
css->fetch = 0;
|
|
|
|
css->status = CONTENT_STATUS_ERROR;
|
|
|
|
}
|
2004-02-20 03:43:17 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
|
|
|
LOG(("got stylesheet '%s'", css->url));
|
|
|
|
c->active--;
|
|
|
|
break;
|
|
|
|
|
2008-04-19 15:07:42 +04:00
|
|
|
case CONTENT_MSG_LAUNCH:
|
|
|
|
/* Fall through */
|
2004-02-20 03:43:17 +03:00
|
|
|
case CONTENT_MSG_ERROR:
|
2007-05-06 04:41:12 +04:00
|
|
|
LOG(("stylesheet %s failed: %s", css->url, data.error));
|
2007-03-18 20:09:55 +03:00
|
|
|
/* The stylesheet we were fetching may have been
|
|
|
|
* redirected, in that case, the object pointers
|
|
|
|
* will differ, so ensure that the object that's
|
|
|
|
* in error is still in use by us before invalidating
|
|
|
|
* the pointer */
|
|
|
|
if (c->data.html.stylesheet_content[i] == css) {
|
|
|
|
c->data.html.stylesheet_content[i] = 0;
|
|
|
|
c->active--;
|
|
|
|
content_add_error(c, "?", 0);
|
|
|
|
}
|
2004-02-20 03:43:17 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, css->status_message);
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2004-02-20 03:43:17 +03:00
|
|
|
break;
|
|
|
|
|
2004-08-11 23:02:32 +04:00
|
|
|
case CONTENT_MSG_NEWPTR:
|
|
|
|
c->data.html.stylesheet_content[i] = css;
|
|
|
|
break;
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
#ifdef WITH_AUTH
|
|
|
|
case CONTENT_MSG_AUTH:
|
2004-06-13 00:08:47 +04:00
|
|
|
c->data.html.stylesheet_content[i] = 0;
|
2004-02-20 03:43:17 +03:00
|
|
|
c->active--;
|
2004-06-11 00:41:26 +04:00
|
|
|
content_add_error(c, "?", 0);
|
2004-06-13 00:08:47 +04:00
|
|
|
break;
|
2004-02-20 03:43:17 +03:00
|
|
|
#endif
|
|
|
|
|
2006-02-23 18:06:54 +03:00
|
|
|
#ifdef WITH_SSL
|
|
|
|
case CONTENT_MSG_SSL:
|
|
|
|
c->data.html.stylesheet_content[i] = 0;
|
|
|
|
c->active--;
|
|
|
|
content_add_error(c, "?", 0);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start a fetch for an object required by a page.
|
|
|
|
*
|
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
|
2004-06-10 03:13:55 +04:00
|
|
|
* \param permitted_types array of types, terminated by CONTENT_UNKNOWN,
|
2004-06-13 00:08:47 +04:00
|
|
|
* or 0 if all types except OTHER and UNKNOWN acceptable
|
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
|
|
|
*/
|
|
|
|
|
2005-01-02 01:05:21 +03:00
|
|
|
bool html_fetch_object(struct content *c, char *url, struct box *box,
|
2004-05-21 18:26:59 +04:00
|
|
|
const 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
|
|
|
{
|
2003-06-17 23:24:21 +04:00
|
|
|
unsigned int i = c->data.html.object_count;
|
2005-01-02 01:05:21 +03:00
|
|
|
struct content_html_object *object;
|
2005-03-24 16:44:24 +03:00
|
|
|
struct content *c_fetch;
|
2005-04-09 13:47:37 +04:00
|
|
|
|
2005-03-24 16:44:24 +03:00
|
|
|
/* initialise fetch */
|
|
|
|
c_fetch = fetchcache(url, html_object_callback,
|
2005-08-21 16:04:18 +04:00
|
|
|
(intptr_t) c, i, available_width, available_height,
|
2005-03-24 16:44:24 +03:00
|
|
|
true, 0, 0, false, false);
|
|
|
|
if (!c_fetch)
|
|
|
|
return false;
|
2003-06-05 17:17:55 +04:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
/* add to object list */
|
2005-04-09 13:47:37 +04:00
|
|
|
object = talloc_realloc(c, c->data.html.object,
|
|
|
|
struct content_html_object, i + 1);
|
2005-03-24 16:44:24 +03:00
|
|
|
if (!object) {
|
2005-08-21 16:04:18 +04:00
|
|
|
content_remove_user(c_fetch, html_object_callback,
|
|
|
|
(intptr_t) c, i);
|
2005-01-02 01:05:21 +03:00
|
|
|
return false;
|
2005-03-24 16:44:24 +03:00
|
|
|
}
|
2005-01-02 01:05:21 +03:00
|
|
|
c->data.html.object = object;
|
2003-06-17 23:24:21 +04:00
|
|
|
c->data.html.object[i].box = box;
|
2004-01-24 20:08:16 +03:00
|
|
|
c->data.html.object[i].permitted_types = permitted_types;
|
2004-06-10 03:13:55 +04:00
|
|
|
c->data.html.object[i].background = background;
|
2005-03-24 16:44:24 +03:00
|
|
|
c->data.html.object[i].content = c_fetch;
|
2005-01-02 01:05:21 +03:00
|
|
|
c->data.html.object_count++;
|
2005-03-24 16:44:24 +03:00
|
|
|
c->active++;
|
2003-04-15 21:53:00 +04:00
|
|
|
|
|
|
|
/* start fetch */
|
2005-03-24 16:44:24 +03:00
|
|
|
fetchcache_go(c_fetch, c->url,
|
2005-08-21 16:04:18 +04:00
|
|
|
html_object_callback, (intptr_t) c, i,
|
2005-01-25 02:02:37 +03:00
|
|
|
available_width, available_height,
|
2007-02-03 02:08:13 +03:00
|
|
|
0, 0, false, c->url);
|
2005-01-02 01:05:21 +03:00
|
|
|
|
|
|
|
return true;
|
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.
|
|
|
|
*
|
|
|
|
* \param c content of type CONTENT_HTML
|
|
|
|
* \param i index of object to replace in c->data.html.object
|
|
|
|
* \param url URL of object to fetch (copied)
|
|
|
|
* \param post_urlenc url encoded post data, or 0 if none
|
|
|
|
* \param post_multipart multipart post data, or 0 if none
|
|
|
|
* \return true on success, false on memory exhaustion
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool html_replace_object(struct content *c, unsigned int i, char *url,
|
|
|
|
char *post_urlenc,
|
|
|
|
struct form_successful_control *post_multipart)
|
|
|
|
{
|
|
|
|
struct content *c_fetch;
|
|
|
|
struct content *page;
|
|
|
|
|
|
|
|
assert(c->type == CONTENT_HTML);
|
|
|
|
|
|
|
|
if (c->data.html.object[i].content) {
|
|
|
|
/* remove existing object */
|
|
|
|
if (c->data.html.object[i].content->status !=
|
|
|
|
CONTENT_STATUS_DONE)
|
|
|
|
c->active--;
|
|
|
|
content_remove_user(c->data.html.object[i].content,
|
|
|
|
html_object_callback, (intptr_t) c, i);
|
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
c->data.html.object[i].box->object = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialise fetch */
|
|
|
|
c_fetch = fetchcache(url, html_object_callback,
|
|
|
|
(intptr_t) c, i,
|
|
|
|
c->data.html.object[i].box->width,
|
|
|
|
c->data.html.object[i].box->height,
|
|
|
|
false, post_urlenc, post_multipart, false, false);
|
|
|
|
if (!c_fetch)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
c->data.html.object[i].content = c_fetch;
|
|
|
|
|
|
|
|
for (page = c; page; page = page->data.html.page) {
|
|
|
|
assert(page->type == CONTENT_HTML);
|
|
|
|
page->active++;
|
|
|
|
page->status = CONTENT_STATUS_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start fetch */
|
|
|
|
fetchcache_go(c_fetch, c->url,
|
|
|
|
html_object_callback, (intptr_t) c, i,
|
|
|
|
c->data.html.object[i].box->width,
|
|
|
|
c->data.html.object[i].box->height,
|
2007-02-03 02:08:13 +03:00
|
|
|
post_urlenc, post_multipart, false, c->url);
|
2005-10-31 00:23:03 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for objects.
|
|
|
|
*/
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
void html_object_callback(content_msg msg, struct content *object,
|
2005-08-21 16:04:18 +04:00
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data)
|
2003-04-15 21:53:00 +04:00
|
|
|
{
|
2005-08-21 16:04:18 +04:00
|
|
|
struct content *c = (struct content *) p1;
|
|
|
|
unsigned int i = p2;
|
2004-04-25 03:42:32 +04:00
|
|
|
int x, y;
|
2003-04-15 21:53:00 +04:00
|
|
|
struct box *box = c->data.html.object[i].box;
|
2004-01-24 20:08:16 +03:00
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
switch (msg) {
|
2003-06-17 23:24:21 +04:00
|
|
|
case CONTENT_MSG_LOADING:
|
2004-01-24 20:08:16 +03:00
|
|
|
/* check if the type is acceptable for this object */
|
|
|
|
if (html_object_type_permitted(object->type,
|
2004-08-12 02:08:26 +04:00
|
|
|
c->data.html.object[i].permitted_types)) {
|
|
|
|
if (c->data.html.bw)
|
|
|
|
content_open(object,
|
|
|
|
c->data.html.bw, c,
|
2005-10-31 00:23:03 +03:00
|
|
|
i, box,
|
2004-08-12 02:08:26 +04:00
|
|
|
box->object_params);
|
2004-01-24 20:08:16 +03:00
|
|
|
break;
|
2004-08-12 02:08:26 +04:00
|
|
|
}
|
2004-01-24 20:08:16 +03:00
|
|
|
|
|
|
|
/* not acceptable */
|
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
c->active--;
|
2004-06-11 00:41:26 +04:00
|
|
|
content_add_error(c, "?", 0);
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, messages_get("BadObject"));
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS, data);
|
2005-08-21 16:04:18 +04:00
|
|
|
content_remove_user(object, html_object_callback,
|
|
|
|
(intptr_t) c, i);
|
2007-03-19 03:04:09 +03:00
|
|
|
if (!object->user_list->next) {
|
|
|
|
/* we were the only user and we
|
|
|
|
* don't want this content, so
|
|
|
|
* stop it fetching and mark it
|
|
|
|
* as having an error so it gets
|
|
|
|
* removed from the cache next time
|
|
|
|
* content_clean() gets called */
|
|
|
|
fetch_abort(object->fetch);
|
|
|
|
object->fetch = 0;
|
|
|
|
object->status = CONTENT_STATUS_ERROR;
|
|
|
|
}
|
2005-04-14 01:58:28 +04:00
|
|
|
html_object_failed(box, c,
|
|
|
|
c->data.html.object[i].background);
|
2003-06-17 23:24:21 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_READY:
|
2004-05-21 18:26:59 +04:00
|
|
|
if (object->type == CONTENT_HTML) {
|
2004-06-11 03:55:23 +04:00
|
|
|
html_object_done(box, object,
|
|
|
|
c->data.html.object[i].background);
|
|
|
|
if (c->status == CONTENT_STATUS_READY ||
|
|
|
|
c->status ==
|
|
|
|
CONTENT_STATUS_DONE)
|
|
|
|
content_reformat(c,
|
2006-06-29 23:55:08 +04:00
|
|
|
c->available_width,
|
|
|
|
c->height);
|
2004-05-21 18:26:59 +04:00
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_DONE:
|
2005-04-14 01:58:28 +04:00
|
|
|
html_object_done(box, object,
|
|
|
|
c->data.html.object[i].background);
|
2003-04-15 21:53:00 +04:00
|
|
|
c->active--;
|
|
|
|
break;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2008-04-19 15:07:42 +04:00
|
|
|
case CONTENT_MSG_LAUNCH:
|
|
|
|
/* Fall through */
|
2003-06-17 23:24:21 +04:00
|
|
|
case CONTENT_MSG_ERROR:
|
2007-03-18 20:09:55 +03:00
|
|
|
/* The object we were fetching may have been
|
|
|
|
* redirected, in that case, the object pointers
|
|
|
|
* will differ, so ensure that the object that's
|
|
|
|
* in error is still in use by us before invalidating
|
|
|
|
* the pointer */
|
|
|
|
if (c->data.html.object[i].content == object) {
|
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
c->active--;
|
|
|
|
content_add_error(c, "?", 0);
|
|
|
|
html_set_status(c, data.error);
|
|
|
|
content_broadcast(c, CONTENT_MSG_STATUS,
|
|
|
|
data);
|
|
|
|
html_object_failed(box, c,
|
2005-04-14 01:58:28 +04:00
|
|
|
c->data.html.object[i].background);
|
2007-03-18 20:09:55 +03:00
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTENT_MSG_STATUS:
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, object->status_message);
|
2003-10-01 20:12:04 +04:00
|
|
|
/* content_broadcast(c, CONTENT_MSG_STATUS, 0); */
|
2003-04-15 21:53:00 +04:00
|
|
|
break;
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2003-09-11 01:44:11 +04:00
|
|
|
case CONTENT_MSG_REFORMAT:
|
|
|
|
break;
|
|
|
|
|
2004-03-21 15:50:10 +03:00
|
|
|
case CONTENT_MSG_REDRAW:
|
2007-01-01 02:47:17 +03:00
|
|
|
if (!box_visible(box))
|
|
|
|
break;
|
2004-04-25 03:42:32 +04:00
|
|
|
box_coords(box, &x, &y);
|
2004-06-21 03:09:52 +04:00
|
|
|
if (object == data.redraw.object) {
|
2004-04-26 17:47:51 +04:00
|
|
|
data.redraw.x = data.redraw.x *
|
2004-06-21 03:09:52 +04:00
|
|
|
box->width / object->width;
|
2004-04-26 17:47:51 +04:00
|
|
|
data.redraw.y = data.redraw.y *
|
2004-06-21 03:09:52 +04:00
|
|
|
box->height / object->height;
|
2004-04-26 17:47:51 +04:00
|
|
|
data.redraw.width = data.redraw.width *
|
2004-06-21 03:09:52 +04:00
|
|
|
box->width / object->width;
|
2004-04-26 17:47:51 +04:00
|
|
|
data.redraw.height = data.redraw.height *
|
2004-06-21 03:09:52 +04:00
|
|
|
box->height / object->height;
|
2004-04-26 17:47:51 +04:00
|
|
|
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];
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_REDRAW, data);
|
2004-03-21 15:50:10 +03:00
|
|
|
break;
|
|
|
|
|
2004-08-11 23:02:32 +04:00
|
|
|
case CONTENT_MSG_NEWPTR:
|
|
|
|
c->data.html.object[i].content = object;
|
|
|
|
break;
|
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
2003-10-25 23:20:13 +04:00
|
|
|
case CONTENT_MSG_AUTH:
|
2004-06-13 00:08:47 +04:00
|
|
|
c->data.html.object[i].content = 0;
|
2003-10-26 02:51:45 +04:00
|
|
|
c->active--;
|
2004-06-11 00:41:26 +04:00
|
|
|
content_add_error(c, "?", 0);
|
2004-06-13 00:08:47 +04:00
|
|
|
break;
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-10-25 23:20:13 +04:00
|
|
|
|
2006-02-23 18:06:54 +03:00
|
|
|
#ifdef WITH_SSL
|
|
|
|
case CONTENT_MSG_SSL:
|
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
c->active--;
|
|
|
|
content_add_error(c, "?", 0);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2006-01-25 09:52:38 +03:00
|
|
|
case CONTENT_MSG_REFRESH:
|
|
|
|
if (object->type == CONTENT_HTML)
|
|
|
|
/* only for HTML objects */
|
|
|
|
schedule(data.delay * 100,
|
|
|
|
html_object_refresh, object);
|
|
|
|
break;
|
|
|
|
|
2003-04-15 21:53:00 +04:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2003-06-17 23:24:21 +04:00
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
if (c->status == CONTENT_STATUS_READY && c->active == 0 &&
|
|
|
|
(msg == CONTENT_MSG_LOADING ||
|
|
|
|
msg == CONTENT_MSG_DONE ||
|
|
|
|
msg == CONTENT_MSG_ERROR ||
|
|
|
|
msg == CONTENT_MSG_AUTH)) {
|
2003-06-17 23:24:21 +04:00
|
|
|
/* all objects have arrived */
|
2006-06-29 23:55:08 +04:00
|
|
|
content_reformat(c, c->available_width, c->height);
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, "");
|
|
|
|
content_set_done(c);
|
2003-06-17 23:24:21 +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,
|
|
|
|
* 3) the object's parent HTML is ready for reformat,
|
|
|
|
* 4) the time since the previous reformat is more than the
|
|
|
|
* configured minimum time between reformats
|
|
|
|
* then reformat the page to display newly fetched objects */
|
|
|
|
else if (option_incremental_reflow && msg == CONTENT_MSG_DONE &&
|
|
|
|
(c->status == CONTENT_STATUS_READY ||
|
|
|
|
c->status == CONTENT_STATUS_DONE) &&
|
2008-03-11 03:14:39 +03:00
|
|
|
(wallclock() > c->reformat_time)) {
|
|
|
|
unsigned int time_before = wallclock(), time_taken;
|
2008-03-01 02:03:26 +03:00
|
|
|
content_reformat(c, c->available_width, c->height);
|
2008-03-11 03:14:39 +03:00
|
|
|
time_taken = wallclock() - time_before;
|
|
|
|
c->reformat_time = wallclock() +
|
|
|
|
((time_taken < option_min_reflow_period ?
|
|
|
|
option_min_reflow_period : time_taken * 1.25));
|
2008-03-01 02:03:26 +03:00
|
|
|
}
|
2003-06-30 19:56:35 +04:00
|
|
|
if (c->status == CONTENT_STATUS_READY)
|
2007-01-13 03:21:15 +03:00
|
|
|
html_set_status(c, "");
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
/**
|
|
|
|
* Update a box whose content has completed rendering.
|
|
|
|
*/
|
|
|
|
|
2004-06-09 23:55:06 +04:00
|
|
|
void html_object_done(struct box *box, struct content *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
|
|
|
|
|
|
|
/* invalidate parent min, max widths */
|
2005-10-31 00:23:03 +03:00
|
|
|
for (b = box; b; b = b->parent)
|
2004-05-21 18:26:59 +04:00
|
|
|
b->max_width = UNKNOWN_MAX_WIDTH;
|
|
|
|
|
|
|
|
/* delete any clones of this box */
|
|
|
|
while (box->next && box->next->clone) {
|
|
|
|
/* box_free_box(box->next); */
|
|
|
|
box->next = box->next->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* Any fallback content for the object is made visible.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_object_failed(struct box *box, struct content *content,
|
|
|
|
bool background)
|
|
|
|
{
|
|
|
|
struct box *b, *ic;
|
|
|
|
|
|
|
|
if (background)
|
|
|
|
return;
|
|
|
|
if (!box->fallback)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* make fallback boxes into children or siblings, as appropriate */
|
|
|
|
if (box->type != BOX_INLINE) {
|
|
|
|
/* easy case: fallbacks become children */
|
|
|
|
assert(box->type == BOX_BLOCK ||
|
|
|
|
box->type == BOX_TABLE_CELL ||
|
|
|
|
box->type == BOX_INLINE_BLOCK);
|
|
|
|
box->children = box->fallback;
|
|
|
|
box->last = box->children;
|
|
|
|
while (box->last->next)
|
|
|
|
box->last = box->last->next;
|
|
|
|
box->fallback = 0;
|
|
|
|
box_normalise_block(box, content);
|
|
|
|
} else {
|
|
|
|
assert(box->parent->type == BOX_INLINE_CONTAINER);
|
|
|
|
if (box->fallback->type == BOX_INLINE_CONTAINER &&
|
|
|
|
!box->fallback->next) {
|
|
|
|
/* the fallback is a single inline container: splice
|
|
|
|
* it into this inline container */
|
|
|
|
for (b = box->fallback->children; b; b = b->next)
|
|
|
|
b->parent = box->parent;
|
|
|
|
box->fallback->last->next = box->next;
|
|
|
|
if (!box->next)
|
|
|
|
box->parent->last = box->fallback->last;
|
|
|
|
box->next = box->fallback->children;
|
|
|
|
box->next->prev = box;
|
|
|
|
box->fallback = 0;
|
|
|
|
} else {
|
|
|
|
if (box->next) {
|
|
|
|
/* split this inline container into two inline
|
|
|
|
* containers */
|
2005-08-23 02:49:52 +04:00
|
|
|
ic = box_create(0, 0, 0, 0, 0, content);
|
2005-04-14 01:58:28 +04:00
|
|
|
if (!ic) {
|
2007-03-12 01:08:57 +03:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
msg_data.error =
|
|
|
|
messages_get("NoMemory");
|
|
|
|
content_broadcast(content,
|
|
|
|
CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
2005-04-14 01:58:28 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ic->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_insert_sibling(box->parent, ic);
|
|
|
|
ic->children = box->next;
|
|
|
|
ic->last = box->parent->last;
|
|
|
|
ic->children->prev = 0;
|
|
|
|
box->next = 0;
|
|
|
|
box->parent->last = box;
|
|
|
|
for (b = ic->children; b; b = b->next)
|
|
|
|
b->parent = ic;
|
|
|
|
}
|
|
|
|
/* insert the fallback after the parent */
|
|
|
|
for (b = box->fallback; b->next; b = b->next)
|
|
|
|
b->parent = box->parent->parent;
|
|
|
|
b->parent = box->parent->parent;
|
|
|
|
/* [b is the last fallback box] */
|
|
|
|
b->next = box->parent->next;
|
|
|
|
if (b->next)
|
|
|
|
b->next->prev = b;
|
|
|
|
box->parent->next = box->fallback;
|
|
|
|
box->fallback->prev = box->parent;
|
|
|
|
box->fallback = 0;
|
|
|
|
box_normalise_block(box->parent->parent, content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* invalidate parent min, max widths */
|
|
|
|
for (b = box->parent; b; b = b->parent)
|
|
|
|
b->max_width = UNKNOWN_MAX_WIDTH;
|
|
|
|
box->width = UNKNOWN_WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-24 20:08:16 +03:00
|
|
|
/**
|
|
|
|
* Check if a type is in a list.
|
|
|
|
*
|
|
|
|
* \param type the content_type to search for
|
|
|
|
* \param permitted_types array of types, terminated by CONTENT_UNKNOWN,
|
2004-06-13 00:08:47 +04:00
|
|
|
* or 0 if all types except OTHER and UNKNOWN acceptable
|
2004-01-24 20:08:16 +03:00
|
|
|
* \return the type is in the list or acceptable
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool html_object_type_permitted(const content_type type,
|
|
|
|
const content_type *permitted_types)
|
|
|
|
{
|
|
|
|
if (permitted_types) {
|
|
|
|
for (; *permitted_types != CONTENT_UNKNOWN; permitted_types++)
|
|
|
|
if (*permitted_types == type)
|
|
|
|
return true;
|
|
|
|
} else if (type < CONTENT_OTHER) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-25 09:52:38 +03:00
|
|
|
/**
|
|
|
|
* schedule() callback for object refresh
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_object_refresh(void *p)
|
|
|
|
{
|
|
|
|
struct content *c = (struct content *)p;
|
|
|
|
|
2008-02-27 21:38:41 +03:00
|
|
|
assert(c->type == CONTENT_HTML);
|
|
|
|
|
|
|
|
/* Ignore if refresh URL has gone
|
|
|
|
* (may happen if fetch errored) */
|
|
|
|
if (!c->refresh)
|
|
|
|
return;
|
2006-01-25 09:52:38 +03:00
|
|
|
|
|
|
|
c->fresh = false;
|
|
|
|
|
|
|
|
if (!html_replace_object(c->data.html.page, c->data.html.index,
|
|
|
|
c->refresh, 0, 0)) {
|
|
|
|
/** \todo handle memory exhaustion */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-21 03:09:52 +04:00
|
|
|
/**
|
|
|
|
* Stop loading a CONTENT_HTML in state READY.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_stop(struct content *c)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct content *object;
|
|
|
|
|
|
|
|
assert(c->status == CONTENT_STATUS_READY);
|
|
|
|
|
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
|
|
|
object = c->data.html.object[i].content;
|
|
|
|
if (!object)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (object->status == CONTENT_STATUS_DONE)
|
|
|
|
; /* already loaded: do nothing */
|
|
|
|
else if (object->status == CONTENT_STATUS_READY)
|
|
|
|
content_stop(object, html_object_callback,
|
2005-08-21 16:04:18 +04:00
|
|
|
(intptr_t) c, i);
|
2004-06-21 03:09:52 +04:00
|
|
|
else {
|
|
|
|
content_remove_user(c->data.html.object[i].content,
|
2005-08-21 16:04:18 +04:00
|
|
|
html_object_callback, (intptr_t) c, i);
|
2004-06-21 03:09:52 +04:00
|
|
|
c->data.html.object[i].content = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c->status = CONTENT_STATUS_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2006-09-17 01:33:55 +04:00
|
|
|
struct box *layout;
|
2006-06-29 23:55:08 +04:00
|
|
|
|
2006-09-17 01:33:55 +04:00
|
|
|
layout_document(c, width, height);
|
|
|
|
layout = c->data.html.layout;
|
|
|
|
|
|
|
|
/* width and height are at least margin box of document */
|
|
|
|
c->width = layout->x + layout->padding[LEFT] + layout->width +
|
|
|
|
layout->padding[RIGHT] + layout->border[RIGHT] +
|
|
|
|
layout->margin[RIGHT];
|
|
|
|
c->height = layout->y + layout->padding[TOP] + layout->height +
|
|
|
|
layout->padding[BOTTOM] + layout->border[BOTTOM] +
|
|
|
|
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;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2003-04-15 21:53:00 +04:00
|
|
|
unsigned int i;
|
2003-02-09 15:58:15 +03:00
|
|
|
LOG(("content %p", c));
|
|
|
|
|
2004-06-13 00:08:47 +04:00
|
|
|
imagemap_destroy(c);
|
2004-03-27 01:16:31 +03:00
|
|
|
|
2005-06-23 21:22:28 +04:00
|
|
|
if (c->bitmap) {
|
|
|
|
bitmap_destroy(c->bitmap);
|
|
|
|
c->bitmap = NULL;
|
|
|
|
}
|
|
|
|
|
2008-09-23 06:19:50 +04:00
|
|
|
if (c->data.html.parser_binding)
|
|
|
|
binding_destroy_tree(c->data.html.parser_binding);
|
2004-02-20 03:43:17 +03:00
|
|
|
|
2008-09-09 01:55:20 +04:00
|
|
|
if (c->data.html.document)
|
|
|
|
xmlFreeDoc(c->data.html.document);
|
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
/* Free base target */
|
|
|
|
if (c->data.html.base_target) {
|
|
|
|
talloc_free(c->data.html.base_target);
|
2006-09-17 01:33:55 +04:00
|
|
|
c->data.html.base_target = NULL;
|
2006-09-02 19:52:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free frameset */
|
|
|
|
if (c->data.html.frameset) {
|
|
|
|
html_destroy_frameset(c->data.html.frameset);
|
|
|
|
talloc_free(c->data.html.frameset);
|
|
|
|
c->data.html.frameset = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free iframes */
|
|
|
|
if (c->data.html.iframe) {
|
|
|
|
html_destroy_iframe(c->data.html.iframe);
|
|
|
|
c->data.html.iframe = NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-20 03:43:17 +03:00
|
|
|
/* Free stylesheets */
|
|
|
|
if (c->data.html.stylesheet_count) {
|
2004-06-21 19:09:59 +04:00
|
|
|
for (i = 0; i != c->data.html.stylesheet_count; i++) {
|
2004-02-20 03:43:17 +03:00
|
|
|
if (c->data.html.stylesheet_content[i])
|
2004-06-21 19:09:59 +04:00
|
|
|
content_remove_user(c->data.html.
|
|
|
|
stylesheet_content[i],
|
|
|
|
html_convert_css_callback,
|
2005-08-21 16:04:18 +04:00
|
|
|
(intptr_t) c, i);
|
2004-06-21 19:09:59 +04:00
|
|
|
}
|
2004-02-20 03:43:17 +03:00
|
|
|
}
|
2005-01-17 00:32:10 +03:00
|
|
|
|
2005-05-22 03:30:19 +04:00
|
|
|
talloc_free(c->data.html.working_stylesheet);
|
2006-09-17 01:33:55 +04:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
/*if (c->data.html.style)
|
|
|
|
css_free_style(c->data.html.style);*/
|
2004-02-20 03:43:17 +03:00
|
|
|
|
|
|
|
/* Free objects */
|
2003-07-10 01:33:01 +04:00
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
|
|
|
LOG(("object %i %p", i, c->data.html.object[i].content));
|
2006-01-25 11:25:38 +03:00
|
|
|
if (c->data.html.object[i].content) {
|
2003-07-10 01:33:01 +04:00
|
|
|
content_remove_user(c->data.html.object[i].content,
|
2005-08-21 16:04:18 +04:00
|
|
|
html_object_callback, (intptr_t) c, i);
|
2006-01-25 11:25:38 +03:00
|
|
|
if (c->data.html.object[i].content->type == CONTENT_HTML)
|
|
|
|
schedule_remove(html_object_refresh,
|
|
|
|
c->data.html.object[i].content);
|
|
|
|
}
|
2003-07-10 01:33:01 +04:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2004-08-12 02:08:26 +04:00
|
|
|
|
2006-09-02 19:52:41 +04:00
|
|
|
void html_destroy_frameset(struct content_html_frames *frameset) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void html_destroy_iframe(struct content_html_iframe *iframe) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-12 02:08:26 +04:00
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
/**
|
|
|
|
* Set the content status.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_set_status(struct content *c, const char *extra)
|
|
|
|
{
|
|
|
|
unsigned int stylesheets = 0, objects = 0;
|
|
|
|
if (c->data.html.object_count == 0)
|
|
|
|
stylesheets = c->data.html.stylesheet_count - c->active;
|
|
|
|
else {
|
|
|
|
stylesheets = c->data.html.stylesheet_count;
|
|
|
|
objects = c->data.html.object_count - c->active;
|
|
|
|
}
|
|
|
|
content_set_status(c, "%u/%u %s %u/%u %s %s",
|
|
|
|
stylesheets, c->data.html.stylesheet_count,
|
|
|
|
messages_get((c->data.html.stylesheet_count == 1) ?
|
|
|
|
"styl" : "styls"),
|
|
|
|
objects, c->data.html.object_count,
|
|
|
|
messages_get((c->data.html.object_count == 1) ?
|
|
|
|
"obj" : "objs"),
|
|
|
|
extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2005-10-31 00:23:03 +03:00
|
|
|
struct content *page, unsigned int index, struct box *box,
|
2004-08-12 02:08:26 +04:00
|
|
|
struct object_params *params)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
c->data.html.bw = bw;
|
2005-10-31 00:23:03 +03:00
|
|
|
c->data.html.page = page;
|
|
|
|
c->data.html.index = index;
|
|
|
|
c->data.html.box = box;
|
2004-08-12 02:08:26 +04:00
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
|
|
|
if (c->data.html.object[i].content == 0)
|
|
|
|
continue;
|
|
|
|
if (c->data.html.object[i].content->type == CONTENT_UNKNOWN)
|
|
|
|
continue;
|
|
|
|
content_open(c->data.html.object[i].content,
|
2005-10-31 00:23:03 +03:00
|
|
|
bw, c, i,
|
2004-08-12 02:08:26 +04:00
|
|
|
c->data.html.object[i].box,
|
|
|
|
c->data.html.object[i].box->object_params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_HTML being closed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void html_close(struct content *c)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
c->data.html.bw = 0;
|
2006-01-25 11:25:38 +03:00
|
|
|
schedule_remove(html_object_refresh, c);
|
2004-08-12 02:08:26 +04:00
|
|
|
for (i = 0; i != c->data.html.object_count; i++) {
|
|
|
|
if (c->data.html.object[i].content == 0)
|
|
|
|
continue;
|
|
|
|
if (c->data.html.object[i].content->type == CONTENT_UNKNOWN)
|
|
|
|
continue;
|
|
|
|
content_close(c->data.html.object[i].content);
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|