2007-08-28 15:28:32 -04:00
|
|
|
/** Generic renderer multiplexer
|
2007-07-27 12:45:02 -04:00
|
|
|
* @file */
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "cache/cache.h"
|
|
|
|
#include "config/options.h"
|
|
|
|
#include "document/document.h"
|
|
|
|
#include "document/dom/renderer.h"
|
2021-07-01 14:18:29 -04:00
|
|
|
#include "document/gemini/renderer.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "document/html/frames.h"
|
2021-07-27 15:05:07 -04:00
|
|
|
#include "document/html/iframes.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "document/html/renderer.h"
|
|
|
|
#include "document/plain/renderer.h"
|
2021-06-13 10:41:54 -04:00
|
|
|
#ifdef CONFIG_XML
|
|
|
|
#include "document/xml/renderer.h"
|
2021-06-20 16:38:17 -04:00
|
|
|
#include "document/xml/renderer2.h"
|
2021-06-13 10:41:54 -04:00
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "document/renderer.h"
|
|
|
|
#include "document/view.h"
|
2021-07-03 03:45:11 -04:00
|
|
|
#ifdef CONFIG_ECMASCRIPT
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "ecmascript/ecmascript.h"
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ECMASCRIPT_SMJS
|
2021-06-21 15:01:37 -04:00
|
|
|
#include "ecmascript/spidermonkey/document.h"
|
2021-07-03 03:45:11 -04:00
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "encoding/encoding.h"
|
|
|
|
#include "intl/charsets.h"
|
|
|
|
#include "main/main.h"
|
|
|
|
#include "main/object.h"
|
|
|
|
#include "protocol/header.h"
|
|
|
|
#include "protocol/protocol.h"
|
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "session/location.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "terminal/window.h"
|
|
|
|
#include "util/error.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
2008-06-10 02:41:34 -04:00
|
|
|
#include "viewer/text/form.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "viewer/text/view.h"
|
|
|
|
#include "viewer/text/vs.h"
|
|
|
|
|
|
|
|
|
2021-10-17 12:17:48 -04:00
|
|
|
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
|
2007-07-27 12:45:02 -04:00
|
|
|
/** @todo XXX: This function is de facto obsolete, since we do not need to copy
|
2005-09-15 09:58:31 -04:00
|
|
|
* snippets around anymore (we process them in one go after the document is
|
|
|
|
* loaded; gradual processing was practically impossible because the snippets
|
|
|
|
* could reorder randomly during the loading - consider i.e.
|
2007-07-27 12:45:02 -04:00
|
|
|
* @<body onLoad>@<script>@</body>: first just @<body> is loaded, but then the
|
|
|
|
* rest of the document is loaded and @<script> gets before @<body>; do not even
|
2005-09-15 09:58:31 -04:00
|
|
|
* imagine the trouble with rewritten (through scripting hooks) documents;
|
|
|
|
* besides, implementing document.write() will be much simpler).
|
|
|
|
* But I want to take no risk by reworking that now. --pasky */
|
|
|
|
static void
|
|
|
|
add_snippets(struct ecmascript_interpreter *interpreter,
|
2007-07-26 15:39:08 -04:00
|
|
|
LIST_OF(struct string_list_item) *doc_snippets,
|
|
|
|
LIST_OF(struct string_list_item) *queued_snippets)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2022-02-17 15:21:50 -05:00
|
|
|
struct string_list_item *doc_current = (struct string_list_item *)doc_snippets->next;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#ifdef CONFIG_LEDS
|
|
|
|
if (list_empty(*queued_snippets) && interpreter->vs->doc_view->session)
|
|
|
|
unset_led_value(interpreter->vs->doc_view->session->status.ecmascript_led);
|
|
|
|
#endif
|
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
if (list_empty(*doc_snippets)
|
|
|
|
|| !get_opt_bool("ecmascript.enable", NULL))
|
2005-09-15 09:58:31 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* We do this all only once per view_state now. */
|
|
|
|
if (!list_empty(*queued_snippets)) {
|
|
|
|
/* So if we already did it, we shouldn't need to do it again.
|
|
|
|
* This is the case of moving around in history - we have all
|
|
|
|
* what happenned recorded in the view_state and needn't bother
|
|
|
|
* again. */
|
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
/* Hopefully. */
|
|
|
|
struct string_list_item *iterator = queued_snippets->next;
|
|
|
|
|
|
|
|
while (iterator != (struct string_list_item *) queued_snippets) {
|
|
|
|
if (doc_current == (struct string_list_item *) doc_snippets) {
|
|
|
|
INTERNAL("add_snippets(): doc_snippets shorter than queued_snippets!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
DBG("Comparing snippets\n%.*s\n###### vs #####\n%.*s\n #####",
|
|
|
|
iterator->string.length, iterator->string.source,
|
|
|
|
doc_current->string.length, doc_current->string.source);
|
|
|
|
#endif
|
|
|
|
assert(!strlcmp(iterator->string.source,
|
|
|
|
iterator->string.length,
|
|
|
|
doc_current->string.source,
|
|
|
|
doc_current->string.length));
|
|
|
|
|
|
|
|
doc_current = doc_current->next;
|
|
|
|
iterator = iterator->next;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(doc_current);
|
|
|
|
for (; doc_current != (struct string_list_item *) doc_snippets;
|
|
|
|
doc_current = doc_current->next) {
|
|
|
|
add_to_string_list(queued_snippets, doc_current->string.source,
|
|
|
|
doc_current->string.length);
|
|
|
|
#if 0
|
|
|
|
DBG("Adding snippet\n%.*s\n #####",
|
|
|
|
doc_current->string.length,
|
|
|
|
doc_current->string.source);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_snippets(struct ecmascript_interpreter *interpreter,
|
2007-07-26 15:39:08 -04:00
|
|
|
LIST_OF(struct string_list_item) *snippets,
|
|
|
|
struct string_list_item **current)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
|
|
|
if (!*current)
|
2022-02-17 14:53:44 -05:00
|
|
|
*current = (struct string_list_item *)snippets->next;
|
2005-09-15 09:58:31 -04:00
|
|
|
for (; *current != (struct string_list_item *) snippets;
|
|
|
|
(*current) = (*current)->next) {
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string *string = &(*current)->string;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *uristring;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct uri *uri;
|
|
|
|
struct cache_entry *cached;
|
|
|
|
struct fragment *fragment;
|
|
|
|
|
|
|
|
if (string->length == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*string->source != '^') {
|
|
|
|
/* Evaluate <script>code</script> snippet */
|
2006-01-27 06:07:45 -05:00
|
|
|
ecmascript_eval(interpreter, string, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Eval external <script src="reference"></script> snippet */
|
|
|
|
uristring = string->source + 1;
|
|
|
|
if (!*uristring) continue;
|
|
|
|
|
|
|
|
uri = get_uri(uristring, URI_BASE);
|
|
|
|
if (!uri) continue;
|
|
|
|
|
|
|
|
cached = get_redirected_cache_entry(uri);
|
|
|
|
done_uri(uri);
|
|
|
|
|
|
|
|
if (!cached) {
|
|
|
|
/* At this time (!gradual_rerendering), we should've
|
|
|
|
* already retrieved this though. So it must've been
|
|
|
|
* that it went away because unused and the cache was
|
|
|
|
* already too full. */
|
|
|
|
#if 0
|
|
|
|
/* Disabled because gradual rerendering can be triggered
|
|
|
|
* by numerous events other than a ecmascript reference
|
|
|
|
* completing like the original document and CSS. Problem
|
|
|
|
* is that we should never continue this loop but rather
|
|
|
|
* break out if that is the case. Somehow we need to
|
|
|
|
* be able to derive URI loading problems at this point
|
|
|
|
* or maybe remove reference snippets if they fail to load.
|
|
|
|
*
|
|
|
|
* This FIFO queue handling should be used for also CSS
|
|
|
|
* imports so it would be cool if it could be general
|
|
|
|
* enough for that. Using it for frames with the FIFOing
|
|
|
|
* disabled probably wouldn't hurt either.
|
|
|
|
*
|
|
|
|
* To top this thing off it would be nice if it also
|
|
|
|
* handled dependency tracking between references so that
|
|
|
|
* CSS documents will not disappear from the cache
|
|
|
|
* before all referencing HTML documents has been deleted
|
|
|
|
* from it.
|
|
|
|
*
|
|
|
|
* Reported as bug 533. */
|
|
|
|
/* Pasky's explanation: If we get the doc in a single
|
|
|
|
* shot, before calling draw_formatted() we didn't have
|
|
|
|
* anything additional queued for loading and the cache
|
|
|
|
* entry was already loaded, so we didn't get
|
|
|
|
* gradual_loading set. But then while parsing the
|
|
|
|
* document we got some external references and trying
|
|
|
|
* to process them right now. Boom.
|
|
|
|
*
|
|
|
|
* The obvious solution would be to always call
|
|
|
|
* draw_formatted() with gradual_loading in
|
|
|
|
* doc_loading_callback() and if we are sure the
|
|
|
|
* loading is really over, call it one more time
|
|
|
|
* without gradual_loading set. I'm not sure about
|
|
|
|
* the implications though so I won't do it before
|
|
|
|
* 0.10.0. --pasky */
|
|
|
|
ERROR("The script of %s was lost in too full a cache!",
|
|
|
|
uristring);
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment = get_cache_fragment(cached);
|
|
|
|
if (fragment) {
|
2022-01-17 11:07:46 -05:00
|
|
|
struct string code = INIT_STRING(fragment->data, (int)fragment->length);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-01-27 06:07:45 -05:00
|
|
|
ecmascript_eval(interpreter, &code, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
2021-07-20 04:05:58 -04:00
|
|
|
check_for_rerender(interpreter, "eval");
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
render_encoded_document(struct cache_entry *cached, struct document *document)
|
|
|
|
{
|
|
|
|
struct uri *uri = cached->uri;
|
2022-01-28 10:17:25 -05:00
|
|
|
stream_encoding_T encoding = ENCODING_NONE;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct fragment *fragment = get_cache_fragment(cached);
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string buffer = INIT_STRING("", 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Even empty documents have to be rendered so that info in the protocol
|
|
|
|
* header, such as refresh info, get processed. (bug 625) */
|
|
|
|
if (fragment) {
|
|
|
|
buffer.source = fragment->data;
|
|
|
|
buffer.length = fragment->length;
|
|
|
|
}
|
|
|
|
|
2005-12-18 11:03:34 -05:00
|
|
|
if (uri->protocol != PROTOCOL_FILE) {
|
2021-01-02 10:20:27 -05:00
|
|
|
char *extension = get_extension_from_uri(uri);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-18 11:03:34 -05:00
|
|
|
if (extension) {
|
|
|
|
encoding = guess_encoding(extension);
|
|
|
|
mem_free(extension);
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2005-12-18 11:03:34 -05:00
|
|
|
if (encoding != ENCODING_NONE) {
|
|
|
|
int length = 0;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *source;
|
2010-09-24 10:12:35 -04:00
|
|
|
struct stream_encoded *stream = open_encoded(-1, encoding);
|
2005-12-18 11:03:34 -05:00
|
|
|
|
2010-09-24 10:12:35 -04:00
|
|
|
if (!stream) {
|
2005-12-18 11:03:34 -05:00
|
|
|
encoding = ENCODING_NONE;
|
2010-09-24 10:12:35 -04:00
|
|
|
} else {
|
|
|
|
source = decode_encoded_buffer(stream, encoding, buffer.source,
|
|
|
|
buffer.length, &length);
|
|
|
|
close_encoded(stream);
|
|
|
|
|
|
|
|
if (source) {
|
|
|
|
buffer.source = source;
|
|
|
|
buffer.length = length;
|
|
|
|
} else {
|
|
|
|
encoding = ENCODING_NONE;
|
|
|
|
}
|
2005-12-18 11:03:34 -05:00
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
2021-06-13 10:41:54 -04:00
|
|
|
#ifdef CONFIG_XML
|
|
|
|
if (document->options.plain && cached->content_type
|
|
|
|
&& (!c_strcasecmp("text/html", cached->content_type)
|
|
|
|
|| !c_strcasecmp("application/xhtml+xml", cached->content_type))) {
|
|
|
|
render_source_document_cxx(cached, document, &buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
if (document->options.plain) {
|
|
|
|
#ifdef CONFIG_DOM
|
|
|
|
if (cached->content_type
|
2008-10-18 21:25:00 -04:00
|
|
|
&& (!c_strcasecmp("text/html", cached->content_type)
|
|
|
|
|| !c_strcasecmp("application/xhtml+xml", cached->content_type)
|
|
|
|
|| !c_strcasecmp("application/docbook+xml", cached->content_type)
|
|
|
|
|| !c_strcasecmp("application/rss+xml", cached->content_type)
|
|
|
|
|| !c_strcasecmp("application/xbel+xml", cached->content_type)
|
|
|
|
|| !c_strcasecmp("application/x-xbel", cached->content_type)
|
|
|
|
|| !c_strcasecmp("application/xbel", cached->content_type)))
|
2005-09-15 09:58:31 -04:00
|
|
|
render_dom_document(cached, document, &buffer);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
render_plain_document(cached, document, &buffer);
|
|
|
|
|
|
|
|
} else {
|
2006-01-07 21:44:23 -05:00
|
|
|
#ifdef CONFIG_DOM
|
|
|
|
if (cached->content_type
|
2008-10-18 21:25:00 -04:00
|
|
|
&& (!c_strlcasecmp("application/rss+xml", 19, cached->content_type, -1)))
|
2006-01-07 21:44:23 -05:00
|
|
|
render_dom_document(cached, document, &buffer);
|
|
|
|
else
|
|
|
|
#endif
|
2021-07-01 14:18:29 -04:00
|
|
|
if (cached->content_type
|
|
|
|
&& (!c_strlcasecmp("text/gemini", 11, cached->content_type, -1)))
|
|
|
|
render_gemini_document(cached, document, &buffer);
|
|
|
|
else
|
2021-06-20 16:38:17 -04:00
|
|
|
#ifdef CONFIG_XML
|
2021-07-06 08:55:28 -04:00
|
|
|
if (false) render_xhtml_document(cached, document, &buffer);
|
2021-06-20 16:38:17 -04:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
render_html_document(cached, document, &buffer);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (encoding != ENCODING_NONE) {
|
|
|
|
done_string(&buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
render_document(struct view_state *vs, struct document_view *doc_view,
|
|
|
|
struct document_options *options)
|
|
|
|
{
|
2021-01-02 10:20:27 -05:00
|
|
|
char *name;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct document *document;
|
|
|
|
struct cache_entry *cached;
|
|
|
|
|
|
|
|
assert(vs && doc_view && options);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
DBG("(Re%u)Rendering %s on doc_view %p [%s] while attaching it to %p",
|
|
|
|
options->gradual_rerendering, struri(vs->uri),
|
|
|
|
doc_view, doc_view->name, vs);
|
|
|
|
#endif
|
2006-02-12 10:03:12 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
name = doc_view->name;
|
|
|
|
doc_view->name = NULL;
|
|
|
|
|
|
|
|
detach_formatted(doc_view);
|
|
|
|
|
|
|
|
doc_view->name = name;
|
|
|
|
doc_view->vs = vs;
|
|
|
|
doc_view->last_x = doc_view->last_y = -1;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* This is a nice idea, but doesn't always work: in particular when
|
|
|
|
* there's a frame name conflict. You loaded something to the vs'
|
|
|
|
* frame, but later something tried to get loaded to a frame with
|
|
|
|
* the same name and we got back this frame again, so we are now
|
|
|
|
* overriding the original document with a cuckoo. This assert()ion
|
|
|
|
* should be re-enabled when we start to get this right (which is
|
|
|
|
* very complex, but someone should rewrite the frames support
|
|
|
|
* anyway). --pasky */
|
|
|
|
assert(!vs->doc_view);
|
|
|
|
#else
|
|
|
|
if (vs->doc_view) {
|
|
|
|
/* It will be still detached, no worries - hopefully it still
|
|
|
|
* resides in ses->scrn_frames. */
|
|
|
|
assert(vs->doc_view->vs == vs);
|
|
|
|
vs->doc_view->used = 0; /* A bit risky, but... */
|
|
|
|
vs->doc_view->vs = NULL;
|
|
|
|
vs->doc_view = NULL;
|
2021-10-17 12:17:48 -04:00
|
|
|
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
|
2005-09-15 09:58:31 -04:00
|
|
|
vs->ecmascript_fragile = 1; /* And is this good? ;-) */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
vs->doc_view = doc_view;
|
|
|
|
|
|
|
|
cached = find_in_cache(vs->uri);
|
|
|
|
if (!cached) {
|
|
|
|
INTERNAL("document %s to format not found", struri(vs->uri));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document = get_cached_document(cached, options);
|
|
|
|
if (document) {
|
|
|
|
doc_view->document = document;
|
|
|
|
} else {
|
|
|
|
document = init_document(cached, options);
|
|
|
|
if (!document) return;
|
|
|
|
doc_view->document = document;
|
|
|
|
|
2008-06-10 02:41:34 -04:00
|
|
|
if (doc_view->session
|
|
|
|
&& doc_view->session->reloadlevel > CACHE_MODE_NORMAL)
|
2008-07-18 12:16:34 -04:00
|
|
|
for (; vs->form_info_len > 0; vs->form_info_len--)
|
|
|
|
done_form_state(&vs->form_info[vs->form_info_len - 1]);
|
2008-06-10 02:41:34 -04:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
shrink_memory(0);
|
2006-02-12 10:03:12 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
render_encoded_document(cached, document);
|
|
|
|
sort_links(document);
|
|
|
|
if (!document->title) {
|
2022-01-28 09:56:59 -05:00
|
|
|
uri_component_T components;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (document->uri->protocol == PROTOCOL_FILE) {
|
|
|
|
components = URI_PATH;
|
|
|
|
} else {
|
|
|
|
components = URI_PUBLIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
document->title = get_uri_string(document->uri, components);
|
2006-03-12 19:54:34 -05:00
|
|
|
if (document->title) {
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2006-03-12 19:54:34 -05:00
|
|
|
if (doc_view->document->options.utf8)
|
|
|
|
decode_uri(document->title);
|
|
|
|
else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-12 19:54:34 -05:00
|
|
|
decode_uri_for_display(document->title);
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_CSS
|
|
|
|
document->css_magic = get_document_css_magic(document);
|
|
|
|
#endif
|
|
|
|
}
|
2021-10-17 12:17:48 -04:00
|
|
|
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!vs->ecmascript_fragile)
|
|
|
|
assert(vs->ecmascript);
|
2020-10-05 14:14:55 -04:00
|
|
|
if (!options->dump && !options->gradual_rerendering) {
|
2005-09-15 09:58:31 -04:00
|
|
|
/* We also reset the state if the underlying document changed
|
|
|
|
* from the last time we did the snippets. This may be
|
|
|
|
* triggered i.e. when redrawing a document which has been
|
|
|
|
* reloaded in a different tab meanwhile (OTOH we don't want
|
|
|
|
* to reset the state if we are redrawing a document we have
|
|
|
|
* already drawn before).
|
|
|
|
*
|
|
|
|
* (vs->ecmascript->onload_snippets_owner) check may be
|
|
|
|
* superfluous since we should always have
|
|
|
|
* vs->ecmascript_fragile set in those cases; that's why we
|
|
|
|
* don't ever bother to re-zero it if we are suddenly doing
|
|
|
|
* gradual rendering again.
|
|
|
|
*
|
|
|
|
* XXX: What happens if a document is still loading in the
|
|
|
|
* other tab when we press ^L here? */
|
|
|
|
if (vs->ecmascript_fragile
|
2008-04-20 16:25:10 -04:00
|
|
|
|| (vs->ecmascript
|
2008-08-03 14:27:56 -04:00
|
|
|
&& vs->ecmascript->onload_snippets_cache_id
|
|
|
|
&& document->cache_id != vs->ecmascript->onload_snippets_cache_id))
|
2005-09-15 09:58:31 -04:00
|
|
|
ecmascript_reset_state(vs);
|
2009-06-28 04:17:06 -04:00
|
|
|
/* If ecmascript_reset_state cannot construct a new
|
|
|
|
* ECMAScript interpreter, it sets vs->ecmascript =
|
|
|
|
* NULL and vs->ecmascript_fragile = 1. */
|
|
|
|
if (vs->ecmascript) {
|
|
|
|
vs->ecmascript->onload_snippets_cache_id = document->cache_id;
|
|
|
|
|
|
|
|
/* Passing of the onload_snippets pointers
|
|
|
|
* gives *_snippets() some feeling of
|
|
|
|
* universality, shall we ever get any other
|
|
|
|
* snippets (?). */
|
|
|
|
add_snippets(vs->ecmascript,
|
|
|
|
&document->onload_snippets,
|
|
|
|
&vs->ecmascript->onload_snippets);
|
|
|
|
process_snippets(vs->ecmascript,
|
|
|
|
&vs->ecmascript->onload_snippets,
|
|
|
|
&vs->ecmascript->current_onload_snippet);
|
2021-10-07 12:27:21 -04:00
|
|
|
check_for_rerender(vs->ecmascript, "process_snippets");
|
2009-06-28 04:17:06 -04:00
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If we do not care about the height and width of the document
|
|
|
|
* just use the setup values. */
|
|
|
|
|
|
|
|
copy_box(&doc_view->box, &document->options.box);
|
|
|
|
|
|
|
|
if (!document->options.needs_width)
|
|
|
|
doc_view->box.width = options->box.width;
|
|
|
|
|
|
|
|
if (!document->options.needs_height)
|
|
|
|
doc_view->box.height = options->box.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
render_document_frames(struct session *ses, int no_cache)
|
|
|
|
{
|
|
|
|
struct document_options doc_opts;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct document_view *current_doc_view = NULL;
|
|
|
|
struct view_state *vs = NULL;
|
|
|
|
|
|
|
|
if (!ses->doc_view) {
|
2022-01-16 15:08:50 -05:00
|
|
|
ses->doc_view = (struct document_view *)mem_calloc(1, sizeof(*ses->doc_view));
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!ses->doc_view) return;
|
|
|
|
ses->doc_view->session = ses;
|
|
|
|
ses->doc_view->search_word = &ses->search_word;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_location(ses)) vs = &cur_loc(ses)->vs;
|
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
init_document_options(ses, &doc_opts);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
set_box(&doc_opts.box, 0, 0,
|
|
|
|
ses->tab->term->width, ses->tab->term->height);
|
|
|
|
|
|
|
|
if (ses->status.show_title_bar) {
|
|
|
|
doc_opts.box.y++;
|
|
|
|
doc_opts.box.height--;
|
|
|
|
}
|
|
|
|
if (ses->status.show_status_bar) doc_opts.box.height--;
|
2006-03-04 04:24:37 -05:00
|
|
|
if (ses->status.show_tabs_bar) {
|
|
|
|
doc_opts.box.height--;
|
|
|
|
if (ses->status.show_tabs_bar_at_top) doc_opts.box.y++;
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2007-08-28 12:41:18 -04:00
|
|
|
doc_opts.color_mode = get_opt_int_tree(ses->tab->term->spec, "colors",
|
|
|
|
NULL);
|
|
|
|
if (!get_opt_bool_tree(ses->tab->term->spec, "underline", NULL))
|
2005-09-15 09:58:31 -04:00
|
|
|
doc_opts.color_flags |= COLOR_ENHANCE_UNDERLINE;
|
|
|
|
|
2008-12-28 10:42:29 -05:00
|
|
|
doc_opts.cp = get_terminal_codepage(ses->tab->term);
|
2005-09-15 09:58:31 -04:00
|
|
|
doc_opts.no_cache = no_cache & 1;
|
|
|
|
doc_opts.gradual_rerendering = !!(no_cache & 2);
|
|
|
|
|
|
|
|
if (vs) {
|
|
|
|
if (vs->plain < 0) vs->plain = 0;
|
|
|
|
doc_opts.plain = vs->plain;
|
|
|
|
doc_opts.wrap = vs->wrap;
|
|
|
|
} else {
|
|
|
|
doc_opts.plain = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (doc_view, ses->scrn_frames) doc_view->used = 0;
|
2021-07-31 09:24:36 -04:00
|
|
|
foreach (doc_view, ses->scrn_iframes) doc_view->used = 0;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (vs) render_document(vs, ses->doc_view, &doc_opts);
|
|
|
|
|
|
|
|
if (document_has_frames(ses->doc_view->document)) {
|
|
|
|
current_doc_view = current_frame(ses);
|
|
|
|
format_frames(ses, ses->doc_view->document->frame_desc, &doc_opts, 0);
|
|
|
|
}
|
|
|
|
|
2021-07-26 15:28:19 -04:00
|
|
|
if (document_has_iframes(ses->doc_view->document)) {
|
|
|
|
format_iframes(ses, ses->doc_view->document->iframe_desc, &doc_opts, 0);
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
foreach (doc_view, ses->scrn_frames) {
|
|
|
|
struct document_view *prev_doc_view = doc_view->prev;
|
|
|
|
|
|
|
|
if (doc_view->used) continue;
|
|
|
|
|
|
|
|
detach_formatted(doc_view);
|
|
|
|
del_from_list(doc_view);
|
|
|
|
mem_free(doc_view);
|
|
|
|
doc_view = prev_doc_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_doc_view) {
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
foreach (doc_view, ses->scrn_frames) {
|
|
|
|
if (document_has_frames(doc_view->document)) continue;
|
|
|
|
if (doc_view == current_doc_view) {
|
|
|
|
cur_loc(ses)->vs.current_link = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Don't cast qsort comparison function pointers.
Instead, convert the element pointers inside the comparison functions.
The last argument of qsort() is supposed to be of type
int (*)(const void *, const void *). Previously, comp_links() was
defined to take struct link * instead of const void *, and the type
mismatch was silenced by casting the function pointer to void *.
This was in principle not portable because:
(1) The different pointer types may have different representations.
In a word-oriented machine, the const void * might include a byte
selector while the struct link * might not.
(2) Casting a function pointer to a data pointer can lose bits in some
memory models. Apparently this does not occur in POSIX-conforming
systems though, as dlsym() would fail if it did.
This commit also fixes hits_cmp() and compare_dir_entries(), which
had similar problems. However, I'm leaving alias_compare() in
src/intl/gettext/localealias.c unchanged for now, so as not to diverge
from the GNU version.
I also checked the bsearch() calls but they were all okay, apart from
one that used the alias_compare() mentioned above.
2007-10-05 22:59:20 -04:00
|
|
|
/* comparison function for qsort() */
|
2005-09-15 09:58:31 -04:00
|
|
|
static int
|
Don't cast qsort comparison function pointers.
Instead, convert the element pointers inside the comparison functions.
The last argument of qsort() is supposed to be of type
int (*)(const void *, const void *). Previously, comp_links() was
defined to take struct link * instead of const void *, and the type
mismatch was silenced by casting the function pointer to void *.
This was in principle not portable because:
(1) The different pointer types may have different representations.
In a word-oriented machine, the const void * might include a byte
selector while the struct link * might not.
(2) Casting a function pointer to a data pointer can lose bits in some
memory models. Apparently this does not occur in POSIX-conforming
systems though, as dlsym() would fail if it did.
This commit also fixes hits_cmp() and compare_dir_entries(), which
had similar problems. However, I'm leaving alias_compare() in
src/intl/gettext/localealias.c unchanged for now, so as not to diverge
from the GNU version.
I also checked the bsearch() calls but they were all okay, apart from
one that used the alias_compare() mentioned above.
2007-10-05 22:59:20 -04:00
|
|
|
comp_links(const void *v1, const void *v2)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2022-01-25 11:52:09 -05:00
|
|
|
const struct link *l1 = (const struct link *)v1, *l2 = (const struct link *)v2;
|
Don't cast qsort comparison function pointers.
Instead, convert the element pointers inside the comparison functions.
The last argument of qsort() is supposed to be of type
int (*)(const void *, const void *). Previously, comp_links() was
defined to take struct link * instead of const void *, and the type
mismatch was silenced by casting the function pointer to void *.
This was in principle not portable because:
(1) The different pointer types may have different representations.
In a word-oriented machine, the const void * might include a byte
selector while the struct link * might not.
(2) Casting a function pointer to a data pointer can lose bits in some
memory models. Apparently this does not occur in POSIX-conforming
systems though, as dlsym() would fail if it did.
This commit also fixes hits_cmp() and compare_dir_entries(), which
had similar problems. However, I'm leaving alias_compare() in
src/intl/gettext/localealias.c unchanged for now, so as not to diverge
from the GNU version.
I also checked the bsearch() calls but they were all okay, apart from
one that used the alias_compare() mentioned above.
2007-10-05 22:59:20 -04:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
assert(l1 && l2);
|
|
|
|
if_assert_failed return 0;
|
|
|
|
return (l1->number - l2->number);
|
|
|
|
}
|
|
|
|
|
2006-01-28 08:13:41 -05:00
|
|
|
void
|
2005-09-15 09:58:31 -04:00
|
|
|
sort_links(struct document *document)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(document);
|
|
|
|
if_assert_failed return;
|
|
|
|
if (!document->nlinks) return;
|
|
|
|
|
2006-01-28 08:13:41 -05:00
|
|
|
if (document->links_sorted) return;
|
2005-09-15 09:58:31 -04:00
|
|
|
assert(document->links);
|
|
|
|
if_assert_failed return;
|
|
|
|
|
|
|
|
qsort(document->links, document->nlinks, sizeof(*document->links),
|
Don't cast qsort comparison function pointers.
Instead, convert the element pointers inside the comparison functions.
The last argument of qsort() is supposed to be of type
int (*)(const void *, const void *). Previously, comp_links() was
defined to take struct link * instead of const void *, and the type
mismatch was silenced by casting the function pointer to void *.
This was in principle not portable because:
(1) The different pointer types may have different representations.
In a word-oriented machine, the const void * might include a byte
selector while the struct link * might not.
(2) Casting a function pointer to a data pointer can lose bits in some
memory models. Apparently this does not occur in POSIX-conforming
systems though, as dlsym() would fail if it did.
This commit also fixes hits_cmp() and compare_dir_entries(), which
had similar problems. However, I'm leaving alias_compare() in
src/intl/gettext/localealias.c unchanged for now, so as not to diverge
from the GNU version.
I also checked the bsearch() calls but they were all okay, apart from
one that used the alias_compare() mentioned above.
2007-10-05 22:59:20 -04:00
|
|
|
comp_links);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!document->height) return;
|
|
|
|
|
2006-02-03 15:12:24 -05:00
|
|
|
mem_free_if(document->lines1);
|
2022-01-16 15:08:50 -05:00
|
|
|
document->lines1 = (struct link **)mem_calloc(document->height, sizeof(*document->lines1));
|
2006-02-03 15:12:24 -05:00
|
|
|
mem_free_if(document->lines2);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!document->lines1) return;
|
2022-01-16 15:08:50 -05:00
|
|
|
document->lines2 = (struct link **)mem_calloc(document->height, sizeof(*document->lines2));
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!document->lines2) {
|
|
|
|
mem_free(document->lines1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < document->nlinks; i++) {
|
|
|
|
struct link *link = &document->links[i];
|
|
|
|
int p, q, j;
|
|
|
|
|
|
|
|
if (!link->npoints) {
|
|
|
|
done_link_members(link);
|
|
|
|
memmove(link, link + 1,
|
|
|
|
(document->nlinks - i - 1) * sizeof(*link));
|
|
|
|
document->nlinks--;
|
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
p = link->points[0].y;
|
|
|
|
q = link->points[link->npoints - 1].y;
|
|
|
|
if (p > q) j = p, p = q, q = j;
|
|
|
|
for (j = p; j <= q; j++) {
|
|
|
|
assertm(j < document->height, "link out of screen");
|
|
|
|
if_assert_failed continue;
|
|
|
|
document->lines2[j] = &document->links[i];
|
|
|
|
if (!document->lines1[j])
|
|
|
|
document->lines1[j] = &document->links[i];
|
|
|
|
}
|
|
|
|
}
|
2006-01-28 08:13:41 -05:00
|
|
|
document->links_sorted = 1;
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct conv_table *
|
2021-01-02 10:20:27 -05:00
|
|
|
get_convert_table(char *head, int to_cp,
|
2005-09-15 09:58:31 -04:00
|
|
|
int default_cp, int *from_cp,
|
|
|
|
enum cp_status *cp_status, int ignore_server_cp)
|
|
|
|
{
|
2021-01-02 10:20:27 -05:00
|
|
|
char *part = head;
|
2005-09-15 09:58:31 -04:00
|
|
|
int cp_index = -1;
|
|
|
|
|
|
|
|
assert(head);
|
|
|
|
if_assert_failed return NULL;
|
|
|
|
|
|
|
|
if (ignore_server_cp) {
|
|
|
|
if (cp_status) *cp_status = CP_STATUS_IGNORED;
|
|
|
|
if (from_cp) *from_cp = default_cp;
|
|
|
|
return get_translation_table(default_cp, to_cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cp_index == -1) {
|
2021-01-02 10:20:27 -05:00
|
|
|
char *ct_charset;
|
2008-06-30 13:32:07 -04:00
|
|
|
/* scan_http_equiv() appends the meta http-equiv directives to
|
|
|
|
* the protocol header before this function is called, but the
|
|
|
|
* HTTP Content-Type header has precedence, so the HTTP header
|
|
|
|
* will be used if it exists and the meta header is only used
|
|
|
|
* as a fallback. See bug 983. */
|
2021-01-02 10:20:27 -05:00
|
|
|
char *a = parse_header(part, "Content-Type", &part);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (!a) break;
|
|
|
|
|
2016-08-21 16:02:46 -04:00
|
|
|
parse_header_param(a, "charset", &ct_charset, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (ct_charset) {
|
|
|
|
cp_index = get_cp_index(ct_charset);
|
|
|
|
mem_free(ct_charset);
|
|
|
|
}
|
|
|
|
mem_free(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp_index == -1) {
|
2021-01-02 10:20:27 -05:00
|
|
|
char *a = parse_header(head, "Content-Charset", NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (a) {
|
|
|
|
cp_index = get_cp_index(a);
|
|
|
|
mem_free(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp_index == -1) {
|
2021-01-02 10:20:27 -05:00
|
|
|
char *a = parse_header(head, "Charset", NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (a) {
|
|
|
|
cp_index = get_cp_index(a);
|
|
|
|
mem_free(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cp_index == -1) {
|
|
|
|
cp_index = default_cp;
|
|
|
|
if (cp_status) *cp_status = CP_STATUS_ASSUMED;
|
|
|
|
} else {
|
|
|
|
if (cp_status) *cp_status = CP_STATUS_SERVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (from_cp) *from_cp = cp_index;
|
|
|
|
|
|
|
|
return get_translation_table(cp_index, to_cp);
|
|
|
|
}
|