From 2366187a91cb03e028a76d79120679bbe43b2d3d Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Mon, 2 Jun 2025 20:32:33 +0100 Subject: [PATCH 1/4] [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 --- css-cascade-4/Overview.bs | 9 ++------- css-color-5/Overview.bs | 2 +- css-fonts-4/Overview.bs | 2 +- css-images-4/Overview.bs | 4 ++-- css-shapes-2/Overview.bs | 6 +++--- css-values-4/Overview.bs | 31 +++++++++++++++++++++---------- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/css-cascade-4/Overview.bs b/css-cascade-4/Overview.bs index 24d3d0d0387..df7a1193c9b 100644 --- a/css-cascade-4/Overview.bs +++ b/css-cascade-4/Overview.bs @@ -279,13 +279,8 @@ Processing Stylesheet Imports 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 location. - 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 diff --git a/css-color-5/Overview.bs b/css-color-5/Overview.bs index b821d451423..9edcb76cafc 100644 --- a/css-color-5/Overview.bs +++ b/css-color-5/Overview.bs @@ -1994,7 +1994,7 @@ or any other color or monochrome output device which has been characterized. To fetch an external color profile, given a ''@color-profile'' rule |rule|, [=fetch a style resource=] given |rule|'s URL, - with stylesheet being |rule|'s parent CSS style sheet, + with ruleOrDeclaration being |rule|, destination "color-profile", CORS mode "cors", and processResponse being the following steps given [=/response=] |/res| and null, failure or diff --git a/css-fonts-4/Overview.bs b/css-fonts-4/Overview.bs index 7b3a5a8e96b..a9e0e4176fd 100644 --- a/css-fonts-4/Overview.bs +++ b/css-fonts-4/Overview.bs @@ -3698,7 +3698,7 @@ Font fetching requirements
To fetch a font given a selected <> |url| for ''@font-face'' |rule|, [=fetch a style resource|fetch=] |url|, - with stylesheet being |rule|'s parent CSS style sheet, + with ruleOrDeclaration being |rule|, destination "font", CORS mode "cors", and processResponse being the following steps given [=/response=] |res| and null, failure or a diff --git a/css-images-4/Overview.bs b/css-images-4/Overview.bs index 57e602f8283..f3c7c1d2624 100644 --- a/css-images-4/Overview.bs +++ b/css-images-4/Overview.bs @@ -145,9 +145,9 @@ Fetching External Images {#fetching-images} ------------------------------------------- To fetch an external image for a stylesheet, - given a <> |url| and {{CSSStyleSheet}} sheet, + given a <> |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 diff --git a/css-shapes-2/Overview.bs b/css-shapes-2/Overview.bs index d60aaac3153..e13e02af03e 100644 --- a/css-shapes-2/Overview.bs +++ b/css-shapes-2/Overview.bs @@ -610,9 +610,9 @@ Shapes from Image Fetching external shapes To fetch an external resource for a shape, either an SVG or an image, given a - {{CSSStyleRule}} |rule|, - [=fetch a style resource=] given |rule|'s URL, - with stylesheet being |rule|'s parent CSS style sheet, + [=CSS style declaration=] |declaration|, + [=fetch a style resource=] given a <> value, + with ruleOrDeclaration being |declaration|, destination "image", CORS mode "cors", and processResponse being the following steps given [=/response=] |res| and null, failure or diff --git a/css-values-4/Overview.bs b/css-values-4/Overview.bs index f74ad22e3d3..9fc972ce7b1 100644 --- a/css-values-4/Overview.bs +++ b/css-values-4/Overview.bs @@ -1149,30 +1149,41 @@ URL Processing Model
To fetch a style resource from a [=/url=] or <> |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 stylesheet base URL 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 stylesheet base URL is not null, then set |base| to |sheet|'s stylesheet base URL. + 1. Otherwise, set |base| to |sheet|'s location. + 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". @@ -1181,7 +1192,7 @@ URL Processing Model 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 location. [[CSSOM]] 8. If |sheet|'s origin-clean flag is set, From 3300545a0f09c4cc6b1e7950526324d99bc6548f Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 3 Jun 2025 12:36:37 +0100 Subject: [PATCH 2/4] Extract the computed absolute URL to a separate algo --- css-values-4/Overview.bs | 51 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/css-values-4/Overview.bs b/css-values-4/Overview.bs index 9fc972ce7b1..420e1170693 100644 --- a/css-values-4/Overview.bs +++ b/css-values-4/Overview.bs @@ -1021,8 +1021,7 @@ Relative URLs the base URL is mutable. When a <> appears in the computed value of a property, - it is resolved to an absolute URL, - as described in the preceding paragraph. + it is [=resolve a style resource URL|resolved to an absolute URL=]. The computed value of a URL that the [=UA=] cannot resolve to an absolute URL is the specified value.
@@ -1147,6 +1146,30 @@ URL Modifiers

URL Processing Model

+
+ To compute the style resource base URL for a [=CSS style rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|: + 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. If |sheet| is not null: + 1. If |sheet|'s stylesheet base URL is not null, + return |sheet|'s stylesheet base URL. + + 1. If |sheet|'s location is not null, return |sheet|'s location. + + 1. Assert: |cssRuleOrDeclaration|'s [=relevant settings object=] is a {{Document}}. + + 1. Return |cssRuleOrDeclaration|'s [=relevant settings object=]'s [=document base URL=]. + + To resolve a style resource URL from a [=/url=] or <> |urlValue|, + and a a [=CSS style rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|, return the result of the [=URL parser=] steps + with |urlValue|'s [=/url=] and the [=style resource base URL=] given |cssRuleOrDeclaration|. +
+
To fetch a style resource from a [=/url=] or <> |urlValue|, given an [=CSS style rule=] or a [=css declaration=] |cssRuleOrDeclaration|, @@ -1155,26 +1178,8 @@ URL Processing Model and an algorithm |processResponse| accepting a [=/response=] and a null, failure or byte stream: - 1. Assert: |cssRuleOrDeclaration|'s [=relevant settings object=] is a {{Document}}. - - 1. Let |document| be |cssRuleOrDeclaration|'s [=relevant settings object=]. - - 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 stylesheet base URL is not null, then set |base| to |sheet|'s stylesheet base URL. - 1. Otherwise, set |base| to |sheet|'s location. - 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. + 1. Let |parsedURL| be the result of [=resolve a style resource URL|resolving=] |urlValue| given |cssRuleOrDeclaration|. + If that failed, return. 4. Let |req| be a new [=/request=] whose [=request/url=] is |parsedUrl|, whose [=request/destination=] is |destination|, @@ -1193,7 +1198,7 @@ URL Processing Model but other specs may do so. 7. If |req|'s [=request/mode=] is "cors", and |sheet| is not null, then - set |req|'s [=request/referrer=] to |sheet|'s location. [[CSSOM]] + set |req|'s [=request/referrer=] to the [=style resource base URL=] given |cssRuleOrDeclaration|. [[CSSOM]] 8. If |sheet|'s origin-clean flag is set, set |req|'s [=request/initiator type=] to "css". [[CSSOM]] From 8792fb15310a14e1b0e2696c296ae8880d215b37 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 3 Jun 2025 13:50:42 +0100 Subject: [PATCH 3/4] A few fixes --- css-values-4/Overview.bs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/css-values-4/Overview.bs b/css-values-4/Overview.bs index 420e1170693..bc82b318467 100644 --- a/css-values-4/Overview.bs +++ b/css-values-4/Overview.bs @@ -1146,8 +1146,8 @@ URL Modifiers

URL Processing Model

-
- To compute the style resource base URL for a [=CSS style rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|: +
+ To compute the style resource base URL for a [=CSS rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|: 1. Let |sheet| be null. 1. If |cssRuleOrDeclaration| is a {{CSSStyleDeclaration}} whose {{CSSStyleDeclaration/parentRule}} is not null, @@ -1161,34 +1161,38 @@ URL Processing Model 1. If |sheet|'s location is not null, return |sheet|'s location. - 1. Assert: |cssRuleOrDeclaration|'s [=relevant settings object=] is a {{Document}}. + 1. Return |cssRuleOrDeclaration|'s [=relevant settings object=]'s [=environment settings object/API base URL=]. - 1. Return |cssRuleOrDeclaration|'s [=relevant settings object=]'s [=document base URL=]. +
+
To resolve a style resource URL from a [=/url=] or <> |urlValue|, - and a a [=CSS style rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|, return the result of the [=URL parser=] steps - with |urlValue|'s [=/url=] and the [=style resource base URL=] given |cssRuleOrDeclaration|. + and a a [=CSS rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|: + 1. Let |base| be the [=style resource base URL=] given |cssRuleOrDeclaration|.. + 1. Return the result of the [=URL parser=] steps with |urlValue|'s [=/url=] and |base|.
To fetch a style resource from a [=/url=] or <> |urlValue|, - given an [=CSS style rule=] or a [=css declaration=] |cssRuleOrDeclaration|, + given an [=CSS 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 |parsedURL| be the result of [=resolve a style resource URL|resolving=] |urlValue| given |cssRuleOrDeclaration|. + 1. Let |parsedUrl| be the result of [=resolve a style resource URL|resolving=] |urlValue| given |cssRuleOrDeclaration|. If that failed, return. + 1. Let |settingsObject| be |cssRuleOrDeclaration|'s [=relevant settings object=]. + 4. Let |req| be a new [=/request=] whose [=request/url=] is |parsedUrl|, whose [=request/destination=] is |destination|, [=request/mode=] is |corsMode|, - [=request/origin=] is |document|'s [=environment settings object/origin=], + [=request/origin=] is |settingsObject|'s [=environment settings object/origin=], [=request/credentials mode=] is "same-origin", [=request/use-url-credentials flag=] is set, - [=request/client=] is |document|, - and whose [=request/referrer=] is |document|'s [=document base URL=]. + [=request/client=] is |settingsObject|, + and whose [=request/referrer=] is "client". 5. If |corsMode| is "no-cors", set |req|'s [=request/credentials mode=] to "include". @@ -1204,7 +1208,7 @@ URL Processing Model set |req|'s [=request/initiator type=] to "css". [[CSSOM]] 9. [=/Fetch=] |req|, - with [=fetch/processresponseconsumebody=] set to |processResponse|. + with [=fetch/processresponseconsumebody|processResponseConsumeBody=] set to |processResponse|.
When interpreting [=URLs=] expressed in CSS, From 1acbb03a8407b0e9690319adff6110f7c5d4a5d1 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 3 Jun 2025 14:03:16 +0100 Subject: [PATCH 4/4] nit --- css-values-4/Overview.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css-values-4/Overview.bs b/css-values-4/Overview.bs index bc82b318467..c8dce68d6de 100644 --- a/css-values-4/Overview.bs +++ b/css-values-4/Overview.bs @@ -1168,7 +1168,7 @@ URL Processing Model
To resolve a style resource URL from a [=/url=] or <> |urlValue|, and a a [=CSS rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|: - 1. Let |base| be the [=style resource base URL=] given |cssRuleOrDeclaration|.. + 1. Let |base| be the [=style resource base URL=] given |cssRuleOrDeclaration|. 1. Return the result of the [=URL parser=] steps with |urlValue|'s [=/url=] and |base|.