[EME] Update the stored license example with more information on destroying the stored session.
authorDavid Dorwin <ddorwin@google.com>
Tue, 29 Apr 2014 11:17:23 -0700
changeset 296 97f675a78a34
parent 295 de0a073d6c16
child 297 ba5233c6654d
[EME] Update the stored license example with more information on destroying the stored session.
encrypted-media/encrypted-media.html
encrypted-media/encrypted-media.xml
--- a/encrypted-media/encrypted-media.html	Mon Apr 28 17:38:59 2014 -0700
+++ b/encrypted-media/encrypted-media.html	Tue Apr 29 11:17:23 2014 -0700
@@ -98,7 +98,7 @@
     <div class="head">
       <p><a href="http://www.w3.org/"><img src="https://www.w3.org/Icons/w3c_home" alt="W3C" width="72" height="48"></a></p>
       <h1>Encrypted Media Extensions</h1>
-      <h2 id="draft-date">W3C Editor's Draft 28 April 2014</h2>
+      <h2 id="draft-date">W3C Editor's Draft 29 April 2014</h2>
       <dl>
         <dt>This Version:</dt>
         <dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html">http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html</a></dd>
@@ -1624,6 +1624,8 @@
     <h3 id="example-stored-license" class="exampleheader">8.5. Stored License</h3>
     <p class="exampledescription">This example requests a persistent license for future use and stores it. It also provides functions for later retrieving the license and for destroying it.</p>
 
+    <div class="issue">
+<div class="issue-title"><span>Issue 7</span></div>There could be a race condition between a CDM-triggered close and setting <var>releaseRequested</var>. Fix this in the spec.</div>
     <div class="example">
       <pre class="code">
 &lt;script&gt;
@@ -1647,7 +1649,13 @@
         keySession.addEventListener("<a href="#dom-eventmessage">message</a>", handleMessage, false);
         keySession.addEventListener("<a href="#dom-eventerror">error</a>", handleError, false);
         keySession.close.then(
-          console.log.bind(console, "Session closed")
+          function() {
+            console.log("Session " + this.sessionId + " closed");
+            if (this.releaseRequested) {
+              console.log("Session " + this.sessionId + " destroyed");
+              // The application should remove its record of this.sessionId.
+            }
+          }.bind(keySession),        
         );
         // Store keySession.<a href="#dom-sessionid">sessionId</a> in the application.
       }
@@ -1662,6 +1670,7 @@
       function(keySession) {
         if (!keySession) {
           console.error("No stored session with the ID " + sessionId + " was found.");
+          // The application should remove its record of |sessionId|.
           return;
         }
         keySession.addEventListener("<a href="#dom-eventmessage">message</a>", handleMessage, false);
@@ -1676,8 +1685,14 @@
   }
 
   // Called when the application wants to remove the license for the media resource.
+  // Calling release() may initiate a series of messages to/from the server.
+  // The license has not been removed until the close promise is fulfilled and
+  // releaseRequested == true.
   removeStoredSession(keySession) {
-    keySession.<a href="#dom-release">release</a>().catch(
+    keySession.<a href="#dom-release">release</a>().then(
+      function() {
+        this.releaseRequested = true;
+      }.bind(keySession),
       console.error.bind(console, "Unable to release the session")
     );
   }
--- a/encrypted-media/encrypted-media.xml	Mon Apr 28 17:38:59 2014 -0700
+++ b/encrypted-media/encrypted-media.xml	Tue Apr 29 11:17:23 2014 -0700
@@ -97,7 +97,7 @@
     <div class="head">
       <p><a href="http://www.w3.org/"><img src="https://www.w3.org/Icons/w3c_home" alt="W3C" width="72" height="48" /></a></p>
       <h1>Encrypted Media Extensions</h1>
-      <h2 id="draft-date">W3C Editor's Draft 28 April 2014</h2>
+      <h2 id="draft-date">W3C Editor's Draft 29 April 2014</h2>
       <dl>
         <dt>This Version:</dt>
         <dd><a href="http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html">http://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html</a></dd>
@@ -1555,6 +1555,7 @@
     <h3 id="example-stored-license" class="exampleheader">8.5. Stored License</h3>
     <p class="exampledescription">This example requests a persistent license for future use and stores it. It also provides functions for later retrieving the license and for destroying it.</p>
 
+    <div class="issue"><div class="issue-title"><span>Issue 7</span></div>There could be a race condition between a CDM-triggered close and setting <var>releaseRequested</var>. Fix this in the spec.</div>
     <div class="example">
       <pre class="code">
 &lt;script&gt;
@@ -1578,7 +1579,13 @@
         keySession.addEventListener("<precoderef prefix="event">message</precoderef>", handleMessage, false);
         keySession.addEventListener("<precoderef prefix="event">error</precoderef>", handleError, false);
         keySession.close.then(
-          console.log.bind(console, "Session closed")
+          function() {
+            console.log("Session " + this.sessionId + " closed");
+            if (this.releaseRequested) {
+              console.log("Session " + this.sessionId + " destroyed");
+              // The application should remove its record of this.sessionId.
+            }
+          }.bind(keySession),        
         );
         // Store keySession.<precoderef>sessionId</precoderef> in the application.
       }
@@ -1593,6 +1600,7 @@
       function(keySession) {
         if (!keySession) {
           console.error("No stored session with the ID " + sessionId + " was found.");
+          // The application should remove its record of |sessionId|.
           return;
         }
         keySession.addEventListener("<precoderef prefix="event">message</precoderef>", handleMessage, false);
@@ -1607,8 +1615,14 @@
   }
 
   // Called when the application wants to remove the license for the media resource.
+  // Calling release() may initiate a series of messages to/from the server.
+  // The license has not been removed until the close promise is fulfilled and
+  // releaseRequested == true.
   removeStoredSession(keySession) {
-    keySession.<premethodref>release</premethodref>().catch(
+    keySession.<premethodref>release</premethodref>().then(
+      function() {
+        this.releaseRequested = true;
+      }.bind(keySession),
       console.error.bind(console, "Unable to release the session")
     );
   }