Use correct base URL for inline stylesheets

This commit is contained in:
John-Mark Bell 2013-02-27 03:55:48 +00:00
parent cd3e073354
commit 6b9f7c3094
4 changed files with 31 additions and 7 deletions

View File

@ -129,6 +129,7 @@ nserror nscss_create(const content_handler *handler,
{ {
nscss_content *result; nscss_content *result;
const char *charset = NULL; const char *charset = NULL;
const char *xnsbase = NULL;
lwc_string *charset_value = NULL; lwc_string *charset_value = NULL;
union content_msg_data msg_data; union content_msg_data msg_data;
nserror error; nserror error;
@ -155,9 +156,14 @@ nserror nscss_create(const content_handler *handler,
charset = lwc_string_data(charset_value); charset = lwc_string_data(charset_value);
} }
/* Compute base URL for stylesheet */
xnsbase = llcache_handle_get_header(llcache, "X-NS-Base");
if (xnsbase == NULL) {
xnsbase = nsurl_access(content_get_url(&result->base));
}
error = nscss_create_css_data(&result->data, error = nscss_create_css_data(&result->data,
nsurl_access(content_get_url(&result->base)), xnsbase, charset, result->base.quirks,
charset, result->base.quirks,
nscss_content_done, result); nscss_content_done, result);
if (error != NSERROR_OK) { if (error != NSERROR_OK) {
msg_data.error = messages_get("NoMemory"); msg_data.error = messages_get("NoMemory");

View File

@ -296,7 +296,7 @@ html_stylesheet_from_domnode(html_content *c,
return NSERROR_OK; return NSERROR_OK;
} }
error = html_css_fetcher_add_item(style, &key); error = html_css_fetcher_add_item(style, c->base_url, &key);
if (error != NSERROR_OK) { if (error != NSERROR_OK) {
dom_string_unref(style); dom_string_unref(style);
return error; return error;

View File

@ -37,6 +37,7 @@
typedef struct html_css_fetcher_item { typedef struct html_css_fetcher_item {
uint32_t key; uint32_t key;
dom_string *data; dom_string *data;
nsurl *base_url;
struct html_css_fetcher_item *r_next, *r_prev; struct html_css_fetcher_item *r_next, *r_prev;
} html_css_fetcher_item; } html_css_fetcher_item;
@ -142,6 +143,7 @@ static void html_css_fetcher_free(void *ctx)
nsurl_unref(c->url); nsurl_unref(c->url);
if (c->item != NULL) { if (c->item != NULL) {
nsurl_unref(c->item->base_url);
dom_string_unref(c->item->data); dom_string_unref(c->item->data);
RING_REMOVE(items, c->item); RING_REMOVE(items, c->item);
free(c->item); free(c->item);
@ -195,7 +197,7 @@ static void html_css_fetcher_poll(lwc_string *scheme)
/* Nothing to do */ /* Nothing to do */
assert(c->locked == false); assert(c->locked == false);
} else if (c->item != NULL) { } else if (c->item != NULL) {
char header[64]; char header[4096];
fetch_set_http_code(c->parent_fetch, 200); fetch_set_http_code(c->parent_fetch, 200);
@ -221,6 +223,18 @@ static void html_css_fetcher_poll(lwc_string *scheme)
html_css_fetcher_send_callback(&msg, c); html_css_fetcher_send_callback(&msg, c);
} }
if (c->aborted == false) {
snprintf(header, sizeof header,
"X-NS-Base: %.*s",
(int) nsurl_length(c->item->base_url),
nsurl_access(c->item->base_url));
msg.type = FETCH_HEADER;
msg.data.header_or_data.buf =
(const uint8_t *) header;
msg.data.header_or_data.len = strlen(header);
html_css_fetcher_send_callback(&msg, c);
}
if (c->aborted == false) { if (c->aborted == false) {
msg.type = FETCH_DATA; msg.type = FETCH_DATA;
msg.data.header_or_data.buf = msg.data.header_or_data.buf =
@ -280,7 +294,8 @@ void html_css_fetcher_register(void)
html_css_fetcher_finalise); html_css_fetcher_finalise);
} }
nserror html_css_fetcher_add_item(dom_string *data, uint32_t *key) nserror html_css_fetcher_add_item(dom_string *data, nsurl *base_url,
uint32_t *key)
{ {
html_css_fetcher_item *item = malloc(sizeof(*item)); html_css_fetcher_item *item = malloc(sizeof(*item));
@ -290,6 +305,7 @@ nserror html_css_fetcher_add_item(dom_string *data, uint32_t *key)
*key = item->key = current_key++; *key = item->key = current_key++;
item->data = dom_string_ref(data); item->data = dom_string_ref(data);
item->base_url = nsurl_ref(base_url);
RING_INSERT(items, item); RING_INSERT(items, item);

View File

@ -268,11 +268,13 @@ nserror html_css_free_stylesheets(html_content *html);
bool html_css_process_link(html_content *htmlc, dom_node *node); bool html_css_process_link(html_content *htmlc, dom_node *node);
bool html_css_update_style(html_content *c, dom_node *style); bool html_css_update_style(html_content *c, dom_node *style);
nserror html_css_new_selection_context(html_content *c, css_select_ctx **ret_select_ctx); nserror html_css_new_selection_context(html_content *c,
css_select_ctx **ret_select_ctx);
/* in render/html_css_fetcher.c */ /* in render/html_css_fetcher.c */
void html_css_fetcher_register(void); void html_css_fetcher_register(void);
nserror html_css_fetcher_add_item(dom_string *data, uint32_t *key); nserror html_css_fetcher_add_item(dom_string *data, nsurl *base_url,
uint32_t *key);
/* in render/html_object.c */ /* in render/html_object.c */