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

Use outside settings object to fetch workers #1149

Merged
merged 1 commit into from
May 11, 2016
Merged

Conversation

domenic
Copy link
Member

@domenic domenic commented Apr 29, 2016

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.

/cc @mkruisselbrink.


<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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't "Fetch a module script tree" still need access to both the outside settings object and the settings object for the worker itself? The modules it fetches should be stored in the module map associated with the worker, not the one associated with the parent environment.

Copy link
Member Author

@domenic domenic May 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right.

This raises an interesting question. When we fetch a module script tree for a worker, what fetch client should we use for fetching imported modules? The outside one, or the inside one? The outside one was used for fetching the original module, but the inside one seems more like the thing that actually initiated the fetch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It certainly seems like it would make sense to mirror what importScripts does, and use the worker as fetch client for purposes of CSP checks, referrers etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. OK, pushed a second commit which corrects that. Thanks for the catch.

@domenic domenic force-pushed the fix-worker-client branch from 46c2f26 to 93f577a Compare May 3, 2016 23:12
@domenic
Copy link
Member Author

domenic commented May 4, 2016

This could use editor review BTW.

@domenic domenic force-pushed the fix-worker-client branch from 890e5b2 to f280eae Compare May 10, 2016 16:59
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.)

Notably, for fetching module script trees, this necessitates separating
the fetch client settings object from the one used for the module map.

This fixes #1111 since now module workers are fetched with the correct
client, and thus automatically get the correct referrer.
<p>The following algorithms are used when <span data-x="fetch a module script tree">fetching a
module script tree</span>, and are not meant to be used directly by other specifications (or by
other parts of this specification).</p>

<p>To <dfn>fetch the descendants of a module script</dfn> <var>module script</var>, given a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not need to be modified too? If a page A fetches a module script B which has C as dependency, the referrer for B is A and C is B. I don't really see where we define that C has B as referrer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a separate bug which I hope to work on after fixing this one: #1150

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that to the commit message.

@annevk annevk merged commit 4e2b006 into master May 11, 2016
@zcorpan zcorpan deleted the fix-worker-client branch May 16, 2016 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Module workers are fetched with incorrect referrer.
3 participants