summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-01 10:35:37 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-07-01 10:35:37 +0000
commit94ff706d99220d915be8cedcda6b93ead998f5b8 (patch)
treef28b6eec02fb023351dbeb2610d19d7c76580757 /src
parent5099ad82bbfc21bd45408bf5ca069df3ecfd0e8d (diff)
downloadlibcss-94ff706d99220d915be8cedcda6b93ead998f5b8.tar.gz
libcss-94ff706d99220d915be8cedcda6b93ead998f5b8.tar.bz2
Make all URIs absolute
svn path=/trunk/libcss/; revision=8228
Diffstat (limited to 'src')
-rw-r--r--src/parse/properties/aural.c25
-rw-r--r--src/parse/properties/background.c14
-rw-r--r--src/parse/properties/generated_list.c33
-rw-r--r--src/parse/properties/ui.c13
-rw-r--r--src/stylesheet.c11
-rw-r--r--src/stylesheet.h3
6 files changed, 80 insertions, 19 deletions
diff --git a/src/parse/properties/aural.c b/src/parse/properties/aural.c
index e87d7e3..b5b3c90 100644
--- a/src/parse/properties/aural.c
+++ b/src/parse/properties/aural.c
@@ -949,7 +949,14 @@ css_error parse_play_during(css_language *c,
int modifiers;
value = PLAY_DURING_URI;
- uri = token->idata;
+
+ error = c->sheet->resolve(c->sheet->resolve_pw,
+ c->sheet->dictionary, c->sheet->url,
+ token->idata, &uri);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
for (modifiers = 0; modifiers < 2; modifiers++) {
consumeWhitespace(vector, ctx);
@@ -999,7 +1006,7 @@ css_error parse_play_during(css_language *c,
memcpy((*result)->bytecode, &opv, sizeof(opv));
if ((flags & FLAG_INHERIT) == false &&
(value & PLAY_DURING_TYPE_MASK) == PLAY_DURING_URI) {
- lwc_context_string_ref(c->sheet->dictionary, uri);
+ /* Don't ref URI -- we want to pass ownership to the bytecode */
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
&uri, sizeof(lwc_string *));
}
@@ -1814,6 +1821,7 @@ css_error parse_cue_common(css_language *c,
uint16_t value = 0;
uint32_t opv;
uint32_t required_size;
+ lwc_string *uri = NULL;
/* URI | IDENT (none, inherit) */
token = parserutils_vector_iterate(vector, ctx);
@@ -1831,6 +1839,14 @@ css_error parse_cue_common(css_language *c,
value = CUE_AFTER_NONE;
} else if (token->type == CSS_TOKEN_URI) {
value = CUE_AFTER_URI;
+
+ error = c->sheet->resolve(c->sheet->resolve_pw,
+ c->sheet->dictionary, c->sheet->url,
+ token->idata, &uri);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
} else {
*ctx = orig_ctx;
return CSS_INVALID;
@@ -1852,10 +1868,9 @@ css_error parse_cue_common(css_language *c,
/* Copy the bytecode to it */
memcpy((*result)->bytecode, &opv, sizeof(opv));
if ((flags & FLAG_INHERIT) == false && value == CUE_AFTER_URI) {
- lwc_context_string_ref(c->sheet->dictionary, token->idata);
+ /* Don't ref URI -- we want to pass ownership to the bytecode */
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
- &token->idata,
- sizeof(lwc_string *));
+ &uri, sizeof(lwc_string *));
}
return CSS_OK;
diff --git a/src/parse/properties/background.c b/src/parse/properties/background.c
index 0ee4dbb..bec2b2f 100644
--- a/src/parse/properties/background.c
+++ b/src/parse/properties/background.c
@@ -400,6 +400,7 @@ css_error parse_background_image(css_language *c,
uint16_t value = 0;
uint32_t opv;
uint32_t required_size;
+ lwc_string *uri = NULL;
/* URI | IDENT (none, inherit) */
token = parserutils_vector_iterate(vector, ctx);
@@ -417,6 +418,14 @@ css_error parse_background_image(css_language *c,
value = BACKGROUND_IMAGE_NONE;
} else if (token->type == CSS_TOKEN_URI) {
value = BACKGROUND_IMAGE_URI;
+
+ error = c->sheet->resolve(c->sheet->resolve_pw,
+ c->sheet->dictionary, c->sheet->url,
+ token->idata, &uri);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
} else {
*ctx = orig_ctx;
return CSS_INVALID;
@@ -438,10 +447,9 @@ css_error parse_background_image(css_language *c,
/* Copy the bytecode to it */
memcpy((*result)->bytecode, &opv, sizeof(opv));
if ((flags & FLAG_INHERIT) == false && value == BACKGROUND_IMAGE_URI) {
- lwc_context_string_ref(c->sheet->dictionary, token->idata);
+ /* Don't ref URI -- we want to pass ownership to the bytecode */
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
- &token->idata,
- sizeof(lwc_string *));
+ &uri, sizeof(lwc_string *));
}
return CSS_OK;
diff --git a/src/parse/properties/generated_list.c b/src/parse/properties/generated_list.c
index 1183558..3efe305 100644
--- a/src/parse/properties/generated_list.c
+++ b/src/parse/properties/generated_list.c
@@ -378,6 +378,7 @@ css_error parse_list_style_image(css_language *c,
uint16_t value = 0;
uint32_t opv;
uint32_t required_size;
+ lwc_string *uri = NULL;
/* URI | IDENT (none, inherit) */
token = parserutils_vector_iterate(vector, ctx);
@@ -395,6 +396,14 @@ css_error parse_list_style_image(css_language *c,
value = LIST_STYLE_IMAGE_NONE;
} else if (token->type == CSS_TOKEN_URI) {
value = LIST_STYLE_IMAGE_URI;
+
+ error = c->sheet->resolve(c->sheet->resolve_pw,
+ c->sheet->dictionary, c->sheet->url,
+ token->idata, &uri);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
} else {
*ctx = orig_ctx;
return CSS_INVALID;
@@ -416,10 +425,9 @@ css_error parse_list_style_image(css_language *c,
/* Copy the bytecode to it */
memcpy((*result)->bytecode, &opv, sizeof(opv));
if ((flags & FLAG_INHERIT) == false && value == LIST_STYLE_IMAGE_URI) {
- lwc_context_string_ref(c->sheet->dictionary, token->idata);
+ /* Don't ref URI -- we want to pass ownership to the bytecode */
memcpy((uint8_t *) (*result)->bytecode + sizeof(opv),
- &token->idata,
- sizeof(lwc_string *));
+ &uri, sizeof(lwc_string *));
}
return CSS_OK;
@@ -874,6 +882,8 @@ css_error parse_content_list(css_language *c,
offset += sizeof(token->idata);
} else if (token->type == CSS_TOKEN_URI) {
+ lwc_string *uri;
+
opv = CONTENT_URI;
if (first == false) {
@@ -886,13 +896,20 @@ css_error parse_content_list(css_language *c,
}
if (buffer != NULL) {
- lwc_context_string_ref(c->sheet->dictionary,
- token->idata);
- memcpy(buffer + offset, &token->idata,
- sizeof(token->idata));
+ error = c->sheet->resolve(c->sheet->resolve_pw,
+ c->sheet->dictionary, c->sheet->url,
+ token->idata, &uri);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
+
+ /* Don't ref URI -- we want to pass ownership
+ * to the bytecode */
+ memcpy(buffer + offset, &uri, sizeof(uri));
}
- offset += sizeof(token->idata);
+ offset += sizeof(uri);
} else if (token->type == CSS_TOKEN_FUNCTION &&
token->ilower == c->strings[ATTR]) {
opv = CONTENT_ATTR;
diff --git a/src/parse/properties/ui.c b/src/parse/properties/ui.c
index 118e835..4a6c34f 100644
--- a/src/parse/properties/ui.c
+++ b/src/parse/properties/ui.c
@@ -204,7 +204,15 @@ css_error parse_cursor(css_language *c,
/* URI* */
while (token != NULL && token->type == CSS_TOKEN_URI) {
- lwc_string *uri = token->idata;
+ lwc_string *uri;
+
+ error = c->sheet->resolve(c->sheet->resolve_pw,
+ c->sheet->dictionary, c->sheet->url,
+ token->idata, &uri);
+ if (error != CSS_OK) {
+ *ctx = orig_ctx;
+ return error;
+ }
if (first == false) {
opv = CURSOR_URI;
@@ -212,7 +220,8 @@ css_error parse_cursor(css_language *c,
ptr += sizeof(opv);
}
- lwc_context_string_ref(c->sheet->dictionary, uri);
+ /* Don't ref URI -- we want to pass ownership to the
+ * bytecode */
memcpy(ptr, &uri, sizeof(uri));
ptr += sizeof(uri);
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 9afed2b..bfd159f 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -31,6 +31,8 @@ static css_error _remove_selectors(css_stylesheet *sheet, css_rule *rule);
* \param dict Dictionary in which to intern strings
* \param alloc Memory (de)allocation function
* \param alloc_pw Client private data for alloc
+ * \param resolve URL resolution function
+ * \param resolve_pw Client private data for resolve
* \param stylesheet Pointer to location to receive stylesheet
* \return CSS_OK on success,
* CSS_BADPARM on bad parameters,
@@ -41,6 +43,7 @@ css_error css_stylesheet_create(css_language_level level,
css_origin origin, uint64_t media, bool allow_quirks,
bool inline_style, lwc_context *dict,
css_allocator_fn alloc, void *alloc_pw,
+ css_url_resolution_fn resolve, void *resolve_pw,
css_stylesheet **stylesheet)
{
css_parser_optparams params;
@@ -48,7 +51,8 @@ css_error css_stylesheet_create(css_language_level level,
css_stylesheet *sheet;
size_t len;
- if (url == NULL || alloc == NULL || stylesheet == NULL)
+ if (url == NULL || alloc == NULL ||
+ resolve == NULL || stylesheet == NULL)
return CSS_BADPARM;
sheet = alloc(NULL, sizeof(css_stylesheet), alloc_pw);
@@ -115,6 +119,7 @@ css_error css_stylesheet_create(css_language_level level,
return CSS_NOMEM;
}
memcpy(sheet->url, url, len);
+ sheet->url[len] = '\0';
if (title != NULL) {
len = strlen(title) + 1;
@@ -128,11 +133,15 @@ css_error css_stylesheet_create(css_language_level level,
return CSS_NOMEM;
}
memcpy(sheet->title, title, len);
+ sheet->title[len] = '\0';
}
sheet->origin = origin;
sheet->media = media;
+ sheet->resolve = resolve;
+ sheet->resolve_pw = resolve_pw;
+
sheet->alloc = alloc;
sheet->pw = alloc_pw;
diff --git a/src/stylesheet.h b/src/stylesheet.h
index f3b2079..4ac560c 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -175,6 +175,9 @@ struct css_stylesheet {
bool inline_style; /**< Is an inline style */
+ css_url_resolution_fn resolve; /**< URL resolution function */
+ void *resolve_pw; /**< Private word */
+
css_allocator_fn alloc; /**< Allocation function */
void *pw; /**< Private word */
};