fix quirk stylesheet loading

This commit is contained in:
Vincent Sanders 2013-02-25 15:00:50 +00:00
parent dd35da2cac
commit 4e7b4259a4
3 changed files with 55 additions and 23 deletions

View File

@ -287,6 +287,12 @@ dom_default_action_DOMSubtreeModified_cb(struct dom_event *evt, void *pw)
* selects a callback function for libdom to call based on the type and phase.
* dom_default_action_phase from events/document_event.h
*
* The principle events are:
* DOMSubtreeModified
* DOMAttrModified
* DOMNodeInserted
* DOMNodeInsertedIntoDocument
*
* @return callback function pointer or NULL for none
*/
static dom_default_action_callback
@ -1508,10 +1514,30 @@ static void html_object_refresh(void *p)
static bool html_convert(struct content *c)
{
html_content *htmlc = (html_content *) c;
dom_exception exc; /* returned by libdom functions */
/* The quirk check and associated stylesheet fetch is "safe"
* once the root node has been inserted into the document
* which must have happened by this point in the parse.
*
* faliure to retrive the quirk mode or to start the
* stylesheet fetch is non fatal as this "only" affects the
* render and it would annoy the user to fail the entire
* render for want of a quirks stylesheet.
*/
exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks);
if (exc == DOM_NO_ERR) {
html_css_quirks_stylesheets(htmlc);
LOG(("quirks set to %d", htmlc->quirks));
}
htmlc->base.active--; /* the html fetch is no longer active */
LOG(("%d fetches active", htmlc->base.active));
/* The parse cannot be completed here because it may be paused
* untill all the resources being fetched have completed.
*/
/* if there are no active fetches in progress no scripts are
* being fetched or they completed already.
*/
@ -1549,7 +1575,6 @@ html_begin_conversion(html_content *htmlc)
return false;
}
/* complete script execution */
html_scripts_exec(htmlc);
@ -1557,14 +1582,6 @@ html_begin_conversion(html_content *htmlc)
* the Document.
*/
/* quirks mode */
exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks);
if (exc != DOM_NO_ERR) {
LOG(("error retrieving quirks"));
/** @todo should this be fatal to the conversion? */
}
LOG(("quirks set to %d", htmlc->quirks));
/* get encoding */
if (htmlc->encoding == NULL) {
const char *encoding;

View File

@ -183,6 +183,34 @@ nserror html_css_free_stylesheets(html_content *html)
return NSERROR_OK;
}
/* exported interface documented in render/html_internal.h */
nserror html_css_quirks_stylesheets(html_content *c)
{
nserror ns_error = NSERROR_OK;
hlcache_child_context child;
assert(c->stylesheets != NULL);
if (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL) {
child.charset = c->encoding;
child.quirks = c->base.quirks;
ns_error = hlcache_handle_retrieve(html_quirks_stylesheet_url,
0, content_get_url(&c->base), NULL,
html_convert_css_callback, c, &child,
CONTENT_CSS,
&c->stylesheets[STYLESHEET_QUIRKS].data.external);
if (ns_error != NSERROR_OK) {
return ns_error;
}
c->base.active++;
LOG(("%d fetches active", c->base.active));
}
return ns_error;
}
/* exported interface documented in render/html_internal.h */
nserror html_css_new_stylesheets(html_content *c)
{
@ -226,20 +254,6 @@ nserror html_css_new_stylesheets(html_content *c)
c->base.active++;
LOG(("%d fetches active", c->base.active));
if (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL) {
ns_error = hlcache_handle_retrieve(html_quirks_stylesheet_url,
0, content_get_url(&c->base), NULL,
html_convert_css_callback, c, &child,
CONTENT_CSS,
&c->stylesheets[STYLESHEET_QUIRKS].data.external);
if (ns_error != NSERROR_OK) {
return ns_error;
}
c->base.active++;
LOG(("%d fetches active", c->base.active));
}
if (nsoption_bool(block_ads)) {
ns_error = hlcache_handle_retrieve(html_adblock_stylesheet_url,

View File

@ -266,6 +266,7 @@ void html_css_fini(void);
* \return nserror
*/
nserror html_css_new_stylesheets(html_content *c);
nserror html_css_quirks_stylesheets(html_content *c);
nserror html_css_free_stylesheets(html_content *html);
bool html_css_process_link(html_content *htmlc, dom_node *node);