Skip to content

Commit

Permalink
Clients.get: block on reserved clients. (#1323)
Browse files Browse the repository at this point in the history
To reflect the decision that we don't expose reserved clients (#1216),
this change introduces the client's discarded flag, and uses that flag and the
execution ready flag to resolve the promise when the client reaches one of those
states instead of capturing and exposing the reserved client.

Follow-up to 07e9487 (#1259).
  • Loading branch information
mfalken authored and jungkees committed Jun 13, 2018
1 parent 70e76c5 commit cca62e6
Show file tree
Hide file tree
Showing 2 changed files with 429 additions and 350 deletions.
67 changes: 45 additions & 22 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe

A <dfn export id="dfn-service-worker-client" for="">service worker client</dfn> is an [=environment=].

A [=/service worker client=] has an associated <dfn export>discarded flag</dfn>. It is initially unset.

Each [=/service worker client=] has the following [=environment discarding steps=]:
1. Set |client|'s [=discarded flag=].

Note: Implementations can discard clients whose [=discarded flag=] is set.

A [=/service worker client=] has an algorithm defined as the <dfn export for="service worker client">origin</dfn> that returns the [=/service worker client=]'s [=environment settings object/origin=] if the [=/service worker client=] is an [=environment settings object=], and the [=/service worker client=]'s <a>creation URL</a>'s [=url/origin=] otherwise.

A <dfn export id="dfn-window-client">window client</dfn> is a [=/service worker client=] whose [=environment settings object/global object=] is a {{Window}} object.
Expand Down Expand Up @@ -1147,28 +1154,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Let |promise| be a new <a>promise</a>.
1. Run these substeps <a>in parallel</a>:
1. For each [=/service worker client=] |client| whose [=service worker client/origin=] is the <a lt="same origin">same</a> as the associated [=ServiceWorkerGlobalScope/service worker=]'s [=environment settings object/origin=]:
1. If |client|'s [=environment/id=] is not |id|, continue to the next iteration of the loop.
1. If |client| is an [=environment settings object=], then:
1. If |client| is not a <a>secure context</a>, reject |promise| with a "{{SecurityError}}" {{DOMException}} and abort these steps.
1. Else:
1. If |client|’s <a>creation URL</a> is not a <a>potentially trustworthy URL</a>, reject |promise| with a "{{SecurityError}}" {{DOMException}} and abort these steps.
1. If |client| is an [=environment settings object=] and is not a [=window client=], then:
1. Let |clientObject| be the result of running <a>Create Client</a> algorithm with |client| as the argument.
1. Resolve |promise| with |clientObject| and abort these steps.
1. Else:
1. Let |browsingContext| be null.
1. Let |visibilityState| be null.
1. Let |focusState| be false.
1. Let |ancestorOriginsList| be the empty list.
1. If |client| is an [=environment settings object=], set |browsingContext| to |client|'s [=environment settings object/global object=]'s [=/browsing context=].
1. Else, set |browsingContext| to |client|’s [=environment/target browsing context=].
1. <a>Queue a task</a> |task| to run the following substeps on |browsingContext|'s <a>event loop</a> using the <a>user interaction task source</a>:
1. Set |visibilityState| to |browsingContext|'s <a>active document</a>'s {{Document/visibilityState}} attribute value.
1. Set |focusState| to the result of running the <a>has focus steps</a> with |browsingContext|'s <a>active document</a> as the argument.
1. If |client| is a <a>window client</a>, set |ancestorOriginsList| to |browsingContext|'s <a>active document</a>'s <a>relevant global object</a>'s {{Location}} object's [=Location/ancestor origins list=]'s associated list.
1. Wait for |task| to have executed.
1. Let |windowClient| be the result of running <a>Create Window Client</a> algorithm with |client|, |visibilityState|, |focusState|, and |ancestorOriginsList| as the arguments.
1. Resolve |promise| with |windowClient| and abort these steps.
1. If |client|'s [=environment/id=] is not |id|, [=continue=].
1. Wait for either |client|'s [=environment/execution ready flag=] to be set or for |client|'s [=discarded flag=] to be set.
1. If |client|'s [=environment/execution ready flag=] is set, then invoke [=Resolve Get Client Promise=] with |client| and |promise|, and abort these steps.
1. Resolve |promise| with undefined.
1. Return |promise|.
</section>
Expand Down Expand Up @@ -3216,6 +3204,41 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe

Note: When an exception is [=throw|thrown=], the implementation does undo (roll back) any changes made to the cache storage during the batch operation job.
</section>

<section algorithm>
<h3 id="resolve-get-client-promise-algorithm"><dfn>Resolve Get Client Promise</dfn></h3>

: Input
:: |client|, a [=/service worker client=]
:: |promise|, a [=promise=]

: Output
:: none

1. If |client| is an [=environment settings object=], then:
1. If |client| is not a [=secure context=], reject |promise| with a "{{SecurityError}}" {{DOMException}} and abort these steps.
1. Else:
1. If |client|’s [=creation URL=] is not a [=potentially trustworthy URL=], reject |promise| with a "{{SecurityError}}" {{DOMException}} and abort these steps.
1. If |client| is an [=environment settings object=] and is not a [=window client=], then:
1. Let |clientObject| be the result of running [=Create Client=] algorithm with |client| as the argument.
1. Resolve |promise| with |clientObject| and abort these steps.
1. Else:
1. Let |browsingContext| be null.
1. Let |visibilityState| be null.
1. Let |focusState| be false.
1. Let |ancestorOriginsList| be the empty list.
1. If |client| is an [=environment settings object=], set |browsingContext| to |client|'s [=environment settings object/global object=]'s [=/browsing context=].
1. Else, set |browsingContext| to |client|’s [=environment/target browsing context=].
1. [=Queue a task=] |task| to run the following substeps on |browsingContext|'s [=event loop=] using the [=user interaction task source=]:
1. Set |visibilityState| to |browsingContext|'s [=active document=]'s {{Document/visibilityState}} attribute value.
1. Set |focusState| to the result of running the [=has focus steps=] with |browsingContext|'s [=active document=] as the argument.
1. If |client| is a [=window client=], set |ancestorOriginsList| to |browsingContext|'s [=active document=]'s [=relevant global object=]'s {{Location}} object's [=Location/ancestor origins list=]'s associated list.
1. Wait for |task| to have executed.
1. If |client|'s [=discarded flag=] is set, resolve |promise| with undefined and abort these steps.
1. Let |windowClient| be the result of running [=Create Window Client=] algorithm with |client|, |visibilityState|, |focusState|, and |ancestorOriginsList| as the arguments.
1. Resolve |promise| with |windowClient|.
</section>

</section>

<section>
Expand Down
Loading

0 comments on commit cca62e6

Please sign in to comment.