Skip to content

Commit 3893c35

Browse files
committed
Improve clients.matchAll(options)
- Embrace the recently added environment concept in enumerating service worker clients. - Add options.includeReserved and the relevant condition to filter the matched clients. - For an environment type client, it references the environment's target browsing context's active document's UI properties to set the visibilityState and the focused state. Related commit: 8b483b0
1 parent 1f64a2d commit 3893c35

File tree

4 files changed

+142
-230
lines changed

4 files changed

+142
-230
lines changed

docs/index.bs

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
12431243
<pre class="idl" id="serviceworker-client-query-options-dictionary">
12441244
dictionary ClientQueryOptions {
12451245
boolean includeUncontrolled = false;
1246+
boolean includeReserved = false;
12461247
ClientType type = "window";
12471248
};
12481249
</pre>
@@ -1287,7 +1288,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
12871288
<li>Let <var>focusState</var> be null.</li>
12881289
<li>If <var>client</var> is a type of <a>environment</a>, set <var>browsingContext</var> to <var>client</var>’s <a for="environment">target browsing context</a>.</li>
12891290
<li>Else, set <var>browsingContext</var> to <var>client</var>'s <a for="environment settings object">global object</a>'s <a for="/">browsing context</a>.</li>
1290-
<li><a>Queue a task</a> <var>task</var> to run the following substeps:
1291+
<li><a>Queue a task</a> <var>task</var> to run the following substeps on <var>browsingContext</var>'s <a>event loop</a> using the <a>user interaction task source</a>:
12911292
<ol>
12921293
<li>Set <var>visibilityState</var> to <var>browsingContext</var>'s <a>active document</a>'s {{Document/visibilityState}} attribute value.</li>
12931294
<li>Set <var>focusState</var> to the result of running the <a>has focus steps</a> with <var>browsingContext</var>'s <a>active document</a> as the argument.</li>
@@ -1324,38 +1325,48 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
13241325
<ol>
13251326
<li>Let <var>targetClients</var> be an empty array.</li>
13261327
<li>For each <a href="#dfn-service-worker-client">service worker client</a> <var>client</var> whose <a for="resource">origin</a> is the <a lt="same origin">same</a> as the associated <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>'s <a for="resource">origin</a>:
1328+
<p class="issue">For environment type clients, the environment's creation URL's origin should be used for the origin check instead of the client's origin. See <a href="https://github.com/whatwg/html/issues/1992">the issue</a> to define the environment's origin algorithm.</p>
13271329
<ol>
1328-
<li>If <var>client</var> is not a <a>secure context</a>, continue to the next iteration of the loop.</li>
1329-
<li>If <var>options</var>.{{ClientQueryOptions/includeUncontrolled}} is false, then:
1330+
<li>If <var>client</var> is a type of <a>environment</a>, then:
13301331
<ol>
1331-
<li>If <var>client</var>'s <a>active service worker</a> is the associated <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>, add <var>client</var> to <var>targetClients</var>.</li>
1332+
<li>If <var>client</var>s <a>creation URL</a> is not a <a>potentially trustworthy URL</a>, continue to the next iteration of the loop.</li>
13321333
</ol>
13331334
</li>
13341335
<li>Else:
13351336
<ol>
1336-
<li>Add <var>client</var> to <var>targetClients</var>.</li>
1337+
<li>If <var>client</var> is not a <a>secure context</a>, continue to the next iteration of the loop.</li>
1338+
</ol>
1339+
</li>
1340+
<li>If <var>options</var>.{{ClientQueryOptions/includeUncontrolled}} is false, then:
1341+
<ol>
1342+
<li>If <var>client</var>'s <a>active service worker</a> is not the associated <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>, continue to the next iteration of the loop.</li>
13371343
</ol>
13381344
</li>
1345+
<li>If <var>options</var>.{{ClientQueryOptions/includeReserved}} is false, then:
1346+
<ol>
1347+
<li>If <var>client</var>'s <a>execution ready flag</a> is unset, continue to the next iteration of the loop.</li>
1348+
</ol>
1349+
</li>
1350+
<li>Add <var>client</var> to <var>targetClients</var>.</li>
13391351
</ol>
13401352
</li>
13411353
<li>Let <var>matchedClients</var> be an empty array.</li>
13421354
<li>For each <a href="#dfn-service-worker-client">service worker client</a> <var>client</var> in <var>targetClients</var>, in the most recently <a lt="focusing steps">focused</a> order for <a href="#dfn-window-client">window clients</a>:
13431355
<ol>
1344-
<li>If <var>options</var>.{{ClientQueryOptions/type}} is "<code>window</code>", and <var>client</var> is a <a href="#dfn-window-client">window client</a>, then:
1356+
<li>If <var>options</var>.{{ClientQueryOptions/type}} is "<code>window</code>" or "<code>all</code>", and <var>client</var> is a type of <a>environment</a> or is a <a href="#dfn-window-client">window client</a>, then:
13451357
<ol>
1346-
<li>Let <var>browsingContext</var> be <var>client</var>'s <a for="environment settings object">global object</a>'s <a for="/">browsing context</a>.</li>
1347-
<li>Let <var>isClientEnumerable</var> be false.</li>
1358+
<li>Let <var>browsingContext</var> be null.</li>
1359+
<li>Let <var>isClientEnumerable</var> be true.</li>
13481360
<li>Let <var>visibilityState</var> be the empty string.</li>
13491361
<li>Let <var>focusState</var> be false.</li>
1350-
<li><a>Queue a task</a> <var>task</var> to run the following substep on <var>client</var>'s <a>responsible event loop</a> using the <a>user interaction task source</a>:
1362+
<li>If <var>client</var> is a type of <a>environment</a>, set <var>browsingContext</var> to <var>client</var>’s <a for="environment">target browsing context</a>.</li>
1363+
<li>Else, set <var>browsingContext</var> to <var>client</var>'s <a for="environment settings object">global object</a>'s <a for="/">browsing context</a>.</li>
1364+
<li><a>Queue a task</a> <var>task</var> to run the following substeps on <var>browsingContext</var>'s <a>event loop</a> using the <a>user interaction task source</a>:
13511365
<ol>
1352-
<li>If <var>browsingContext</var> has not been <a lt="a browsing context is discarded">discarded</a> and <var>client</var>'s <a>responsible document</a> is <var>browsingContext</var>'s <a>active document</a>, then:
1353-
<ol>
1354-
<li>Set <var>visibilityState</var> to <var>browsingContext</var>'s <a>active document</a>'s {{Document/visibilityState}} attribute value.</li>
1355-
<li>Set <var>focusState</var> to the result of running the <a>has focus steps</a> with <var>browsingContext</var>'s <a>active document</a> as the argument.</li>
1356-
<li>Set <var>isClientEnumerable</var> to true.</li>
1357-
</ol>
1358-
</li>
1366+
<li>If <var>browsingContext</var> has been <a lt="a browsing context is discarded">discarded</a>, set <var>isClientEnumerable</var> to false and abort these steps.</li>
1367+
<li>If <var>client</var> is a window client and <var>client</var>'s <a>responsible document</a> is not <var>browsingContext</var>'s <a>active document</a>, set <var>isClientEnumerable</var> to false and abort these steps.</li>
1368+
<li>Set <var>visibilityState</var> to <var>browsingContext</var>'s <a>active document</a>'s {{Document/visibilityState}} attribute value.</li>
1369+
<li>Set <var>focusState</var> to the result of running the <a>has focus steps</a> with <var>browsingContext</var>'s <a>active document</a> as the argument.</li>
13591370
</ol>
13601371
</li>
13611372
<li>Wait for <var>task</var> to have executed.
@@ -1369,49 +1380,12 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
13691380
</li>
13701381
</ol>
13711382
</li>
1372-
<li>Else if <var>options</var>.{{ClientQueryOptions/type}} is "<code>worker</code>" and <var>client</var> is a <a href="#dfn-dedicatedworker-client">dedicated worker client</a>, or <var>options</var>.{{ClientQueryOptions/type}} is "<code>sharedworker</code>" and <var>client</var> is a <a href="#dfn-sharedworker-client">shared worker client</a>, then:
1383+
<li>Else if <var>options</var>.{{ClientQueryOptions/type}} is "<code>worker</code>" or "<code>all</code>" and <var>client</var> is a <a href="#dfn-dedicatedworker-client">dedicated worker client</a>, or <var>options</var>.{{ClientQueryOptions/type}} is "<code>sharedworker</code>" or "<code>all</code>" and <var>client</var> is a <a href="#dfn-sharedworker-client">shared worker client</a>, then:
13731384
<ol>
13741385
<li>Let <var>clientObject</var> be the result of running <a href="#create-client-algorithm">Create Client</a> algorithm with <var>client</var> as the argument.</li>
13751386
<li>Add <var>clientObject</var> to <var>matchedClients</var>.</li>
13761387
</ol>
13771388
</li>
1378-
<li>Else if <var>options</var>.{{ClientQueryOptions/type}} is "<code>all</code>", then:
1379-
<ol>
1380-
<li>If <var>client</var> is a <a href="#dfn-window-client">window client</a>, then:
1381-
<ol>
1382-
<li>Let <var>browsingContext</var> be <var>client</var>'s <a for="environment settings object">global object</a>'s <a for="/">browsing context</a>.</li>
1383-
<li>Let <var>isClientEnumerable</var> be false.</li>
1384-
<li>Let <var>visibilityState</var> be the empty string.</li>
1385-
<li>Let <var>focusState</var> be false.</li>
1386-
<li><a>Queue a task</a> <var>task</var> to run the following substep on <var>client</var>'s <a>responsible event loop</a> using the <a>user interaction task source</a>:
1387-
<ol>
1388-
<li>If <var>browsingContext</var> has not been <a lt="a browsing context is discarded">discarded</a> and <var>client</var>'s <a>responsible document</a> is <var>browsingContext</var>'s <a>active document</a>, then:
1389-
<ol>
1390-
<li>Set <var>visibilityState</var> to <var>browsingContext</var>'s <a>active document</a>'s {{Document/visibilityState}} attribute value.</li>
1391-
<li>Set <var>focusState</var> to the result of running the <a>has focus steps</a> with <var>browsingContext</var>'s <a>active document</a> as the argument.</li>
1392-
<li>Set <var>isClientEnumerable</var> to true.</li>
1393-
</ol>
1394-
</li>
1395-
</ol>
1396-
</li>
1397-
<li>Wait for <var>task</var> to have executed.
1398-
<p class="note">Wait is a blocking wait, but implementers may run the iterations in parallel as long as the state is not broken.</p>
1399-
</li>
1400-
<li>If <var>isClientEnumerable</var> is true, then:
1401-
<ol>
1402-
<li>Let <var>windowClient</var> be the result of running <a href="#create-windowclient-algorithm">Create Window Client</a> algorithm with <var>client</var>, <var>visibilityState</var> and <var>focusState</var> as the arguments.</li>
1403-
<li>Add <var>windowClient</var> to <var>matchedClients</var>.</li>
1404-
</ol>
1405-
</li>
1406-
</ol>
1407-
</li>
1408-
<li>Else:
1409-
<ol>
1410-
<li>Let <var>clientObject</var> be the result of running <a href="#create-client-algorithm">Create Client</a> algorithm with <var>client</var> as the argument.</li>
1411-
<li>Add <var>clientObject</var> to <var>matchedClients</var>.</li>
1412-
</ol>
1413-
</li>
1414-
</ol>
14151389
</ol>
14161390
</li>
14171391
<li>Resolve <var>promise</var> with <var>matchedClients</var>.</li>

0 commit comments

Comments
 (0)