Skip to content

Commit

Permalink
Replacing InstallEvent.replace with skip waiting flag - TODO: make an…
Browse files Browse the repository at this point in the history
… API to this
  • Loading branch information
jakearchibald committed Nov 6, 2014
1 parent 7823c12 commit c839e33
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 60 deletions.
12 changes: 0 additions & 12 deletions service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ var InstallEvent = (function (_super) {
_super.apply(this, arguments);
this.activeWorker = null;
}
// Ensures that the worker is used in place of existing workers for
// the currently controlled set of window instances.
// NOTE(TOSPEC): this interacts with waitUntil in the following way:
// - replacement only happens upon successful installation
// - successful installation can be delayed by waitUntil, perhaps
// by subsequent event handlers.
// - therefore, replace doesn't happen immediately.
InstallEvent.prototype.replace = function () {
};
return InstallEvent;
})(ExtendableEvent);

Expand Down Expand Up @@ -337,9 +328,6 @@ var FetchEvent = (function (_super) {
// Design notes:
// - Caches are atomic: they are not complete until all of their resources are
// fetched
// - Updates are also atomic: the old contents are visible until all new
// contents are fetched/installed.
// - Caches should have version numbers and "update" should set/replace it
// This largely describes the current Application Cache API. It's only available
// inside worker instances (not in regular documents), meaning that caching is a
// feature of the event worker. This is likely to change!
Expand Down
12 changes: 0 additions & 12 deletions service_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ class ExtendableEvent extends _Event {

class InstallEvent extends ExtendableEvent {
activeWorker: ServiceWorker = null;

// Ensures that the worker is used in place of existing workers for
// the currently controlled set of window instances.
// NOTE(TOSPEC): this interacts with waitUntil in the following way:
// - replacement only happens upon successful installation
// - successful installation can be delayed by waitUntil, perhaps
// by subsequent event handlers.
// - therefore, replace doesn't happen immediately.
replace(): void {}
}

interface InstallEventHandler { (e:InstallEvent); }
Expand Down Expand Up @@ -496,9 +487,6 @@ class FetchEvent extends _Event {
// Design notes:
// - Caches are atomic: they are not complete until all of their resources are
// fetched
// - Updates are also atomic: the old contents are visible until all new
// contents are fetched/installed.
// - Caches should have version numbers and "update" should set/replace it

// This largely describes the current Application Cache API. It's only available
// inside worker instances (not in regular documents), meaning that caching is a
Expand Down
39 changes: 3 additions & 36 deletions spec/service_worker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ <h1>Service Worker</h1>
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-script-url">script url</dfn> (a <a href="https://url.spec.whatwg.org/#concept-url">URL</a>).</p>
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-containing-service-worker-registration">containing service worker registration</dfn> (a <a href="#dfn-service-worker-registration">service worker registration</a>), which contains itself.</p>
<p>A <a href="#dfn-service-worker">service worker</a> is dispatched a set of <dfn id="#dfn-lifecycle-events">lifecycle events</dfn>, <a href="#service-worker-global-scope-install-event">install</a> and <a href="#service-worker-global-scope-activate-event">activate</a>, and <dfn id="dfn-functional-events">functional events</dfn> including <a href="#service-worker-global-scope-fetch-event">fetch</a>.</p>
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-skip-waiting-flag">skip waiting flag</dfn>. Unless stated otherwise it is unset.</p>

<spec-section id="service-worker-lifetime">
<h1>Lifetime</h1>
Expand Down Expand Up @@ -587,7 +588,7 @@ <h1>Events</h1>
<tr>
<td><dfn id="service-worker-container-controllerchange-event"><code>controllerchange</code></dfn></td>
<td><code><a href="http://dom.spec.whatwg.org/#event">Event</a></code></td>
<td>The <a href="#service-worker-container-associated-document">document</a>'s associated <a href="#dfn-client-service-worker-registration">service worker registration</a> acquires a new <a href="#dfn-active-worker">active worker</a>. (See step 1.8 of the <a href="#activation-algorithm">Activate</a> algorithm. When the <a href="#activation-algorithm">activation</a> of the <a href="#dfn-service-worker-registration">service worker registration</a> is triggered by <a href="#install-event-replace-method">replace</a>() method call within the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handlers">event handler</a> of the <a href="#service-worker-global-scope-install-event">install event</a>, <code><a href="#service-worker-container-controller-attribute">navigator.serviceWorker.controller</a></code> 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-document-control">controls</a> the document.)</td>
<td>The <a href="#service-worker-container-associated-document">document</a>'s associated <a href="#dfn-client-service-worker-registration">service worker registration</a> acquires a new <a href="#dfn-active-worker">active worker</a>. (See step 1.8 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="#service-worker-client-concept">clients</a> are <a href="#dfn-use">using</a> the <a href="#dfn-service-worker-registration">service worker registration</a>, <code><a href="#service-worker-container-controller-attribute">navigator.serviceWorker.controller</a></code> 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-document-control">controls</a> the document.)</td>
</tr>
<tr>
<td><dfn id="service-worker-container-error-event"><code>error</code></dfn></td>
Expand Down Expand Up @@ -1436,27 +1437,12 @@ <h1><code>InstallEvent</code></h1>
[Constructor(DOMString <var>type</var>, optional <a href="#install-event-init-dictionary">InstallEventInit</a> <var>eventInitDict</var>), Exposed=ServiceWorker]
interface <dfn id="install-event-interface" title="InstallEvent">InstallEvent</dfn> : <a href="#extendable-event-interface">ExtendableEvent</a> {
readonly attribute <a href="#service-worker-interface">ServiceWorker</a>? <a href="#install-event-activeworker-attribute">activeWorker</a>;
void <a href="#install-event-replace-method">replace</a>();
};

dictionary <dfn id="install-event-init-dictionary" title="InstallEventInit">InstallEventInit</dfn> : <a href="http://goo.gl/AbWMT8">EventInit</a> {
<a href="#service-worker-interface">ServiceWorker</a> activeWorker;
};
</spec-idl>

<p>Each event using <code><a href="#install-event-interface">InstallEvent</a></code> interface has the following associated flag that is initially unset:
<ul>
<li><dfn id="activate-immediate-flag">activate immediate flag</dfn></li>
</ul></p>

<spec-section id="replace-method">
<h1><code>event.replace()</code></h1>

<p><code><a href="#install-event-replace-method">event.replace()</a></code> method interacts with <code><a href="#extendable-event-waituntil-method">event.waitUntil(<var>f</var>)</a></code> method. Successful installation can be delayed by <code><a href="#extendable-event-waituntil-method">event.waitUntil(<var>f</var>)</a></code>. Replacement only happens upon successful installation. That is, replacement of the <a href="#dfn-active-worker">active worker</a> (if any) by invoking <code><a href="#install-event-replace-method">event.replace()</a></code> method is not immediate, but it may occur as soon as the event's <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handlers">event handler</a> completes its execution which is extended by <code><a href="#extendable-event-waituntil-method">event.waitUntil(<var>f</var>)</a></code>.</p>

<p><dfn id="install-event-replace-method"><code>replace()</code></dfn> method must set the <a href="#activate-immediate-flag">activate immediate flag</a>.</p>

</spec-section>
</spec-section>

<spec-section id="fetch-event-section">
Expand Down Expand Up @@ -1969,7 +1955,6 @@ <h1>Install</h1>
</dl>
<ol>
<li>Let <var>installFailed</var> be false.</li>
<li>Let <var>activateImmediate</var> be false.</li>
<li><em>CheckPriority</em>: If the value of the top element of <a href="#installation-queue-adt">[[InstallationQueue]]</a> matches <var>timeStamp</var>, then:
<ol>
<li>Pop the top element from <a href="#installation-queue-adt">[[InstallationQueue]]</a>.</li>
Expand Down Expand Up @@ -2028,11 +2013,6 @@ <h1>Install</h1>
</li>
</ol>
</li>
<li>If <var>event</var>'s <a href="#activate-immediate-flag">activate immediate flag</a> is set, then:
<ol>
<li>Set <var>activateImmediate</var> to true.</li>
</ol>
</li>
</ol>
</li>
</ol>
Expand Down Expand Up @@ -2088,21 +2068,8 @@ <h1>Install</h1>
<li>Unset <var>registration</var>'s <a href="#dfn-uninstalling-flag">uninstalling flag</a>.</li>
</ol>
</li>
<li>If <var>activateImmediate</var> is true, then:
<li>If <var>registration</var>'s <a href="#dfn-waiting-worker">waiting worker</a>'s <a href="#dfn-skip-waiting-flag">skip waiting flag</a> is set, then:
<ol>
<li>For each <a href="#dfn-service-worker-client">service worker client</a> <var>client</var> whose <a href="#dfn-client-url">client url</a> <a href="#scope-match-algorithm">matches</a> <var>registration</var>'s <a href="#dfn-scope-url">scope url</a>:
<ol>
<li>Let <var>exitingWorker</var> be the <a href="#dfn-active-worker">active worker</a> that <a href="#dfn-control">controls</a> <var>client</var>.</li>
<li>If <var>exitingWorker</var> is not null, then:
<ol>
<li>Wait for <var>exitingWorker</var> to finish handling any in-progress requests.
</li>
<li><a href="http://goo.gl/fkJaja">Terminate</a> <var>exitingWorker</var>.</li>
<li>Run the <a href="#update-state-algorithm">Update State</a> algorithm passing <var>exitingWorker</var> and <em>redundant</em> as the arguments.</li>
</ol>
</li>
</ol>
</li>
<li>Run <a href="#activation-algorithm">Activate</a> algorithm, or its <a href="#dfn-processing-equivalence">equivalent</a>, passing <var>registration</var> as the argument.</li>
<li>Abort these steps.</li>
</ol>
Expand Down

0 comments on commit c839e33

Please sign in to comment.