<!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>[225813] trunk/Source/WebCore</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/225813">225813</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2017-12-12 15:12:20 -0800 (Tue, 12 Dec 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[EME] Support FPS-over-HLS in the Modern EME API
https://bugs.webkit.org/show_bug.cgi?id=180707

Reviewed by Eric Carlson.

Add support for the "skd" initDataType, where the initData is the URI provided in the
EXT-X-KEY tag in a HLS manifest:

* platform/graphics/avfoundation/CDMFairPlayStreaming.cpp:
(WebCore::CDMPrivateFairPlayStreaming::sinfName):
(WebCore::CDMPrivateFairPlayStreaming::skdName):
(WebCore::extractSinfData):
(WebCore::CDMPrivateFairPlayStreaming::sanitizeSkd):
(WebCore::CDMPrivateFairPlayStreaming::extractKeyIDsSkd):
(WebCore::validInitDataTypes):
(WebCore::CDMFactory::platformRegisterFactories):
(WebCore::CDMPrivateFairPlayStreaming::supportsInitDataType const):
(WebCore::CDMPrivateFairPlayStreaming::supportsConfiguration const):
(WebCore::CDMPrivateFairPlayStreaming::supportsInitData const):
(WebCore::sinfName): Deleted.

Add support for creating a AVContentKeyRequest from a skd key URI rather than from
initialization data, and for extracting keyIDs from the AVContentKeyRequest identifier.

* platform/graphics/avfoundation/CDMFairPlayStreaming.h:
* platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:
* platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::keyIDs):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::requestLicense):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::updateLicense):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest):

Add support for AVContentKeySession to MediaPlayerPrivateAVFoundationObjC, and for emitting
initializationData messages when encountering a loading request for a "skd" URI.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
(WebCore::MediaPlayerPrivateAVFoundationObjC::cdmInstanceAttached):
(WebCore::MediaPlayerPrivateAVFoundationObjC::cdmInstanceDetached):
(WebCore::MediaPlayerPrivateAVFoundationObjC::attemptToDecryptWithInstance):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationCDMFairPlayStreamingcpp">trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationCDMFairPlayStreamingh">trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMInstanceFairPlayStreamingAVFObjCh">trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMInstanceFairPlayStreamingAVFObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCh">trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (225812 => 225813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-12-12 23:12:02 UTC (rev 225812)
+++ trunk/Source/WebCore/ChangeLog      2017-12-12 23:12:20 UTC (rev 225813)
</span><span class="lines">@@ -1,3 +1,47 @@
</span><ins>+2017-12-12  Jer Noble  <jer.noble@apple.com>
+
+        [EME] Support FPS-over-HLS in the Modern EME API
+        https://bugs.webkit.org/show_bug.cgi?id=180707
+
+        Reviewed by Eric Carlson.
+
+        Add support for the "skd" initDataType, where the initData is the URI provided in the 
+        EXT-X-KEY tag in a HLS manifest:
+
+        * platform/graphics/avfoundation/CDMFairPlayStreaming.cpp:
+        (WebCore::CDMPrivateFairPlayStreaming::sinfName):
+        (WebCore::CDMPrivateFairPlayStreaming::skdName):
+        (WebCore::extractSinfData):
+        (WebCore::CDMPrivateFairPlayStreaming::sanitizeSkd):
+        (WebCore::CDMPrivateFairPlayStreaming::extractKeyIDsSkd):
+        (WebCore::validInitDataTypes):
+        (WebCore::CDMFactory::platformRegisterFactories):
+        (WebCore::CDMPrivateFairPlayStreaming::supportsInitDataType const):
+        (WebCore::CDMPrivateFairPlayStreaming::supportsConfiguration const):
+        (WebCore::CDMPrivateFairPlayStreaming::supportsInitData const):
+        (WebCore::sinfName): Deleted.
+
+        Add support for creating a AVContentKeyRequest from a skd key URI rather than from
+        initialization data, and for extracting keyIDs from the AVContentKeyRequest identifier.
+
+        * platform/graphics/avfoundation/CDMFairPlayStreaming.h:
+        * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:
+        * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::keyIDs):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::requestLicense):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::updateLicense):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest):
+
+        Add support for AVContentKeySession to MediaPlayerPrivateAVFoundationObjC, and for emitting
+        initializationData messages when encountering a loading request for a "skd" URI.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::cdmInstanceAttached):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::cdmInstanceDetached):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::attemptToDecryptWithInstance):
+
</ins><span class="cx"> 2017-12-12  Antoine Quint  <graouts@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [Web Animations] Expose promises on Animation interface
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationCDMFairPlayStreamingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp (225812 => 225813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp     2017-12-12 23:12:02 UTC (rev 225812)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp        2017-12-12 23:12:20 UTC (rev 225813)
</span><span class="lines">@@ -62,12 +62,18 @@
</span><span class="cx">     return validSchemes;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static const String& sinfName()
</del><ins>+const AtomicString& CDMPrivateFairPlayStreaming::sinfName()
</ins><span class="cx"> {
</span><del>-    static NeverDestroyed<String> sinf { MAKE_STATIC_STRING_IMPL("sinf") };
</del><ins>+    static NeverDestroyed<AtomicString> sinf { MAKE_STATIC_STRING_IMPL("sinf") };
</ins><span class="cx">     return sinf;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+const AtomicString& CDMPrivateFairPlayStreaming::skdName()
+{
+    static NeverDestroyed<AtomicString> skd { MAKE_STATIC_STRING_IMPL("skd") };
+    return skd;
+}
+
</ins><span class="cx"> static Vector<Ref<SharedBuffer>> extractSinfData(const SharedBuffer& buffer)
</span><span class="cx"> {
</span><span class="cx">     // JSON of the format: "{ sinf: [ <base64-encoded-string> ] }"
</span><span class="lines">@@ -84,7 +90,7 @@
</span><span class="cx">         return { };
</span><span class="cx"> 
</span><span class="cx">     RefPtr<JSON::Array> sinfArray;
</span><del>-    if (!object->getArray(sinfName(), sinfArray))
</del><ins>+    if (!object->getArray(CDMPrivateFairPlayStreaming::sinfName(), sinfArray))
</ins><span class="cx">         return { };
</span><span class="cx"> 
</span><span class="cx">     Vector<Ref<SharedBuffer>> sinfs;
</span><span class="lines">@@ -174,12 +180,34 @@
</span><span class="cx">     return buffer.copy();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr<SharedBuffer> CDMPrivateFairPlayStreaming::sanitizeSkd(const SharedBuffer& buffer)
+{
+    UNUSED_PARAM(buffer);
+    notImplemented();
+    return buffer.copy();
+}
+
+Vector<Ref<SharedBuffer>> CDMPrivateFairPlayStreaming::extractKeyIDsSkd(const SharedBuffer& buffer)
+{
+    // In the 'skd' scheme, the init data is the key ID.
+    Vector<Ref<SharedBuffer>> keyIDs;
+    keyIDs.append(buffer.copy());
+    return keyIDs;
+}
+
+static const HashSet<AtomicString>& validInitDataTypes()
+{
+    static NeverDestroyed<HashSet<AtomicString>> validTypes = HashSet<AtomicString>({ CDMPrivateFairPlayStreaming::sinfName(), CDMPrivateFairPlayStreaming::skdName() });
+    return validTypes;
+}
+
</ins><span class="cx"> void CDMFactory::platformRegisterFactories(Vector<CDMFactory*>& factories)
</span><span class="cx"> {
</span><span class="cx">     factories.append(&CDMFactoryClearKey::singleton());
</span><span class="cx">     factories.append(&CDMFactoryFairPlayStreaming::singleton());
</span><span class="cx"> 
</span><del>-    InitDataRegistry::shared().registerInitDataType(sinfName(), { CDMPrivateFairPlayStreaming::sanitizeSinf, CDMPrivateFairPlayStreaming::extractKeyIDsSinf });
</del><ins>+    InitDataRegistry::shared().registerInitDataType(CDMPrivateFairPlayStreaming::sinfName(), { CDMPrivateFairPlayStreaming::sanitizeSinf, CDMPrivateFairPlayStreaming::extractKeyIDsSinf });
+    InitDataRegistry::shared().registerInitDataType(CDMPrivateFairPlayStreaming::skdName(), { CDMPrivateFairPlayStreaming::sanitizeSkd, CDMPrivateFairPlayStreaming::extractKeyIDsSkd });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CDMFactoryFairPlayStreaming& CDMFactoryFairPlayStreaming::singleton()
</span><span class="lines">@@ -211,12 +239,12 @@
</span><span class="cx"> 
</span><span class="cx"> bool CDMPrivateFairPlayStreaming::supportsInitDataType(const AtomicString& initDataType) const
</span><span class="cx"> {
</span><del>-    return initDataType == sinfName();
</del><ins>+    return validInitDataTypes().contains(initDataType);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool CDMPrivateFairPlayStreaming::supportsConfiguration(const CDMKeySystemConfiguration& configuration) const
</span><span class="cx"> {
</span><del>-    if (!configuration.initDataTypes.contains(sinfName()))
</del><ins>+    if (!WTF::anyOf(configuration.initDataTypes, [] (auto& initDataType) { return validInitDataTypes().contains(initDataType); }))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(AVCONTENTKEYSESSION)
</span><span class="lines">@@ -331,9 +359,17 @@
</span><span class="cx">     if (!supportsInitDataType(initDataType))
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    return WTF::anyOf(extractSchemeAndKeyIdFromSinf(initData), [](auto& result) {
-        return validFairPlayStreamingSchemes().contains(result.first);
-    });
</del><ins>+    if (initDataType == sinfName()) {
+        return WTF::anyOf(extractSchemeAndKeyIdFromSinf(initData), [](auto& result) {
+            return validFairPlayStreamingSchemes().contains(result.first);
+        });
+    }
+
+    if (initDataType == skdName())
+        return true;
+
+    ASSERT_NOT_REACHED();
+    return false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> RefPtr<SharedBuffer> CDMPrivateFairPlayStreaming::sanitizeResponse(const SharedBuffer& response) const
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationCDMFairPlayStreamingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h (225812 => 225813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h       2017-12-12 23:12:02 UTC (rev 225812)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h  2017-12-12 23:12:20 UTC (rev 225813)
</span><span class="lines">@@ -65,8 +65,13 @@
</span><span class="cx">     RefPtr<SharedBuffer> sanitizeResponse(const SharedBuffer&) const override;
</span><span class="cx">     std::optional<String> sanitizeSessionId(const String&) const override;
</span><span class="cx"> 
</span><ins>+    static const AtomicString& sinfName();
</ins><span class="cx">     static Vector<Ref<SharedBuffer>> extractKeyIDsSinf(const SharedBuffer&);
</span><span class="cx">     static RefPtr<SharedBuffer> sanitizeSinf(const SharedBuffer&);
</span><ins>+
+    static const AtomicString& skdName();
+    static Vector<Ref<SharedBuffer>> extractKeyIDsSkd(const SharedBuffer&);
+    static RefPtr<SharedBuffer> sanitizeSkd(const SharedBuffer&);
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMInstanceFairPlayStreamingAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h (225812 => 225813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h   2017-12-12 23:12:02 UTC (rev 225812)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h      2017-12-12 23:12:20 UTC (rev 225813)
</span><span class="lines">@@ -81,6 +81,8 @@
</span><span class="cx">     WeakPtr<CDMInstanceFairPlayStreamingAVFObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(*this); }
</span><span class="cx">     bool isLicenseTypeSupported(LicenseType) const;
</span><span class="cx"> 
</span><ins>+    Vector<Ref<SharedBuffer>> keyIDs();
+
</ins><span class="cx">     WeakPtrFactory<CDMInstanceFairPlayStreamingAVFObjC> m_weakPtrFactory;
</span><span class="cx">     RefPtr<SharedBuffer> m_serverCertificate;
</span><span class="cx">     bool m_persistentStateAllowed { true };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcCDMInstanceFairPlayStreamingAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm (225812 => 225813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm  2017-12-12 23:12:02 UTC (rev 225812)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm     2017-12-12 23:12:20 UTC (rev 225813)
</span><span class="lines">@@ -225,8 +225,21 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CDMInstanceFairPlayStreamingAVFObjC::requestLicense(LicenseType licenseType, const AtomicString&, Ref<SharedBuffer>&& initData, LicenseCallback callback)
</del><ins>+Vector<Ref<SharedBuffer>> CDMInstanceFairPlayStreamingAVFObjC::keyIDs()
</ins><span class="cx"> {
</span><ins>+    // FIXME(rdar://problem/35597141): use the future AVContentKeyRequest keyID property, rather than parsing it out of the init
+    // data, to get the keyID.
+    if ([m_request.get().identifier isKindOfClass:[NSString class]])
+        return Vector<Ref<SharedBuffer>>::from(SharedBuffer::create([(NSString *)m_request.get().identifier dataUsingEncoding:NSUTF8StringEncoding]));
+    if ([m_request.get().identifier isKindOfClass:[NSData class]])
+        return Vector<Ref<SharedBuffer>>::from(SharedBuffer::create((NSData *)m_request.get().identifier));
+    if (m_request.get().initializationData)
+        return CDMPrivateFairPlayStreaming::extractKeyIDsSinf(SharedBuffer::create(m_request.get().initializationData));
+    return { };
+}
+
+void CDMInstanceFairPlayStreamingAVFObjC::requestLicense(LicenseType licenseType, const AtomicString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback callback)
+{
</ins><span class="cx">     if (!isLicenseTypeSupported(licenseType)) {
</span><span class="cx">         callback(SharedBuffer::create(), emptyString(), false, Failed);
</span><span class="cx">         return;
</span><span class="lines">@@ -237,9 +250,20 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    RetainPtr<NSString> identifier;
+    RetainPtr<NSData> initializationData;
+
+    if (initDataType == CDMPrivateFairPlayStreaming::sinfName())
+        initializationData = initData->createNSData();
+    else if (initDataType == CDMPrivateFairPlayStreaming::skdName())
+        identifier = adoptNS([[NSString alloc] initWithData:initData->createNSData().get() encoding:NSUTF8StringEncoding]);
+    else {
+        callback(SharedBuffer::create(), emptyString(), false, Failed);
+        return;
+    }
+
</ins><span class="cx">     m_requestLicenseCallback = WTFMove(callback);
</span><del>-
-    [m_session processContentKeyRequestWithIdentifier:nil initializationData:initData->createNSData().get() options:nil];
</del><ins>+    [m_session processContentKeyRequestWithIdentifier:identifier.get() initializationData:initializationData.get() options:nil];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool isEqual(const SharedBuffer& data, const String& value)
</span><span class="lines">@@ -276,9 +300,7 @@
</span><span class="cx">         callback(false, std::nullopt, std::nullopt, std::nullopt, Failed);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><del>-    // FIXME(rdar://problem/35597141): use the future AVContentKeyRequest keyID property, rather than parsing it out of the init
-    // data, to get the keyID.
-    Vector<Ref<SharedBuffer>> keyIDs = CDMPrivateFairPlayStreaming::extractKeyIDsSinf(SharedBuffer::create(m_request.get().initializationData));
</del><ins>+    Vector<Ref<SharedBuffer>> keyIDs = this->keyIDs();
</ins><span class="cx">     if (keyIDs.isEmpty()) {
</span><span class="cx">         callback(false, std::nullopt, std::nullopt, std::nullopt, Failed);
</span><span class="cx">         return;
</span><span class="lines">@@ -400,7 +422,8 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     RetainPtr<NSData> appIdentifier = m_serverCertificate ? m_serverCertificate->createNSData() : nullptr;
</span><del>-    Vector<Ref<SharedBuffer>> keyIDs = CDMPrivateFairPlayStreaming::extractKeyIDsSinf(SharedBuffer::create(request.initializationData));
</del><ins>+    Vector<Ref<SharedBuffer>> keyIDs = this->keyIDs();
+
</ins><span class="cx">     if (keyIDs.isEmpty()) {
</span><span class="cx">         m_requestLicenseCallback(SharedBuffer::create(), m_sessionId, false, Failed);
</span><span class="cx">         m_requestLicenseCallback = nullptr;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (225812 => 225813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h    2017-12-12 23:12:02 UTC (rev 225812)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h       2017-12-12 23:12:20 UTC (rev 225813)
</span><span class="lines">@@ -63,6 +63,7 @@
</span><span class="cx"> 
</span><span class="cx"> class AudioSourceProviderAVFObjC;
</span><span class="cx"> class AudioTrackPrivateAVFObjC;
</span><ins>+class CDMInstanceFairPlayStreamingAVFObjC;
</ins><span class="cx"> class CDMSessionAVFoundationObjC;
</span><span class="cx"> class InbandMetadataTextTrackPrivateAVF;
</span><span class="cx"> class InbandTextTrackPrivateAVFObjC;
</span><span class="lines">@@ -153,6 +154,12 @@
</span><span class="cx">     void removeSession(LegacyCDMSession&);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(ENCRYPTED_MEDIA)
+    void cdmInstanceAttached(CDMInstance&) final;
+    void cdmInstanceDetached(CDMInstance&) final;
+    void attemptToDecryptWithInstance(CDMInstance&) final;
+#endif
+
</ins><span class="cx">     WeakPtr<MediaPlayerPrivateAVFoundationObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(*this); }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -397,6 +404,9 @@
</span><span class="cx"> #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
</span><span class="cx">     WeakPtr<CDMSessionAVFoundationObjC> m_session;
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
+    RefPtr<CDMInstanceFairPlayStreamingAVFObjC> m_cdmInstance;
+#endif
</ins><span class="cx"> 
</span><span class="cx">     mutable RetainPtr<NSArray> m_cachedSeekableRanges;
</span><span class="cx">     mutable RetainPtr<NSArray> m_cachedLoadedRanges;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (225812 => 225813)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm   2017-12-12 23:12:02 UTC (rev 225812)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm      2017-12-12 23:12:20 UTC (rev 225813)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #import "AudioSourceProviderAVFObjC.h"
</span><span class="cx"> #import "AudioTrackPrivateAVFObjC.h"
</span><span class="cx"> #import "AuthenticationChallenge.h"
</span><ins>+#import "CDMInstanceFairPlayStreamingAVFObjC.h"
</ins><span class="cx"> #import "CDMSessionAVFoundationObjC.h"
</span><span class="cx"> #import "Cookie.h"
</span><span class="cx"> #import "DeprecatedGlobalSettings.h"
</span><span class="lines">@@ -54,6 +55,7 @@
</span><span class="cx"> #import "PlatformTimeRanges.h"
</span><span class="cx"> #import "SecurityOrigin.h"
</span><span class="cx"> #import "SerializedPlatformRepresentationMac.h"
</span><ins>+#import "SharedBuffer.h"
</ins><span class="cx"> #import "TextEncoding.h"
</span><span class="cx"> #import "TextTrackRepresentation.h"
</span><span class="cx"> #import "TextureCacheCV.h"
</span><span class="lines">@@ -1766,8 +1768,9 @@
</span><span class="cx">     String scheme = [[[avRequest request] URL] scheme];
</span><span class="cx">     String keyURI = [[[avRequest request] URL] absoluteString];
</span><span class="cx"> 
</span><ins>+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA)
+    if (scheme == "skd") {
</ins><span class="cx"> #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
</span><del>-    if (scheme == "skd") {
</del><span class="cx">         // Create an initData with the following layout:
</span><span class="cx">         // [4 bytes: keyURI size], [keyURI size bytes: keyURI]
</span><span class="cx">         unsigned keyURISize = keyURI.length() * sizeof(UChar);
</span><span class="lines">@@ -1782,11 +1785,20 @@
</span><span class="cx">         RefPtr<Uint8Array> initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
</span><span class="cx">         if (!player()->keyNeeded(initData.get()))
</span><span class="cx">             return false;
</span><ins>+#endif
+        m_keyURIToRequestMap.set(keyURI, avRequest);
+#if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
+        if (m_cdmInstance)
+            return false;
</ins><span class="cx"> 
</span><del>-        m_keyURIToRequestMap.set(keyURI, avRequest);
</del><ins>+        RetainPtr<NSData> keyURIData = [keyURI dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
+        auto keyURIBuffer = SharedBuffer::create(keyURIData.get());
+        player()->initializationDataEncountered(ASCIILiteral("skd"), keyURIBuffer->tryCreateArrayBuffer());
+#endif
</ins><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
</ins><span class="cx">     if (scheme == "clearkey") {
</span><span class="cx">         String keyID = [[[avRequest request] URL] resourceSpecifier];
</span><span class="cx">         auto encodedKeyId = UTF8Encoding().encode(keyID, UnencodableHandling::URLEncodedEntities);
</span><span class="lines">@@ -1807,6 +1819,7 @@
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">     RefPtr<WebCoreAVFResourceLoader> resourceLoader = WebCoreAVFResourceLoader::create(this, avRequest);
</span><span class="cx">     m_resourceLoaderMap.add(avRequest, resourceLoader);
</span><span class="lines">@@ -2477,6 +2490,46 @@
</span><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(ENCRYPTED_MEDIA)
+void MediaPlayerPrivateAVFoundationObjC::cdmInstanceAttached(CDMInstance& instance)
+{
+#if HAVE(AVCONTENTKEYSESSION)
+    if (!is<CDMInstanceFairPlayStreamingAVFObjC>(instance))
+        return;
+
+    auto& fpsInstance = downcast<CDMInstanceFairPlayStreamingAVFObjC>(instance);
+    if (&fpsInstance == m_cdmInstance)
+        return;
+
+    if (m_cdmInstance)
+        cdmInstanceDetached(*m_cdmInstance);
+
+    m_cdmInstance = &fpsInstance;
+    [m_cdmInstance->contentKeySession() addContentKeyRecipient:m_avAsset.get()];
+#else
+    UNUSED_PARAM(instance);
+#endif
+}
+
+void MediaPlayerPrivateAVFoundationObjC::cdmInstanceDetached(CDMInstance& instance)
+{
+#if HAVE(AVCONTENTKEYSESSION)
+    ASSERT_UNUSED(instance, m_cdmInstance && m_cdmInstance == &instance);
+    [m_cdmInstance->contentKeySession() removeContentKeyRecipient:m_avAsset.get()];
+    m_cdmInstance = nullptr;
+#else
+    UNUSED_PARAM(instance);
+#endif
+}
+
+void MediaPlayerPrivateAVFoundationObjC::attemptToDecryptWithInstance(CDMInstance&)
+{
+    auto keyURIToRequestMap = WTFMove(m_keyURIToRequestMap);
+    for (auto& request : keyURIToRequestMap.values())
+        [request finishLoading];
+}
+#endif
+
</ins><span class="cx"> #if !HAVE(AVFOUNDATION_LEGIBLE_OUTPUT_SUPPORT)
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateAVFoundationObjC::processLegacyClosedCaptionsTracks()
</span></span></pre>
</div>
</div>

</body>
</html>