Skip to content

Commit a5bc071

Browse files
committed
Add an option to include frozen documents.
It is off by default to exclude them when frozen. Since postMessage will be delayed until the page is unfrozen this is the safest option to exclude frozen pages by default.
1 parent 7c07a47 commit a5bc071

File tree

1 file changed

+56
-11
lines changed

1 file changed

+56
-11
lines changed

docs/index.bs

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ spec: page-visibility; urlPrefix: https://www.w3.org/TR/page-visibility/
6666
type: enum; text: VisibilityState; url: VisibilityState
6767
type: attribute; text: visibilityState; for: Document; url: dom-document-visibilitystate
6868

69+
spec: page-lifecycle; urlPrefix: https://wicg.github.io/page-lifecycle/spec.html
70+
type: dfn; text: frozen; url: frozen
71+
type: dfn; text: owning document; url: dedicatedworkerglobalscope-owning-document
72+
6973
spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
7074
type: attribute
7175
urlPrefix: comms.html
@@ -1048,6 +1052,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
10481052
readonly attribute FrameType frameType;
10491053
readonly attribute DOMString id;
10501054
readonly attribute ClientType type;
1055+
readonly attribute ClientState state;
10511056
void postMessage(any message, sequence<object> transfer);
10521057
void postMessage(any message, optional PostMessageOptions options);
10531058
};
@@ -1073,6 +1078,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
10731078

10741079
A {{Client}} object has an associated <dfn id="dfn-service-worker-client-frame-type" for="Client">frame type</dfn>, which is one of "`auxiliary`", "`top-level`", "`nested`", and "`none`". Unless stated otherwise it is "`none`".
10751080

1081+
A {{Client}} object has an associated <dfn id="dfn-service-worker-client-state" for="Client">client state</dfn>, which is one of "`active`", and "`frozen`". Unless stated otherwise it is "`active`".
1082+
10761083
A {{WindowClient}} object has an associated <dfn id="dfn-service-worker-client-browsing-context" for="WindowClient">browsing context</dfn>, which is its [=Client/service worker client=]'s [=environment settings object/global object=]'s [=/browsing context=].
10771084

10781085
A {{WindowClient}} object has an associated <dfn id="dfn-service-worker-client-visibilitystate">visibility state</dfn>, which is one of {{Document/visibilityState}} attribute value.
@@ -1113,6 +1120,12 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
11131120
1. Return {{ClientType/"window"}}.
11141121
</section>
11151122

1123+
<section>
1124+
<h4 id="client-state">{{Client/state}}</h4>
1125+
1126+
The <dfn attribute for="Client"><code>state</code></dfn> attribute *must* return the <a>context object</a>'s <a>client state</a>.
1127+
</section>
1128+
11161129
<section algorithm="client-postmessage">
11171130
<h4 id="client-postmessage">{{Client/postMessage(message, transfer)}}</h4>
11181131

@@ -1176,11 +1189,12 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
11761189
1. [=Queue a task=] to run the following steps on the [=context object=]'s associated [=Client/service worker client=]'s [=responsible event loop=] using the [=user interaction task source=]:
11771190
1. Run the [=focusing steps=] with the [=context object=]'s [=WindowClient/browsing context=].
11781191
1. Let |frameType| be the result of running [=Get Frame Type=] with the [=context object=]'s [=WindowClient/browsing context=].
1192+
1. Let |state| be the result of running [=Get Client State=] with [=context object=]'s associated [=Client/service worker client=].
11791193
1. Let |visibilityState| be the [=context object=]'s [=WindowClient/browsing context=]'s [=active document=]'s {{Document/visibilityState}} attribute value.
11801194
1. Let |focusState| be the result of running the [=has focus steps=] with the [=context object=]'s [=WindowClient/browsing context=]'s [=active document=].
11811195
1. Let |ancestorOriginsList| be the [=context object=]'s [=WindowClient/browsing context=]'s [=active document=]'s [=relevant global object=]'s {{Location}} object's [=Location/ancestor origins list=]'s associated list.
11821196
1. [=Queue a task=] to run the following steps on |serviceWorkerEventLoop| using the [=DOM manipulation task source=]:
1183-
1. Let |windowClient| be the result of running [=Create Window Client=] with the [=context object=]'s associated [=Client/service worker client=], |frameType|, |visibilityState|, |focusState|, and |ancestorOriginsList|.
1197+
1. Let |windowClient| be the result of running [=Create Window Client=] with the [=context object=]'s associated [=Client/service worker client=], |frameType|, |visibilityState|, |focusState|, |ancestorOriginsList|, and |state|.
11841198
1. If |windowClient|'s [=focus state=] is true, resolve |promise| with |windowClient|.
11851199
1. Else, reject |promise| with a `TypeError`.
11861200
1. Return |promise|.
@@ -1203,12 +1217,13 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12031217
1. *HandleNavigate*: [=Navigate=] |browsingContext| to |url| with [=exceptions enabled flag|exceptions enabled=]. The [=source browsing context=] must be |browsingContext|.
12041218
1. If the algorithm steps invoked in the step labeled *HandleNavigate* [=throws=] an exception, [=queue a task=] to reject |promise| with the exception, on |serviceWorkerEventLoop| using the [=DOM manipulation task source=], and abort these steps.
12051219
1. Let |frameType| be the result of running [=Get Frame Type=] with |browsingContext|.
1220+
1. Let |state| be the result of running [=Get Client State=] with [=context object=]'s associated [=Client/service worker client=].
12061221
1. Let |visibilityState| be |browsingContext|'s <a>active document</a>'s {{Document/visibilityState}} attribute value.
12071222
1. Let |focusState| be the result of running the [=has focus steps=] with |browsingContext|'s [=active document=].
12081223
1. Let |ancestorOriginsList| be |browsingContext|'s [=active document=]'s [=relevant global object=]'s {{Location}} object's [=Location/ancestor origins list=]'s associated list.
12091224
1. [=Queue a task=] to run the following steps on |serviceWorkerEventLoop| using the [=DOM manipulation task source=]:
12101225
1. If |browsingContext|'s {{Window}} object's <a>environment settings object</a>'s <a>creation URL</a>'s [=url/origin=] is not the <a lt="same origin">same</a> as the [=ServiceWorkerGlobalScope/service worker=]'s [=environment settings object/origin=], resolve |promise| with null and abort these steps.
1211-
1. Let |windowClient| be the result of running [=Create Window Client=] with the [=context object=]'s [=Client/service worker client=], |frameType|, |visibilityState|, |focusState|, and |ancestorOriginsList|.
1226+
1. Let |windowClient| be the result of running [=Create Window Client=] with the [=context object=]'s [=Client/service worker client=], |frameType|, |visibilityState|, |focusState|, |ancestorOriginsList|, and |state|.
12121227
1. Resolve |promise| with |windowClient|.
12131228
1. Return |promise|.
12141229
</section>
@@ -1230,6 +1245,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12301245
<pre class="idl" id="serviceworker-client-query-options-dictionary">
12311246
dictionary ClientQueryOptions {
12321247
boolean includeUncontrolled = false;
1248+
ClientState state = "active";
12331249
ClientType type = "window";
12341250
};
12351251
</pre>
@@ -1241,6 +1257,13 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12411257
"all"
12421258
};
12431259
</pre>
1260+
<pre class="idl" id="client-state-enum">
1261+
enum ClientState {
1262+
"active",
1263+
"frozen",
1264+
"all"
1265+
};
1266+
</pre>
12441267

12451268
The user agent *must* create a {{Clients}} object when a {{ServiceWorkerGlobalScope}} object is created and associate it with that object.
12461269

@@ -1273,10 +1296,12 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12731296
1. If |options|["{{ClientQueryOptions/includeUncontrolled}}"] is false, and if |client|'s [=active service worker=] is not the associated [=ServiceWorkerGlobalScope/service worker=], [=continue=].
12741297
1. Add |client| to |targetClients|.
12751298
1. Let |matchedWindowData| be a new [=list=].
1276-
1. Let |matchedClients| be a new [=list=].
1299+
1. Let |matchedClientData| be a new [=list=].
12771300
1. For each [=/service worker client=] |client| in |targetClients|:
1301+
1. Let |state| be the result of running [=Get Client State=] with |client|.
1302+
1. If |options|["{{ClientQueryOptions/type}}"] is not {{ClientType/"all"}} and does not equal |state|, then [=continue=].
12781303
1. If |options|["{{ClientQueryOptions/type}}"] is {{ClientType/"window"}} or {{ClientType/"all"}}, and |client| is not an [=environment settings object=] or is a [=window client=], then:
1279-
1. Let |windowData| be «[ "client" → |client|, "ancestorOriginsList" → a new [=list=] ]».
1304+
1. Let |windowData| be «[ "client" → |client|, "ancestorOriginsList" → a new [=list=], "state" → |state| ]».
12801305
1. Let |browsingContext| be null.
12811306
1. Let |isClientEnumerable| be true.
12821307
1. If |client| is an [=environment settings object=], set |browsingContext| to |client|'s [=environment settings object/global object=]'s [=/browsing context=].
@@ -1295,14 +1320,14 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
12951320
1. If |isClientEnumerable| is true, then:
12961321
1. Add |windowData| to |matchedWindowData|.
12971322
1. Else if |options|["{{ClientQueryOptions/type}}"] is {{ClientType/"worker"}} or {{ClientType/"all"}} and |client| is a [=dedicated worker client=], or |options|["{{ClientQueryOptions/type}}"] is {{ClientType/"sharedworker"}} or {{ClientType/"all"}} and |client| is a [=shared worker client=], then:
1298-
1. Add |client| to |matchedClients|.
1323+
1. Add «[ "client" → |client|, "state" → |state| ]» to |matchedClientData|.
12991324
1. [=Queue a task=] to run the following steps on |promise|'s [=relevant settings object=]'s [=responsible event loop=] using the [=DOM manipulation task source=]:
13001325
1. Let |clientObjects| be a new [=list=].
13011326
1. [=list/For each=] |windowData| in |matchedWindowData|:
1302-
1. Let |windowClient| be the result of running [=Create Window Client=] algorithm with |windowData|["`client`"], |windowData|["`frameType`"], |windowData|["`visibilityState`"], |windowData|["`focusState`"], and |windowData|["`ancestorOriginsList`"] as the arguments.
1327+
1. Let |windowClient| be the result of running [=Create Window Client=] algorithm with |windowData|["`client`"], |windowData|["`frameType`"], |windowData|["`visibilityState`"], |windowData|["`focusState`"], |windowData|["`ancestorOriginsList`"], and |windowData|["`state`"] as the arguments.
13031328
1. [=Append=] |windowClient| to |clientObjects|.
1304-
1. [=list/For each=] |client| in |matchedClients|:
1305-
1. Let |clientObject| be the result of running [=Create Client=] algorithm with |client| as the argument.
1329+
1. [=list/For each=] |clientData| in |matchedClientData|:
1330+
1. Let |clientObject| be the result of running [=Create Client=] algorithm with |clientData|["`client`"], and |clientData|["`state`"] as the arguments.
13061331
1. [=Append=] |clientObject| to |clientObjects|.
13071332
1. Sort |clientObjects| such that:
13081333
* {{WindowClient}} objects whose [=WindowClient/browsing context=] has been [=focusing steps|focused=] are placed first, sorted in the most recently [=focusing steps|focused=] order.
@@ -1332,11 +1357,12 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
13321357
1. If the algorithm steps invoked in the step labeled *HandleNavigate* [=throws=] an exception, [=queue a task=] to reject |promise| with the exception, on |serviceWorkerEventLoop| using the [=DOM manipulation task source=], and abort these steps.
13331358
1. Let |frameType| be the result of running [=Get Frame Type=] with |newContext|.
13341359
1. Let |visibilityState| be |newContext|'s <a>active document</a>'s {{Document/visibilityState}} attribute value.
1360+
1. Let |state| be the result of running [=Get Client State=] with [=context object=]'s associated [=Client/service worker client=].
13351361
1. Let |focusState| be the result of running the <a>has focus steps</a> with |newContext|'s <a>active document</a> as the argument.
13361362
1. Let |ancestorOriginsList| be |newContext|'s <a>active document</a>'s <a>relevant global object</a>'s {{Location}} object's [=Location/ancestor origins list=]'s associated list.
13371363
1. [=Queue a task=] to run the following steps on |serviceWorkerEventLoop| using the [=DOM manipulation task source=]:
13381364
1. If |newContext|'s {{Window}} object's [=environment settings object=]'s [=creation URL=]'s [=environment settings object/origin=] is not the [=same origin|same=] as the [=ServiceWorkerGlobalScope/service worker=]'s [=environment settings object/origin=], resolve |promise| with null and abort these steps.
1339-
1. Let |client| be the result of running [=Create Window Client=] with |newContext|'s {{Window}} object's [=environment settings object=], |frameType|, |visibilityState|, |focusState|, and |ancestorOriginsList| as the arguments.
1365+
1. Let |client| be the result of running [=Create Window Client=] with |newContext|'s {{Window}} object's [=environment settings object=], |frameType|, |visibilityState|, |focusState|, |ancestorOriginsList|, and |state| as the arguments.
13401366
1. Resolve |promise| with |client|.
13411367
1. Return |promise|.
13421368
</section>
@@ -3291,11 +3317,13 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
32913317

32923318
: Input
32933319
:: |client|, a [=/service worker client=]
3320+
:: |state|, a string
32943321
: Output
32953322
:: |clientObject|, a {{Client}} object
32963323

32973324
1. Let |clientObject| be a new {{Client}} object.
32983325
1. Set |clientObject|'s [=Client/service worker client=] to |client|.
3326+
1. Set |clientObject|'s [=state=] to |state|.
32993327
1. Return |clientObject|.
33003328
</section>
33013329

@@ -3308,6 +3336,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
33083336
:: |visibilityState|, a string
33093337
:: |focusState|, a boolean
33103338
:: |ancestorOriginsList|, a list
3339+
:: |state|, a string
33113340
: Output
33123341
:: |windowClient|, a {{WindowClient}} object
33133342

@@ -3316,6 +3345,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
33163345
1. Set |windowClient|'s [=frame type=] to |frameType|.
33173346
1. Set |windowClient|'s [=visibility state=] to |visibilityState|.
33183347
1. Set |windowClient|'s [=focus state=] to |focusState|.
3348+
1. Set |windowClient|'s [=state=] to |state|.
33193349
1. Set |windowClient|'s [=WindowClient/ancestor origins array=] to a [=frozen array type|frozen array=] created from |ancestorOriginsList|.
33203350
1. Return |windowClient|.
33213351
</section>
@@ -3353,8 +3383,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
33533383
1. If |client| is not a [=secure context=], [=queue a task=] to reject |promise| with a "{{SecurityError}}" {{DOMException}}, on |promise|'s [=relevant settings object=]'s [=responsible event loop=] using the [=DOM manipulation task source=], and abort these steps.
33543384
1. Else:
33553385
1. If |client|’s [=creation URL=] is not a [=potentially trustworthy URL=], [=queue a task=] to reject |promise| with a "{{SecurityError}}" {{DOMException}}, on |promise|'s [=relevant settings object=]'s [=responsible event loop=] using the [=DOM manipulation task source=], and abort these steps.
3386+
1. Let |state| be the result of running [=Get Client State=] with |client|.
33563387
1. If |client| is an [=environment settings object=] and is not a [=window client=], then:
3357-
1. Let |clientObject| be the result of running [=Create Client=] algorithm with |client| as the argument.
3388+
1. Let |clientObject| be the result of running [=Create Client=] algorithm with |client|, and |state| as the arguments.
33583389
1. [=Queue a task=] to resolve |promise| with |clientObject|, on |promise|'s [=relevant settings object=]'s [=responsible event loop=] using the [=DOM manipulation task source=], and abort these steps.
33593390
1. Else:
33603391
1. Let |browsingContext| be null.
@@ -3368,7 +3399,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
33683399
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.
33693400
1. [=Queue a task=] to run the following steps on |promise|'s [=relevant settings object=]'s [=responsible event loop=] using the [=DOM manipulation task source=]:
33703401
1. If |client|'s [=discarded flag=] is set, resolve |promise| with undefined and abort these steps.
3371-
1. Let |windowClient| be the result of running [=Create Window Client=] with |client|, |frameType|, |visibilityState|, |focusState|, and |ancestorOriginsList|.
3402+
1. Let |windowClient| be the result of running [=Create Window Client=] with |client|, |frameType|, |visibilityState|, |focusState|, |ancestorOriginsList| and |state|.
33723403
1. Resolve |promise| with |windowClient|.
33733404
</section>
33743405

@@ -3465,6 +3496,20 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
34653496

34663497
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.
34673498
</section>
3499+
3500+
<section algorithm>
3501+
<h3 id="get-client-state-algorithm"><dfn>Get Client State</dfn></h3>
3502+
3503+
: Input
3504+
:: |client|, a [=/service worker client=]
3505+
: Output
3506+
:: |state|, a string
3507+
3508+
1. Let |state| be {{ClientState/"active"}}.
3509+
1. If |client|'s [=environment settings object/global object=]'s [=owning document=] is [=frozen=], set |state| to be {{ClientState/"frozen"}}.
3510+
1. Return |state|.
3511+
</section>
3512+
34683513
</section>
34693514

34703515
<section>

0 commit comments

Comments
 (0)