Skip to content

Commit

Permalink
(WIP) Improve registration matching and exposing reserved/target client
Browse files Browse the repository at this point in the history
This patch fixes the client matching flow and exposes reserved client
and target client information by adding necessary hooks to fetch and
HTML.

Related issue: #870
Call flow: #870 (comment)
Expected behavior: #870 (comment)
Related changes:
 - HTML:
 - Fetch:

* Work on Handle Fetch is done. Work on the client API is in progress.
  • Loading branch information
jungkees committed Sep 13, 2016
1 parent 1c20df6 commit df39d89
Show file tree
Hide file tree
Showing 4 changed files with 633 additions and 663 deletions.
31 changes: 14 additions & 17 deletions spec/service_worker/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,6 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<h3 id="service-worker-client-concept">Service Worker Client</h3>
<p>A <dfn id="dfn-service-worker-client" for="">service worker client</dfn> is a type of <a>environment settings object</a>.</p>

<p>A <a href="#dfn-service-worker-client">service worker client</a> has an associated <dfn id="dfn-service-worker-client-active-worker">active worker</dfn> (an <a href="#dfn-active-worker">active worker</a>) which currently <a href="#dfn-control">controls</a> it. It is initially set to null.</p>

<p>A <a href="#dfn-service-worker-client">service worker client</a> has an associated <dfn id="dfn-service-worker-client-id">id</dfn> (an opaque string), which uniquely identifies itself during its lifetime. It is initially set to a new unique value when the corresponding <a>environment settings object</a> that it represents is created.</p>

<p>A <a href="#dfn-service-worker-client">service worker client</a> has an associated <dfn id="dfn-service-worker-client-frame-type">frame type</dfn>, which is one of <em>auxiliary</em>, <em>top-level</em>, <em>nested</em>, and <em>none</em>. Unless stated otherwise it is <em>none</em>.

<p>A <dfn id="dfn-window-client">window client</dfn> is a <a href="#dfn-service-worker-client">service worker client</a> whose <a for="environment settings object">global object</a> is a {{Window}} object.</p>
Expand Down Expand Up @@ -634,7 +630,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<section algorithm="navigator-service-worker-unregister">
<h4 id="navigator-service-worker-unregister">{{ServiceWorkerRegistration/unregister()}}</h4>

<p class="note">The {{ServiceWorkerRegistration/unregister()}} method unregisters the <a href="#dfn-service-worker-registration">service worker registration</a>. It is important to note that the currently <a href="#dfn-control">controlled</a> <a href="#dfn-service-worker-client">service worker client</a>'s <a href="#dfn-service-worker-client-active-worker">active worker</a>'s <a href="#dfn-containing-service-worker-registration">containing service worker registration</a> is effective until all the <a href="#dfn-service-worker-client">service worker clients</a> (including itself) using this <a href="#dfn-service-worker-registration">service worker registration</a> unload. That is, the {{ServiceWorkerRegistration/unregister()}} method only affects subsequent <a lt="navigate">navigations</a>.</p>
<p class="note">The {{ServiceWorkerRegistration/unregister()}} method unregisters the <a href="#dfn-service-worker-registration">service worker registration</a>. It is important to note that the currently <a href="#dfn-control">controlled</a> <a href="#dfn-service-worker-client">service worker client</a>'s <a>active worker</a>'s <a href="#dfn-containing-service-worker-registration">containing service worker registration</a> is effective until all the <a href="#dfn-service-worker-client">service worker clients</a> (including itself) using this <a href="#dfn-service-worker-registration">service worker registration</a> unload. That is, the {{ServiceWorkerRegistration/unregister()}} method only affects subsequent <a lt="navigate">navigations</a>.</p>

<p><dfn method id="service-worker-registration-unregister-method"><code>unregister()</code></dfn> method <em class="rfc2119" title="MUST">must</em> run these steps:</p>

Expand Down Expand Up @@ -730,7 +726,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

<ol>
<li>Let <var>client</var> be the <a>context object</a>'s <a href="#dfn-service-worker-container-interface-client">service worker client</a>.</li>
<li>Return the {{ServiceWorker}} object that represents <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active worker</a>.</li>
<li>Return the {{ServiceWorker}} object that represents <var>client</var>'s <a>active worker</a>.</li>
</ol>

<p class="note">{{ServiceWorkerContainer/controller|navigator.serviceWorker.controller}} returns <code>null</code> if the request is a force refresh (shift+refresh). The {{ServiceWorker}} objects returned from this attribute getter that represent the same <a href="#dfn-service-worker">service worker</a> are the same objects.</p>
Expand Down Expand Up @@ -988,7 +984,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<tr>
<td><dfn event id="service-worker-container-controllerchange-event"><code>controllerchange</code></dfn></td>
<td>{{Event}}</td>
<td>The <a href="#dfn-service-worker-container-interface-client">service worker client</a>'s <a href="#dfn-service-worker-client-active-worker">active worker</a> changes. (See step 9.2 of the <a href="#activation-algorithm">Activate</a> algorithm. The <a href="#dfn-skip-waiting-flag">skip waiting flag</a> of a <a href="#dfn-service-worker">service worker</a> causes <a href="#activation-algorithm">activation</a> of the <a href="#dfn-service-worker-registration">service worker registration</a> to occur while <a href="#dfn-service-worker-client">service worker clients</a> are <a href="#dfn-use">using</a> the <a href="#dfn-service-worker-registration">service worker registration</a>, {{ServiceWorkerContainer/controller|navigator.serviceWorker.controller}} immediately reflects the <a href="#dfn-active-worker">active worker</a> as the <a href="#dfn-service-worker">service worker</a> that <a href="#dfn-control">controls</a> the <a href="#dfn-service-worker-client">service worker client</a>.)</td>
<td>The <a href="#dfn-service-worker-container-interface-client">service worker client</a>'s <a>active worker</a> changes. (See step 9.2 of the <a href="#activation-algorithm">Activate</a> algorithm. The <a href="#dfn-skip-waiting-flag">skip waiting flag</a> of a <a href="#dfn-service-worker">service worker</a> causes <a href="#activation-algorithm">activation</a> of the <a href="#dfn-service-worker-registration">service worker registration</a> to occur while <a href="#dfn-service-worker-client">service worker clients</a> are <a href="#dfn-use">using</a> the <a href="#dfn-service-worker-registration">service worker registration</a>, {{ServiceWorkerContainer/controller|navigator.serviceWorker.controller}} immediately reflects the <a href="#dfn-active-worker">active worker</a> as the <a href="#dfn-service-worker">service worker</a> that <a href="#dfn-control">controls</a> the <a href="#dfn-service-worker-client">service worker client</a>.)</td>
</tr>
<tr>
<td><dfn event id="service-worker-container-message-event"><code>message</code></dfn></td>
Expand Down Expand Up @@ -1209,7 +1205,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<section>
<h4 id="client-id">{{Client/id}}</h4>

<p>The <dfn attribute for="Client" id="client-id-attribute"><code>id</code></dfn> attribute <em class="rfc2119" title="MUST">must</em> return its associated <a href="#dfn-service-worker-client-client">service worker client</a>'s <a href="#dfn-service-worker-client-id">id</a>.</p>
<p>The <dfn attribute for="Client" id="client-id-attribute"><code>id</code></dfn> attribute <em class="rfc2119" title="MUST">must</em> return its associated <a href="#dfn-service-worker-client-client">service worker client</a>'s <a>id</a>.</p>
</section>

<section algorithm="client-postmessage">
Expand Down Expand Up @@ -1289,7 +1285,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<li>Let <var>url</var> be the result of <a for="url">parsing</a> <var>url</var> with the <a>context object</a>'s <a>relevant settings object</a>'s <a>API base URL</a>.</li>
<li>If <var>url</var> is failure, return a <a>promise</a> rejected with a <code>TypeError</code>.</li>
<li>If <var>url</var> is <code><a>about:blank</a></code>, return a <a>promise</a> rejected with a <code>TypeError</code>.</li>
<li>If the <a>context object</a>'s associated <a href="#dfn-service-worker-client-client">service worker client</a>'s <a href="#dfn-service-worker-client-active-worker">active worker</a> is not the <a>context object</a>'s <a>relevant global object</a>'s <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>, return a <a>promise</a> rejected with a <code>TypeError</code>.</li>
<li>If the <a>context object</a>'s associated <a href="#dfn-service-worker-client-client">service worker client</a>'s <a>active worker</a> is not the <a>context object</a>'s <a>relevant global object</a>'s <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>, return a <a>promise</a> rejected with a <code>TypeError</code>.</li>
<li>Let <var>promise</var> be a new <a>promise</a>.</li>
<li>Run these substeps <a>in parallel</a>:
<ol>
Expand Down Expand Up @@ -1364,7 +1360,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<ol>
<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>:
<ol>
<li>If <var>client</var>'s <a href="#dfn-service-worker-client-id">id</a> is <var>id</var>, then:
<li>If <var>client</var>'s <a>id</a> is <var>id</var>, then:
<ol>
<li>If <var>client</var> is not a <a>secure context</a>, reject <var>promise</var> with a "{{SecurityError}}" exception and abort these steps.</li>
<li>If <var>client</var> is a <a href="#dfn-window-client">window client</a>, then:
Expand Down Expand Up @@ -1415,7 +1411,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<li>If <var>client</var> is not a <a>secure context</a>, continue to the next iteration of the loop.</li>
<li>If <var>options</var>.{{ClientQueryOptions/includeUncontrolled}} is false, then:
<ol>
<li>If <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active 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>
<li>If <var>client</var>'s <a>active 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>
</ol>
</li>
<li>Else:
Expand Down Expand Up @@ -3603,17 +3599,16 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<li>Else if <var>request</var> is a <a>non-subresource request</a>, then:
<p class="note">If the non-subresource request is under the scope of a service worker registration, application cache is completely bypassed regardless of whether the non-subresource request uses the service worker registration.</p>
<ol>
<li>If <var>client</var> is not a <a>secure context</a>, return null.</li>
<li>If <var>request</var> is a <a>navigation request</a> and the <a lt="navigate">navigation</a> triggering it was initiated with a shift+reload or equivalent, return null.</li>
<li>Set <var>registration</var> to the result of running <a href="#scope-match-algorithm">Match Service Worker Registration</a> algorithm passing <var>request</var>'s <a for="request">url</a> as the argument.</li>
<li>If <var>request</var>'s <a>reserved client</a> is not null and <var>request</var>'s <a>reserved client</a>'s <a>active worker</a> <var>activeWorker</var> is not null, set <var>registration</var> to <var>activeWorker</var>'s <a>containing service worker registration</a>.</li>
<li>Else, set <var>registration</var> to the result of running <a href="#scope-match-algorithm">Match Service Worker Registration</a> algorithm passing <var>request</var>'s <a for="request">url</a> as the argument.</li>
<li>If <var>registration</var> is null or <var>registration</var>'s <a href="#dfn-active-worker">active worker</a> is null, return null.</li>
<li>Set <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active worker</a> to <var>registration</var>'s <a href="#dfn-active-worker">active worker</a>.</li>
</ol>
<p class="note">From this point, the <a href="#dfn-service-worker-client">service worker client</a> starts to <a href="#dfn-use">use</a> its <a href="#dfn-service-worker-client-active-worker">active worker</a>'s <a href="#dfn-containing-service-worker-registration">containing service worker registration</a>.</p>
<p class="note">From this point, the <a href="#dfn-service-worker-client">service worker client</a> starts to <a href="#dfn-use">use</a> its <a>active worker</a>'s <a href="#dfn-containing-service-worker-registration">containing service worker registration</a>.</p>
</li>
<li>Else if <var>request</var> is a <a>subresource request</a>, then:
<ol>
<li>If <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active worker</a> is non-null, set <var>registration</var> to <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active worker</a>'s <a href="#dfn-containing-service-worker-registration">containing service worker registration</a>.</li>
<li>If <var>client</var>'s <a>active worker</a> is non-null, set <var>registration</var> to <var>client</var>'s <a>active worker</a>'s <a href="#dfn-containing-service-worker-registration">containing service worker registration</a>.</li>
<li>Else, return null.</li>
</ol>
</li>
Expand All @@ -3627,7 +3622,9 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<ol>
<li>Create a <a>trusted event</a> <var>e</var> that uses the {{FetchEvent}} interface, with the event type <code><a href="#service-worker-global-scope-fetch-event">fetch</a></code>, which does not bubble.</li>
<li>Let the <a href="#fetch-event-request-attribute">request</a> attribute of <var>e</var> be initialized to <var>r</var>.</li>
<li>Let the <a href="#fetch-event-clientid-attribute">clientId</a> attribute of <var>e</var> be initialized to <var>client</var>'s <a href="#dfn-service-worker-client-id">id</a> if <var>request</var> is not a <a>non-subresource request</a>, and to null otherwise.</li>
<li>Initialize <var>e</var>'s <a>clientId</a> attribute to <var>client</var>'s <a>id</a>.</li>
<li>If <var>request</var> is a <a>non-subresource request</a>, initialize <var>e</var>'s <a>reservedClientId</a> attribute to <var>request</var>'s <a>reserved client</a>'s <a>id</a>, and to undefined otherwise.</li>
<li>If <var>request</var> is a <a>navigation request</a>, initialize <var>e</var>'s <a>targetClientId</a> attribute to <var>request</var>'s <a>target browsing context</a>'s <a>active document</a>'s <a>relevant settings object</a>'s <a>id</a>, and to undefined otherwise.</li>
<li>Let the <a href="#fetch-event-isreload-attribute">isReload</a> attribute of <var>e</var> be initialized to <code>true</code> if <var>request</var>'s <a for="request">client</a> is a <a href="#dfn-window-client">window client</a> and the event was dispatched with the user's intention for the page reload, and <code>false</code> otherwise.</li>
<li><a>Dispatch</a> <var>e</var> at <var>activeWorker</var>'s <a>environment settings object</a>'s <a for="environment settings object">global object</a>.</li>
<li>If <var>e</var>'s <a href="#respond-with-entered-flag">respond-with entered flag</a> is set, set <var>respondWithEntered</var> to true.</li>
Expand Down
Loading

0 comments on commit df39d89

Please sign in to comment.