Skip to content

Commit

Permalink
Add Clients.get(id).
Browse files Browse the repository at this point in the history
  • Loading branch information
jungkees committed Nov 6, 2015
1 parent 09e47de commit 71d3ca5
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
50 changes: 49 additions & 1 deletion spec/service_worker/index.html
Expand Up @@ -980,7 +980,7 @@ <h1><code>Client</code></h1>

<spec-idl>[Exposed=ServiceWorker]
interface <dfn id="client-interface" title="Client">Client</dfn> {
readonly attribute <a href="http://heycam.github.io/webidl/#idl-USVString">USVString</a> url;
readonly attribute <a href="http://heycam.github.io/webidl/#idl-USVString">USVString</a> <a href="#client-url-attribute">url</a>;
readonly attribute <a href="#contextframetype-enum">FrameType</a> <a href="#client-frametype-attribute">frameType</a>;
readonly attribute DOMString <a href="#client-id-attribute">id</a>;
void <a href="#client-postmessage-method">postMessage</a>(any <var>message</var>, optional sequence&lt;<a href="https://html.spec.whatwg.org/multipage/infrastructure.html#transferable">Transferable</a>&gt; <var>transfer</var>);
Expand Down Expand Up @@ -1171,6 +1171,7 @@ <h1><code>Clients</code></h1>
<spec-idl>[Exposed=ServiceWorker]
interface <dfn id="clients-interface" title="Clients">Clients</dfn> {
// The objects returned will be new instances every time
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;any&gt; <a href="#clients-get-method">get</a>(DOMString <var>id</var>);
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;sequence&lt;<a href="#client-interface">Client</a>&gt;&gt; <a href="#clients-matchall-method">matchAll</a>(optional <a href="#serviceworker-client-query-options-dictionary">ClientQueryOptions</a> <var>options</var>);
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;<a href="#window-client-interface">WindowClient</a>?&gt; <a href="#clients-openwindow-method">openWindow</a>(<a href="http://heycam.github.io/webidl/#idl-USVString">USVString</a> <var>url</var>);
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;void&gt; <a href="#clients-claim-method">claim</a>();
Expand All @@ -1190,6 +1191,53 @@ <h1><code>Clients</code></h1>
</spec-idl>
<p>The user agent <em class="rfc2119" title="MUST">must</em> create a <code><a href="#clients-interface">Clients</a></code> object when a <code><a href="#service-worker-global-scope-interface">ServiceWorkerGlobalScope</a></code> object is created and associate it with that object.</p>

<spec-section id="clients-get">
<h1><code>get(<var>id</var>)</code></h1>
<p>The <dfn id="clients-get-method"><code>get(<var>id</var>)</code></dfn> method <em class="rfc2119" title="MUST">must</em> run these steps or their <a href="#dfn-processing-equivalence">equivalent</a>:</p>
<spec-algorithm>
<ol>
<li>Let <var>promise</var> be a new <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">promise</a>.</li>
<li>Run these substeps <a href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>:
<ol>
<li>For each <a href="#dfn-service-worker-client">service worker client</a> <var>client</var> whose <a href="https://html.spec.whatwg.org/multipage/browsers.html#origin-2">origin</a> is the <a href="https://html.spec.whatwg.org/multipage/browsers.html#same-origin">same</a> as the associated <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#origin-2">origin</a>:
<ol>
<li>If <var>client</var>'s <a href="#dfn-service-worker-client-id">id</a> is <var>id</var>, then:
<ol>
<li>If <var>client</var> is not a <a href="https://w3c.github.io/webappsec-secure-contexts/#secure-context">secure context</a>, reject <var>promise</var> with a "<code><a href="http://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" exception and abort these steps.</li>
<li>If <var>client</var> is a <a href="#dfn-window-client">window client</a>, then:
<ol>
<li>Let <var>browsingContext</var> be <var>client</var>'s <a href="https://html.spec.whatwg.org/multipage/webappapis.html#global-object">global object</a>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context">browsing context</a>.</li>
<li>Let <var>visibilityState</var> be null.</li>
<li>Let <var>focusState</var> be null.</li>
<li><a href="https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task">Queue a task</a> <var>task</var> to run the following substeps:
<ol>
<li>Set <var>visibilityState</var> to <var>browsingContext</var>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#active-document">active document</a>'s <a href="http://www.w3.org/TR/page-visibility/#dom-document-visibilitystate">visibilityState</a> attribute value.</li>
<li>Set <var>focusState</var> to the result of running the <a href="https://html.spec.whatwg.org/multipage/interaction.html#has-focus-steps">has focus steps</a> with <var>browsingContext</var>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#active-document">active document</a> as the argument.</li>
</ol>
</li>
<li>Wait for <var>task</var> to have executed.</li>
<li>Let <var>windowClient</var> be the result of running <a href="#create-windowclient-algorithm">Create Window Client</a> algorithm, or its <a href="#dfn-processing-equivalence">equivalent</a>, with <var>client</var>, <var>visibilityState</var> and <var>focusState</var> as the arguments.</li>
<li>Resolve <var>promise</var> with <var>windowClient</var> and abort these steps.</li>
</ol>
</li>
<li>Else:
<ol>
<li>Let <var>clientObject</var> be the result of running <a href="#create-client-algorithm">Create Client</a> algorithm, or its <a href="#dfn-processing-equivalence">equivalent</a>, with <var>client</var> as the argument.</li>
<li>Resolve <var>promise</var> with <var>clientObject</var> and abort these steps.</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
<li>Resolve <var>promise</var> with undefined.</li>
</ol>
</li>
<li>Return <var>promise</var>.</li>
</ol>
</spec-algorithm>
</spec-section>

<spec-section id="clients-getall">
<h1><code>matchAll(<var>options</var>)</code></h1>
<p>The <dfn id="clients-matchall-method"><code>matchAll(<var>options</var>)</code></dfn> method <em class="rfc2119" title="MUST">must</em> run these steps or their <a href="#dfn-processing-equivalence">equivalent</a>:</p>
Expand Down
50 changes: 49 additions & 1 deletion spec/service_worker_1/index.html
Expand Up @@ -978,7 +978,7 @@ <h1><code>Client</code></h1>

<spec-idl>[Exposed=ServiceWorker]
interface <dfn id="client-interface" title="Client">Client</dfn> {
readonly attribute <a href="http://heycam.github.io/webidl/#idl-USVString">USVString</a> url;
readonly attribute <a href="http://heycam.github.io/webidl/#idl-USVString">USVString</a> <a href="#client-url-attribute">url</a>;
readonly attribute <a href="#contextframetype-enum">FrameType</a> <a href="#client-frametype-attribute">frameType</a>;
readonly attribute DOMString <a href="#client-id-attribute">id</a>;
void <a href="#client-postmessage-method">postMessage</a>(any <var>message</var>, optional sequence&lt;<a href="https://html.spec.whatwg.org/multipage/infrastructure.html#transferable">Transferable</a>&gt; <var>transfer</var>);
Expand Down Expand Up @@ -1169,6 +1169,7 @@ <h1><code>Clients</code></h1>
<spec-idl>[Exposed=ServiceWorker]
interface <dfn id="clients-interface" title="Clients">Clients</dfn> {
// The objects returned will be new instances every time
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;any&gt; <a href="#clients-get-method">get</a>(DOMString <var>id</var>);
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;sequence&lt;<a href="#client-interface">Client</a>&gt;&gt; <a href="#clients-matchall-method">matchAll</a>(optional <a href="#serviceworker-client-query-options-dictionary">ClientQueryOptions</a> <var>options</var>);
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;<a href="#window-client-interface">WindowClient</a>?&gt; <a href="#clients-openwindow-method">openWindow</a>(<a href="http://heycam.github.io/webidl/#idl-USVString">USVString</a> <var>url</var>);
[NewObject] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">Promise</a>&lt;void&gt; <a href="#clients-claim-method">claim</a>();
Expand All @@ -1188,6 +1189,53 @@ <h1><code>Clients</code></h1>
</spec-idl>
<p>The user agent <em class="rfc2119" title="MUST">must</em> create a <code><a href="#clients-interface">Clients</a></code> object when a <code><a href="#service-worker-global-scope-interface">ServiceWorkerGlobalScope</a></code> object is created and associate it with that object.</p>

<spec-section id="clients-get">
<h1><code>get(<var>id</var>)</code></h1>
<p>The <dfn id="clients-get-method"><code>get(<var>id</var>)</code></dfn> method <em class="rfc2119" title="MUST">must</em> run these steps or their <a href="#dfn-processing-equivalence">equivalent</a>:</p>
<spec-algorithm>
<ol>
<li>Let <var>promise</var> be a new <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">promise</a>.</li>
<li>Run these substeps <a href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>:
<ol>
<li>For each <a href="#dfn-service-worker-client">service worker client</a> <var>client</var> whose <a href="https://html.spec.whatwg.org/multipage/browsers.html#origin-2">origin</a> is the <a href="https://html.spec.whatwg.org/multipage/browsers.html#same-origin">same</a> as the associated <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#origin-2">origin</a>:
<ol>
<li>If <var>client</var>'s <a href="#dfn-service-worker-client-id">id</a> is <var>id</var>, then:
<ol>
<li>If <var>client</var> is not a <a href="https://w3c.github.io/webappsec-secure-contexts/#secure-context">secure context</a>, reject <var>promise</var> with a "<code><a href="http://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" exception and abort these steps.</li>
<li>If <var>client</var> is a <a href="#dfn-window-client">window client</a>, then:
<ol>
<li>Let <var>browsingContext</var> be <var>client</var>'s <a href="https://html.spec.whatwg.org/multipage/webappapis.html#global-object">global object</a>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context">browsing context</a>.</li>
<li>Let <var>visibilityState</var> be null.</li>
<li>Let <var>focusState</var> be null.</li>
<li><a href="https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task">Queue a task</a> <var>task</var> to run the following substeps:
<ol>
<li>Set <var>visibilityState</var> to <var>browsingContext</var>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#active-document">active document</a>'s <a href="http://www.w3.org/TR/page-visibility/#dom-document-visibilitystate">visibilityState</a> attribute value.</li>
<li>Set <var>focusState</var> to the result of running the <a href="https://html.spec.whatwg.org/multipage/interaction.html#has-focus-steps">has focus steps</a> with <var>browsingContext</var>'s <a href="https://html.spec.whatwg.org/multipage/browsers.html#active-document">active document</a> as the argument.</li>
</ol>
</li>
<li>Wait for <var>task</var> to have executed.</li>
<li>Let <var>windowClient</var> be the result of running <a href="#create-windowclient-algorithm">Create Window Client</a> algorithm, or its <a href="#dfn-processing-equivalence">equivalent</a>, with <var>client</var>, <var>visibilityState</var> and <var>focusState</var> as the arguments.</li>
<li>Resolve <var>promise</var> with <var>windowClient</var> and abort these steps.</li>
</ol>
</li>
<li>Else:
<ol>
<li>Let <var>clientObject</var> be the result of running <a href="#create-client-algorithm">Create Client</a> algorithm, or its <a href="#dfn-processing-equivalence">equivalent</a>, with <var>client</var> as the argument.</li>
<li>Resolve <var>promise</var> with <var>clientObject</var> and abort these steps.</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
<li>Resolve <var>promise</var> with undefined.</li>
</ol>
</li>
<li>Return <var>promise</var>.</li>
</ol>
</spec-algorithm>
</spec-section>

<spec-section id="clients-getall">
<h1><code>matchAll(<var>options</var>)</code></h1>
<p>The <dfn id="clients-matchall-method"><code>matchAll(<var>options</var>)</code></dfn> method <em class="rfc2119" title="MUST">must</em> run these steps or their <a href="#dfn-processing-equivalence">equivalent</a>:</p>
Expand Down

0 comments on commit 71d3ca5

Please sign in to comment.