8000 [css-values-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-images-4] [css-shapes-2] Clean up fetching by noamr · Pull Request #12261 · w3c/csswg-drafts · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[css-vlaues-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-image…
…s-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
  • Loading branch information
noamr committed Jun 2, 2025
commit 2366187a91cb03e028a76d79120679bbe43b2d3d
9 changes: 2 additions & 7 deletions css-cascade-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,8 @@ Processing Stylesheet Imports</h3>
and that condition is not true,
return.

3. Let |parsedUrl| be the result of the [=URL parser=] steps with |rule|'s URL and
|parentStylesheet|'s <a spec=cssom>location</a>.
If the algorithm returns an error,
return. [[CSSOM]]

4. [=Fetch a style resource=] from |parsedUrl|,
with stylesheet |parentStylesheet|,
4. [=Fetch a style resource=] from |rule|'s URL,
with ruleOrDeclaration |rule|,
destination "style",
CORS mode "no-cors",
and processResponse being the following steps given [=/response=] |response| and
Expand Down
2 changes: 1 addition & 1 deletion css-color-5/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ or any other color or monochrome output device which has been characterized.
To <dfn export>fetch an external color profile</dfn>, given a
''@color-profile'' rule |rule|,
[=fetch a style resource=] given |rule|'s URL,
with stylesheet being |rule|'s <a spec=cssom for=CSSRule>parent CSS style sheet</a>,
with ruleOrDeclaration being |rule|,
destination "color-profile",
CORS mode "cors",
and processResponse being the following steps given [=/response=] |/res| and null, failure or
Expand Down
2 changes: 1 addition & 1 deletion css-fonts-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3698,7 +3698,7 @@ Font fetching requirements</h4>
<div algorithm>
To <dfn>fetch a font</dfn> given a selected <<url>> |url| for ''@font-face'' |rule|,
[=fetch a style resource|fetch=] |url|,
with stylesheet being |rule|'s <a spec=cssom for=CSSRule>parent CSS style sheet</a>,
with ruleOrDeclaration being |rule|,
destination "font",
CORS mode "cors",
and processResponse being the following steps given [=/response=] |res| and null, failure or a
Expand Down
4 changes: 2 additions & 2 deletions css-images-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ Fetching External Images {#fetching-images}
-------------------------------------------

To <dfn export>fetch an external image for a stylesheet</dfn>,
given a <<url>> |url| and {{CSSStyleSheet}} sheet,
given a <<url>> |url| and a [=CSS style declaration=] |declaration|,
[=fetch a style resource=] given |url|,
with stylesheet {{CSSStyleSheet}},
with ruleOrDeclaration being |declaration|,
destination "image",
CORS mode "no-cors",
and processResponse being the following steps
Expand Down
6 changes: 3 additions & 3 deletions css-shapes-2/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ Shapes from Image</h3>
Fetching external shapes</h2>

To <dfn>fetch an external resource for a shape</dfn>, either an SVG or an image, given a
{{CSSStyleRule}} |rule|,
[=fetch a style resource=] given |rule|'s URL,
with stylesheet being |rule|'s <a spec=cssom for=CSSRule>parent CSS style sheet</a>,
[=CSS style declaration=] |declaration|,
[=fetch a style resource=] given a <<url>> value,
with ruleOrDeclaration being |declaration|,
destination "image",
CORS mode "cors",
and processResponse being the following steps given [=/response=] |res| and null, failure or
Expand Down
31 changes: 21 additions & 10 deletions css-values-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,30 +1149,41 @@ URL Processing Model</h4>

<div algorithm="fetch a style resource">
To <dfn export>fetch a style resource</dfn> from a [=/url=] or <<url>> |urlValue|,
given a {{CSSStyleSheet}} |sheet|,
given an [=CSS style rule=] or a [=css declaration=] |cssRuleOrDeclaration|,
a string |destination| matching a {{RequestDestination}},
a "no-cors" or "cors" |corsMode|,
and an algorithm |processResponse| accepting a [=/response=]
and a null, failure or byte stream:

1. Let |environmentSettings| be |sheet|'s [=relevant settings object=].
1. Assert: |cssRuleOrDeclaration|'s [=relevant settings object=] is a {{Document}}.

2. Let |base| be |sheet|'s <a spec=cssom>stylesheet base URL</a> if it is not null,
otherwise |environmentSettings|'s [=API base URL=].
[[CSSOM]]
1. Let |document| be |cssRuleOrDeclaration|'s [=relevant settings object=].

3. Let |parsedUrl| be the result of the [=URL parser=] steps
1. Let |sheet| be null.

1. If |cssRuleOrDeclaration| is a {{CSSStyleDeclaration}} whose {{CSSStyleDeclaration/parentRule}} is not null,
set |cssRuleOrDeclaration| to |cssRuleOrDeclaration|'s {{CSSStyleDeclaration/parentRule}}.

1. If |cssRuleOrDeclaration| is a {{CSSRule}}, set |sheet| to |cssRuleOrDeclaration|'s {{CSSRule/parentStyleSheet}}.

1. Let |base| be be null.
1. If |sheet| is not null:
1. If |sheet|'s <a spec=cssom>stylesheet base URL</a> is not null, then set |base| to |sheet|'s <a spec=cssom>stylesheet base URL</a>.
1. Otherwise, set |base| to |sheet|'s <a spec=cssom>location</a>.
1. If |base| is null, set |base| to |document|'s [=document base URL=].

1. Let |parsedUrl| be the result of the [=URL parser=] steps
with |urlValue|'s [=/url=] and |base|.
If the algorithm returns an error, return.

4. Let |req| be a new [=/request=] whose [=request/url=] is |parsedUrl|,
whose [=request/destination=] is |destination|,
[=request/mode=] is |corsMode|,
[=request/origin=] is |environmentSettings|'s [=environment settings object/origin=],
[=request/origin=] is |document|'s [=environment settings object/origin=],
[=request/credentials mode=] is "same-origin",
[=request/use-url-credentials flag=] is set,
[=request/client=] is |environmentSettings|,
and whose [=request/referrer=] is |environmentSettings|'s [=API base URL=].
[=request/client=] is |document|,
and whose [=request/referrer=] is |document|'s [=document base URL=].

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

Expand All @@ -1181,7 +1192,7 @@ URL Processing Model</h4>
Note: This specification does not define any URL request modification steps,
but other specs may do so.

7. If |req|'s [=request/mode=] is "cors",
7. If |req|'s [=request/mode=] is "cors", and |sheet| is not null, then
set |req|'s [=request/referrer=] to |sheet|'s <a spec=cssom>location</a>. [[CSSOM]]

8. If |sheet|'s <a spec=cssom>origin-clean flag</a> is set,
Expand Down
0