diff --git a/docs/index.bs b/docs/index.bs index a5b3635f..468c5cc9 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -133,6 +133,22 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ text: obtain a storage key; url: obtain-a-storage-key text: storage key/equals; url: storage-key-equals +spec: urlpattern; urlPrefix: https://wicg.github.io/urlpattern/ + type: dfn + text: parse; for: urlpattern; url: parse-a-pattern-string + text: component; for: urlpattern; url: component + text: match; for: urlpattern; url: match + text: protocol component; for: urlpattern; url: urlpattern-protocol-component + text: username component; for: urlpattern; url: urlpattern-username-component + text: password component; for: urlpattern; url: urlpattern-password-component + text: hostname component; for: urlpattern; url: urlpattern-hostname-component + text: port component; for: urlpattern; url: urlpattern-port-component + text: pathname component; for: urlpattern; url: urlpattern-pathname-component + text: search component; for: urlpattern; url: urlpattern-search-component + text: hash component; for: urlpattern; url: urlpattern-hash-component + text: pattern string; for: urlpattern-component; url: component-pattern-string + text: type; for: urlpattern-part; url: part-type +
@@ -207,6 +223,8 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ A [=/service worker=] has an associated all fetch listeners are empty flag. It is initially unset. + A [=/service worker=] has an associated static router rules object. It is initially unset. + A [=/service worker=] is said to be running if its [=event loop=] is running.@@ -1545,6 +1563,46 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ Note: [=/Service workers=] delay treating the [=installing worker=] as "`installed`" until all the [=promises=] in the {{install!!event}} event's [=extend lifetime promises=] resolve successfully. (See the relevant [Install algorithm step](#install-settle-step).) If any of the promises rejects, the installation fails. This is primarily used to ensure that a [=/service worker=] is not considered "`installed`" until all of the core caches it depends on are populated. Likewise, [=/service workers=] delay treating the [=active worker=] as "`activated`" until all the [=promises=] in the {{activate!!event}} event's [=extend lifetime promises=] settle. (See the relevant [Activate algorithm step](#activate-settle-step).) This is primarily used to ensure that any [=functional events=] are not dispatched to the [=/service worker=] until it upgrades database schemas and deletes the outdated cache entries. ++ +{{InstallEvent}}
+ ++ [Exposed=ServiceWorker] + interface InstallEvent : ExtendableEvent { + Promise<undefined> registerRouter((RouterRule or sequence<RouterRule>) rules); + }; + + dictionary RouterRule { + required RouterCondition condition; + required RouterSourceEnum source; + }; + + dictionary RouterCondition { + USVString urlPattern; + }; + + enum RouterSourceEnum { "network" }; ++ + Each {{RouterCondition/urlPattern}} object has an associated URLPattern, a {{URLPattern}}, which is initially unset. + ++ +{{InstallEvent/registerRouter(rules)|event.registerRouter(rules)}}
+ + {{InstallEvent/registerRouter(rules)}} registers this service worker the rules to offload simple tasks that the fetch handler does. + +registerRouter(|rules|)
method *must* run these steps: + + 1. Let |routerRules| be a list of {{RouterRule}} dictionaries. + 1. If |rules| is a {{RouterRule}} dictionary, set |rules| to « |rules| ». + 1. for each |rule| in |rules|: + 1. If running [=VerifyRouterRule=] algorithm with |rule| and [=/service worker=] returns false, throw aTypeError
. + 1. Append |rule| to |routerRules|. + 1. Set [=/service worker=]'s [=static router rules object=] to |routerRules|. + ++ {{FetchEvent}}
@@ -2822,7 +2880,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ 1. Set |installFailed| to true. 1. Else: 1. [=Queue a task=] |task| on |installingWorker|'s [=event loop=] using the [=DOM manipulation task source=] to run the following steps: - 1. Let |e| be the result of creating an event with {{ExtendableEvent}}. + 1. Let |e| be the result of creating an event with {{InstallEvent}}. 1. Initialize |e|’s {{Event/type}} attribute to {{install!!event}}. 1. Dispatch |e| at |installingWorker|'s [=service worker/global object=]. 1. *WaitForAsynchronousExtensions*: Run the following substeps in parallel: @@ -3067,6 +3125,8 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ 1. Assert: |request|'s [=request/destination=] is not "serviceworker
". 1. If |request|'s [=request/destination=] is either "embed
" or "object
", then: 1. Return null. + 1. Else if |registration|'s active worker's [=static router rules object=] is set: + 1. If running [=GetRouterSource=] algorithm with [=static router rules object=] and |request| returns "network", return null. 1. Else if |request| is a non-subresource request, then: 1. If |reservedClient| is not null and is an environment settings object, then: 1. If |reservedClient| is not a secure context, return null. @@ -3175,6 +3235,78 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ 1. Return |response|.+ + +VerifyRouterRule
+ + : Input + :: |rule|, a {{RouterRule}} + :: |serviceWorker|, a [=/service worker=] + : Output + :: a boolean + + 1. If |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"] is the empty string, return false. + 1. Let |rawPattern| be |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"]. + 1. If |rawPattern| is a [=string=], then: + 1. Let |baseURL| be |serviceWorker|'s [=service worker/script url=]. + 1. Set |pattern| to the result of constructing a {{URLPattern}} using the {{URLPattern/URLPattern(input, baseURL)}} constructor steps given |rawPattern| and |baseURL|. If those steps throw, catch the exception and return false. + 1. Otherwise, if |rawPattern| is {{URLPatternInit}}: + 1. Set |pattern| to the result of constructing a {{URLPattern}} using the {{URLPattern/URLPattern(input)}} constructor steps given |rawPattern|. If those steps throw, catch the exception and return false. + 1. Otherwise, return false. + 1. If running the [=VerifyURLPattern=] algorithm with |pattern| returns false, return false. + 1. Set |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"]'s associated {{URLPattern}} to |pattern|. + 1. Return true. ++ + +VerifyURLPattern
+ + : Input + :: |pattern|, a {{URLPattern}} + : Output + :: a boolean + + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/protocol component=] returns false, return false. + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/username component=] returns false, return false. + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/password component=] returns false, return false. + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/hostname component=] returns false, return false. + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/port component=] returns false, return false. + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/pathname component=] returns false, return false. + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/search component=] returns false, return false. + 1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/hash component=] returns false, return false. + 1. Return true. ++ + +VerifyURLPatternComponent
+ + : Input + :: |component|, a [=component=]. + : Output + :: a boolean + + 1. Let |parts| be a result of [=urlpattern/parsing=] |component|'s associated [=urlpattern-component/pattern string=]. + 1. [=list/For each=] |part| of |parts|: + 1. If |part|'s [=urlpattern-part/type=] is "regexp
", return false. + + Note: Since running a user-defined regular expression has a security concern, it is prohibited. + + 1. Return true. ++ +GetRouterSource
+ : Input + :: |rules|, a list of {{RouterRule}} + :: |request|, a [=/request=] + : Output + :: {{RouterSourceEnum}} or null + + 1. [=list/For each=] |rule| of |rules|: + 1. If running [=urlpattern/match=] with |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"]'s associated [=URLPattern=] and |request|'s [=request/URL=] returns null, [=continue=]. + 1. Return |rule|'s {{RouterRule/source}}. + 1. Return null. +Should Skip Event
: Input