Skip to content

Commit 3a644c2

Browse files
committed
Fixup algorithms for prefetch matching
24b2405 was not fully correct.
1 parent 3f24fad commit 3a644c2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

prefetch.bs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ The user agent may [=prefetch record/cancel and discard=] records from the [=Doc
243243
</div>
244244

245245
<div algorithm>
246-
To <dfn export>find a matching complete prefetch record</dfn> given a [=source snapshot params=] |sourceSnapshotParams|, [=URL=] |url|, and [=sandboxing flag set=] |sandboxFlags|, perform the following steps.
246+
To <dfn export>find a matching complete prefetch record</dfn> given a [=navigable=] |navigable|, [=source snapshot params=] |sourceSnapshotParams|, [=URL=] |url|, and [=sandboxing flag set=] |sandboxFlags|, perform the following steps.
247247

248248
1. Let |exactRecord| be null.
249249
1. Let |inexactRecord| be null.
@@ -261,10 +261,10 @@ The user agent may [=prefetch record/cancel and discard=] records from the [=Doc
261261
1. Set |inexactRecord| to |record|.
262262
1. Let |recordToUse| be |exactRecord| if |exactRecord| is not null, otherwise |inexactRecord|.
263263
1. If |recordToUse| is not null:
264-
1. Let |currentTime| be the [=current high resolution time=] for the [=relevant global object=] of |document|.
264+
1. Let |currentTime| be the [=current high resolution time=] for |navigable|'s [=navigable/active document=].
265265
1. If |recordToUse|'s [=prefetch record/expiry time=] is less than |currentTime|, return null.
266266
1. [=list/For each=] |exchangeRecord| of |recordToUse|'s [=prefetch record/redirect chain=]:
267-
1. If [=conflicting credentials exist=] for |exchangeRecord|'s [=exchange record/response=] given |document|'s [=node navigable=] and |recordToUse|'s [=prefetch record/source partition key=], return null.
267+
1. If [=conflicting credentials exist=] for |exchangeRecord|'s [=exchange record/response=] given |navigable| and |recordToUse|'s [=prefetch record/source partition key=], return null.
268268

269269
<div class="note">This handles the case where there were no cross-partition credentials initially, but there are now. User agents could use a slightly coarser algorithm, such as monitoring whether the cookies for the URL have been modified at all, or storing a hash, timestamp or revision number.</div>
270270

@@ -277,24 +277,24 @@ The user agent may [=prefetch record/cancel and discard=] records from the [=Doc
277277
</div>
278278

279279
<div algorithm>
280-
To <dfn export>wait for a matching prefetch record</dfn> given a [=source snapshot params=] |sourceSnapshotParams|, [=URL=] |url|, and [=sandboxing flag set=] |sandboxFlags|, perform the following steps.
280+
To <dfn export>wait for a matching prefetch record</dfn> given a [=navigable=] |navigable|, [=source snapshot params=] |sourceSnapshotParams|, [=URL=] |url|, and [=sandboxing flag set=] |sandboxFlags|, perform the following steps.
281281

282282
1. [=Assert=]: this is running [=in parallel=].
283283
1. Let |cutoffTime| be null.
284284
1. While true:
285-
1. Let |completeRecord| be the result of [=finding a matching complete prefetch record=] given |document|, |url|, and |sandboxFlags|.
285+
1. Let |completeRecord| be the result of [=finding a matching complete prefetch record=] given |navigable|, |sourceSnapshotParams|, |url|, and |sandboxFlags|.
286286
1. If |completeRecord| is not null, return |completeRecord|.
287287
1. Let |potentialRecords| be an empty [=list=].
288288
1. [=list/For each=] |record| of |sourceSnapshotParams|'s [=source snapshot params/prefetch records=]:
289289
1. If all of the following are true, then [=list/append=] |record| to |potentialRecords|:
290290
* |record|'s [=prefetch record/state=] is "`ongoing`".
291291
* |record| [=prefetch record/is expected to match a URL=] given |url|.
292292
* |record|'s [=prefetch record/sandboxing flag set=] is not empty or |sandboxFlags| is empty.
293-
* |record|'s [=prefetch record/expiry time=] is greater than the [=current high resolution time=] for the [=relevant global object=] of |document|.
293+
* |record|'s [=prefetch record/expiry time=] is greater than the [=current high resolution time=] for |navigable|'s [=navigable/active window=].
294294
* |cutoffTime| is null or |record|'s [=prefetch record/start time=] is less than |cutoffTime|.
295295
1. If |potentialRecords| [=list/is empty=], return null.
296296
1. Wait until the [=prefetch record/state=] of any element of |sourceSnapshotParams|'s [=source snapshot params/prefetch records=] changes.
297-
1. If |cutoffTime| is null and any element of |potentialRecords| has a [=prefetch record/state=] that is not "`ongoing`", set |cutoffTime| to the [=current high resolution time=] for |sourceSnapshotParams|'s [=source snapshot params/fetch client=]'s [=environment settings object/global object=].
297+
1. If |cutoffTime| is null and any element of |potentialRecords| has a [=prefetch record/state=] that is not "`ongoing`", set |cutoffTime| to the [=current high resolution time=] for |navigable|'s [=navigable/active window=].
298298

299299
<p class="note">The reasoning for setting the cutoff time *after* waiting for a prefetch record to finish is to allow for flexibility in selecting a prefetch to serve the navigation while still guaranteeing falling back to a non-prefetched navigation in the case of repeated prefetch failures. We allow blocking on prefetch attempts which started before we see an attempt fail, but we don't block on subsequent attempts. Notably, this approach: does not finalize the set of prefetches to block on at the start of the navigation; allows a prefetch which started and completed after the navigation started to serve the navigation; avoids the use of a fixed timeout, which would be arbitrary and detrimental to the use of prefetch with slower servers; and blocks on, at most, two nearly-consecutive prefetches before falling back to a conventional navigation.</p>
300300
</div>
@@ -484,7 +484,7 @@ Modify the [=snapshot source snapshot params=] algorithm to set the return value
484484

485485
1. Let |request| be the result of [=creating a navigation request=] given <var ignore>entry</var>, <var ignore>sourceSnapshotParams</var>'s [=source snapshot params/fetch client=], <var ignore>navigable</var>'s [=navigable/container=], and <var ignore>sourceSnapshotParams</var>'s [=source snapshot params/has transient activation=].
486486
1. Set |request|'s [=request/replaces client id=] to <var ignore>navigable</var>'s [=navigable/active document=]'s [=relevant settings object=]'s [=environment/id=].
487-
1. Let |prefetchRecord| be the result of [=waiting for a matching prefetch record=] given <var ignore>sourceSnapshotParams</var>, <var ignore>entry</var>'s [=session history entry/URL=], and <var ignore>targetSnapshotParams</var>'s [=target snapshot params/sandboxing flags=].
487+
1. Let |prefetchRecord| be the result of [=waiting for a matching prefetch record=] given <var ignore>navigable</var>, <var ignore>sourceSnapshotParams</var>, <var ignore>entry</var>'s [=session history entry/URL=], and <var ignore>targetSnapshotParams</var>'s [=target snapshot params/sandboxing flags=].
488488
1. If <var ignore>documentResource</var> is null and |prefetchRecord| is not null:
489489
1. Set <var ignore>navigationParams</var> to the result of [=creating navigation params from a prefetch record=] given <var ignore>navigable</var>, <var ignore>entry</var>'s [=session history entry/document state=], <var ignore>navigationId</var>, <var ignore>navTimingType</var>, <var ignore>request</var>, |prefetchRecord|, <var ignore>targetSnapshotParams</var>, and <var ignore>sourceSnapshotParams</var>.
490490
1. [=Copy prefetch cookies=] given |prefetchRecord|'s [=prefetch record/isolated partition key=] and <var ignore>navigationParams</var>'s [=navigation params/reserved environment=].

0 commit comments

Comments
 (0)