Make a generic CDMPrivateMediaPlayer and move its CDMSession into platform/.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Feb 2014 00:13:01 +0000 (00:13 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Feb 2014 00:13:01 +0000 (00:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129164

Reviewed by Eric Carlson.

Move the session created by CDMPrivateAVFoundation into platform, and rename
CDMPrivateAVFoundation to CDMPrivateMediaPlayer. Future media engines who want
to support a keysystem from within the media engine can create their own
CDMSession as part of the MediaPlayerPrivate interface.

* Modules/encryptedmedia/CDM.cpp:
(WebCore::installedCDMFactories):
(WebCore::CDM::createSession):
* Modules/encryptedmedia/CDM.h:
* Modules/encryptedmedia/CDMPrivate.h:
* Modules/encryptedmedia/MediaKeySession.cpp:
* Modules/encryptedmedia/MediaKeySession.h:
* Modules/encryptedmedia/CDMPrivateAVFoundation.mm: Removed.
* Modules/encryptedmedia/CDMPrivateMediaPlayer.cpp: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.cpp.
(WebCore::CDMPrivateMediaPlayer::supportsKeySystem):
(WebCore::CDMPrivateMediaPlayer::supportsKeySystemAndMimeType):
(WebCore::CDMPrivateMediaPlayer::supportsMIMEType):
(WebCore::CDMPrivateMediaPlayer::createSession):
* Modules/encryptedmedia/CDMPrivateMediaPlayer.h: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.h.
(WebCore::CDMPrivateMediaPlayer::create):
(WebCore::CDMPrivateMediaPlayer::~CDMPrivateMediaPlayer):
(WebCore::CDMPrivateMediaPlayer::cdm):
(WebCore::CDMPrivateMediaPlayer::CDMPrivateMediaPlayer):
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/CDMSession.h: Extracted from CDMPrivateAVFoundation.h.
(WebCore::CDMSessionClient::~CDMSessionClient):
(WebCore::CDMSession::CDMSession):
(WebCore::CDMSession::~CDMSession):
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::createSession):
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::createSession):
* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.h.
(WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC):
* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.mm.
(WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC):
(WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
(WebCore::CDMSessionAVFoundationObjC::releaseKeys):
(WebCore::CDMSessionAVFoundationObjC::update):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::createSession):
* testing/MockCDM.cpp:
(WebCore::MockCDMSession::setClient):
(WebCore::MockCDM::createSession):
* testing/MockCDM.h:

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

20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/CDM.cpp
Source/WebCore/Modules/encryptedmedia/CDM.h
Source/WebCore/Modules/encryptedmedia/CDMPrivate.h
Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.mm [deleted file]
Source/WebCore/Modules/encryptedmedia/CDMPrivateMediaPlayer.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/CDMPrivateMediaPlayer.h [moved from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.h with 77% similarity]
Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeySession.h
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/CDMSession.h [new file with mode: 0644]
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/testing/MockCDM.cpp
Source/WebCore/testing/MockCDM.h

index 0baf312..4cf0b26 100644 (file)
@@ -1,5 +1,60 @@
 2014-02-21  Jer Noble  <jer.noble@apple.com>
 
+        Make a generic CDMPrivateMediaPlayer and move its CDMSession into platform/.
+        https://bugs.webkit.org/show_bug.cgi?id=129164
+
+        Reviewed by Eric Carlson.
+
+        Move the session created by CDMPrivateAVFoundation into platform, and rename
+        CDMPrivateAVFoundation to CDMPrivateMediaPlayer. Future media engines who want
+        to support a keysystem from within the media engine can create their own
+        CDMSession as part of the MediaPlayerPrivate interface.
+
+        * Modules/encryptedmedia/CDM.cpp:
+        (WebCore::installedCDMFactories):
+        (WebCore::CDM::createSession):
+        * Modules/encryptedmedia/CDM.h:
+        * Modules/encryptedmedia/CDMPrivate.h:
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        * Modules/encryptedmedia/MediaKeySession.h:
+        * Modules/encryptedmedia/CDMPrivateAVFoundation.mm: Removed.
+        * Modules/encryptedmedia/CDMPrivateMediaPlayer.cpp: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.cpp.
+        (WebCore::CDMPrivateMediaPlayer::supportsKeySystem):
+        (WebCore::CDMPrivateMediaPlayer::supportsKeySystemAndMimeType):
+        (WebCore::CDMPrivateMediaPlayer::supportsMIMEType):
+        (WebCore::CDMPrivateMediaPlayer::createSession):
+        * Modules/encryptedmedia/CDMPrivateMediaPlayer.h: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.h.
+        (WebCore::CDMPrivateMediaPlayer::create):
+        (WebCore::CDMPrivateMediaPlayer::~CDMPrivateMediaPlayer):
+        (WebCore::CDMPrivateMediaPlayer::cdm):
+        (WebCore::CDMPrivateMediaPlayer::CDMPrivateMediaPlayer):
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/CDMSession.h: Extracted from CDMPrivateAVFoundation.h.
+        (WebCore::CDMSessionClient::~CDMSessionClient):
+        (WebCore::CDMSession::CDMSession):
+        (WebCore::CDMSession::~CDMSession):
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::createSession):
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h:
+        (WebCore::MediaPlayerPrivateInterface::createSession):
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.h.
+        (WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC):
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: Renamed from Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.mm.
+        (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC):
+        (WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
+        (WebCore::CDMSessionAVFoundationObjC::releaseKeys):
+        (WebCore::CDMSessionAVFoundationObjC::update):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession):
+        * testing/MockCDM.cpp:
+        (WebCore::MockCDMSession::setClient):
+        (WebCore::MockCDM::createSession):
+        * testing/MockCDM.h:
+
+2014-02-21  Jer Noble  <jer.noble@apple.com>
+
         Add a supportsKeySystem media engine factory parameter.
         https://bugs.webkit.org/show_bug.cgi?id=129161
 
index 782087c..c4cf4ee 100644 (file)
 
 #include "CDM.h"
 
-#include "CDMPrivate.h"
+#include "CDMPrivateMediaPlayer.h"
+#include "CDMSession.h"
 #include "MediaKeyError.h"
 #include "MediaKeys.h"
 #include <wtf/text/WTFString.h>
 
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-#include "CDMPrivateAVFoundation.h"
-#endif
-
 namespace WebCore {
 
 struct CDMFactory {
@@ -63,10 +60,7 @@ static Vector<CDMFactory*>& installedCDMFactories()
         queriedCDMs = true;
 
         // FIXME: initialize specific UA CDMs. http://webkit.org/b/109318, http://webkit.org/b/109320
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-        cdms.append(new CDMFactory(CDMPrivateAVFoundation::create, CDMPrivateAVFoundation::supportsKeySystem, CDMPrivateAVFoundation::supportsKeySystemAndMimeType));
-#endif
-
+        cdms.append(new CDMFactory(CDMPrivateMediaPlayer::create, CDMPrivateMediaPlayer::supportsKeySystem, CDMPrivateMediaPlayer::supportsKeySystemAndMimeType));
     }
 
     return cdms;
@@ -123,7 +117,7 @@ bool CDM::supportsMIMEType(const String& mimeType) const
     return m_private->supportsMIMEType(mimeType);
 }
 
-PassOwnPtr<CDMSession> CDM::createSession()
+std::unique_ptr<CDMSession> CDM::createSession()
 {
     return m_private->createSession();
 }
index 344b118..f30d64f 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
 
+#include "CDMSession.h"
 #include <runtime/Uint8Array.h>
 #include <wtf/Forward.h>
 #include <wtf/PassRefPtr.h>
@@ -37,7 +38,6 @@ namespace WebCore {
 
 class CDM;
 class CDMPrivateInterface;
-class CDMSession;
 class MediaPlayer;
 
 typedef PassOwnPtr<CDMPrivateInterface> (*CreateCDM)(CDM*);
@@ -51,17 +51,6 @@ public:
     virtual MediaPlayer* cdmMediaPlayer(const CDM*) const = 0;
 };
 
-class CDMSession {
-public:
-    CDMSession() { }
-    virtual ~CDMSession() { }
-
-    virtual const String& sessionId() const = 0;
-    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) = 0;
-    virtual void releaseKeys() = 0;
-    virtual bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) = 0;
-};
-
 class CDM {
 public:
 
@@ -73,7 +62,7 @@ public:
     ~CDM();
 
     bool supportsMIMEType(const String&) const;
-    PassOwnPtr<CDMSession> createSession();
+    std::unique_ptr<CDMSession> createSession();
 
     const String& keySystem() const { return m_keySystem; }
 
index 82a5857..8bb801f 100644 (file)
@@ -42,7 +42,7 @@ public:
 
     virtual bool supportsMIMEType(const String&) = 0;
 
-    virtual PassOwnPtr<CDMSession> createSession() = 0;
+    virtual std::unique_ptr<CDMSession> createSession() = 0;
 };
 
 }
diff --git a/Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.mm b/Source/WebCore/Modules/encryptedmedia/CDMPrivateAVFoundation.mm
deleted file mode 100644 (file)
index cbfcb8d..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#import "config.h"
-#import "CDMPrivateAVFoundation.h"
-
-#if ENABLE(ENCRYPTED_MEDIA_V2) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-
-#import "CDM.h"
-#import "ExceptionCode.h"
-#import "MediaPlayer.h"
-#import "MediaPlayerPrivateAVFoundationObjC.h"
-#import "SoftLinking.h"
-#import "UUID.h"
-#import <AVFoundation/AVFoundation.h>
-#import <objc/objc-runtime.h>
-
-namespace WebCore {
-
-class CDMSessionAVFoundation : public CDMSession {
-public:
-    CDMSessionAVFoundation(CDMPrivateAVFoundation* parent);
-    virtual ~CDMSessionAVFoundation() { }
-
-    virtual const String& sessionId() const override { return m_sessionId; }
-    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) override;
-    virtual void releaseKeys() override;
-    virtual bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) override;
-
-protected:
-    CDMPrivateAVFoundation* m_parent;
-    String m_sessionId;
-    RetainPtr<AVAssetResourceLoadingRequest> m_request;
-};
-
-SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
-SOFT_LINK_CLASS(AVFoundation, AVURLAsset)
-SOFT_LINK_CLASS(AVFoundation, AVAssetResourceLoadingRequest)
-#define AVURLAsset getAVURLAssetClass()
-#define AVAssetResourceLoadingRequest getAVAssetResourceLoadingRequest()
-
-
-bool CDMPrivateAVFoundation::supportsKeySystem(const String& keySystem)
-{
-    return equalIgnoringCase(keySystem, "com.apple.fps") || equalIgnoringCase(keySystem, "com.apple.fps.1_0");
-}
-
-bool CDMPrivateAVFoundation::supportsKeySystemAndMimeType(const String& keySystem, const String& mimeType)
-{
-    if (!supportsKeySystem(keySystem))
-        return false;
-    return [AVURLAsset isPlayableExtendedMIMEType:mimeType];
-}
-
-bool CDMPrivateAVFoundation::supportsMIMEType(const String& mimeType)
-{
-    return [AVURLAsset isPlayableExtendedMIMEType:mimeType];
-}
-
-PassOwnPtr<CDMSession> CDMPrivateAVFoundation::createSession()
-{
-    return adoptPtr(new CDMSessionAVFoundation(this));
-}
-
-CDMSessionAVFoundation::CDMSessionAVFoundation(CDMPrivateAVFoundation* parent)
-    : m_parent(parent)
-    , m_sessionId(createCanonicalUUIDString())
-{
-}
-
-static unsigned short MediaKeyExceptionToErrorCode(MediaPlayer::MediaKeyException error)
-{
-    switch (error) {
-    case MediaPlayer::NoError:
-        return 0;
-    case MediaPlayer::InvalidPlayerState:
-        return INVALID_STATE_ERR;
-    case MediaPlayer::KeySystemNotSupported:
-        return NOT_SUPPORTED_ERR;
-    default:
-        ASSERT_NOT_REACHED();
-        return 0;
-    }
-}
-
-PassRefPtr<Uint8Array> CDMSessionAVFoundation::generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode)
-{
-    UNUSED_PARAM(mimeType);
-
-    MediaPlayer* mediaPlayer = m_parent->cdm()->mediaPlayer();
-    if (!mediaPlayer) {
-        errorCode = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
-
-    m_sessionId = createCanonicalUUIDString();
-
-    MediaPlayer::MediaKeyException error;
-    RefPtr<Uint8Array> request = mediaPlayer->generateKeyRequest(m_sessionId, mimeType, initData, destinationURL, error, systemCode);
-    errorCode = MediaKeyExceptionToErrorCode(error);
-    return request;
-}
-
-void CDMSessionAVFoundation::releaseKeys()
-{
-    MediaPlayer* mediaPlayer = m_parent->cdm()->mediaPlayer();
-    if (!mediaPlayer)
-        return;
-
-    mediaPlayer->releaseKeys(m_sessionId);
-}
-
-bool CDMSessionAVFoundation::update(Uint8Array* key, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode)
-{
-    if (!key)
-        return false;
-
-    MediaPlayer* mediaPlayer = m_parent->cdm()->mediaPlayer();
-    if (!mediaPlayer) {
-        errorCode = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
-
-    MediaPlayer::MediaKeyException error;
-    bool succeeded = mediaPlayer->update(m_sessionId, key, nextMessage, error, systemCode);
-    errorCode = MediaKeyExceptionToErrorCode(error);
-    return succeeded;
-}
-
-}
-
-#endif
diff --git a/Source/WebCore/Modules/encryptedmedia/CDMPrivateMediaPlayer.cpp b/Source/WebCore/Modules/encryptedmedia/CDMPrivateMediaPlayer.cpp
new file mode 100644 (file)
index 0000000..d362140
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#import "config.h"
+#import "CDMPrivateMediaPlayer.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#import "CDM.h"
+#import "CDMSession.h"
+#import "ContentType.h"
+#import "ExceptionCode.h"
+#import "MediaPlayer.h"
+#import "SoftLinking.h"
+
+namespace WebCore {
+
+bool CDMPrivateMediaPlayer::supportsKeySystem(const String& keySystem)
+{
+    return MediaPlayer::supportsKeySystem(keySystem, emptyString());
+}
+
+bool CDMPrivateMediaPlayer::supportsKeySystemAndMimeType(const String& keySystem, const String& mimeType)
+{
+    return MediaPlayer::supportsKeySystem(keySystem, mimeType);
+}
+
+bool CDMPrivateMediaPlayer::supportsMIMEType(const String& mimeType)
+{
+    return MediaPlayer::supportsKeySystem(m_cdm->keySystem(), mimeType);
+}
+
+std::unique_ptr<CDMSession> CDMPrivateMediaPlayer::createSession()
+{
+    MediaPlayer* mediaPlayer = m_cdm->mediaPlayer();
+    if (!mediaPlayer)
+        return nullptr;
+
+    return mediaPlayer->createSession(m_cdm->keySystem());
+}
+
+}
+
+#endif
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef CDMPrivateAVFoundation_h
-#define CDMPrivateAVFoundation_h
+#ifndef CDMPrivateMediaPlayer_h
+#define CDMPrivateMediaPlayer_h
 
 #include "CDMPrivate.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/RetainPtr.h>
 
-#if ENABLE(ENCRYPTED_MEDIA_V2) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+#if ENABLE(ENCRYPTED_MEDIA_V2)
 
 namespace WebCore {
 
 class CDM;
 
-class CDMPrivateAVFoundation : public CDMPrivateInterface {
+class CDMPrivateMediaPlayer : public CDMPrivateInterface {
 public:
-    // CDMFactory support:
-    static PassOwnPtr<CDMPrivateInterface> create(CDM* cdm) { return adoptPtr(new CDMPrivateAVFoundation(cdm)); }
+    static PassOwnPtr<CDMPrivateInterface> create(CDM* cdm) { return adoptPtr(new CDMPrivateMediaPlayer(cdm)); }
     static bool supportsKeySystem(const String&);
     static bool supportsKeySystemAndMimeType(const String& keySystem, const String& mimeType);
 
-    virtual ~CDMPrivateAVFoundation() { }
+    virtual ~CDMPrivateMediaPlayer() { }
 
     virtual bool supportsMIMEType(const String& mimeType) override;
-    virtual PassOwnPtr<CDMSession> createSession() override;
+    virtual std::unique_ptr<CDMSession> createSession() override;
 
     CDM* cdm() const { return m_cdm; }
 
 protected:
-    CDMPrivateAVFoundation(CDM* cdm) : m_cdm(cdm) { }
+    CDMPrivateMediaPlayer(CDM* cdm) : m_cdm(cdm) { }
     CDM* m_cdm;
 };
 
@@ -59,4 +58,4 @@ protected:
 
 #endif
 
-#endif // CDMPrivateAVFoundation_h
+#endif // CDMPriavateMediaPlayer_h
index c542a0c..70a73ce 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(ENCRYPTED_MEDIA_V2)
 
 #include "CDM.h"
+#include "CDMSession.h"
 #include "Event.h"
 #include "GenericEventQueue.h"
 #include "MediaKeyError.h"
index 0d532ea..c5afbeb 100644 (file)
@@ -85,7 +85,7 @@ protected:
     String m_sessionId;
     RefPtr<MediaKeyError> m_error;
     GenericEventQueue m_asyncEventQueue;
-    OwnPtr<CDMSession> m_session;
+    std::unique_ptr<CDMSession> m_session;
 
     struct PendingKeyRequest {
         PendingKeyRequest(const String& mimeType, Uint8Array* initData) : mimeType(mimeType), initData(initData) { }
index 54d03f0..e424be0 100644 (file)
                CD3E251C18046B0600E27F56 /* GridCoordinate.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3E251B18046B0600E27F56 /* GridCoordinate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD3E252318046BCD00E27F56 /* CSSGridTemplateAreasValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3E252118046BCD00E27F56 /* CSSGridTemplateAreasValue.cpp */; };
                CD3E252418046BCD00E27F56 /* CSSGridTemplateAreasValue.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3E252218046BCD00E27F56 /* CSSGridTemplateAreasValue.h */; };
-               CD47B3FC16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD47B3FA16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm */; };
                CD4AC52A1496AE9A0087C4EF /* Composite.wav in Copy Audio Resources */ = {isa = PBXBuildFile; fileRef = CD4AC5281496AE2F0087C4EF /* Composite.wav */; };
                CD5393D3175E018600C07123 /* JSMemoryInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5393D1175E018600C07123 /* JSMemoryInfo.cpp */; };
                CD5393D4175E018600C07123 /* JSMemoryInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CD5393D2175E018600C07123 /* JSMemoryInfo.h */; };
                CDC8B5AB18047FF10016E685 /* SourceBufferPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC8B5A918047FF10016E685 /* SourceBufferPrivateAVFObjC.h */; };
                CDC8B5AD1804AE5D0016E685 /* SourceBufferPrivateClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC8B5AC1804AE5D0016E685 /* SourceBufferPrivateClient.h */; };
                CDCA82961679100F00875714 /* TextTrackRepresentationIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDCA82941679100F00875714 /* TextTrackRepresentationIOS.mm */; };
+               CDCA98EB18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDCA98EA18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp */; };
                CDD525D7145B6DD0008D204D /* JSHTMLMediaElementCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDF65CCC145B6AFE00C4C7AA /* JSHTMLMediaElementCustom.cpp */; };
                CDD7089618359F6F002B3DC6 /* SampleMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDD7089418359F6E002B3DC6 /* SampleMap.cpp */; };
                CDD7089718359F6F002B3DC6 /* SampleMap.h in Headers */ = {isa = PBXBuildFile; fileRef = CDD7089518359F6F002B3DC6 /* SampleMap.h */; };
                CDDC1E7A18A952F30027A9D4 /* MediaSourcePrivateClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDC1E7918A952F30027A9D4 /* MediaSourcePrivateClient.h */; };
+               CDDD571518B57A8200A94FCB /* CDMSession.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDE02E918B3DFC700CF7FF1 /* CDMSession.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CDDE02ED18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDDE02EB18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.mm */; };
                CDE3A85417F5FCE600C5BE20 /* AudioTrackPrivateAVF.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE3A85217F5FCE600C5BE20 /* AudioTrackPrivateAVF.h */; };
                CDE3A85717F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */; };
                CDE3A85817F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */; };
                CD3E251B18046B0600E27F56 /* GridCoordinate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GridCoordinate.h; path = style/GridCoordinate.h; sourceTree = "<group>"; };
                CD3E252118046BCD00E27F56 /* CSSGridTemplateAreasValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGridTemplateAreasValue.cpp; sourceTree = "<group>"; };
                CD3E252218046BCD00E27F56 /* CSSGridTemplateAreasValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSGridTemplateAreasValue.h; sourceTree = "<group>"; };
-               CD47B3F916CC34F800A21EC8 /* CDMPrivateAVFoundation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMPrivateAVFoundation.h; sourceTree = "<group>"; };
-               CD47B3FA16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CDMPrivateAVFoundation.mm; sourceTree = "<group>"; };
                CD4AC5281496AE2F0087C4EF /* Composite.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = Composite.wav; path = platform/audio/resources/Composite.wav; sourceTree = SOURCE_ROOT; };
                CD4E0AFA11F7BC27009D3811 /* fullscreen.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = fullscreen.css; sourceTree = "<group>"; };
                CD5393CB175DCCE600C07123 /* MemoryInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryInfo.h; sourceTree = "<group>"; };
                CDC8B5A918047FF10016E685 /* SourceBufferPrivateAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SourceBufferPrivateAVFObjC.h; path = objc/SourceBufferPrivateAVFObjC.h; sourceTree = "<group>"; };
                CDC8B5AC1804AE5D0016E685 /* SourceBufferPrivateClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceBufferPrivateClient.h; sourceTree = "<group>"; };
                CDCA82941679100F00875714 /* TextTrackRepresentationIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextTrackRepresentationIOS.mm; sourceTree = "<group>"; };
+               CDCA98E918B2C8D000C12FF9 /* CDMPrivateMediaPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDMPrivateMediaPlayer.h; sourceTree = "<group>"; };
+               CDCA98EA18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CDMPrivateMediaPlayer.cpp; sourceTree = "<group>"; };
                CDCE5CD014633BC900D47CCA /* EventTargetFactory.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = EventTargetFactory.in; sourceTree = "<group>"; };
                CDD1E525167BA56400CE820B /* TextTrackRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentation.h; sourceTree = "<group>"; };
                CDD7089418359F6E002B3DC6 /* SampleMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SampleMap.cpp; sourceTree = "<group>"; };
                CDD7089518359F6F002B3DC6 /* SampleMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleMap.h; sourceTree = "<group>"; };
                CDDC1E7918A952F30027A9D4 /* MediaSourcePrivateClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSourcePrivateClient.h; sourceTree = "<group>"; };
+               CDDE02E918B3DFC700CF7FF1 /* CDMSession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDMSession.h; sourceTree = "<group>"; };
+               CDDE02EA18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDMSessionAVFoundationObjC.h; path = objc/CDMSessionAVFoundationObjC.h; sourceTree = "<group>"; };
+               CDDE02EB18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CDMSessionAVFoundationObjC.mm; path = objc/CDMSessionAVFoundationObjC.mm; sourceTree = "<group>"; };
                CDE3A85217F5FCE600C5BE20 /* AudioTrackPrivateAVF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioTrackPrivateAVF.h; sourceTree = "<group>"; };
                CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AudioTrackPrivateAVFObjC.mm; path = objc/AudioTrackPrivateAVFObjC.mm; sourceTree = "<group>"; };
                CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioTrackPrivateAVFObjC.h; path = objc/AudioTrackPrivateAVFObjC.h; sourceTree = "<group>"; };
                                BEF29EE91715DD0900C4B4C9 /* AudioTrackPrivate.h */,
                                A89943270B42338700D7C802 /* BitmapImage.cpp */,
                                A89943260B42338700D7C802 /* BitmapImage.h */,
+                               CDDE02E918B3DFC700CF7FF1 /* CDMSession.h */,
                                B27535380B053814002CE64F /* Color.cpp */,
                                B27535390B053814002CE64F /* Color.h */,
                                9382DF5710A8D5C900925652 /* ColorSpace.h */,
                                CDA98E091603CD5900FEA3B1 /* CDM.cpp */,
                                CDA98E0A1603CD5900FEA3B1 /* CDM.h */,
                                CDA98E0C1603CF3C00FEA3B1 /* CDMPrivate.h */,
-                               CD47B3F916CC34F800A21EC8 /* CDMPrivateAVFoundation.h */,
-                               CD47B3FA16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm */,
+                               CDCA98E918B2C8D000C12FF9 /* CDMPrivateMediaPlayer.h */,
+                               CDCA98EA18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp */,
                                CDA98DD516025BED00FEA3B1 /* MediaKeyMessageEvent.cpp */,
                                CDA98DD616025BED00FEA3B1 /* MediaKeyMessageEvent.h */,
                                CDA98DD716025BEE00FEA3B1 /* MediaKeyMessageEvent.idl */,
                                CD54A761180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.h */,
                                CD336F6017F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h */,
                                CD336F5F17F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm */,
+                               CDDE02EA18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.h */,
+                               CDDE02EB18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.mm */,
                                07AA6B69166D019500D45671 /* InbandTextTrackPrivateAVFObjC.h */,
                                07AA6B6A166D019500D45671 /* InbandTextTrackPrivateAVFObjC.mm */,
                                07367DDD172CA67F00D861B9 /* InbandTextTrackPrivateLegacyAVFObjC.h */,
                                1ABA80001897341200DCE9D6 /* VisitedLinkProvider.h in Headers */,
                                2E0888D51148848A00AF4265 /* JSDOMFormData.h in Headers */,
                                E1C36C030EB076D6007410BC /* JSDOMGlobalObject.h in Headers */,
+                               CDDD571518B57A8200A94FCB /* CDMSession.h in Headers */,
                                65DF31F809D1CC60000BE325 /* JSDOMImplementation.h in Headers */,
                                A9D248070D757E7D00FDF959 /* JSDOMMimeType.h in Headers */,
                                A9D248090D757E7D00FDF959 /* JSDOMMimeTypeArray.h in Headers */,
                                6550B69D099DF0270090D781 /* CDATASection.cpp in Sources */,
                                078E090917D14CEE00420AA1 /* RTCIceCandidate.cpp in Sources */,
                                CDA98E0B1603CD6000FEA3B1 /* CDM.cpp in Sources */,
-                               CD47B3FC16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm in Sources */,
                                990A1A0418ADA48400183FD1 /* ReplayInputTypes.cpp in Sources */,
                                E1A8E56617552B2A007488E7 /* CFURLExtras.cpp in Sources */,
                                97BC69DC1505F076001B74AC /* ChangeVersionWrapper.cpp in Sources */,
                                977B3866122883E900B81FF8 /* HTMLDocumentParser.cpp in Sources */,
                                93309DE7099E64920056E581 /* htmlediting.cpp in Sources */,
                                A516E8B8136E04DB0076C3C0 /* LocalizedDateCache.mm in Sources */,
+                               CDDE02ED18B3ED6D00CF7FF1 /* CDMSessionAVFoundationObjC.mm in Sources */,
                                93F19A9208245E59001E9ABC /* HTMLElement.cpp in Sources */,
                                E157A8F018185425009F821D /* JSCryptoAlgorithmBuilder.cpp in Sources */,
                                A17C81220F2A5CF7005DAAEB /* HTMLElementFactory.cpp in Sources */,
                                B27B28270CEF0C0700D39D54 /* JSSVGGlyphElement.cpp in Sources */,
                                070363E1181A1CDC00C074A5 /* AVAudioCaptureSource.mm in Sources */,
                                24D9129813CA96DE00D21915 /* JSSVGGlyphRefElement.cpp in Sources */,
+                               CDCA98EB18B2C8EB00C12FF9 /* CDMPrivateMediaPlayer.cpp in Sources */,
                                B2FA3D9C0AB75A6F000E5AC4 /* JSSVGGradientElement.cpp in Sources */,
                                85174EC2BCCAF17EAE3F46F8 /* JSSVGGraphicsElement.cpp in Sources */,
                                8485227B1190162C006EDC7F /* JSSVGHKernElement.cpp in Sources */,
diff --git a/Source/WebCore/platform/graphics/CDMSession.h b/Source/WebCore/platform/graphics/CDMSession.h
new file mode 100644 (file)
index 0000000..06f6743
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#ifndef CDMSession_h
+#define CDMSession_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include <runtime/Uint8Array.h>
+#include <wtf/Forward.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class CDMSessionClient {
+public:
+    virtual ~CDMSessionClient() { };
+    virtual void sendMessage(Uint8Array*, String destinationURL) = 0;
+};
+
+class CDMSession {
+public:
+    CDMSession() { }
+    virtual ~CDMSession() { }
+
+    virtual void setClient(CDMSessionClient*) = 0;
+    virtual const String& sessionId() const = 0;
+    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) = 0;
+    virtual void releaseKeys() = 0;
+    virtual bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) = 0;
+};
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA_V2)
+
+#endif // CDMSession_h
index 99b30f3..ca884e9 100644 (file)
@@ -526,19 +526,9 @@ MediaPlayer::MediaKeyException MediaPlayer::cancelKeyRequest(const String& keySy
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
-PassRefPtr<Uint8Array> MediaPlayer::generateKeyRequest(const String& sessionID, const String& mimeType, Uint8Array* initData, String& destinationURL, MediaKeyException& error, unsigned long& systemCode)
+std::unique_ptr<CDMSession> MediaPlayer::createSession(const String& keySystem)
 {
-    return m_private->generateKeyRequest(sessionID, mimeType, initData, destinationURL, error, systemCode);
-}
-
-void MediaPlayer::releaseKeys(const String& sessionID)
-{
-    m_private->releaseKeys(sessionID);
-}
-
-bool MediaPlayer::update(const String& sessionID, Uint8Array* key, RefPtr<Uint8Array>& nextMessage, MediaKeyException& error, unsigned long& systemCode)
-{
-    return m_private->update(sessionID, key, nextMessage, error, systemCode);
+    return m_private->createSession(keySystem);
 }
 #endif
     
index 2983827..c27731e 100644 (file)
@@ -33,6 +33,7 @@
 #endif
 
 #include "AudioTrackPrivate.h"
+#include "CDMSession.h"
 #include "InbandTextTrackPrivate.h"
 #include "IntRect.h"
 #include "URL.h"
@@ -329,9 +330,7 @@ public:
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
-    PassRefPtr<Uint8Array> generateKeyRequest(const String& sessionID, const String& mimeType, Uint8Array* initData, String& destinationURL, MediaKeyException& error, unsigned long& systemCode);
-    void releaseKeys(const String& sessionID);
-    bool update(const String& sessionID, Uint8Array* key, RefPtr<Uint8Array>& nextMessage, MediaKeyException& error, unsigned long& systemCode);
+    std::unique_ptr<CDMSession> createSession(const String& keySystem);
 #endif
 
     bool paused() const;
index 8e2b356..a2d985e 100644 (file)
@@ -209,9 +209,7 @@ public:
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
-    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String&, const String&, Uint8Array*, String&, MediaPlayer::MediaKeyException&, unsigned long&) { return nullptr; }
-    virtual void releaseKeys(const String&) { }
-    virtual bool update(const String&, Uint8Array*, RefPtr<Uint8Array>&, MediaPlayer::MediaKeyException&, unsigned long&) { return false; }
+    virtual std::unique_ptr<CDMSession> createSession(const String&) { return nullptr; }
 #endif
 
 #if ENABLE(VIDEO_TRACK)
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h b/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h
new file mode 100644 (file)
index 0000000..5760107
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#ifndef CDMSessionAVFoundationObjC_h
+#define CDMSessionAVFoundationObjC_h
+
+#include "CDMSession.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RetainPtr.h>
+
+#if ENABLE(ENCRYPTED_MEDIA_V2) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+
+OBJC_CLASS AVAssetResourceLoadingRequest;
+
+namespace WebCore {
+
+class MediaPlayerPrivateAVFoundationObjC;
+
+class CDMSessionAVFoundationObjC : public CDMSession {
+public:
+    CDMSessionAVFoundationObjC(MediaPlayerPrivateAVFoundationObjC* parent);
+    virtual ~CDMSessionAVFoundationObjC() { }
+
+    virtual void setClient(CDMSessionClient* client) override { m_client = client; }
+    virtual const String& sessionId() const override { return m_sessionId; }
+    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) override;
+    virtual void releaseKeys() override;
+    virtual bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) override;
+
+protected:
+    MediaPlayerPrivateAVFoundationObjC* m_parent;
+    CDMSessionClient* m_client;
+    String m_sessionId;
+    RetainPtr<AVAssetResourceLoadingRequest> m_request;
+};
+
+}
+
+#endif
+
+#endif // CDMSessionAVFoundationObjC_h
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm b/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm
new file mode 100644 (file)
index 0000000..a7b8f26
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#import "config.h"
+#import "CDMSessionAVFoundationObjC.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+
+#import "CDM.h"
+#import "CDMSession.h"
+#import "ExceptionCode.h"
+#import "MediaPlayer.h"
+#import "MediaPlayerPrivateAVFoundationObjC.h"
+#import "SoftLinking.h"
+#import "UUID.h"
+#import <AVFoundation/AVFoundation.h>
+#import <objc/objc-runtime.h>
+
+namespace WebCore {
+
+SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
+SOFT_LINK_CLASS(AVFoundation, AVURLAsset)
+SOFT_LINK_CLASS(AVFoundation, AVAssetResourceLoadingRequest)
+#define AVURLAsset getAVURLAssetClass()
+#define AVAssetResourceLoadingRequest getAVAssetResourceLoadingRequest()
+
+CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC(MediaPlayerPrivateAVFoundationObjC* parent)
+    : m_parent(parent)
+    , m_client(nullptr)
+    , m_sessionId(createCanonicalUUIDString())
+{
+}
+
+PassRefPtr<Uint8Array> CDMSessionAVFoundationObjC::generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode)
+{
+    UNUSED_PARAM(mimeType);
+
+    String keyURI;
+    String keyID;
+    RefPtr<Uint8Array> certificate;
+    if (!MediaPlayerPrivateAVFoundationObjC::extractKeyURIKeyIDAndCertificateFromInitData(initData, keyURI, keyID, certificate)) {
+        errorCode = MediaPlayer::InvalidPlayerState;
+        return nullptr;
+    }
+
+    m_request = m_parent->takeRequestForKeyURI(keyURI);
+    if (!m_request) {
+        errorCode = MediaPlayer::InvalidPlayerState;
+        return nullptr;
+    }
+
+    RetainPtr<NSData> certificateData = adoptNS([[NSData alloc] initWithBytes:certificate->baseAddress() length:certificate->byteLength()]);
+    NSString* assetStr = keyID;
+    RetainPtr<NSData> assetID = [NSData dataWithBytes: [assetStr cStringUsingEncoding:NSUTF8StringEncoding] length:[assetStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
+    NSError* nsError = 0;
+    RetainPtr<NSData> keyRequest = [m_request streamingContentKeyRequestDataForApp:certificateData.get() contentIdentifier:assetID.get() options:nil error:&nsError];
+
+    if (!keyRequest) {
+        NSError* underlyingError = [[nsError userInfo] objectForKey:NSUnderlyingErrorKey];
+        systemCode = [underlyingError code];
+        return nullptr;
+    }
+
+    errorCode = MediaPlayer::NoError;
+    systemCode = 0;
+    destinationURL = String();
+
+    RefPtr<ArrayBuffer> keyRequestBuffer = ArrayBuffer::create([keyRequest.get() bytes], [keyRequest.get() length]);
+    return Uint8Array::create(keyRequestBuffer, 0, keyRequestBuffer->byteLength());
+}
+
+void CDMSessionAVFoundationObjC::releaseKeys()
+{
+}
+
+bool CDMSessionAVFoundationObjC::update(Uint8Array* key, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode)
+{
+    RetainPtr<NSData> keyData = adoptNS([[NSData alloc] initWithBytes:key->baseAddress() length:key->byteLength()]);
+    [[m_request dataRequest] respondWithData:keyData.get()];
+    [m_request finishLoading];
+    errorCode = MediaPlayer::NoError;
+    systemCode = 0;
+    nextMessage = nullptr;
+
+    return true;
+}
+
+}
+
+#endif
index 576952a..65c20d5 100644 (file)
@@ -91,7 +91,7 @@ public:
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
-    static RetainPtr<AVAssetResourceLoadingRequest> takeRequestForPlayerAndKeyURI(MediaPlayer*, const String&);
+    RetainPtr<AVAssetResourceLoadingRequest> takeRequestForKeyURI(const String&);
 #endif
 
     void playerItemStatusDidChange(int);
@@ -200,9 +200,7 @@ private:
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
-    PassRefPtr<Uint8Array> generateKeyRequest(const String& sessionId, const String& mimeType, Uint8Array* initData, String& destinationURL, MediaPlayer::MediaKeyException& error, unsigned long& systemCode);
-    void releaseKeys(const String& sessionId);
-    bool update(const String& sessionId, Uint8Array* key, RefPtr<Uint8Array>& nextMessage, MediaPlayer::MediaKeyException& error, unsigned long& systemCode);
+    std::unique_ptr<CDMSession> createSession(const String& keySystem);
 #endif
 
     virtual String languageOfPrimaryAudioTrack() const override;
index ad583d3..ff8aa59 100644 (file)
@@ -33,6 +33,7 @@
 #import "AudioTrackPrivateAVFObjC.h"
 #import "AuthenticationChallenge.h"
 #import "BlockExceptions.h"
+#import "CDMSessionAVFoundationObjC.h"
 #import "ExceptionCodePlaceholder.h"
 #import "FloatConversion.h"
 #import "FloatConversion.h"
@@ -1621,69 +1622,17 @@ MediaPlayer::MediaKeyException MediaPlayerPrivateAVFoundationObjC::cancelKeyRequ
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
-PassRefPtr<Uint8Array> MediaPlayerPrivateAVFoundationObjC::generateKeyRequest(const String& sessionId, const String& mimeType, Uint8Array* initData, String& destinationURL, MediaPlayer::MediaKeyException& error, unsigned long& systemCode)
+RetainPtr<AVAssetResourceLoadingRequest> MediaPlayerPrivateAVFoundationObjC::takeRequestForKeyURI(const String& keyURI)
 {
-    UNUSED_PARAM(mimeType);
-
-    String keyURI;
-    String keyID;
-    RefPtr<Uint8Array> certificate;
-    if (!MediaPlayerPrivateAVFoundationObjC::extractKeyURIKeyIDAndCertificateFromInitData(initData, keyURI, keyID, certificate)) {
-        error = MediaPlayer::InvalidPlayerState;
-        return 0;
-    }
-
-    RetainPtr<AVAssetResourceLoadingRequest> request = m_keyURIToRequestMap.take(keyURI);
-    if (!request) {
-        error = MediaPlayer::InvalidPlayerState;
-        return 0;
-    }
-
-    m_sessionIDToRequestMap.add(sessionId, request);
-
-    RetainPtr<NSData> certificateData = adoptNS([[NSData alloc] initWithBytes:certificate->baseAddress() length:certificate->byteLength()]);
-    NSString* assetStr = keyID;
-    RetainPtr<NSData> assetID = [NSData dataWithBytes: [assetStr cStringUsingEncoding:NSUTF8StringEncoding] length:[assetStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
-    NSError* nsError = 0;
-    RetainPtr<NSData> keyRequest = [request streamingContentKeyRequestDataForApp:certificateData.get() contentIdentifier:assetID.get() options:nil error:&nsError];
-
-    if (!keyRequest) {
-        NSError* underlyingError = [[nsError userInfo] objectForKey:NSUnderlyingErrorKey];
-        systemCode = [underlyingError code];
-        return 0;
-    }
-
-    error = MediaPlayer::NoError;
-    systemCode = 0;
-    destinationURL = String();
-
-    RefPtr<ArrayBuffer> keyRequestBuffer = ArrayBuffer::create([keyRequest.get() bytes], [keyRequest.get() length]);
-    return Uint8Array::create(keyRequestBuffer, 0, keyRequestBuffer->byteLength());
+    return m_keyURIToRequestMap.take(keyURI);
 }
 
-void MediaPlayerPrivateAVFoundationObjC::releaseKeys(const String& sessionId)
+std::unique_ptr<CDMSession> MediaPlayerPrivateAVFoundationObjC::createSession(const String& keySystem)
 {
-    UNUSED_PARAM(sessionId);
-}
-
-bool MediaPlayerPrivateAVFoundationObjC::update(const String& sessionId, Uint8Array* key, RefPtr<Uint8Array>& nextMessage, MediaPlayer::MediaKeyException& error, unsigned long& systemCode)
-{
-    ASSERT(key);
-
-    RetainPtr<AVAssetResourceLoadingRequest> request = m_sessionIDToRequestMap.get(sessionId);
-    if (!request) {
-        error = MediaPlayer::InvalidPlayerState;
-        return false;
-    }
-
-    RetainPtr<NSData> keyData = adoptNS([[NSData alloc] initWithBytes:key->baseAddress() length:key->byteLength()]);
-    [[request dataRequest] respondWithData:keyData.get()];
-    [request finishLoading];
-    error = MediaPlayer::NoError;
-    systemCode = 0;
-    nextMessage = nullptr;
+    if (!keySystemIsSupported(keySystem))
+        return nullptr;
 
-    return true;
+    return std::make_unique<CDMSessionAVFoundationObjC>(this);
 }
 #endif
 
index 36f5c6d..812b0c6 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(ENCRYPTED_MEDIA_V2)
 
 #include "CDM.h"
+#include "CDMSession.h"
 #include "MediaKeyError.h"
 #include <runtime/JSCInlines.h>
 #include <runtime/TypedArrayInlines.h>
@@ -38,17 +39,17 @@ namespace WebCore {
 
 class MockCDMSession : public CDMSession {
 public:
-    static PassOwnPtr<MockCDMSession> create() { return adoptPtr(new MockCDMSession()); }
+    MockCDMSession();
     virtual ~MockCDMSession() { }
 
+    virtual void setClient(CDMSessionClient* client) { m_client = client; }
     virtual const String& sessionId() const override { return m_sessionId; }
     virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) override;
     virtual void releaseKeys() override;
     virtual bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) override;
 
 protected:
-    MockCDMSession();
-
+    CDMSessionClient* m_client;
     String m_sessionId;
 };
 
@@ -70,9 +71,9 @@ bool MockCDM::supportsMIMEType(const String& mimeType)
     return equalIgnoringCase(mimeType, "video/mock");
 }
 
-PassOwnPtr<CDMSession> MockCDM::createSession()
+std::unique_ptr<CDMSession> MockCDM::createSession()
 {
-    return MockCDMSession::create();
+    return std::make_unique<MockCDMSession>();
 }
 
 static Uint8Array* initDataPrefix()
index 2883875..97d0207 100644 (file)
@@ -45,7 +45,7 @@ public:
     virtual ~MockCDM() { }
 
     virtual bool supportsMIMEType(const String& mimeType) override;
-    virtual PassOwnPtr<CDMSession> createSession() override;
+    virtual std::unique_ptr<CDMSession> createSession() override;
 
 protected:
     MockCDM(CDM* cdm) : m_cdm(cdm) { }