Skip to content

Conversation

@jakearchibald
Copy link
Contributor

Needs review.

docs/index.bs Outdated
text: append to header list; url: concept-header-list-append
text: basic filtered response; url: concept-filtered-response-basic
text: cancel a ReadableStream; url: concept-cancel-readablestream
text: cloning the request; url: concept-request-clone
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get the feeling this is the wrong way to do this, but I'm not sure what the right way is

Copy link
Member

Choose a reason for hiding this comment

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

It is. You want <a for=request>clone</a> and don't add this link at all. This whole list of terms seems basically wrong...

docs/index.bs Outdated
<p><a>Fetch</a> <var>preloadRequest</var>.</p>
<p>To <a>process response</a> for <var>preloadResponse</var>, run these substeps:</p>
<ol>
<li><p>If <var>preloadResponse</var>'s <a>type</a> is "<code>error</code>", reject <var>navigationPreload</var> with a <code>TypeError</code> and terminate these substeps.</li>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

type isn't linking up properly, but I'm not sure what the right way to do this is.

docs/index.bs Outdated
<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>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>
<li>If <var>request</var> is a <a>navigation request</a> and <var>registration</var>'s <a>navigation preload enabled flag</a> is set, and <var>request</var>'s <a>method</a> is `<code>GET</code>`, then:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@annevk this is the section I'm least confident in - it's fetch for the preload. I don't think redirects are a problem since the mode will be manual. When the redirect is sent back to the navigate algorithm it'll be associated with the original request, which won't have the header.

Having said that, that may be unexpected for same-origin redirects.

Copy link
Member

Choose a reason for hiding this comment

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

It's likely not a problem. Should we prefix the header so that it cannot be set through script?

docs/index.bs Outdated
<pre class="idl" id="navigation-preload-state">
dictionary NavigationPreloadState {
boolean enabled = false;
DOMString headerValue;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be ByteString? The Fetch and XHR specs are using ByteString for HTTP header values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, it should be

docs/index.bs Outdated
<ol>
<li>
<p><a>Fetch</a> <var>preloadRequest</var>.</p>
<p>To <a>process response</a> for <var>navigationPreloadResponse</var>, run these substeps:</p>
Copy link
Member

Choose a reason for hiding this comment

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

This variable seems to come out of nowhere...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using https://fetch.spec.whatwg.org/#fetch-method has a guide, and response seems to come out of nowhere there too. What's the right thing to do here, and why is fetch right to do it this way?

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, I guess this is fine. I should refactor this at some point to make it more clear...

docs/index.bs Outdated
[Constructor(DOMString type, FetchEventInit eventInitDict), Exposed=ServiceWorker]
interface FetchEvent : ExtendableEvent {
[SameObject] readonly attribute Request request;
readonly attribute Promise&lt;Response?&gt; preloadResponse;
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong if you want to resolve it with undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to show that preloadResponse is a promise that resolves with a response or undefined. What's the right IDL in this case? "any" seems less informative.

Copy link
Member

Choose a reason for hiding this comment

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

any is the only correct option here. I recommend complaining in the IDL repository. Perhaps someone can up priority of fixing that.

docs/index.bs Outdated
<pre class="idl" id="fetch-event-init-dictionary">
dictionary FetchEventInit : ExtendableEventInit {
required Request request;
required Promise&lt;Response?&gt; preloadResponse;
Copy link
Member

Choose a reason for hiding this comment

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

Why would you allow null as a value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again the intent is for this to be a promise that resolves with a response or undefined.

@jakearchibald
Copy link
Contributor Author

@jungkees I'm happy with this now. Could you review?

Copy link
Collaborator

@jungkees jungkees left a comment

Choose a reason for hiding this comment

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

@jakearchibald, great! Please see my comments.


<section algorithm>
<h4 id="navigation-preload-manager-setheadervalue"><dfn>{{NavigationPreloadManager/setHeaderValue(value)}}</dfn></h4>

Copy link
Collaborator

Choose a reason for hiding this comment

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

s/[=a new promise=]/a new [=promise=]/

Copy link
Contributor Author

@jakearchibald jakearchibald Dec 16, 2016

Choose a reason for hiding this comment

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

I thought the same, but it's "a new promise".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah.. That's right. I got it.


<section algorithm>
<h4 id="navigation-preload-manager-getstate"><dfn>{{NavigationPreloadManager/getState()}}</dfn></h4>

Copy link
Collaborator

Choose a reason for hiding this comment

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

s/[=a new promise=]/a new [=promise=]/

docs/index.bs Outdated
1. Set |registration| to the result of running <a>Match Service Worker Registration</a> algorithm passing |request|'s [=request/url=] as the argument.
1. If |registration| is null or |registration|'s <a>active worker</a> is null, return null.
1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>.
1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then:
Copy link
Collaborator

Choose a reason for hiding this comment

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

request's method is a byte sequence, so \`<code>GET</code>\` would be better.

docs/index.bs Outdated
1. If |registration| is null or |registration|'s <a>active worker</a> is null, return null.
1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>.
1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then:
1. Let |preloadRequest| be the result of [=request/cloning=] the request |request|
Copy link
Collaborator

Choose a reason for hiding this comment

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

A period is missing.

docs/index.bs Outdated
1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>.
1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then:
1. Let |preloadRequest| be the result of [=request/cloning=] the request |request|
1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=]
Copy link
Collaborator

Choose a reason for hiding this comment

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

A period is missing.

docs/index.bs Outdated
1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then:
1. Let |preloadRequest| be the result of [=request/cloning=] the request |request|
1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=]
1. Let |preloadResponseObject| be a new {{Response}} object and a new associated {{Headers}} object whose [=guard=] is "`immutable`"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be ".. new {{Response}} object associated with a new associated {{Headers}} object ..".

Please add missing periods in this algorithm.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this one hasn't been addressed yet? I missed that the value of the guard is just a string, so it seems it should be "<code>immutable</code>".

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jakearchibald, I was confused with the markdown syntax here. If "`immutable`" works fine, that'd be good as-is.

docs/index.bs Outdated
1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=]
1. Let |preloadResponseObject| be a new {{Response}} object and a new associated {{Headers}} object whose [=guard=] is "`immutable`"
1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is "`Service-Worker-Navigation-Preload`" and [=header/value=] is |registration|'s [=navigation preload header value=]
1. Set |preloadRequest|'s [=skip-service-worker flag=]
Copy link
Collaborator

Choose a reason for hiding this comment

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

It may need changes after #1025 and whatwg/fetch#435.

docs/index.bs Outdated
1. Let |preloadRequest| be the result of [=request/cloning=] the request |request|
1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=]
1. Let |preloadResponseObject| be a new {{Response}} object and a new associated {{Headers}} object whose [=guard=] is "`immutable`"
1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is "`Service-Worker-Navigation-Preload`" and [=header/value=] is |registration|'s [=navigation preload header value=]
Copy link
Collaborator

Choose a reason for hiding this comment

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

A header's name and value are also byte sequences. So, using backticks without qutotation marks would be more correct.

docs/index.bs Outdated

A [=/service worker registration=] has an associated <dfn export>navigation preload enabled flag</dfn>. It is initially unset.

A [=/service worker registration=] has an associated <dfn export>navigation preload header value</dfn>, which is a DOMString. It is initially set to "<code>true</code>".
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the type should be a byte sequence instead of a DOMString here. Also the initial value should be \`<code>true</code>\`.

[SecureContext, Exposed=(Window,Worker)]
interface NavigationPreloadManager {
Promise&lt;void&gt; enable();
Promise&lt;void&gt; disable();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The param type should be ByteString instead of DOMString.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damnit it @mattto mentioned this too - sorry for forgetting


1. Let |registration| be the [=context object=]'s associated [=/service worker registration=].
1. If |registration|'s [=active worker=] is null, [=reject=] |promise| with an "{{InvalidStateError}}" exception, and abort these steps.
1. Set |registration|'s [=navigation preload enabled flag=].
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should resolve with undefined I guess.

@jakearchibald
Copy link
Contributor Author

@jungkees excellent review, thank you. I've updated the branch.

@jungkees
Copy link
Collaborator

@jakearchibald, LGTM with the following points!

Please include the corresponding html file when you merge it. Thank you!

@jakearchibald
Copy link
Contributor Author

jakearchibald commented Dec 16, 2016

@jungkees the guard setting is correct I think. "`foo`" is markdown shorthand for "<code>foo</code>".

I'll revert the "service-workers mode" change before I merge.

@jakearchibald jakearchibald merged commit fbc0faa into master Dec 16, 2016
@jakearchibald jakearchibald deleted the navigation-preload branch December 16, 2016 14:22
@jungkees
Copy link
Collaborator

@jakearchibald, with the first bullet point in the previous comment, I tried to say the following sentence might have to be changed,
From:
"Let preloadResponseObject be a new Response object and a new associated Headers object whose guard is "immutable"."
To:
"Let preloadResponseObject be a new Response object associated with a new Headers object whose guard is "immutable"."

@jungkees jungkees changed the title (WIP) Navigation preload Navigation preload Dec 16, 2016
@jungkees
Copy link
Collaborator

jungkees commented Dec 16, 2016

@jakearchibald, sorry I found some places that need editorial changes just now. Noticed them through reviewing the html output. Addressed them with this follow-up commit: a6f6a32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants