Bug Summary

File:content/handlers/html/html.c
Warning:line 323, column 29
1st function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name html.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/scan-build-netsurf -fcoverage-compilation-dir=/var/lib/jenkins/workspace/scan-build-netsurf -resource-dir /usr/lib/llvm-19/lib/clang/19 -isystem /usr/include/mit-krb5 -I . -I include -I build/Linux-gtk2 -I frontends -I content/handlers -D WITH_JPEG -U WITH_PDF_EXPORT -D LIBICONV_PLUG -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -I /usr/include/x86_64-linux-gnu -I /usr/include/p11-kit-1 -D WITH_CURL -D WITH_OPENSSL -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D UTF8PROC_EXPORTS -D WITH_UTF8PROC -I /usr/include/webp -D WITH_WEBP -I /usr/include/libpng16 -D WITH_PNG -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include/ -D WITH_BMP -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_GIF -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_NS_SVG -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_NSSPRITE -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_NSPSL -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_NSLOG -D NETSURF_UA_FORMAT_STRING="Mozilla/5.0 (%s) NetSurf/%d.%d" -D NETSURF_HOMEPAGE="about:welcome" -D NETSURF_LOG_LEVEL=VERBOSE -D NETSURF_BUILTIN_LOG_FILTER="(level:WARNING || cat:jserrors)" -D NETSURF_BUILTIN_VERBOSE_FILTER="(level:VERBOSE || cat:jserrors)" -D STMTEXPR=1 -I /usr/include/librsvg-2.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/libpng16 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/cairo -I /usr/include/freetype2 -I /usr/include/pixman-1 -I /usr/include/harfbuzz -I /usr/include/libxml2 -I /usr/include/pango-1.0 -I /usr/include/fribidi -D WITH_RSVG -I /usr/include/gtk-2.0 -I /usr/lib/x86_64-linux-gnu/gtk-2.0/include -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/atk-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -D gtk -D nsgtk -D G_DISABLE_SINGLE_INCLUDES -D G_DISABLE_DEPRECATED -D GTK_DISABLE_SINGLE_INCLUDES -D GTK_MULTIHEAD_SAFE -D PANGO_DISABLE_DEPRECATED -D GTK_DISABLE_DEPRECATED -D _XOPEN_SOURCE=700 -D _POSIX_C_SOURCE=200809L -D _BSD_SOURCE -D _DEFAULT_SOURCE -D _NETBSD_SOURCE -D GTK_RESPATH="/var/lib/jenkins/artifacts-x86_64-linux-gnu/share/netsurf/:./frontends/gtk/res/" -D WITH_GRESOURCE -D DUK_OPT_HAVE_CUSTOM_H -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wwrite-strings -Wno-unused-parameter -Wno-unused-but-set-variable -std=c99 -fconst-strings -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -vectorize-loops -vectorize-slp -analyzer-display-progress -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/lib/jenkins/workspace/scan-build-netsurf/clangScanBuildReports/2025-11-30-114731-3042003-1 -x c content/handlers/html/html.c
1/*
2 * Copyright 2007 James Bursa <bursa@users.sourceforge.net>
3 * Copyright 2010 Michael Drake <tlsa@netsurf-browser.org>
4 *
5 * This file is part of NetSurf, http://www.netsurf-browser.org/
6 *
7 * NetSurf is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * NetSurf is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/**
21 * \file
22 * Implementation of HTML content handling.
23 */
24
25#include <assert.h>
26#include <stdint.h>
27#include <string.h>
28#include <strings.h>
29#include <stdlib.h>
30#include <nsutils/time.h>
31
32#include "utils/utils.h"
33#include "utils/config.h"
34#include "utils/corestrings.h"
35#include "utils/http.h"
36#include "utils/libdom.h"
37#include "utils/log.h"
38#include "utils/messages.h"
39#include "utils/talloc.h"
40#include "utils/utf8.h"
41#include "utils/nsoption.h"
42#include "utils/string.h"
43#include "utils/ascii.h"
44#include "netsurf/content.h"
45#include "netsurf/browser_window.h"
46#include "netsurf/utf8.h"
47#include "netsurf/keypress.h"
48#include "netsurf/layout.h"
49#include "netsurf/misc.h"
50#include "content/hlcache.h"
51#include "content/content_factory.h"
52#include "content/textsearch.h"
53#include "desktop/selection.h"
54#include "desktop/scrollbar.h"
55#include "desktop/textarea.h"
56#include "netsurf/bitmap.h"
57#include "javascript/js.h"
58#include "desktop/gui_internal.h"
59
60#include "html/html.h"
61#include "html/private.h"
62#include "html/dom_event.h"
63#include "html/css.h"
64#include "html/object.h"
65#include "html/html_save.h"
66#include "html/interaction.h"
67#include "html/box.h"
68#include "html/box_construct.h"
69#include "html/box_inspect.h"
70#include "html/form_internal.h"
71#include "html/imagemap.h"
72#include "html/layout.h"
73#include "html/textselection.h"
74
75#define CHUNK4096 4096
76
77/* Change these to 1 to cause a dump to stderr of the frameset or box
78 * when the trees have been built.
79 */
80#define ALWAYS_DUMP_FRAMESET0 0
81#define ALWAYS_DUMP_BOX0 0
82
83static const char *html_types[] = {
84 "application/xhtml+xml",
85 "text/html"
86};
87
88/**
89 * Fire an event at the DOM
90 *
91 * Helper that swallows DOM errors.
92 *
93 * \param[in] event the event to fire at the DOM
94 * \param[in] target the event target
95 * \return true on success
96 */
97static bool_Bool fire_dom_event(dom_event *event, dom_node *target)
98{
99 dom_exception exc;
100 bool_Bool result;
101
102 exc = dom_event_target_dispatch_event(target, event, &result)dom_event_target_dispatch_event((dom_event_target *) (target)
, (struct dom_event *) (event), (_Bool *) (&result))
;
103 if (exc != DOM_NO_ERR) {
104 return false0;
105 }
106
107 return result;
108}
109
110/* Exported interface, see html_internal.h */
111bool_Bool fire_generic_dom_event(dom_string *type, dom_node *target,
112 bool_Bool bubbles, bool_Bool cancelable)
113{
114 dom_exception exc;
115 dom_event *evt;
116 bool_Bool result;
117
118 exc = dom_event_create(&evt)_dom_event_create((dom_event **) (&evt));
119 if (exc != DOM_NO_ERR) return false0;
120 exc = dom_event_init(evt, type, bubbles, cancelable)_dom_event_init((dom_event *) (evt), (dom_string *) (type), (
_Bool) (bubbles), (_Bool) (cancelable))
;
121 if (exc != DOM_NO_ERR) {
122 dom_event_unref(evt)_dom_event_unref((dom_event *) (evt));
123 return false0;
124 }
125 NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 126
, }; nslog__log(&_nslog_ctx, "Dispatching '%*s' against %p"
, (int)dom_string_length(type), dom_string_data(type), target
); } } while(0)
126 (int)dom_string_length(type), dom_string_data(type), target)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 126
, }; nslog__log(&_nslog_ctx, "Dispatching '%*s' against %p"
, (int)dom_string_length(type), dom_string_data(type), target
); } } while(0)
;
127 result = fire_dom_event(evt, target);
128 dom_event_unref(evt)_dom_event_unref((dom_event *) (evt));
129 return result;
130}
131
132/* Exported interface, see html_internal.h */
133bool_Bool fire_dom_keyboard_event(dom_string *type, dom_node *target,
134 bool_Bool bubbles, bool_Bool cancelable, uint32_t key)
135{
136 bool_Bool is_special = key <= 0x001F || (0x007F <= key && key <= 0x009F);
137 dom_string *dom_key = NULL((void*)0);
138 dom_keyboard_event *evt;
139 dom_exception exc;
140 bool_Bool result;
141
142 if (is_special) {
143 switch (key) {
144 case NS_KEY_ESCAPE:
145 dom_key = dom_string_ref(corestring_dom_Escape);
146 break;
147 case NS_KEY_LEFT:
148 dom_key = dom_string_ref(corestring_dom_ArrowLeft);
149 break;
150 case NS_KEY_RIGHT:
151 dom_key = dom_string_ref(corestring_dom_ArrowRight);
152 break;
153 case NS_KEY_UP:
154 dom_key = dom_string_ref(corestring_dom_ArrowUp);
155 break;
156 case NS_KEY_DOWN:
157 dom_key = dom_string_ref(corestring_dom_ArrowDown);
158 break;
159 case NS_KEY_PAGE_UP:
160 dom_key = dom_string_ref(corestring_dom_PageUp);
161 break;
162 case NS_KEY_PAGE_DOWN:
163 dom_key = dom_string_ref(corestring_dom_PageDown);
164 break;
165 case NS_KEY_TEXT_START:
166 dom_key = dom_string_ref(corestring_dom_Home);
167 break;
168 case NS_KEY_TEXT_END:
169 dom_key = dom_string_ref(corestring_dom_End);
170 break;
171 default:
172 dom_key = NULL((void*)0);
173 break;
174 }
175 } else {
176 char utf8[6];
177 size_t length = utf8_from_ucs4(key, utf8);
178 utf8[length] = '\0';
179
180 exc = dom_string_create((const uint8_t *)utf8, strlen(utf8),
181 &dom_key);
182 if (exc != DOM_NO_ERR) {
183 return exc;
184 }
185 }
186
187 exc = dom_keyboard_event_create(&evt)_dom_keyboard_event_create((dom_keyboard_event **) (&evt)
)
;
188 if (exc != DOM_NO_ERR) {
189 dom_string_unref(dom_key);
190 return false0;
191 }
192
193 exc = dom_keyboard_event_init(evt, type, bubbles, cancelable, NULL,_dom_keyboard_event_init((dom_keyboard_event *) (evt), (dom_string
*) (type), (_Bool) (bubbles), (_Bool) (cancelable), (struct dom_abstract_view
*) (((void*)0)), (dom_string *) (dom_key), (dom_string *) ((
(void*)0)), (dom_key_location) (DOM_KEY_LOCATION_STANDARD), (
_Bool) (0), (_Bool) (0), (_Bool) (0), (_Bool) (0), (_Bool) (0
), (_Bool) (0))
194 dom_key, NULL, DOM_KEY_LOCATION_STANDARD, false,_dom_keyboard_event_init((dom_keyboard_event *) (evt), (dom_string
*) (type), (_Bool) (bubbles), (_Bool) (cancelable), (struct dom_abstract_view
*) (((void*)0)), (dom_string *) (dom_key), (dom_string *) ((
(void*)0)), (dom_key_location) (DOM_KEY_LOCATION_STANDARD), (
_Bool) (0), (_Bool) (0), (_Bool) (0), (_Bool) (0), (_Bool) (0
), (_Bool) (0))
195 false, false, false, false, false)_dom_keyboard_event_init((dom_keyboard_event *) (evt), (dom_string
*) (type), (_Bool) (bubbles), (_Bool) (cancelable), (struct dom_abstract_view
*) (((void*)0)), (dom_string *) (dom_key), (dom_string *) ((
(void*)0)), (dom_key_location) (DOM_KEY_LOCATION_STANDARD), (
_Bool) (0), (_Bool) (0), (_Bool) (0), (_Bool) (0), (_Bool) (0
), (_Bool) (0))
;
196 dom_string_unref(dom_key);
197 if (exc != DOM_NO_ERR) {
198 dom_event_unref(evt)_dom_event_unref((dom_event *) (evt));
199 return false0;
200 }
201
202 NSLOG(netsurf, INFO, "Dispatching '%*s' against %p",do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 203
, }; nslog__log(&_nslog_ctx, "Dispatching '%*s' against %p"
, (int)dom_string_length(type), dom_string_data(type), target
); } } while(0)
203 (int)dom_string_length(type), dom_string_data(type), target)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 203
, }; nslog__log(&_nslog_ctx, "Dispatching '%*s' against %p"
, (int)dom_string_length(type), dom_string_data(type), target
); } } while(0)
;
204
205 result = fire_dom_event((dom_event *) evt, target);
206 dom_event_unref(evt)_dom_event_unref((dom_event *) (evt));
207 return result;
208}
209
210/**
211 * Perform post-box-creation conversion of a document
212 *
213 * \param c HTML content to complete conversion of
214 * \param success Whether box tree construction was successful
215 */
216static void html_box_convert_done(html_content *c, bool_Bool success)
217{
218 nserror err;
219 dom_exception exc; /* returned by libdom functions */
220 dom_node *html;
221
222 NSLOG(netsurf, INFO, "DOM to box conversion complete (content %p)", c)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 222
, }; nslog__log(&_nslog_ctx, "DOM to box conversion complete (content %p)"
, c); } } while(0)
;
223
224 c->box_conversion_context = NULL((void*)0);
225
226 /* Clean up and report error if unsuccessful or aborted */
227 if ((success == false0) || (c->aborted)) {
228 html_object_free_objects(c);
229
230 if (success == false0) {
231 content_broadcast_error(&c->base, NSERROR_BOX_CONVERT, NULL((void*)0));
232 } else {
233 content_broadcast_error(&c->base, NSERROR_STOPPED, NULL((void*)0));
234 }
235
236 content_set_error(&c->base);
237 return;
238 }
239
240
241#if ALWAYS_DUMP_BOX0
242 box_dump(stderrstderr, c->layout->children, 0, true1);
243#endif
244#if ALWAYS_DUMP_FRAMESET0
245 if (c->frameset)
246 html_dump_frameset(c->frameset, 0);
247#endif
248
249 exc = dom_document_get_document_element(c->document, (void *) &html)dom_document_get_document_element((dom_document *) (c->document
), (struct dom_element **) ((void *) &html))
;
250 if ((exc != DOM_NO_ERR) || (html == NULL((void*)0))) {
251 /** @todo should this call html_object_free_objects(c);
252 * like the other error paths
253 */
254 NSLOG(netsurf, INFO, "error retrieving html element from dom")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 254
, }; nslog__log(&_nslog_ctx, "error retrieving html element from dom"
); } } while(0)
;
255 content_broadcast_error(&c->base, NSERROR_DOM, NULL((void*)0));
256 content_set_error(&c->base);
257 return;
258 }
259
260 /* extract image maps - can't do this sensibly in dom_to_box */
261 err = imagemap_extract(c);
262 if (err != NSERROR_OK) {
263 NSLOG(netsurf, INFO, "imagemap extraction failed")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 263
, }; nslog__log(&_nslog_ctx, "imagemap extraction failed"
); } } while(0)
;
264 html_object_free_objects(c);
265 content_broadcast_error(&c->base, err, NULL((void*)0));
266 content_set_error(&c->base);
267 dom_node_unref(html)dom_node_unref((dom_node *) (html));
268 return;
269 }
270 /*imagemap_dump(c);*/
271
272 /* Destroy the parser binding */
273 dom_hubbub_parser_destroy(c->parser);
274 c->parser = NULL((void*)0);
275
276 content_set_ready(&c->base);
277
278 html_proceed_to_done(c);
279
280 dom_node_unref(html)dom_node_unref((dom_node *) (html));
281}
282
283/* Documented in html_internal.h */
284nserror
285html_proceed_to_done(html_content *html)
286{
287 switch (content__get_status(&html->base)) {
288 case CONTENT_STATUS_READY:
289 if (html->base.active == 0) {
290 content_set_done(&html->base);
291 return NSERROR_OK;
292 }
293 break;
294 case CONTENT_STATUS_DONE:
295 /* fallthrough */
296 case CONTENT_STATUS_LOADING:
297 return NSERROR_OK;
298 default:
299 NSLOG(netsurf, ERROR, "Content status unexpectedly not LOADING/READY/DONE")do { if (NSLOG_LEVEL_ERROR >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_ERROR, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 299
, }; nslog__log(&_nslog_ctx, "Content status unexpectedly not LOADING/READY/DONE"
); } } while(0)
;
300 break;
301 }
302 return NSERROR_UNKNOWN;
303}
304
305
306static void html_get_dimensions(html_content *htmlc)
307{
308 css_fixed device_dpi = nscss_screen_dpi;
309 unsigned f_size;
310 unsigned f_min;
311 unsigned w;
43
'w' declared without an initial value
312 unsigned h;
313 union content_msg_data msg_data = {
314 .getdims = {
315 .viewport_width = &w,
316 .viewport_height = &h,
317 },
318 };
319
320 content_broadcast(&htmlc->base, CONTENT_MSG_GETDIMS, &msg_data);
321
322
323 w = css_unit_device2css_px(INTTOFIX(w)(css_int_to_fixed(w)), device_dpi);
44
1st function call argument is an uninitialized value
324 h = css_unit_device2css_px(INTTOFIX(h)(css_int_to_fixed(h)), device_dpi);
325
326 htmlc->media.width = w;
327 htmlc->media.height = h;
328 htmlc->unit_len_ctx.viewport_width = w;
329 htmlc->unit_len_ctx.viewport_height = h;
330 htmlc->unit_len_ctx.device_dpi = device_dpi;
331
332 /** \todo Change nsoption font sizes to px. */
333 f_size = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_size)), F_10)), F_72)(css_divide_fixed(((css_multiply_fixed((0x00018000), ((css_divide_fixed
(((css_int_to_fixed((nsoptions[NSOPTION_font_size].value.i)))
), (0x00002800))))))), (0x00012000)))
;
334 f_min = FDIV(FMUL(F_96, FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)), F_72)(css_divide_fixed(((css_multiply_fixed((0x00018000), ((css_divide_fixed
(((css_int_to_fixed((nsoptions[NSOPTION_font_min_size].value.
i)))), (0x00002800))))))), (0x00012000)))
;
335
336 htmlc->unit_len_ctx.font_size_default = f_size;
337 htmlc->unit_len_ctx.font_size_minimum = f_min;
338}
339
340/* exported function documented in html/html_internal.h */
341void html_finish_conversion(html_content *htmlc)
342{
343 union content_msg_data msg_data;
344 dom_exception exc; /* returned by libdom functions */
345 dom_node *html;
346 nserror error;
347
348 /* Bail out if we've been aborted */
349 if (htmlc->aborted) {
29
Assuming field 'aborted' is false
30
Taking false branch
350 content_broadcast_error(&htmlc->base, NSERROR_STOPPED, NULL((void*)0));
351 content_set_error(&htmlc->base);
352 return;
353 }
354
355 /* If we already have a selection context, then we have already
356 * "finished" conversion. We can get here twice if e.g. some JS
357 * adds a new stylesheet, and the stylesheet gets added after
358 * the HTML content is initially finished.
359 *
360 * If we didn't do this, the HTML content would try to rebuild the
361 * box tree for the html content when this new stylesheet is ready.
362 * NetSurf has no concept of dynamically changing documents, so this
363 * would break badly.
364 */
365 if (htmlc->select_ctx != NULL((void*)0)) {
31
Assuming field 'select_ctx' is equal to NULL
32
Taking false branch
366 NSLOG(netsurf, INFO,do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 367
, }; nslog__log(&_nslog_ctx, "Ignoring style change: NS layout is static."
); } } while(0)
367 "Ignoring style change: NS layout is static.")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 367
, }; nslog__log(&_nslog_ctx, "Ignoring style change: NS layout is static."
); } } while(0)
;
368 return;
369 }
370
371 /* create new css selection context */
372 error = html_css_new_selection_context(htmlc, &htmlc->select_ctx);
373 if (error != NSERROR_OK) {
33
Assuming 'error' is equal to NSERROR_OK
34
Taking false branch
374 content_broadcast_error(&htmlc->base, error, NULL((void*)0));
375 content_set_error(&htmlc->base);
376 return;
377 }
378
379
380 /* fire a simple event named load at the Document's Window
381 * object, but with its target set to the Document object (and
382 * the currentTarget set to the Window object)
383 */
384 if (htmlc->jsthread != NULL((void*)0)) {
35
Assuming field 'jsthread' is equal to NULL
36
Taking false branch
385 js_fire_event(htmlc->jsthread, "load", htmlc->document, NULL((void*)0));
386 }
387
388 /* convert dom tree to box tree */
389 NSLOG(netsurf, INFO, "DOM to box (%p)", htmlc)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 389
, }; nslog__log(&_nslog_ctx, "DOM to box (%p)", htmlc); }
} while(0)
;
37
Taking true branch
38
Loop condition is false. Exiting loop
390 content_set_status(&htmlc->base, messages_get("Processing"));
391 msg_data.explicit_status_text = NULL((void*)0);
392 content_broadcast(&htmlc->base, CONTENT_MSG_STATUS, &msg_data);
393
394 exc = dom_document_get_document_element(htmlc->document, (void *) &html)dom_document_get_document_element((dom_document *) (htmlc->
document), (struct dom_element **) ((void *) &html))
;
395 if ((exc != DOM_NO_ERR) || (html == NULL((void*)0))) {
39
Assuming 'exc' is equal to DOM_NO_ERR
40
Assuming 'html' is not equal to NULL
41
Taking false branch
396 NSLOG(netsurf, INFO, "error retrieving html element from dom")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 396
, }; nslog__log(&_nslog_ctx, "error retrieving html element from dom"
); } } while(0)
;
397 content_broadcast_error(&htmlc->base, NSERROR_DOM, NULL((void*)0));
398 content_set_error(&htmlc->base);
399 return;
400 }
401
402 html_get_dimensions(htmlc);
42
Calling 'html_get_dimensions'
403
404 error = dom_to_box(html, htmlc, html_box_convert_done, &htmlc->box_conversion_context);
405 if (error != NSERROR_OK) {
406 NSLOG(netsurf, INFO, "box conversion failed")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 406
, }; nslog__log(&_nslog_ctx, "box conversion failed"); } }
while(0)
;
407 dom_node_unref(html)dom_node_unref((dom_node *) (html));
408 html_object_free_objects(htmlc);
409 content_broadcast_error(&htmlc->base, error, NULL((void*)0));
410 content_set_error(&htmlc->base);
411 return;
412 }
413
414 dom_node_unref(html)dom_node_unref((dom_node *) (html));
415}
416
417
418static void
419html_document_user_data_handler(dom_node_operation operation,
420 dom_string *key, void *data,
421 struct dom_node *src,
422 struct dom_node *dst)
423{
424 if (dom_string_isequal(corestring_dom___ns_key_html_content_data,
425 key) == false0 || data == NULL((void*)0)) {
426 return;
427 }
428
429 switch (operation) {
430 case DOM_NODE_CLONED:
431 NSLOG(netsurf, INFO, "Cloned")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 431
, }; nslog__log(&_nslog_ctx, "Cloned"); } } while(0)
;
432 break;
433 case DOM_NODE_RENAMED:
434 NSLOG(netsurf, INFO, "Renamed")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 434
, }; nslog__log(&_nslog_ctx, "Renamed"); } } while(0)
;
435 break;
436 case DOM_NODE_IMPORTED:
437 NSLOG(netsurf, INFO, "imported")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 437
, }; nslog__log(&_nslog_ctx, "imported"); } } while(0)
;
438 break;
439 case DOM_NODE_ADOPTED:
440 NSLOG(netsurf, INFO, "Adopted")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 440
, }; nslog__log(&_nslog_ctx, "Adopted"); } } while(0)
;
441 break;
442 case DOM_NODE_DELETED:
443 /* This is the only path I expect */
444 break;
445 default:
446 NSLOG(netsurf, INFO, "User data operation not handled.")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 446
, }; nslog__log(&_nslog_ctx, "User data operation not handled."
); } } while(0)
;
447 assert(0)((0) ? (void) (0) : __assert_fail ("0", "content/handlers/html/html.c"
, 447, __extension__ __PRETTY_FUNCTION__))
;
448 }
449}
450
451
452static nserror
453html_create_html_data(html_content *c, const http_parameter *params)
454{
455 lwc_string *charset;
456 nserror nerror;
457 dom_hubbub_parser_params parse_params;
458 dom_hubbub_error error;
459 dom_exception err;
460 void *old_node_data;
461 const char *prefer_color_mode = (nsoption_bool(prefer_dark_mode)(nsoptions[NSOPTION_prefer_dark_mode].value.b)) ?
462 "dark" : "light";
463
464 c->parser = NULL((void*)0);
465 c->parse_completed = false0;
466 c->conversion_begun = false0;
467 c->document = NULL((void*)0);
468 c->quirks = DOM_DOCUMENT_QUIRKS_MODE_NONE;
469 c->encoding = NULL((void*)0);
470 c->base_url = nsurl_ref(content_get_url(&c->base));
471 c->base_target = NULL((void*)0);
472 c->aborted = false0;
473 c->refresh = false0;
474 c->reflowing = false0;
475 c->title = NULL((void*)0);
476 c->bctx = NULL((void*)0);
477 c->layout = NULL((void*)0);
478 c->background_colour = NS_TRANSPARENT0x01000000;
479 c->stylesheet_count = 0;
480 c->stylesheets = NULL((void*)0);
481 c->select_ctx = NULL((void*)0);
482 c->media.type = CSS_MEDIA_SCREEN;
483 c->universal = NULL((void*)0);
484 c->num_objects = 0;
485 c->object_list = NULL((void*)0);
486 c->forms = NULL((void*)0);
487 c->imagemaps = NULL((void*)0);
488 c->bw = NULL((void*)0);
489 c->frameset = NULL((void*)0);
490 c->iframe = NULL((void*)0);
491 c->page = NULL((void*)0);
492 c->font_func = guit->layout;
493 c->drag_type = HTML_DRAG_NONE;
494 c->drag_owner.no_owner = true1;
495 c->selection_type = HTML_SELECTION_NONE;
496 c->selection_owner.none = true1;
497 c->focus_type = HTML_FOCUS_SELF;
498 c->focus_owner.self = true1;
499 c->scripts_count = 0;
500 c->scripts = NULL((void*)0);
501 c->jsthread = NULL((void*)0);
502
503 c->enable_scripting = nsoption_bool(enable_javascript)(nsoptions[NSOPTION_enable_javascript].value.b);
504 c->base.active = 1; /* The html content itself is active */
505
506 if (lwc_intern_string("*", SLEN("*")(sizeof(("*")) - 1), &c->universal) != lwc_error_ok) {
507 return NSERROR_NOMEM;
508 }
509
510 if (lwc_intern_string(prefer_color_mode, strlen(prefer_color_mode),
511 &c->media.prefers_color_scheme) != lwc_error_ok) {
512 lwc_string_unref(c->universal){ lwc_string *__lwc_s = (c->universal); if (__lwc_s != ((void
*)0)) { __lwc_s->refcnt--; if ((__lwc_s->refcnt == 0) ||
((__lwc_s->refcnt == 1) && (__lwc_s->insensitive
== __lwc_s))) lwc_string_destroy(__lwc_s); } }
;
513 c->universal = NULL((void*)0);
514 return NSERROR_NOMEM;
515 }
516
517 c->sel = selection_create((struct content *)c);
518
519 nerror = http_parameter_list_find_item(params, corestring_lwc_charset, &charset);
520 if (nerror == NSERROR_OK) {
521 c->encoding = strdup(lwc_string_data(charset)({((charset != ((void*)0)) ? (void) (0) : __assert_fail ("charset != NULL"
, "content/handlers/html/html.c", 521, __extension__ __PRETTY_FUNCTION__
)); (const char *)((charset)+1);})
);
522
523 lwc_string_unref(charset){ lwc_string *__lwc_s = (charset); if (__lwc_s != ((void*)0))
{ __lwc_s->refcnt--; if ((__lwc_s->refcnt == 0) || ((__lwc_s
->refcnt == 1) && (__lwc_s->insensitive == __lwc_s
))) lwc_string_destroy(__lwc_s); } }
;
524
525 if (c->encoding == NULL((void*)0)) {
526 lwc_string_unref(c->universal){ lwc_string *__lwc_s = (c->universal); if (__lwc_s != ((void
*)0)) { __lwc_s->refcnt--; if ((__lwc_s->refcnt == 0) ||
((__lwc_s->refcnt == 1) && (__lwc_s->insensitive
== __lwc_s))) lwc_string_destroy(__lwc_s); } }
;
527 c->universal = NULL((void*)0);
528 lwc_string_unref(c->media.prefers_color_scheme){ lwc_string *__lwc_s = (c->media.prefers_color_scheme); if
(__lwc_s != ((void*)0)) { __lwc_s->refcnt--; if ((__lwc_s
->refcnt == 0) || ((__lwc_s->refcnt == 1) && (__lwc_s
->insensitive == __lwc_s))) lwc_string_destroy(__lwc_s); }
}
;
529 c->media.prefers_color_scheme = NULL((void*)0);
530 return NSERROR_NOMEM;
531
532 }
533 c->encoding_source = DOM_HUBBUB_ENCODING_SOURCE_HEADER;
534 }
535
536 /* Create the parser binding */
537 parse_params.enc = c->encoding;
538 parse_params.fix_enc = true1;
539 parse_params.enable_script = c->enable_scripting;
540 parse_params.msg = NULL((void*)0);
541 parse_params.script = html_process_script;
542 parse_params.ctx = c;
543 parse_params.daf = html_dom_event_fetcher;
544
545 error = dom_hubbub_parser_create(&parse_params,
546 &c->parser,
547 &c->document);
548 if ((error != DOM_HUBBUB_OK) && (c->encoding != NULL((void*)0))) {
549 /* Ok, we don't support the declared encoding. Bailing out
550 * isn't exactly user-friendly, so fall back to autodetect */
551 free(c->encoding);
552 c->encoding = NULL((void*)0);
553
554 parse_params.enc = c->encoding;
555
556 error = dom_hubbub_parser_create(&parse_params,
557 &c->parser,
558 &c->document);
559 }
560 if (error != DOM_HUBBUB_OK) {
561 nsurl_unref(c->base_url);
562 c->base_url = NULL((void*)0);
563
564 lwc_string_unref(c->universal){ lwc_string *__lwc_s = (c->universal); if (__lwc_s != ((void
*)0)) { __lwc_s->refcnt--; if ((__lwc_s->refcnt == 0) ||
((__lwc_s->refcnt == 1) && (__lwc_s->insensitive
== __lwc_s))) lwc_string_destroy(__lwc_s); } }
;
565 c->universal = NULL((void*)0);
566 lwc_string_unref(c->media.prefers_color_scheme){ lwc_string *__lwc_s = (c->media.prefers_color_scheme); if
(__lwc_s != ((void*)0)) { __lwc_s->refcnt--; if ((__lwc_s
->refcnt == 0) || ((__lwc_s->refcnt == 1) && (__lwc_s
->insensitive == __lwc_s))) lwc_string_destroy(__lwc_s); }
}
;
567 c->media.prefers_color_scheme = NULL((void*)0);
568
569 return libdom_hubbub_error_to_nserror(error);
570 }
571
572 err = dom_node_set_user_data(c->document,dom_node_set_user_data( (dom_node *) (c->document), (corestring_dom___ns_key_html_content_data
), (void *) (c), (dom_user_data_handler) html_document_user_data_handler
, (void **) ((void *) &old_node_data))
573 corestring_dom___ns_key_html_content_data,dom_node_set_user_data( (dom_node *) (c->document), (corestring_dom___ns_key_html_content_data
), (void *) (c), (dom_user_data_handler) html_document_user_data_handler
, (void **) ((void *) &old_node_data))
574 c, html_document_user_data_handler,dom_node_set_user_data( (dom_node *) (c->document), (corestring_dom___ns_key_html_content_data
), (void *) (c), (dom_user_data_handler) html_document_user_data_handler
, (void **) ((void *) &old_node_data))
575 (void *) &old_node_data)dom_node_set_user_data( (dom_node *) (c->document), (corestring_dom___ns_key_html_content_data
), (void *) (c), (dom_user_data_handler) html_document_user_data_handler
, (void **) ((void *) &old_node_data))
;
576 if (err != DOM_NO_ERR) {
577 dom_hubbub_parser_destroy(c->parser);
578 c->parser = NULL((void*)0);
579 nsurl_unref(c->base_url);
580 c->base_url = NULL((void*)0);
581
582 lwc_string_unref(c->universal){ lwc_string *__lwc_s = (c->universal); if (__lwc_s != ((void
*)0)) { __lwc_s->refcnt--; if ((__lwc_s->refcnt == 0) ||
((__lwc_s->refcnt == 1) && (__lwc_s->insensitive
== __lwc_s))) lwc_string_destroy(__lwc_s); } }
;
583 c->universal = NULL((void*)0);
584 lwc_string_unref(c->media.prefers_color_scheme){ lwc_string *__lwc_s = (c->media.prefers_color_scheme); if
(__lwc_s != ((void*)0)) { __lwc_s->refcnt--; if ((__lwc_s
->refcnt == 0) || ((__lwc_s->refcnt == 1) && (__lwc_s
->insensitive == __lwc_s))) lwc_string_destroy(__lwc_s); }
}
;
585 c->media.prefers_color_scheme = NULL((void*)0);
586
587 NSLOG(netsurf, INFO, "Unable to set user data.")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 587
, }; nslog__log(&_nslog_ctx, "Unable to set user data.");
} } while(0)
;
588 return NSERROR_DOM;
589 }
590
591 assert(old_node_data == NULL)((old_node_data == ((void*)0)) ? (void) (0) : __assert_fail (
"old_node_data == NULL", "content/handlers/html/html.c", 591,
__extension__ __PRETTY_FUNCTION__))
;
592
593 return NSERROR_OK;
594
595}
596
597/**
598 * Create a CONTENT_HTML.
599 *
600 * The content_html_data structure is initialized and the HTML parser is
601 * created.
602 */
603
604static nserror
605html_create(const content_handler *handler,
606 lwc_string *imime_type,
607 const http_parameter *params,
608 llcache_handle *llcache,
609 const char *fallback_charset,
610 bool_Bool quirks,
611 struct content **c)
612{
613 html_content *html;
614 nserror error;
615
616 html = calloc(1, sizeof(html_content));
617 if (html == NULL((void*)0))
618 return NSERROR_NOMEM;
619
620 error = content__init(&html->base, handler, imime_type, params,
621 llcache, fallback_charset, quirks);
622 if (error != NSERROR_OK) {
623 free(html);
624 return error;
625 }
626
627 error = html_create_html_data(html, params);
628 if (error != NSERROR_OK) {
629 content_broadcast_error(&html->base, error, NULL((void*)0));
630 free(html);
631 return error;
632 }
633
634 error = html_css_new_stylesheets(html);
635 if (error != NSERROR_OK) {
636 content_broadcast_error(&html->base, error, NULL((void*)0));
637 free(html);
638 return error;
639 }
640
641 *c = (struct content *) html;
642
643 return NSERROR_OK;
644}
645
646
647
648static nserror
649html_process_encoding_change(struct content *c,
650 const char *data,
651 unsigned int size)
652{
653 html_content *html = (html_content *) c;
654 dom_hubbub_parser_params parse_params;
655 dom_hubbub_error error;
656 const char *encoding;
657 const uint8_t *source_data;
658 size_t source_size;
659
660 /* Retrieve new encoding */
661 encoding = dom_hubbub_parser_get_encoding(html->parser,
662 &html->encoding_source);
663 if (encoding == NULL((void*)0)) {
664 return NSERROR_NOMEM;
665 }
666
667 if (html->encoding != NULL((void*)0)) {
668 free(html->encoding);
669 html->encoding = NULL((void*)0);
670 }
671
672 html->encoding = strdup(encoding);
673 if (html->encoding == NULL((void*)0)) {
674 return NSERROR_NOMEM;
675 }
676
677 /* Destroy binding */
678 dom_hubbub_parser_destroy(html->parser);
679 html->parser = NULL((void*)0);
680
681 if (html->document != NULL((void*)0)) {
682 dom_node_unref(html->document)dom_node_unref((dom_node *) (html->document));
683 }
684
685 parse_params.enc = html->encoding;
686 parse_params.fix_enc = true1;
687 parse_params.enable_script = html->enable_scripting;
688 parse_params.msg = NULL((void*)0);
689 parse_params.script = html_process_script;
690 parse_params.ctx = html;
691 parse_params.daf = html_dom_event_fetcher;
692
693 /* Create new binding, using the new encoding */
694 error = dom_hubbub_parser_create(&parse_params,
695 &html->parser,
696 &html->document);
697 if (error != DOM_HUBBUB_OK) {
698 /* Ok, we don't support the declared encoding. Bailing out
699 * isn't exactly user-friendly, so fall back to Windows-1252 */
700 free(html->encoding);
701 html->encoding = strdup("Windows-1252");
702 if (html->encoding == NULL((void*)0)) {
703 return NSERROR_NOMEM;
704 }
705 parse_params.enc = html->encoding;
706
707 error = dom_hubbub_parser_create(&parse_params,
708 &html->parser,
709 &html->document);
710
711 if (error != DOM_HUBBUB_OK) {
712 return libdom_hubbub_error_to_nserror(error);
713 }
714
715 }
716
717 source_data = content__get_source_data(c, &source_size);
718
719 /* Reprocess all the data. This is safe because
720 * the encoding is now specified at parser start which means
721 * it cannot be changed again.
722 */
723 error = dom_hubbub_parser_parse_chunk(html->parser,
724 source_data,
725 source_size);
726
727 return libdom_hubbub_error_to_nserror(error);
728}
729
730
731/**
732 * Process data for CONTENT_HTML.
733 */
734
735static bool_Bool
736html_process_data(struct content *c, const char *data, unsigned int size)
737{
738 html_content *html = (html_content *) c;
739 dom_hubbub_error dom_ret;
740 nserror err = NSERROR_OK; /* assume its all going to be ok */
741
742 dom_ret = dom_hubbub_parser_parse_chunk(html->parser,
743 (const uint8_t *) data,
744 size);
745
746 err = libdom_hubbub_error_to_nserror(dom_ret);
747
748 /* deal with encoding change */
749 if (err == NSERROR_ENCODING_CHANGE) {
750 err = html_process_encoding_change(c, data, size);
751 }
752
753 /* broadcast the error if necessary */
754 if (err != NSERROR_OK) {
755 content_broadcast_error(c, err, NULL((void*)0));
756 return false0;
757 }
758
759 return true1;
760}
761
762
763/**
764 * Convert a CONTENT_HTML for display.
765 *
766 * The following steps are carried out in order:
767 *
768 * - parsing to an XML tree is completed
769 * - stylesheets are fetched
770 * - the XML tree is converted to a box tree and object fetches are started
771 *
772 * On exit, the content status will be either CONTENT_STATUS_DONE if the
773 * document is completely loaded or CONTENT_STATUS_READY if objects are still
774 * being fetched.
775 */
776
777static bool_Bool html_convert(struct content *c)
1
[debug] analyzing from html_convert
778{
779 html_content *htmlc = (html_content *) c;
780 dom_exception exc; /* returned by libdom functions */
781
782 /* The quirk check and associated stylesheet fetch is "safe"
783 * once the root node has been inserted into the document
784 * which must have happened by this point in the parse.
785 *
786 * faliure to retrive the quirk mode or to start the
787 * stylesheet fetch is non fatal as this "only" affects the
788 * render and it would annoy the user to fail the entire
789 * render for want of a quirks stylesheet.
790 */
791 exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks)dom_document_get_quirks_mode((dom_document *) (htmlc->document
), (&htmlc->quirks))
;
792 if (exc == DOM_NO_ERR) {
2
Assuming 'exc' is not equal to DOM_NO_ERR
3
Taking false branch
793 html_css_quirks_stylesheets(htmlc);
794 NSLOG(netsurf, INFO, "quirks set to %d", htmlc->quirks)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 794
, }; nslog__log(&_nslog_ctx, "quirks set to %d", htmlc->
quirks); } } while(0)
;
795 }
796
797 htmlc->base.active--; /* the html fetch is no longer active */
798 NSLOG(netsurf, INFO, "%d fetches active (%p)", htmlc->base.active, c)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 798
, }; nslog__log(&_nslog_ctx, "%d fetches active (%p)", htmlc
->base.active, c); } } while(0)
;
4
Taking true branch
5
Loop condition is false. Exiting loop
799
800 /* The parse cannot be completed here because it may be paused
801 * untill all the resources being fetched have completed.
802 */
803
804 /* if there are no active fetches in progress no scripts are
805 * being fetched or they completed already.
806 */
807 if (html_can_begin_conversion(htmlc)) {
6
Assuming the condition is true
7
Taking true branch
808 return html_begin_conversion(htmlc);
8
Calling 'html_begin_conversion'
809 }
810 return true1;
811}
812
813/* Exported interface documented in html_internal.h */
814bool_Bool html_can_begin_conversion(html_content *htmlc)
815{
816 unsigned int i;
817
818 /* Cannot begin conversion if we're still fetching stuff */
819 if (htmlc->base.active != 0)
820 return false0;
821
822 for (i = 0; i != htmlc->stylesheet_count; i++) {
823 /* Cannot begin conversion if the stylesheets are modified */
824 if (htmlc->stylesheets[i].modified)
825 return false0;
826 }
827
828 /* All is good, begin */
829 return true1;
830}
831
832bool_Bool
833html_begin_conversion(html_content *htmlc)
834{
835 dom_node *html;
836 nserror ns_error;
837 struct form *f;
838 dom_exception exc; /* returned by libdom functions */
839 dom_string *node_name = NULL((void*)0);
840 dom_hubbub_error error;
841
842 /* The act of completing the parse can result in additional data
843 * being flushed through the parser. This may result in new style or
844 * script nodes, upon which the conversion depends. Thus, once we
845 * have completed the parse, we must check again to see if we can
846 * begin the conversion. If we can't, we must stop and wait for the
847 * new styles/scripts to be processed. Once they have been processed,
848 * we will be called again to begin the conversion for real. Thus,
849 * we must also ensure that we don't attempt to complete the parse
850 * multiple times, so store a flag to indicate that parsing is
851 * complete to avoid repeating the completion pointlessly.
852 */
853 if (htmlc->parse_completed == false0) {
9
Assuming field 'parse_completed' is not equal to false
10
Taking false branch
854 NSLOG(netsurf, INFO, "Completing parse (%p)", htmlc)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 854
, }; nslog__log(&_nslog_ctx, "Completing parse (%p)", htmlc
); } } while(0)
;
855 /* complete parsing */
856 error = dom_hubbub_parser_completed(htmlc->parser);
857 if (error == DOM_HUBBUB_HUBBUB_ERR_PAUSED && htmlc->base.active > 0) {
858 /* The act of completing the parse failed because we've
859 * encountered a sync script which needs to run
860 */
861 NSLOG(netsurf, INFO, "Completing parse brought synchronous JS to light, cannot complete yet")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 861
, }; nslog__log(&_nslog_ctx, "Completing parse brought synchronous JS to light, cannot complete yet"
); } } while(0)
;
862 return true1;
863 }
864 if (error != DOM_HUBBUB_OK) {
865 NSLOG(netsurf, INFO, "Parsing failed")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 865
, }; nslog__log(&_nslog_ctx, "Parsing failed"); } } while
(0)
;
866
867 content_broadcast_error(&htmlc->base,
868 libdom_hubbub_error_to_nserror(error),
869 NULL((void*)0));
870
871 return false0;
872 }
873 htmlc->parse_completed = true1;
874 }
875
876 if (html_can_begin_conversion(htmlc) == false0) {
11
Assuming the condition is false
12
Taking false branch
877 NSLOG(netsurf, INFO, "Can't begin conversion (%p)", htmlc)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 877
, }; nslog__log(&_nslog_ctx, "Can't begin conversion (%p)"
, htmlc); } } while(0)
;
878 /* We can't proceed (see commentary above) */
879 return true1;
880 }
881
882 /* Give up processing if we've been aborted */
883 if (htmlc->aborted) {
13
Assuming field 'aborted' is false
14
Taking false branch
884 NSLOG(netsurf, INFO, "Conversion aborted (%p) (active: %u)",do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 885
, }; nslog__log(&_nslog_ctx, "Conversion aborted (%p) (active: %u)"
, htmlc, htmlc->base.active); } } while(0)
885 htmlc, htmlc->base.active)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 885
, }; nslog__log(&_nslog_ctx, "Conversion aborted (%p) (active: %u)"
, htmlc, htmlc->base.active); } } while(0)
;
886 content_set_error(&htmlc->base);
887 content_broadcast_error(&htmlc->base, NSERROR_STOPPED, NULL((void*)0));
888 return false0;
889 }
890
891 /* Conversion begins proper at this point */
892 htmlc->conversion_begun = true1;
893
894 /* complete script execution, including deferred scripts */
895 html_script_exec(htmlc, true1);
896
897 /* fire a simple event that bubbles named DOMContentLoaded at
898 * the Document.
899 */
900
901 /* get encoding */
902 if (htmlc->encoding == NULL((void*)0)) {
15
Assuming field 'encoding' is not equal to NULL
16
Taking false branch
903 const char *encoding;
904
905 encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
906 &htmlc->encoding_source);
907 if (encoding == NULL((void*)0)) {
908 content_broadcast_error(&htmlc->base,
909 NSERROR_NOMEM,
910 NULL((void*)0));
911 return false0;
912 }
913
914 htmlc->encoding = strdup(encoding);
915 if (htmlc->encoding == NULL((void*)0)) {
916 content_broadcast_error(&htmlc->base,
917 NSERROR_NOMEM,
918 NULL((void*)0));
919 return false0;
920 }
921 }
922
923 /* locate root element and ensure it is html */
924 exc = dom_document_get_document_element(htmlc->document, (void *) &html)dom_document_get_document_element((dom_document *) (htmlc->
document), (struct dom_element **) ((void *) &html))
;
925 if ((exc != DOM_NO_ERR) || (html == NULL((void*)0))) {
17
Assuming 'exc' is equal to DOM_NO_ERR
18
Assuming 'html' is not equal to NULL
19
Taking false branch
926 NSLOG(netsurf, INFO, "error retrieving html element from dom")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 926
, }; nslog__log(&_nslog_ctx, "error retrieving html element from dom"
); } } while(0)
;
927 content_broadcast_error(&htmlc->base, NSERROR_DOM, NULL((void*)0));
928 return false0;
929 }
930
931 exc = dom_node_get_node_name(html, &node_name)dom_node_get_node_name((dom_node *) (html), (&node_name));
932 if ((exc != DOM_NO_ERR) ||
20
Assuming 'exc' is equal to DOM_NO_ERR
23
Taking false branch
933 (node_name == NULL((void*)0)) ||
21
Assuming 'node_name' is not equal to NULL
934 (!dom_string_caseless_lwc_isequal(node_name,
22
Assuming the condition is false
935 corestring_lwc_html))) {
936 NSLOG(netsurf, INFO, "root element not html")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 936
, }; nslog__log(&_nslog_ctx, "root element not html"); } }
while(0)
;
937 content_broadcast_error(&htmlc->base, NSERROR_DOM, NULL((void*)0));
938 dom_node_unref(html)dom_node_unref((dom_node *) (html));
939 return false0;
940 }
941 dom_string_unref(node_name);
942
943 /* Retrieve forms from parser */
944 htmlc->forms = html_forms_get_forms(htmlc->encoding,
945 (dom_html_document *) htmlc->document);
946 for (f = htmlc->forms; f != NULL((void*)0); f = f->prev) {
24
Assuming 'f' is equal to NULL
25
Loop condition is false. Execution continues on line 994
947 nsurl *action;
948
949 /* Make all actions absolute */
950 if (f->action == NULL((void*)0) || f->action[0] == '\0') {
951 /* HTML5 4.10.22.3 step 9 */
952 nsurl *doc_addr = content_get_url(&htmlc->base);
953 ns_error = nsurl_join(htmlc->base_url,
954 nsurl_access(doc_addr),
955 &action);
956 } else {
957 ns_error = nsurl_join(htmlc->base_url,
958 f->action,
959 &action);
960 }
961
962 if (ns_error != NSERROR_OK) {
963 content_broadcast_error(&htmlc->base, ns_error, NULL((void*)0));
964
965 dom_node_unref(html)dom_node_unref((dom_node *) (html));
966 return false0;
967 }
968
969 free(f->action);
970 f->action = strdup(nsurl_access(action));
971 nsurl_unref(action);
972 if (f->action == NULL((void*)0)) {
973 content_broadcast_error(&htmlc->base,
974 NSERROR_NOMEM,
975 NULL((void*)0));
976
977 dom_node_unref(html)dom_node_unref((dom_node *) (html));
978 return false0;
979 }
980
981 /* Ensure each form has a document encoding */
982 if (f->document_charset == NULL((void*)0)) {
983 f->document_charset = strdup(htmlc->encoding);
984 if (f->document_charset == NULL((void*)0)) {
985 content_broadcast_error(&htmlc->base,
986 NSERROR_NOMEM,
987 NULL((void*)0));
988 dom_node_unref(html)dom_node_unref((dom_node *) (html));
989 return false0;
990 }
991 }
992 }
993
994 dom_node_unref(html)dom_node_unref((dom_node *) (html));
995
996 if (htmlc->base.active == 0) {
26
Assuming field 'active' is equal to 0
27
Taking true branch
997 html_finish_conversion(htmlc);
28
Calling 'html_finish_conversion'
998 }
999
1000 return true1;
1001}
1002
1003
1004/**
1005 * Stop loading a CONTENT_HTML.
1006 *
1007 * called when the content is aborted. This must clean up any state
1008 * created during the fetch.
1009 */
1010
1011static void html_stop(struct content *c)
1012{
1013 html_content *htmlc = (html_content *) c;
1014
1015 switch (c->status) {
1016 case CONTENT_STATUS_LOADING:
1017 /* Still loading; simply flag that we've been aborted
1018 * html_convert/html_finish_conversion will do the rest */
1019 htmlc->aborted = true1;
1020 if (htmlc->jsthread != NULL((void*)0)) {
1021 /* Close the JS thread to cancel out any callbacks */
1022 js_closethread(htmlc->jsthread);
1023 }
1024 break;
1025
1026 case CONTENT_STATUS_READY:
1027 html_object_abort_objects(htmlc);
1028
1029 /* If there are no further active fetches and we're still
1030 * in the READY state, transition to the DONE state. */
1031 if (c->status == CONTENT_STATUS_READY && c->active == 0) {
1032 content_set_done(c);
1033 }
1034
1035 break;
1036
1037 case CONTENT_STATUS_DONE:
1038 /* Nothing to do */
1039 break;
1040
1041 default:
1042 NSLOG(netsurf, INFO, "Unexpected status %d (%p)", c->status,do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1043
, }; nslog__log(&_nslog_ctx, "Unexpected status %d (%p)",
c->status, c); } } while(0)
1043 c)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1043
, }; nslog__log(&_nslog_ctx, "Unexpected status %d (%p)",
c->status, c); } } while(0)
;
1044 assert(0)((0) ? (void) (0) : __assert_fail ("0", "content/handlers/html/html.c"
, 1044, __extension__ __PRETTY_FUNCTION__))
;
1045 }
1046}
1047
1048
1049/**
1050 * Reformat a CONTENT_HTML to a new width.
1051 */
1052
1053static void html_reformat(struct content *c, int width, int height)
1054{
1055 html_content *htmlc = (html_content *) c;
1056 struct box *layout;
1057 uint64_t ms_before;
1058 uint64_t ms_after;
1059 uint64_t ms_interval;
1060
1061 nsu_getmonotonic_ms(&ms_before);
1062
1063 htmlc->reflowing = true1;
1064
1065 htmlc->unit_len_ctx.viewport_width = css_unit_device2css_px(
1066 INTTOFIX(width)(css_int_to_fixed(width)), htmlc->unit_len_ctx.device_dpi);
1067 htmlc->unit_len_ctx.viewport_height = css_unit_device2css_px(
1068 INTTOFIX(height)(css_int_to_fixed(height)), htmlc->unit_len_ctx.device_dpi);
1069 htmlc->unit_len_ctx.root_style = htmlc->layout->style;
1070
1071 layout_document(htmlc, width, height);
1072 layout = htmlc->layout;
1073
1074 /* width and height are at least margin box of document */
1075 c->width = layout->x + layout->padding[LEFT] + layout->width +
1076 layout->padding[RIGHT] + layout->border[RIGHT].width +
1077 layout->margin[RIGHT];
1078 c->height = layout->y + layout->padding[TOP] + layout->height +
1079 layout->padding[BOTTOM] + layout->border[BOTTOM].width +
1080 layout->margin[BOTTOM];
1081
1082 /* if boxes overflow right or bottom edge, expand to contain it */
1083 if (c->width < layout->x + layout->descendant_x1)
1084 c->width = layout->x + layout->descendant_x1;
1085 if (c->height < layout->y + layout->descendant_y1)
1086 c->height = layout->y + layout->descendant_y1;
1087
1088 selection_reinit(htmlc->sel);
1089
1090 htmlc->reflowing = false0;
1091 htmlc->had_initial_layout = true1;
1092
1093 /* calculate next reflow time at three times what it took to reflow */
1094 nsu_getmonotonic_ms(&ms_after);
1095
1096 ms_interval = (ms_after - ms_before) * 3;
1097 if (ms_interval < (nsoption_uint(min_reflow_period)(nsoptions[NSOPTION_min_reflow_period].value.u) * 10)) {
1098 ms_interval = nsoption_uint(min_reflow_period)(nsoptions[NSOPTION_min_reflow_period].value.u) * 10;
1099 }
1100 c->reformat_time = ms_after + ms_interval;
1101}
1102
1103
1104/**
1105 * Redraw a box.
1106 *
1107 * \param h content containing the box, of type CONTENT_HTML
1108 * \param box box to redraw
1109 */
1110
1111void html_redraw_a_box(hlcache_handle *h, struct box *box)
1112{
1113 int x, y;
1114
1115 box_coords(box, &x, &y);
1116
1117 content_request_redraw(h, x, y,
1118 box->padding[LEFT] + box->width + box->padding[RIGHT],
1119 box->padding[TOP] + box->height + box->padding[BOTTOM]);
1120}
1121
1122
1123/**
1124 * Redraw a box.
1125 *
1126 * \param html content containing the box, of type CONTENT_HTML
1127 * \param box box to redraw.
1128 */
1129
1130void html__redraw_a_box(struct html_content *html, struct box *box)
1131{
1132 int x, y;
1133
1134 box_coords(box, &x, &y);
1135
1136 content__request_redraw((struct content *)html, x, y,
1137 box->padding[LEFT] + box->width + box->padding[RIGHT],
1138 box->padding[TOP] + box->height + box->padding[BOTTOM]);
1139}
1140
1141static void html_destroy_frameset(struct content_html_frames *frameset)
1142{
1143 int i;
1144
1145 if (frameset->name) {
1146 talloc_free(frameset->name);
1147 frameset->name = NULL((void*)0);
1148 }
1149 if (frameset->url) {
1150 talloc_free(frameset->url);
1151 frameset->url = NULL((void*)0);
1152 }
1153 if (frameset->children) {
1154 for (i = 0; i < (frameset->rows * frameset->cols); i++) {
1155 if (frameset->children[i].name) {
1156 talloc_free(frameset->children[i].name);
1157 frameset->children[i].name = NULL((void*)0);
1158 }
1159 if (frameset->children[i].url) {
1160 nsurl_unref(frameset->children[i].url);
1161 frameset->children[i].url = NULL((void*)0);
1162 }
1163 if (frameset->children[i].children)
1164 html_destroy_frameset(&frameset->children[i]);
1165 }
1166 talloc_free(frameset->children);
1167 frameset->children = NULL((void*)0);
1168 }
1169}
1170
1171static void html_destroy_iframe(struct content_html_iframe *iframe)
1172{
1173 struct content_html_iframe *next;
1174 next = iframe;
1175 while ((iframe = next) != NULL((void*)0)) {
1176 next = iframe->next;
1177 if (iframe->name)
1178 talloc_free(iframe->name);
1179 if (iframe->url) {
1180 nsurl_unref(iframe->url);
1181 iframe->url = NULL((void*)0);
1182 }
1183 talloc_free(iframe);
1184 }
1185}
1186
1187
1188static void html_free_layout(html_content *htmlc)
1189{
1190 if (htmlc->bctx != NULL((void*)0)) {
1191 /* freeing talloc context should let the entire box
1192 * set be destroyed
1193 */
1194 talloc_free(htmlc->bctx);
1195 }
1196}
1197
1198/**
1199 * Destroy a CONTENT_HTML and free all resources it owns.
1200 */
1201
1202static void html_destroy(struct content *c)
1203{
1204 html_content *html = (html_content *) c;
1205 struct form *f, *g;
1206
1207 NSLOG(netsurf, INFO, "content %p", c)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1207
, }; nslog__log(&_nslog_ctx, "content %p", c); } } while(
0)
;
1208
1209 /* If we're still converting a layout, cancel it */
1210 if (html->box_conversion_context != NULL((void*)0)) {
1211 if (cancel_dom_to_box(html->box_conversion_context) != NSERROR_OK) {
1212 NSLOG(netsurf, CRITICAL, "WARNING, Unable to cancel conversion context, browser may crash")do { if (NSLOG_LEVEL_CRITICAL >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_CRITICAL, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 1212, }; nslog__log(&_nslog_ctx
, "WARNING, Unable to cancel conversion context, browser may crash"
); } } while(0)
;
1213 }
1214 }
1215
1216 selection_destroy(html->sel);
1217
1218 /* Destroy forms */
1219 for (f = html->forms; f != NULL((void*)0); f = g) {
1220 g = f->prev;
1221
1222 form_free(f);
1223 }
1224
1225 imagemap_destroy(html);
1226
1227 if (c->refresh)
1228 nsurl_unref(c->refresh);
1229
1230 if (html->base_url)
1231 nsurl_unref(html->base_url);
1232
1233 /* At this point we can be moderately confident the JS is offline
1234 * so we destroy the JS thread.
1235 */
1236 if (html->jsthread != NULL((void*)0)) {
1237 js_destroythread(html->jsthread);
1238 html->jsthread = NULL((void*)0);
1239 }
1240
1241 if (html->parser != NULL((void*)0)) {
1242 dom_hubbub_parser_destroy(html->parser);
1243 html->parser = NULL((void*)0);
1244 }
1245
1246 if (html->document != NULL((void*)0)) {
1247 dom_node_unref(html->document)dom_node_unref((dom_node *) (html->document));
1248 html->document = NULL((void*)0);
1249 }
1250
1251 if (html->title != NULL((void*)0)) {
1252 dom_node_unref(html->title)dom_node_unref((dom_node *) (html->title));
1253 html->title = NULL((void*)0);
1254 }
1255
1256 /* Free encoding */
1257 if (html->encoding != NULL((void*)0)) {
1258 free(html->encoding);
1259 html->encoding = NULL((void*)0);
1260 }
1261
1262 /* Free base target */
1263 if (html->base_target != NULL((void*)0)) {
1264 free(html->base_target);
1265 html->base_target = NULL((void*)0);
1266 }
1267
1268 /* Free frameset */
1269 if (html->frameset != NULL((void*)0)) {
1270 html_destroy_frameset(html->frameset);
1271 talloc_free(html->frameset);
1272 html->frameset = NULL((void*)0);
1273 }
1274
1275 /* Free iframes */
1276 if (html->iframe != NULL((void*)0)) {
1277 html_destroy_iframe(html->iframe);
1278 html->iframe = NULL((void*)0);
1279 }
1280
1281 /* Destroy selection context */
1282 if (html->select_ctx != NULL((void*)0)) {
1283 css_select_ctx_destroy(html->select_ctx);
1284 html->select_ctx = NULL((void*)0);
1285 }
1286
1287 lwc_string_unref(html->universal){ lwc_string *__lwc_s = (html->universal); if (__lwc_s != (
(void*)0)) { __lwc_s->refcnt--; if ((__lwc_s->refcnt ==
0) || ((__lwc_s->refcnt == 1) && (__lwc_s->insensitive
== __lwc_s))) lwc_string_destroy(__lwc_s); } }
;
1288 html->universal = NULL((void*)0);
1289
1290 lwc_string_unref(html->media.prefers_color_scheme){ lwc_string *__lwc_s = (html->media.prefers_color_scheme)
; if (__lwc_s != ((void*)0)) { __lwc_s->refcnt--; if ((__lwc_s
->refcnt == 0) || ((__lwc_s->refcnt == 1) && (__lwc_s
->insensitive == __lwc_s))) lwc_string_destroy(__lwc_s); }
}
;
1291 html->media.prefers_color_scheme = NULL((void*)0);
1292
1293 /* Free stylesheets */
1294 html_css_free_stylesheets(html);
1295
1296 /* Free scripts */
1297 html_script_free(html);
1298
1299 /* Free objects */
1300 html_object_free_objects(html);
1301
1302 /* free layout */
1303 html_free_layout(html);
1304}
1305
1306
1307static nserror html_clone(const struct content *old, struct content **newc)
1308{
1309 /** \todo Clone HTML specifics */
1310
1311 /* In the meantime, we should never be called, as HTML contents
1312 * cannot be shared and we're not intending to fix printing's
1313 * cloning of documents. */
1314 assert(0 && "html_clone should never be called")((0 && "html_clone should never be called") ? (void) (
0) : __assert_fail ("0 && \"html_clone should never be called\""
, "content/handlers/html/html.c", 1314, __extension__ __PRETTY_FUNCTION__
))
;
1315
1316 return true1;
1317}
1318
1319
1320/**
1321 * Handle a window containing a CONTENT_HTML being opened.
1322 */
1323
1324static nserror
1325html_open(struct content *c,
1326 struct browser_window *bw,
1327 struct content *page,
1328 struct object_params *params)
1329{
1330 html_content *html = (html_content *) c;
1331
1332 html->bw = bw;
1333 html->page = (html_content *) page;
1334
1335 html->drag_type = HTML_DRAG_NONE;
1336 html->drag_owner.no_owner = true1;
1337
1338 /* text selection */
1339 selection_init(html->sel);
1340 html->selection_type = HTML_SELECTION_NONE;
1341 html->selection_owner.none = true1;
1342
1343 html_object_open_objects(html, bw);
1344
1345 return NSERROR_OK;
1346}
1347
1348
1349/**
1350 * Handle a window containing a CONTENT_HTML being closed.
1351 */
1352
1353static nserror html_close(struct content *c)
1354{
1355 html_content *htmlc = (html_content *) c;
1356 nserror ret = NSERROR_OK;
1357
1358 selection_clear(htmlc->sel, false0);
1359
1360 /* clear the html content reference to the browser window */
1361 htmlc->bw = NULL((void*)0);
1362
1363 /* remove all object references from the html content */
1364 html_object_close_objects(htmlc);
1365
1366 if (htmlc->jsthread != NULL((void*)0)) {
1367 /* Close, but do not destroy (yet) the JS thread */
1368 ret = js_closethread(htmlc->jsthread);
1369 }
1370
1371 return ret;
1372}
1373
1374
1375/**
1376 * Return an HTML content's selection context
1377 */
1378
1379static void html_clear_selection(struct content *c)
1380{
1381 html_content *html = (html_content *) c;
1382
1383 switch (html->selection_type) {
1384 case HTML_SELECTION_NONE:
1385 /* Nothing to do */
1386 assert(html->selection_owner.none == true)((html->selection_owner.none == 1) ? (void) (0) : __assert_fail
("html->selection_owner.none == true", "content/handlers/html/html.c"
, 1386, __extension__ __PRETTY_FUNCTION__))
;
1387 break;
1388 case HTML_SELECTION_TEXTAREA:
1389 textarea_clear_selection(html->selection_owner.textarea->
1390 gadget->data.text.ta);
1391 break;
1392 case HTML_SELECTION_SELF:
1393 assert(html->selection_owner.none == false)((html->selection_owner.none == 0) ? (void) (0) : __assert_fail
("html->selection_owner.none == false", "content/handlers/html/html.c"
, 1393, __extension__ __PRETTY_FUNCTION__))
;
1394 selection_clear(html->sel, true1);
1395 break;
1396 case HTML_SELECTION_CONTENT:
1397 content_clear_selection(html->selection_owner.content->object);
1398 break;
1399 default:
1400 break;
1401 }
1402
1403 /* There is no selection now. */
1404 html->selection_type = HTML_SELECTION_NONE;
1405 html->selection_owner.none = true1;
1406}
1407
1408
1409/**
1410 * Return an HTML content's selection context
1411 */
1412
1413static char *html_get_selection(struct content *c)
1414{
1415 html_content *html = (html_content *) c;
1416
1417 switch (html->selection_type) {
1418 case HTML_SELECTION_TEXTAREA:
1419 return textarea_get_selection(html->selection_owner.textarea->
1420 gadget->data.text.ta);
1421 case HTML_SELECTION_SELF:
1422 assert(html->selection_owner.none == false)((html->selection_owner.none == 0) ? (void) (0) : __assert_fail
("html->selection_owner.none == false", "content/handlers/html/html.c"
, 1422, __extension__ __PRETTY_FUNCTION__))
;
1423 return selection_get_copy(html->sel);
1424 case HTML_SELECTION_CONTENT:
1425 return content_get_selection(
1426 html->selection_owner.content->object);
1427 case HTML_SELECTION_NONE:
1428 /* Nothing to do */
1429 assert(html->selection_owner.none == true)((html->selection_owner.none == 1) ? (void) (0) : __assert_fail
("html->selection_owner.none == true", "content/handlers/html/html.c"
, 1429, __extension__ __PRETTY_FUNCTION__))
;
1430 break;
1431 default:
1432 break;
1433 }
1434
1435 return NULL((void*)0);
1436}
1437
1438
1439/**
1440 * Get access to any content, link URLs and objects (images) currently
1441 * at the given (x, y) coordinates.
1442 *
1443 * \param[in] c html content to look inside
1444 * \param[in] x x-coordinate of point of interest
1445 * \param[in] y y-coordinate of point of interest
1446 * \param[out] data Positional features struct to be updated with any
1447 * relevent content, or set to NULL if none.
1448 * \return NSERROR_OK on success else appropriate error code.
1449 */
1450static nserror
1451html_get_contextual_content(struct content *c, int x, int y,
1452 struct browser_window_features *data)
1453{
1454 html_content *html = (html_content *) c;
1455
1456 struct box *box = html->layout;
1457 struct box *next;
1458 int box_x = 0, box_y = 0;
1459
1460 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1461 &box_x, &box_y)) != NULL((void*)0)) {
1462 box = next;
1463
1464 /* hidden boxes are ignored */
1465 if ((box->style != NULL((void*)0)) &&
1466 css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) {
1467 continue;
1468 }
1469
1470 if (box->iframe) {
1471 float scale = browser_window_get_scale(box->iframe);
1472 browser_window_get_features(box->iframe,
1473 (x - box_x) * scale,
1474 (y - box_y) * scale,
1475 data);
1476 }
1477
1478 if (box->object)
1479 content_get_contextual_content(box->object,
1480 x - box_x, y - box_y, data);
1481
1482 if (box->object)
1483 data->object = box->object;
1484
1485 if (box->href) {
1486 data->link = box->href;
1487 data->link_title = box->text;
1488 data->link_title_length = box->length;
1489 }
1490
1491 if (box->usemap) {
1492 const char *target = NULL((void*)0);
1493 nsurl *url = imagemap_get(html, box->usemap, box_x,
1494 box_y, x, y, &target);
1495 /* Box might have imagemap, but no actual link area
1496 * at point */
1497 if (url != NULL((void*)0))
1498 data->link = url;
1499 }
1500 if (box->gadget) {
1501 switch (box->gadget->type) {
1502 case GADGET_TEXTBOX:
1503 case GADGET_TEXTAREA:
1504 case GADGET_PASSWORD:
1505 data->form_features = CTX_FORM_TEXT;
1506 break;
1507
1508 case GADGET_FILE:
1509 data->form_features = CTX_FORM_FILE;
1510 break;
1511
1512 default:
1513 data->form_features = CTX_FORM_NONE;
1514 break;
1515 }
1516 }
1517 }
1518 return NSERROR_OK;
1519}
1520
1521
1522/**
1523 * Scroll deepest thing within the content which can be scrolled at given point
1524 *
1525 * \param c html content to look inside
1526 * \param x x-coordinate of point of interest
1527 * \param y y-coordinate of point of interest
1528 * \param scrx number of px try to scroll something in x direction
1529 * \param scry number of px try to scroll something in y direction
1530 * \return true iff scroll was consumed by something in the content
1531 */
1532static bool_Bool
1533html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
1534{
1535 html_content *html = (html_content *) c;
1536
1537 struct box *box = html->layout;
1538 struct box *next;
1539 int box_x = 0, box_y = 0;
1540 bool_Bool handled_scroll = false0;
1541
1542 /* TODO: invert order; visit deepest box first */
1543
1544 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1545 &box_x, &box_y)) != NULL((void*)0)) {
1546 box = next;
1547
1548 if (box->style && css_computed_visibility(box->style) ==
1549 CSS_VISIBILITY_HIDDEN)
1550 continue;
1551
1552 /* Pass into iframe */
1553 if (box->iframe) {
1554 float scale = browser_window_get_scale(box->iframe);
1555
1556 if (browser_window_scroll_at_point(box->iframe,
1557 (x - box_x) * scale,
1558 (y - box_y) * scale,
1559 scrx, scry) == true1)
1560 return true1;
1561 }
1562
1563 /* Pass into textarea widget */
1564 if (box->gadget && (box->gadget->type == GADGET_TEXTAREA ||
1565 box->gadget->type == GADGET_PASSWORD ||
1566 box->gadget->type == GADGET_TEXTBOX) &&
1567 textarea_scroll(box->gadget->data.text.ta,
1568 scrx, scry) == true1)
1569 return true1;
1570
1571 /* Pass into object */
1572 if (box->object != NULL((void*)0) && content_scroll_at_point(
1573 box->object, x - box_x, y - box_y,
1574 scrx, scry) == true1)
1575 return true1;
1576
1577 /* Handle box scrollbars */
1578 if (box->scroll_y && scrollbar_scroll(box->scroll_y, scry))
1579 handled_scroll = true1;
1580
1581 if (box->scroll_x && scrollbar_scroll(box->scroll_x, scrx))
1582 handled_scroll = true1;
1583
1584 if (handled_scroll == true1)
1585 return true1;
1586 }
1587
1588 return false0;
1589}
1590
1591/** Helper for file gadgets to store their filename unencoded on the
1592 * dom node associated with the gadget.
1593 *
1594 * \todo Get rid of this crap eventually
1595 */
1596static void html__dom_user_data_handler(dom_node_operation operation,
1597 dom_string *key, void *_data, struct dom_node *src,
1598 struct dom_node *dst)
1599{
1600 char *oldfile;
1601 char *data = (char *)_data;
1602
1603 if (!dom_string_isequal(corestring_dom___ns_key_file_name_node_data,
1604 key) || data == NULL((void*)0)) {
1605 return;
1606 }
1607
1608 switch (operation) {
1609 case DOM_NODE_CLONED:
1610 if (dom_node_set_user_data(dst,dom_node_set_user_data( (dom_node *) (dst), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(data)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
1611 corestring_dom___ns_key_file_name_node_data,dom_node_set_user_data( (dom_node *) (dst), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(data)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
1612 strdup(data), html__dom_user_data_handler,dom_node_set_user_data( (dom_node *) (dst), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(data)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
1613 &oldfile)dom_node_set_user_data( (dom_node *) (dst), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(data)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
== DOM_NO_ERR) {
1614 if (oldfile != NULL((void*)0))
1615 free(oldfile);
1616 }
1617 break;
1618
1619 case DOM_NODE_RENAMED:
1620 case DOM_NODE_IMPORTED:
1621 case DOM_NODE_ADOPTED:
1622 break;
1623
1624 case DOM_NODE_DELETED:
1625 free(data);
1626 break;
1627 default:
1628 NSLOG(netsurf, INFO, "User data operation not handled.")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1628
, }; nslog__log(&_nslog_ctx, "User data operation not handled."
); } } while(0)
;
1629 assert(0)((0) ? (void) (0) : __assert_fail ("0", "content/handlers/html/html.c"
, 1629, __extension__ __PRETTY_FUNCTION__))
;
1630 }
1631}
1632
1633static void html__set_file_gadget_filename(struct content *c,
1634 struct form_control *gadget, const char *fn)
1635{
1636 nserror ret;
1637 char *utf8_fn, *oldfile = NULL((void*)0);
1638 html_content *html = (html_content *)c;
1639 struct box *file_box = gadget->box;
1640
1641 ret = guit->utf8->local_to_utf8(fn, 0, &utf8_fn);
1642 if (ret != NSERROR_OK) {
1643 assert(ret != NSERROR_BAD_ENCODING)((ret != NSERROR_BAD_ENCODING) ? (void) (0) : __assert_fail (
"ret != NSERROR_BAD_ENCODING", "content/handlers/html/html.c"
, 1643, __extension__ __PRETTY_FUNCTION__))
;
1644 NSLOG(netsurf, INFO,do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1645
, }; nslog__log(&_nslog_ctx, "utf8 to local encoding conversion failed"
); } } while(0)
1645 "utf8 to local encoding conversion failed")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1645
, }; nslog__log(&_nslog_ctx, "utf8 to local encoding conversion failed"
); } } while(0)
;
1646 /* Load was for us - just no memory */
1647 return;
1648 }
1649
1650 form_gadget_update_value(gadget, utf8_fn);
1651
1652 /* corestring_dom___ns_key_file_name_node_data */
1653 if (dom_node_set_user_data((dom_node *)file_box->gadget->node,dom_node_set_user_data( (dom_node *) ((dom_node *)file_box->
gadget->node), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(fn)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
1654 corestring_dom___ns_key_file_name_node_data,dom_node_set_user_data( (dom_node *) ((dom_node *)file_box->
gadget->node), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(fn)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
1655 strdup(fn), html__dom_user_data_handler,dom_node_set_user_data( (dom_node *) ((dom_node *)file_box->
gadget->node), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(fn)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
1656 &oldfile)dom_node_set_user_data( (dom_node *) ((dom_node *)file_box->
gadget->node), (corestring_dom___ns_key_file_name_node_data
), (void *) (strdup(fn)), (dom_user_data_handler) html__dom_user_data_handler
, (void **) (&oldfile))
== DOM_NO_ERR) {
1657 if (oldfile != NULL((void*)0))
1658 free(oldfile);
1659 }
1660
1661 /* Redraw box. */
1662 html__redraw_a_box(html, file_box);
1663}
1664
1665void html_set_file_gadget_filename(struct hlcache_handle *hl,
1666 struct form_control *gadget, const char *fn)
1667{
1668 return html__set_file_gadget_filename(hlcache_handle_get_content(hl),
1669 gadget, fn);
1670}
1671
1672/**
1673 * Drop a file onto a content at a particular point, or determine if a file
1674 * may be dropped onto the content at given point.
1675 *
1676 * \param c html content to look inside
1677 * \param x x-coordinate of point of interest
1678 * \param y y-coordinate of point of interest
1679 * \param file path to file to be dropped, or NULL to know if drop allowed
1680 * \return true iff file drop has been handled, or if drop possible (NULL file)
1681 */
1682static bool_Bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
1683{
1684 html_content *html = (html_content *) c;
1685
1686 struct box *box = html->layout;
1687 struct box *next;
1688 struct box *file_box = NULL((void*)0);
1689 struct box *text_box = NULL((void*)0);
1690 int box_x = 0, box_y = 0;
1691
1692 /* Scan box tree for boxes that can handle drop */
1693 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1694 &box_x, &box_y)) != NULL((void*)0)) {
1695 box = next;
1696
1697 if (box->style &&
1698 css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
1699 continue;
1700
1701 if (box->iframe) {
1702 float scale = browser_window_get_scale(box->iframe);
1703 return browser_window_drop_file_at_point(
1704 box->iframe,
1705 (x - box_x) * scale,
1706 (y - box_y) * scale,
1707 file);
1708 }
1709
1710 if (box->object &&
1711 content_drop_file_at_point(box->object,
1712 x - box_x, y - box_y, file) == true1)
1713 return true1;
1714
1715 if (box->gadget) {
1716 switch (box->gadget->type) {
1717 case GADGET_FILE:
1718 file_box = box;
1719 break;
1720
1721 case GADGET_TEXTBOX:
1722 case GADGET_TEXTAREA:
1723 case GADGET_PASSWORD:
1724 text_box = box;
1725 break;
1726
1727 default: /* appease compiler */
1728 break;
1729 }
1730 }
1731 }
1732
1733 if (!file_box && !text_box)
1734 /* No box capable of handling drop */
1735 return false0;
1736
1737 if (file == NULL((void*)0))
1738 /* There is a box capable of handling drop here */
1739 return true1;
1740
1741 /* Handle the drop */
1742 if (file_box) {
1743 /* File dropped on file input */
1744 html__set_file_gadget_filename(c, file_box->gadget, file);
1745
1746 } else {
1747 /* File dropped on text input */
1748
1749 size_t file_len;
1750 FILE *fp = NULL((void*)0);
1751 char *buffer;
1752 char *utf8_buff;
1753 nserror ret;
1754 unsigned int size;
1755 int bx, by;
1756
1757 /* Open file */
1758 fp = fopen(file, "rb");
1759 if (fp == NULL((void*)0)) {
1760 /* Couldn't open file, but drop was for us */
1761 return true1;
1762 }
1763
1764 /* Get filesize */
1765 fseek(fp, 0, SEEK_END2);
1766 file_len = ftell(fp);
1767 fseek(fp, 0, SEEK_SET0);
1768
1769 if ((long)file_len == -1) {
1770 /* unable to get file length, but drop was for us */
1771 fclose(fp);
1772 return true1;
1773 }
1774
1775 /* Allocate buffer for file data */
1776 buffer = malloc(file_len + 1);
1777 if (buffer == NULL((void*)0)) {
1778 /* No memory, but drop was for us */
1779 fclose(fp);
1780 return true1;
1781 }
1782
1783 /* Stick file into buffer */
1784 if (file_len != fread(buffer, 1, file_len, fp)) {
1785 /* Failed, but drop was for us */
1786 free(buffer);
1787 fclose(fp);
1788 return true1;
1789 }
1790
1791 /* Done with file */
1792 fclose(fp);
1793
1794 /* Ensure buffer's string termination */
1795 buffer[file_len] = '\0';
1796
1797 /* TODO: Sniff for text? */
1798
1799 /* Convert to UTF-8 */
1800 ret = guit->utf8->local_to_utf8(buffer, file_len, &utf8_buff);
1801 if (ret != NSERROR_OK) {
1802 /* bad encoding shouldn't happen */
1803 NSLOG(netsurf, ERROR,do { if (NSLOG_LEVEL_ERROR >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_ERROR, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1805
, }; nslog__log(&_nslog_ctx, "local to utf8 encoding failed (%s)"
, messages_get_errorcode(ret)); } } while(0)
1804 "local to utf8 encoding failed (%s)",do { if (NSLOG_LEVEL_ERROR >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_ERROR, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1805
, }; nslog__log(&_nslog_ctx, "local to utf8 encoding failed (%s)"
, messages_get_errorcode(ret)); } } while(0)
1805 messages_get_errorcode(ret))do { if (NSLOG_LEVEL_ERROR >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_ERROR, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1805
, }; nslog__log(&_nslog_ctx, "local to utf8 encoding failed (%s)"
, messages_get_errorcode(ret)); } } while(0)
;
1806 assert(ret != NSERROR_BAD_ENCODING)((ret != NSERROR_BAD_ENCODING) ? (void) (0) : __assert_fail (
"ret != NSERROR_BAD_ENCODING", "content/handlers/html/html.c"
, 1806, __extension__ __PRETTY_FUNCTION__))
;
1807 free(buffer);
1808 return true1;
1809 }
1810
1811 /* Done with buffer */
1812 free(buffer);
1813
1814 /* Get new length */
1815 size = strlen(utf8_buff);
1816
1817 /* Simulate a click over the input box, to place caret */
1818 box_coords(text_box, &bx, &by);
1819 textarea_mouse_action(text_box->gadget->data.text.ta,
1820 BROWSER_MOUSE_PRESS_1, x - bx, y - by);
1821
1822 /* Paste the file as text */
1823 textarea_drop_text(text_box->gadget->data.text.ta,
1824 utf8_buff, size);
1825
1826 free(utf8_buff);
1827 }
1828
1829 return true1;
1830}
1831
1832
1833/**
1834 * set debug status.
1835 *
1836 * \param c The content to debug
1837 * \param op The debug operation type
1838 */
1839static nserror
1840html_debug(struct content *c, enum content_debug op)
1841{
1842 html_redraw_debug = !html_redraw_debug;
1843
1844 return NSERROR_OK;
1845}
1846
1847
1848/**
1849 * Dump debug info concerning the html_content
1850 *
1851 * \param c The content to debug
1852 * \param f The file to dump to
1853 * \param op The debug dump type
1854 */
1855static nserror
1856html_debug_dump(struct content *c, FILE *f, enum content_debug op)
1857{
1858 html_content *htmlc = (html_content *)c;
1859 dom_node *html;
1860 dom_exception exc; /* returned by libdom functions */
1861 nserror ret;
1862
1863 assert(htmlc != NULL)((htmlc != ((void*)0)) ? (void) (0) : __assert_fail ("htmlc != NULL"
, "content/handlers/html/html.c", 1863, __extension__ __PRETTY_FUNCTION__
))
;
1864
1865 if (op == CONTENT_DEBUG_RENDER) {
1866 assert(htmlc->layout != NULL)((htmlc->layout != ((void*)0)) ? (void) (0) : __assert_fail
("htmlc->layout != NULL", "content/handlers/html/html.c",
1866, __extension__ __PRETTY_FUNCTION__))
;
1867 box_dump(f, htmlc->layout, 0, true1);
1868 ret = NSERROR_OK;
1869 } else {
1870 if (htmlc->document == NULL((void*)0)) {
1871 NSLOG(netsurf, INFO, "No document to dump")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1871
, }; nslog__log(&_nslog_ctx, "No document to dump"); } } while
(0)
;
1872 return NSERROR_DOM;
1873 }
1874
1875 exc = dom_document_get_document_element(htmlc->document, (void *) &html)dom_document_get_document_element((dom_document *) (htmlc->
document), (struct dom_element **) ((void *) &html))
;
1876 if ((exc != DOM_NO_ERR) || (html == NULL((void*)0))) {
1877 NSLOG(netsurf, INFO, "Unable to obtain root node")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1877
, }; nslog__log(&_nslog_ctx, "Unable to obtain root node"
); } } while(0)
;
1878 return NSERROR_DOM;
1879 }
1880
1881 ret = libdom_dump_structure(html, f, 0);
1882
1883 NSLOG(netsurf, INFO, "DOM structure dump returning %d", ret)do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "content/handlers/html/html.c", sizeof("content/handlers/html/html.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 1883
, }; nslog__log(&_nslog_ctx, "DOM structure dump returning %d"
, ret); } } while(0)
;
1884
1885 dom_node_unref(html)dom_node_unref((dom_node *) (html));
1886 }
1887
1888 return ret;
1889}
1890
1891
1892#if ALWAYS_DUMP_FRAMESET0
1893/**
1894 * Print a frameset tree to stderr.
1895 */
1896
1897static void
1898html_dump_frameset(struct content_html_frames *frame, unsigned int depth)
1899{
1900 unsigned int i;
1901 int row, col, index;
1902 const char *unit[] = {"px", "%", "*"};
1903 const char *scrolling[] = {"auto", "yes", "no"};
1904
1905 assert(frame)((frame) ? (void) (0) : __assert_fail ("frame", "content/handlers/html/html.c"
, 1905, __extension__ __PRETTY_FUNCTION__))
;
1906
1907 fprintf(stderrstderr, "%p ", frame);
1908
1909 fprintf(stderrstderr, "(%i %i) ", frame->rows, frame->cols);
1910
1911 fprintf(stderrstderr, "w%g%s ", frame->width.value, unit[frame->width.unit]);
1912 fprintf(stderrstderr, "h%g%s ", frame->height.value,unit[frame->height.unit]);
1913 fprintf(stderrstderr, "(margin w%i h%i) ",
1914 frame->margin_width, frame->margin_height);
1915
1916 if (frame->name)
1917 fprintf(stderrstderr, "'%s' ", frame->name);
1918 if (frame->url)
1919 fprintf(stderrstderr, "<%s> ", frame->url);
1920
1921 if (frame->no_resize)
1922 fprintf(stderrstderr, "noresize ");
1923 fprintf(stderrstderr, "(scrolling %s) ", scrolling[frame->scrolling]);
1924 if (frame->border)
1925 fprintf(stderrstderr, "border %x ",
1926 (unsigned int) frame->border_colour);
1927
1928 fprintf(stderrstderr, "\n");
1929
1930 if (frame->children) {
1931 for (row = 0; row != frame->rows; row++) {
1932 for (col = 0; col != frame->cols; col++) {
1933 for (i = 0; i != depth; i++)
1934 fprintf(stderrstderr, " ");
1935 fprintf(stderrstderr, "(%i %i): ", row, col);
1936 index = (row * frame->cols) + col;
1937 html_dump_frameset(&frame->children[index],
1938 depth + 1);
1939 }
1940 }
1941 }
1942}
1943
1944#endif
1945
1946/**
1947 * Retrieve HTML document tree
1948 *
1949 * \param h HTML content to retrieve document tree from
1950 * \return Pointer to document tree
1951 */
1952dom_document *html_get_document(hlcache_handle *h)
1953{
1954 html_content *c = (html_content *) hlcache_handle_get_content(h);
1955
1956 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 1956, __extension__ __PRETTY_FUNCTION__
))
;
1957
1958 return c->document;
1959}
1960
1961/**
1962 * Retrieve box tree
1963 *
1964 * \param h HTML content to retrieve tree from
1965 * \return Pointer to box tree
1966 *
1967 * \todo This API must die, as must all use of the box tree outside of
1968 * HTML content handler
1969 */
1970struct box *html_get_box_tree(hlcache_handle *h)
1971{
1972 html_content *c = (html_content *) hlcache_handle_get_content(h);
1973
1974 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 1974, __extension__ __PRETTY_FUNCTION__
))
;
1975
1976 return c->layout;
1977}
1978
1979/**
1980 * Retrieve the charset of an HTML document
1981 *
1982 * \param c Content to retrieve charset from
1983 * \param op The content encoding operation to perform.
1984 * \return Pointer to charset, or NULL
1985 */
1986static const char *html_encoding(const struct content *c, enum content_encoding_type op)
1987{
1988 html_content *html = (html_content *) c;
1989 static char enc_token[10] = "Encoding0";
1990
1991 assert(html != NULL)((html != ((void*)0)) ? (void) (0) : __assert_fail ("html != NULL"
, "content/handlers/html/html.c", 1991, __extension__ __PRETTY_FUNCTION__
))
;
1992
1993 if (op == CONTENT_ENCODING_SOURCE) {
1994 enc_token[8] = '0' + html->encoding_source;
1995 return messages_get(enc_token);
1996 }
1997
1998 return html->encoding;
1999}
2000
2001
2002/**
2003 * Retrieve framesets used in an HTML document
2004 *
2005 * \param h Content to inspect
2006 * \return Pointer to framesets, or NULL if none
2007 */
2008struct content_html_frames *html_get_frameset(hlcache_handle *h)
2009{
2010 html_content *c = (html_content *) hlcache_handle_get_content(h);
2011
2012 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2012, __extension__ __PRETTY_FUNCTION__
))
;
2013
2014 return c->frameset;
2015}
2016
2017/**
2018 * Retrieve iframes used in an HTML document
2019 *
2020 * \param h Content to inspect
2021 * \return Pointer to iframes, or NULL if none
2022 */
2023struct content_html_iframe *html_get_iframe(hlcache_handle *h)
2024{
2025 html_content *c = (html_content *) hlcache_handle_get_content(h);
2026
2027 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2027, __extension__ __PRETTY_FUNCTION__
))
;
2028
2029 return c->iframe;
2030}
2031
2032/**
2033 * Retrieve an HTML content's base URL
2034 *
2035 * \param h Content to retrieve base target from
2036 * \return Pointer to URL
2037 */
2038nsurl *html_get_base_url(hlcache_handle *h)
2039{
2040 html_content *c = (html_content *) hlcache_handle_get_content(h);
2041
2042 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2042, __extension__ __PRETTY_FUNCTION__
))
;
2043
2044 return c->base_url;
2045}
2046
2047/**
2048 * Retrieve an HTML content's base target
2049 *
2050 * \param h Content to retrieve base target from
2051 * \return Pointer to target, or NULL if none
2052 */
2053const char *html_get_base_target(hlcache_handle *h)
2054{
2055 html_content *c = (html_content *) hlcache_handle_get_content(h);
2056
2057 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2057, __extension__ __PRETTY_FUNCTION__
))
;
2058
2059 return c->base_target;
2060}
2061
2062
2063/**
2064 * Retrieve layout coordinates of box with given id
2065 *
2066 * \param h HTML document to search
2067 * \param frag_id String containing an element id
2068 * \param x Updated to global x coord iff id found
2069 * \param y Updated to global y coord iff id found
2070 * \return true iff id found
2071 */
2072bool_Bool html_get_id_offset(hlcache_handle *h, lwc_string *frag_id, int *x, int *y)
2073{
2074 struct box *pos;
2075 struct box *layout;
2076
2077 if (content_get_type(h) != CONTENT_HTML)
2078 return false0;
2079
2080 layout = html_get_box_tree(h);
2081
2082 if ((pos = box_find_by_id(layout, frag_id)) != 0) {
2083 box_coords(pos, x, y);
2084 return true1;
2085 }
2086 return false0;
2087}
2088
2089bool_Bool html_exec(struct content *c, const char *src, size_t srclen)
2090{
2091 html_content *htmlc = (html_content *)c;
2092 bool_Bool result = false0;
2093 dom_exception err;
2094 dom_html_body_element *body_node;
2095 dom_string *dom_src;
2096 dom_text *text_node;
2097 dom_node *spare_node;
2098 dom_html_script_element *script_node;
2099
2100 if (htmlc->document == NULL((void*)0)) {
2101 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, no document")do { if (NSLOG_LEVEL_DEEPDEBUG >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_DEEPDEBUG, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 2101, }; nslog__log(&_nslog_ctx
, "Unable to exec, no document"); } } while(0)
;
2102 goto out_no_string;
2103 }
2104
2105 err = dom_string_create((const uint8_t *)src, srclen, &dom_src);
2106 if (err != DOM_NO_ERR) {
2107 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create string")do { if (NSLOG_LEVEL_DEEPDEBUG >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_DEEPDEBUG, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 2107, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not create string"); } } while(0)
;
2108 goto out_no_string;
2109 }
2110
2111 err = dom_html_document_get_body(htmlc->document, &body_node)dom_html_document_get_body((dom_html_document *) (htmlc->document
), (struct dom_html_element **) (&body_node))
;
2112 if (err != DOM_NO_ERR) {
2113 NSLOG(netsurf, DEEPDEBUG, "Unable to retrieve body element")do { if (NSLOG_LEVEL_DEEPDEBUG >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_DEEPDEBUG, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 2113, }; nslog__log(&_nslog_ctx
, "Unable to retrieve body element"); } } while(0)
;
2114 goto out_no_body;
2115 }
2116
2117 err = dom_document_create_text_node(htmlc->document, dom_src, &text_node)dom_document_create_text_node((dom_document *) (htmlc->document
), (dom_src), (struct dom_text **) (&text_node))
;
2118 if (err != DOM_NO_ERR) {
2119 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create text node")do { if (NSLOG_LEVEL_DEEPDEBUG >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_DEEPDEBUG, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 2119, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not create text node"); } } while(0)
;
2120 goto out_no_text_node;
2121 }
2122
2123 err = dom_document_create_element(htmlc->document, corestring_dom_SCRIPT, &script_node)dom_document_create_element( (dom_document *) (htmlc->document
), (corestring_dom_SCRIPT), (struct dom_element **) (&script_node
))
;
2124 if (err != DOM_NO_ERR) {
2125 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not create script node")do { if (NSLOG_LEVEL_DEEPDEBUG >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_DEEPDEBUG, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 2125, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not create script node"); } } while(
0)
;
2126 goto out_no_script_node;
2127 }
2128
2129 err = dom_node_append_child(script_node, text_node, &spare_node)dom_node_append_child( (dom_node *) (script_node), (dom_node *
) (text_node), (dom_node **) (&spare_node))
;
2130 if (err != DOM_NO_ERR) {
2131 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not insert code node into script node")do { if (NSLOG_LEVEL_DEEPDEBUG >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_DEEPDEBUG, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 2131, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not insert code node into script node"
); } } while(0)
;
2132 goto out_unparented;
2133 }
2134 dom_node_unref(spare_node)dom_node_unref((dom_node *) (spare_node)); /* We do not need the spare ref at all */
2135
2136 err = dom_node_append_child(body_node, script_node, &spare_node)dom_node_append_child( (dom_node *) (body_node), (dom_node *)
(script_node), (dom_node **) (&spare_node))
;
2137 if (err != DOM_NO_ERR) {
2138 NSLOG(netsurf, DEEPDEBUG, "Unable to exec, could not insert script node into document body")do { if (NSLOG_LEVEL_DEEPDEBUG >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_DEEPDEBUG, "content/handlers/html/html.c", sizeof
("content/handlers/html/html.c") - 1, __PRETTY_FUNCTION__, sizeof
(__PRETTY_FUNCTION__) - 1, 2138, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not insert script node into document body"
); } } while(0)
;
2139 goto out_unparented;
2140 }
2141 dom_node_unref(spare_node)dom_node_unref((dom_node *) (spare_node)); /* Again no need for the spare ref */
2142
2143 /* We successfully inserted the node into the DOM */
2144
2145 result = true1;
2146
2147 /* Now we unwind, starting by removing the script from wherever it
2148 * ended up parented
2149 */
2150
2151 err = dom_node_get_parent_node(script_node, &spare_node)dom_node_get_parent_node( (dom_node *) (script_node), (dom_node
**) (&spare_node))
;
2152 if (err == DOM_NO_ERR && spare_node != NULL((void*)0)) {
2153 dom_node *second_spare;
2154 err = dom_node_remove_child(spare_node, script_node, &second_spare)dom_node_remove_child( (dom_node *) (spare_node), (dom_node *
) (script_node), (dom_node **) (&second_spare))
;
2155 if (err == DOM_NO_ERR) {
2156 dom_node_unref(second_spare)dom_node_unref((dom_node *) (second_spare));
2157 }
2158 dom_node_unref(spare_node)dom_node_unref((dom_node *) (spare_node));
2159 }
2160
2161out_unparented:
2162 dom_node_unref(script_node)dom_node_unref((dom_node *) (script_node));
2163out_no_script_node:
2164 dom_node_unref(text_node)dom_node_unref((dom_node *) (text_node));
2165out_no_text_node:
2166 dom_node_unref(body_node)dom_node_unref((dom_node *) (body_node));
2167out_no_body:
2168 dom_string_unref(dom_src);
2169out_no_string:
2170 return result;
2171}
2172
2173/* See \ref content_saw_insecure_objects */
2174static bool_Bool
2175html_saw_insecure_objects(struct content *c)
2176{
2177 html_content *htmlc = (html_content *)c;
2178 struct content_html_object *obj = htmlc->object_list;
2179
2180 /* Check through the object list */
2181 while (obj != NULL((void*)0)) {
2182 if (obj->content != NULL((void*)0)) {
2183 if (content_saw_insecure_objects(obj->content))
2184 return true1;
2185 }
2186 obj = obj->next;
2187 }
2188
2189 /* Now check the script list */
2190 if (html_saw_insecure_scripts(htmlc)) {
2191 return true1;
2192 }
2193
2194 /* Now check stylesheets */
2195 if (html_css_saw_insecure_stylesheets(htmlc)) {
2196 return true1;
2197 }
2198
2199 return false0;
2200}
2201
2202/**
2203 * Compute the type of a content
2204 *
2205 * \return CONTENT_HTML
2206 */
2207static content_type html_content_type(void)
2208{
2209 return CONTENT_HTML;
2210}
2211
2212
2213static void html_fini(void)
2214{
2215 html_css_fini();
2216}
2217
2218/**
2219 * Finds all occurrences of a given string in an html box
2220 *
2221 * \param pattern the string pattern to search for
2222 * \param p_len pattern length
2223 * \param cur pointer to the current box
2224 * \param case_sens whether to perform a case sensitive search
2225 * \param context The search context to add the entry to.
2226 * \return true on success, false on memory allocation failure
2227 */
2228static nserror
2229find_occurrences_html_box(const char *pattern,
2230 int p_len,
2231 struct box *cur,
2232 bool_Bool case_sens,
2233 struct textsearch_context *context)
2234{
2235 struct box *a;
2236 nserror res = NSERROR_OK;
2237
2238 /* ignore this box, if there's no visible text */
2239 if (!cur->object && cur->text) {
2240 const char *text = cur->text;
2241 unsigned length = cur->length;
2242
2243 while (length > 0) {
2244 unsigned match_length;
2245 unsigned match_offset;
2246 const char *new_text;
2247 const char *pos;
2248
2249 pos = content_textsearch_find_pattern(text,
2250 length,
2251 pattern,
2252 p_len,
2253 case_sens,
2254 &match_length);
2255 if (!pos)
2256 break;
2257
2258 /* found string in box => add to list */
2259 match_offset = pos - cur->text;
2260
2261 res = content_textsearch_add_match(context,
2262 cur->byte_offset + match_offset,
2263 cur->byte_offset + match_offset + match_length,
2264 cur,
2265 cur);
2266 if (res != NSERROR_OK) {
2267 return res;
2268 }
2269
2270 new_text = pos + match_length;
2271 length -= (new_text - text);
2272 text = new_text;
2273 }
2274 }
2275
2276 /* and recurse */
2277 for (a = cur->children; a; a = a->next) {
2278 res = find_occurrences_html_box(pattern,
2279 p_len,
2280 a,
2281 case_sens,
2282 context);
2283 if (res != NSERROR_OK) {
2284 return res;
2285 }
2286 }
2287
2288 return res;
2289}
2290
2291/**
2292 * Finds all occurrences of a given string in the html box tree
2293 *
2294 * \param pattern the string pattern to search for
2295 * \param p_len pattern length
2296 * \param c The content to search
2297 * \param csens whether to perform a case sensitive search
2298 * \param context The search context to add the entry to.
2299 * \return true on success, false on memory allocation failure
2300 */
2301static nserror
2302html_textsearch_find(struct content *c,
2303 struct textsearch_context *context,
2304 const char *pattern,
2305 int p_len,
2306 bool_Bool csens)
2307{
2308 html_content *html = (html_content *)c;
2309
2310 if (html->layout == NULL((void*)0)) {
2311 return NSERROR_INVALID;
2312 }
2313
2314 return find_occurrences_html_box(pattern,
2315 p_len,
2316 html->layout,
2317 csens,
2318 context);
2319}
2320
2321
2322static nserror
2323html_textsearch_bounds(struct content *c,
2324 unsigned start_idx,
2325 unsigned end_idx,
2326 struct box *start_box,
2327 struct box *end_box,
2328 struct rect *bounds)
2329{
2330 /* get box position and jump to it */
2331 box_coords(start_box, &bounds->x0, &bounds->y0);
2332 /* \todo: move x0 in by correct idx */
2333 box_coords(end_box, &bounds->x1, &bounds->y1);
2334 /* \todo: move x1 in by correct idx */
2335 bounds->x1 += end_box->width;
2336 bounds->y1 += end_box->height;
2337
2338 return NSERROR_OK;
2339}
2340
2341
2342/**
2343 * HTML content handler function table
2344 */
2345static const content_handler html_content_handler = {
2346 .fini = html_fini,
2347 .create = html_create,
2348 .process_data = html_process_data,
2349 .data_complete = html_convert,
2350 .reformat = html_reformat,
2351 .destroy = html_destroy,
2352 .stop = html_stop,
2353 .mouse_track = html_mouse_track,
2354 .mouse_action = html_mouse_action,
2355 .keypress = html_keypress,
2356 .redraw = html_redraw,
2357 .open = html_open,
2358 .close = html_close,
2359 .get_selection = html_get_selection,
2360 .clear_selection = html_clear_selection,
2361 .get_contextual_content = html_get_contextual_content,
2362 .scroll_at_point = html_scroll_at_point,
2363 .drop_file_at_point = html_drop_file_at_point,
2364 .debug_dump = html_debug_dump,
2365 .debug = html_debug,
2366 .clone = html_clone,
2367 .get_encoding = html_encoding,
2368 .type = html_content_type,
2369 .exec = html_exec,
2370 .saw_insecure_objects = html_saw_insecure_objects,
2371 .textsearch_find = html_textsearch_find,
2372 .textsearch_bounds = html_textsearch_bounds,
2373 .textselection_redraw = html_textselection_redraw,
2374 .textselection_copy = html_textselection_copy,
2375 .textselection_get_end = html_textselection_get_end,
2376 .no_share = true1,
2377};
2378
2379
2380/* exported function documented in html/html.h */
2381nserror html_init(void)
2382{
2383 uint32_t i;
2384 nserror error;
2385
2386 error = html_css_init();
2387 if (error != NSERROR_OK)
2388 goto error;
2389
2390 for (i = 0; i < NOF_ELEMENTS(html_types)(sizeof(html_types)/sizeof(*(html_types))); i++) {
2391 error = content_factory_register_handler(html_types[i],
2392 &html_content_handler);
2393 if (error != NSERROR_OK)
2394 goto error;
2395 }
2396
2397 return NSERROR_OK;
2398
2399error:
2400 html_fini();
2401
2402 return error;
2403}