Skip to content

Commit 64becb5

Browse files
committed
Formalize fetching and resource timing reporting
Add a generic method to fetch style resources, and make use of it in fonts & imports. [css-syntax-3]: Make sure we have a location when parsing a stylesheet. [css-values-3]: Add a reusable method to fetch a style-originated resource. [css-cascade-4]: Formalize the import algorithm to use the new fetch method. [css=fonts-4]: Formalize font loading to use the new fetch method.
1 parent 92102b5 commit 64becb5

File tree

4 files changed

+80
-66
lines changed

4 files changed

+80
-66
lines changed

css-cascade-4/Overview.bs

+21-61
Original file line numberDiff line numberDiff line change
@@ -265,82 +265,42 @@ Processing Stylesheet Imports</h3>
265265
<div algorithm>
266266
To <dfn export>fetch an @import</dfn>, given an ''@import'' rule |rule|:
267267

268+
1. Let |parentStylesheet| be |rule|'s <a spec=cssom for=CSSRule>parent CSS style sheet</a>.
269+
[[CSSOM]]
270+
268271
1. If |rule| has a <<supports-condition>>,
269272
and that condition is not true,
270-
return nothing.
271-
272-
1. [=Parse a URL=] given |rule|'s URL,
273-
relative to |rule|'s [=CSSRule/parent CSS style sheet's=] [=CSSStyleSheet/location=].
274-
275-
Issue: Make sure this is defined correctly,
276-
drawing from the document when it's a <{style}> element, etc.
277-
278-
If that fails, then return nothing. Otherwise, let |url| be the [=resulting URL record=].
279-
280-
2. Let |request| be a new [=/request=]
281-
whose [=request/URL=] is |url|,
282-
[=request/destination=] is <code>"style"</code>,
283-
[=request/mode=] is <code>"no-cors"</code>,
284-
[=request/credentials mode=] is <code>"include"</code>,
285-
and whose [=request/use-URL-credentials flag=] is set.
286-
287-
3. Set |request|'s client to ????
288-
289-
Issue: The Fetch spec doesn't provide any information about what a client is
290-
or what it does,
291-
so I have no idea of what to provide here.
292-
293-
4. Run the following steps [=in parallel=]:
273+
return.
294274

295-
1. Let |response| be the result of [=/fetching=] |request|.
275+
1. Let |parsedUrl| be the result of the [=URL parser=] steps with |relativeUrl| and
276+
|parentStylesheet|'s <a spec=cssom>location</a>. If the algorithm returns an error,
277+
return. [[CSSOM]]
296278

297-
2. Let |success| initially be true.
279+
1. [=Fetch a style resource=] |parsedUrl|, with |parentStylesheet|, "style", "no-cors",
280+
and the following steps given [=/response=] |response|:
298281

299-
3. If |response| is a [=network error=]
300-
or its [=response/status=] is not an [=ok status=],
301-
set |success| to false.
282+
1. If |response| is a [=network error=] or its [=response/status=] is not an
283+
[=ok status=], return.
302284

303-
4. If |rule|'s [=CSSRule/parent style sheet=] is in [=quirks mode=]
285+
1. If |parentStylesheet| is in [=quirks mode=]
304286
and |response| is [=CORS-same-origin=],
305287
let |content type| be <code>"text/css"</code>.
306288
Otherwise, let |content type| be the Content Type metadata of |response|.
307289

308-
5. If |content type| is not <code>"text/css"</code>,
290+
1. If |content type| is not <code>"text/css"</code>,
309291
return.
310292

311-
6. Issue: Do we wait for sub-imports to run now?
312-
Need to explore this.
293+
1. Let |importedStylesheet| be the result of [=Parse a stylesheet|parsing=] |response|'s
294+
[=response/body=]'s [=body/stream=] given |parsedUrl|.
313295

314-
7. Let |global| be the result of [=finding the relevant global object for a stylesheet=]
315-
given |rule|'s [=CSSRule/parent CSS style sheet=].
296+
1. Set |importedStylesheet|'s <a spec=cssom>origin-clean flag</a> to
297+
|parentStylesheet|'s <a spec=cssom>origin-clean flag</a>.
316298

317-
8. [=Queue a global task=],
318-
given the [=networking task source=]
319-
and |global|,
320-
to [=process an imported stylesheet=]
321-
given |rule|,
322-
|success|,
323-
and |response|.
324-
</div>
325-
326-
<div algorithm>
327-
To <dfn export>find the relevant global object for a stylesheet</dfn> given a CSS style sheet |stylesheet|:
328-
329-
1. If |stylesheet| has a [=CSSStyleSheet/parent CSS style sheet=],
330-
return the result of [=finding the relevant global object for a stylesheet=]
331-
given the [=CSSStyleSheet/parent CSS style sheet=].
332-
333-
2. If |stylesheet| has an [=CSSStyleSheet/owner node=],
334-
return the [=CSSStyleSheet/owner node's=] [=relevant global object=].
335-
</div>
336-
337-
<div algorithm>
338-
To <dfn export>process an imported stylesheet</dfn>
339-
given a parent rule |rule|,
340-
a success flag |success|,
341-
and a response |response|:
299+
1. If |response|'s [=response/url=]'s [=url/origin=] is not the [=same origin=] as
300+
|rule|'s [=relevant settings object=]'s [=environment settings object/origin=],
301+
unset |importedStylesheet|'s <a spec=cssom>origin-clean flag</a>.
342302

343-
Issue: Create a stylesheet, assign it to the parent rule.
303+
1. Set |rule|'s {{CSSImportRule/styleSheet}} to |importedStylesheet|.
344304
</div>
345305

346306
<h3 id='content-type'>

css-fonts-4/Overview.bs

+12-3
Original file line numberDiff line numberDiff line change
@@ -2944,9 +2944,18 @@ downloadable fonts to avoid large page reflows where possible.
29442944
<h4 id="font-fetching-requirements" oldids="same-origin-restriction,allowing-cross-origin-font-loading">
29452945
Font fetching requirements</h4>
29462946

2947-
For font loads from @font-face rules, user agents must create a <a>request</a>
2948-
whose <var>url</var> is the URL given by the @font-face rule, whose <var>referrer</var>
2949-
is the stylesheet's URL, and whose <var>origin</var> is the URL of the containing document.
2947+
<div algorithm>
2948+
To <dfn>fetch a font</dfn> given a selected [=/url=] |url| for ''@font-face'' |rule|,
2949+
[=fetch a style resource|fetch=] |url|, with |rule|'s
2950+
<a spec=cssom for=CSSRule>parent CSS style sheet</a>, "font", "cors" and the following steps
2951+
given [=/response=] |res|:
2952+
2953+
1. Let |body| be |res|'s [=response/body=].
2954+
2955+
1. If |body| is null, return.
2956+
2957+
1. ISSUE: Load a font from |body| according to its type.
2958+
</div>
29502959

29512960
Note: The implications of this for authors are that fonts
29522961
will typically not be loaded cross-origin unless authors specifically

css-syntax-3/Overview.bs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,8 @@ Parse A Comma-Separated List According To A CSS Grammar</h4>
21212121
Parse a stylesheet</h4>
21222122

21232123
<div algorithm>
2124-
To <dfn export>parse a stylesheet</dfn> from an |input|:
2124+
To <dfn export>parse a stylesheet</dfn> from an |input| given [=/url=] or Null |location|
2125+
(default null):
21252126

21262127
<ol>
21272128
<li>
@@ -2134,7 +2135,7 @@ Parse a stylesheet</h4>
21342135
and set |input| to the result.
21352136

21362137
<li>
2137-
Create a new stylesheet.
2138+
Create a new stylesheet, with its <a spec=cssom>location</a> set to |location|.
21382139

21392140
<li>
21402141
<a>Consume a list of rules</a> from |input|,

css-values-4/Overview.bs

+44
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,50 @@ URL Modifiers</h4>
989989
Note: A <<url>> that is either unquoted or not wrapped in ''url()'' notation
990990
cannot accept any <<url-modifier>>s.
991991

992+
<h4 id='prcoessing-model'>
993+
URL processing model</h4>
994+
995+
<div algorithm>
996+
To <dfn export>fetch a style resource</dfn> [=/url=] |url|, given a {{CSSStyleSheet}}
997+
|sheet|, a string |destination|, a "no-cors" or "cors" |corsMode|, and an algorithm
998+
|processResponse| accepting a [=/response=]:
999+
1000+
1. Let |environmentSettings| be |sheet|'s [=relevant settings object=].
1001+
1002+
1. Let |global| be |environmentSettings|'s [=environment settings object/global object=].
1003+
1004+
1. Let |documentBase| be |environmentSettings|'s [=API base URL=].
1005+
1006+
1. Let |base| be |sheet|'s <a spec=cssom>stylesheet base URL</a>. [[CSSOM]]
1007+
1008+
1. Let |referrer| be |documentBase|.
1009+
1010+
1. Let |handleResourceFetchDone| be to do nothing.
1011+
1012+
1. If |base| is null, set |base| to |documentBase|.
1013+
1014+
1. Let |parsedUrl| be the result of the [=URL parser=] steps with |url| and |base|.
1015+
If the algorithm returns an error, return.
1016+
1017+
1. If |corsMode| is not "cors", or |url| is the [=same origin=] as |environmentSettings|'s
1018+
[=environment settings object/origin=], set |referrer| to |sheet|'s
1019+
<a spec=cssom>location</a>. [[CSSOM]]
1020+
1021+
1. Let |req| be a new [=/request=] whose [=request/url=] is |parsedUrl|, whose
1022+
[=request/destination=] is |destination|, [=request/mode=] is |mode|, [=request/origin=]
1023+
is |environmentSettings|'s [=environment settings object/origin=],
1024+
[=request/credentials mode=] is "same-origin", [=request/use-url-credentials flag=] is
1025+
set, and whose [=request/header list=] is a [=/header list=] containing a [=header=]
1026+
with its [=header/name=] set to "referrer" and its [=header/value=] set to |referrer|.
1027+
1028+
1. If |sheet|'s <a spec=cssom>origin-clean flag</a> is set, set |handleResourceFetchDone|
1029+
given [=/response=] |res| to [=finalize and report timing=] with |res|, |global|, and
1030+
<code>"css"</code>. [[CSSOM]]
1031+
1032+
1. [=/Fetch=] |req|, with |processResponseDone| set to |handleResourceFetchDone|,
1033+
|taskDestination| set to |global|, and |processResponse| set to |processResponse|.
1034+
</div>
1035+
9921036
<h2 id="numeric-types">
9931037
Numeric Data Types</h2>
9941038

0 commit comments

Comments
 (0)