Skip to content

Commit 526370e

Browse files
committed
Use new quota algorithm
See WICG/pending-beacon#87 (comment)
1 parent 8f5d624 commit 526370e

File tree

1 file changed

+128
-47
lines changed

1 file changed

+128
-47
lines changed

fetch.bs

+128-47
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,13 @@ a <a for=/>list</a> of <a for="/" data-lt="fetch record">fetch records</a>.
27372737
<dfn export for="fetch group" id=concept-defer=fetch-record>deferred fetch records</dfn>,
27382738
a <a for=/>list</a> of <a data-lt="deferred fetch record">deferred fetch records</a>.
27392739

2740+
<p>A <a for=fetch>fetch group</a> has an associated boolean
2741+
<dfn for="fetch group">is eligible for deferred fetching</dfn>.
2742+
2743+
To initialize a <a for=fetch>fetch group</a> for a given <a>environment settings object</a>
2744+
<var>settings</var>, set its <a for="fetch group">is eligible for deferred fetching</a> to the
2745+
result of calling <a>check deferred fetching eligibility</a> given <var>settings</var>.
2746+
27402747
<p>A <dfn export>fetch record</dfn> is a [=struct=]. It has the following items:
27412748

27422749
<dl>
@@ -6775,9 +6782,9 @@ i.e., when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
67756782
<li><p>If <var>request</var>'s <a for=request>URL</a> is not a
67766783
<a>potentially trustworthy url</a>, then throw a "{{SecurityError}}" {{DOMException}}.
67776784

6778-
<li><p>If the result of calling [$Is feature enabled in document for origin?$] given
6779-
"<code>deferred-fetch</code>", <var>document</var>, and <var>request</var>'s
6780-
<a for=request>origin</a> is <code>Disabled</code>, then throw a {{NotAllowedError}}.
6785+
<li><p>If <var>request</var>'s <a for=request>client</a>'s <a for=fetch>fetch group</a>
6786+
<a for="fetch group">is eligible for deferred fetching</a> is false, then throw a
6787+
"{{NotAllowedError}}" {{DOMException}}.
67816788

67826789
<li>
67836790
<p>If <var>request</var>'s <a for=request>body</a> is non-null then:
@@ -6792,50 +6799,11 @@ i.e., when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
67926799

67936800
<p class=note>This disallows sending deferred fetches with a live {{ReadableStream}}.
67946801

6795-
<li><p>Let <var>totalScheduledDeferredBytesForTopLevelDocument</var> be
6796-
<var>request</var>'s <a for=request>body</a>'s <a for=body>length</a>.
6797-
6798-
<li><p>Let <var>totalScheduledDeferredBytesForOrigin</var> be <var>request</var>'s
6799-
<a for=request>body</a>'s <a for=body>length</a>.
6800-
6801-
<li>
6802-
<p><a for=list>For each</a> <var>navigable</var> of <var>document</var>'s
6803-
<a>node navigable</a>'s <a for=navigable>top-level traversable</a>'s
6804-
<a for=Document>inclusive descendant navigables</a>:
6805-
6806-
<p class=note>This algorithm asserts that this deferred fetch doesn't exceed two quotas: one for
6807-
the top-level document (640 kibibytes), and one for the reporting origin (64 kibibytes). The
6808-
larger quota ensures that the top-level {{Document}} and its subresources don't continue using
6809-
an unlimited amount of bandwidth after being destroyed. The smaller quota ensures that a single
6810-
reporting sink doesn't reserve the whole quota to itself.
6811-
6812-
<ol>
6813-
<li>
6814-
<p><a for=list>For each</a> <a>deferred fetch record</a> <var>deferredRecord</var> in
6815-
<var>navigable</var>'s <a>active document</a>'s <a for=fetch>fetch group</a>'s
6816-
<a for="fetch group">deferred fetch records</a>:</p>
6817-
6818-
<ol>
6819-
<li><p>Let <var>length</var> be <var>deferredRecord</var>'s
6820-
<a for="deferred fetch record">request</a>'s <a for=request>body</a>'s
6821-
<a for=body>length</a>.
6822-
6823-
<li><p>Increment <var>totalScheduledDeferredBytesForTopLevelDocument</var> by <var>length</var>.
6824-
6825-
<li><p>If <var>totalScheduledDeferredBytesForTopLevelDocument</var> is greater than 640
6826-
kibibytes, then throw a "{{QuotaExceededError}}" {{DOMException}}.
6827-
6828-
<li><p>If <var>deferredRecord</var>'s <a for="deferred fetch record">request</a>'s
6829-
<a for=request>URL</a>'s <a for=url>origin</a> is <a>same origin</a> with
6830-
<var>request</var>'s <a for=request>origin</a>, then increment
6831-
<var>totalScheduledDeferredBytesForOrigin</var> by <var>length</var>.
6832-
6833-
<li><p>If <var>totalScheduledDeferredBytesForOrigin</var> is greater than 64 kibibytes, then
6834-
throw a "{{QuotaExceededError}}" {{DOMException}}.
6835-
</ol>
6836-
</li>
6837-
</ol>
6838-
</li>
6802+
<li><p>If the
6803+
<a>available deferred fetching quota</a> given <var>document</var> and <var>request</var>'s
6804+
<a for=request>URL</a>'s <a for=url>origin</a> is less than <var>request</var>'s
6805+
<a for=request>body</a>'s <a for=body>length</a>, then throw a "{{QuotaExceededError}}"
6806+
{{DOMException}}.
68396807
</ol>
68406808

68416809
<li><p>Set <var>request</var>'s <a for=request>service-workers mode</a> to "<code>none</code>".
@@ -6871,6 +6839,119 @@ i.e., when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
68716839
</ol>
68726840
</div>
68736841

6842+
<div algorithm>
6843+
<p>To get the <dfn>available deferred fetching quota</dfn> given a <code>Document</code>
6844+
<var>document</var> and an <a for=/>origin</a>-or-null <var>origin</var>:
6845+
6846+
<p class=note>This algorithm asserts that this deferred fetch doesn't exceed two quotas: one for the
6847+
top-level document (640 kibibytes), and one for the reporting origin (64 kibibytes). The larger
6848+
quota ensures that the top-level {{Document}} and its subresources don't continue using an unlimited
6849+
amount of bandwidth after being destroyed. The smaller quota ensures that a single reporting sink
6850+
doesn't reserve the whole quota to itself.
6851+
6852+
<ol>
6853+
<li><p>Let <var>closestSameOriginInclusiveAncestor</var> be <var>document</var>'s
6854+
<a>node navigable</a>.
6855+
6856+
<li><p>While <var>closestSameOriginInclusiveAncestor</var>'s <a for=navigable>parent</a> is a
6857+
<a for=/>navigable</a> whose <a>active document</a>'s <a for=Document>origin</a> is <a>same origin</a>
6858+
with <var>document</var>'s <a for=Document>origin</a>, set
6859+
<var>closestSameOriginInclusiveAncestor</var> to <var>closestSameOriginInclusiveAncestor</var>'s
6860+
<a for=navigable>parent</a>.
6861+
6862+
<li><p>Let <var>directRelativeSameOriginNavigables</var> be the
6863+
<a>inclusive direct same origin descendants</a> of <var>closestSameOriginInclusiveAncestor</var>.
6864+
6865+
<li><p>Let <var>remainingTotalQuota</var> be 640 kibibytes if
6866+
<var>directRelativeSameOriginNavigables</var> includes <var>document</var>'s
6867+
<a>node navigable</a>'s <a for=navigable>top-level traversable</a>, and 64 kibibytes otherwise.
6868+
6869+
<li><p>Let <var>remainingQuotaForOrigin</var> be 64 kibibytes.
6870+
6871+
<li>
6872+
<p><a for=list>For each</a> <var>navigable</var> in
6873+
<var>directRelativeSameOriginNavigables</var>:
6874+
6875+
<ol>
6876+
<li>
6877+
<p><a for=list>For each</a> <a>deferred fetch record</a> <var>deferredRecord</var> in
6878+
<var>navigable</var>'s <a>active document</a>'s <a for=fetch>fetch group</a>'s
6879+
<a for="fetch group">deferred fetch records</a>:</p>
6880+
6881+
<ol>
6882+
<li><p>Let <var>length</var> be <var>deferredRecord</var>'s
6883+
<a for="deferred fetch record">request</a>'s <a for=request>body</a>'s
6884+
<a for=body>length</a>.
6885+
6886+
<li><p>Decrement <var>remainingTotalQuota</var> by <var>length</var>.
6887+
6888+
<li><p>If <var>origin</var> is not null, and <var>deferredRecord</var>'s
6889+
<a for="deferred fetch record">request</a>'s <a for=request>URL</a>'s <a for=url>origin</a> is
6890+
<a>same origin</a> with <var>origin</var>, then decrement <var>remainingQuotaForOrigin</var> by
6891+
<var>length</var>.
6892+
</ol>
6893+
</li>
6894+
6895+
<li><p>Let <var>navigableContainers</var> be a list of all <a>shadow-including descendants</a> of
6896+
<var>navigable</var>'s <a>active document</a> that are <a>navigable containers</a>.
6897+
6898+
<li>
6899+
<p><a for=list>For each</a> <var>childNavigable</var> of <var>navigableContainers</var>:
6900+
6901+
<ol>
6902+
<li><p>If <var>childNavigable</var>'s <a>active document</a>'s <a for=Document>origin</a> is
6903+
not <a>same origin</a> with <a for=/>navigable</a>'s <a>active document</a>'s
6904+
<a for=Document>origin</a> and <var>childNavigable</var>'s <a>active document</a>'s
6905+
<a for=fetch>fetch group</a>'s <a for="fetch group">is eligible for deferred fetching</a> is true,
6906+
then decrement <var>remainingTotalQuota</var> by 64 kibibytes.
6907+
</ol>
6908+
</li>
6909+
</ol>
6910+
</li>
6911+
6912+
<li><p>If <var>remainingTotalQuota</var> is less than <var>remainingQuotaForOrigin</var>, then
6913+
return <var>remainingTotalQuota</var>.
6914+
6915+
<li><p>Return <var>remainingQuotaForOrigin</var>.
6916+
</ol>
6917+
</div>
6918+
6919+
<div algorithm>
6920+
<p>To get the <dfn>inclusive direct same origin descendants</dfn> of a <a for=/>navigable</a>
6921+
<var>root</var>:</p>
6922+
6923+
<ol>
6924+
<li><p>Let <var>descendants</var> be « <var>root</var> ».
6925+
6926+
<li><p>Let <var>navigableContainers</var> be a list of all <a>shadow-including descendants</a>
6927+
of <var>root</var>'s <a>active document</a> that are <a>navigable containers</a>.
6928+
6929+
<li><p><a for=list>For each</a> <var>childNavigable</var> of <var>navigableContainers</var>
6930+
whose <a>active document</a>'s <a for=Document>origin</a> is <a>same origin</a> with
6931+
<a for=/>navigable</a>'s <a>active document</a>'s <a for=Document>origin</a>, <a for=list>extend</a>
6932+
<var>descendants</var> with <var>childNavigable</var>'s
6933+
<a>inclusive direct same origin descendants</a>.
6934+
6935+
<li><p>Return <var>descendants</var>.
6936+
</ol>
6937+
</div>
6938+
6939+
<div algorithm>
6940+
To <dfn>check deferred fetching eligibility</dfn> given an <a>environment settings object</a>
6941+
<var>settings</var>:
6942+
6943+
<ol>
6944+
<li><p>If <var>settings</var> is not a <code>Document</code>, return false.
6945+
6946+
<li><p>If the result of calling [$Is feature enabled in document for origin?$] given
6947+
<var>settings</var> is <code>Disabled</code>, return false.
6948+
6949+
<li><p>If the <a>available deferred fetching quota</a> given <var>settings</var> and null is less
6950+
than 64 kibibytes, return false.
6951+
6952+
<li><p>Return true.
6953+
</div>
6954+
68746955
<div algorithm>
68756956
<p>To <dfn export>process deferred fetches</dfn> given a <a>fetch group</a> <var>fetchGroup</var>:
68766957

0 commit comments

Comments
 (0)