diff --git a/subresource-loading.bs b/subresource-loading.bs index d820be2c..ff0d66f7 100644 --- a/subresource-loading.bs +++ b/subresource-loading.bs @@ -8,18 +8,30 @@ Repository: WICG/webpackage URL: https://wicg.github.io/webpackage/subresource-loading.html Editor: Hayato Ito, Google Inc. https://google.com/, hayato@google.com Abstract: How UAs load subresources from Web Bundles. - Complain About: accidental-2119 yes, missing-example-ids yes Markup Shorthands: markdown yes, css no Assume Explicit For: yes +
+{
+  "draft-yasskin-wpack-bundled-exchanges": {
+    "href": "https://wicg.github.io/webpackage/draft-yasskin-wpack-bundled-exchanges.html",
+    "title": "Web Bundles"
+  }
+}
+
+
+spec: fetch; urlPrefix: https://fetch.spec.whatwg.org/#
+    type: dfn
+        text: fetch params; url: fetch-params
+
-
- # Introduction # {#intro} This section is non-normative. @@ -31,7 +43,143 @@ specification describes how web browsers load those resources. It is expressed as several monkeypatches to the [[HTML]] and [[FETCH]] specification which call algorithms defined here. -

- This specification is under construct. See - #708. -

+Note: This specification is under construct. See #708. + +# Structures # {#structures} + +A fetched web bundle is a representation of a web bundle format +defined in [[draft-yasskin-wpack-bundled-exchanges]]. + +A bundle rule is a [=struct=] with the following +[=struct/items=]: + +- source, a [=URL=]. +- credentials, a [=request/mode=]. +- resources, a list of [=URLs=]. +- scopes, a list of [=URLs=]. + +A web bundle is a [=struct=] with the following [=struct/items=]: + +- fetched bundle, a [=fetched web bundle=] or null. +- rule, a [=bundle rule=]. +- state, an internal state which is "fetching", "fetched", or "failed". Initially "fetching". + +# New Document fields # {#new-document-fields} + +A {{Document}} has a web bundle list, which is a list of [=web bundles=]. + +# Fetch web bundle # {#fetch-web-bundle-section} + +
+To fetch web bundle given [=web bundle=] |web bundle| and [=fetch params=] |fetch params|: + +1. Assert: |webbundle|'s [=web bundle/state=] is "fetching". + +1. Let |request| be |fetch params|'s [=request=]. + +1. Let |request|'s [=request/url=] is |webbundle|'s [=web bundle/rule=]'s [=bundle rule/source=]. + + Note: Source URL is resolved on document's base URL. + +1. Let |request|'s [=request/destination=] is "webbundle", + +1. Let |request|'s [=request/mode=] is "cors", + +1. Let |request|'s [=request/credentials mode=] be |web bundle|'s [=web bundle/rule=]'s [=bundle rule/credentials=] if [=bundle rule/credentials=] is non-null. Otherwise "same-origin" + +1. Append a [=header=], a tuple of ("Accept", "application/webbundle;v=1"), to |request|'s [=request/header list=]. + + Note: Chromium's experimental implementation uses "application/webbundle;v=b2" as a header value. + Once the web bundle format ([[draft-yasskin-wpack-bundled-exchanges]]) goes RFC, Chromium would use "1" as a version number. + +1. Let |response| be the result of running HTTP-network-or-cache fetch given |fetch params|. + + Note: Chromium's current implementation doesn't allow a *nested bundle*. + A Web bundle is never fetched from other web bundles. + +1. If |response|'s [=response/status=] is 200, + + 1. Let |webbundle|'s [=web bundle/fetched bundle=] be the result of parsing |response|'s body ([[draft-yasskin-wpack-bundled-exchanges]]) and |webbundle|' [=web bundle/state=] be "fetched". If parsing fails, or any other conformance is violated, let [=web bundle/fetched bundle=] be null and [=web bundle/state=] be "failed". + + Note: In parsing, Chromium's experimental implementation only accepts "b2" as a web bundle format version number ([[draft-yasskin-wpack-bundled-exchanges]]). + Once the web bundle format goes RFC, Chromium would accept "1" as a web bundle format version number. + +1. Otherwise, let |webbundle|' [=web bundle/state=] be "failed". + +
+ +# HTML monkeypatches # {#html-monkeypatches} + +## Script ## {#script} + +Note: TODO. This section uses [=fetch web bundle=]. + +# Fetch monkeypatches # {#fetch-monkeypatches} + +## Fetch subresource from web bundle ## {#fetch-subresource-from-web-bundle} + +In HTTP-network-or-cache fetch, before + +> 8.22. Set httpCache to the result of determining the HTTP cache partition, given|httpRequest|. + +add the following steps: + +22. Set the |response| to the result of [=fetch from web bundle=], given |httpRequest|. + + 1. If |response| is [=network error=], return [=network error=]. + + 2. If |response| is non-null, skip the steps 8.22-8.24 and goto the step 9. + + Note: That means a subresource from a webbundle never interacts with HttpCache. + We plan to support HttpCache as a feature enhancement in the future. + +
+To fetch from web bundle given [=request=] |httpRequest|: + + 1. For each |web bundle| of [=document=]'s [=document/web bundle list=]: + + 1. If the result of running [=match url with web bundle=] given |httpRequest|'s [=request/url=] and |web bundle| is true: + + 1. Let |response| be the result of [=get response from web bundle=] given |httpRequest|'s [=request/url=] and |web bundle|. + + 2. If |response| is null, return a [=network error=]. + + Note: This means a browser does not fallback to fetch a subresource from network. + + 3. Otherwise, return |response|. + + 2. Return null. + +
+ +
+ To match url with web bundle given [=url=] |url| and [=web bundle=] |web bundle|: + + 1. If |url| doesn't meet a path restriction rule, given |web bundle|'s [=web bundle/rule=]'s [=bundle rule/source=], then return false. + + Issue: Clarify path restriction rule in algorithm. + + + 2. If |url| matches any of |web bundle|'s [=web bundle/rule=]'s [=bundle rule/resources=], then return true. + + 2. If |url|'s prefix matches any of |web bundle|'s [=web bundle/rule=]'s [=bundle rule/scopes=], then return true. + + 3. Otherwise, return false. + +
+ +
+ To get response from web bundle given [=url=] |url| and [=web bundle=] |web bundle|: + + 1. If |web bundle|'s [=web bundle/state=] is "fetching", await until [=web bundle/state=] becomes "fetched" or "failed" asynchronously. + + 1. If |web bundle|'s [=web bundle/state=] is "failed", return null. + + 2. Assert: |web bundle|'s [=web bundle/fetched bundle=] is non-null. + + 3. Returns [=response=] from |web bundle|'s [=web bundle/fetched bundle=] given |url| ([[draft-yasskin-wpack-bundled-exchanges]]). If a representation of |url| is not found in [=web bundle/fetched bundle=], return null. +
+ +## Navigation ## {#navigation} + +Note: TODO