Speculatively start image fetches as we parse the document.

This commit is contained in:
John-Mark Bell 2014-01-05 14:34:04 +00:00
parent b80da8bf0b
commit 32468516e3
3 changed files with 53 additions and 10 deletions

View File

@ -435,7 +435,7 @@ static bool save_complete_save_html_objects(save_complete_ctx *ctx,
object = html_get_objects(c, &count);
for (; object != NULL; object = object->next) {
if (object->content != NULL) {
if (object->content != NULL || object->box != NULL) {
if (save_complete_save_html_object(ctx,
object->content) == false)
return false;

View File

@ -507,6 +507,37 @@ static nserror html_meta_refresh_process_element(html_content *c, dom_node *n)
return error;
}
static bool html_process_img(html_content *c, dom_node *node)
{
dom_string *src;
nsurl *url;
nserror err;
dom_exception exc;
bool success;
/* Do nothing if foreground images are disabled */
if (nsoption_bool(foreground_images) == false) {
return true;
}
exc = dom_element_get_attribute(node, corestring_dom_src, &src);
if (exc != DOM_NO_ERR || src == NULL) {
return true;
}
err = nsurl_join(c->base_url, dom_string_data(src), &url);
if (err != NSERROR_OK) {
dom_string_unref(src);
return false;
}
dom_string_unref(src);
/* Speculatively fetch the image */
success = html_fetch_object(c, url, NULL, CONTENT_IMAGE, 0, 0, false);
nsurl_unref(url);
return success;
}
/**
* Complete conversion of an HTML document
@ -608,6 +639,10 @@ dom_default_action_DOMNodeInserted_cb(struct dom_event *evt, void *pw)
name, corestring_lwc_title) &&
htmlc->title == NULL) {
htmlc->title = dom_node_ref(node);
} else if (dom_string_caseless_lwc_isequal(
name, corestring_lwc_img)) {
html_process_img(htmlc,
(dom_node *) node);
}
dom_string_unref(name);

View File

@ -123,6 +123,9 @@ html_object_callback(hlcache_handle *object,
assert(c->base.status != CONTENT_STATUS_ERROR);
box = o->box;
if (box == NULL && event->type != CONTENT_MSG_ERROR) {
return NSERROR_OK;
}
switch (event->type) {
case CONTENT_MSG_LOADING:
@ -181,11 +184,13 @@ html_object_callback(hlcache_handle *object,
o->content = NULL;
c->base.active--;
LOG(("%d fetches active", c->base.active));
if (box != NULL) {
c->base.active--;
LOG(("%d fetches active", c->base.active));
content_add_error(&c->base, "?", 0);
html_object_failed(box, c, o->background);
content_add_error(&c->base, "?", 0);
html_object_failed(box, c, o->background);
}
break;
case CONTENT_MSG_STATUS:
@ -464,7 +469,7 @@ html_object_callback(hlcache_handle *object,
* then reformat the page to display newly fetched objects */
else if (nsoption_bool(incremental_reflow) &&
event->type == CONTENT_MSG_DONE &&
!(box->flags & REPLACE_DIM) &&
box != NULL && !(box->flags & REPLACE_DIM) &&
(c->base.status == CONTENT_STATUS_READY ||
c->base.status == CONTENT_STATUS_DONE) &&
(wallclock() > c->base.reformat_time)) {
@ -491,6 +496,7 @@ static bool html_replace_object(struct content_html_object *object, nsurl *url)
nserror error;
assert(object != NULL);
assert(object->box != NULL);
c = (html_content *) object->parent;
@ -562,7 +568,7 @@ nserror html_object_open_objects(html_content *html, struct browser_window *bw)
for (object = html->object_list; object != NULL; object = next) {
next = object->next;
if (object->content == NULL)
if (object->content == NULL || object->box == NULL)
continue;
if (content_get_type(object->content) == CONTENT_NONE)
@ -621,7 +627,7 @@ nserror html_object_close_objects(html_content *html)
for (object = html->object_list; object != NULL; object = next) {
next = object->next;
if (object->content == NULL)
if (object->content == NULL || object->box == NULL)
continue;
if (content_get_type(object->content) == CONTENT_NONE)
@ -701,8 +707,10 @@ bool html_fetch_object(html_content *c, nsurl *url, struct box *box,
c->object_list = object;
c->num_objects++;
c->base.active++;
LOG(("%d fetches active", c->base.active));
if (box != NULL) {
c->base.active++;
LOG(("%d fetches active", c->base.active));
}
return true;
}