Skip to content

Commit 034a433

Browse files
authored
[css-values-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-images-4] [css-shapes-2] Clean up fetching (#12261)
* [css-vlaues-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-images-4] [css-shapes-2] Clean up fetching This fixes a few cases around fetching external URLs for style resources: - The base URL is the sheet's base URL if exists, otherwise the sheet's location, otherwise the document base URL. - The algorithm can take either a rule or declaration block, and derive the correct stylesheet and base URL from that. Updated the calling sites to take that onto account. - Removed redundant URL parsing in "@import". Closes #12065 Closes #12068 Closes #12086 Closes #12147 * Extract the computed absolute URL to a separate algo * A few fixes * nit
1 parent d4a6d5f commit 034a433

File tree

6 files changed

+46
-31
lines changed

6 files changed

+46
-31
lines changed

css-cascade-4/Overview.bs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,8 @@ Processing Stylesheet Imports</h3>
279279
and that condition is not true,
280280
return.
281281

282-
3. Let |parsedUrl| be the result of the [=URL parser=] steps with |rule|'s URL and
283-
|parentStylesheet|'s <a spec=cssom>location</a>.
284-
If the algorithm returns an error,
285-
return. [[CSSOM]]
286-
287-
4. [=Fetch a style resource=] from |parsedUrl|,
288-
with stylesheet |parentStylesheet|,
282+
4. [=Fetch a style resource=] from |rule|'s URL,
283+
with ruleOrDeclaration |rule|,
289284
destination "style",
290285
CORS mode "no-cors",
291286
and processResponse being the following steps given [=/response=] |response| and

css-color-5/Overview.bs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ or any other color or monochrome output device which has been characterized.
19941994
To <dfn export>fetch an external color profile</dfn>, given a
19951995
''@color-profile'' rule |rule|,
19961996
[=fetch a style resource=] given |rule|'s URL,
1997-
with stylesheet being |rule|'s <a spec=cssom for=CSSRule>parent CSS style sheet</a>,
1997+
with ruleOrDeclaration being |rule|,
19981998
destination "color-profile",
19991999
CORS mode "cors",
20002000
and processResponse being the following steps given [=/response=] |/res| and null, failure or

css-fonts-4/Overview.bs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3698,7 +3698,7 @@ Font fetching requirements</h4>
36983698
<div algorithm>
36993699
To <dfn>fetch a font</dfn> given a selected <<url>> |url| for ''@font-face'' |rule|,
37003700
[=fetch a style resource|fetch=] |url|,
3701-
with stylesheet being |rule|'s <a spec=cssom for=CSSRule>parent CSS style sheet</a>,
3701+
with ruleOrDeclaration being |rule|,
37023702
destination "font",
37033703
CORS mode "cors",
37043704
and processResponse being the following steps given [=/response=] |res| and null, failure or a

css-images-4/Overview.bs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ Fetching External Images {#fetching-images}
145145
-------------------------------------------
146146

147147
To <dfn export>fetch an external image for a stylesheet</dfn>,
148-
given a <<url>> |url| and {{CSSStyleSheet}} sheet,
148+
given a <<url>> |url| and a [=CSS style declaration=] |declaration|,
149149
[=fetch a style resource=] given |url|,
150-
with stylesheet {{CSSStyleSheet}},
150+
with ruleOrDeclaration being |declaration|,
151151
destination "image",
152152
CORS mode "no-cors",
153153
and processResponse being the following steps

css-shapes-2/Overview.bs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ Shapes from Image</h3>
610610
Fetching external shapes</h2>
611611

612612
To <dfn>fetch an external resource for a shape</dfn>, either an SVG or an image, given a
613-
{{CSSStyleRule}} |rule|,
614-
[=fetch a style resource=] given |rule|'s URL,
615-
with stylesheet being |rule|'s <a spec=cssom for=CSSRule>parent CSS style sheet</a>,
613+
[=CSS style declaration=] |declaration|,
614+
[=fetch a style resource=] given a <<url>> value,
615+
with ruleOrDeclaration being |declaration|,
616616
destination "image",
617617
CORS mode "cors",
618618
and processResponse being the following steps given [=/response=] |res| and null, failure or

css-values-4/Overview.bs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,7 @@ Relative URLs</h4>
10211021
the <a href="https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dynamic-changes-to-base-urls">base URL is mutable</a>.
10221022

10231023
When a <<url>> appears in the computed value of a property,
1024-
it is resolved to an absolute URL,
1025-
as described in the preceding paragraph.
1024+
it is [=resolve a style resource URL|resolved to an absolute URL=].
10261025
The computed value of a URL that the [=UA=] cannot resolve to an absolute URL is the specified value.
10271026

10281027
<div class="example">
@@ -1147,32 +1146,53 @@ URL Modifiers</h4>
11471146
<h4 id='url-processing'>
11481147
URL Processing Model</h4>
11491148

1149+
<div algorithm="style resource base URL">
1150+
To compute the <dfn>style resource base URL</dfn> for a [=CSS rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|:
1151+
1. Let |sheet| be null.
1152+
1153+
1. If |cssRuleOrDeclaration| is a {{CSSStyleDeclaration}} whose {{CSSStyleDeclaration/parentRule}} is not null,
1154+
set |cssRuleOrDeclaration| to |cssRuleOrDeclaration|'s {{CSSStyleDeclaration/parentRule}}.
1155+
1156+
1. If |cssRuleOrDeclaration| is a {{CSSRule}}, set |sheet| to |cssRuleOrDeclaration|'s {{CSSRule/parentStyleSheet}}.
1157+
1158+
1. If |sheet| is not null:
1159+
1. If |sheet|'s <a spec=cssom>stylesheet base URL</a> is not null,
1160+
return |sheet|'s <a spec=cssom>stylesheet base URL</a>.
1161+
1162+
1. If |sheet|'s <a spec=cssom>location</a> is not null, return |sheet|'s <a spec=cssom>location</a>.
1163+
1164+
1. Return |cssRuleOrDeclaration|'s [=relevant settings object=]'s [=environment settings object/API base URL=].
1165+
1166+
</div>
1167+
1168+
<div algorithm="resolve a style resource URL">
1169+
To <dfn>resolve a style resource URL</dfn> from a [=/url=] or <<url>> |urlValue|,
1170+
and a a [=CSS rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|:
1171+
1. Let |base| be the [=style resource base URL=] given |cssRuleOrDeclaration|.
1172+
1. Return the result of the [=URL parser=] steps with |urlValue|'s [=/url=] and |base|.
1173+
</div>
1174+
11501175
<div algorithm="fetch a style resource">
11511176
To <dfn export>fetch a style resource</dfn> from a [=/url=] or <<url>> |urlValue|,
1152-
given a {{CSSStyleSheet}} |sheet|,
1177+
given an [=CSS rule=] or a [=css declaration=] |cssRuleOrDeclaration|,
11531178
a string |destination| matching a {{RequestDestination}},
11541179
a "no-cors" or "cors" |corsMode|,
11551180
and an algorithm |processResponse| accepting a [=/response=]
11561181
and a null, failure or byte stream:
11571182

1158-
1. Let |environmentSettings| be |sheet|'s [=relevant settings object=].
1159-
1160-
2. Let |base| be |sheet|'s <a spec=cssom>stylesheet base URL</a> if it is not null,
1161-
otherwise |environmentSettings|'s [=API base URL=].
1162-
[[CSSOM]]
1183+
1. Let |parsedUrl| be the result of [=resolve a style resource URL|resolving=] |urlValue| given |cssRuleOrDeclaration|.
1184+
If that failed, return.
11631185

1164-
3. Let |parsedUrl| be the result of the [=URL parser=] steps
1165-
with |urlValue|'s [=/url=] and |base|.
1166-
If the algorithm returns an error, return.
1186+
1. Let |settingsObject| be |cssRuleOrDeclaration|'s [=relevant settings object=].
11671187

11681188
4. Let |req| be a new [=/request=] whose [=request/url=] is |parsedUrl|,
11691189
whose [=request/destination=] is |destination|,
11701190
[=request/mode=] is |corsMode|,
1171-
[=request/origin=] is |environmentSettings|'s [=environment settings object/origin=],
1191+
[=request/origin=] is |settingsObject|'s [=environment settings object/origin=],
11721192
[=request/credentials mode=] is "same-origin",
11731193
[=request/use-url-credentials flag=] is set,
1174-
[=request/client=] is |environmentSettings|,
1175-
and whose [=request/referrer=] is |environmentSettings|'s [=API base URL=].
1194+
[=request/client=] is |settingsObject|,
1195+
and whose [=request/referrer=] is "client".
11761196

11771197
5. If |corsMode| is "no-cors", set |req|'s [=request/credentials mode=] to "include".
11781198

@@ -1181,14 +1201,14 @@ URL Processing Model</h4>
11811201
Note: This specification does not define any URL request modification steps,
11821202
but other specs may do so.
11831203

1184-
7. If |req|'s [=request/mode=] is "cors",
1185-
set |req|'s [=request/referrer=] to |sheet|'s <a spec=cssom>location</a>. [[CSSOM]]
1204+
7. If |req|'s [=request/mode=] is "cors", and |sheet| is not null, then
1205+
set |req|'s [=request/referrer=] to the [=style resource base URL=] given |cssRuleOrDeclaration|. [[CSSOM]]
11861206

11871207
8. If |sheet|'s <a spec=cssom>origin-clean flag</a> is set,
11881208
set |req|'s [=request/initiator type=] to "css". [[CSSOM]]
11891209

11901210
9. [=/Fetch=] |req|,
1191-
with [=fetch/processresponseconsumebody=] set to |processResponse|.
1211+
with [=fetch/processresponseconsumebody|processResponseConsumeBody=] set to |processResponse|.
11921212
</div>
11931213

11941214
When interpreting [=URLs=] expressed in CSS,

0 commit comments

Comments
 (0)