<!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>[210445] 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/210445">210445</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2017-01-06 10:48:29 -0800 (Fri, 06 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add support for MediaKeySystemAccess.createMediaKeys()
https://bugs.webkit.org/show_bug.cgi?id=166749

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/encrypted-media/mock-MediaKeySystemAccess.html

Implement MediaKeySystemAccess::createMediaKeys(). This requires some
additions to CDM, CDMPrivate, and a new interface CDMInstance to support
eventual platform adoption and to implement mock support for testing.

* Modules/encryptedmedia/CDM.cpp:
(WebCore::CDM::loadAndInitialize):
(WebCore::CDM::createInstance):
* Modules/encryptedmedia/CDM.h:
* Modules/encryptedmedia/CDMInstance.h:
(WebCore::CDMInstance::~CDMInstance):
* Modules/encryptedmedia/CDMPrivate.h:
* Modules/encryptedmedia/MediaKeySystemAccess.cpp:
(WebCore::MediaKeySystemAccess::createMediaKeys):
* Modules/encryptedmedia/MediaKeySystemAccess.h:
* Modules/encryptedmedia/MediaKeys.cpp:
(WebCore::MediaKeys::MediaKeys):
* Modules/encryptedmedia/MediaKeys.h:
(WebCore::MediaKeys::create):
* Modules/encryptedmedia/MediaKeys.idl:
* Modules/encryptedmedia/NavigatorEME.cpp:
(WebCore::tryNextSupportedConfiguration):
* WebCore.xcodeproj/project.pbxproj:
* testing/MockCDMFactory.cpp:
(WebCore::MockCDM::MockCDM):
(WebCore::MockCDM::createInstance):
(WebCore::MockCDM::loadAndInitialize):
(WebCore::MockCDMInstance::MockCDMInstance):
(WebCore::MockCDMInstance::initializeWithConfiguration):
(WebCore::MockCDMInstance::setDistinctiveIdentifiersAllowed):
(WebCore::MockCDMInstance::setPersistentStateAllowed):
* testing/MockCDMFactory.h:
(WebCore::MockCDMFactory::canCreateInstances):
(WebCore::MockCDMFactory::setCanCreateInstances):
(WebCore::MockCDM::factory):
* testing/MockCDMFactory.idl:

LayoutTests:

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</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="#trunkSourceWebCoreModulesencryptedmediaCDMcpp">trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaCDMh">trunk/Source/WebCore/Modules/encryptedmedia/CDM.h</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaCDMPrivateh">trunk/Source/WebCore/Modules/encryptedmedia/CDMPrivate.h</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaMediaKeySystemAccesscpp">trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaMediaKeySystemAccessh">trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.h</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaMediaKeyscpp">trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaMediaKeysh">trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaMediaKeysidl">trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaNavigatorEMEcpp">trunk/Source/WebCore/Modules/encryptedmedia/NavigatorEME.cpp</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</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>
<li><a href="#trunkSourceWebCoretestingMockCDMFactoryidl">trunk/Source/WebCore/testing/MockCDMFactory.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsmediaencryptedmediamockMediaKeySystemAccessexpectedtxt">trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediaencryptedmediamockMediaKeySystemAccesshtml">trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess.html</a></li>
<li><a href="#trunkSourceWebCoreModulesencryptedmediaCDMInstanceh">trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/LayoutTests/ChangeLog        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2017-01-06  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Add support for MediaKeySystemAccess.createMediaKeys()
+        https://bugs.webkit.org/show_bug.cgi?id=166749
+
+        Reviewed by Eric Carlson.
+
+        * media/encrypted-media/mock-MediaKeySystemAccess-expected.txt: Added.
+        * media/encrypted-media/mock-MediaKeySystemAccess.html: Added.
+        * platform/mac/TestExpectations:
+
</ins><span class="cx"> 2017-01-06  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add pass expectation for fast/text/emoji-num-glyphs.html on Sierra.
</span></span></pre></div>
<a id="trunkLayoutTestsmediaencryptedmediamockMediaKeySystemAccessexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess-expected.txt (0 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess-expected.txt                                (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess-expected.txt        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+RUN(internals.initializeMockMediaSource())
+RUN(mock = internals.registerMockCDM())
+RUN(mock.supportedDataTypes = [&quot;mock&quot;])
+
+RUN(capabilities.initDataTypes = [&quot;mock&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
+
+RUN(mock.canCreateInstances = false)
+RUN(promise = mediaKeySystemAccess.createMediaKeys())
+Promise rejected correctly OK
+
+RUN(mock.canCreateInstances = true)
+RUN(capabilities.distinctiveIdentifier = &quot;not-allowed&quot;)
+RUN(promise = navigator.requestMediaKeySystemAccess(&quot;org.webkit.mock&quot;, [capabilities]))
+Promise resolved OK
+
+RUN(promise = mediaKeySystemAccess.createMediaKeys())
+Promise resolved OK
+
+RUN(mock.distinctiveIdentifiersRequirement = &quot;required&quot;)
+RUN(promise = mediaKeySystemAccess.createMediaKeys())
+Promise rejected correctly OK
+
+RUN(mock.distinctiveIdentifiersRequirement = &quot;optional&quot;)
+RUN(capabilities.persistentState = &quot;not-allowed&quot;)
+RUN(promise = navigator.requestMediaKeySystemAccess(&quot;org.webkit.mock&quot;, [capabilities]))
+Promise resolved OK
+
+RUN(promise = mediaKeySystemAccess.createMediaKeys())
+Promise resolved OK
+
+RUN(mock.persistentStateRequirement = &quot;required&quot;)
+RUN(promise = mediaKeySystemAccess.createMediaKeys())
+Promise rejected correctly OK
+END OF TEST
+
</ins></span></pre></div>
<a id="trunkLayoutTestsmediaencryptedmediamockMediaKeySystemAccesshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess.html (0 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess.html                                (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-MediaKeySystemAccess.html        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -0,0 +1,122 @@
</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 capabilities = {};
+
+    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;mock&quot;]');
+
+        next();
+    }
+
+    function next() {
+        if (!tests.length) {
+            mock.unregister();
+            endTest()
+            return;
+        }
+
+        var nextTest = tests.shift();
+        consoleWrite('');
+        nextTest();
+    }
+
+    function shouldResolve(promise) {
+        promise.then(mediaKeySystemAccess =&gt; {
+            logResult(Success, 'Promise resolved');
+            next();
+        }, () =&gt; {
+            logResult(Failed, 'Promise rejected');
+            next();
+        });
+    }
+
+    function shouldReject(promise) {
+        promise.then(() =&gt; {
+            logResult(Failed, 'Promise resolved incorrectly');
+            next();
+        }, exceptionCode =&gt; {
+            logResult(Success, 'Promise rejected correctly');
+            next();
+        });
+    }
+
+    function gotMediaKeySystemAccess(result) {
+        logResult(Success, 'Promise resolved');
+        mediaKeySystemAccess = result;
+        next();
+    }
+
+    tests = [
+        function() {
+            run('capabilities.initDataTypes = [&quot;mock&quot;]');
+            run(`capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs=&quot;mock&quot;' }] `);
+            run('promise = navigator.requestMediaKeySystemAccess(&quot;org.webkit.mock&quot;, [capabilities])');
+            promise.then(gotMediaKeySystemAccess).catch(failTest);
+        },
+
+        function() {
+            run('promise = mediaKeySystemAccess.createMediaKeys()');
+            shouldResolve(promise);
+        },
+
+        function() {
+            run('mock.canCreateInstances = false');
+            run('promise = mediaKeySystemAccess.createMediaKeys()');
+            shouldReject(promise);
+        },
+
+        function() {
+            run('mock.canCreateInstances = true');
+            run('capabilities.distinctiveIdentifier = &quot;not-allowed&quot;');
+            run('promise = navigator.requestMediaKeySystemAccess(&quot;org.webkit.mock&quot;, [capabilities])');
+            promise.then(gotMediaKeySystemAccess).catch(failTest);
+        },
+
+        function() {
+            run('promise = mediaKeySystemAccess.createMediaKeys()');
+            shouldResolve(promise);
+        },
+
+        function() {
+            run('mock.distinctiveIdentifiersRequirement = &quot;required&quot;');
+            run('promise = mediaKeySystemAccess.createMediaKeys()');
+            shouldReject(promise);
+        },
+
+        function() {
+            run('mock.distinctiveIdentifiersRequirement = &quot;optional&quot;');
+            run('capabilities.persistentState = &quot;not-allowed&quot;');
+            run('promise = navigator.requestMediaKeySystemAccess(&quot;org.webkit.mock&quot;, [capabilities])');
+            promise.then(gotMediaKeySystemAccess).catch(failTest);
+        },
+
+        function() {
+            run('promise = mediaKeySystemAccess.createMediaKeys()');
+            shouldResolve(promise);
+        },
+
+        function() {
+            run('mock.persistentStateRequirement = &quot;required&quot;');
+            run('promise = mediaKeySystemAccess.createMediaKeys()');
+            shouldReject(promise);
+        },
+    ];
+    &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="trunkLayoutTestsplatformmacTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/TestExpectations (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/TestExpectations        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/LayoutTests/platform/mac/TestExpectations        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -1465,5 +1465,6 @@
</span><span class="cx"> 
</span><span class="cx"> # New Encrypted Media API not enabled on Mac
</span><span class="cx"> media/encrypted-media/mock-navigator-requestMediaKeySystemAccess.html [ Skip ]
</span><ins>+media/encrypted-media/mock-MediaKeySystemAccess.html [ Skip ]
</ins><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 (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/ChangeLog        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2017-01-06  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Add support for MediaKeySystemAccess.createMediaKeys()
+        https://bugs.webkit.org/show_bug.cgi?id=166749
+
+        Reviewed by Eric Carlson.
+
+        Test: media/encrypted-media/mock-MediaKeySystemAccess.html
+
+        Implement MediaKeySystemAccess::createMediaKeys(). This requires some
+        additions to CDM, CDMPrivate, and a new interface CDMInstance to support
+        eventual platform adoption and to implement mock support for testing.
+
+        * Modules/encryptedmedia/CDM.cpp:
+        (WebCore::CDM::loadAndInitialize):
+        (WebCore::CDM::createInstance):
+        * Modules/encryptedmedia/CDM.h:
+        * Modules/encryptedmedia/CDMInstance.h:
+        (WebCore::CDMInstance::~CDMInstance):
+        * Modules/encryptedmedia/CDMPrivate.h:
+        * Modules/encryptedmedia/MediaKeySystemAccess.cpp:
+        (WebCore::MediaKeySystemAccess::createMediaKeys):
+        * Modules/encryptedmedia/MediaKeySystemAccess.h:
+        * Modules/encryptedmedia/MediaKeys.cpp:
+        (WebCore::MediaKeys::MediaKeys):
+        * Modules/encryptedmedia/MediaKeys.h:
+        (WebCore::MediaKeys::create):
+        * Modules/encryptedmedia/MediaKeys.idl:
+        * Modules/encryptedmedia/NavigatorEME.cpp:
+        (WebCore::tryNextSupportedConfiguration):
+        * WebCore.xcodeproj/project.pbxproj:
+        * testing/MockCDMFactory.cpp:
+        (WebCore::MockCDM::MockCDM):
+        (WebCore::MockCDM::createInstance):
+        (WebCore::MockCDM::loadAndInitialize):
+        (WebCore::MockCDMInstance::MockCDMInstance):
+        (WebCore::MockCDMInstance::initializeWithConfiguration):
+        (WebCore::MockCDMInstance::setDistinctiveIdentifiersAllowed):
+        (WebCore::MockCDMInstance::setPersistentStateAllowed):
+        * testing/MockCDMFactory.h:
+        (WebCore::MockCDMFactory::canCreateInstances):
+        (WebCore::MockCDMFactory::setCanCreateInstances):
+        (WebCore::MockCDM::factory):
+        * testing/MockCDMFactory.idl:
+
</ins><span class="cx"> 2017-01-06  Andreas Kling  &lt;akling@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Give RenderObject a Page&amp; getter.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaCDMcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -611,6 +611,19 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void CDM::loadAndInitialize()
+{
+    if (m_private)
+        m_private-&gt;loadAndInitialize();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+std::unique_ptr&lt;CDMInstance&gt; CDM::createInstance()
+{
+    if (!m_private)
+        return nullptr;
+    return m_private-&gt;createInstance();
+}
+
+}
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaCDMh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDM.h (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/CDM.h        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDM.h        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class CDM;
</span><ins>+class CDMInstance;
</ins><span class="cx"> class CDMPrivate;
</span><span class="cx"> class Document;
</span><span class="cx"> class ScriptExecutionContext;
</span><span class="lines">@@ -68,6 +69,9 @@
</span><span class="cx"> 
</span><span class="cx">     const String&amp; keySystem() const { return m_keySystem; }
</span><span class="cx"> 
</span><ins>+    void loadAndInitialize();
+    std::unique_ptr&lt;CDMInstance&gt; createInstance();
+
</ins><span class="cx"> private:
</span><span class="cx">     CDM(Document&amp;, const String&amp; keySystem);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaCDMInstancehfromrev210443trunkSourceWebCoretestingMockCDMFactoryidl"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h (from rev 210443, trunk/Source/WebCore/testing/MockCDMFactory.idl) (0 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h                                (rev 0)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -0,0 +1,52 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(ENCRYPTED_MEDIA)
+
+#include &lt;wtf/Forward.h&gt;
+
+namespace WebCore {
+
+struct MediaKeySystemConfiguration;
+
+class CDMInstance {
+public:
+    virtual ~CDMInstance() { }
+
+    enum SuccessValue {
+        Failed,
+        Succeeded,
+    };
+
+    virtual SuccessValue initializeWithConfiguration(const MediaKeySystemConfiguration&amp;) = 0;
+    virtual SuccessValue setDistinctiveIdentifiersAllowed(bool) = 0;
+    virtual SuccessValue setPersistentStateAllowed(bool) = 0;
+};
+
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaCDMPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDMPrivate.h (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/CDMPrivate.h        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDMPrivate.h        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA)
</span><span class="cx"> 
</span><ins>+#include &quot;CDMInstance.h&quot;
</ins><span class="cx"> #include &quot;MediaKeySessionType.h&quot;
</span><span class="cx"> #include &quot;MediaKeysRequirement.h&quot;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="lines">@@ -39,6 +40,7 @@
</span><span class="cx"> class CDMPrivate {
</span><span class="cx"> public:
</span><span class="cx">     virtual ~CDMPrivate() { }
</span><ins>+
</ins><span class="cx">     virtual bool supportsInitDataType(const String&amp;) = 0;
</span><span class="cx">     virtual bool supportsConfiguration(const MediaKeySystemConfiguration&amp;) = 0;
</span><span class="cx">     virtual bool supportsConfigurationWithRestrictions(const MediaKeySystemConfiguration&amp;, const MediaKeysRestrictions&amp;) = 0;
</span><span class="lines">@@ -47,6 +49,8 @@
</span><span class="cx">     virtual MediaKeysRequirement distinctiveIdentifiersRequirement(const MediaKeySystemConfiguration&amp;, const MediaKeysRestrictions&amp;) = 0;
</span><span class="cx">     virtual MediaKeysRequirement persistentStateRequirement(const MediaKeySystemConfiguration&amp;, const MediaKeysRestrictions&amp;) = 0;
</span><span class="cx">     virtual bool distinctiveIdentifiersAreUniquePerOriginAndClearable(const MediaKeySystemConfiguration&amp;) = 0;
</span><ins>+    virtual std::unique_ptr&lt;CDMInstance&gt; createInstance() = 0;
+    virtual void loadAndInitialize() = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaMediaKeySystemAccesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.cpp (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.cpp        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.cpp        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -32,7 +32,10 @@
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CDM.h&quot;
</span><ins>+#include &quot;CDMInstance.h&quot;
+#include &quot;JSMediaKeys.h&quot;
</ins><span class="cx"> #include &quot;MediaKeySystemConfiguration.h&quot;
</span><ins>+#include &quot;MediaKeys.h&quot;
</ins><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -51,9 +54,64 @@
</span><span class="cx"> 
</span><span class="cx"> MediaKeySystemAccess::~MediaKeySystemAccess() = default;
</span><span class="cx"> 
</span><del>-void MediaKeySystemAccess::createMediaKeys(Ref&lt;DeferredPromise&gt;&amp;&amp;)
</del><ins>+void MediaKeySystemAccess::createMediaKeys(Ref&lt;DeferredPromise&gt;&amp;&amp; promise)
</ins><span class="cx"> {
</span><del>-    notImplemented();
</del><ins>+    // https://w3c.github.io/encrypted-media/#dom-mediakeysystemaccess-createmediakeys
+    // W3C Editor's Draft 09 November 2016
+
+    // When this method is invoked, the user agent must run the following steps:
+    // 1. Let promise be a new promise.
+    // 2. Run the following steps in parallel:
+    m_taskQueue.enqueueTask([this, promise = WTFMove(promise)] () mutable {
+        // 2.1. Let configuration be the value of this object's configuration value.
+        // 2.2. Let use distinctive identifier be true if the value of configuration's distinctiveIdentifier member is &quot;required&quot; and false otherwise.
+        bool useDistinctiveIdentifier = m_configuration-&gt;distinctiveIdentifier == MediaKeysRequirement::Required;
+
+        // 2.3. Let persistent state allowed be true if the value of configuration's persistentState member is &quot;required&quot; and false otherwise.
+        bool persistentStateAllowed = m_configuration-&gt;persistentState == MediaKeysRequirement::Required;
+
+        // 2.4. Load and initialize the Key System implementation represented by this object's cdm implementation value if necessary.
+        m_implementation-&gt;loadAndInitialize();
+
+        // 2.5. Let instance be a new instance of the Key System implementation represented by this object's cdm implementation value.
+        std::unique_ptr&lt;CDMInstance&gt; instance = m_implementation-&gt;createInstance();
+        if (!instance) {
+            promise-&gt;reject(INVALID_STATE_ERR);
+            return;
+        }
+
+        // 2.6. Initialize instance to enable, disable and/or select Key System features using configuration.
+        if (instance-&gt;initializeWithConfiguration(*m_configuration) == CDMInstance::Failed) {
+            promise-&gt;reject(NotAllowedError);
+            return;
+        }
+
+        // 2.7. If use distinctive identifier is false, prevent instance from using Distinctive Identifier(s) and Distinctive Permanent Identifier(s).
+        if (!useDistinctiveIdentifier &amp;&amp; instance-&gt;setDistinctiveIdentifiersAllowed(false) == CDMInstance::Failed) {
+            promise-&gt;reject(NotAllowedError);
+            return;
+        }
+
+        // 2.8. If persistent state allowed is false, prevent instance from persisting any state related to the application or origin of this object's Document.
+        if (!persistentStateAllowed &amp;&amp; instance-&gt;setPersistentStateAllowed(false) == CDMInstance::Failed) {
+            promise-&gt;reject(NotAllowedError);
+            return;
+        }
+
+        // 2.9. If any of the preceding steps failed, reject promise with a new DOMException whose name is the appropriate error name.
+        // 2.10. Let media keys be a new MediaKeys object, and initialize it as follows:
+        // 2.10.1. Let the use distinctive identifier value be use distinctive identifier.
+        // 2.10.2. Let the persistent state allowed value be persistent state allowed.
+        // 2.10.3. Let the supported session types value be be the value of configuration's sessionTypes member.
+        // 2.10.4. Let the cdm implementation value be this object's cdm implementation value.
+        // 2.10.5. Let the cdm instance value be instance.
+        auto mediaKeys = MediaKeys::create(useDistinctiveIdentifier, persistentStateAllowed, m_configuration-&gt;sessionTypes, m_implementation.copyRef(), WTFMove(instance));
+
+        // 2.11. Resolve promise with media keys.
+        promise-&gt;resolveWithNewlyCreated&lt;IDLInterface&lt;MediaKeys&gt;&gt;(WTFMove(mediaKeys));
+    });
+
+    // 3. Return promise.
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaMediaKeySystemAccessh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.h (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.h        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.h        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA)
</span><span class="cx"> 
</span><ins>+#include &quot;GenericTaskQueue.h&quot;
</ins><span class="cx"> #include &quot;JSDOMPromise.h&quot;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="lines">@@ -56,6 +57,7 @@
</span><span class="cx">     String m_keySystem;
</span><span class="cx">     std::unique_ptr&lt;MediaKeySystemConfiguration&gt; m_configuration;
</span><span class="cx">     Ref&lt;CDM&gt; m_implementation;
</span><ins>+    GenericTaskQueue&lt;Timer&gt; m_taskQueue;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaMediaKeyscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -31,12 +31,21 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA)
</span><span class="cx"> 
</span><ins>+#include &quot;CDM.h&quot;
+#include &quot;CDMInstance.h&quot;
</ins><span class="cx"> #include &quot;MediaKeySession.h&quot;
</span><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-MediaKeys::MediaKeys() = default;
</del><ins>+MediaKeys::MediaKeys(bool useDistinctiveIdentifier, bool persistentStateAllowed, const Vector&lt;MediaKeySessionType&gt;&amp; supportedSessionTypes, Ref&lt;CDM&gt;&amp;&amp; implementation, std::unique_ptr&lt;CDMInstance&gt;&amp;&amp; instance)
+    : m_useDistinctiveIdentifier(useDistinctiveIdentifier)
+    , m_persistentStateAllowed(persistentStateAllowed)
+    , m_supportedSessionTypes(supportedSessionTypes)
+    , m_implementation(WTFMove(implementation))
+    , m_instance(WTFMove(instance))
+{
+}
</ins><span class="cx"> 
</span><span class="cx"> MediaKeys::~MediaKeys() = default;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaMediaKeysh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -38,6 +38,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class CDM;
+class CDMInstance;
</ins><span class="cx"> class BufferSource;
</span><span class="cx"> class MediaKeySession;
</span><span class="cx"> 
</span><span class="lines">@@ -45,12 +47,12 @@
</span><span class="cx"> public:
</span><span class="cx">     using KeySessionType = MediaKeySessionType;
</span><span class="cx"> 
</span><del>-    static Ref&lt;MediaKeys&gt; create()
</del><ins>+    static Ref&lt;MediaKeys&gt; create(bool useDistinctiveIdentifier, bool persistentStateAllowed, const Vector&lt;MediaKeySessionType&gt;&amp; supportedSessionTypes, Ref&lt;CDM&gt;&amp;&amp; implementation, std::unique_ptr&lt;CDMInstance&gt;&amp;&amp; instance)
</ins><span class="cx">     {
</span><del>-        return adoptRef(*new MediaKeys);
</del><ins>+        return adoptRef(*new MediaKeys(useDistinctiveIdentifier, persistentStateAllowed, supportedSessionTypes, WTFMove(implementation), WTFMove(instance)));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    virtual ~MediaKeys();
</del><ins>+    ~MediaKeys();
</ins><span class="cx"> 
</span><span class="cx">     ExceptionOr&lt;Ref&lt;MediaKeySession&gt;&gt; createSession(MediaKeySessionType);
</span><span class="cx"> 
</span><span class="lines">@@ -57,7 +59,13 @@
</span><span class="cx">     void setServerCertificate(const BufferSource&amp;, Ref&lt;DeferredPromise&gt;&amp;&amp;);
</span><span class="cx"> 
</span><span class="cx"> protected:
</span><del>-    MediaKeys();
</del><ins>+    MediaKeys(bool useDistinctiveIdentifier, bool persistentStateAllowed, const Vector&lt;MediaKeySessionType&gt;&amp;, Ref&lt;CDM&gt;&amp;&amp;, std::unique_ptr&lt;CDMInstance&gt;&amp;&amp;);
+
+    bool m_useDistinctiveIdentifier;
+    bool m_persistentStateAllowed;
+    Vector&lt;MediaKeySessionType&gt; m_supportedSessionTypes;
+    Ref&lt;CDM&gt; m_implementation;
+    std::unique_ptr&lt;CDMInstance&gt; m_instance;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaMediaKeysidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -28,7 +28,8 @@
</span><span class="cx"> 
</span><span class="cx"> [
</span><span class="cx">     Conditional=ENCRYPTED_MEDIA,
</span><del>-    EnabledAtRuntime=EncryptedMediaAPI
</del><ins>+    EnabledAtRuntime=EncryptedMediaAPI,
+    ImplementationLacksVTable,
</ins><span class="cx"> ] interface MediaKeys {
</span><span class="cx">     [MayThrowException] MediaKeySession createSession(optional MediaKeySessionType sessionType = &quot;temporary&quot;);
</span><span class="cx">     Promise&lt;bool&gt; setServerCertificate(BufferSource serverCertificate);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesencryptedmediaNavigatorEMEcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/encryptedmedia/NavigatorEME.cpp (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/encryptedmedia/NavigatorEME.cpp        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/Modules/encryptedmedia/NavigatorEME.cpp        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -90,7 +90,7 @@
</span><span class="cx">                 // 6.3.3.1.3. Let the cdm implementation value be implementation.
</span><span class="cx">                 auto access = MediaKeySystemAccess::create(implementation-&gt;keySystem(), WTFMove(supportedConfiguration.value()), implementation.releaseNonNull());
</span><span class="cx">                 // 6.3.3.2. Resolve promise with access and abort the parallel steps of this algorithm.
</span><del>-                promise-&gt;resolve&lt;IDLInterface&lt;MediaKeySystemAccess&gt;&gt;(access.get());
</del><ins>+                promise-&gt;resolveWithNewlyCreated&lt;IDLInterface&lt;MediaKeySystemAccess&gt;&gt;(WTFMove(access));
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -13738,6 +13738,7 @@
</span><span class="cx">                 CD8B5A48180E138B008B8E65 /* TextTrackMediaSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackMediaSource.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD8B5A4A180E17A3008B8E65 /* AudioTrackMediaSource.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = AudioTrackMediaSource.idl; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD8B5A4B180E17C0008B8E65 /* AudioTrackMediaSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioTrackMediaSource.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                CD9D05421E1EFA12003B4C4F /* CDMInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMInstance.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 CD9D82731C7AE535006FF066 /* TextureCacheCV.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TextureCacheCV.mm; path = ../cv/TextureCacheCV.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD9D82741C7AE535006FF066 /* TextureCacheCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TextureCacheCV.h; path = ../cv/TextureCacheCV.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD9D82771C7B8EE1006FF066 /* VideoTextureCopierCV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VideoTextureCopierCV.cpp; path = ../cv/VideoTextureCopierCV.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -22754,6 +22755,7 @@
</span><span class="cx">                                 2D0621461DA639EC00A7FB26 /* legacy */,
</span><span class="cx">                                 CDF4B7131E00B7E500E235A2 /* CDM.cpp */,
</span><span class="cx">                                 CDF4B7141E00B7E500E235A2 /* CDM.h */,
</span><ins>+                                CD9D05421E1EFA12003B4C4F /* CDMInstance.h */,
</ins><span class="cx">                                 CDF4B7251E03C15B00E235A2 /* CDMPrivate.h */,
</span><span class="cx">                                 2D9BF72F1DBFDC0F007A7D99 /* MediaKeyMessageEvent.cpp */,
</span><span class="cx">                                 2D9BF7301DBFDC0F007A7D99 /* MediaKeyMessageEvent.h */,
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockCDMFactorycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockCDMFactory.cpp (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockCDMFactory.cpp        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/testing/MockCDMFactory.cpp        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -63,6 +63,7 @@
</span><span class="cx"> 
</span><span class="cx"> MockCDM::MockCDM(WeakPtr&lt;MockCDMFactory&gt; factory)
</span><span class="cx">     : m_factory(WTFMove(factory))
</span><ins>+    , m_weakPtrFactory(this)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -119,6 +120,59 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+std::unique_ptr&lt;CDMInstance&gt; MockCDM::createInstance()
+{
+    if (m_factory &amp;&amp; !m_factory-&gt;canCreateInstances())
+        return nullptr;
+    return std::unique_ptr&lt;CDMInstance&gt;(new MockCDMInstance(m_weakPtrFactory.createWeakPtr()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MockCDM::loadAndInitialize()
+{
+    // No-op.
+}
+
+MockCDMInstance::MockCDMInstance(WeakPtr&lt;MockCDM&gt; cdm)
+    : m_cdm(cdm)
+{
+}
+
+CDMInstance::SuccessValue MockCDMInstance::initializeWithConfiguration(const MediaKeySystemConfiguration&amp; configuration)
+{
+    if (!m_cdm || !m_cdm-&gt;supportsConfiguration(configuration))
+        return Failed;
+
+    return Succeeded;
+}
+
+CDMInstance::SuccessValue MockCDMInstance::setDistinctiveIdentifiersAllowed(bool distinctiveIdentifiersAllowed)
+{
+    if (m_distinctiveIdentifiersAllowed == distinctiveIdentifiersAllowed)
+        return Succeeded;
+
+    MockCDMFactory* factory = m_cdm ? m_cdm-&gt;factory() : nullptr;
+
+    if (!factory || (!distinctiveIdentifiersAllowed &amp;&amp; factory-&gt;distinctiveIdentifiersRequirement() == MediaKeysRequirement::Required))
+        return Failed;
+
+    m_distinctiveIdentifiersAllowed = distinctiveIdentifiersAllowed;
+    return Succeeded;
+}
+
+CDMInstance::SuccessValue MockCDMInstance::setPersistentStateAllowed(bool persistentStateAllowed)
+{
+    if (m_persistentStateAllowed == persistentStateAllowed)
+        return Succeeded;
+
+    MockCDMFactory* factory = m_cdm ? m_cdm-&gt;factory() : nullptr;
+
+    if (!factory || (!persistentStateAllowed &amp;&amp; factory-&gt;persistentStateRequirement() == MediaKeysRequirement::Required))
+        return Failed;
+
+    m_persistentStateAllowed = persistentStateAllowed;
+    return Succeeded;
+}
+
+}
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockCDMFactoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockCDMFactory.h (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockCDMFactory.h        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/testing/MockCDMFactory.h        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CDM.h&quot;
</span><ins>+#include &quot;CDMInstance.h&quot;
</ins><span class="cx"> #include &quot;CDMPrivate.h&quot;
</span><span class="cx"> #include &quot;MediaKeysRequirement.h&quot;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="lines">@@ -53,6 +54,9 @@
</span><span class="cx">     MediaKeysRequirement persistentStateRequirement() const { return m_persistentStateRequirement; }
</span><span class="cx">     void setPersistentStateRequirement(MediaKeysRequirement requirement) { m_persistentStateRequirement = requirement; }
</span><span class="cx"> 
</span><ins>+    bool canCreateInstances() const { return m_canCreateInstances; }
+    void setCanCreateInstances(bool flag) { m_canCreateInstances = flag; }
+
</ins><span class="cx">     void unregister();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -65,6 +69,7 @@
</span><span class="cx">     Vector&lt;String&gt; m_supportedDataTypes;
</span><span class="cx">     Vector&lt;String&gt; m_supportedRobustness;
</span><span class="cx">     bool m_registered { true };
</span><ins>+    bool m_canCreateInstances { true };
</ins><span class="cx">     WeakPtrFactory&lt;MockCDMFactory&gt; m_weakPtrFactory;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -72,7 +77,11 @@
</span><span class="cx"> public:
</span><span class="cx">     MockCDM(WeakPtr&lt;MockCDMFactory&gt;);
</span><span class="cx"> 
</span><ins>+    MockCDMFactory* factory() { return m_factory.get(); }
+
</ins><span class="cx"> private:
</span><ins>+    friend class MockCDMInstance;
+
</ins><span class="cx">     bool supportsInitDataType(const String&amp;) final;
</span><span class="cx">     bool supportsConfiguration(const MediaKeySystemConfiguration&amp;) final;
</span><span class="cx">     bool supportsConfigurationWithRestrictions(const MediaKeySystemConfiguration&amp;, const MediaKeysRestrictions&amp;) final;
</span><span class="lines">@@ -81,10 +90,27 @@
</span><span class="cx">     MediaKeysRequirement distinctiveIdentifiersRequirement(const MediaKeySystemConfiguration&amp;, const MediaKeysRestrictions&amp;) final;
</span><span class="cx">     MediaKeysRequirement persistentStateRequirement(const MediaKeySystemConfiguration&amp;, const MediaKeysRestrictions&amp;) final;
</span><span class="cx">     bool distinctiveIdentifiersAreUniquePerOriginAndClearable(const MediaKeySystemConfiguration&amp;) final;
</span><ins>+    std::unique_ptr&lt;CDMInstance&gt; createInstance() final;
+    void loadAndInitialize() final;
</ins><span class="cx"> 
</span><span class="cx">     WeakPtr&lt;MockCDMFactory&gt; m_factory;
</span><ins>+    WeakPtrFactory&lt;MockCDM&gt; m_weakPtrFactory;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><ins>+class MockCDMInstance : public CDMInstance {
+public:
+    MockCDMInstance(WeakPtr&lt;MockCDM&gt;);
+
+private:
+    SuccessValue initializeWithConfiguration(const MediaKeySystemConfiguration&amp;) final;
+    SuccessValue setDistinctiveIdentifiersAllowed(bool) final;
+    SuccessValue setPersistentStateAllowed(bool) final;
+
+    WeakPtr&lt;MockCDM&gt; m_cdm;
+    bool m_distinctiveIdentifiersAllowed { true };
+    bool m_persistentStateAllowed { true };
+};
+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockCDMFactoryidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockCDMFactory.idl (210444 => 210445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockCDMFactory.idl        2017-01-06 17:55:42 UTC (rev 210444)
+++ trunk/Source/WebCore/testing/MockCDMFactory.idl        2017-01-06 18:48:29 UTC (rev 210445)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx">     attribute sequence&lt;DOMString&gt; supportedRobustness;
</span><span class="cx">     attribute MediaKeysRequirement distinctiveIdentifiersRequirement;
</span><span class="cx">     attribute MediaKeysRequirement persistentStateRequirement;
</span><ins>+    attribute boolean canCreateInstances;
</ins><span class="cx"> 
</span><span class="cx">     void unregister();
</span><span class="cx"> };
</span></span></pre>
</div>
</div>

</body>
</html>