Skip to content

Commit c748e69

Browse files
dtapuskadomenic
authored andcommitted
Add state to Service Worker clients
As discussed on w3c/ServiceWorker#1442 Unfortunately adoption of page-lifecycle is yet to be formally supported by other vendors so we need to monkey patch this in the page lifecycle spec.
1 parent 539cefb commit c748e69

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

spec.bs

+115
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ Editor: Domenic Denicola, Google https://google.com, [email protected]
1010
Repository: wicg/page-lifecycle
1111
Abstract: This document defines an API that supports browsers' ability to manage lifecycle of web pages.
1212
Default Biblio Status: current
13+
Markup Shorthands: markdown yes
1314
</pre>
1415

1516
<pre class='link-defaults'>
1617
spec:dom; type:interface; text:Document
18+
spec: infra;
19+
type: dfn;
20+
text: list;
21+
for: set; text: append
22+
for: list; text: append
1723
</pre>
1824

1925
<pre class='anchors'>
@@ -42,6 +48,9 @@ spec: ECMA262; urlPrefix: https://tc39.github.io/ecma262/;
4248
type: dfn; text: realm; url: #sec-code-realms
4349
spec: CSS-Houdini; urlPrefix: https://drafts.css-houdini.org/worklets;
4450
type: dfn; text: owning document; for: worklet; url: #workletglobalscope-owner-document
51+
spec: ServiceWorker; urlPrefix: https://w3c.github.io/ServiceWorker/
52+
type: dfn; text: create window client; url: #create-windowclient-algorithm
53+
type: dfn; text: create client; url: #create-client-algorithm
4554
</pre>
4655

4756

@@ -244,6 +253,112 @@ Run the [=update document frozenness steps=] given <var ignore>child document</v
244253

245254
Each {{HTMLMediaElement}} has a <dfn for="HTMLMediaElement">resume frozen flag</dfn>, which is initially set to false.
246255

256+
Modifications to the Service Worker Standard {#serviceworker-mod}
257+
--------------------------------------------
258+
259+
### <a href="https://w3c.github.io/ServiceWorker/#client-interface">`Client`</a> ### {#serviceworker-client-dfn}
260+
261+
<pre class="idl">
262+
partial interface Client {
263+
readonly attribute ClientLifecycleState lifecycleState;
264+
};
265+
266+
enum ClientLifecycleState {
267+
"active",
268+
"frozen"
269+
};
270+
</pre>
271+
272+
A {{Client}} object has an associated <dfn id="dfn-service-worker-client-lifecycle-state" for="Client">lifecycle state</dfn>, which is one of the {{ClientLifecycleState}} enumeration values.
273+
274+
#### {{ServiceWorkerClient/lifecycleState}} #### {#service-worker-client-lifecycle-state}
275+
276+
The <dfn attribute for="ServiceWorkerClient">lifecycleState</dfn> attribute <em>must</em> return the [=context object=]'s [=Client/lifecycle state=].
277+
278+
### <a href="https://w3c.github.io/ServiceWorker/#clients-interface">`Clients`</a> ### {#serviceworker-clients-dfn}
279+
280+
<pre class="idl">
281+
partial dictionary ClientQueryOptions {
282+
ClientLifecycleStateQuery lifecycleState = "active";
283+
};
284+
285+
enum ClientLifecycleStateQuery {
286+
"active",
287+
"frozen",
288+
"all"
289+
};
290+
</pre>
291+
292+
#### <a href="https://w3c.github.io/ServiceWorker/#clients-matchall">`matchAll(options)`</a> #### {#serviceworker-matchall-dfn}
293+
294+
Rename variable in Step #4.
295+
1. Let |matchedClientData| be a new [=list=].
296+
297+
Before Step #2.5.1 insert
298+
299+
1. Let <var ignore>lifecycleState</var> be the result of running [=Get Client Lifecycle State=] with <var ignore>client</var>.
300+
1. If <var ignore>options</var>["{{ClientQueryOptions/lifecycleState}}"] is not {{ClientLifecycleStateQuery/"all"}} and does not equal <var ignore>lifecycleState</var>, then [=continue=].
301+
302+
Append lifecycleState to list in Step #5.3.1
303+
1. Let |windowData| be «[ "client" → |client|, "ancestorOriginsList" → a new [=list=], "lifecycleState" → |lifecycleState| ]».
304+
305+
Append lifecycleState to matchedClientData in Step #5.4
306+
1. Add «[ "client" → |client|, "lifecycleState" → |lifecycleState| ]» to |matchedClientData|.
307+
308+
Pass windowData lifecycleState into Create Window Client algorithm in Step #6.2
309+
1. Let <var ignore>windowClient</var> be the result of running [=Create Window Client=] algorithm with |windowData|["`client`"], |windowData|["`frameType`"], |windowData|["`visibilityState`"], |windowData|["`focusState`"], |windowData|["`ancestorOriginsList`"], and |windowData|["`lifecycleState`"] as the arguments.
310+
311+
Adjust Step #6.3
312+
1. [=list/For each=] |clientData| in |matchedClientData|:
313+
1. Let |clientObject| be the result of running [=Create Client=] algorithm with |clientData|["`client`"], and |clientData|["`lifecycleState`"] as the arguments.
314+
1. [=Append=] |clientObject| to <var ignore>clientObjects</var>.
315+
316+
317+
#### <a href="https://w3c.github.io/ServiceWorker/#dom-clients-openwindow">`openWindow(url)`</a> #### {#serviceworker-openwindow-dfn}
318+
319+
Before Step #7.5 insert
320+
1. Let |lifecycleState| be the result of running [=Get Client Lifecycle State=] with [=context object=]'s associated [=service worker client=].
321+
322+
Adjust Step #7.8.2 to provide lifecycleState
323+
1. Let |client| be the result of running [=Create Window Client=] with <var ignore>newContext</var>'s {{Window}} object's [=environment settings object=], <var ignore>frameType</var>, <var ignore>visibilityState</var>, <var ignore>focusState</var>, <var ignore>ancestorOriginsList</var>, and |lifecycleState| as the arguments.
324+
325+
### <a href="https://w3c.github.io/ServiceWorker/#algorithms">Algorithms</a> ### {#serviceworker-algorithms-dfn}
326+
327+
<section algorithm>
328+
#### <dfn>Get Client Lifecycle State</dfn> #### {#get-client-lifecycle-state-algorithm}
329+
330+
Append the following algorithm:
331+
332+
: Input
333+
:: |client|, a [=/service worker client=]
334+
: Output
335+
:: |state|, a string
336+
337+
1. Let |state| be {{ClientLifecycleState/"active"}}.
338+
1. If |client|'s [=environment settings object/global object=]'s [=owning document=] is [=frozen=], set |state| to be {{ClientLifecycleState/"frozen"}}
339+
1. Return |state|.
340+
</section>
341+
342+
<section algorithm="create-client-monkeypatch">
343+
#### <a href="https://w3c.github.io/ServiceWorker/#create-client-algorithm">Create Client</a> #### {#serviceworker-createclient-dfn}
344+
345+
To Input append
346+
|lifecycleState|, a string
347+
348+
After Step #2 in Output append
349+
1. Set <var ignore>clientObject</var>'s [=Client/lifecycle state=] to |lifecycleState|.
350+
</section>
351+
352+
<section algorithm="create-window-client-monkeypatch">
353+
#### <a href="https://w3c.github.io/ServiceWorker/#create-windowclient-algorithm">Create Window Client</a> #### {#serviceworker-createwindowclient-dfn}
354+
355+
To Input append
356+
|lifecycleState|, a string
357+
358+
After Step #5 in Output append
359+
1. Set <var ignore>windowClient</var>'s [=Client/lifecycle state=] to |lifecycleState|.
360+
</section>
361+
247362
Page lifecycle processing model {#page-lifecycle}
248363
--------------------------------------------
249364

0 commit comments

Comments
 (0)