Skip to content

Commit

Permalink
Use outside settings object to fetch workers
Browse files Browse the repository at this point in the history
As discussed in #1122, #1111, and in
w3c/ServiceWorker#889 (comment),
a number of problems are caused by the current setup of using the
settings object of the worker itself as the feth client. Instead, we use
the incumbent settings object to do the fetching. (Incumbent, instead
of e.g. current, because almost everything else in the (Shared)Worker
constructors uses the incumbent settings object.)

This fixes #1111 since now module workers are fetched with the correct
client, and thus automatically get the correct referrer.
  • Loading branch information
domenic committed May 2, 2016
1 parent 6bc91fa commit 46c2f26
Showing 1 changed file with 45 additions and 81 deletions.
126 changes: 45 additions & 81 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -87041,18 +87041,16 @@ interface <dfn>NavigatorOnLine</dfn> {
<li>Asynchronously complete this algorithm with <var>script</var>.</li>
</ol>

<p>To <dfn>fetch a classic worker script</dfn> given a <var>url</var>, a <var>referrer</var>, a
<var>settings object</var>, and a <var>destination</var>, run these steps. The algorithm will
asynchronously complete with either null (on failure) or a new <span>classic script</span> (on
success).</p>
<p>To <dfn>fetch a classic worker script</dfn> given a <var>url</var>, a <var>settings
object</var>, and a <var>destination</var>, run these steps. The algorithm will asynchronously
complete with either null (on failure) or a new <span>classic script</span> (on success).</p>

<ol>
<li><p>Let <var>request</var> be a new <span data-x="concept-request">request</span> whose
<span data-x="concept-request-url">url</span> is <var>url</var>, <span
data-x="concept-request-client">client</span> is <var>settings object</var>, <span
data-x="concept-request-type">type</span> is "<code data-x="">script</code>", <span
data-x="concept-request-destination">destination</span> is <var>destination</var>, <span
data-x="concept-request-referrer">referrer</span> is <var>referrer</var>, <span
data-x="concept-request-mode">mode</span> is "<code data-x="">same-origin</code>", <span
data-x="concept-request-credentials-mode">credentials mode</span> is "<code
data-x="">same-origin</code>", <span data-x="concept-request-parser-metadata">parser
Expand Down Expand Up @@ -96486,10 +96484,9 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {

<p>When a user agent is to <dfn data-export="">run a worker</dfn> for a script with
<code>Worker</code> or <code>SharedWorker</code> object <var>worker</var>, <span>URL</span>
<var>url</var>, <span>URL</span> <var>referrer</var>, <code>MessagePort</code> <var>outside
port</var>, <span>list of relevant <code>Document</code> objects to add</span> <var>docs</var>,
possible <code>WorkerGlobalScope</code> <var>parent worker global scope</var>, and a
<code>WorkerOptions</code> dictionary <var>options</var>, it must run the following steps:</p>
<var>url</var>, <span>environment settings object</span> <var>outside settings</var>,
<code>MessagePort</code> <var>outside port</var>, and a <code>WorkerOptions</code> dictionary
<var>options</var>, it must run the following steps:</p>

<ol>

Expand All @@ -96506,6 +96503,16 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {
<li><p>Let <var>is shared</var> be true if <var>worker</var> is a <code>SharedWorker</code>
object, and false otherwise.</p></li>

<li><p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
add</span> given <var>outside settings</var>.</p></li>

<li><p>Let <var>parent worker global scope</var> be null.</p>

<li><p>If <var>outside settings</var>'s <span data-x="concept-settings-object-global">global
object</span> is a <code>WorkerGlobalScope</code> object (i.e. we are creating a nested worker),
set <var>parent worker global scope</var> to <var>outside settings</var>'s <span
data-x="concept-settings-object-global">global object</span>.</p></li>

<li>
<p>Call the JavaScript <span
data-x="js-InitializeHostDefinedRealm">InitializeHostDefinedRealm()</span> abstract
Expand Down Expand Up @@ -96534,14 +96541,14 @@ interface <dfn>WorkerGlobalScope</dfn> : <span>EventTarget</span> {

<dl class="switch">
<dt>"<code data-x="">classic</code>"</dt>
<dd><span>Fetch a classic worker script</span> given <var>url</var>, <var>referrer</var>,
<var>settings object</var>, and <var>destination</var>.</dd>
<dd><span>Fetch a classic worker script</span> given <var>url</var>, <var>outside
settings</var>, and <var>destination</var>.</dd>

<dt>"<code data-x="">module</code>"</dt>
<dd><span>Fetch a module script tree</span> given <var>url</var>, the value of the <code
data-x="">credentials</code> member of <var>options</var>, the empty string (as no
<var>cryptographic nonce</var> is present for workers), "<code data-x="">not
parser-inserted</code>", <var>destination</var>, and <var>settings object</var>.</dd>
parser-inserted</code>", <var>destination</var>, and <var>outside settings</var>.</dd>
</dl>

<p>In both cases, to <span data-x="fetching-scripts-process-response">process the
Expand Down Expand Up @@ -97029,31 +97036,23 @@ enum <dfn>WorkerType</dfn> { "classic", "module" };
data-x="blob protocol">blob:</code> URLs.</p>
</li>

<li><p>Let <var>outside settings</var> be the <span>incumbent settings object</span>.</p>

<li><p>Let <var>worker</var> be a new <code>Worker</code> object.</p></li>

<li><p><span>Create a new <code>MessagePort</code> object</span> whose <span
data-x="concept-port-owner">owner</span> is the <span>incumbent settings object</span>. Let this
be the <var>outside port</var>.</p></li>
data-x="concept-port-owner">owner</span> is <var>outside settings</var>. Let this be the
<var>outside port</var>.</p></li>

<li><p>Associate the <var>outside port</var> with <var>worker</var>.</p></li>

<li><p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
add</span> given the <span>incumbent settings object</span>.</p></li>

<li><p>Let <var>parent worker global scope</var> be null.</p></li>

<li><p>If the <span data-x="concept-settings-object-global">global object</span> specified by the
<span>incumbent settings object</span> is a <code>WorkerGlobalScope</code> object (i.e. we are
creating a nested worker), set <var>parent worker global scope</var> to the
<code>WorkerGlobalScope</code> object that is the <span
data-x="concept-settings-object-global">global object</span> specified by the <span>incumbent
settings object</span>.</p></li>
add</span> given <var>outside settings</var>.</p></li>

<li><p>Return <var>worker</var>, and run the following step <span>in parallel</span>.</p></li>

<li><p><span>Run a worker</span> given <var>worker</var>, <var>worker URL</var>, the
<span>incumbent settings object</span>'s <span>creation URL</span>, <var>outside port</var>,
<var>docs</var>, <var>parent worker global scope</var>, and <var>options</var>.</p></li>
<li><p><span>Run a worker</span> given <var>worker</var>, <var>worker URL</var>, <var>outside
settings</var>, <var>outside port</var>, and <var>options</var>.</p></li>

</ol>

Expand Down Expand Up @@ -97095,7 +97094,6 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
the following steps:</p>

<ol>

<li><p>The user agent may throw a <code>SecurityError</code> exception and abort these steps if
the request violates a policy decision (e.g. if the user agent is configured to not allow the
page to start shared workers).</p></li>
Expand All @@ -97113,12 +97111,7 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
data-x="blob protocol">blob:</code> URLs.</p>
</li>

<li>

<p>Let <var>docs</var> be the <span>list of relevant <code>Document</code> objects to
add</span> given the <span>incumbent settings object</span>.</p>

</li>
<li><p>Let <var>outside settings</var> be the <span>incumbent settings object</span>.</p></li>

<li>

Expand All @@ -97129,8 +97122,8 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
<li><p>Let <var>worker</var> be a new <code>SharedWorker</code> object.</p></li>

<li><p><span>Create a new <code>MessagePort</code> object</span> whose <span
data-x="concept-port-owner">owner</span> is the <span>incumbent settings object</span>. Let
this be the <var>outside port</var>.</p></li>
data-x="concept-port-owner">owner</span> is <var>outside settings</var>. Let this be the
<var>outside port</var>.</p></li>

<li><p>Assign <var>outside port</var> to the <code
data-x="dom-SharedWorker-port">port</code> attribute of <var>worker</var>.</p></li>
Expand All @@ -97145,27 +97138,23 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
<code>SharedWorkerGlobalScope</code> object.</p></li>

<li>

<p>If <var>worker global scope</var> is not null, but the user agent has been
configured to disallow communication between the worker represented by the <var>worker global scope</var> and the <span data-x="concept-script">scripts</span> whose
<span data-x="settings object">settings objects</span> are the <span>incumbent settings
object</span>, then set <var>worker global scope</var> to null.</p>
configured to disallow communication between the worker represented by the <var>worker global
scope</var> and the <span data-x="concept-script">scripts</span> whose <span data-x="settings
object">settings object</span> is <var>outside settings</var>, then set <var>worker global
scope</var> to null.</p>

<p class="note">For example, a user agent could have a development mode that isolates a
particular <span>top-level browsing context</span> from all other pages, and scripts in that
development mode could be blocked from connecting to shared workers running in the normal
browser mode.</p>

</li>

<li>

<p>If <var>worker global scope</var> is not null, then run these steps:</p>

<ol>

<li><p>Associate <var>worker</var> with <var>worker global
scope</var>.</p></li>
<li><p>Associate <var>worker</var> with <var>worker global scope</var>.</p></li>

<li><p>Let <var>settings object</var> be the <span>relevant settings object</span> for
<var>worker global scope</var>.</p></li>
Expand All @@ -97174,8 +97163,7 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
data-x="concept-port-owner">owner</span> is <var>settings object</var>. Let this be
the <var>inside port</var>.</p></li>

<li><p><span>Entangle</span> <var>outside port</var>
and <var>inside port</var>.</p></li>
<li><p><span>Entangle</span> <var>outside port</var> and <var>inside port</var>.</p></li>

<li><p>Create a <span data-x="concept-events-trusted">trusted</span> event that uses the
<code>MessageEvent</code> interface, with the name <code
Expand All @@ -97189,51 +97177,27 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
source</span>, to <span data-x="concept-event-dispatch">dispatch</span> the event at
<var>worker global scope</var>.</p></li>

<li>

<p><span data-x="add a document to the worker's Documents">Add to <var>worker global
scope</var>'s list of <span>the worker's <code>Document</code>s</span></span> the
<code>Document</code> objects in <var>docs</var>.</p>

</li>

<li>

<p>If the <span data-x="concept-settings-object-global">global object</span> specified by
the <span>incumbent settings object</span> is a <code>WorkerGlobalScope</code> object, add
<var>worker global scope</var> to the list of <span>the worker's workers</span> of the
<code>WorkerGlobalScope</code> object that is the <span
data-x="concept-settings-object-global">global object</span> specified by the
<span>incumbent settings object</span>.</p>
<li><p><span data-x="add a document to the worker's Documents">Add to <var>worker global
scope</var>'s list of <span>the worker's <code>Document</code>s</span></span> the
<span>list of relevant <code>Document</code> objects to add</span> given <var>outside
settings</var>.</p></li>

</li>
<li><p>If <var>outside settings</var>'s <span data-x="concept-settings-object-global">global
object</span> is a <code>WorkerGlobalScope</code> object, add <var>worker global scope</var>
to the list of <span>the worker's workers</span> of <var>outside settings</var>'s <span
data-x="concept-settings-object-global">global object</span>.</p></li>

<li><p>Return <var>worker</var> and abort all these steps.</p></li>

</ol>

</li>

<!-- OTHERWISE: -->

<li><p>Let <var>parent worker global scope</var> be null.</p></li>

<li><p>If the <span data-x="concept-settings-object-global">global object</span> specified by
the <span>incumbent settings object</span> is a <code>WorkerGlobalScope</code> object (i.e. we
are creating a nested worker), set <var>parent worker global scope</var> to the
<code>WorkerGlobalScope</code> object that is the <span
data-x="concept-settings-object-global">global object</span> specified by the <span>incumbent
settings object</span>.</p></li>
</ol>

</li>

<li><p>Return <var>worker</var> and perform the remaining steps <span>in
parallel</span>.</p></li>

<li><p><span>Run a worker</span> given <var>worker</var>, <var>urlRecord</var>, the
<span>incumbent settings object</span>'s <span>creation URL</span>, <var>outside port</var>,
<var>docs</var>, <var>parent worker global scope</var>, and <var>options</var>.</p></li>
<li><p><span>Run a worker</span> given <var>worker</var>, <var>urlRecord</var>, <var>outside
settings</var>, <var>outside port</var>, and <var>options</var>.</p></li>

</ol>

Expand Down

0 comments on commit 46c2f26

Please sign in to comment.