From 232c07aa7f6412d74788fb931a22f9f891fbba6c Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 20 Apr 2008 22:25:10 +0200 Subject: [PATCH] bug 1009: id variables renamed, added document_id to the document. cached->id => cached->cache_id document->id => document->cache_id onload_snippets_owner => onload_snippets_document_id Added the distinct document->document_id. Always reset ecmascript when a document changes for example a next chunk of it is loaded. --- src/cache/cache.c | 6 +++--- src/cache/cache.h | 2 +- src/cache/dialogs.c | 2 +- src/document/document.c | 10 ++++++---- src/document/document.h | 3 ++- src/document/renderer.c | 7 ++++--- src/ecmascript/ecmascript.h | 2 +- src/viewer/text/draw.c | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/cache/cache.c b/src/cache/cache.c index 5a66b1df7..5f4d638f2 100644 --- a/src/cache/cache.c +++ b/src/cache/cache.c @@ -150,7 +150,7 @@ get_cache_entry(struct uri *uri) cached->valid = 1; init_list(cached->frag); - cached->id = id_counter++; + cached->cache_id = id_counter++; object_nolock(cached, "cache_entry"); /* Debugging purpose. */ cached->box_item = add_listbox_leaf(&cache_browser, NULL, cached); @@ -385,7 +385,7 @@ add_fragment(struct cache_entry *cached, off_t offset, /* id marks each entry, and change each time it's modified, * used in HTML renderer. */ - cached->id = id_counter++; + cached->cache_id = id_counter++; /* Possibly insert the new data in the middle of existing fragment. */ foreach (f, cached->frag) { @@ -639,7 +639,7 @@ delete_entry_content(struct cache_entry *cached) del_from_list(f); frag_free(f); } - cached->id = id_counter++; + cached->cache_id = id_counter++; cached->length = 0; cached->incomplete = 1; diff --git a/src/cache/cache.h b/src/cache/cache.h index ed68d1fee..bbb4eb926 100644 --- a/src/cache/cache.h +++ b/src/cache/cache.h @@ -42,7 +42,7 @@ struct cache_entry { unsigned char *ssl_info; /* SSL ciphers used during transfer */ unsigned char *encoding_info; /* Encoding used during transfer */ - unsigned int id; /* Change each time entry is modified. */ + unsigned int cache_id; /* Change each time entry is modified. */ time_t seconds; /* Access time. Used by 'If-Modified-Since' */ diff --git a/src/cache/dialogs.c b/src/cache/dialogs.c index 2ee30fd9e..9d60548fc 100644 --- a/src/cache/dialogs.c +++ b/src/cache/dialogs.c @@ -146,7 +146,7 @@ get_cache_entry_info(struct listbox_item *item, struct terminal *term) #ifdef CONFIG_DEBUG add_format_to_string(&msg, "\n%s: %d", "Refcount", get_object_refcount(cached)); - add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->id); + add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->cache_id); if (cached->head && *cached->head) { add_format_to_string(&msg, "\n%s:\n\n%s", _("Header", term), diff --git a/src/document/document.c b/src/document/document.c index 52b93030c..1920e9a1a 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -33,6 +33,7 @@ #include "util/string.h" #include "viewer/text/link.h" +static int document_init_counter = 0; static INIT_LIST_OF(struct document, format_cache); @@ -46,7 +47,7 @@ init_document(struct cache_entry *cached, struct document_options *options) document->uri = get_uri_reference(cached->uri); object_lock(cached); - document->id = cached->id; + document->cache_id = cached->cache_id; document->cached = cached; init_list(document->forms); @@ -55,6 +56,7 @@ init_document(struct cache_entry *cached, struct document_options *options) #ifdef CONFIG_ECMASCRIPT init_list(document->onload_snippets); + document->document_id = ++document_init_counter; #endif #ifdef CONFIG_COMBINE @@ -214,7 +216,7 @@ get_document_css_magic(struct document *document) foreach_uri (uri, index, &document->css_imports) { struct cache_entry *cached = find_in_cache(uri); - if (cached) css_magic += cached->id + cached->data_size; + if (cached) css_magic += cached->cache_id + cached->data_size; } return css_magic; @@ -256,7 +258,7 @@ get_cached_document(struct cache_entry *cached, struct document_options *options continue; if (options->no_cache - || cached->id != document->id + || cached->cache_id != document->cache_id || !check_document_css_magic(document)) { if (!is_object_used(document)) { done_document(document); @@ -289,7 +291,7 @@ shrink_format_cache(int whole) /* Destroy obsolete renderer documents which are already * out-of-sync. */ - if (document->cached->id == document->id) + if (document->cached->cache_id == document->cache_id) continue; done_document(document); diff --git a/src/document/document.h b/src/document/document.h index a9beb791d..8782351a6 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -166,6 +166,7 @@ struct document { struct uri_list ecmascript_imports; /** used by setTimeout */ timer_id_T timeout; + unsigned int document_id; #endif #ifdef CONFIG_CSS /** @todo FIXME: We should externally maybe using cache_entry store the @@ -210,7 +211,7 @@ struct document { /* Positions of the last base character.*/ int comb_x, comb_y; #endif - unsigned int id; /**< Used to check cache entries. */ + unsigned int cache_id; /**< Used to check cache entries. */ int cp; int width, height; /**< size of document */ diff --git a/src/document/renderer.c b/src/document/renderer.c index 4e3f9847d..509f3c25a 100644 --- a/src/document/renderer.c +++ b/src/document/renderer.c @@ -383,11 +383,12 @@ render_document(struct view_state *vs, struct document_view *doc_view, * XXX: What happens if a document is still loading in the * other tab when we press ^L here? */ if (vs->ecmascript_fragile - || (vs->ecmascript && vs->ecmascript->onload_snippets_owner - && document->id != vs->ecmascript->onload_snippets_owner)) + || (vs->ecmascript + && vs->ecmascript->onload_snippets_document_id + && document->document_id != vs->ecmascript->onload_snippets_document_id)) ecmascript_reset_state(vs); assert(vs->ecmascript); - vs->ecmascript->onload_snippets_owner = document->id; + vs->ecmascript->onload_snippets_document_id = document->document_id; /* Passing of the onload_snippets pointers gives *_snippets() * some feeling of universality, shall we ever get any other diff --git a/src/ecmascript/ecmascript.h b/src/ecmascript/ecmascript.h index 87ec27c16..a7392e834 100644 --- a/src/ecmascript/ecmascript.h +++ b/src/ecmascript/ecmascript.h @@ -50,7 +50,7 @@ struct ecmascript_interpreter { * ecmascript_fragile, but it can happen i.e. when the urrent document * is reloaded in another tab and then you just cause the current tab * to redraw. */ - unsigned int onload_snippets_owner; + unsigned int onload_snippets_document_id; }; /* Why is the interpreter bound to {struct view_state} instead of {struct diff --git a/src/viewer/text/draw.c b/src/viewer/text/draw.c index 19191cd60..161838069 100644 --- a/src/viewer/text/draw.c +++ b/src/viewer/text/draw.c @@ -67,7 +67,7 @@ check_document_fragment(struct session *ses, struct document_view *doc_view) struct cache_entry *cached = document->cached; assert(cached); - if (cached->incomplete || cached->id != document->id) { + if (cached->incomplete || cached->cache_id != document->cache_id) { done_string(&fragment); return -2; }