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-store=region -analyzer-opt-analyze-nested-blocks -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 -fcoverage-compilation-dir=/var/lib/jenkins/workspace/scan-build-netsurf -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -I . -I include -I build/Linux-monkey -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 -D WITH_CURL -D WITH_OPENSSL -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D UTF8PROC_EXPORTS -D WITH_UTF8PROC -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_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 -D monkey -D nsmonkey -D MONKEY_RESPATH="/var/lib/jenkins/artifacts-x86_64-linux-gnu/share/netsurf/" -D _POSIX_C_SOURCE=200809L -D _XOPEN_SOURCE=700 -D _BSD_SOURCE -D _DEFAULT_SOURCE -D _NETBSD_SOURCE -D DUK_OPT_HAVE_CUSTOM_H -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../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 -fdebug-compilation-dir=/var/lib/jenkins/workspace/scan-build-netsurf -ferror-limit 19 -fgnuc-version=4.2.1 -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/2024-09-27-095240-3006188-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;
42
'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);
43
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) {
28
Assuming field 'aborted' is false
29
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)) {
30
Assuming field 'select_ctx' is equal to NULL
31
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) {
32
Assuming 'error' is equal to NSERROR_OK
33
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)) {
34
Assuming field 'jsthread' is equal to NULL
35
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)
;
36
Taking true branch
37
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))) {
38
Assuming 'exc' is equal to DOM_NO_ERR
39
Assuming 'html' is not equal to NULL
40
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);
41
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); ((__lwc_s != ((void
*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL", "content/handlers/html/html.c"
, 512, __extension__ __PRETTY_FUNCTION__)); __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); ((__lwc_s != ((void*)0)) ?
(void) (0) : __assert_fail ("__lwc_s != NULL", "content/handlers/html/html.c"
, 523, __extension__ __PRETTY_FUNCTION__)); __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); ((__lwc_s != ((void
*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL", "content/handlers/html/html.c"
, 526, __extension__ __PRETTY_FUNCTION__)); __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); (
(__lwc_s != ((void*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL"
, "content/handlers/html/html.c", 528, __extension__ __PRETTY_FUNCTION__
)); __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); ((__lwc_s != ((void
*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL", "content/handlers/html/html.c"
, 564, __extension__ __PRETTY_FUNCTION__)); __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); (
(__lwc_s != ((void*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL"
, "content/handlers/html/html.c", 566, __extension__ __PRETTY_FUNCTION__
)); __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); ((__lwc_s != ((void
*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL", "content/handlers/html/html.c"
, 582, __extension__ __PRETTY_FUNCTION__)); __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); (
(__lwc_s != ((void*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL"
, "content/handlers/html/html.c", 584, __extension__ __PRETTY_FUNCTION__
)); __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)
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) {
1
Assuming 'exc' is not equal to DOM_NO_ERR
2
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)
;
3
Taking true branch
4
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)) {
5
Assuming the condition is true
6
Taking true branch
808 return html_begin_conversion(htmlc);
7
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) {
8
Assuming field 'parse_completed' is not equal to false
9
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) {
10
Assuming the condition is false
11
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) {
12
Assuming field 'aborted' is false
13
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)) {
14
Assuming field 'encoding' is not equal to NULL
15
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))) {
16
Assuming 'exc' is equal to DOM_NO_ERR
17
Assuming 'html' is not equal to NULL
18
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) ||
19
Assuming 'exc' is equal to DOM_NO_ERR
22
Taking false branch
933 (node_name == NULL((void*)0)) ||
20
Assuming 'node_name' is not equal to NULL
934 (!dom_string_caseless_lwc_isequal(node_name,
21
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) {
23
Assuming 'f' is equal to NULL
24
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) {
25
Assuming field 'active' is equal to 0
26
Taking true branch
997 html_finish_conversion(htmlc);
27
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 if (html->universal != NULL((void*)0)) {
1288 lwc_string_unref(html->universal){ lwc_string *__lwc_s = (html->universal); ((__lwc_s != ((
void*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL", "content/handlers/html/html.c"
, 1288, __extension__ __PRETTY_FUNCTION__)); __lwc_s->refcnt
--; if ((__lwc_s->refcnt == 0) || ((__lwc_s->refcnt == 1
) && (__lwc_s->insensitive == __lwc_s))) lwc_string_destroy
(__lwc_s); }
;
1289 html->universal = NULL((void*)0);
1290 }
1291
1292 if (html->media.prefers_color_scheme != NULL((void*)0)) {
1293 lwc_string_unref(html->media.prefers_color_scheme){ lwc_string *__lwc_s = (html->media.prefers_color_scheme)
; ((__lwc_s != ((void*)0)) ? (void) (0) : __assert_fail ("__lwc_s != NULL"
, "content/handlers/html/html.c", 1293, __extension__ __PRETTY_FUNCTION__
)); __lwc_s->refcnt--; if ((__lwc_s->refcnt == 0) || ((
__lwc_s->refcnt == 1) && (__lwc_s->insensitive ==
__lwc_s))) lwc_string_destroy(__lwc_s); }
;
1294 html->media.prefers_color_scheme = NULL((void*)0);
1295 }
1296
1297 /* Free stylesheets */
1298 html_css_free_stylesheets(html);
1299
1300 /* Free scripts */
1301 html_script_free(html);
1302
1303 /* Free objects */
1304 html_object_free_objects(html);
1305
1306 /* free layout */
1307 html_free_layout(html);
1308}
1309
1310
1311static nserror html_clone(const struct content *old, struct content **newc)
1312{
1313 /** \todo Clone HTML specifics */
1314
1315 /* In the meantime, we should never be called, as HTML contents
1316 * cannot be shared and we're not intending to fix printing's
1317 * cloning of documents. */
1318 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", 1318, __extension__ __PRETTY_FUNCTION__
))
;
1319
1320 return true1;
1321}
1322
1323
1324/**
1325 * Handle a window containing a CONTENT_HTML being opened.
1326 */
1327
1328static nserror
1329html_open(struct content *c,
1330 struct browser_window *bw,
1331 struct content *page,
1332 struct object_params *params)
1333{
1334 html_content *html = (html_content *) c;
1335
1336 html->bw = bw;
1337 html->page = (html_content *) page;
1338
1339 html->drag_type = HTML_DRAG_NONE;
1340 html->drag_owner.no_owner = true1;
1341
1342 /* text selection */
1343 selection_init(html->sel);
1344 html->selection_type = HTML_SELECTION_NONE;
1345 html->selection_owner.none = true1;
1346
1347 html_object_open_objects(html, bw);
1348
1349 return NSERROR_OK;
1350}
1351
1352
1353/**
1354 * Handle a window containing a CONTENT_HTML being closed.
1355 */
1356
1357static nserror html_close(struct content *c)
1358{
1359 html_content *htmlc = (html_content *) c;
1360 nserror ret = NSERROR_OK;
1361
1362 selection_clear(htmlc->sel, false0);
1363
1364 /* clear the html content reference to the browser window */
1365 htmlc->bw = NULL((void*)0);
1366
1367 /* remove all object references from the html content */
1368 html_object_close_objects(htmlc);
1369
1370 if (htmlc->jsthread != NULL((void*)0)) {
1371 /* Close, but do not destroy (yet) the JS thread */
1372 ret = js_closethread(htmlc->jsthread);
1373 }
1374
1375 return ret;
1376}
1377
1378
1379/**
1380 * Return an HTML content's selection context
1381 */
1382
1383static void html_clear_selection(struct content *c)
1384{
1385 html_content *html = (html_content *) c;
1386
1387 switch (html->selection_type) {
1388 case HTML_SELECTION_NONE:
1389 /* Nothing to do */
1390 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"
, 1390, __extension__ __PRETTY_FUNCTION__))
;
1391 break;
1392 case HTML_SELECTION_TEXTAREA:
1393 textarea_clear_selection(html->selection_owner.textarea->
1394 gadget->data.text.ta);
1395 break;
1396 case HTML_SELECTION_SELF:
1397 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"
, 1397, __extension__ __PRETTY_FUNCTION__))
;
1398 selection_clear(html->sel, true1);
1399 break;
1400 case HTML_SELECTION_CONTENT:
1401 content_clear_selection(html->selection_owner.content->object);
1402 break;
1403 default:
1404 break;
1405 }
1406
1407 /* There is no selection now. */
1408 html->selection_type = HTML_SELECTION_NONE;
1409 html->selection_owner.none = true1;
1410}
1411
1412
1413/**
1414 * Return an HTML content's selection context
1415 */
1416
1417static char *html_get_selection(struct content *c)
1418{
1419 html_content *html = (html_content *) c;
1420
1421 switch (html->selection_type) {
1422 case HTML_SELECTION_TEXTAREA:
1423 return textarea_get_selection(html->selection_owner.textarea->
1424 gadget->data.text.ta);
1425 case HTML_SELECTION_SELF:
1426 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"
, 1426, __extension__ __PRETTY_FUNCTION__))
;
1427 return selection_get_copy(html->sel);
1428 case HTML_SELECTION_CONTENT:
1429 return content_get_selection(
1430 html->selection_owner.content->object);
1431 case HTML_SELECTION_NONE:
1432 /* Nothing to do */
1433 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"
, 1433, __extension__ __PRETTY_FUNCTION__))
;
1434 break;
1435 default:
1436 break;
1437 }
1438
1439 return NULL((void*)0);
1440}
1441
1442
1443/**
1444 * Get access to any content, link URLs and objects (images) currently
1445 * at the given (x, y) coordinates.
1446 *
1447 * \param[in] c html content to look inside
1448 * \param[in] x x-coordinate of point of interest
1449 * \param[in] y y-coordinate of point of interest
1450 * \param[out] data Positional features struct to be updated with any
1451 * relevent content, or set to NULL if none.
1452 * \return NSERROR_OK on success else appropriate error code.
1453 */
1454static nserror
1455html_get_contextual_content(struct content *c, int x, int y,
1456 struct browser_window_features *data)
1457{
1458 html_content *html = (html_content *) c;
1459
1460 struct box *box = html->layout;
1461 struct box *next;
1462 int box_x = 0, box_y = 0;
1463
1464 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1465 &box_x, &box_y)) != NULL((void*)0)) {
1466 box = next;
1467
1468 /* hidden boxes are ignored */
1469 if ((box->style != NULL((void*)0)) &&
1470 css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) {
1471 continue;
1472 }
1473
1474 if (box->iframe) {
1475 float scale = browser_window_get_scale(box->iframe);
1476 browser_window_get_features(box->iframe,
1477 (x - box_x) * scale,
1478 (y - box_y) * scale,
1479 data);
1480 }
1481
1482 if (box->object)
1483 content_get_contextual_content(box->object,
1484 x - box_x, y - box_y, data);
1485
1486 if (box->object)
1487 data->object = box->object;
1488
1489 if (box->href)
1490 data->link = box->href;
1491
1492 if (box->usemap) {
1493 const char *target = NULL((void*)0);
1494 nsurl *url = imagemap_get(html, box->usemap, box_x,
1495 box_y, x, y, &target);
1496 /* Box might have imagemap, but no actual link area
1497 * at point */
1498 if (url != NULL((void*)0))
1499 data->link = url;
1500 }
1501 if (box->gadget) {
1502 switch (box->gadget->type) {
1503 case GADGET_TEXTBOX:
1504 case GADGET_TEXTAREA:
1505 case GADGET_PASSWORD:
1506 data->form_features = CTX_FORM_TEXT;
1507 break;
1508
1509 case GADGET_FILE:
1510 data->form_features = CTX_FORM_FILE;
1511 break;
1512
1513 default:
1514 data->form_features = CTX_FORM_NONE;
1515 break;
1516 }
1517 }
1518 }
1519 return NSERROR_OK;
1520}
1521
1522
1523/**
1524 * Scroll deepest thing within the content which can be scrolled at given point
1525 *
1526 * \param c html content to look inside
1527 * \param x x-coordinate of point of interest
1528 * \param y y-coordinate of point of interest
1529 * \param scrx number of px try to scroll something in x direction
1530 * \param scry number of px try to scroll something in y direction
1531 * \return true iff scroll was consumed by something in the content
1532 */
1533static bool_Bool
1534html_scroll_at_point(struct content *c, int x, int y, int scrx, int scry)
1535{
1536 html_content *html = (html_content *) c;
1537
1538 struct box *box = html->layout;
1539 struct box *next;
1540 int box_x = 0, box_y = 0;
1541 bool_Bool handled_scroll = false0;
1542
1543 /* TODO: invert order; visit deepest box first */
1544
1545 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1546 &box_x, &box_y)) != NULL((void*)0)) {
1547 box = next;
1548
1549 if (box->style && css_computed_visibility(box->style) ==
1550 CSS_VISIBILITY_HIDDEN)
1551 continue;
1552
1553 /* Pass into iframe */
1554 if (box->iframe) {
1555 float scale = browser_window_get_scale(box->iframe);
1556
1557 if (browser_window_scroll_at_point(box->iframe,
1558 (x - box_x) * scale,
1559 (y - box_y) * scale,
1560 scrx, scry) == true1)
1561 return true1;
1562 }
1563
1564 /* Pass into textarea widget */
1565 if (box->gadget && (box->gadget->type == GADGET_TEXTAREA ||
1566 box->gadget->type == GADGET_PASSWORD ||
1567 box->gadget->type == GADGET_TEXTBOX) &&
1568 textarea_scroll(box->gadget->data.text.ta,
1569 scrx, scry) == true1)
1570 return true1;
1571
1572 /* Pass into object */
1573 if (box->object != NULL((void*)0) && content_scroll_at_point(
1574 box->object, x - box_x, y - box_y,
1575 scrx, scry) == true1)
1576 return true1;
1577
1578 /* Handle box scrollbars */
1579 if (box->scroll_y && scrollbar_scroll(box->scroll_y, scry))
1580 handled_scroll = true1;
1581
1582 if (box->scroll_x && scrollbar_scroll(box->scroll_x, scrx))
1583 handled_scroll = true1;
1584
1585 if (handled_scroll == true1)
1586 return true1;
1587 }
1588
1589 return false0;
1590}
1591
1592/** Helper for file gadgets to store their filename unencoded on the
1593 * dom node associated with the gadget.
1594 *
1595 * \todo Get rid of this crap eventually
1596 */
1597static void html__dom_user_data_handler(dom_node_operation operation,
1598 dom_string *key, void *_data, struct dom_node *src,
1599 struct dom_node *dst)
1600{
1601 char *oldfile;
1602 char *data = (char *)_data;
1603
1604 if (!dom_string_isequal(corestring_dom___ns_key_file_name_node_data,
1605 key) || data == NULL((void*)0)) {
1606 return;
1607 }
1608
1609 switch (operation) {
1610 case DOM_NODE_CLONED:
1611 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))
1612 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))
1613 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))
1614 &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) {
1615 if (oldfile != NULL((void*)0))
1616 free(oldfile);
1617 }
1618 break;
1619
1620 case DOM_NODE_RENAMED:
1621 case DOM_NODE_IMPORTED:
1622 case DOM_NODE_ADOPTED:
1623 break;
1624
1625 case DOM_NODE_DELETED:
1626 free(data);
1627 break;
1628 default:
1629 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, 1629
, }; nslog__log(&_nslog_ctx, "User data operation not handled."
); } } while(0)
;
1630 assert(0)((0) ? (void) (0) : __assert_fail ("0", "content/handlers/html/html.c"
, 1630, __extension__ __PRETTY_FUNCTION__))
;
1631 }
1632}
1633
1634static void html__set_file_gadget_filename(struct content *c,
1635 struct form_control *gadget, const char *fn)
1636{
1637 nserror ret;
1638 char *utf8_fn, *oldfile = NULL((void*)0);
1639 html_content *html = (html_content *)c;
1640 struct box *file_box = gadget->box;
1641
1642 ret = guit->utf8->local_to_utf8(fn, 0, &utf8_fn);
1643 if (ret != NSERROR_OK) {
1644 assert(ret != NSERROR_BAD_ENCODING)((ret != NSERROR_BAD_ENCODING) ? (void) (0) : __assert_fail (
"ret != NSERROR_BAD_ENCODING", "content/handlers/html/html.c"
, 1644, __extension__ __PRETTY_FUNCTION__))
;
1645 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, 1646
, }; nslog__log(&_nslog_ctx, "utf8 to local encoding conversion failed"
); } } while(0)
1646 "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, 1646
, }; nslog__log(&_nslog_ctx, "utf8 to local encoding conversion failed"
); } } while(0)
;
1647 /* Load was for us - just no memory */
1648 return;
1649 }
1650
1651 form_gadget_update_value(gadget, utf8_fn);
1652
1653 /* corestring_dom___ns_key_file_name_node_data */
1654 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))
1655 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))
1656 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))
1657 &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) {
1658 if (oldfile != NULL((void*)0))
1659 free(oldfile);
1660 }
1661
1662 /* Redraw box. */
1663 html__redraw_a_box(html, file_box);
1664}
1665
1666void html_set_file_gadget_filename(struct hlcache_handle *hl,
1667 struct form_control *gadget, const char *fn)
1668{
1669 return html__set_file_gadget_filename(hlcache_handle_get_content(hl),
1670 gadget, fn);
1671}
1672
1673/**
1674 * Drop a file onto a content at a particular point, or determine if a file
1675 * may be dropped onto the content at given point.
1676 *
1677 * \param c html content to look inside
1678 * \param x x-coordinate of point of interest
1679 * \param y y-coordinate of point of interest
1680 * \param file path to file to be dropped, or NULL to know if drop allowed
1681 * \return true iff file drop has been handled, or if drop possible (NULL file)
1682 */
1683static bool_Bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
1684{
1685 html_content *html = (html_content *) c;
1686
1687 struct box *box = html->layout;
1688 struct box *next;
1689 struct box *file_box = NULL((void*)0);
1690 struct box *text_box = NULL((void*)0);
1691 int box_x = 0, box_y = 0;
1692
1693 /* Scan box tree for boxes that can handle drop */
1694 while ((next = box_at_point(&html->unit_len_ctx, box, x, y,
1695 &box_x, &box_y)) != NULL((void*)0)) {
1696 box = next;
1697
1698 if (box->style &&
1699 css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
1700 continue;
1701
1702 if (box->iframe) {
1703 float scale = browser_window_get_scale(box->iframe);
1704 return browser_window_drop_file_at_point(
1705 box->iframe,
1706 (x - box_x) * scale,
1707 (y - box_y) * scale,
1708 file);
1709 }
1710
1711 if (box->object &&
1712 content_drop_file_at_point(box->object,
1713 x - box_x, y - box_y, file) == true1)
1714 return true1;
1715
1716 if (box->gadget) {
1717 switch (box->gadget->type) {
1718 case GADGET_FILE:
1719 file_box = box;
1720 break;
1721
1722 case GADGET_TEXTBOX:
1723 case GADGET_TEXTAREA:
1724 case GADGET_PASSWORD:
1725 text_box = box;
1726 break;
1727
1728 default: /* appease compiler */
1729 break;
1730 }
1731 }
1732 }
1733
1734 if (!file_box && !text_box)
1735 /* No box capable of handling drop */
1736 return false0;
1737
1738 if (file == NULL((void*)0))
1739 /* There is a box capable of handling drop here */
1740 return true1;
1741
1742 /* Handle the drop */
1743 if (file_box) {
1744 /* File dropped on file input */
1745 html__set_file_gadget_filename(c, file_box->gadget, file);
1746
1747 } else {
1748 /* File dropped on text input */
1749
1750 size_t file_len;
1751 FILE *fp = NULL((void*)0);
1752 char *buffer;
1753 char *utf8_buff;
1754 nserror ret;
1755 unsigned int size;
1756 int bx, by;
1757
1758 /* Open file */
1759 fp = fopen(file, "rb");
1760 if (fp == NULL((void*)0)) {
1761 /* Couldn't open file, but drop was for us */
1762 return true1;
1763 }
1764
1765 /* Get filesize */
1766 fseek(fp, 0, SEEK_END2);
1767 file_len = ftell(fp);
1768 fseek(fp, 0, SEEK_SET0);
1769
1770 if ((long)file_len == -1) {
1771 /* unable to get file length, but drop was for us */
1772 fclose(fp);
1773 return true1;
1774 }
1775
1776 /* Allocate buffer for file data */
1777 buffer = malloc(file_len + 1);
1778 if (buffer == NULL((void*)0)) {
1779 /* No memory, but drop was for us */
1780 fclose(fp);
1781 return true1;
1782 }
1783
1784 /* Stick file into buffer */
1785 if (file_len != fread(buffer, 1, file_len, fp)) {
1786 /* Failed, but drop was for us */
1787 free(buffer);
1788 fclose(fp);
1789 return true1;
1790 }
1791
1792 /* Done with file */
1793 fclose(fp);
1794
1795 /* Ensure buffer's string termination */
1796 buffer[file_len] = '\0';
1797
1798 /* TODO: Sniff for text? */
1799
1800 /* Convert to UTF-8 */
1801 ret = guit->utf8->local_to_utf8(buffer, file_len, &utf8_buff);
1802 if (ret != NSERROR_OK) {
1803 /* bad encoding shouldn't happen */
1804 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, 1806
, }; nslog__log(&_nslog_ctx, "local to utf8 encoding failed (%s)"
, messages_get_errorcode(ret)); } } while(0)
1805 "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, 1806
, }; nslog__log(&_nslog_ctx, "local to utf8 encoding failed (%s)"
, messages_get_errorcode(ret)); } } while(0)
1806 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, 1806
, }; nslog__log(&_nslog_ctx, "local to utf8 encoding failed (%s)"
, messages_get_errorcode(ret)); } } while(0)
;
1807 assert(ret != NSERROR_BAD_ENCODING)((ret != NSERROR_BAD_ENCODING) ? (void) (0) : __assert_fail (
"ret != NSERROR_BAD_ENCODING", "content/handlers/html/html.c"
, 1807, __extension__ __PRETTY_FUNCTION__))
;
1808 free(buffer);
1809 return true1;
1810 }
1811
1812 /* Done with buffer */
1813 free(buffer);
1814
1815 /* Get new length */
1816 size = strlen(utf8_buff);
1817
1818 /* Simulate a click over the input box, to place caret */
1819 box_coords(text_box, &bx, &by);
1820 textarea_mouse_action(text_box->gadget->data.text.ta,
1821 BROWSER_MOUSE_PRESS_1, x - bx, y - by);
1822
1823 /* Paste the file as text */
1824 textarea_drop_text(text_box->gadget->data.text.ta,
1825 utf8_buff, size);
1826
1827 free(utf8_buff);
1828 }
1829
1830 return true1;
1831}
1832
1833
1834/**
1835 * set debug status.
1836 *
1837 * \param c The content to debug
1838 * \param op The debug operation type
1839 */
1840static nserror
1841html_debug(struct content *c, enum content_debug op)
1842{
1843 html_redraw_debug = !html_redraw_debug;
1844
1845 return NSERROR_OK;
1846}
1847
1848
1849/**
1850 * Dump debug info concerning the html_content
1851 *
1852 * \param c The content to debug
1853 * \param f The file to dump to
1854 * \param op The debug dump type
1855 */
1856static nserror
1857html_debug_dump(struct content *c, FILE *f, enum content_debug op)
1858{
1859 html_content *htmlc = (html_content *)c;
1860 dom_node *html;
1861 dom_exception exc; /* returned by libdom functions */
1862 nserror ret;
1863
1864 assert(htmlc != NULL)((htmlc != ((void*)0)) ? (void) (0) : __assert_fail ("htmlc != NULL"
, "content/handlers/html/html.c", 1864, __extension__ __PRETTY_FUNCTION__
))
;
1865
1866 if (op == CONTENT_DEBUG_RENDER) {
1867 assert(htmlc->layout != NULL)((htmlc->layout != ((void*)0)) ? (void) (0) : __assert_fail
("htmlc->layout != NULL", "content/handlers/html/html.c",
1867, __extension__ __PRETTY_FUNCTION__))
;
1868 box_dump(f, htmlc->layout, 0, true1);
1869 ret = NSERROR_OK;
1870 } else {
1871 if (htmlc->document == NULL((void*)0)) {
1872 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, 1872
, }; nslog__log(&_nslog_ctx, "No document to dump"); } } while
(0)
;
1873 return NSERROR_DOM;
1874 }
1875
1876 exc = dom_document_get_document_element(htmlc->document, (void *) &html)dom_document_get_document_element((dom_document *) (htmlc->
document), (struct dom_element **) ((void *) &html))
;
1877 if ((exc != DOM_NO_ERR) || (html == NULL((void*)0))) {
1878 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, 1878
, }; nslog__log(&_nslog_ctx, "Unable to obtain root node"
); } } while(0)
;
1879 return NSERROR_DOM;
1880 }
1881
1882 ret = libdom_dump_structure(html, f, 0);
1883
1884 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, 1884
, }; nslog__log(&_nslog_ctx, "DOM structure dump returning %d"
, ret); } } while(0)
;
1885
1886 dom_node_unref(html)dom_node_unref((dom_node *) (html));
1887 }
1888
1889 return ret;
1890}
1891
1892
1893#if ALWAYS_DUMP_FRAMESET0
1894/**
1895 * Print a frameset tree to stderr.
1896 */
1897
1898static void
1899html_dump_frameset(struct content_html_frames *frame, unsigned int depth)
1900{
1901 unsigned int i;
1902 int row, col, index;
1903 const char *unit[] = {"px", "%", "*"};
1904 const char *scrolling[] = {"auto", "yes", "no"};
1905
1906 assert(frame)((frame) ? (void) (0) : __assert_fail ("frame", "content/handlers/html/html.c"
, 1906, __extension__ __PRETTY_FUNCTION__))
;
1907
1908 fprintf(stderrstderr, "%p ", frame);
1909
1910 fprintf(stderrstderr, "(%i %i) ", frame->rows, frame->cols);
1911
1912 fprintf(stderrstderr, "w%g%s ", frame->width.value, unit[frame->width.unit]);
1913 fprintf(stderrstderr, "h%g%s ", frame->height.value,unit[frame->height.unit]);
1914 fprintf(stderrstderr, "(margin w%i h%i) ",
1915 frame->margin_width, frame->margin_height);
1916
1917 if (frame->name)
1918 fprintf(stderrstderr, "'%s' ", frame->name);
1919 if (frame->url)
1920 fprintf(stderrstderr, "<%s> ", frame->url);
1921
1922 if (frame->no_resize)
1923 fprintf(stderrstderr, "noresize ");
1924 fprintf(stderrstderr, "(scrolling %s) ", scrolling[frame->scrolling]);
1925 if (frame->border)
1926 fprintf(stderrstderr, "border %x ",
1927 (unsigned int) frame->border_colour);
1928
1929 fprintf(stderrstderr, "\n");
1930
1931 if (frame->children) {
1932 for (row = 0; row != frame->rows; row++) {
1933 for (col = 0; col != frame->cols; col++) {
1934 for (i = 0; i != depth; i++)
1935 fprintf(stderrstderr, " ");
1936 fprintf(stderrstderr, "(%i %i): ", row, col);
1937 index = (row * frame->cols) + col;
1938 html_dump_frameset(&frame->children[index],
1939 depth + 1);
1940 }
1941 }
1942 }
1943}
1944
1945#endif
1946
1947/**
1948 * Retrieve HTML document tree
1949 *
1950 * \param h HTML content to retrieve document tree from
1951 * \return Pointer to document tree
1952 */
1953dom_document *html_get_document(hlcache_handle *h)
1954{
1955 html_content *c = (html_content *) hlcache_handle_get_content(h);
1956
1957 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 1957, __extension__ __PRETTY_FUNCTION__
))
;
1958
1959 return c->document;
1960}
1961
1962/**
1963 * Retrieve box tree
1964 *
1965 * \param h HTML content to retrieve tree from
1966 * \return Pointer to box tree
1967 *
1968 * \todo This API must die, as must all use of the box tree outside of
1969 * HTML content handler
1970 */
1971struct box *html_get_box_tree(hlcache_handle *h)
1972{
1973 html_content *c = (html_content *) hlcache_handle_get_content(h);
1974
1975 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 1975, __extension__ __PRETTY_FUNCTION__
))
;
1976
1977 return c->layout;
1978}
1979
1980/**
1981 * Retrieve the charset of an HTML document
1982 *
1983 * \param c Content to retrieve charset from
1984 * \param op The content encoding operation to perform.
1985 * \return Pointer to charset, or NULL
1986 */
1987static const char *html_encoding(const struct content *c, enum content_encoding_type op)
1988{
1989 html_content *html = (html_content *) c;
1990 static char enc_token[10] = "Encoding0";
1991
1992 assert(html != NULL)((html != ((void*)0)) ? (void) (0) : __assert_fail ("html != NULL"
, "content/handlers/html/html.c", 1992, __extension__ __PRETTY_FUNCTION__
))
;
1993
1994 if (op == CONTENT_ENCODING_SOURCE) {
1995 enc_token[8] = '0' + html->encoding_source;
1996 return messages_get(enc_token);
1997 }
1998
1999 return html->encoding;
2000}
2001
2002
2003/**
2004 * Retrieve framesets used in an HTML document
2005 *
2006 * \param h Content to inspect
2007 * \return Pointer to framesets, or NULL if none
2008 */
2009struct content_html_frames *html_get_frameset(hlcache_handle *h)
2010{
2011 html_content *c = (html_content *) hlcache_handle_get_content(h);
2012
2013 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2013, __extension__ __PRETTY_FUNCTION__
))
;
2014
2015 return c->frameset;
2016}
2017
2018/**
2019 * Retrieve iframes used in an HTML document
2020 *
2021 * \param h Content to inspect
2022 * \return Pointer to iframes, or NULL if none
2023 */
2024struct content_html_iframe *html_get_iframe(hlcache_handle *h)
2025{
2026 html_content *c = (html_content *) hlcache_handle_get_content(h);
2027
2028 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2028, __extension__ __PRETTY_FUNCTION__
))
;
2029
2030 return c->iframe;
2031}
2032
2033/**
2034 * Retrieve an HTML content's base URL
2035 *
2036 * \param h Content to retrieve base target from
2037 * \return Pointer to URL
2038 */
2039nsurl *html_get_base_url(hlcache_handle *h)
2040{
2041 html_content *c = (html_content *) hlcache_handle_get_content(h);
2042
2043 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2043, __extension__ __PRETTY_FUNCTION__
))
;
2044
2045 return c->base_url;
2046}
2047
2048/**
2049 * Retrieve an HTML content's base target
2050 *
2051 * \param h Content to retrieve base target from
2052 * \return Pointer to target, or NULL if none
2053 */
2054const char *html_get_base_target(hlcache_handle *h)
2055{
2056 html_content *c = (html_content *) hlcache_handle_get_content(h);
2057
2058 assert(c != NULL)((c != ((void*)0)) ? (void) (0) : __assert_fail ("c != NULL",
"content/handlers/html/html.c", 2058, __extension__ __PRETTY_FUNCTION__
))
;
2059
2060 return c->base_target;
2061}
2062
2063
2064/**
2065 * Retrieve layout coordinates of box with given id
2066 *
2067 * \param h HTML document to search
2068 * \param frag_id String containing an element id
2069 * \param x Updated to global x coord iff id found
2070 * \param y Updated to global y coord iff id found
2071 * \return true iff id found
2072 */
2073bool_Bool html_get_id_offset(hlcache_handle *h, lwc_string *frag_id, int *x, int *y)
2074{
2075 struct box *pos;
2076 struct box *layout;
2077
2078 if (content_get_type(h) != CONTENT_HTML)
2079 return false0;
2080
2081 layout = html_get_box_tree(h);
2082
2083 if ((pos = box_find_by_id(layout, frag_id)) != 0) {
2084 box_coords(pos, x, y);
2085 return true1;
2086 }
2087 return false0;
2088}
2089
2090bool_Bool html_exec(struct content *c, const char *src, size_t srclen)
2091{
2092 html_content *htmlc = (html_content *)c;
2093 bool_Bool result = false0;
2094 dom_exception err;
2095 dom_html_body_element *body_node;
2096 dom_string *dom_src;
2097 dom_text *text_node;
2098 dom_node *spare_node;
2099 dom_html_script_element *script_node;
2100
2101 if (htmlc->document == NULL((void*)0)) {
2102 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, 2102, }; nslog__log(&_nslog_ctx
, "Unable to exec, no document"); } } while(0)
;
2103 goto out_no_string;
2104 }
2105
2106 err = dom_string_create((const uint8_t *)src, srclen, &dom_src);
2107 if (err != DOM_NO_ERR) {
2108 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, 2108, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not create string"); } } while(0)
;
2109 goto out_no_string;
2110 }
2111
2112 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))
;
2113 if (err != DOM_NO_ERR) {
2114 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, 2114, }; nslog__log(&_nslog_ctx
, "Unable to retrieve body element"); } } while(0)
;
2115 goto out_no_body;
2116 }
2117
2118 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))
;
2119 if (err != DOM_NO_ERR) {
2120 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, 2120, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not create text node"); } } while(0)
;
2121 goto out_no_text_node;
2122 }
2123
2124 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
))
;
2125 if (err != DOM_NO_ERR) {
2126 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, 2126, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not create script node"); } } while(
0)
;
2127 goto out_no_script_node;
2128 }
2129
2130 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))
;
2131 if (err != DOM_NO_ERR) {
2132 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, 2132, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not insert code node into script node"
); } } while(0)
;
2133 goto out_unparented;
2134 }
2135 dom_node_unref(spare_node)dom_node_unref((dom_node *) (spare_node)); /* We do not need the spare ref at all */
2136
2137 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))
;
2138 if (err != DOM_NO_ERR) {
2139 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, 2139, }; nslog__log(&_nslog_ctx
, "Unable to exec, could not insert script node into document body"
); } } while(0)
;
2140 goto out_unparented;
2141 }
2142 dom_node_unref(spare_node)dom_node_unref((dom_node *) (spare_node)); /* Again no need for the spare ref */
2143
2144 /* We successfully inserted the node into the DOM */
2145
2146 result = true1;
2147
2148 /* Now we unwind, starting by removing the script from wherever it
2149 * ended up parented
2150 */
2151
2152 err = dom_node_get_parent_node(script_node, &spare_node)dom_node_get_parent_node( (dom_node *) (script_node), (dom_node
**) (&spare_node))
;
2153 if (err == DOM_NO_ERR && spare_node != NULL((void*)0)) {
2154 dom_node *second_spare;
2155 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))
;
2156 if (err == DOM_NO_ERR) {
2157 dom_node_unref(second_spare)dom_node_unref((dom_node *) (second_spare));
2158 }
2159 dom_node_unref(spare_node)dom_node_unref((dom_node *) (spare_node));
2160 }
2161
2162out_unparented:
2163 dom_node_unref(script_node)dom_node_unref((dom_node *) (script_node));
2164out_no_script_node:
2165 dom_node_unref(text_node)dom_node_unref((dom_node *) (text_node));
2166out_no_text_node:
2167 dom_node_unref(body_node)dom_node_unref((dom_node *) (body_node));
2168out_no_body:
2169 dom_string_unref(dom_src);
2170out_no_string:
2171 return result;
2172}
2173
2174/* See \ref content_saw_insecure_objects */
2175static bool_Bool
2176html_saw_insecure_objects(struct content *c)
2177{
2178 html_content *htmlc = (html_content *)c;
2179 struct content_html_object *obj = htmlc->object_list;
2180
2181 /* Check through the object list */
2182 while (obj != NULL((void*)0)) {
2183 if (obj->content != NULL((void*)0)) {
2184 if (content_saw_insecure_objects(obj->content))
2185 return true1;
2186 }
2187 obj = obj->next;
2188 }
2189
2190 /* Now check the script list */
2191 if (html_saw_insecure_scripts(htmlc)) {
2192 return true1;
2193 }
2194
2195 /* Now check stylesheets */
2196 if (html_css_saw_insecure_stylesheets(htmlc)) {
2197 return true1;
2198 }
2199
2200 return false0;
2201}
2202
2203/**
2204 * Compute the type of a content
2205 *
2206 * \return CONTENT_HTML
2207 */
2208static content_type html_content_type(void)
2209{
2210 return CONTENT_HTML;
2211}
2212
2213
2214static void html_fini(void)
2215{
2216 html_css_fini();
2217}
2218
2219/**
2220 * Finds all occurrences of a given string in an html box
2221 *
2222 * \param pattern the string pattern to search for
2223 * \param p_len pattern length
2224 * \param cur pointer to the current box
2225 * \param case_sens whether to perform a case sensitive search
2226 * \param context The search context to add the entry to.
2227 * \return true on success, false on memory allocation failure
2228 */
2229static nserror
2230find_occurrences_html_box(const char *pattern,
2231 int p_len,
2232 struct box *cur,
2233 bool_Bool case_sens,
2234 struct textsearch_context *context)
2235{
2236 struct box *a;
2237 nserror res = NSERROR_OK;
2238
2239 /* ignore this box, if there's no visible text */
2240 if (!cur->object && cur->text) {
2241 const char *text = cur->text;
2242 unsigned length = cur->length;
2243
2244 while (length > 0) {
2245 unsigned match_length;
2246 unsigned match_offset;
2247 const char *new_text;
2248 const char *pos;
2249
2250 pos = content_textsearch_find_pattern(text,
2251 length,
2252 pattern,
2253 p_len,
2254 case_sens,
2255 &match_length);
2256 if (!pos)
2257 break;
2258
2259 /* found string in box => add to list */
2260 match_offset = pos - cur->text;
2261
2262 res = content_textsearch_add_match(context,
2263 cur->byte_offset + match_offset,
2264 cur->byte_offset + match_offset + match_length,
2265 cur,
2266 cur);
2267 if (res != NSERROR_OK) {
2268 return res;
2269 }
2270
2271 new_text = pos + match_length;
2272 length -= (new_text - text);
2273 text = new_text;
2274 }
2275 }
2276
2277 /* and recurse */
2278 for (a = cur->children; a; a = a->next) {
2279 res = find_occurrences_html_box(pattern,
2280 p_len,
2281 a,
2282 case_sens,
2283 context);
2284 if (res != NSERROR_OK) {
2285 return res;
2286 }
2287 }
2288
2289 return res;
2290}
2291
2292/**
2293 * Finds all occurrences of a given string in the html box tree
2294 *
2295 * \param pattern the string pattern to search for
2296 * \param p_len pattern length
2297 * \param c The content to search
2298 * \param csens whether to perform a case sensitive search
2299 * \param context The search context to add the entry to.
2300 * \return true on success, false on memory allocation failure
2301 */
2302static nserror
2303html_textsearch_find(struct content *c,
2304 struct textsearch_context *context,
2305 const char *pattern,
2306 int p_len,
2307 bool_Bool csens)
2308{
2309 html_content *html = (html_content *)c;
2310
2311 if (html->layout == NULL((void*)0)) {
2312 return NSERROR_INVALID;
2313 }
2314
2315 return find_occurrences_html_box(pattern,
2316 p_len,
2317 html->layout,
2318 csens,
2319 context);
2320}
2321
2322
2323static nserror
2324html_textsearch_bounds(struct content *c,
2325 unsigned start_idx,
2326 unsigned end_idx,
2327 struct box *start_box,
2328 struct box *end_box,
2329 struct rect *bounds)
2330{
2331 /* get box position and jump to it */
2332 box_coords(start_box, &bounds->x0, &bounds->y0);
2333 /* \todo: move x0 in by correct idx */
2334 box_coords(end_box, &bounds->x1, &bounds->y1);
2335 /* \todo: move x1 in by correct idx */
2336 bounds->x1 += end_box->width;
2337 bounds->y1 += end_box->height;
2338
2339 return NSERROR_OK;
2340}
2341
2342
2343/**
2344 * HTML content handler function table
2345 */
2346static const content_handler html_content_handler = {
2347 .fini = html_fini,
2348 .create = html_create,
2349 .process_data = html_process_data,
2350 .data_complete = html_convert,
2351 .reformat = html_reformat,
2352 .destroy = html_destroy,
2353 .stop = html_stop,
2354 .mouse_track = html_mouse_track,
2355 .mouse_action = html_mouse_action,
2356 .keypress = html_keypress,
2357 .redraw = html_redraw,
2358 .open = html_open,
2359 .close = html_close,
2360 .get_selection = html_get_selection,
2361 .clear_selection = html_clear_selection,
2362 .get_contextual_content = html_get_contextual_content,
2363 .scroll_at_point = html_scroll_at_point,
2364 .drop_file_at_point = html_drop_file_at_point,
2365 .debug_dump = html_debug_dump,
2366 .debug = html_debug,
2367 .clone = html_clone,
2368 .get_encoding = html_encoding,
2369 .type = html_content_type,
2370 .exec = html_exec,
2371 .saw_insecure_objects = html_saw_insecure_objects,
2372 .textsearch_find = html_textsearch_find,
2373 .textsearch_bounds = html_textsearch_bounds,
2374 .textselection_redraw = html_textselection_redraw,
2375 .textselection_copy = html_textselection_copy,
2376 .textselection_get_end = html_textselection_get_end,
2377 .no_share = true1,
2378};
2379
2380
2381/* exported function documented in html/html.h */
2382nserror html_init(void)
2383{
2384 uint32_t i;
2385 nserror error;
2386
2387 error = html_css_init();
2388 if (error != NSERROR_OK)
2389 goto error;
2390
2391 for (i = 0; i < NOF_ELEMENTS(html_types)(sizeof(html_types)/sizeof(*(html_types))); i++) {
2392 error = content_factory_register_handler(html_types[i],
2393 &html_content_handler);
2394 if (error != NSERROR_OK)
2395 goto error;
2396 }
2397
2398 return NSERROR_OK;
2399
2400error:
2401 html_fini();
2402
2403 return error;
2404}