Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for changes to HTML's script-fetching algorithms #923

Merged
merged 1 commit into from
Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 27 additions & 51 deletions spec/service_worker/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,17 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
text: classic script
text: creation url
text: dom manipulation task source
text: fetch a classic worker script
text: fetch a module script tree
text: fire a simple event
text: https state
text: https state; for: environment settings object
text: module script
text: realm execution context
text: report the error
text: run a classic script
text: run a module script
text: script; url: concept-script
text: set up the request; url: fetching-scripts-set-up-request
text: task queue; for: event loop
text: process the response; url: fetching-scripts-process-response
urlPrefix: workers.html
text: get a fetch result
text: https state
text: import scripts into worker global scope
text: kill a worker
text: postprocess the fetch result
Expand Down Expand Up @@ -328,7 +323,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-service-worker-id">id</dfn> (an opaque string), which uniquely identifies itself during the lifetime of its <a href="#dfn-containing-service-worker-registration">containing service worker registration</a>.</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-script-resource">script resource</dfn> (a <a>script</a>), which represents its own script resource. It is initially set to null. A <a href="#dfn-script-resource">script resource</a> has an associated <dfn id="dfn-has-ever-been-evaluated-flag">has ever been evaluated flag</dfn>. It is initially unset. A <a href="#dfn-script-resource">script resource</a> has an associated <dfn id="dfn-https-state">HTTPS state</dfn> which is "<code>none</code>", "<code>deprecated</code>", or "<code>modern</code>". Unless stated otherwise, it is "<code>none</code>".</p>
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-script-resource-map">script resource map</dfn> which is a <a>List</a> of the <a>Record</a> {\[[key]], \[[value]]} where \[[key]] is a <a for="url">URL</a> and \[[value]] is a script resource.</p>
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-script-resource-map">script resource map</dfn> which is a <a>List</a> of the <a>Record</a> {\[[key]], \[[value]]} where \[[key]] is a <a for="url">URL</a> and \[[value]] is a <a for="response">response</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>
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-imported-scripts-updated-flag">imported scripts updated flag</dfn>. It is initially unset.</p>
<p>A <a href="#dfn-service-worker">service worker</a> has an associated <dfn id="dfn-set-of-event-types-to-handle">set of event types to handle</dfn> whose element type is an <a>event listener</a>'s event type. It is initially set to null.</p>
Expand Down Expand Up @@ -2781,43 +2776,29 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<section>
<h4 id="importscripts">{{WorkerGlobalScope/importScripts(urls)}}</h4>

<p>When the <dfn method for="ServiceWorkerGlobalScope" id="importscripts-method"><code>importScripts(<var>urls</var>)</code></dfn> method is called on a {{ServiceWorkerGlobalScope}} object, the user agent <em class="rfc2119" title="MUST">must</em> <a>import scripts into worker global scope</a>, with the following options:</p>

<p>To <a>validate the state</a>, the user agent <em class="rfc2119" title="MUST">must</em> do nothing.</p>

<p>To <a>get a fetch result</a>, the user agent <em class="rfc2119" title="MUST">must</em> run the following steps:</p>
<p>When the <dfn method for="ServiceWorkerGlobalScope" id="importscripts-method"><code>importScripts(<var>urls</var>)</code></dfn> method is called on a {{ServiceWorkerGlobalScope}} object, the user agent <em class="rfc2119" title="MUST">must</em> <a>import scripts into worker global scope</a>, given this {{ServiceWorkerGlobalScope}} object and <var>urls</var>, and with the following steps to <a for="fetching scripts">perform the fetch</a> given the <a for="fetch">request</a> <var>request</var>:</p>

<ol>
<li>Let <var>serviceWorker</var> be the <var>settings object</var>'s <a>global object</a>'s <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>.</li>
<li>Let <var>serviceWorker</var> be <var>request</var>'s <a for="request">client</a>'s <a>global object</a>'s <a href="#dfn-service-worker-global-scope-service-worker">service worker</a>.</li>
<li>If <var>serviceWorker</var>'s <a href="#dfn-imported-scripts-updated-flag">imported scripts updated flag</a> is unset, then:
<ol>
<li>Attempt to <a>fetch</a> each resource identified by the resulting <a>absolute URLs</a>, from the <a for="resource">origin</a> specified by <em>settings object</em>, using the <a>referrer source</a> specified by <em>settings object</em>, and with the <em>blocking flag</em> set.</li>
<li>Let <var>response</var> be the result of <a lt="fetch">fetching</a> <var>request</var>.</li>
<li>If <var>response</var>'s <a>unsafe response</a>'s <a for="response">type</a> is not "<code>error</code>", and <var>response</var>'s <a for="response">status</a> is an <a>ok status</a>, then:
<ol>
<li>If there exists a corresponding Record <var>record</var> for <var>request</var>'s <a for="request">url</a> in <var>serviceWorker</var>'s <a href="#dfn-script-resource-map">script resource map</a>, set <var>record</var>.\[[value]] to <var>response</var>.</li>
<li>Else, set a newly-created Record {\[[key]]: <var>url</var>, \[[value]]: <var>response</var>} to <var>serviceWorker</var>'s <a href="#dfn-script-resource-map">script resource map</a>.</li>
</ol>
</li>
<li>Return <var>response</var>.
</ol>
</li>
<li>Else:
<ol>
<li>If there exists a corresponding Record <var>record</var> for <var>url</var> in <var>serviceWorker</var>'s <a href="#dfn-script-resource-map">script resource map</a>, set the script resource to <var>record</var>.\[[value]].</li>
<li>Else, set the script resource to null.</li>
<li>If there exists a corresponding Record <var>record</var> for <var>url</var> in <var>serviceWorker</var>'s <a href="#dfn-script-resource-map">script resource map</a>, return <var>record</var>.\[[value]].</li>
<li>Else, return a <a>network error</a>.</li>
</ol>
</li>
</ol>

<p>To <a>postprocess the fetch result</a>, the user agent <em class="rfc2119" title="MUST">must</em> run the following steps:</p>

<ol>
<li>If <var>serviceWorker</var>'s <a href="#dfn-imported-scripts-updated-flag">imported scripts updated flag</a> is unset, then:
<ol>
<li>If the fetching attempt failed (e.g. the server returned a 4xx or 5xx status code <a lt="http equivalent codes">or equivalent</a>, or there was a DNS error), <a>throw</a> a "{{NetworkError}}" exception and abort all these steps.</li>
<li>Else:
<ol>
<li>If there exists a corresponding Record <var>record</var> for the resulting <a>absolute URL</a> <var>url</var> in <var>serviceWorker</var>'s <a href="#dfn-script-resource-map">script resource map</a>, set <var>record</var>.\[[value]] to the fetched script resource.</li>
<li>Else, set a newly-created Record {\[[key]]: <var>url</var>, \[[value]]: the fetched script resource} to <var>serviceWorker</var>'s <a href="#dfn-script-resource-map">script resource map</a>.</li>
</ol>
</li>
</ol>
</li>
<li>Else, if the script resource is null, <a>throw</a> a "{{NetworkError}}" exception and abort all these steps.</li>
</ol>
</section>
</section>

Expand Down Expand Up @@ -3195,9 +3176,9 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<dt><em>"<code>classic</code>"</em></dt>
<dd><p><a>Fetch a classic worker script</a> given <var>job</var>’s <a>serialized</a> <a href="#dfn-job-script-url">script url</a>, <var>job</var>’s <a href="#dfn-job-client">client</a>, and "<code>serviceworker</code>".</p></dd>
<dt><em>"<code>module</code>"</em></dt>
<dd><p><a>Fetch a module script tree</a> given <var>job</var>’s <a>serialized</a> <a href="#dfn-job-script-url">script url</a>, "<code>omit</code>", "<code>serviceworker</code>", and <var>job</var>’s <a href="#dfn-job-client">client</a>.</p></dd>
<dd><p><a>Fetch a module worker script tree</a> given <var>job</var>’s <a>serialized</a> <a href="#dfn-job-script-url">script url</a>, <var>job</var>’s <a href="#dfn-job-client">client</a>, "<code>serviceworker</code>", "<code>omit</code>", and the to-be-created <a>environment settings object</a> for this service worker.</p></dd> <!-- TODO: reorganize algorithm so that the worker environment is created before fetching happens -->
</dl>
<p>To <a>set up the request</a> given <var>request</var>, run the following steps:</p>
<p>To <a for="fetching scripts">perform the fetch</a> given <var>request</var>, run the following steps if the <a for="fetching scripts">is top-level</a> flag is set:</p>
<ol>
<li>Append `<code>Service-Worker</code>`/`<code>script</code>` to <var>request</var>'s <a for="request">header list</a>.
<p class="note">See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.</p>
Expand All @@ -3209,26 +3190,19 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
</ol>
<p class="note">Even if the cache mode is not set to "reload", the user agent obeys Cache-Control header's max-age value in the network layer to determine if it should bypass the browser cache.</p>
</li>
</ol>
<p>To <a>process the response</a> given <var>response</var>, run the following steps:</p>
<ol>
<li><a>Fetch</a> <var>request</var>, and asynchronously wait to run the remaining steps as part of fetch's <a>process response</a> for the <a for="fetch">response</a> <var>response</var>.</li>
<li><a>Extract a MIME type</a> from the <var>response</var>'s <a for="response">header list</a>. If this MIME type (ignoring parameters) is not one of <code>text/javascript</code>, <code>application/x-javascript</code>, and <code>application/javascript</code>, then:
<ol>
<li>Invoke <a href="#reject-job-promise-algorithm">Reject Job Promise</a> with <var>job</var> and a "{{SecurityError}}" exception.</li>
<li>If <var>newestWorker</var> is null, invoke <a href="#clear-registration-algorithm">Clear Registration</a> algorithm passing <var>registration</var> as its argument.</li>
<li>Invoke <a href="#finish-job-algorithm">Finish Job</a> with <var>job</var>.</li>
<li>Return false and abort these steps.</li>
<li>Asynchronously complete these steps with a <a>network error</a>.</li>
</ol>
</li>
<li>Let <var>serviceWorkerAllowed</var> be the result of <a for="header">parsing</a> `<code>Service-Worker-Allowed</code>` in <var>response</var>'s <a for="response">header list</a>.
<p class="note">See the definition of the Service-Worker-Allowed header in Appendix B: Extended HTTP headers.</p>
</li>
<li>If <var>serviceWorkerAllowed</var> is failure, then:
<ol>
<li>Invoke <a href="#reject-job-promise-algorithm">Reject Job Promise</a> with <var>job</var> and a <code>TypeError</code>.</li>
<li>If <var>newestWorker</var> is null, invoke <a href="#clear-registration-algorithm">Clear Registration</a> algorithm passing <var>registration</var> as its argument.</li>
<li>Invoke <a href="#finish-job-algorithm">Finish Job</a> with <var>job</var>.</li>
<li>Return false and abort these steps.</li>
<li>Asynchronously complete these steps with a <a>network error</a>.</li>
</ol>
</li>
<li>Let <var>scopeURL</var> be <var>registration</var>'s <a href="#dfn-scope-url">scope url</a>.</li>
Expand All @@ -3249,17 +3223,19 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<li>Else:
<ol>
<li>Invoke <a href="#reject-job-promise-algorithm">Reject Job Promise</a> with <var>job</var> and a "{{SecurityError}}" exception.</li>
<li>If <var>newestWorker</var> is null, invoke <a href="#clear-registration-algorithm">Clear Registration</a> algorithm passing <var>registration</var> as its argument.</li>
<li>Invoke <a href="#finish-job-algorithm">Finish Job</a> with <var>job</var>.</li>
<li>Return false and abort these steps.</li>
<li>Asynchronously complete these steps with a <a>network error</a>.</li>
</ol>
</li>
<li>If <var>response</var>'s <a for="response">cache state</a> is not "<code>local</code>", set <var>registration</var>'s <a href="#dfn-last-update-check-time">last update check time</a> to the current time.</li>
<li>Return true.</li>
</ol>
<p>If the algorithm asynchronously completes with null, then:
<ol>
<li>Invoke <a href="#reject-job-promise-algorithm">Reject Job Promise</a> with <var>job</var> and a <code>TypeError</code>.</li>
<li>
<p>Invoke <a href="#reject-job-promise-algorithm">Reject Job Promise</a> with <var>job</var> and a <code>TypeError</code>.</p>

<p class="note">This will do nothing if <a href="#reject-job-promise-algorithm">Reject Job Promise</a> was previously invoked with a "{{SecurityError}}" exception.</p>
</li>
<li>If <var>newestWorker</var> is null, invoke <a href="#clear-registration-algorithm">Clear Registration</a> algorithm passing <var>registration</var> as its argument.</li>
<li>Invoke <a href="#finish-job-algorithm">Finish Job</a> with <var>job</var> and abort these steps.</li>
</ol>
Expand Down Expand Up @@ -3495,11 +3471,11 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
<dd>Return UTF-8.</dd>
<dt>The <a>API base URL</a></dt>
<dd>Return <var>serviceWorker</var>'s <a href="#dfn-script-url">script url</a>.</dd>
<dt>The <a for="resource">origin</a> and <a>effective script origin</a></dt>
<dt>The <a for="resource">origin</a></dt>
<dd>Return its registering <a href="#dfn-service-worker-client">service worker client</a>'s <a for="resource">origin</a>.</dd>
<dt>The <a>creation URL</a></dt>
<dd>Return <var>workerGlobalScope</var>'s <a for="workerglobalscope">url</a>.</dd>
<dt>The <a>HTTPS state</a></dt>
<dt>The <a for="environment settings object">HTTPS state</a></dt>
<dd>Return <var>workerGlobalScope</var>'s <a for="workerglobalscope">HTTPS state</a>.</dd>
</dl>
</li>
Expand Down