Skip to content

Commit b5a79de

Browse files
authored
Fix #365: Do not allow operations after close() is called but before the session is actually closed (#421)
Introduce a new "closing or closed" value and use it when determining whether to abort MediaKeySession algorithms. Make media-key-session-closed depend on an explicit state. Previously, this definition depended on whether an algorithm had been run, which is slightly ambiguous.
1 parent e055347 commit b5a79de

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

encrypted-media-respec.html

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ <h2><a>MediaKeys</a> Interface</h2>
14691469
<li><p>Let the <var>session type</var> value be <var>sessionType</var>.</p></li>
14701470
<li><p>Let the <var>uninitialized</var> value be true.</p></li>
14711471
<li><p>Let the <var>callable</var> value be false.</p></li>
1472+
<li><p>Let the <var>closing or closed</var> value be false.</p></li>
14721473
<li><p>Let the <var>use distinctive identifier</var> value be this object's <var>use distinctive identifier</var> value.</p></li>
14731474
<li><p>Let the <var>cdm implementation</var> value be this object's <var>cdm implementation</var>.</p></li>
14741475
<li><p>Let the <var>cdm instance</var> value be this object's <var>cdm instance</var>.</p></li>
@@ -1578,8 +1579,7 @@ <h3>Storage and Persistence</h3>
15781579
<h2><a>MediaKeySession</a> Interface</h2>
15791580
<p>The MediaKeySession object represents a <a href="#key-session">key session</a>.</p>
15801581
<p>
1581-
A <a>MediaKeySession</a> object is <dfn id="media-key-session-closed">closed</dfn> if and only if the <a def-id="session-closed-algorithm"></a> algorithm has
1582-
been run.
1582+
A <a>MediaKeySession</a> object is <dfn id="media-key-session-closed">closed</dfn> if and only if the object's <a def-id="closed"></a> attribute has been resolved.
15831583
</p>
15841584
<p>
15851585
The User Agent SHALL execute the <a def-id="monitor-cdm-algorithm"></a> algorithm continuously for each <a>MediaKeySession</a> object
@@ -1658,7 +1658,7 @@ <h2><a>MediaKeySession</a> Interface</h2>
16581658

16591659

16601660
<ol class="method-algorithm">
1661-
<li><p>If this object is <a def-id="media-key-session-closed"></a>, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
1661+
<li><p><li><p>If this object's <var>closing or closed</var> value is true, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
16621662
<li><p>If this object's <var>uninitialized</var> value is false, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
16631663
<li><p>Let this object's <var>uninitialized</var> value be false.</p></li><!-- For simplicity and consistency, this object cannot be reused after any failure. -->
16641664
<li><p>If <var>initDataType</var> is the empty string, return a promise rejected with a newly created <a def-id="TypeError"></a>.</p></li>
@@ -1755,7 +1755,7 @@ <h2><a>MediaKeySession</a> Interface</h2>
17551755
<ol>
17561756
<li><p>If any of the preceding steps failed, reject <var>promise</var> with <a def-id="new-domexception-named"></a> <a def-id="appropriate-error-name"></a>.</p></li>
17571757
<li><p>Set the <a def-id="sessionId"></a> attribute to <var>session id</var>.</p></li>
1758-
<li><p>Let this object's <var>callable</var> value be true.</p></li>
1758+
<li><p>Set this object's <var>callable</var> value to true.</p></li>
17591759
<li><p>Run the <a def-id="queue-message-algorithm"></a> algorithm on the <var>session</var>, providing <var>message type</var> and <var>message</var>.</p>
17601760
<li>
17611761
<p>Resolve <var>promise</var>.</p>
@@ -1777,7 +1777,7 @@ <h2><a>MediaKeySession</a> Interface</h2>
17771777

17781778

17791779
<ol class="method-algorithm">
1780-
<li><p>If this object is <a def-id="media-key-session-closed"></a>, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
1780+
<li><p><li><p>If this object's <var>closing or closed</var> value is true, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
17811781
<li><p>If this object's <var>uninitialized</var> value is false, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
17821782
<li><p>Let this object's <var>uninitialized</var> value be false.</p></li><!-- For simplicity and consistency, this object cannot be reused after any failure. -->
17831783
<li><p>If <var>sessionId</var> is the empty string, return a promise rejected with a newly created <a def-id="TypeError"></a>.</p></li>
@@ -1824,7 +1824,7 @@ <h2><a>MediaKeySession</a> Interface</h2>
18241824
<ol>
18251825
<li><p>If any of the preceding steps failed, reject <var>promise</var> with a <a def-id="appropriate-error-name"></a>.</p></li>
18261826
<li><p>Set the <a def-id="sessionId"></a> attribute to <var>sanitized session ID</var>.</p></li>
1827-
<li><p>Let this object's <var>callable</var> value be true.</p></li>
1827+
<li><p>Set this object's <var>callable</var> value to true.</p></li>
18281828
<li>
18291829
<p>
18301830
If the loaded session contains information about any keys (there are <a href="#known-key">known keys</a>), run the <a def-id="update-key-statuses-algorithm"></a> algorithm on the <var>session</var>, providing each key's <a def-id="key-id"></a> along with the appropriate <a>MediaKeyStatus</a>.
@@ -1854,7 +1854,7 @@ <h2><a>MediaKeySession</a> Interface</h2>
18541854

18551855

18561856
<ol class="method-algorithm">
1857-
<li><p>If this object is <a def-id="media-key-session-closed"></a>, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
1857+
<li><p><li><p>If this object's <var>closing or closed</var> value is true, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
18581858
<li><p>If this object's <var>callable</var> value is false, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
18591859
<li><p>If <var>response</var> is an empty array, return a promise rejected with a newly created <a def-id="TypeError"></a>.</p></li>
18601860
<li><p>Let <var>response copy</var> be a copy of the contents of the <var>response</var> parameter.</p></li>
@@ -1984,9 +1984,10 @@ <h2><a>MediaKeySession</a> Interface</h2>
19841984
<p class="note">The returned promise is resolved when the request has been processed, and the <a def-id="closed"></a> attribute promise is resolved when the session is closed.</p>
19851985

19861986
<ol class="method-algorithm">
1987-
<li><p>If this object is <a def-id="media-key-session-closed"></a>, return a resolved promise.</p></li>
1987+
<li><p><li><p>If this object's <var>closing or closed</var> value is true, return a resolved promise.</p></li>
19881988
<li><p>If this object's <var>callable</var> value is false, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
19891989
<li><p>Let <var>promise</var> be a new promise.</p></li>
1990+
<li><p>Set this object's <var>closing or closed</var> value to true.</p></li>
19901991
<li><p>Run the following steps in parallel:</p>
19911992
<ol>
19921993
<li><p>Let <var>cdm</var> be the CDM instance represented by this object's <var>cdm instance</var> value.</p></li>
@@ -2015,7 +2016,7 @@ <h2><a>MediaKeySession</a> Interface</h2>
20152016
</p>
20162017

20172018
<ol class="method-algorithm">
2018-
<li><p>If this object is <a def-id="media-key-session-closed"></a>, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
2019+
<li><p><li><p>If this object's <var>closing or closed</var> value is true, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
20192020
<li><p>If this object's <var>callable</var> value is false, return a promise rejected with an <a def-id="InvalidStateError"></a>.</p></li>
20202021
<li><p>Let <var>promise</var> be a new promise.</p></li>
20212022
<li><p>Run the following steps in parallel:</p>
@@ -2354,9 +2355,13 @@ <h4>Session Closed</h4>
23542355
<p>The following steps are run:</p>
23552356
<ol>
23562357
<li><p>Let <var>session</var> be the associated <a>MediaKeySession</a> object.</p></li>
2358+
<li><p>Let <var>promise</var> be the <var>session</var>'s <a def-id="closed"></a> attribute.</p></li>
2359+
<!-- Avoid a race condition that could cause the algorithms below to be run multiple times. -->
2360+
<li><p>If <var>promise</var> is resolved, abort these steps.</p></li>
2361+
<!-- Handle the case that this algorithm is reached by a path other than close(). In all cases, the value is set before the algorithms below are run. -->
2362+
<li><p>Set the <var>session</var>'s <var>closing or closed</var> value to true.</p></li>
23572363
<li><p>Run the <a def-id="update-key-statuses-algorithm"></a> algorithm on the <var>session</var>, providing an empty sequence.</p></li>
23582364
<li><p>Run the <a def-id="update-expiration-algorithm"></a> algorithm on the <var>session</var>, providing <code>NaN</code>.</p></li>
2359-
<li><p>Let <var>promise</var> be the <a def-id="closed"></a> attribute of the <var>session</var>.</p></li>
23602365
<li><p>Resolve <var>promise</var>.</p></li>
23612366
</ol>
23622367
</section>

0 commit comments

Comments
 (0)