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

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -265,82 +265,42 @@ Processing Stylesheet Imports
265265
266266
To fetch an @import, given an ''@import'' rule |rule|:
267267

268+
1. Let |parentStylesheet| be |rule|'s parent CSS style sheet.
269+
[[CSSOM]]
270+
268271
1. If |rule| has a <>,
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 "style",
283-
[=request/mode=] is "no-cors",
284-
[=request/credentials mode=] is "include",
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 location. 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 "text/css".
306288
Otherwise, let |content type| be the Content Type metadata of |response|.
307289

308-
5. If |content type| is not "text/css",
290+
1. If |content type| is not "text/css",
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 origin-clean flag to
297+
|parentStylesheet|'s origin-clean flag.
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-
325-
326-
327-
To find the relevant global object for a stylesheet 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-
336-
337-
338-
To process an imported stylesheet
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 origin-clean flag.
342302

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

346306

css-fonts-4/Overview.bs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,9 +2944,18 @@ downloadable fonts to avoid large page reflows where possible.
29442944

29452945
Font fetching requirements
29462946

2947-
For font loads from @font-face rules, user agents must create a request
2948-
whose url is the URL given by the @font-face rule, whose referrer
2949-
is the stylesheet's URL, and whose origin is the URL of the containing document.
2947+
2948+
To fetch a font given a selected [=/url=] |url| for ''@font-face'' |rule|,
2949+
[=fetch a style resource|fetch=] |url|, with |rule|'s
2950+
parent CSS style sheet, "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+
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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,8 @@ Parse A Comma-Separated List According To A CSS Grammar
21212121
Parse a stylesheet
21222122

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

21262127
    21272128
  1. @@ -2134,7 +2135,7 @@ Parse a stylesheet
    21342135
    and set |input| to the result.
    21352136

    21362137
  2. 2137-
    Create a new stylesheet.
    2138+
    Create a new stylesheet, with its location set to |location|.
    21382139

    21392140
  3. 21402141

    css-values-4/Overview.bs

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

    992+

    993+
    URL processing model
    994+
    995+
    996+
    To fetch a style resource [=/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 stylesheet base URL. [[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+
    location. [[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 origin-clean flag is set, set |handleResourceFetchDone|
    1029+
    given [=/response=] |res| to [=finalize and report timing=] with |res|, |global|, and
    1030+
    "css". [[CSSOM]]
    1031+
    1032+
    1. [=/Fetch=] |req|, with |processResponseDone| set to |handleResourceFetchDone|,
    1033+
    |taskDestination| set to |global|, and |processResponse| set to |processResponse|.
    1034+
    1035+
    9921036

    9931037
    Numeric Data Types
    9941038

    0 commit comments

    Comments
     (0)