<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211857] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211857">211857</a></dd>
<dt>Author</dt> <dd>zandobersek@gmail.com</dd>
<dt>Date</dt> <dd>2017-02-08 02:39:49 -0800 (Wed, 08 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[EME] Implement MediaKeySession::remove()
https://bugs.webkit.org/show_bug.cgi?id=167870

Reviewed by Xabier Rodriguez-Calvar.

Source/WebCore:

Implement MediaKeySession::remove() as outlined in the specification.

The CDMInstance::removeSessionData() virtual method is added. CDMInstance
implementors should remove any session data stored for the session that's
represented by the passed-in session ID and session type.

Once the session data is removed, the passed-in callback should be invoked
by the CDMInstance object so that MediaKeySession can immediately queue a
task in which it updates key statuses and expiration, reject the promise if
the data removal failed, or enqueue any license-release message and finally
successfully resolve the promise.

MockCDMFactory gains the removeKeysFromSessionWithID() method that purges
the keys for a given session ID. The method is called from
MockCDMInstance::removeSessionData() implementation, which passes the
removed keys to the RemoveSessionDataCallback, along with a license-release
message that is checked in the tests. The key removal itself isn't tested
yet because the MediaKeySession's `update key statuses` algorithm isn't
implemented yet.

Test: media/encrypted-media/mock-MediaKeySession-remove.html

* Modules/encryptedmedia/CDMInstance.h:
* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::remove):
* testing/MockCDMFactory.cpp:
(WebCore::MockCDMFactory::removeKeysFromSessionWithID):
(WebCore::MockCDMInstance::removeSessionData):
* testing/MockCDMFactory.h:

LayoutTests:

Add the mock-MediaKeySession-remove.html test that tests the functionality
of the MediaKeySession::remove() implementation. The test checks that the
calls to that method properly resolve or reject the returned promise,
depending on the object state. Another test checks the message that's
queued upon a successful removal.

Additional tests will be added later once MediaKeySession properly
implements the close() method and key status updates.

* media/encrypted-media/mock-MediaKeySession-remove-expected.txt: Added.
* media/encrypted-media/mock-MediaKeySession-remove.html: Added.
* platform/efl/TestExpectations:
* platform/mac/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformeflTestExpectations">trunk/LayoutTests/platform/efl/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsplatformmacTestExpectations">trunk/LayoutTests/platform/mac/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaCDMInstanceh">trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaMediaKeySessioncpp">trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingMockCDMFactorycpp">trunk/Source/WebCore/testing/MockCDMFactory.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingMockCDMFactoryh">trunk/Source/WebCore/testing/MockCDMFactory.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsmediaencryptedmediamockMediaKeySessionremoveexpectedtxt">trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediaencryptedmediamockMediaKeySessionremovehtml">trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/LayoutTests/ChangeLog        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -1,5 +1,26 @@
</span><span class="cx"> 2017-02-08  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [EME] Implement MediaKeySession::remove()
+        https://bugs.webkit.org/show_bug.cgi?id=167870
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Add the mock-MediaKeySession-remove.html test that tests the functionality
+        of the MediaKeySession::remove() implementation. The test checks that the
+        calls to that method properly resolve or reject the returned promise,
+        depending on the object state. Another test checks the message that's
+        queued upon a successful removal.
+
+        Additional tests will be added later once MediaKeySession properly
+        implements the close() method and key status updates.
+
+        * media/encrypted-media/mock-MediaKeySession-remove-expected.txt: Added.
+        * media/encrypted-media/mock-MediaKeySession-remove.html: Added.
+        * platform/efl/TestExpectations:
+        * platform/mac/TestExpectations:
+
+2017-02-08  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
+
</ins><span class="cx">         [EME] Implement MediaKeySession::close()
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=167869
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsmediaencryptedmediamockMediaKeySessionremoveexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove-expected.txt (0 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove-expected.txt                                (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove-expected.txt        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+RUN(internals.initializeMockMediaSource())
+RUN(mock = internals.registerMockCDM())
+RUN(mock.supportedDataTypes = [&quot;keyids&quot;])
+RUN(capabilities.initDataTypes = [&quot;keyids&quot;])
+RUN(capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs=&quot;mock&quot;' }] )
+RUN(promise = navigator.requestMediaKeySystemAccess(&quot;org.webkit.mock&quot;, [capabilities]))
+Promise resolved OK
+
+RUN(promise = mediaKeySystemAccess.createMediaKeys())
+Promise resolved OK
+
+Removing from a non-callable MediaKeySession should reject.
+RUN(mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;))
+EXPECTED (typeof mediaKeySession == 'object') OK
+RUN(promise = mediaKeySession.remove())
+Promise rejected correctly OK
+
+Removing from a failed MediaKeySession should reject.
+RUN(kids = JSON.stringify({ invalid: &quot;invalid&quot; }))
+RUN(mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;))
+RUN(promise = mediaKeySession.generateRequest(&quot;keyids&quot;, encoder.encode(kids)))
+Promise rejected correctly OK
+RUN(promise = mediaKeySession.remove())
+Promise rejected correctly OK
+
+Removing from a valid MediaKeySession should resolve.
+RUN(kids = JSON.stringify({ kids: [ &quot;MTIzNDU=&quot; ] }))
+RUN(mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;))
+RUN(promise = mediaKeySession.generateRequest(&quot;keyids&quot;, encoder.encode(kids)))
+Promise resolved OK
+RUN(promise = mediaKeySession.remove())
+Promise resolved OK
+
+Removing from a valid MediaKeySession should dispatch a license-release message.
+RUN(kids = JSON.stringify({ kids: [ &quot;MTIzNDU=&quot; ] }))
+RUN(mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;))
+RUN(promise = mediaKeySession.generateRequest(&quot;keyids&quot;, encoder.encode(kids)))
+Promise resolved OK
+RUN(promise = mediaKeySession.remove())
+EXPECTED (event.messageType == 'license-release') OK
+EXPECTED (new Uint8Array(event.message).length == '14') OK
+EXPECTED (new Uint8Array(event.message)[0] == '114') OK
+EXPECTED (new Uint8Array(event.message)[1] == '101') OK
+EXPECTED (new Uint8Array(event.message)[2] == '109') OK
+EXPECTED (new Uint8Array(event.message)[3] == '111') OK
+EXPECTED (new Uint8Array(event.message)[4] == '118') OK
+EXPECTED (new Uint8Array(event.message)[5] == '101') OK
+EXPECTED (new Uint8Array(event.message)[6] == '45') OK
+EXPECTED (new Uint8Array(event.message)[7] == '109') OK
+EXPECTED (new Uint8Array(event.message)[8] == '101') OK
+EXPECTED (new Uint8Array(event.message)[9] == '115') OK
+EXPECTED (new Uint8Array(event.message)[10] == '115') OK
+EXPECTED (new Uint8Array(event.message)[11] == '97') OK
+EXPECTED (new Uint8Array(event.message)[12] == '103') OK
+EXPECTED (new Uint8Array(event.message)[13] == '101') OK
+Promise resolved OK
+END OF TEST
+
</ins></span></pre></div>
<a id="trunkLayoutTestsmediaencryptedmediamockMediaKeySessionremovehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove.html (0 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove.html                                (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove.html        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -0,0 +1,109 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;script src=../video-test.js&gt;&lt;/script&gt;
+    &lt;script type=&quot;text/javascript&quot;&gt;
+    var mock;
+    var promise;
+    var mediaKeySystemAccess;
+    var mediaKeys;
+    var mediaKeySession;
+    var capabilities = {};
+    var kids;
+    var encoder = new TextEncoder();
+
+    function doTest()
+    {
+        if (!window.internals) {
+            failTest(&quot;Internals is required for this test.&quot;)
+            return;
+        }
+
+        run('internals.initializeMockMediaSource()');
+        run('mock = internals.registerMockCDM()');
+        run('mock.supportedDataTypes = [&quot;keyids&quot;]');
+        run('capabilities.initDataTypes = [&quot;keyids&quot;]');
+        run(`capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs=&quot;mock&quot;' }] `);
+        run('promise = navigator.requestMediaKeySystemAccess(&quot;org.webkit.mock&quot;, [capabilities])');
+        shouldResolve(promise).then(gotMediaKeySystemAccess, failTest);
+    }
+
+    function next() {
+        if (!tests.length) {
+            mock.unregister();
+            endTest()
+            return;
+        }
+
+        var nextTest = tests.shift();
+        consoleWrite('');
+        nextTest();
+    }
+
+    function gotMediaKeySystemAccess(result) {
+        mediaKeySystemAccess = result;
+        next();
+    }
+
+    function gotMediaKeys(result) {
+        mediaKeys = result;
+        next();
+    }
+
+    tests = [
+        function() {
+            run('promise = mediaKeySystemAccess.createMediaKeys()');
+            shouldResolve(promise).then(gotMediaKeys, failTest);
+        },
+
+        function() {
+            consoleWrite('Removing from a non-callable MediaKeySession should reject.');
+            run('mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;)');
+            testExpected('typeof mediaKeySession', 'object');
+            run('promise = mediaKeySession.remove()');
+            shouldReject(promise).then(next, next);
+        },
+
+        function() {
+            consoleWrite('Removing from a failed MediaKeySession should reject.');
+            run('kids = JSON.stringify({ invalid: &quot;invalid&quot; })');
+            run('mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;)');
+            run('promise = mediaKeySession.generateRequest(&quot;keyids&quot;, encoder.encode(kids))');
+            shouldReject(promise).then(function() {
+                run('promise = mediaKeySession.remove()');
+                shouldReject(promise).then(next, next);
+            }, next);
+        },
+
+        function() {
+            consoleWrite('Removing from a valid MediaKeySession should resolve.');
+            run('kids = JSON.stringify({ kids: [ &quot;MTIzNDU=&quot; ] })');
+            run('mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;)');
+            run('promise = mediaKeySession.generateRequest(&quot;keyids&quot;, encoder.encode(kids))');
+            shouldResolve(promise).then(function() {
+                run('promise = mediaKeySession.remove()');
+                shouldResolve(promise).then(next, next);
+            }, next);
+        },
+
+        function() {
+            consoleWrite('Removing from a valid MediaKeySession should dispatch a license-release message.');
+            run('kids = JSON.stringify({ kids: [ &quot;MTIzNDU=&quot; ] })');
+            run('mediaKeySession = mediaKeys.createSession(&quot;temporary&quot;)');
+            run('promise = mediaKeySession.generateRequest(&quot;keyids&quot;, encoder.encode(kids))');
+            shouldResolve(promise).then(function() {
+                run('promise = mediaKeySession.remove()');
+                mediaKeySession.addEventListener('message', function(event) {
+                    testExpected('event.messageType', 'license-release');
+                    testArraysEqual('new Uint8Array(event.message)', encoder.encode(&quot;remove-message&quot;));
+
+                    shouldResolve(promise).then(next, next);
+                }, true);
+            }, next);
+        },
+    ];
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;doTest()&quot;&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformeflTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/efl/TestExpectations (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/efl/TestExpectations        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/LayoutTests/platform/efl/TestExpectations        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -2983,6 +2983,7 @@
</span><span class="cx"> Bug(EFL) media/encrypted-media/encrypted-media-syntax.html [ Failure ]
</span><span class="cx"> Bug(EFL) media/encrypted-media/mock-MediaKeySession-close.html [ Failure ]
</span><span class="cx"> Bug(EFL) media/encrypted-media/mock-MediaKeySession-generateRequest.html [ Failure ]
</span><ins>+Bug(EFL) media/encrypted-media/mock-MediaKeySession-remove.html [ Failure ]
</ins><span class="cx"> Bug(EFL) media/encrypted-media/mock-MediaKeySession-update.html [ Failure ]
</span><span class="cx"> Bug(EFL) media/encrypted-media/mock-MediaKeySystemAccess.html [ Failure ]
</span><span class="cx"> Bug(EFL) media/encrypted-media/mock-MediaKeys-createSession.html [ Failure ]
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/TestExpectations (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/TestExpectations        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/LayoutTests/platform/mac/TestExpectations        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -1494,6 +1494,7 @@
</span><span class="cx"> media/encrypted-media/mock-MediaKeys-createSession.html [ Skip ]
</span><span class="cx"> media/encrypted-media/mock-MediaKeySession-close.html [ Skip ]
</span><span class="cx"> media/encrypted-media/mock-MediaKeySession-generateRequest.html [ Skip ]
</span><ins>+media/encrypted-media/mock-MediaKeySession-remove.html [ Skip ]
</ins><span class="cx"> media/encrypted-media/mock-MediaKeySession-update.html [ Skip ]
</span><span class="cx"> 
</span><span class="cx"> webkit.org/b/166025 http/tests/fetch/fetching-same-resource-with-diffferent-options.html [ Pass Failure ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/ChangeLog        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -1,5 +1,42 @@
</span><span class="cx"> 2017-02-08  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [EME] Implement MediaKeySession::remove()
+        https://bugs.webkit.org/show_bug.cgi?id=167870
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Implement MediaKeySession::remove() as outlined in the specification.
+
+        The CDMInstance::removeSessionData() virtual method is added. CDMInstance
+        implementors should remove any session data stored for the session that's
+        represented by the passed-in session ID and session type.
+
+        Once the session data is removed, the passed-in callback should be invoked
+        by the CDMInstance object so that MediaKeySession can immediately queue a
+        task in which it updates key statuses and expiration, reject the promise if
+        the data removal failed, or enqueue any license-release message and finally
+        successfully resolve the promise.
+
+        MockCDMFactory gains the removeKeysFromSessionWithID() method that purges
+        the keys for a given session ID. The method is called from
+        MockCDMInstance::removeSessionData() implementation, which passes the
+        removed keys to the RemoveSessionDataCallback, along with a license-release
+        message that is checked in the tests. The key removal itself isn't tested
+        yet because the MediaKeySession's `update key statuses` algorithm isn't
+        implemented yet.
+
+        Test: media/encrypted-media/mock-MediaKeySession-remove.html
+
+        * Modules/encryptedmedia/CDMInstance.h:
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        (WebCore::MediaKeySession::remove):
+        * testing/MockCDMFactory.cpp:
+        (WebCore::MockCDMFactory::removeKeysFromSessionWithID):
+        (WebCore::MockCDMInstance::removeSessionData):
+        * testing/MockCDMFactory.h:
+
+2017-02-08  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
+
</ins><span class="cx">         [EME] Implement MediaKeySession::close()
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=167869
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaCDMInstanceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -69,6 +69,9 @@
</span><span class="cx"> 
</span><span class="cx">     using CloseSessionCallback = Function&lt;void()&gt;;
</span><span class="cx">     virtual void closeSession(const String&amp; sessionId, CloseSessionCallback) = 0;
</span><ins>+
+    using RemoveSessionDataCallback = Function&lt;void(KeyStatusVector&amp;&amp;, std::optional&lt;Ref&lt;SharedBuffer&gt;&gt;&amp;&amp;, SuccessValue)&gt;;
+    virtual void removeSessionData(const String&amp; sessionId, LicenseType, RemoveSessionDataCallback) = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaMediaKeySessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -400,9 +400,70 @@
</span><span class="cx">     // 6. Return promise.
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaKeySession::remove(Ref&lt;DeferredPromise&gt;&amp;&amp;)
</del><ins>+void MediaKeySession::remove(Ref&lt;DeferredPromise&gt;&amp;&amp; promise)
</ins><span class="cx"> {
</span><del>-    notImplemented();
</del><ins>+    // https://w3c.github.io/encrypted-media/#dom-mediakeysession-remove
+    // W3C Editor's Draft 09 November 2016
+
+    // 1. If this object is closed, return a promise rejected with an InvalidStateError.
+    // 2. If this object's callable value is false, return a promise rejected with an InvalidStateError.
+    if (m_closed || !m_callable) {
+        promise-&gt;reject(INVALID_STATE_ERR);
+        return;
+    }
+
+    // 3. Let promise be a new promise.
+    // 4. Run the following steps in parallel:
+    m_taskQueue.enqueueTask([this, promise = WTFMove(promise)] () mutable {
+        // 4.1. Let cdm be the CDM instance represented by this object's cdm instance value.
+        // 4.2. Let message be null.
+        // 4.3. Let message type be null.
+
+        // 4.4. Use the cdm to execute the following steps:
+        m_instance-&gt;removeSessionData(m_sessionId, m_sessionType, [this, weakThis = m_weakPtrFactory.createWeakPtr(), promise = WTFMove(promise)] (CDMInstance::KeyStatusVector&amp;&amp; keys, std::optional&lt;Ref&lt;SharedBuffer&gt;&gt;&amp;&amp; message, CDMInstance::SuccessValue succeeded) mutable {
+            if (!weakThis)
+                return;
+
+            // 4.4.1. If any license(s) and/or key(s) are associated with the session:
+            //   4.4.1.1. Destroy the license(s) and/or key(s) associated with the session.
+            //   4.4.1.2. Follow the steps for the value of this object's session type from the following list:
+            //     ↳ &quot;temporary&quot;
+            //       4.4.1.2.1.1 Continue with the following steps.
+            //     ↳ &quot;persistent-license&quot;
+            //       4.4.1.2.2.1. Let record of license destruction be a record of license destruction for the license represented by this object.
+            //       4.4.1.2.2.2. Store the record of license destruction.
+            //       4.4.1.2.2.3. Let message be a message containing or reflecting the record of license destruction.
+            //     ↳ &quot;persistent-usage-record&quot;
+            //       4.4.1.2.3.1. Store this object's record of key usage.
+            //       4.4.1.2.3.2. Let message be a message containing or reflecting this object's record of key usage.
+            // NOTE: Step 4.4.1. should be implemented in CDMInstance.
+
+            // 4.5. Queue a task to run the following steps:
+            m_taskQueue.enqueueTask([this, keys = WTFMove(keys), message = WTFMove(message), succeeded, promise = WTFMove(promise)] () mutable {
+                // 4.5.1. Run the Update Key Statuses algorithm on the session, providing all key ID(s) in the session along with the &quot;released&quot; MediaKeyStatus value for each.
+                updateKeyStatuses(WTFMove(keys));
+
+                // 4.5.2. Run the Update Expiration algorithm on the session, providing NaN.
+                updateExpiration(std::numeric_limits&lt;double&gt;::quiet_NaN());
+
+                // 4.5.3. If any of the preceding steps failed, reject promise with a new DOMException whose name is the appropriate error name.
+                if (succeeded == CDMInstance::SuccessValue::Failed) {
+                    promise-&gt;reject(NOT_SUPPORTED_ERR);
+                    return;
+                }
+
+                // 4.5.4. Let message type be &quot;license-release&quot;.
+                // 4.5.5. If message is not null, run the Queue a &quot;message&quot; Event algorithm on the session, providing message type and message.
+                if (message)
+                    enqueueMessage(MediaKeyMessageType::LicenseRelease, *message);
+
+                // 4.5.6. Resolve promise.
+                promise-&gt;resolve();
+            });
+        });
+    });
+
+    // 5. Return promise.
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MediaKeySession::enqueueMessage(MediaKeyMessageType messageType, const SharedBuffer&amp; message)
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockCDMFactorycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockCDMFactory.cpp (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockCDMFactory.cpp        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/testing/MockCDMFactory.cpp        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -72,6 +72,15 @@
</span><span class="cx">         value.append(WTFMove(key));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Vector&lt;Ref&lt;SharedBuffer&gt;&gt; MockCDMFactory::removeKeysFromSessionWithID(const String&amp; id)
+{
+    auto it = m_sessions.find(id);
+    if (it == m_sessions.end())
+        return { };
+
+    return WTFMove(it-&gt;value);
+}
+
</ins><span class="cx"> void MockCDMFactory::setSupportedDataTypes(Vector&lt;String&gt;&amp;&amp; types)
</span><span class="cx"> {
</span><span class="cx">     m_supportedDataTypes.clear();
</span><span class="lines">@@ -301,6 +310,24 @@
</span><span class="cx">     callback();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MockCDMInstance::removeSessionData(const String&amp; id, LicenseType, RemoveSessionDataCallback callback)
+{
+    MockCDMFactory* factory = m_cdm ? m_cdm-&gt;factory() : nullptr;
+    if (!factory) {
+        callback({ }, std::nullopt, SuccessValue::Failed);
+        return;
+    }
+
+    auto keys = factory-&gt;removeKeysFromSessionWithID(id);
+    KeyStatusVector keyStatusVector;
+    keyStatusVector.reserveInitialCapacity(keys.size());
+    for (auto&amp; key : keys)
+        keyStatusVector.uncheckedAppend({ WTFMove(key), KeyStatus::Released });
+
+    CString message { &quot;remove-message&quot; };
+    callback(WTFMove(keyStatusVector), SharedBuffer::create(message.data(), message.length()), SuccessValue::Succeeded);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockCDMFactoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockCDMFactory.h (211856 => 211857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockCDMFactory.h        2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/testing/MockCDMFactory.h        2017-02-08 10:39:49 UTC (rev 211857)
</span><span class="lines">@@ -72,6 +72,7 @@
</span><span class="cx">     bool hasSessionWithID(const String&amp; id) { return m_sessions.contains(id); }
</span><span class="cx">     void removeSessionWithID(const String&amp; id) { m_sessions.remove(id); }
</span><span class="cx">     void addKeysToSessionWithID(const String&amp; id, Vector&lt;Ref&lt;SharedBuffer&gt;&gt;&amp;&amp;);
</span><ins>+    Vector&lt;Ref&lt;SharedBuffer&gt;&gt; removeKeysFromSessionWithID(const String&amp; id);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     MockCDMFactory();
</span><span class="lines">@@ -131,6 +132,7 @@
</span><span class="cx">     void requestLicense(LicenseType, const AtomicString&amp; initDataType, Ref&lt;SharedBuffer&gt;&amp;&amp; initData, LicenseCallback) final;
</span><span class="cx">     void updateLicense(LicenseType, const SharedBuffer&amp;, LicenseUpdateCallback) final;
</span><span class="cx">     void closeSession(const String&amp;, CloseSessionCallback) final;
</span><ins>+    void removeSessionData(const String&amp;, LicenseType, RemoveSessionDataCallback) final;
</ins><span class="cx"> 
</span><span class="cx">     WeakPtr&lt;MockCDM&gt; m_cdm;
</span><span class="cx">     bool m_distinctiveIdentifiersAllowed { true };
</span></span></pre>
</div>
</div>

</body>
</html>