[GPUP] Implement Modern EME API in the GPU Process
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Feb 2020 23:20:03 +0000 (23:20 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Feb 2020 23:20:03 +0000 (23:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208090

Reviewed by Eric Carlson.

Source/WebCore:

To enable caching of certain CDM properties, allow them to be fetched rather than queries. As such,
CDMPrivate::supportsInitDataType -> supportedInitDataTypes, supportsRobustness -> supportedRobustnesses.

To enable CDM types to be passed across XPC, add explicit sizes to the enumerations, and add encode and
decode templates to the data types.

To enable async messaging form the GPU process's MediaPlayer, send the MediaPlayer the information it
needs when both legacy- and modern-EME APIs are both enabled, rather than allow the MediaPlayerPrivate
to query the MediaPlayer.

Move most of the algorithimic implementation from CDM into CDMPrivate, allowing it to be run from within
the GPU process. Similmarly, make most of the synchronous methods in CDMInstance instead take a callback
parameter, allowing them to be implemented in a remote process.

* Headers.cmake:
* Modules/encryptedmedia/CDM.cpp:
(WebCore::CDM::getSupportedConfiguration):
(WebCore::CDM::supportsInitDataType const):
* Modules/encryptedmedia/CDM.h:
* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::update):
* Modules/encryptedmedia/MediaKeySystemAccess.cpp:
(WebCore::MediaKeySystemAccess::createMediaKeys):
* Modules/encryptedmedia/MediaKeys.cpp:
(WebCore::MediaKeys::setServerCertificate):
* Modules/encryptedmedia/MediaKeys.h:
* Modules/encryptedmedia/MediaKeys.idl:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::updateShouldContinueAfterNeedKey):
(WebCore::HTMLMediaElement::mediaPlayerKeyNeeded):
(WebCore::HTMLMediaElement::mediaEngineWasUpdated):
(WebCore::HTMLMediaElement::addEventListener):
(WebCore::HTMLMediaElement::removeEventListener):
* html/HTMLMediaElement.h:
* platform/encryptedmedia/CDMEncryptionScheme.h:
* platform/encryptedmedia/CDMFactory.cpp:
(WebCore::CDMFactory::resetFactories):
* platform/encryptedmedia/CDMFactory.h:
* platform/encryptedmedia/CDMInstance.h:
* platform/encryptedmedia/CDMInstanceSession.h:
* platform/encryptedmedia/CDMKeyStatus.h:
* platform/encryptedmedia/CDMKeySystemConfiguration.h:
(WebCore::CDMKeySystemConfiguration::encode const):
(WebCore::CDMKeySystemConfiguration::decode):
* platform/encryptedmedia/CDMMediaCapability.h:
(WebCore::CDMMediaCapability::encode const):
(WebCore::CDMMediaCapability::decode):
* platform/encryptedmedia/CDMMessageType.h:
* platform/encryptedmedia/CDMPrivate.cpp:
(WebCore::CDMPrivate::getSupportedConfiguration):
(WebCore::CDMPrivate::doSupportedConfigurationStep):
(WebCore::CDMPrivate::isPersistentType):
(WebCore::CDMPrivate::getSupportedCapabilitiesForAudioVideoType):
(WebCore::CDMPrivate::getConsentStatus):
* platform/encryptedmedia/CDMPrivate.h:
* platform/encryptedmedia/CDMRequirement.h:
* platform/encryptedmedia/CDMRestrictions.h:
(WebCore::CDMRestrictions::encode const):
(WebCore::CDMRestrictions::decode):
* platform/encryptedmedia/CDMSessionType.h:
* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::CDMPrivateClearKey::supportedInitDataTypes const):
(WebCore::CDMPrivateClearKey::supportsSessionTypeWithConfiguration const):
(WebCore::CDMPrivateClearKey::supportedRobustnesses const):
(WebCore::CDMInstanceClearKey::initializeWithConfiguration):
(WebCore::CDMInstanceClearKey::setServerCertificate):
(WebCore::CDMInstanceClearKey::setStorageDirectory):
(WebCore::CDMInstanceSessionClearKey::updateLicense):
* platform/encryptedmedia/clearkey/CDMClearKey.h:
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::setShouldContinueAfterKeyNeeded):
(WebCore::MediaPlayer::keyNeeded):
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaPlayerKeyNeeded):
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::setShouldContinueAfterKeyNeeded):
* platform/graphics/avfoundation/CDMFairPlayStreaming.cpp:
(WebCore::CDMPrivateFairPlayStreaming::supportedInitDataTypes const):
(WebCore::CDMPrivateFairPlayStreaming::supportsSessionTypeWithConfiguration const):
(WebCore::CDMPrivateFairPlayStreaming::supportedRobustnesses const):
(WebCore::CDMPrivateFairPlayStreaming::supportsInitData const):
* platform/graphics/avfoundation/CDMFairPlayStreaming.h:
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::AVFWrapper::shouldWaitForLoadingOfResource):
* platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:
* platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::initializeWithConfiguration):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::setServerCertificate):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::setStorageDirectory):
(WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense):
(WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::sessionIdentifierChanged):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
* testing/MockCDMFactory.cpp:
(WebCore::MockCDMFactory::setSupportedRobustness):
(WebCore::MockCDM::supportedInitDataTypes const):
(WebCore::MockCDM::supportedRobustnesses const):
(WebCore::MockCDM::supportsSessionTypeWithConfiguration const):
(WebCore::MockCDM::supportsInitData const):
(WebCore::MockCDMInstance::initializeWithConfiguration):
(WebCore::MockCDMInstance::setServerCertificate):
(WebCore::MockCDMInstance::setStorageDirectory):
(WebCore::MockCDMInstanceSession::updateLicense):
* testing/MockCDMFactory.h:
(WebCore::MockCDMFactory::supportedRobustness const):

Source/WebKit:

Adopt changes to MediaPlayerProxy.

* GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::mediaPlayerKeyNeeded):
* GPUProcess/media/RemoteMediaPlayerProxy.h:
* WebProcess/GPU/media/WebMediaStrategy.cpp:
(WebKit::WebMediaStrategy::registerCDMFactories):
* WebProcess/GPU/media/WebMediaStrategy.h:

Source/WebKitLegacy/mac:

Adopt changes to PlatformStrategies.

* GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::mediaPlayerKeyNeeded):
* GPUProcess/media/RemoteMediaPlayerProxy.h:
* WebCoreSupport/WebPlatformStrategies.mm:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257660 268f45cc-cd09-0410-ab3c-d52691b4dbfc

48 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Headers.cmake
Source/WebCore/Modules/encryptedmedia/CDM.cpp
Source/WebCore/Modules/encryptedmedia/CDM.h
Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeySystemAccess.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeys.h
Source/WebCore/Modules/encryptedmedia/MediaKeys.idl
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/MediaStrategy.h
Source/WebCore/platform/encryptedmedia/CDMEncryptionScheme.h
Source/WebCore/platform/encryptedmedia/CDMFactory.cpp
Source/WebCore/platform/encryptedmedia/CDMFactory.h
Source/WebCore/platform/encryptedmedia/CDMInstance.h
Source/WebCore/platform/encryptedmedia/CDMInstanceSession.h
Source/WebCore/platform/encryptedmedia/CDMKeyStatus.h
Source/WebCore/platform/encryptedmedia/CDMKeySystemConfiguration.h
Source/WebCore/platform/encryptedmedia/CDMMediaCapability.h
Source/WebCore/platform/encryptedmedia/CDMMessageType.h
Source/WebCore/platform/encryptedmedia/CDMPrivate.cpp [new file with mode: 0644]
Source/WebCore/platform/encryptedmedia/CDMPrivate.h
Source/WebCore/platform/encryptedmedia/CDMRequirement.h
Source/WebCore/platform/encryptedmedia/CDMRestrictions.h
Source/WebCore/platform/encryptedmedia/CDMSessionType.h
Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp
Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp
Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.h
Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp
Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/testing/MockCDMFactory.cpp
Source/WebCore/testing/MockCDMFactory.h
Source/WebKit/ChangeLog
Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp
Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h
Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.cpp
Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm

index fb39504..709cc9c 100644 (file)
@@ -1,3 +1,118 @@
+2020-02-28  Jer Noble  <jer.noble@apple.com>
+
+        [GPUP] Implement Modern EME API in the GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=208090
+
+        Reviewed by Eric Carlson.
+
+        To enable caching of certain CDM properties, allow them to be fetched rather than queries. As such,
+        CDMPrivate::supportsInitDataType -> supportedInitDataTypes, supportsRobustness -> supportedRobustnesses.
+
+        To enable CDM types to be passed across XPC, add explicit sizes to the enumerations, and add encode and
+        decode templates to the data types.
+
+        To enable async messaging form the GPU process's MediaPlayer, send the MediaPlayer the information it
+        needs when both legacy- and modern-EME APIs are both enabled, rather than allow the MediaPlayerPrivate
+        to query the MediaPlayer.
+
+        Move most of the algorithimic implementation from CDM into CDMPrivate, allowing it to be run from within
+        the GPU process. Similmarly, make most of the synchronous methods in CDMInstance instead take a callback
+        parameter, allowing them to be implemented in a remote process.
+
+        * Headers.cmake:
+        * Modules/encryptedmedia/CDM.cpp:
+        (WebCore::CDM::getSupportedConfiguration):
+        (WebCore::CDM::supportsInitDataType const):
+        * Modules/encryptedmedia/CDM.h:
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        (WebCore::MediaKeySession::update):
+        * Modules/encryptedmedia/MediaKeySystemAccess.cpp:
+        (WebCore::MediaKeySystemAccess::createMediaKeys):
+        * Modules/encryptedmedia/MediaKeys.cpp:
+        (WebCore::MediaKeys::setServerCertificate):
+        * Modules/encryptedmedia/MediaKeys.h:
+        * Modules/encryptedmedia/MediaKeys.idl:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::updateShouldContinueAfterNeedKey):
+        (WebCore::HTMLMediaElement::mediaPlayerKeyNeeded):
+        (WebCore::HTMLMediaElement::mediaEngineWasUpdated):
+        (WebCore::HTMLMediaElement::addEventListener):
+        (WebCore::HTMLMediaElement::removeEventListener):
+        * html/HTMLMediaElement.h:
+        * platform/encryptedmedia/CDMEncryptionScheme.h:
+        * platform/encryptedmedia/CDMFactory.cpp:
+        (WebCore::CDMFactory::resetFactories):
+        * platform/encryptedmedia/CDMFactory.h:
+        * platform/encryptedmedia/CDMInstance.h:
+        * platform/encryptedmedia/CDMInstanceSession.h:
+        * platform/encryptedmedia/CDMKeyStatus.h:
+        * platform/encryptedmedia/CDMKeySystemConfiguration.h:
+        (WebCore::CDMKeySystemConfiguration::encode const):
+        (WebCore::CDMKeySystemConfiguration::decode):
+        * platform/encryptedmedia/CDMMediaCapability.h:
+        (WebCore::CDMMediaCapability::encode const):
+        (WebCore::CDMMediaCapability::decode):
+        * platform/encryptedmedia/CDMMessageType.h:
+        * platform/encryptedmedia/CDMPrivate.cpp:
+        (WebCore::CDMPrivate::getSupportedConfiguration):
+        (WebCore::CDMPrivate::doSupportedConfigurationStep):
+        (WebCore::CDMPrivate::isPersistentType):
+        (WebCore::CDMPrivate::getSupportedCapabilitiesForAudioVideoType):
+        (WebCore::CDMPrivate::getConsentStatus):
+        * platform/encryptedmedia/CDMPrivate.h:
+        * platform/encryptedmedia/CDMRequirement.h:
+        * platform/encryptedmedia/CDMRestrictions.h:
+        (WebCore::CDMRestrictions::encode const):
+        (WebCore::CDMRestrictions::decode):
+        * platform/encryptedmedia/CDMSessionType.h:
+        * platform/encryptedmedia/clearkey/CDMClearKey.cpp:
+        (WebCore::CDMPrivateClearKey::supportedInitDataTypes const):
+        (WebCore::CDMPrivateClearKey::supportsSessionTypeWithConfiguration const):
+        (WebCore::CDMPrivateClearKey::supportedRobustnesses const):
+        (WebCore::CDMInstanceClearKey::initializeWithConfiguration):
+        (WebCore::CDMInstanceClearKey::setServerCertificate):
+        (WebCore::CDMInstanceClearKey::setStorageDirectory):
+        (WebCore::CDMInstanceSessionClearKey::updateLicense):
+        * platform/encryptedmedia/clearkey/CDMClearKey.h:
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::setShouldContinueAfterKeyNeeded):
+        (WebCore::MediaPlayer::keyNeeded):
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayerClient::mediaPlayerKeyNeeded):
+        * platform/graphics/MediaPlayerPrivate.h:
+        (WebCore::MediaPlayerPrivateInterface::setShouldContinueAfterKeyNeeded):
+        * platform/graphics/avfoundation/CDMFairPlayStreaming.cpp:
+        (WebCore::CDMPrivateFairPlayStreaming::supportedInitDataTypes const):
+        (WebCore::CDMPrivateFairPlayStreaming::supportsSessionTypeWithConfiguration const):
+        (WebCore::CDMPrivateFairPlayStreaming::supportedRobustnesses const):
+        (WebCore::CDMPrivateFairPlayStreaming::supportsInitData const):
+        * platform/graphics/avfoundation/CDMFairPlayStreaming.h:
+        * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
+        (WebCore::AVFWrapper::shouldWaitForLoadingOfResource):
+        * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:
+        * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::initializeWithConfiguration):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::setServerCertificate):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::setStorageDirectory):
+        (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense):
+        (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::sessionIdentifierChanged):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
+        * testing/MockCDMFactory.cpp:
+        (WebCore::MockCDMFactory::setSupportedRobustness):
+        (WebCore::MockCDM::supportedInitDataTypes const):
+        (WebCore::MockCDM::supportedRobustnesses const):
+        (WebCore::MockCDM::supportsSessionTypeWithConfiguration const):
+        (WebCore::MockCDM::supportsInitData const):
+        (WebCore::MockCDMInstance::initializeWithConfiguration):
+        (WebCore::MockCDMInstance::setServerCertificate):
+        (WebCore::MockCDMInstance::setStorageDirectory):
+        (WebCore::MockCDMInstanceSession::updateLicense):
+        * testing/MockCDMFactory.h:
+        (WebCore::MockCDMFactory::supportedRobustness const):
+
 2020-02-28  Chris Dumez  <cdumez@apple.com> and Yusuke Suzuki  <ysuzuki@apple.com>
 
         Clear FontDatabase when low-memory-warning happens
index 9f1bb0c..dbaa1d7 100644 (file)
@@ -1035,6 +1035,20 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
     platform/audio/PlatformMediaSession.h
     platform/audio/PlatformMediaSessionManager.h
 
+    platform/encryptedmedia/CDMEncryptionScheme.h
+    platform/encryptedmedia/CDMFactory.h
+    platform/encryptedmedia/CDMInstance.h
+    platform/encryptedmedia/CDMInstanceSession.h
+    platform/encryptedmedia/CDMKeyStatus.h
+    platform/encryptedmedia/CDMKeySystemConfiguration.h
+    platform/encryptedmedia/CDMMediaCapability.h
+    platform/encryptedmedia/CDMMessageType.h
+    platform/encryptedmedia/CDMPrivate.h
+    platform/encryptedmedia/CDMProxy.h
+    platform/encryptedmedia/CDMRequirement.h
+    platform/encryptedmedia/CDMRestrictions.h
+    platform/encryptedmedia/CDMSessionType.h
+
     platform/gamepad/GamepadProvider.h
     platform/gamepad/GamepadProviderClient.h
     platform/gamepad/PlatformGamepad.h
index 4bbb2bc..c55be06 100644 (file)
@@ -79,510 +79,18 @@ void CDM::getSupportedConfiguration(MediaKeySystemConfiguration&& candidateConfi
 {
     // https://w3c.github.io/encrypted-media/#get-supported-configuration
     // W3C Editor's Draft 09 November 2016
+    // Implemented in CDMPrivate::getSupportedConfiguration()
 
-    // 3.1.1.1 Get Supported Configuration
-    // Given a Key Systems implementation implementation, MediaKeySystemConfiguration candidate configuration, and origin,
-    // this algorithm returns a supported configuration or NotSupported as appropriate.
-
-    // 1. Let supported configuration be ConsentDenied.
-    // 2. Initialize restrictions to indicate that no configurations have had user consent denied.
-    MediaKeysRestrictions restrictions { };
-    doSupportedConfigurationStep(WTFMove(candidateConfiguration), WTFMove(restrictions), WTFMove(callback));
-}
-
-void CDM::doSupportedConfigurationStep(MediaKeySystemConfiguration&& candidateConfiguration, MediaKeysRestrictions&& restrictions, SupportedConfigurationCallback&& callback)
-{
-    // https://w3c.github.io/encrypted-media/#get-supported-configuration
-    // W3C Editor's Draft 09 November 2016, ctd.
-
-    // 3.1.1.1 Get Supported Configuration
-    // 3. Repeat the following step while supported configuration is ConsentDenied:
-    // 3.1. Let supported configuration and, if provided, restrictions be the result of executing the
-    // Get Supported Configuration and Consent algorithm with implementation, candidate configuration,
-    // restrictions and origin.
-    auto optionalConfiguration = getSupportedConfiguration(candidateConfiguration, restrictions);
-    if (!optionalConfiguration) {
+    Document* document = downcast<Document>(m_scriptExecutionContext);
+    if (!document || !m_private) {
         callback(WTF::nullopt);
         return;
     }
 
-    auto consentCallback = [weakThis = makeWeakPtr(*this), callback = WTFMove(callback)] (ConsentStatus status, MediaKeySystemConfiguration&& configuration, MediaKeysRestrictions&& restrictions) mutable {
-        if (!weakThis) {
-            callback(WTF::nullopt);
-            return;
-        }
-        // 3.1.1.2 Get Supported Configuration and Consent, ctd.
-        // 22. Let consent status and updated restrictions be the result of running the Get Consent Status algorithm on accumulated configuration,
-        //     restrictions and origin and follow the steps for the value of consent status from the following list:
-        switch (status) {
-        case ConsentStatus::ConsentDenied:
-            // ↳ ConsentDenied:
-            //    Return ConsentDenied and updated restrictions.
-            weakThis->doSupportedConfigurationStep(WTFMove(configuration), WTFMove(restrictions), WTFMove(callback));
-            return;
-
-        case ConsentStatus::InformUser:
-            // ↳ InformUser
-            //    Inform the user that accumulated configuration is in use in the origin including, specifically, the information that
-            //    Distinctive Identifier(s) and/or Distinctive Permanent Identifier(s) as appropriate will be used if the
-            //    distinctiveIdentifier member of accumulated configuration is "required". Continue to the next step.
-            // NOTE: Implement.
-            break;
-
-        case ConsentStatus::Allowed:
-            // ↳ Allowed:
-            // Continue to the next step.
-            break;
-        }
-        // 23. Return accumulated configuration.
-        callback(WTFMove(configuration));
-    };
-    getConsentStatus(WTFMove(optionalConfiguration.value()), WTFMove(restrictions), WTFMove(consentCallback));
-}
-
-bool CDM::isPersistentType(MediaKeySessionType sessionType)
-{
-    // https://w3c.github.io/encrypted-media/#is-persistent-session-type
-    // W3C Editor's Draft 09 November 2016
-
-    // 5.1.1. Is persistent session type?
-    // 1. Let the session type be the specified MediaKeySessionType value.
-    // 2. Follow the steps for the value of session type from the following list:
-    switch (sessionType) {
-    case MediaKeySessionType::Temporary:
-        // ↳ "temporary"
-        return false;
-    case MediaKeySessionType::PersistentLicense:
-    case MediaKeySessionType::PersistentUsageRecord:
-        // ↳ "persistent-license"
-        return true;
-    }
-
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-Optional<MediaKeySystemConfiguration> CDM::getSupportedConfiguration(const MediaKeySystemConfiguration& candidateConfiguration, MediaKeysRestrictions& restrictions)
-{
-    // https://w3c.github.io/encrypted-media/#get-supported-configuration-and-consent
-    // W3C Editor's Draft 09 November 2016
-
-    ASSERT(m_private);
-    if (!m_private)
-        return WTF::nullopt;
-
-    // 3.1.1.2 Get Supported Configuration and Consent
-    // Given a Key Systems implementation implementation, MediaKeySystemConfiguration candidate configuration,
-    // restrictions and origin, this algorithm returns a supported configuration, NotSupported, or ConsentDenied
-    // as appropriate and, in the ConsentDenied case, restrictions.
-
-    // 1. Let accumulated configuration be a new MediaKeySystemConfiguration dictionary.
-    MediaKeySystemConfiguration accumulatedConfiguration { };
-
-    // 2. Set the label member of accumulated configuration to equal the label member of candidate configuration.
-    accumulatedConfiguration.label = candidateConfiguration.label;
-
-    // 3. If the initDataTypes member of candidate configuration is non-empty, run the following steps:
-    if (!candidateConfiguration.initDataTypes.isEmpty()) {
-        // 3.1. Let supported types be an empty sequence of DOMStrings.
-        Vector<String> supportedTypes;
-
-        // 3.2. For each value in candidate configuration's initDataTypes member:
-        for (auto initDataType : candidateConfiguration.initDataTypes) {
-            // 3.2.1. Let initDataType be the value.
-            // 3.2.2. If the implementation supports generating requests based on initDataType, add initDataType
-            //        to supported types. String comparison is case-sensitive. The empty string is never supported.
-            if (initDataType.isEmpty())
-                continue;
-
-            if (m_private && m_private->supportsInitDataType(initDataType))
-                supportedTypes.append(initDataType);
-        }
-
-        // 3.3. If supported types is empty, return NotSupported.
-        if (supportedTypes.isEmpty())
-            return WTF::nullopt;
-
-        // 3.4. Set the initDataTypes member of accumulated configuration to supported types.
-        accumulatedConfiguration.initDataTypes = WTFMove(supportedTypes);
-    }
-
-    // 4. Let distinctive identifier requirement be the value of candidate configuration's distinctiveIdentifier member.
-    MediaKeysRequirement distinctiveIdentifierRequirement = candidateConfiguration.distinctiveIdentifier;
-
-    // 5. If distinctive identifier requirement is "optional" and Distinctive Identifiers are not allowed according to
-    //    restrictions, set distinctive identifier requirement to "not-allowed".
-    if (distinctiveIdentifierRequirement == MediaKeysRequirement::Optional && restrictions.distinctiveIdentifierDenied)
-        distinctiveIdentifierRequirement = MediaKeysRequirement::NotAllowed;
-
-    // 6. Follow the steps for distinctive identifier requirement from the following list:
-    switch (distinctiveIdentifierRequirement) {
-    case MediaKeysRequirement::Required:
-        // ↳ "required"
-        // If the implementation does not support use of Distinctive Identifier(s) in combination
-        // with accumulated configuration and restrictions, return NotSupported.
-        if (m_private->distinctiveIdentifiersRequirement(accumulatedConfiguration, restrictions) == MediaKeysRequirement::NotAllowed)
-            return WTF::nullopt;
-        break;
-
-    case MediaKeysRequirement::Optional:
-        // ↳ "optional"
-        // Continue with the following steps.
-        break;
-
-    case MediaKeysRequirement::NotAllowed:
-        // ↳ "not-allowed"
-        // If the implementation requires use Distinctive Identifier(s) or Distinctive Permanent Identifier(s)
-        // in combination with accumulated configuration and restrictions, return NotSupported.
-        if (m_private->distinctiveIdentifiersRequirement(accumulatedConfiguration, restrictions) == MediaKeysRequirement::Required)
-            return WTF::nullopt;
-        break;
-    }
-
-    // 7. Set the distinctiveIdentifier member of accumulated configuration to equal distinctive identifier requirement.
-    accumulatedConfiguration.distinctiveIdentifier = distinctiveIdentifierRequirement;
-
-    // 8. Let persistent state requirement be equal to the value of candidate configuration's persistentState member.
-    MediaKeysRequirement persistentStateRequirement = candidateConfiguration.persistentState;
-
-    // 9. If persistent state requirement is "optional" and persisting state is not allowed according to restrictions,
-    //    set persistent state requirement to "not-allowed".
-    if (persistentStateRequirement == MediaKeysRequirement::Optional && restrictions.persistentStateDenied)
-        persistentStateRequirement =  MediaKeysRequirement::NotAllowed;
-
-    // 10. Follow the steps for persistent state requirement from the following list:
-    switch (persistentStateRequirement) {
-    case MediaKeysRequirement::Required:
-        // ↳ "required"
-        // If the implementation does not support persisting state in combination with accumulated configuration
-        // and restrictions, return NotSupported.
-        if (m_private->persistentStateRequirement(accumulatedConfiguration, restrictions) == MediaKeysRequirement::NotAllowed)
-            return WTF::nullopt;
-        break;
-
-    case MediaKeysRequirement::Optional:
-        // ↳ "optional"
-        // Continue with the following steps.
-        break;
-
-    case MediaKeysRequirement::NotAllowed:
-        // ↳ "not-allowed"
-        // If the implementation requires persisting state in combination with accumulated configuration
-        // and restrictions, return NotSupported
-        if (m_private->persistentStateRequirement(accumulatedConfiguration, restrictions) == MediaKeysRequirement::Required)
-            return WTF::nullopt;
-        break;
-    }
-
-    // 11. Set the persistentState member of accumulated configuration to equal the value of persistent state requirement.
-    accumulatedConfiguration.persistentState = persistentStateRequirement;
-
-    // 12. Follow the steps for the first matching condition from the following list:
-    Vector<MediaKeySessionType> sessionTypes;
-
-    if (!candidateConfiguration.sessionTypes.isEmpty()) {
-        // ↳ If the sessionTypes member is present [WebIDL] in candidate configuration
-        // Let session types be candidate configuration's sessionTypes member.
-        sessionTypes = candidateConfiguration.sessionTypes;
-    } else {
-        // ↳ Otherwise
-        // Let session types be [ "temporary" ].
-        sessionTypes = { MediaKeySessionType::Temporary };
-    }
-
-    // 13. For each value in session types:
-    for (auto& sessionType : sessionTypes) {
-        // 13.1. Let session type be the value.
-        // 13.2. If accumulated configuration's persistentState value is "not-allowed" and the
-        //       Is persistent session type? algorithm returns true for session type return NotSupported.
-        if (accumulatedConfiguration.persistentState == MediaKeysRequirement::NotAllowed && isPersistentType(sessionType))
-            return WTF::nullopt;
-
-        // 13.3. If the implementation does not support session type in combination with accumulated configuration
-        //       and restrictions for other reasons, return NotSupported.
-        if (!m_private->supportsSessionTypeWithConfiguration(sessionType, accumulatedConfiguration))
-            return WTF::nullopt;
-
-        // 13.4 If accumulated configuration's persistentState value is "optional" and the result of running the Is
-        //      persistent session type? algorithm on session type is true, change accumulated configuration's persistentState
-        //      value to "required".
-        if (accumulatedConfiguration.persistentState == MediaKeysRequirement::Optional && isPersistentType(sessionType))
-            accumulatedConfiguration.persistentState = MediaKeysRequirement::Required;
-    }
-
-    // 14. Set the sessionTypes member of accumulated configuration to session types.
-    accumulatedConfiguration.sessionTypes = sessionTypes;
-
-    // 15. If the videoCapabilities and audioCapabilities members in candidate configuration are both empty, return NotSupported.
-    if (candidateConfiguration.videoCapabilities.isEmpty() && candidateConfiguration.audioCapabilities.isEmpty())
-        return WTF::nullopt;
-
-    // 16. ↳ If the videoCapabilities member in candidate configuration is non-empty:
-    if (!candidateConfiguration.videoCapabilities.isEmpty()) {
-        // 16.1. Let video capabilities be the result of executing the Get Supported Capabilities for Audio/Video Type algorithm on
-        //       Video, candidate configuration's videoCapabilities member, accumulated configuration, and restrictions.
-        auto videoCapabilities = getSupportedCapabilitiesForAudioVideoType(AudioVideoType::Video, candidateConfiguration.videoCapabilities, accumulatedConfiguration, restrictions);
-
-        // 16.2. If video capabilities is null, return NotSupported.
-        if (!videoCapabilities)
-            return WTF::nullopt;
-
-        // 16.3 Set the videoCapabilities member of accumulated configuration to video capabilities.
-        accumulatedConfiguration.videoCapabilities = WTFMove(videoCapabilities.value());
-    } else {
-        // 16. ↳ Otherwise:
-        //     Set the videoCapabilities member of accumulated configuration to an empty sequence.
-        accumulatedConfiguration.videoCapabilities = { };
-    }
-
-    // 17. ↳ If the audioCapabilities member in candidate configuration is non-empty:
-    if (!candidateConfiguration.audioCapabilities.isEmpty()) {
-        // 17.1. Let audio capabilities be the result of executing the Get Supported Capabilities for Audio/Video Type algorithm on
-        //       Audio, candidate configuration's audioCapabilities member, accumulated configuration, and restrictions.
-        auto audioCapabilities = getSupportedCapabilitiesForAudioVideoType(AudioVideoType::Audio, candidateConfiguration.audioCapabilities, accumulatedConfiguration, restrictions);
-
-        // 17.2. If audio capabilities is null, return NotSupported.
-        if (!audioCapabilities)
-            return WTF::nullopt;
-
-        // 17.3 Set the audioCapabilities member of accumulated configuration to audio capabilities.
-        accumulatedConfiguration.audioCapabilities = WTFMove(audioCapabilities.value());
-    } else {
-        // 17. ↳ Otherwise:
-        //     Set the audioCapabilities member of accumulated configuration to an empty sequence.
-        accumulatedConfiguration.audioCapabilities = { };
-    }
-
-    // 18. If accumulated configuration's distinctiveIdentifier value is "optional", follow the steps for the first matching
-    //     condition from the following list:
-    if (accumulatedConfiguration.distinctiveIdentifier == MediaKeysRequirement::Optional) {
-        // ↳ If the implementation requires use Distinctive Identifier(s) or Distinctive Permanent Identifier(s) for any of the
-        //    combinations in accumulated configuration
-        if (m_private->distinctiveIdentifiersRequirement(accumulatedConfiguration, restrictions) == MediaKeysRequirement::Required) {
-            // Change accumulated configuration's distinctiveIdentifier value to "required".
-            accumulatedConfiguration.distinctiveIdentifier = MediaKeysRequirement::Required;
-        } else {
-            // ↳ Otherwise
-            //    Change accumulated configuration's distinctiveIdentifier value to "not-allowed".
-            accumulatedConfiguration.distinctiveIdentifier = MediaKeysRequirement::NotAllowed;
-        }
-    }
-
-    // 19. If accumulated configuration's persistentState value is "optional", follow the steps for the first matching
-    //     condition from the following list:
-    if (accumulatedConfiguration.persistentState == MediaKeysRequirement::Optional) {
-        // ↳ If the implementation requires persisting state for any of the combinations in accumulated configuration
-        if (m_private->persistentStateRequirement(accumulatedConfiguration, restrictions) == MediaKeysRequirement::Required) {
-            // Change accumulated configuration's persistentState value to "required".
-            accumulatedConfiguration.persistentState = MediaKeysRequirement::Required;
-        } else {
-            // ↳ Otherwise
-            //    Change accumulated configuration's persistentState value to "not-allowed".
-            accumulatedConfiguration.persistentState = MediaKeysRequirement::NotAllowed;
-        }
-    }
-
-    // 20. If implementation in the configuration specified by the combination of the values in accumulated configuration
-    //     is not supported or not allowed in the origin, return NotSupported.
-    if (!m_private->supportsConfiguration(accumulatedConfiguration))
-        return WTF::nullopt;
-
-    Document* document = downcast<Document>(m_scriptExecutionContext);
-    if (!document)
-        return WTF::nullopt;
-
     SecurityOrigin& origin = document->securityOrigin();
     SecurityOrigin& topOrigin = document->topOrigin();
-
-    if ((accumulatedConfiguration.distinctiveIdentifier == MediaKeysRequirement::Required || accumulatedConfiguration.persistentState == MediaKeysRequirement::Required) && !origin.canAccessLocalStorage(&topOrigin))
-        return WTF::nullopt;
-
-    return accumulatedConfiguration;
-    // NOTE: Continued in getConsentStatus().
-}
-
-Optional<Vector<MediaKeySystemMediaCapability>> CDM::getSupportedCapabilitiesForAudioVideoType(CDM::AudioVideoType type, const Vector<MediaKeySystemMediaCapability>& requestedCapabilities, const MediaKeySystemConfiguration& partialConfiguration, MediaKeysRestrictions& restrictions)
-{
-    // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-audio-video-type
-    // W3C Editor's Draft 09 November 2016
-
-    ASSERT(m_private);
-    if (!m_private)
-        return WTF::nullopt;
-
-    // 3.1.1.3 Get Supported Capabilities for Audio/Video Type
-
-    // Given an audio/video type, MediaKeySystemMediaCapability sequence requested media capabilities, MediaKeySystemConfiguration
-    // partial configuration, and restrictions, this algorithm returns a sequence of supported MediaKeySystemMediaCapability values
-    // for this audio/video type or null as appropriate.
-
-    // 1. Let local accumulated configuration be a local copy of partial configuration.
-    MediaKeySystemConfiguration accumulatedConfiguration = partialConfiguration;
-
-    // 2. Let supported media capabilities be an empty sequence of MediaKeySystemMediaCapability dictionaries.
-    Vector<MediaKeySystemMediaCapability> supportedMediaCapabilities { };
-
-    // 3. For each requested media capability in requested media capabilities:
-    for (auto& requestedCapability : requestedCapabilities) {
-        // 3.1. Let content type be requested media capability's contentType member.
-        // 3.2. Let robustness be requested media capability's robustness member.
-        String robustness = requestedCapability.robustness;
-
-        // 3.3. If content type is the empty string, return null.
-        if (requestedCapability.contentType.isEmpty())
-            return WTF::nullopt;
-
-        // 3.4. If content type is an invalid or unrecognized MIME type, continue to the next iteration.
-        Optional<ParsedContentType> contentType = ParsedContentType::create(requestedCapability.contentType, Mode::Rfc2045);
-        if (!contentType)
-            continue;
-
-        // 3.5. Let container be the container type specified by content type.
-        String container = contentType->mimeType();
-
-        // 3.6. If the user agent does not support container, continue to the next iteration. The case-sensitivity
-        //      of string comparisons is determined by the appropriate RFC.
-        // 3.7. Let parameters be the RFC 6381 [RFC6381] parameters, if any, specified by content type.
-        // 3.8. If the user agent does not recognize one or more parameters, continue to the next iteration.
-        // 3.9. Let media types be the set of codecs and codec constraints specified by parameters. The case-sensitivity
-        //      of string comparisons is determined by the appropriate RFC or other specification.
-        String codecs = contentType->parameterValueForName("codecs");
-        if (contentType->parameterCount() > (codecs.isEmpty() ? 0 : 1))
-            continue;
-
-        // 3.10. If media types is empty:
-        if (codecs.isEmpty()) {
-            // ↳ If container normatively implies a specific set of codecs and codec constraints:
-            // ↳ Otherwise:
-            notImplemented();
-        }
-
-        // 3.11. If content type is not strictly a audio/video type, continue to the next iteration.
-        // 3.12. If robustness is not the empty string and contains an unrecognized value or a value not supported by
-        //       implementation, continue to the next iteration. String comparison is case-sensitive.
-        if (!robustness.isEmpty() && !m_private->supportsRobustness(robustness))
-            continue;
-
-        // 3.13. If the user agent and implementation definitely support playback of encrypted media data for the
-        //       combination of container, media types, robustness and local accumulated configuration in combination
-        //       with restrictions:
-        MediaEngineSupportParameters parameters;
-        parameters.type = ContentType(contentType->mimeType());
-        if (MediaPlayer::supportsType(parameters) == MediaPlayer::SupportsType::IsNotSupported) {
-
-            // Try with Media Source:
-            parameters.isMediaSource = true;
-            if (MediaPlayer::supportsType(parameters) == MediaPlayer::SupportsType::IsNotSupported)
-                continue;
-        }
-
-        if (!m_private->supportsConfigurationWithRestrictions(accumulatedConfiguration, restrictions))
-            continue;
-
-        // 3.13.1. Add requested media capability to supported media capabilities.
-        supportedMediaCapabilities.append(requestedCapability);
-
-        // 3.13.2. ↳ If audio/video type is Video:
-        //         Add requested media capability to the videoCapabilities member of local accumulated configuration.
-        if (type == AudioVideoType::Video)
-            accumulatedConfiguration.videoCapabilities.append(requestedCapability);
-        // 3.13.2. ↳ If audio/video type is Audio:
-        //         Add requested media capability to the audioCapabilities member of local accumulated configuration.
-        else
-            accumulatedConfiguration.audioCapabilities.append(requestedCapability);
-    }
-
-    // 4. If supported media capabilities is empty, return null.
-    if (supportedMediaCapabilities.isEmpty())
-        return WTF::nullopt;
-
-    // 5. Return supported media capabilities.
-    return supportedMediaCapabilities;
-}
-
-void CDM::getConsentStatus(MediaKeySystemConfiguration&& accumulatedConfiguration, MediaKeysRestrictions&& restrictions, ConsentStatusCallback&& callback)
-{
-    // https://w3c.github.io/encrypted-media/#get-supported-configuration-and-consent
-    // W3C Editor's Draft 09 November 2016
-    if (!m_scriptExecutionContext) {
-        callback(ConsentStatus::ConsentDenied, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
-        return;
-    }
-
-    // NOTE: In the future, these checks belowe will involve asking the page client, possibly across a process boundary.
-    // They will by necessity be asynchronous with callbacks. For now, imply this behavior by performing it in an async task.
-
-    m_scriptExecutionContext->postTask([this, weakThis = makeWeakPtr(*this), accumulatedConfiguration = WTFMove(accumulatedConfiguration), restrictions = WTFMove(restrictions), callback = WTFMove(callback)] (ScriptExecutionContext&) mutable {
-        if (!weakThis || !m_private) {
-            callback(ConsentStatus::ConsentDenied, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
-            return;
-        }
-
-        Document* document = downcast<Document>(m_scriptExecutionContext);
-        if (!document) {
-            callback(ConsentStatus::ConsentDenied, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
-            return;
-        }
-
-        SecurityOrigin& origin = document->securityOrigin();
-        SecurityOrigin& topOrigin = document->topOrigin();
-
-        // 3.1.1.2 Get Supported Configuration and Consent, ctd.
-        // 21. If accumulated configuration's distinctiveIdentifier value is "required" and the Distinctive Identifier(s) associated
-        //     with accumulated configuration are not unique per origin and profile and clearable:
-        if (accumulatedConfiguration.distinctiveIdentifier == MediaKeysRequirement::Required && !m_private->distinctiveIdentifiersAreUniquePerOriginAndClearable(accumulatedConfiguration)) {
-            // 21.1. Update restrictions to reflect that all configurations described by accumulated configuration do not have user consent.
-            restrictions.distinctiveIdentifierDenied = true;
-            callback(ConsentStatus::ConsentDenied, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
-            return;
-        }
-
-        // https://w3c.github.io/encrypted-media/#get-consent-status
-        // 3.1.1.4 Get Consent Status
-        // Given an accumulated configuration, restrictions and origin, this algorithm returns the consent status for accumulated
-        // configuration and origin as one of ConsentDenied, InformUser or Allowed, together with an updated value for restrictions
-        // in the ConsentDenied case.
-
-        // 1. If there is persisted denial for origin indicating that accumulated configuration is not allowed, run the following steps:
-        // 1.1. Update restrictions to reflect the configurations for which consent has been denied.
-        // 1.2. Return ConsentDenied and restrictions.
-        // 2. If there is persisted consent for origin indicating accumulated configuration is allowed, return Allowed.
-        // NOTE: persisted denial / consent unimplemented.
-
-        // 3. If any of the following are true:
-        //    ↳ The distinctiveIdentifier member of accumulated configuration is not "not-allowed" and the combination of the User Agent,
-        //       implementation and accumulated configuration does not follow all the recommendations of Allow Persistent Data to Be Cleared
-        //       with respect to Distinctive Identifier(s).
-        // NOTE: assume that implementations follow all recommendations.
-
-        //    ↳ The user agent requires explicit user consent for the accumulated configuration for other reasons.
-        // NOTE: assume the user agent does not require explicit user consent.
-
-        // 3.1. Request user consent to use accumulated configuration in the origin and wait for the user response.
-        //      The consent must include consent to use a Distinctive Identifier(s) and/or Distinctive Permanent Identifier(s) as appropriate
-        //      if accumulated configuration's distinctiveIdentifier member is "required".
-        // 3.2. If consent was denied, run the following steps:
-        // 3.2.1. Update restrictions to reflect the configurations for which consent was denied.
-        // 3.2.1. Return ConsentDenied and restrictions.
-        // NOTE: assume implied consent if the combination of origin and topOrigin allows it.
-        if (accumulatedConfiguration.distinctiveIdentifier == MediaKeysRequirement::Required && !origin.canAccessLocalStorage(&topOrigin)) {
-            restrictions.distinctiveIdentifierDenied = true;
-            callback(ConsentStatus::ConsentDenied, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
-            return;
-        }
-
-        // 4. If the distinctiveIdentifier member of accumulated configuration is not "not-allowed", return InformUser.
-        if (accumulatedConfiguration.distinctiveIdentifier != MediaKeysRequirement::NotAllowed) {
-            callback(ConsentStatus::InformUser, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
-            return;
-        }
-
-        // 5. If the user agent requires informing the user for the accumulated configuration for other reasons, return InformUser.
-        // NOTE: assume the user agent does not require informing the user.
-
-        // 6. Return Allowed.
-        callback(ConsentStatus::Allowed, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
-    });
+    CDMPrivate::LocalStorageAccess access = origin.canAccessLocalStorage(&topOrigin) ? CDMPrivate::LocalStorageAccess::Allowed : CDMPrivate::LocalStorageAccess::NotAllowed;
+    m_private->getSupportedConfiguration(WTFMove(candidateConfiguration), access, WTFMove(callback));
 }
 
 void CDM::loadAndInitialize()
@@ -612,7 +120,7 @@ bool CDM::supportsSessions() const
 
 bool CDM::supportsInitDataType(const AtomString& initDataType) const
 {
-    return m_private && m_private->supportsInitDataType(initDataType);
+    return m_private && m_private->supportedInitDataTypes().contains(initDataType);
 }
 
 RefPtr<SharedBuffer> CDM::sanitizeInitData(const AtomString& initDataType, const SharedBuffer& initData)
index ae98325..d58cb0f 100644 (file)
@@ -80,29 +80,6 @@ public:
 private:
     CDM(Document&, const String& keySystem);
 
-    enum class ConfigurationStatus {
-        Supported,
-        NotSupported,
-        ConsentDenied,
-    };
-
-    enum class ConsentStatus {
-        ConsentDenied,
-        InformUser,
-        Allowed,
-    };
-
-    enum class AudioVideoType {
-        Audio,
-        Video,
-    };
-
-    void doSupportedConfigurationStep(MediaKeySystemConfiguration&& candidateConfiguration, MediaKeysRestrictions&&, SupportedConfigurationCallback&&);
-    Optional<MediaKeySystemConfiguration>  getSupportedConfiguration(const MediaKeySystemConfiguration& candidateConfiguration, MediaKeysRestrictions&);
-    Optional<Vector<MediaKeySystemMediaCapability>> getSupportedCapabilitiesForAudioVideoType(AudioVideoType, const Vector<MediaKeySystemMediaCapability>& requestedCapabilities, const MediaKeySystemConfiguration& partialConfiguration, MediaKeysRestrictions&);
-
-    using ConsentStatusCallback = WTF::Function<void(ConsentStatus, MediaKeySystemConfiguration&&, MediaKeysRestrictions&&)>;
-    void getConsentStatus(MediaKeySystemConfiguration&& accumulatedConfiguration, MediaKeysRestrictions&&, ConsentStatusCallback&&);
     String m_keySystem;
     std::unique_ptr<CDMPrivate> m_private;
 };
index da19bbf..29fab49 100644 (file)
@@ -401,7 +401,7 @@ void MediaKeySession::update(const BufferSource& response, Ref<DeferredPromise>&
         // 6.5. Let session closed be false.
         // 6.6. Let cdm be the CDM instance represented by this object's cdm instance value.
         // 6.7. Use the cdm to execute the following steps:
-        m_instanceSession->updateLicense(m_sessionId, m_sessionType, *sanitizedResponse, [this, weakThis = makeWeakPtr(*this), promise = WTFMove(promise)] (bool sessionWasClosed, Optional<CDMInstanceSession::KeyStatusVector>&& changedKeys, Optional<double>&& changedExpiration, Optional<CDMInstanceSession::Message>&& message, CDMInstanceSession::SuccessValue succeeded) mutable {
+        m_instanceSession->updateLicense(m_sessionId, m_sessionType, sanitizedResponse.releaseNonNull(), [this, weakThis = makeWeakPtr(*this), promise = WTFMove(promise)] (bool sessionWasClosed, Optional<CDMInstanceSession::KeyStatusVector>&& changedKeys, Optional<double>&& changedExpiration, Optional<CDMInstanceSession::Message>&& message, CDMInstanceSession::SuccessValue succeeded) mutable {
             if (!weakThis)
                 return;
 
index 30c34cd..7eb7b20 100644 (file)
@@ -81,34 +81,29 @@ void MediaKeySystemAccess::createMediaKeys(Ref<DeferredPromise>&& promise)
         }
 
         // 2.6. Initialize instance to enable, disable and/or select Key System features using configuration.
-        if (instance->initializeWithConfiguration(*m_configuration) == CDMInstance::Failed) {
-            promise->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 && instance->setDistinctiveIdentifiersAllowed(false) == CDMInstance::Failed) {
-            promise->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 && instance->setPersistentStateAllowed(false) == CDMInstance::Failed) {
-            promise->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->sessionTypes, m_implementation.copyRef(), instance.releaseNonNull());
-
-        // 2.11. Resolve promise with media keys.
-        promise->resolveWithNewlyCreated<IDLInterface<MediaKeys>>(WTFMove(mediaKeys));
+        auto allowDistinctiveIdentifiers = useDistinctiveIdentifier ? CDMInstance::AllowDistinctiveIdentifiers::Yes : CDMInstance::AllowDistinctiveIdentifiers::No;
+        auto allowPersistentState = persistentStateAllowed ? CDMInstance::AllowPersistentState::Yes : CDMInstance::AllowPersistentState::No;
+
+        instance->initializeWithConfiguration(*m_configuration, allowDistinctiveIdentifiers, allowPersistentState, [sessionTypes = m_configuration->sessionTypes, implementation = m_implementation.copyRef(), useDistinctiveIdentifier, persistentStateAllowed, instance = instance.releaseNonNull(), promise = WTFMove(promise)] (auto successValue) mutable {
+            if (successValue == CDMInstance::Failed) {
+                promise->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, sessionTypes, WTFMove(implementation), WTFMove(instance));
+
+            // 2.11. Resolve promise with media keys.
+            promise->resolveWithNewlyCreated<IDLInterface<MediaKeys>>(WTFMove(mediaKeys));
+        });
     });
 
     // 3. Return promise.
index c624e53..187d59d 100644 (file)
@@ -81,7 +81,7 @@ ExceptionOr<Ref<MediaKeySession>> MediaKeys::createSession(ScriptExecutionContex
     return session;
 }
 
-void MediaKeys::setServerCertificate(ScriptExecutionContext& context, const BufferSource& serverCertificate, Ref<DeferredPromise>&& promise)
+void MediaKeys::setServerCertificate(const BufferSource& serverCertificate, Ref<DeferredPromise>&& promise)
 {
     // https://w3c.github.io/encrypted-media/#dom-mediakeys-setservercertificate
     // W3C Editor's Draft 09 November 2016
@@ -106,16 +106,14 @@ void MediaKeys::setServerCertificate(ScriptExecutionContext& context, const Buff
     // 4. Let promise be a new promise.
     // 5. Run the following steps in parallel:
 
-    context.eventLoop().queueTask(TaskSource::Networking, [this, certificate = WTFMove(certificate), promise = WTFMove(promise)] () mutable {
-        // 5.1. Use this object's cdm instance to process certificate.
-        if (m_instance->setServerCertificate(WTFMove(certificate)) == CDMInstance::Failed) {
-            // 5.2. If the preceding step failed, resolve promise with a new DOMException whose name is the appropriate error name.
+    // 5.1. Use this object's cdm instance to process certificate.
+    m_instance->setServerCertificate(WTFMove(certificate), [promise = WTFMove(promise)] (auto success) {
+        // 5.2. If the preceding step failed, resolve promise with a new DOMException whose name is the appropriate error name.
+        // 5.1. [Else,] Resolve promise with true.
+        if (success == CDMInstance::Failed)
             promise->reject(InvalidStateError);
-            return;
-        }
-
-        // 5.1. Resolve promise with true.
-        promise->resolve<IDLBoolean>(true);
+        else
+            promise->resolve<IDLBoolean>(true);
     });
 
     // 6. Return promise.
index 1e2e1a2..b6b72a2 100644 (file)
@@ -58,7 +58,7 @@ public:
     ~MediaKeys();
 
     ExceptionOr<Ref<MediaKeySession>> createSession(ScriptExecutionContext&, MediaKeySessionType);
-    void setServerCertificate(ScriptExecutionContext&, const BufferSource&, Ref<DeferredPromise>&&);
+    void setServerCertificate(const BufferSource&, Ref<DeferredPromise>&&);
 
     void attachCDMClient(CDMClient&);
     void detachCDMClient(CDMClient&);
index d6f04cd..db1b053 100644 (file)
@@ -33,5 +33,5 @@
     ImplementationLacksVTable,
 ] interface MediaKeys {
     [CallWith=ScriptExecutionContext, MayThrowException] MediaKeySession createSession(optional MediaKeySessionType sessionType = "temporary");
-    [CallWith=ScriptExecutionContext] Promise<bool> setServerCertificate(BufferSource serverCertificate);
+    Promise<bool> setServerCertificate(BufferSource serverCertificate);
 };
index 726e8c9..f9719a5 100644 (file)
@@ -1823,6 +1823,7 @@ platform/audio/VectorMath.cpp
 platform/audio/ZeroPole.cpp
 
 platform/encryptedmedia/CDMFactory.cpp
+platform/encryptedmedia/CDMPrivate.cpp
 platform/encryptedmedia/CDMProxy.cpp
 
 platform/graphics/ANGLEWebKitBridge.cpp
index 0d9ff17..64ae155 100644 (file)
                CD3A495F17A9D01B00274E42 /* MediaSource.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495617A9D01B00274E42 /* MediaSource.h */; };
                CD3A496217A9D01B00274E42 /* SourceBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495917A9D01B00274E42 /* SourceBuffer.h */; };
                CD3A496517A9D01B00274E42 /* SourceBufferList.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3A495C17A9D01B00274E42 /* SourceBufferList.h */; };
+               CD3CE0F82401AAD9004BA01D /* CDMEncryptionScheme.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF7569B215C23A400EFCB50 /* CDMEncryptionScheme.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE0F92401AAD9004BA01D /* CDMFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5D21F71CB6B00F525C5 /* CDMFactory.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE0FA2401AAD9004BA01D /* CDMInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5CE1F71CB6A00F525C5 /* CDMInstance.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE0FB2401AAD9004BA01D /* CDMInstanceSession.h in Headers */ = {isa = PBXBuildFile; fileRef = CD9D375A215163E40049657B /* CDMInstanceSession.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE0FC2401AAD9004BA01D /* CDMKeyStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5D41F71CB6C00F525C5 /* CDMKeyStatus.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE0FD2401AAD9004BA01D /* CDMKeySystemConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5CD1F71CB6900F525C5 /* CDMKeySystemConfiguration.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE0FE2401AAD9004BA01D /* CDMMediaCapability.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5D31F71CB6C00F525C5 /* CDMMediaCapability.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE0FF2401AADA004BA01D /* CDMMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5D61F71CB6D00F525C5 /* CDMMessageType.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE1002401AADA004BA01D /* CDMPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5CF1F71CB6A00F525C5 /* CDMPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE1012401AADA004BA01D /* CDMProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5CF1F71CB6100F525C5 /* CDMProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE1022401AADA004BA01D /* CDMRequirement.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5CC1F71CB6900F525C5 /* CDMRequirement.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE1032401AADA004BA01D /* CDMRestrictions.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5D01F71CB6B00F525C5 /* CDMRestrictions.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD3CE1042401AADA004BA01D /* CDMSessionType.h in Headers */ = {isa = PBXBuildFile; fileRef = CD94A5D51F71CB6D00F525C5 /* CDMSessionType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD3E21DD2183444A00E66F55 /* ImageBufferUtilitiesCG.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3E21DB21833F5100E66F55 /* ImageBufferUtilitiesCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD3E251C18046B0600E27F56 /* GridArea.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3E251B18046B0600E27F56 /* GridArea.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD3E252418046BCD00E27F56 /* CSSGridTemplateAreasValue.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3E252218046BCD00E27F56 /* CSSGridTemplateAreasValue.h */; };
                CDF2B0191820540700F2B424 /* MockTracks.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF2B00F1820540600F2B424 /* MockTracks.h */; };
                CDF4B7121E0087AE00E235A2 /* LegacyCDMSession.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDE02E918B3DFC700CF7FF1 /* LegacyCDMSession.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CDF4B7151E00B7E500E235A2 /* CDM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDF4B7131E00B7E500E235A2 /* CDM.cpp */; };
-               CDF4B7161E00B7E500E235A2 /* CDM.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF4B7141E00B7E500E235A2 /* CDM.h */; };
+               CDF4B7161E00B7E500E235A2 /* CDM.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF4B7141E00B7E500E235A2 /* CDM.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CDF4B7181E01CB9100E235A2 /* MediaKeysRestrictions.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF4B7171E01CB9100E235A2 /* MediaKeysRestrictions.h */; };
                CDF4B71A1E01D3D000E235A2 /* MediaKeySessionType.idl in Headers */ = {isa = PBXBuildFile; fileRef = CDF4B7191E01D3D000E235A2 /* MediaKeySessionType.idl */; };
                CDF4B71E1E01E11A00E235A2 /* JSMediaKeySessionType.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF4B71C1E01E11A00E235A2 /* JSMediaKeySessionType.h */; };
                CD3A495B17A9D01B00274E42 /* SourceBufferList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SourceBufferList.cpp; sourceTree = "<group>"; };
                CD3A495C17A9D01B00274E42 /* SourceBufferList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceBufferList.h; sourceTree = "<group>"; };
                CD3A495D17A9D01B00274E42 /* SourceBufferList.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SourceBufferList.idl; sourceTree = "<group>"; };
+               CD3CE11C240451AF004BA01D /* CDMPrivate.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CDMPrivate.cpp; sourceTree = "<group>"; };
                CD3E21DB21833F5100E66F55 /* ImageBufferUtilitiesCG.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageBufferUtilitiesCG.h; sourceTree = "<group>"; };
                CD3E251B18046B0600E27F56 /* GridArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridArea.h; sourceTree = "<group>"; };
                CD3E252118046BCD00E27F56 /* CSSGridTemplateAreasValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGridTemplateAreasValue.cpp; sourceTree = "<group>"; };
                                CD94A5CD1F71CB6900F525C5 /* CDMKeySystemConfiguration.h */,
                                CD94A5D31F71CB6C00F525C5 /* CDMMediaCapability.h */,
                                CD94A5D61F71CB6D00F525C5 /* CDMMessageType.h */,
+                               CD3CE11C240451AF004BA01D /* CDMPrivate.cpp */,
                                CD94A5CF1F71CB6A00F525C5 /* CDMPrivate.h */,
                                CD94A5CF1F71CB6100F525D5 /* CDMProxy.cpp */,
                                CD94A5CF1F71CB6100F525C5 /* CDMProxy.h */,
                                6550B69E099DF0270090D781 /* CDATASection.h in Headers */,
                                CDF4B7161E00B7E500E235A2 /* CDM.h in Headers */,
                                CD94A5DE1F72F57B00F525C5 /* CDMClient.h in Headers */,
+                               CD3CE0F82401AAD9004BA01D /* CDMEncryptionScheme.h in Headers */,
+                               CD3CE0F92401AAD9004BA01D /* CDMFactory.h in Headers */,
                                CDB7045A1F7465A1003923DF /* CDMFairPlayStreaming.h in Headers */,
+                               CD3CE0FA2401AAD9004BA01D /* CDMInstance.h in Headers */,
+                               CD3CE0FB2401AAD9004BA01D /* CDMInstanceSession.h in Headers */,
+                               CD3CE0FC2401AAD9004BA01D /* CDMKeyStatus.h in Headers */,
+                               CD3CE0FD2401AAD9004BA01D /* CDMKeySystemConfiguration.h in Headers */,
+                               CD3CE0FE2401AAD9004BA01D /* CDMMediaCapability.h in Headers */,
+                               CD3CE0FF2401AADA004BA01D /* CDMMessageType.h in Headers */,
+                               CD3CE1002401AADA004BA01D /* CDMPrivate.h in Headers */,
                                CD318623199F1E2A0030A0F7 /* CDMPrivateMediaSourceAVFObjC.h in Headers */,
+                               CD3CE1012401AADA004BA01D /* CDMProxy.h in Headers */,
+                               CD3CE1022401AADA004BA01D /* CDMRequirement.h in Headers */,
+                               CD3CE1032401AADA004BA01D /* CDMRestrictions.h in Headers */,
                                CDE595971BF26E2100A1CBE8 /* CDMSessionMediaSourceAVFObjC.h in Headers */,
+                               CD3CE1042401AADA004BA01D /* CDMSessionType.h in Headers */,
                                5FA904CA178E61F5004C8A2D /* CertificateInfo.h in Headers */,
                                91B8F0B521953D65000C2B00 /* CertificateInfoBase.h in Headers */,
                                FE36FD1516C7826500F887C1 /* ChangeVersionData.h in Headers */,
index 969c50d..215849a 100644 (file)
@@ -2561,15 +2561,25 @@ void HTMLMediaElement::setReadyState(MediaPlayer::ReadyState state)
 }
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA)
+void HTMLMediaElement::updateShouldContinueAfterNeedKey()
+{
+    if (!m_player)
+        return;
+    bool shouldContinue = hasEventListeners("webkitneedkey") || (RuntimeEnabledFeatures::sharedFeatures().encryptedMediaAPIEnabled() && !document().quirks().hasBrokenEncryptedMediaAPISupportQuirk());
+    m_player->setShouldContinueAfterKeyNeeded(shouldContinue);
+}
+#endif
+
 RefPtr<ArrayBuffer> HTMLMediaElement::mediaPlayerCachedKeyForKeyId(const String& keyId) const
 {
     return m_webKitMediaKeys ? m_webKitMediaKeys->cachedKeyForKeyId(keyId) : nullptr;
 }
 
-bool HTMLMediaElement::mediaPlayerKeyNeeded(Uint8Array* initData)
+void HTMLMediaElement::mediaPlayerKeyNeeded(Uint8Array* initData)
 {
     if (!RuntimeEnabledFeatures::sharedFeatures().legacyEncryptedMediaAPIEnabled())
-        return false;
+        return;
 
     if (!hasEventListeners("webkitneedkey")
 #if ENABLE(ENCRYPTED_MEDIA)
@@ -2580,14 +2590,12 @@ bool HTMLMediaElement::mediaPlayerKeyNeeded(Uint8Array* initData)
         ) {
         m_error = MediaError::create(MediaError::MEDIA_ERR_ENCRYPTED);
         scheduleEvent(eventNames().errorEvent);
-        return false;
+        return;
     }
 
     auto event = WebKitMediaKeyNeededEvent::create(eventNames().webkitneedkeyEvent, initData);
     event->setTarget(this);
     m_asyncEventQueue->enqueueEvent(WTFMove(event));
-
-    return true;
 }
 
 String HTMLMediaElement::mediaPlayerMediaKeysStorageDirectory() const
@@ -5129,6 +5137,10 @@ void HTMLMediaElement::mediaEngineWasUpdated()
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
     scheduleUpdateMediaState();
 #endif
+
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    updateShouldContinueAfterNeedKey();
+#endif
 }
 
 void HTMLMediaElement::mediaPlayerEngineUpdated()
@@ -5891,6 +5903,11 @@ void HTMLMediaElement::dispatchEvent(Event& event)
 
 bool HTMLMediaElement::addEventListener(const AtomString& eventType, Ref<EventListener>&& listener, const AddEventListenerOptions& options)
 {
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    if (eventType == eventNames().webkitneedkeyEvent)
+        updateShouldContinueAfterNeedKey();
+#endif
+
     if (eventType != eventNames().webkitplaybacktargetavailabilitychangedEvent)
         return Node::addEventListener(eventType, WTFMove(listener), options);
 
@@ -5912,6 +5929,11 @@ bool HTMLMediaElement::addEventListener(const AtomString& eventType, Ref<EventLi
 
 bool HTMLMediaElement::removeEventListener(const AtomString& eventType, EventListener& listener, const ListenerOptions& options)
 {
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    if (eventType == eventNames().webkitneedkeyEvent)
+        updateShouldContinueAfterNeedKey();
+#endif
+
     if (eventType != eventNames().webkitplaybacktargetavailabilitychangedEvent)
         return Node::removeEventListener(eventType, listener, options);
 
index 5de0d11..f6920f6 100644 (file)
@@ -680,7 +680,7 @@ private:
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     RefPtr<ArrayBuffer> mediaPlayerCachedKeyForKeyId(const String& keyId) const final;
-    bool mediaPlayerKeyNeeded(Uint8Array*) final;
+    void mediaPlayerKeyNeeded(Uint8Array*) final;
     String mediaPlayerMediaKeysStorageDirectory() const final;
 #endif
 
@@ -694,6 +694,10 @@ private:
     // CDMClient
     void cdmClientAttemptToResumePlaybackIfNecessary() final;
 #endif
+
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    void updateShouldContinueAfterNeedKey();
+#endif
     
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
     void mediaPlayerCurrentPlaybackTargetIsWirelessChanged(bool) final;
@@ -1166,6 +1170,7 @@ private:
     MediaProvider m_mediaProvider;
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
+    bool m_hasNeedkeyListener { false };
     RefPtr<WebKitMediaKeys> m_webKitMediaKeys;
 #endif
 
index 5ed04c4..60a5847 100644 (file)
@@ -31,6 +31,7 @@ namespace WebCore {
 
 class AudioDestination;
 class AudioIOCallback;
+class CDMFactory;
 
 class WEBCORE_EXPORT MediaStrategy {
 public:
@@ -38,6 +39,9 @@ public:
     virtual std::unique_ptr<AudioDestination> createAudioDestination(
         AudioIOCallback&, const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, float sampleRate) = 0;
 #endif
+#if ENABLE(ENCRYPTED_MEDIA)
+    virtual void registerCDMFactories(Vector<CDMFactory*>&) = 0;
+#endif
 protected:
     virtual ~MediaStrategy() = default;
 };
index 74b3aa7..1a7a562 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include <wtf/Forward.h>
+
 namespace WebCore {
 
-enum class CDMEncryptionScheme {
+enum class CDMEncryptionScheme : uint8_t {
     cenc,
     cbcs,
 };
 
 }
 
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::CDMEncryptionScheme> {
+    using values = EnumValues<
+        WebCore::CDMEncryptionScheme,
+        WebCore::CDMEncryptionScheme::cenc,
+        WebCore::CDMEncryptionScheme::cbcs
+    >;
+};
+
+}
+
 #endif
index 4bb599f..992d49a 100644 (file)
@@ -30,6 +30,8 @@
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include "MediaStrategy.h"
+#include "PlatformStrategies.h"
 #include <mutex>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/Vector.h>
@@ -40,7 +42,9 @@ Vector<CDMFactory*>& CDMFactory::registeredFactories()
 {
     static NeverDestroyed<Vector<CDMFactory*>> factories;
     static std::once_flag once;
-    std::call_once(once, [&] { platformRegisterFactories(factories); });
+    std::call_once(once, [&] {
+        platformStrategies()->mediaStrategy().registerCDMFactories(factories);
+    });
 
     return factories;
 }
index 44eaab0..525c84e 100644 (file)
@@ -48,7 +48,7 @@ public:
 
     // Platform-specific function that's called when the list of
     // registered CDMFactory objects is queried for the first time.
-    static void platformRegisterFactories(Vector<CDMFactory*>&);
+    WEBCORE_EXPORT static void platformRegisterFactories(Vector<CDMFactory*>&);
 };
 
 } // namespace WebCore
index 8f9f3eb..734c935 100644 (file)
@@ -31,6 +31,7 @@
 #include "CDMMessageType.h"
 #include "CDMSessionType.h"
 #include <utility>
+#include <wtf/CompletionHandler.h>
 #include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
 #include <wtf/ThreadSafeRefCounted.h>
@@ -52,23 +53,33 @@ public:
         Mock,
         ClearKey,
         FairPlayStreaming,
+        Remote,
     };
     virtual ImplementationType implementationType() const = 0;
 
-    enum SuccessValue {
+    enum SuccessValue : bool {
         Failed,
         Succeeded,
     };
+    using SuccessCallback = CompletionHandler<void(SuccessValue)>;
 
-    virtual SuccessValue initializeWithConfiguration(const CDMKeySystemConfiguration&) = 0;
-    virtual SuccessValue setDistinctiveIdentifiersAllowed(bool) = 0;
-    virtual SuccessValue setPersistentStateAllowed(bool) = 0;
-    virtual SuccessValue setServerCertificate(Ref<SharedBuffer>&&) = 0;
-    virtual SuccessValue setStorageDirectory(const String&) = 0;
+    enum class AllowDistinctiveIdentifiers : bool {
+        No,
+        Yes,
+    };
+
+    enum class AllowPersistentState : bool {
+        No,
+        Yes,
+    };
+
+    virtual void initializeWithConfiguration(const CDMKeySystemConfiguration&, AllowDistinctiveIdentifiers, AllowPersistentState, SuccessCallback&&) = 0;
+    virtual void setServerCertificate(Ref<SharedBuffer>&&, SuccessCallback&&) = 0;
+    virtual void setStorageDirectory(const String&) = 0;
     virtual const String& keySystem() const = 0;
     virtual RefPtr<CDMInstanceSession> createSession() = 0;
 
-    enum class HDCPStatus {
+    enum class HDCPStatus : uint8_t {
         Unknown,
         Valid,
         OutputRestricted,
index 8725a31..d464b74 100644 (file)
@@ -72,9 +72,9 @@ public:
     using KeyStatusVector = CDMInstanceSessionClient::KeyStatusVector;
     using Message = std::pair<MessageType, Ref<SharedBuffer>>;
     using LicenseUpdateCallback = CompletionHandler<void(bool sessionWasClosed, Optional<KeyStatusVector>&& changedKeys, Optional<double>&& changedExpiration, Optional<Message>&& message, SuccessValue succeeded)>;
-    virtual void updateLicense(const String& sessionId, LicenseType, const SharedBuffer& response, LicenseUpdateCallback&&) = 0;
+    virtual void updateLicense(const String& sessionId, LicenseType, Ref<SharedBuffer>&& response, LicenseUpdateCallback&&) = 0;
 
-    enum class SessionLoadFailure {
+    enum class SessionLoadFailure : uint8_t {
         None,
         NoSessionData,
         MismatchedSessionType,
index ad96962..cc5e718 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include <wtf/Forward.h>
+
 namespace WebCore {
 
-enum class CDMKeyStatus {
+enum class CDMKeyStatus : uint8_t {
     Usable,
     Expired,
     Released,
@@ -44,4 +46,20 @@ enum class CDMKeyStatus {
 
 } // namespace WebCore
 
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::CDMKeyStatus> {
+    using values = EnumValues<
+    WebCore::CDMKeyStatus,
+    WebCore::CDMKeyStatus::Usable,
+    WebCore::CDMKeyStatus::Expired,
+    WebCore::CDMKeyStatus::Released,
+    WebCore::CDMKeyStatus::OutputRestricted,
+    WebCore::CDMKeyStatus::OutputDownscaled,
+    WebCore::CDMKeyStatus::StatusPending,
+    WebCore::CDMKeyStatus::InternalError
+    >;
+};
+
+}
 #endif // ENABLE(ENCRYPTED_MEDIA)
index 612d645..852587c 100644 (file)
@@ -48,6 +48,67 @@ struct CDMKeySystemConfiguration {
     CDMRequirement distinctiveIdentifier { CDMRequirement::Optional };
     CDMRequirement persistentState { CDMRequirement::Optional };
     Vector<CDMSessionType> sessionTypes;
+
+    template<class Encoder>
+    void encode(Encoder& encoder) const
+    {
+        encoder << label;
+        encoder << initDataTypes;
+        encoder << audioCapabilities;
+        encoder << videoCapabilities;
+        encoder << distinctiveIdentifier;
+        encoder << persistentState;
+        encoder << sessionTypes;
+    }
+
+    template <class Decoder>
+    static Optional<CDMKeySystemConfiguration> decode(Decoder& decoder)
+    {
+        Optional<String> label;
+        decoder >> label;
+        if (!label)
+            return WTF::nullopt;
+
+        Optional<Vector<String>> initDataTypes;
+        decoder >> initDataTypes;
+        if (!initDataTypes)
+            return WTF::nullopt;
+
+        Optional<Vector<CDMMediaCapability>> audioCapabilities;
+        decoder >> audioCapabilities;
+        if (!audioCapabilities)
+            return WTF::nullopt;
+
+        Optional<Vector<CDMMediaCapability>> videoCapabilities;
+        decoder >> videoCapabilities;
+        if (!videoCapabilities)
+            return WTF::nullopt;
+
+        Optional<CDMRequirement> distinctiveIdentifier;
+        decoder >> distinctiveIdentifier;
+        if (!distinctiveIdentifier)
+            return WTF::nullopt;
+        
+        Optional<CDMRequirement> persistentState;
+        decoder >> persistentState;
+        if (!persistentState)
+            return WTF::nullopt;
+
+        Optional<Vector<CDMSessionType>> sessionTypes;
+        decoder >> sessionTypes;
+        if (!sessionTypes)
+            return WTF::nullopt;
+
+        return {{
+            WTFMove(*label),
+            WTFMove(*initDataTypes),
+            WTFMove(*audioCapabilities),
+            WTFMove(*videoCapabilities),
+            *distinctiveIdentifier,
+            *persistentState,
+            WTFMove(*sessionTypes),
+        }};
+    }
 };
 
 } // namespace WebCore
index 901b54f..f84a0d1 100644 (file)
@@ -39,6 +39,39 @@ struct CDMMediaCapability {
     String contentType;
     String robustness;
     Optional<CDMEncryptionScheme> encryptionScheme;
+
+    template<class Encoder>
+    void encode(Encoder& encoder) const
+    {
+        encoder << contentType;
+        encoder << robustness;
+        encoder << encryptionScheme;
+    }
+
+    template <class Decoder>
+    static Optional<CDMMediaCapability> decode(Decoder& decoder)
+    {
+        Optional<String> contentType;
+        decoder >> contentType;
+        if (!contentType)
+            return WTF::nullopt;
+
+        Optional<String> robustness;
+        decoder >> robustness;
+        if (!robustness)
+            return WTF::nullopt;
+
+        Optional<Optional<CDMEncryptionScheme>> encryptionScheme;
+        decoder >> encryptionScheme;
+        if (!encryptionScheme)
+            return WTF::nullopt;
+
+        return {{
+            WTFMove(*contentType),
+            WTFMove(*robustness),
+            WTFMove(*encryptionScheme),
+        }};
+    }
 };
 
 } // namespace WebCore
index e5f796a..95bf28c 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include <wtf/Forward.h>
+
 namespace WebCore {
 
-enum class CDMMessageType {
+enum class CDMMessageType : uint8_t {
     LicenseRequest,
     LicenseRenewal,
     LicenseRelease,
@@ -41,4 +43,18 @@ enum class CDMMessageType {
 
 } // namespace WebCore
 
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::CDMMessageType> {
+    using values = EnumValues<
+        WebCore::CDMMessageType,
+        WebCore::CDMMessageType::LicenseRequest,
+        WebCore::CDMMessageType::LicenseRenewal,
+        WebCore::CDMMessageType::LicenseRelease,
+        WebCore::CDMMessageType::IndividualizationRequest
+    >;
+};
+
+}
+
 #endif // ENABLE(ENCRYPTED_MEDIA)
diff --git a/Source/WebCore/platform/encryptedmedia/CDMPrivate.cpp b/Source/WebCore/platform/encryptedmedia/CDMPrivate.cpp
new file mode 100644 (file)
index 0000000..164ba49
--- /dev/null
@@ -0,0 +1,520 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#include "config.h"
+#include "CDMPrivate.h"
+
+#if ENABLE(ENCRYPTED_MEDIA)
+
+#include "CDMKeySystemConfiguration.h"
+#include "CDMMediaCapability.h"
+#include "CDMRequirement.h"
+#include "CDMRestrictions.h"
+#include "MediaPlayer.h"
+#include "NotImplemented.h"
+#include "ParsedContentType.h"
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+CDMPrivate::CDMPrivate() = default;
+CDMPrivate::~CDMPrivate() = default;
+
+void CDMPrivate::getSupportedConfiguration(CDMKeySystemConfiguration&& candidateConfiguration, LocalStorageAccess access, SupportedConfigurationCallback&& callback)
+{
+    // https://w3c.github.io/encrypted-media/#get-supported-configuration
+    // W3C Editor's Draft 09 November 2016
+
+    // 3.1.1.1 Get Supported Configuration
+    // Given a Key Systems implementation implementation, CDMKeySystemConfiguration candidate configuration, and origin,
+    // this algorithm returns a supported configuration or NotSupported as appropriate.
+
+    // 1. Let supported configuration be ConsentDenied.
+    // 2. Initialize restrictions to indicate that no configurations have had user consent denied.
+    CDMRestrictions restrictions { };
+    doSupportedConfigurationStep(WTFMove(candidateConfiguration), WTFMove(restrictions), access, WTFMove(callback));
+}
+
+void CDMPrivate::doSupportedConfigurationStep(CDMKeySystemConfiguration&& candidateConfiguration, CDMRestrictions&& restrictions, LocalStorageAccess access, SupportedConfigurationCallback&& callback)
+{
+    // https://w3c.github.io/encrypted-media/#get-supported-configuration
+    // W3C Editor's Draft 09 November 2016, ctd.
+
+    // 3.1.1.1 Get Supported Configuration
+    // 3. Repeat the following step while supported configuration is ConsentDenied:
+    // 3.1. Let supported configuration and, if provided, restrictions be the result of executing the
+    // Get Supported Configuration and Consent algorithm with implementation, candidate configuration,
+    // restrictions and origin.
+    auto optionalConfiguration = getSupportedConfiguration(candidateConfiguration, restrictions, access);
+    if (!optionalConfiguration) {
+        callback(WTF::nullopt);
+        return;
+    }
+
+    auto consentCallback = [weakThis = makeWeakPtr(*this), callback = WTFMove(callback), access] (ConsentStatus status, CDMKeySystemConfiguration&& configuration, CDMRestrictions&& restrictions) mutable {
+        if (!weakThis) {
+            callback(WTF::nullopt);
+            return;
+        }
+        // 3.1.1.2 Get Supported Configuration and Consent, ctd.
+        // 22. Let consent status and updated restrictions be the result of running the Get Consent Status algorithm on accumulated configuration,
+        //     restrictions and origin and follow the steps for the value of consent status from the following list:
+        switch (status) {
+        case ConsentStatus::ConsentDenied:
+            // ↳ ConsentDenied:
+            //    Return ConsentDenied and updated restrictions.
+            weakThis->doSupportedConfigurationStep(WTFMove(configuration), WTFMove(restrictions), access, WTFMove(callback));
+            return;
+
+        case ConsentStatus::InformUser:
+            // ↳ InformUser
+            //    Inform the user that accumulated configuration is in use in the origin including, specifically, the information that
+            //    Distinctive Identifier(s) and/or Distinctive Permanent Identifier(s) as appropriate will be used if the
+            //    distinctiveIdentifier member of accumulated configuration is "required". Continue to the next step.
+            // NOTE: Implement.
+            break;
+
+        case ConsentStatus::Allowed:
+            // ↳ Allowed:
+            // Continue to the next step.
+            break;
+        }
+        // 23. Return accumulated configuration.
+        callback(WTFMove(configuration));
+    };
+    getConsentStatus(WTFMove(optionalConfiguration.value()), WTFMove(restrictions), access, WTFMove(consentCallback));
+}
+
+bool CDMPrivate::isPersistentType(CDMSessionType sessionType)
+{
+    // https://w3c.github.io/encrypted-media/#is-persistent-session-type
+    // W3C Editor's Draft 09 November 2016
+
+    // 5.1.1. Is persistent session type?
+    // 1. Let the session type be the specified CDMSessionType value.
+    // 2. Follow the steps for the value of session type from the following list:
+    switch (sessionType) {
+    case CDMSessionType::Temporary:
+        // ↳ "temporary"
+        return false;
+    case CDMSessionType::PersistentLicense:
+    case CDMSessionType::PersistentUsageRecord:
+        // ↳ "persistent-license"
+        return true;
+    }
+
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+Optional<CDMKeySystemConfiguration> CDMPrivate::getSupportedConfiguration(const CDMKeySystemConfiguration& candidateConfiguration, CDMRestrictions& restrictions, LocalStorageAccess access)
+{
+    // https://w3c.github.io/encrypted-media/#get-supported-configuration-and-consent
+    // W3C Editor's Draft 09 November 2016
+
+    // 3.1.1.2 Get Supported Configuration and Consent
+    // Given a Key Systems implementation implementation, CDMKeySystemConfiguration candidate configuration,
+    // restrictions and origin, this algorithm returns a supported configuration, NotSupported, or ConsentDenied
+    // as appropriate and, in the ConsentDenied case, restrictions.
+
+    // 1. Let accumulated configuration be a new CDMKeySystemConfiguration dictionary.
+    CDMKeySystemConfiguration accumulatedConfiguration { };
+
+    // 2. Set the label member of accumulated configuration to equal the label member of candidate configuration.
+    accumulatedConfiguration.label = candidateConfiguration.label;
+
+    // 3. If the initDataTypes member of candidate configuration is non-empty, run the following steps:
+    if (!candidateConfiguration.initDataTypes.isEmpty()) {
+        // 3.1. Let supported types be an empty sequence of DOMStrings.
+        Vector<String> supportedTypes;
+
+        // 3.2. For each value in candidate configuration's initDataTypes member:
+        for (auto initDataType : candidateConfiguration.initDataTypes) {
+            // 3.2.1. Let initDataType be the value.
+            // 3.2.2. If the implementation supports generating requests based on initDataType, add initDataType
+            //        to supported types. String comparison is case-sensitive. The empty string is never supported.
+            if (initDataType.isEmpty())
+                continue;
+
+            if (supportedInitDataTypes().contains(initDataType))
+                supportedTypes.append(initDataType);
+        }
+
+        // 3.3. If supported types is empty, return NotSupported.
+        if (supportedTypes.isEmpty())
+            return WTF::nullopt;
+
+        // 3.4. Set the initDataTypes member of accumulated configuration to supported types.
+        accumulatedConfiguration.initDataTypes = WTFMove(supportedTypes);
+    }
+
+    // 4. Let distinctive identifier requirement be the value of candidate configuration's distinctiveIdentifier member.
+    CDMRequirement distinctiveIdentifierRequirement = candidateConfiguration.distinctiveIdentifier;
+
+    // 5. If distinctive identifier requirement is "optional" and Distinctive Identifiers are not allowed according to
+    //    restrictions, set distinctive identifier requirement to "not-allowed".
+    if (distinctiveIdentifierRequirement == CDMRequirement::Optional && restrictions.distinctiveIdentifierDenied)
+        distinctiveIdentifierRequirement = CDMRequirement::NotAllowed;
+
+    // 6. Follow the steps for distinctive identifier requirement from the following list:
+    switch (distinctiveIdentifierRequirement) {
+    case CDMRequirement::Required:
+        // ↳ "required"
+        // If the implementation does not support use of Distinctive Identifier(s) in combination
+        // with accumulated configuration and restrictions, return NotSupported.
+        if (distinctiveIdentifiersRequirement(accumulatedConfiguration, restrictions) == CDMRequirement::NotAllowed)
+            return WTF::nullopt;
+        break;
+
+    case CDMRequirement::Optional:
+        // ↳ "optional"
+        // Continue with the following steps.
+        break;
+
+    case CDMRequirement::NotAllowed:
+        // ↳ "not-allowed"
+        // If the implementation requires use Distinctive Identifier(s) or Distinctive Permanent Identifier(s)
+        // in combination with accumulated configuration and restrictions, return NotSupported.
+        if (distinctiveIdentifiersRequirement(accumulatedConfiguration, restrictions) == CDMRequirement::Required)
+            return WTF::nullopt;
+        break;
+    }
+
+    // 7. Set the distinctiveIdentifier member of accumulated configuration to equal distinctive identifier requirement.
+    accumulatedConfiguration.distinctiveIdentifier = distinctiveIdentifierRequirement;
+
+    // 8. Let persistent state requirement be equal to the value of candidate configuration's persistentState member.
+    CDMRequirement persistentStateRequirement = candidateConfiguration.persistentState;
+
+    // 9. If persistent state requirement is "optional" and persisting state is not allowed according to restrictions,
+    //    set persistent state requirement to "not-allowed".
+    if (persistentStateRequirement == CDMRequirement::Optional && restrictions.persistentStateDenied)
+        persistentStateRequirement = CDMRequirement::NotAllowed;
+
+    // 10. Follow the steps for persistent state requirement from the following list:
+    switch (persistentStateRequirement) {
+    case CDMRequirement::Required:
+        // ↳ "required"
+        // If the implementation does not support persisting state in combination with accumulated configuration
+        // and restrictions, return NotSupported.
+        if (this->persistentStateRequirement(accumulatedConfiguration, restrictions) == CDMRequirement::NotAllowed)
+            return WTF::nullopt;
+        break;
+
+    case CDMRequirement::Optional:
+        // ↳ "optional"
+        // Continue with the following steps.
+        break;
+
+    case CDMRequirement::NotAllowed:
+        // ↳ "not-allowed"
+        // If the implementation requires persisting state in combination with accumulated configuration
+        // and restrictions, return NotSupported
+        if (this->persistentStateRequirement(accumulatedConfiguration, restrictions) == CDMRequirement::Required)
+            return WTF::nullopt;
+        break;
+    }
+
+    // 11. Set the persistentState member of accumulated configuration to equal the value of persistent state requirement.
+    accumulatedConfiguration.persistentState = persistentStateRequirement;
+
+    // 12. Follow the steps for the first matching condition from the following list:
+    Vector<CDMSessionType> sessionTypes;
+
+    if (!candidateConfiguration.sessionTypes.isEmpty()) {
+        // ↳ If the sessionTypes member is present [WebIDL] in candidate configuration
+        // Let session types be candidate configuration's sessionTypes member.
+        sessionTypes = candidateConfiguration.sessionTypes;
+    } else {
+        // ↳ Otherwise
+        // Let session types be [ "temporary" ].
+        sessionTypes = { CDMSessionType::Temporary };
+    }
+
+    // 13. For each value in session types:
+    for (auto& sessionType : sessionTypes) {
+        // 13.1. Let session type be the value.
+        // 13.2. If accumulated configuration's persistentState value is "not-allowed" and the
+        //       Is persistent session type? algorithm returns true for session type return NotSupported.
+        if (accumulatedConfiguration.persistentState == CDMRequirement::NotAllowed && isPersistentType(sessionType))
+            return WTF::nullopt;
+
+        // 13.3. If the implementation does not support session type in combination with accumulated configuration
+        //       and restrictions for other reasons, return NotSupported.
+        if (!supportsSessionTypeWithConfiguration(sessionType, accumulatedConfiguration))
+            return WTF::nullopt;
+
+        // 13.4 If accumulated configuration's persistentState value is "optional" and the result of running the Is
+        //      persistent session type? algorithm on session type is true, change accumulated configuration's persistentState
+        //      value to "required".
+        if (accumulatedConfiguration.persistentState == CDMRequirement::Optional && isPersistentType(sessionType))
+            accumulatedConfiguration.persistentState = CDMRequirement::Required;
+    }
+
+    // 14. Set the sessionTypes member of accumulated configuration to session types.
+    accumulatedConfiguration.sessionTypes = sessionTypes;
+
+    // 15. If the videoCapabilities and audioCapabilities members in candidate configuration are both empty, return NotSupported.
+    if (candidateConfiguration.videoCapabilities.isEmpty() && candidateConfiguration.audioCapabilities.isEmpty())
+        return WTF::nullopt;
+
+    // 16. ↳ If the videoCapabilities member in candidate configuration is non-empty:
+    if (!candidateConfiguration.videoCapabilities.isEmpty()) {
+        // 16.1. Let video capabilities be the result of executing the Get Supported Capabilities for Audio/Video Type algorithm on
+        //       Video, candidate configuration's videoCapabilities member, accumulated configuration, and restrictions.
+        auto videoCapabilities = getSupportedCapabilitiesForAudioVideoType(AudioVideoType::Video, candidateConfiguration.videoCapabilities, accumulatedConfiguration, restrictions);
+
+        // 16.2. If video capabilities is null, return NotSupported.
+        if (!videoCapabilities)
+            return WTF::nullopt;
+
+        // 16.3 Set the videoCapabilities member of accumulated configuration to video capabilities.
+        accumulatedConfiguration.videoCapabilities = WTFMove(videoCapabilities.value());
+    } else {
+        // 16. ↳ Otherwise:
+        //     Set the videoCapabilities member of accumulated configuration to an empty sequence.
+        accumulatedConfiguration.videoCapabilities = { };
+    }
+
+    // 17. ↳ If the audioCapabilities member in candidate configuration is non-empty:
+    if (!candidateConfiguration.audioCapabilities.isEmpty()) {
+        // 17.1. Let audio capabilities be the result of executing the Get Supported Capabilities for Audio/Video Type algorithm on
+        //       Audio, candidate configuration's audioCapabilities member, accumulated configuration, and restrictions.
+        auto audioCapabilities = getSupportedCapabilitiesForAudioVideoType(AudioVideoType::Audio, candidateConfiguration.audioCapabilities, accumulatedConfiguration, restrictions);
+
+        // 17.2. If audio capabilities is null, return NotSupported.
+        if (!audioCapabilities)
+            return WTF::nullopt;
+
+        // 17.3 Set the audioCapabilities member of accumulated configuration to audio capabilities.
+        accumulatedConfiguration.audioCapabilities = WTFMove(audioCapabilities.value());
+    } else {
+        // 17. ↳ Otherwise:
+        //     Set the audioCapabilities member of accumulated configuration to an empty sequence.
+        accumulatedConfiguration.audioCapabilities = { };
+    }
+
+    // 18. If accumulated configuration's distinctiveIdentifier value is "optional", follow the steps for the first matching
+    //     condition from the following list:
+    if (accumulatedConfiguration.distinctiveIdentifier == CDMRequirement::Optional) {
+        // ↳ If the implementation requires use Distinctive Identifier(s) or Distinctive Permanent Identifier(s) for any of the
+        //    combinations in accumulated configuration
+        if (distinctiveIdentifiersRequirement(accumulatedConfiguration, restrictions) == CDMRequirement::Required) {
+            // Change accumulated configuration's distinctiveIdentifier value to "required".
+            accumulatedConfiguration.distinctiveIdentifier = CDMRequirement::Required;
+        } else {
+            // ↳ Otherwise
+            //    Change accumulated configuration's distinctiveIdentifier value to "not-allowed".
+            accumulatedConfiguration.distinctiveIdentifier = CDMRequirement::NotAllowed;
+        }
+    }
+
+    // 19. If accumulated configuration's persistentState value is "optional", follow the steps for the first matching
+    //     condition from the following list:
+    if (accumulatedConfiguration.persistentState == CDMRequirement::Optional) {
+        // ↳ If the implementation requires persisting state for any of the combinations in accumulated configuration
+        if (this->persistentStateRequirement(accumulatedConfiguration, restrictions) == CDMRequirement::Required) {
+            // Change accumulated configuration's persistentState value to "required".
+            accumulatedConfiguration.persistentState = CDMRequirement::Required;
+        } else {
+            // ↳ Otherwise
+            //    Change accumulated configuration's persistentState value to "not-allowed".
+            accumulatedConfiguration.persistentState = CDMRequirement::NotAllowed;
+        }
+    }
+
+    // 20. If implementation in the configuration specified by the combination of the values in accumulated configuration
+    //     is not supported or not allowed in the origin, return NotSupported.
+    if (!supportsConfiguration(accumulatedConfiguration))
+        return WTF::nullopt;
+
+    if ((accumulatedConfiguration.distinctiveIdentifier == CDMRequirement::Required || accumulatedConfiguration.persistentState == CDMRequirement::Required) && access == LocalStorageAccess::NotAllowed)
+        return WTF::nullopt;
+
+    return accumulatedConfiguration;
+    // NOTE: Continued in getConsentStatus().
+}
+
+Optional<Vector<CDMMediaCapability>> CDMPrivate::getSupportedCapabilitiesForAudioVideoType(CDMPrivate::AudioVideoType type, const Vector<CDMMediaCapability>& requestedCapabilities, const CDMKeySystemConfiguration& partialConfiguration, CDMRestrictions& restrictions)
+{
+    // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-audio-video-type
+    // W3C Editor's Draft 09 November 2016
+
+    // 3.1.1.3 Get Supported Capabilities for Audio/Video Type
+
+    // Given an audio/video type, CDMMediaCapability sequence requested media capabilities, CDMKeySystemConfiguration
+    // partial configuration, and restrictions, this algorithm returns a sequence of supported CDMMediaCapability values
+    // for this audio/video type or null as appropriate.
+
+    // 1. Let local accumulated configuration be a local copy of partial configuration.
+    CDMKeySystemConfiguration accumulatedConfiguration = partialConfiguration;
+
+    // 2. Let supported media capabilities be an empty sequence of CDMMediaCapability dictionaries.
+    Vector<CDMMediaCapability> supportedMediaCapabilities { };
+
+    // 3. For each requested media capability in requested media capabilities:
+    for (auto& requestedCapability : requestedCapabilities) {
+        // 3.1. Let content type be requested media capability's contentType member.
+        // 3.2. Let robustness be requested media capability's robustness member.
+        String robustness = requestedCapability.robustness;
+
+        // 3.3. If content type is the empty string, return null.
+        if (requestedCapability.contentType.isEmpty())
+            return WTF::nullopt;
+
+        // 3.4. If content type is an invalid or unrecognized MIME type, continue to the next iteration.
+        Optional<ParsedContentType> contentType = ParsedContentType::create(requestedCapability.contentType, Mode::Rfc2045);
+        if (!contentType)
+            continue;
+
+        // 3.5. Let container be the container type specified by content type.
+        String container = contentType->mimeType();
+
+        // 3.6. If the user agent does not support container, continue to the next iteration. The case-sensitivity
+        //      of string comparisons is determined by the appropriate RFC.
+        // 3.7. Let parameters be the RFC 6381 [RFC6381] parameters, if any, specified by content type.
+        // 3.8. If the user agent does not recognize one or more parameters, continue to the next iteration.
+        // 3.9. Let media types be the set of codecs and codec constraints specified by parameters. The case-sensitivity
+        //      of string comparisons is determined by the appropriate RFC or other specification.
+        String codecs = contentType->parameterValueForName("codecs");
+        if (contentType->parameterCount() > (codecs.isEmpty() ? 0 : 1))
+            continue;
+
+        // 3.10. If media types is empty:
+        if (codecs.isEmpty()) {
+            // ↳ If container normatively implies a specific set of codecs and codec constraints:
+            // ↳ Otherwise:
+            notImplemented();
+        }
+
+        // 3.11. If content type is not strictly a audio/video type, continue to the next iteration.
+        // 3.12. If robustness is not the empty string and contains an unrecognized value or a value not supported by
+        //       implementation, continue to the next iteration. String comparison is case-sensitive.
+        if (!robustness.isEmpty() && !supportedRobustnesses().contains(robustness))
+            continue;
+
+        // 3.13. If the user agent and implementation definitely support playback of encrypted media data for the
+        //       combination of container, media types, robustness and local accumulated configuration in combination
+        //       with restrictions:
+        MediaEngineSupportParameters parameters;
+        parameters.type = ContentType(contentType->mimeType());
+        if (MediaPlayer::supportsType(parameters) == MediaPlayer::SupportsType::IsNotSupported) {
+
+            // Try with Media Source:
+            parameters.isMediaSource = true;
+            if (MediaPlayer::supportsType(parameters) == MediaPlayer::SupportsType::IsNotSupported)
+                continue;
+        }
+
+        if (!supportsConfigurationWithRestrictions(accumulatedConfiguration, restrictions))
+            continue;
+
+        // 3.13.1. Add requested media capability to supported media capabilities.
+        supportedMediaCapabilities.append(requestedCapability);
+
+        // 3.13.2. ↳ If audio/video type is Video:
+        //         Add requested media capability to the videoCapabilities member of local accumulated configuration.
+        if (type == AudioVideoType::Video)
+            accumulatedConfiguration.videoCapabilities.append(requestedCapability);
+        // 3.13.2. ↳ If audio/video type is Audio:
+        //         Add requested media capability to the audioCapabilities member of local accumulated configuration.
+        else
+            accumulatedConfiguration.audioCapabilities.append(requestedCapability);
+    }
+
+    // 4. If supported media capabilities is empty, return null.
+    if (supportedMediaCapabilities.isEmpty())
+        return WTF::nullopt;
+
+    // 5. Return supported media capabilities.
+    return supportedMediaCapabilities;
+}
+
+void CDMPrivate::getConsentStatus(CDMKeySystemConfiguration&& accumulatedConfiguration, CDMRestrictions&& restrictions, LocalStorageAccess access, ConsentStatusCallback&& callback)
+{
+    // https://w3c.github.io/encrypted-media/#get-supported-configuration-and-consent
+    // W3C Editor's Draft 09 November 2016
+
+    // 3.1.1.2 Get Supported Configuration and Consent, ctd.
+    // 21. If accumulated configuration's distinctiveIdentifier value is "required" and the Distinctive Identifier(s) associated
+    //     with accumulated configuration are not unique per origin and profile and clearable:
+    if (accumulatedConfiguration.distinctiveIdentifier == CDMRequirement::Required && !distinctiveIdentifiersAreUniquePerOriginAndClearable(accumulatedConfiguration)) {
+        // 21.1. Update restrictions to reflect that all configurations described by accumulated configuration do not have user consent.
+        restrictions.distinctiveIdentifierDenied = true;
+        callback(ConsentStatus::ConsentDenied, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
+        return;
+    }
+
+    // https://w3c.github.io/encrypted-media/#get-consent-status
+    // 3.1.1.4 Get Consent Status
+    // Given an accumulated configuration, restrictions and origin, this algorithm returns the consent status for accumulated
+    // configuration and origin as one of ConsentDenied, InformUser or Allowed, together with an updated value for restrictions
+    // in the ConsentDenied case.
+
+    // 1. If there is persisted denial for origin indicating that accumulated configuration is not allowed, run the following steps:
+    // 1.1. Update restrictions to reflect the configurations for which consent has been denied.
+    // 1.2. Return ConsentDenied and restrictions.
+    // 2. If there is persisted consent for origin indicating accumulated configuration is allowed, return Allowed.
+    // NOTE: persisted denial / consent unimplemented.
+
+    // 3. If any of the following are true:
+    //    ↳ The distinctiveIdentifier member of accumulated configuration is not "not-allowed" and the combination of the User Agent,
+    //       implementation and accumulated configuration does not follow all the recommendations of Allow Persistent Data to Be Cleared
+    //       with respect to Distinctive Identifier(s).
+    // NOTE: assume that implementations follow all recommendations.
+
+    //    ↳ The user agent requires explicit user consent for the accumulated configuration for other reasons.
+    // NOTE: assume the user agent does not require explicit user consent.
+
+    // 3.1. Request user consent to use accumulated configuration in the origin and wait for the user response.
+    //      The consent must include consent to use a Distinctive Identifier(s) and/or Distinctive Permanent Identifier(s) as appropriate
+    //      if accumulated configuration's distinctiveIdentifier member is "required".
+    // 3.2. If consent was denied, run the following steps:
+    // 3.2.1. Update restrictions to reflect the configurations for which consent was denied.
+    // 3.2.1. Return ConsentDenied and restrictions.
+    // NOTE: assume implied consent if the combination of origin and topOrigin allows it.
+    if (accumulatedConfiguration.distinctiveIdentifier == CDMRequirement::Required && access == LocalStorageAccess::NotAllowed) {
+        restrictions.distinctiveIdentifierDenied = true;
+        callback(ConsentStatus::ConsentDenied, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
+        return;
+    }
+
+    // 4. If the distinctiveIdentifier member of accumulated configuration is not "not-allowed", return InformUser.
+    if (accumulatedConfiguration.distinctiveIdentifier != CDMRequirement::NotAllowed) {
+        callback(ConsentStatus::InformUser, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
+        return;
+    }
+
+    // 5. If the user agent requires informing the user for the accumulated configuration for other reasons, return InformUser.
+    // NOTE: assume the user agent does not require informing the user.
+
+    // 6. Return Allowed.
+    callback(ConsentStatus::Allowed, WTFMove(accumulatedConfiguration), WTFMove(restrictions));
+}
+
+
+}
+
+#endif
index 25f7816..f8d2c13 100644 (file)
 #include "CDMRequirement.h"
 #include "CDMSessionType.h"
 #include <wtf/Forward.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
 struct CDMKeySystemConfiguration;
+struct CDMMediaCapability;
 struct CDMRestrictions;
 
-class CDMPrivate {
+class CDMPrivate : public CanMakeWeakPtr<CDMPrivate> {
 public:
-    virtual ~CDMPrivate() = default;
+    WEBCORE_EXPORT virtual ~CDMPrivate();
 
-    virtual bool supportsInitDataType(const AtomString&) const = 0;
+    enum class LocalStorageAccess : bool {
+        NotAllowed,
+        Allowed,
+    };
+
+    using SupportedConfigurationCallback = WTF::Function<void(Optional<CDMKeySystemConfiguration>)>;
+    WEBCORE_EXPORT virtual void getSupportedConfiguration(CDMKeySystemConfiguration&& candidateConfiguration, LocalStorageAccess, SupportedConfigurationCallback&&);
+
+    virtual Vector<AtomString> supportedInitDataTypes() const = 0;
     virtual bool supportsConfiguration(const CDMKeySystemConfiguration&) const = 0;
     virtual bool supportsConfigurationWithRestrictions(const CDMKeySystemConfiguration&, const CDMRestrictions&) const = 0;
-    virtual bool supportsSessionTypeWithConfiguration(CDMSessionType&, const CDMKeySystemConfiguration&) const = 0;
-    virtual bool supportsRobustness(const String&) const = 0;
+    virtual bool supportsSessionTypeWithConfiguration(const CDMSessionType&, const CDMKeySystemConfiguration&) const = 0;
+    virtual Vector<AtomString> supportedRobustnesses() const = 0;
     virtual CDMRequirement distinctiveIdentifiersRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const = 0;
     virtual CDMRequirement persistentStateRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const = 0;
     virtual bool distinctiveIdentifiersAreUniquePerOriginAndClearable(const CDMKeySystemConfiguration&) const = 0;
@@ -56,6 +66,34 @@ public:
     virtual bool supportsInitData(const AtomString&, const SharedBuffer&) const = 0;
     virtual RefPtr<SharedBuffer> sanitizeResponse(const SharedBuffer&) const = 0;
     virtual Optional<String> sanitizeSessionId(const String&) const = 0;
+
+protected:
+    WEBCORE_EXPORT CDMPrivate();
+    static bool isPersistentType(CDMSessionType);
+
+    enum class ConfigurationStatus {
+        Supported,
+        NotSupported,
+        ConsentDenied,
+    };
+
+    enum class ConsentStatus {
+        ConsentDenied,
+        InformUser,
+        Allowed,
+    };
+
+    enum class AudioVideoType {
+        Audio,
+        Video,
+    };
+
+    void doSupportedConfigurationStep(CDMKeySystemConfiguration&& candidateConfiguration, CDMRestrictions&&, LocalStorageAccess, SupportedConfigurationCallback&&);
+    Optional<CDMKeySystemConfiguration> getSupportedConfiguration(const CDMKeySystemConfiguration& candidateConfiguration, CDMRestrictions&, LocalStorageAccess);
+    Optional<Vector<CDMMediaCapability>> getSupportedCapabilitiesForAudioVideoType(AudioVideoType, const Vector<CDMMediaCapability>& requestedCapabilities, const CDMKeySystemConfiguration& partialConfiguration, CDMRestrictions&);
+
+    using ConsentStatusCallback = WTF::Function<void(ConsentStatus, CDMKeySystemConfiguration&&, CDMRestrictions&&)>;
+    void getConsentStatus(CDMKeySystemConfiguration&& accumulatedConfiguration, CDMRestrictions&&, LocalStorageAccess, ConsentStatusCallback&&);
 };
 
 }
index 69ac12d..5b0b778 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include <wtf/Forward.h>
+
 namespace WebCore {
 
-enum class CDMRequirement {
+enum class CDMRequirement : uint8_t {
     Required,
     Optional,
     NotAllowed
@@ -40,4 +42,17 @@ enum class CDMRequirement {
 
 } // namespace WebCore
 
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::CDMRequirement> {
+    using values = EnumValues<
+        WebCore::CDMRequirement,
+        WebCore::CDMRequirement::Required,
+        WebCore::CDMRequirement::Optional,
+        WebCore::CDMRequirement::NotAllowed
+    >;
+};
+
+}
+
 #endif // ENABLE(ENCRYPTED_MEDIA)
index c52e282..9ca2ac5 100644 (file)
@@ -36,6 +36,39 @@ struct CDMRestrictions {
     bool distinctiveIdentifierDenied { false };
     bool persistentStateDenied { false };
     HashSet<CDMSessionType, WTF::IntHash<CDMSessionType>, WTF::StrongEnumHashTraits<CDMSessionType>> deniedSessionTypes;
+
+    template<class Encoder>
+    void encode(Encoder& encoder) const
+    {
+        encoder << distinctiveIdentifierDenied;
+        encoder << persistentStateDenied;
+        encoder << deniedSessionTypes;
+    }
+
+    template <class Decoder>
+    static Optional<CDMRestrictions> decode(Decoder& decoder)
+    {
+        Optional<bool> distinctiveIdentifierDenied;
+        decoder >> distinctiveIdentifierDenied;
+        if (!distinctiveIdentifierDenied)
+            return WTF::nullopt;
+
+        Optional<bool> persistentStateDenied;
+        decoder >> persistentStateDenied;
+        if (!persistentStateDenied)
+            return WTF::nullopt;
+
+        Optional<HashSet<CDMSessionType, WTF::IntHash<CDMSessionType>, WTF::StrongEnumHashTraits<CDMSessionType>>> deniedSessionTypes;
+        decoder >> deniedSessionTypes;
+        if (!deniedSessionTypes)
+            return WTF::nullopt;
+
+        return {{
+            *distinctiveIdentifierDenied,
+            *persistentStateDenied,
+            WTFMove(*deniedSessionTypes),
+        }};
+    }
 };
 
 } // namespace WebCore
index 60574a5..e07c300 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include <wtf/Forward.h>
+
 namespace WebCore {
 
-enum class CDMSessionType {
+enum class CDMSessionType : uint8_t {
     Temporary,
     PersistentUsageRecord,
     PersistentLicense
@@ -40,4 +42,17 @@ enum class CDMSessionType {
 
 } // namespace WebCore
 
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::CDMSessionType> {
+    using values = EnumValues<
+        WebCore::CDMSessionType,
+        WebCore::CDMSessionType::Temporary,
+        WebCore::CDMSessionType::PersistentUsageRecord,
+        WebCore::CDMSessionType::PersistentLicense
+    >;
+};
+
+}
+
 #endif // ENABLE(ENCRYPTED_MEDIA)
index 45111dc..daa3cec 100644 (file)
@@ -34,6 +34,7 @@
 #include "CDMKeySystemConfiguration.h"
 #include "CDMRestrictions.h"
 #include "CDMSessionType.h"
+#include "InitDataRegistry.h"
 #include "Logging.h"
 #include "SharedBuffer.h"
 #include <algorithm>
@@ -290,10 +291,13 @@ bool CDMFactoryClearKey::supportsKeySystem(const String& keySystem)
 CDMPrivateClearKey::CDMPrivateClearKey() = default;
 CDMPrivateClearKey::~CDMPrivateClearKey() = default;
 
-bool CDMPrivateClearKey::supportsInitDataType(const AtomString& initDataType) const
+Vector<AtomString> CDMPrivateClearKey::supportedInitDataTypes() const
 {
-    // `keyids` and 'cenc' are the only supported init data type.
-    return (equalLettersIgnoringASCIICase(initDataType, "keyids") || equalLettersIgnoringASCIICase(initDataType, "cenc") || equalLettersIgnoringASCIICase(initDataType, "webm"));
+    return {
+        InitDataRegistry::keyidsName(),
+        InitDataRegistry::cencName(),
+        InitDataRegistry::webmName(),
+    };
 }
 
 static bool containsPersistentLicenseType(const Vector<CDMSessionType>& types)
@@ -337,7 +341,7 @@ bool CDMPrivateClearKey::supportsConfigurationWithRestrictions(const CDMKeySyste
     return true;
 }
 
-bool CDMPrivateClearKey::supportsSessionTypeWithConfiguration(CDMSessionType& sessionType, const CDMKeySystemConfiguration& configuration) const
+bool CDMPrivateClearKey::supportsSessionTypeWithConfiguration(const CDMSessionType& sessionType, const CDMKeySystemConfiguration& configuration) const
 {
     // Only support the 'temporary' and 'persistent-license' session types.
     if (sessionType != CDMSessionType::Temporary && sessionType != CDMSessionType::PersistentLicense)
@@ -345,10 +349,10 @@ bool CDMPrivateClearKey::supportsSessionTypeWithConfiguration(CDMSessionType& se
     return supportsConfiguration(configuration);
 }
 
-bool CDMPrivateClearKey::supportsRobustness(const String& robustness) const
+Vector<AtomString> CDMPrivateClearKey::supportedRobustnesses() const
 {
     // Only empty `robustness` string is supported.
-    return robustness.isEmpty();
+    return { emptyAtom() };
 }
 
 CDMRequirement CDMPrivateClearKey::distinctiveIdentifiersRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions& restrictions) const
@@ -432,34 +436,20 @@ Optional<String> CDMPrivateClearKey::sanitizeSessionId(const String& sessionId)
 
 CDMInstanceClearKey::~CDMInstanceClearKey() = default;
 
-CDMInstance::SuccessValue CDMInstanceClearKey::initializeWithConfiguration(const CDMKeySystemConfiguration&)
+void CDMInstanceClearKey::initializeWithConfiguration(const CDMKeySystemConfiguration&, AllowDistinctiveIdentifiers distinctiveIdentifiers, AllowPersistentState persistentState, SuccessCallback&& callback)
 {
-    // No-op.
-    return Succeeded;
-}
-
-CDMInstance::SuccessValue CDMInstanceClearKey::setDistinctiveIdentifiersAllowed(bool allowed)
-{
-    // Reject setting distinctive identifiers as allowed.
-    return !allowed ? Succeeded : Failed;
-}
-
-CDMInstance::SuccessValue CDMInstanceClearKey::setPersistentStateAllowed(bool allowed)
-{
-    // Reject setting persistent state as allowed.
-    return !allowed ? Succeeded : Failed;
+    SuccessValue succeeded = (distinctiveIdentifiers == AllowDistinctiveIdentifiers::No && persistentState == AllowPersistentState::No) ? Succeeded : Failed;
+    callback(succeeded);
 }
 
-CDMInstance::SuccessValue CDMInstanceClearKey::setServerCertificate(Ref<SharedBuffer>&&)
+void CDMInstanceClearKey::setServerCertificate(Ref<SharedBuffer>&&, SuccessCallback&& callback)
 {
     // Reject setting any server certificate.
-    return Failed;
+    callback(Failed);
 }
 
-CDMInstance::SuccessValue CDMInstanceClearKey::setStorageDirectory(const String& storageDirectory)
+void CDMInstanceClearKey::setStorageDirectory(const String&)
 {
-    // Reject any persistent state storage.
-    return storageDirectory.isEmpty() ? Succeeded : Failed;
 }
 
 const String& CDMInstanceClearKey::keySystem() const
@@ -498,7 +488,7 @@ void CDMInstanceSessionClearKey::requestLicense(LicenseType, const AtomString& i
         });
 }
 
-void CDMInstanceSessionClearKey::updateLicense(const String& sessionId, LicenseType, const SharedBuffer& response, LicenseUpdateCallback&& callback)
+void CDMInstanceSessionClearKey::updateLicense(const String& sessionId, LicenseType, Ref<SharedBuffer>&& response, LicenseUpdateCallback&& callback)
 {
 #if LOG_DISABLED
     // We only use the sesion ID for debug logging. The verbose preprocessor checks are because
index 6704ae7..6697a04 100644 (file)
@@ -74,11 +74,11 @@ public:
     CDMPrivateClearKey();
     virtual ~CDMPrivateClearKey();
 
-    bool supportsInitDataType(const AtomString&) const final;
+    Vector<AtomString> supportedInitDataTypes() const final;
+    Vector<AtomString> supportedRobustnesses() const final;
     bool supportsConfiguration(const CDMKeySystemConfiguration&) const final;
     bool supportsConfigurationWithRestrictions(const CDMKeySystemConfiguration&, const CDMRestrictions&) const final;
-    bool supportsSessionTypeWithConfiguration(CDMSessionType&, const CDMKeySystemConfiguration&) const final;
-    bool supportsRobustness(const String&) const final;
+    bool supportsSessionTypeWithConfiguration(const CDMSessionType&, const CDMKeySystemConfiguration&) const final;
     CDMRequirement distinctiveIdentifiersRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const final;
     CDMRequirement persistentStateRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const final;
     bool distinctiveIdentifiersAreUniquePerOriginAndClearable(const CDMKeySystemConfiguration&) const final;
@@ -97,11 +97,9 @@ public:
 
     // CDMInstance
     ImplementationType implementationType() const final { return ImplementationType::ClearKey; }
-    SuccessValue initializeWithConfiguration(const CDMKeySystemConfiguration&) final;
-    SuccessValue setDistinctiveIdentifiersAllowed(bool) final;
-    SuccessValue setPersistentStateAllowed(bool) final;
-    SuccessValue setServerCertificate(Ref<SharedBuffer>&&) final;
-    SuccessValue setStorageDirectory(const String&) final;
+    void initializeWithConfiguration(const CDMKeySystemConfiguration&, AllowDistinctiveIdentifiers, AllowPersistentState, SuccessCallback&&) final;
+    void setServerCertificate(Ref<SharedBuffer>&&, SuccessCallback&&) final;
+    void setStorageDirectory(const String&) final;
     const String& keySystem() const final;
     RefPtr<CDMInstanceSession> createSession() final;
 };
@@ -111,7 +109,7 @@ public:
     CDMInstanceSessionClearKey(CDMInstanceClearKey& parent)
         : m_parentInstance(parent) { }
     void requestLicense(LicenseType, const AtomString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback&&) final;
-    void updateLicense(const String&, LicenseType, const SharedBuffer&, LicenseUpdateCallback&&) final;
+    void updateLicense(const String&, LicenseType, Ref<SharedBuffer>&&, LicenseUpdateCallback&&) final;
     void loadSession(LicenseType, const String&, const String&, LoadSessionCallback&&) final;
     void closeSession(const String&, CloseSessionCallback&&) final;
     void removeSessionData(const String&, LicenseType, RemoveSessionDataCallback&&) final;
index d11fbee..a3eb1cb 100644 (file)
@@ -657,6 +657,14 @@ void MediaPlayer::attemptToDecryptWithInstance(CDMInstance& instance)
 
 #endif
 
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+void MediaPlayer::setShouldContinueAfterKeyNeeded(bool should)
+{
+    m_shouldContinueAfterKeyNeeded = should;
+    m_private->setShouldContinueAfterKeyNeeded(should);
+}
+#endif
+
 MediaTime MediaPlayer::duration() const
 {
     return m_private->durationMediaTime();
@@ -1289,9 +1297,9 @@ RefPtr<ArrayBuffer> MediaPlayer::cachedKeyForKeyId(const String& keyId) const
     return client().mediaPlayerCachedKeyForKeyId(keyId);
 }
 
-bool MediaPlayer::keyNeeded(Uint8Array* initData)
+void MediaPlayer::keyNeeded(Uint8Array* initData)
 {
-    return client().mediaPlayerKeyNeeded(initData);
+    client().mediaPlayerKeyNeeded(initData);
 }
 
 String MediaPlayer::mediaKeysStorageDirectory() const
index ff696eb..1fdd5ba 100644 (file)
@@ -200,7 +200,7 @@ public:
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     virtual RefPtr<ArrayBuffer> mediaPlayerCachedKeyForKeyId(const String&) const { return nullptr; }
-    virtual bool mediaPlayerKeyNeeded(Uint8Array*) { return false; }
+    virtual void mediaPlayerKeyNeeded(Uint8Array*) { }
     virtual String mediaPlayerMediaKeysStorageDirectory() const { return emptyString(); }
 #endif
 
@@ -366,6 +366,11 @@ public:
     void attemptToDecryptWithInstance(CDMInstance&);
 #endif
 
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    void setShouldContinueAfterKeyNeeded(bool);
+    bool shouldContinueAfterKeyNeeded() const { return m_shouldContinueAfterKeyNeeded; }
+#endif
+
     bool paused() const;
     bool seeking() const;
 
@@ -510,7 +515,7 @@ public:
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     RefPtr<ArrayBuffer> cachedKeyForKeyId(const String& keyId) const;
-    bool keyNeeded(Uint8Array* initData);
+    void keyNeeded(Uint8Array* initData);
     String mediaKeysStorageDirectory() const;
 #endif
 
@@ -656,6 +661,9 @@ private:
 #if ENABLE(MEDIA_STREAM)
     RefPtr<MediaStreamPrivate> m_mediaStream;
 #endif
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    bool m_shouldContinueAfterKeyNeeded { false };
+#endif
 };
 
 class MediaPlayerFactory {
index 9a080fe..ed6185d 100644 (file)
@@ -234,6 +234,10 @@ public:
     virtual bool waitingForKey() const { return false; }
 #endif
 
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    virtual void setShouldContinueAfterKeyNeeded(bool) { }
+#endif
+
 #if ENABLE(VIDEO_TRACK)
     virtual bool requiresTextTrackRepresentation() const { return false; }
     virtual void setTextTrackRepresentation(TextTrackRepresentation*) { }
index 4fc6787..b6babfc 100644 (file)
@@ -247,9 +247,9 @@ bool CDMFactoryFairPlayStreaming::supportsKeySystem(const String& keySystem)
 CDMPrivateFairPlayStreaming::CDMPrivateFairPlayStreaming() = default;
 CDMPrivateFairPlayStreaming::~CDMPrivateFairPlayStreaming() = default;
 
-bool CDMPrivateFairPlayStreaming::supportsInitDataType(const AtomString& initDataType) const
+Vector<AtomString> CDMPrivateFairPlayStreaming::supportedInitDataTypes() const
 {
-    return validInitDataTypes().contains(initDataType);
+    return copyToVector(validInitDataTypes());
 }
 
 bool CDMPrivateFairPlayStreaming::supportsConfiguration(const CDMKeySystemConfiguration& configuration) const
@@ -305,7 +305,7 @@ bool CDMPrivateFairPlayStreaming::supportsConfigurationWithRestrictions(const CD
     return supportsConfiguration(configuration);
 }
 
-bool CDMPrivateFairPlayStreaming::supportsSessionTypeWithConfiguration(CDMSessionType& sessionType, const CDMKeySystemConfiguration& configuration) const
+bool CDMPrivateFairPlayStreaming::supportsSessionTypeWithConfiguration(const CDMSessionType& sessionType, const CDMKeySystemConfiguration& configuration) const
 {
     if (sessionType == CDMSessionType::Temporary) {
         if (configuration.persistentState == CDMRequirement::Required)
@@ -316,13 +316,10 @@ bool CDMPrivateFairPlayStreaming::supportsSessionTypeWithConfiguration(CDMSessio
     return supportsConfiguration(configuration);
 }
 
-bool CDMPrivateFairPlayStreaming::supportsRobustness(const String& robustness) const
+Vector<AtomString> CDMPrivateFairPlayStreaming::supportedRobustnesses() const
 {
-    if (robustness.isEmpty())
-        return true;
-
     // FIXME: Determine an enumerated list of robustness values supported by FPS.
-    return false;
+    return { emptyAtom() };
 }
 
 CDMRequirement CDMPrivateFairPlayStreaming::distinctiveIdentifiersRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const
@@ -366,7 +363,7 @@ bool CDMPrivateFairPlayStreaming::supportsSessions() const
 
 bool CDMPrivateFairPlayStreaming::supportsInitData(const AtomString& initDataType, const SharedBuffer& initData) const
 {
-    if (!supportsInitDataType(initDataType))
+    if (!validInitDataTypes().contains(initDataType))
         return false;
 
     if (initDataType == sinfName()) {
index 5386969..387b9f9 100644 (file)
@@ -55,11 +55,11 @@ public:
     CDMPrivateFairPlayStreaming();
     virtual ~CDMPrivateFairPlayStreaming();
 
-    bool supportsInitDataType(const AtomString&) const override;
+    Vector<AtomString> supportedInitDataTypes() const override;
     bool supportsConfiguration(const CDMKeySystemConfiguration&) const override;
     bool supportsConfigurationWithRestrictions(const CDMKeySystemConfiguration&, const CDMRestrictions&) const override;
-    bool supportsSessionTypeWithConfiguration(CDMSessionType&, const CDMKeySystemConfiguration&) const override;
-    bool supportsRobustness(const String&) const override;
+    bool supportsSessionTypeWithConfiguration(const CDMSessionType&, const CDMKeySystemConfiguration&) const override;
+    Vector<AtomString> supportedRobustnesses() const override;
     CDMRequirement distinctiveIdentifiersRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const override;
     CDMRequirement persistentStateRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const override;
     bool distinctiveIdentifiersAreUniquePerOriginAndClearable(const CDMKeySystemConfiguration&) const override;
index 70eac36..5d9a9a0 100644 (file)
@@ -1931,9 +1931,7 @@ bool AVFWrapper::shouldWaitForLoadingOfResource(AVCFAssetResourceLoadingRequestR
 
         unsigned byteLength = initDataBuffer->byteLength();
         auto initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
-        if (!m_owner->player()->keyNeeded(initData.ptr()))
-            return false;
-
+        m_owner->player()->keyNeeded(initData.ptr());
         setRequestForKey(keyURI, avRequest);
         return true;
     }
index b11f71a..00b6fb8 100644 (file)
@@ -74,11 +74,9 @@ public:
 
     ImplementationType implementationType() const final { return ImplementationType::FairPlayStreaming; }
 
-    SuccessValue initializeWithConfiguration(const CDMKeySystemConfiguration&) final;
-    SuccessValue setDistinctiveIdentifiersAllowed(bool) final;
-    SuccessValue setPersistentStateAllowed(bool) final;
-    SuccessValue setServerCertificate(Ref<SharedBuffer>&&) final;
-    SuccessValue setStorageDirectory(const String&) final;
+    void initializeWithConfiguration(const CDMKeySystemConfiguration&, AllowDistinctiveIdentifiers, AllowPersistentState, SuccessCallback&&) final;
+    void setServerCertificate(Ref<SharedBuffer>&&, SuccessCallback&&) final;
+    void setStorageDirectory(const String&) final;
     RefPtr<CDMInstanceSession> createSession() final;
 
     const String& keySystem() const final;
@@ -120,7 +118,7 @@ public:
 
     // CDMInstanceSession
     void requestLicense(LicenseType, const AtomString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback&&) final;
-    void updateLicense(const String&, LicenseType, const SharedBuffer&, LicenseUpdateCallback&&) final;
+    void updateLicense(const String&, LicenseType, Ref<SharedBuffer>&&, LicenseUpdateCallback&&) final;
     void loadSession(LicenseType, const String&, const String&, LoadSessionCallback&&) final;
     void closeSession(const String&, CloseSessionCallback&&) final;
     void removeSessionData(const String&, LicenseType, RemoveSessionDataCallback&&) final;
index 7326775..2a8bb38 100644 (file)
@@ -268,72 +268,63 @@ bool CDMInstanceFairPlayStreamingAVFObjC::supportsMediaCapability(const CDMMedia
     return true;
 }
 
-CDMInstance::SuccessValue CDMInstanceFairPlayStreamingAVFObjC::initializeWithConfiguration(const CDMKeySystemConfiguration& configuration)
+void CDMInstanceFairPlayStreamingAVFObjC::initializeWithConfiguration(const CDMKeySystemConfiguration& configuration, AllowDistinctiveIdentifiers, AllowPersistentState persistentState, SuccessCallback&& callback)
 {
     // FIXME: verify that FairPlayStreaming does not (and cannot) expose a distinctive identifier to the client
-    if (configuration.distinctiveIdentifier == CDMRequirement::Required)
-        return Failed;
-
-    if (configuration.persistentState != CDMRequirement::Required && (configuration.sessionTypes.contains(CDMSessionType::PersistentUsageRecord) || configuration.sessionTypes.contains(CDMSessionType::PersistentLicense)))
-        return Failed;
-
-    if (configuration.persistentState == CDMRequirement::Required && !m_storageURL)
-        return Failed;
+    auto initialize = [&] () {
+        if (configuration.distinctiveIdentifier == CDMRequirement::Required)
+            return Failed;
 
-    if (configuration.sessionTypes.contains(CDMSessionType::PersistentLicense) && !supportsPersistentKeys())
-        return Failed;
+        if (configuration.persistentState != CDMRequirement::Required && (configuration.sessionTypes.contains(CDMSessionType::PersistentUsageRecord) || configuration.sessionTypes.contains(CDMSessionType::PersistentLicense)))
+            return Failed;
 
-    if (!PAL::canLoad_AVFoundation_AVContentKeySystemFairPlayStreaming())
-        return Failed;
+        if (configuration.persistentState == CDMRequirement::Required && !m_storageURL)
+            return Failed;
 
-    return Succeeded;
-}
+        if (configuration.sessionTypes.contains(CDMSessionType::PersistentLicense) && !supportsPersistentKeys())
+            return Failed;
 
-CDMInstance::SuccessValue CDMInstanceFairPlayStreamingAVFObjC::setDistinctiveIdentifiersAllowed(bool)
-{
-    // FIXME: verify that FairPlayStreaming does not (and cannot) expose a distinctive identifier to the client
-    return Succeeded;
-}
+        if (!PAL::canLoad_AVFoundation_AVContentKeySystemFairPlayStreaming())
+            return Failed;
 
-CDMInstance::SuccessValue CDMInstanceFairPlayStreamingAVFObjC::setPersistentStateAllowed(bool persistentStateAllowed)
-{
-    m_persistentStateAllowed = persistentStateAllowed;
-    return Succeeded;
+        m_persistentStateAllowed = persistentState == AllowPersistentState::Yes;
+        return Succeeded;
+    };
+    callback(initialize());
 }
 
-CDMInstance::SuccessValue CDMInstanceFairPlayStreamingAVFObjC::setServerCertificate(Ref<SharedBuffer>&& serverCertificate)
+void CDMInstanceFairPlayStreamingAVFObjC::setServerCertificate(Ref<SharedBuffer>&& serverCertificate, SuccessCallback&& callback)
 {
     m_serverCertificate = WTFMove(serverCertificate);
-    return Succeeded;
+    callback(Succeeded);
 }
 
-CDMInstance::SuccessValue CDMInstanceFairPlayStreamingAVFObjC::setStorageDirectory(const String& storageDirectory)
+void CDMInstanceFairPlayStreamingAVFObjC::setStorageDirectory(const String& storageDirectory)
 {
     if (storageDirectory.isEmpty()) {
         m_storageURL = nil;
-        return Succeeded;
+        return;
     }
 
     auto storagePath = FileSystem::pathByAppendingComponent(storageDirectory, "SecureStop.plist");
 
     if (!FileSystem::fileExists(storageDirectory)) {
         if (!FileSystem::makeAllDirectories(storageDirectory))
-            return Failed;
+            return;
     } else if (!FileSystem::fileIsDirectory(storageDirectory, FileSystem::ShouldFollowSymbolicLinks::Yes)) {
         auto tempDirectory = FileSystem::createTemporaryDirectory(@"MediaKeys");
         if (!tempDirectory)
-            return Failed;
+            return;
 
         auto tempStoragePath = FileSystem::pathByAppendingComponent(tempDirectory, FileSystem::pathGetFileName(storagePath));
         if (!FileSystem::moveFile(storageDirectory, tempStoragePath))
-            return Failed;
+            return;
 
         if (!FileSystem::moveFile(tempDirectory, storageDirectory))
-            return Failed;
+            return;
     }
 
     m_storageURL = adoptNS([[NSURL alloc] initFileURLWithPath:storagePath isDirectory:NO]);
-    return Succeeded;
 }
 
 RefPtr<CDMInstanceSession> CDMInstanceFairPlayStreamingAVFObjC::createSession()
@@ -580,7 +571,7 @@ static bool isEqual(const SharedBuffer& data, const String& value)
     return stringOrException.returnValue() == value;
 }
 
-void CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense(const String&, LicenseType, const SharedBuffer& responseData, LicenseUpdateCallback&& callback)
+void CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense(const String&, LicenseType, Ref<SharedBuffer>&& responseData, LicenseUpdateCallback&& callback)
 {
     if (!m_expiredSessions.isEmpty() && isEqual(responseData, "acknowledged"_s)) {
         auto expiredSessions = adoptNS([[NSMutableArray alloc] init]);
@@ -711,7 +702,7 @@ void CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense(const String&, Li
             }
         }
     } else
-        [m_currentRequest.value().requests.first() processContentKeyResponse:[PAL::getAVContentKeyResponseClass() contentKeyResponseWithFairPlayStreamingKeyResponseData:responseData.createNSData().get()]];
+        [m_currentRequest.value().requests.first() processContentKeyResponse:[PAL::getAVContentKeyResponseClass() contentKeyResponseWithFairPlayStreamingKeyResponseData:responseData->createNSData().get()]];
 
     // FIXME(rdar://problem/35592277): stash the callback and call it once AVContentKeyResponse supports a success callback.
     struct objc_method_description method = protocol_getMethodDescription(@protocol(AVContentKeySessionDelegate), @selector(contentKeySession:contentKeyRequestDidSucceed:), NO, YES);
@@ -1140,7 +1131,8 @@ void CDMInstanceSessionFairPlayStreamingAVFObjC::sessionIdentifierChanged(NSData
         return;
 
     m_sessionId = sessionId;
-    m_client->sessionIdChanged(m_sessionId);
+    if (m_client)
+        m_client->sessionIdChanged(m_sessionId);
 }
 
 void CDMInstanceSessionFairPlayStreamingAVFObjC::groupSessionIdentifierChanged(AVContentKeyReportGroup* group, NSData *sessionIdentifier)
index f2a86ca..6dfc013 100644 (file)
@@ -1678,8 +1678,11 @@ bool MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource(AVAssetR
         keyURIArray->setRange(StringView(keyURI).upconvertedCharacters(), keyURI.length() / sizeof(unsigned char), 0);
 
         auto initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
-        if (!player()->keyNeeded(initData.ptr()))
-            return false;
+        player()->keyNeeded(initData.ptr());
+#if ENABLE(ENCRYPTED_MEDIA)
+        if (!player()->shouldContinueAfterKeyNeeded())
+            return true;
+#endif
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
@@ -1713,7 +1716,9 @@ bool MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource(AVAssetR
             return false;
         }
 
-        if (!player()->keyNeeded(initData.ptr()))
+        player()->keyNeeded(initData.ptr());
+
+        if (!player()->shouldContinueAfterKeyNeeded())
             return false;
 
         m_keyURIToRequestMap.set(keyID, avRequest);
index ce5d8f7..891964b 100644 (file)
@@ -98,6 +98,11 @@ void MockCDMFactory::setSupportedDataTypes(Vector<String>&& types)
         m_supportedDataTypes.append(type);
 }
 
+void MockCDMFactory::setSupportedRobustness(Vector<String>&& robustnesses)
+{
+    m_supportedRobustness = robustnesses.map([] (auto& robustness) -> AtomString { return robustness; });
+}
+
 std::unique_ptr<CDMPrivate> MockCDMFactory::createCDM(const String&)
 {
     return makeUnique<MockCDM>(makeWeakPtr(*this));
@@ -108,11 +113,18 @@ MockCDM::MockCDM(WeakPtr<MockCDMFactory> factory)
 {
 }
 
-bool MockCDM::supportsInitDataType(const AtomString& initDataType) const
+Vector<AtomString> MockCDM::supportedInitDataTypes() const
+{
+    if (m_factory)
+        return m_factory->supportedDataTypes();
+    return { };
+}
+
+Vector<AtomString> MockCDM::supportedRobustnesses() const
 {
     if (m_factory)
-        return m_factory->supportedDataTypes().contains(initDataType);
-    return false;
+        return m_factory->supportedRobustness();
+    return { };
 }
 
 bool MockCDM::supportsConfiguration(const MediaKeySystemConfiguration& configuration) const
@@ -139,7 +151,7 @@ bool MockCDM::supportsConfigurationWithRestrictions(const MediaKeySystemConfigur
     return true;
 }
 
-bool MockCDM::supportsSessionTypeWithConfiguration(MediaKeySessionType& sessionType, const MediaKeySystemConfiguration&) const
+bool MockCDM::supportsSessionTypeWithConfiguration(const MediaKeySessionType& sessionType, const MediaKeySystemConfiguration&) const
 {
     if (!m_factory || !m_factory->supportedSessionTypes().contains(sessionType))
         return false;
@@ -148,13 +160,6 @@ bool MockCDM::supportsSessionTypeWithConfiguration(MediaKeySessionType& sessionT
     return true;
 }
 
-bool MockCDM::supportsRobustness(const String& robustness) const
-{
-    if (m_factory)
-        return m_factory->supportedRobustness().contains(robustness);
-    return false;
-}
-
 MediaKeysRequirement MockCDM::distinctiveIdentifiersRequirement(const MediaKeySystemConfiguration&, const MediaKeysRestrictions&) const
 {
     if (m_factory)
@@ -199,7 +204,7 @@ bool MockCDM::supportsSessions() const
 
 bool MockCDM::supportsInitData(const AtomString& initDataType, const SharedBuffer& initData) const
 {
-    if (!supportsInitDataType(initDataType))
+    if (!supportedInitDataTypes().contains(initDataType))
         return false;
 
     UNUSED_PARAM(initData);
@@ -231,55 +236,48 @@ MockCDMInstance::MockCDMInstance(WeakPtr<MockCDM> cdm)
 {
 }
 
-CDMInstance::SuccessValue MockCDMInstance::initializeWithConfiguration(const MediaKeySystemConfiguration& configuration)
+void MockCDMInstance::initializeWithConfiguration(const MediaKeySystemConfiguration& configuration, AllowDistinctiveIdentifiers distinctiveIdentifiers, AllowPersistentState persistentState, SuccessCallback&& callback)
 {
-    if (!m_cdm || !m_cdm->supportsConfiguration(configuration))
-        return Failed;
+    auto initialize = [&] {
+        if (!m_cdm || !m_cdm->supportsConfiguration(configuration))
+            return Failed;
 
-    return Succeeded;
-}
+        MockCDMFactory* factory = m_cdm ? m_cdm->factory() : nullptr;
+        if (!factory)
+            return Failed;
 
-CDMInstance::SuccessValue MockCDMInstance::setDistinctiveIdentifiersAllowed(bool distinctiveIdentifiersAllowed)
-{
-    if (m_distinctiveIdentifiersAllowed == distinctiveIdentifiersAllowed)
-        return Succeeded;
+        bool distinctiveIdentifiersAllowed = (distinctiveIdentifiers == AllowDistinctiveIdentifiers::Yes);
 
-    auto* factory = m_cdm ? m_cdm->factory() : nullptr;
+        if (m_distinctiveIdentifiersAllowed != distinctiveIdentifiersAllowed) {
+            if (!distinctiveIdentifiersAllowed && factory->distinctiveIdentifiersRequirement() == MediaKeysRequirement::Required)
+                return Failed;
 
-    if (!factory || (!distinctiveIdentifiersAllowed && factory->distinctiveIdentifiersRequirement() == MediaKeysRequirement::Required))
-        return Failed;
+            m_distinctiveIdentifiersAllowed = distinctiveIdentifiersAllowed;
+        }
 
-    m_distinctiveIdentifiersAllowed = distinctiveIdentifiersAllowed;
-    return Succeeded;
-}
+        bool persistentStateAllowed = (persistentState == AllowPersistentState::Yes);
 
-CDMInstance::SuccessValue MockCDMInstance::setPersistentStateAllowed(bool persistentStateAllowed)
-{
-    if (m_persistentStateAllowed == persistentStateAllowed)
-        return Succeeded;
+        if (m_persistentStateAllowed != persistentStateAllowed) {
+            if (!persistentStateAllowed && factory->persistentStateRequirement() == MediaKeysRequirement::Required)
+                return Failed;
 
-    MockCDMFactory* factory = m_cdm ? m_cdm->factory() : nullptr;
-
-    if (!factory || (!persistentStateAllowed && factory->persistentStateRequirement() == MediaKeysRequirement::Required))
-        return Failed;
+            m_persistentStateAllowed = persistentStateAllowed;
+        }
+        return Succeeded;
+    };
 
-    m_persistentStateAllowed = persistentStateAllowed;
-    return Succeeded;
+    callback(initialize());
 }
 
-CDMInstance::SuccessValue MockCDMInstance::setServerCertificate(Ref<SharedBuffer>&& certificate)
+void MockCDMInstance::setServerCertificate(Ref<SharedBuffer>&& certificate, SuccessCallback&& callback)
 {
     StringView certificateStringView(certificate->data(), certificate->size());
 
-    if (equalIgnoringASCIICase(certificateStringView, "valid"))
-        return Succeeded;
-    return Failed;
+    callback(equalIgnoringASCIICase(certificateStringView, "valid") ? Succeeded : Failed);
 }
 
-CDMInstance::SuccessValue MockCDMInstance::setStorageDirectory(const String&)
+void MockCDMInstance::setStorageDirectory(const String&)
 {
-    // On disk storage is unused; no-op.
-    return Succeeded;
 }
 
 const String& MockCDMInstance::keySystem() const
@@ -325,7 +323,7 @@ void MockCDMInstanceSession::requestLicense(LicenseType licenseType, const AtomS
     callback(SharedBuffer::create(license.data(), license.length()), sessionID, false, SuccessValue::Succeeded);
 }
 
-void MockCDMInstanceSession::updateLicense(const String& sessionID, LicenseType, const SharedBuffer& response, LicenseUpdateCallback&& callback)
+void MockCDMInstanceSession::updateLicense(const String& sessionID, LicenseType, Ref<SharedBuffer>&& response, LicenseUpdateCallback&& callback)
 {
     MockCDMFactory* factory = m_instance ? m_instance->factory() : nullptr;
     if (!factory) {
@@ -333,7 +331,7 @@ void MockCDMInstanceSession::updateLicense(const String& sessionID, LicenseType,
         return;
     }
 
-    Vector<String> responseVector = String(response.data(), response.size()).split(' ');
+    Vector<String> responseVector = String(response->data(), response->size()).split(' ');
 
     if (responseVector.contains(String("invalid-format"_s))) {
         callback(false, WTF::nullopt, WTF::nullopt, WTF::nullopt, SuccessValue::Failed);
index 39909b9..370b6e2 100644 (file)
@@ -52,8 +52,8 @@ public:
     const Vector<MediaKeySessionType>& supportedSessionTypes() const { return m_supportedSessionTypes; }
     void setSupportedSessionTypes(Vector<MediaKeySessionType>&& types) { m_supportedSessionTypes = WTFMove(types); }
 
-    const Vector<String>& supportedRobustness() const { return m_supportedRobustness; }
-    void setSupportedRobustness(Vector<String>&& robustness) { m_supportedRobustness = WTFMove(robustness); }
+    const Vector<AtomString>& supportedRobustness() const { return m_supportedRobustness; }
+    void setSupportedRobustness(Vector<String>&&);
 
     MediaKeysRequirement distinctiveIdentifiersRequirement() const { return m_distinctiveIdentifiersRequirement; }
     void setDistinctiveIdentifiersRequirement(MediaKeysRequirement requirement) { m_distinctiveIdentifiersRequirement = requirement; }
@@ -90,7 +90,7 @@ private:
     MediaKeysRequirement m_persistentStateRequirement { MediaKeysRequirement::Optional };
     Vector<AtomString> m_supportedDataTypes;
     Vector<MediaKeySessionType> m_supportedSessionTypes;
-    Vector<String> m_supportedRobustness;
+    Vector<AtomString> m_supportedRobustness;
     Vector<MediaKeyEncryptionScheme> m_supportedEncryptionSchemes;
     bool m_registered { true };
     bool m_canCreateInstances { true };
@@ -99,7 +99,7 @@ private:
     HashMap<String, Vector<Ref<SharedBuffer>>> m_sessions;
 };
 
-class MockCDM : public CDMPrivate, public CanMakeWeakPtr<MockCDM> {
+class MockCDM : public CDMPrivate {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     MockCDM(WeakPtr<MockCDMFactory>);
@@ -109,11 +109,11 @@ public:
 private:
     friend class MockCDMInstance;
 
-    bool supportsInitDataType(const AtomString&) const final;
+    Vector<AtomString> supportedInitDataTypes() const final;
+    Vector<AtomString> supportedRobustnesses() const final;
     bool supportsConfiguration(const MediaKeySystemConfiguration&) const final;
     bool supportsConfigurationWithRestrictions(const MediaKeySystemConfiguration&, const MediaKeysRestrictions&) const final;
-    bool supportsSessionTypeWithConfiguration(MediaKeySessionType&, const MediaKeySystemConfiguration&) const final;
-    bool supportsRobustness(const String&) const final;
+    bool supportsSessionTypeWithConfiguration(const MediaKeySessionType&, const MediaKeySystemConfiguration&) const final;
     MediaKeysRequirement distinctiveIdentifiersRequirement(const MediaKeySystemConfiguration&, const MediaKeysRestrictions&) const final;
     MediaKeysRequirement persistentStateRequirement(const MediaKeySystemConfiguration&, const MediaKeysRestrictions&) const final;
     bool distinctiveIdentifiersAreUniquePerOriginAndClearable(const MediaKeySystemConfiguration&) const final;
@@ -138,11 +138,9 @@ public:
 
 private:
     ImplementationType implementationType() const final { return ImplementationType::Mock; }
-    SuccessValue initializeWithConfiguration(const MediaKeySystemConfiguration&) final;
-    SuccessValue setDistinctiveIdentifiersAllowed(bool) final;
-    SuccessValue setPersistentStateAllowed(bool) final;
-    SuccessValue setServerCertificate(Ref<SharedBuffer>&&) final;
-    SuccessValue setStorageDirectory(const String&) final;
+    void initializeWithConfiguration(const MediaKeySystemConfiguration&, AllowDistinctiveIdentifiers, AllowPersistentState, SuccessCallback&&) final;
+    void setServerCertificate(Ref<SharedBuffer>&&, SuccessCallback&&) final;
+    void setStorageDirectory(const String&) final;
     const String& keySystem() const final;
     RefPtr<CDMInstanceSession> createSession() final;
 
@@ -157,7 +155,7 @@ public:
 
 private:
     void requestLicense(LicenseType, const AtomString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback&&) final;
-    void updateLicense(const String&, LicenseType, const SharedBuffer&, LicenseUpdateCallback&&) final;
+    void updateLicense(const String&, LicenseType, Ref<SharedBuffer>&&, LicenseUpdateCallback&&) final;
     void loadSession(LicenseType, const String&, const String&, LoadSessionCallback&&) final;
     void closeSession(const String&, CloseSessionCallback&&) final;
     void removeSessionData(const String&, LicenseType, RemoveSessionDataCallback&&) final;
index c8b547d..84b184c 100644 (file)
@@ -1,3 +1,19 @@
+2020-02-28  Jer Noble  <jer.noble@apple.com>
+
+        [GPUP] Implement Modern EME API in the GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=208090
+
+        Reviewed by Eric Carlson.
+
+        Adopt changes to MediaPlayerProxy.
+
+        * GPUProcess/media/RemoteMediaPlayerProxy.cpp:
+        (WebKit::RemoteMediaPlayerProxy::mediaPlayerKeyNeeded):
+        * GPUProcess/media/RemoteMediaPlayerProxy.h:
+        * WebProcess/GPU/media/WebMediaStrategy.cpp:
+        (WebKit::WebMediaStrategy::registerCDMFactories):
+        * WebProcess/GPU/media/WebMediaStrategy.h:
+
 2020-02-28  Tim Horton  <timothy_horton@apple.com>
 
         macCatalyst: 'Open' context menu item doesn't work
index 891b1d7..fe8844b 100644 (file)
@@ -522,10 +522,9 @@ RefPtr<ArrayBuffer> RemoteMediaPlayerProxy::mediaPlayerCachedKeyForKeyId(const S
     return nullptr;
 }
 
-bool RemoteMediaPlayerProxy::mediaPlayerKeyNeeded(Uint8Array*)
+void RemoteMediaPlayerProxy::mediaPlayerKeyNeeded(Uint8Array*)
 {
     notImplemented();
-    return false;
 }
 #endif
 
index fb24d17..f78ec06 100644 (file)
@@ -180,7 +180,7 @@ private:
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     RefPtr<ArrayBuffer> mediaPlayerCachedKeyForKeyId(const String&) const final;
-    bool mediaPlayerKeyNeeded(Uint8Array*) final;
+    void mediaPlayerKeyNeeded(Uint8Array*) final;
     String mediaPlayerMediaKeysStorageDirectory() const final;
 #endif
 
@@ -264,6 +264,10 @@ private:
     WebCore::LayoutRect m_videoContentBoxRect;
     float m_videoContentScale { 1.0 };
 
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) && ENABLE(ENCRYPTED_MEDIA)
+    bool m_shouldContinueAfterKeyNeeded { false };
+#endif
+
 #if !RELEASE_LOG_DISABLED
     const Logger& m_logger;
 #endif
index 3912b40..2aae5e5 100644 (file)
@@ -30,6 +30,7 @@
 #include "RemoteAudioDestinationProxy.h"
 #include <WebCore/AudioDestination.h>
 #include <WebCore/AudioIOCallback.h>
+#include <WebCore/CDMFactory.h>
 
 namespace WebKit {
 
@@ -47,4 +48,11 @@ std::unique_ptr<WebCore::AudioDestination> WebMediaStrategy::createAudioDestinat
 }
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA)
+void WebMediaStrategy::registerCDMFactories(Vector<WebCore::CDMFactory*>& factories)
+{
+    return WebCore::CDMFactory::platformRegisterFactories(factories);
+}
+#endif
+
 } // namespace WebKit
index e19a53a..4fab0e9 100644 (file)
@@ -42,6 +42,9 @@ private:
     std::unique_ptr<WebCore::AudioDestination> createAudioDestination(WebCore::AudioIOCallback&,
         const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, float sampleRate) override;
 #endif
+#if ENABLE(ENCRYPTED_MEDIA)
+    void registerCDMFactories(Vector<WebCore::CDMFactory*>&) override;
+#endif
 
 #if ENABLE(GPU_PROCESS)
     bool m_useGPUProcess { false };
index c1279a7..1959edd 100644 (file)
@@ -1,3 +1,17 @@
+2020-02-28  Jer Noble  <jer.noble@apple.com>
+
+        [GPUP] Implement Modern EME API in the GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=208090
+
+        Reviewed by Eric Carlson.
+
+        Adopt changes to PlatformStrategies.
+
+        * GPUProcess/media/RemoteMediaPlayerProxy.cpp:
+        (WebKit::RemoteMediaPlayerProxy::mediaPlayerKeyNeeded):
+        * GPUProcess/media/RemoteMediaPlayerProxy.h:
+        * WebCoreSupport/WebPlatformStrategies.mm:
+
 2020-02-27  Daniel Bates  <dabates@apple.com>
 
         Change HitTestRequestType to an OptionSet
index 60f3451..b909ecc 100644 (file)
@@ -30,6 +30,7 @@
 #import "WebResourceLoadScheduler.h"
 #import <WebCore/AudioDestination.h>
 #import <WebCore/BlobRegistryImpl.h>
+#import <WebCore/CDMFactory.h>
 #import <WebCore/Color.h>
 #import <WebCore/Frame.h>
 #import <WebCore/MediaStrategy.h>
@@ -73,6 +74,12 @@ private:
         return AudioDestination::create(callback, inputDeviceId, numberOfInputChannels, numberOfOutputChannels, sampleRate);
     }
 #endif
+#if ENABLE(ENCRYPTED_MEDIA)
+    void registerCDMFactories(Vector<CDMFactory*>& factories) override
+    {
+        return WebCore::CDMFactory::platformRegisterFactories(factories);
+    }
+#endif
 };
 
 MediaStrategy* WebPlatformStrategies::createMediaStrategy()