| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 | |
| 28 #if ENABLE(ENCRYPTED_MEDIA_V2) | |
| 29 | |
| 30 #include "modules/encryptedmedia/CDM.h" | |
| 31 | |
| 32 #include "core/html/MediaKeyError.h" | |
| 33 #include "modules/encryptedmedia/CDMPrivate.h" | |
| 34 #include "modules/encryptedmedia/MediaKeys.h" | |
| 35 #include "wtf/text/WTFString.h" | |
| 36 | |
| 37 namespace WebCore { | |
| 38 | |
| 39 struct CDMFactory { | |
| 40 WTF_MAKE_NONCOPYABLE(CDMFactory); WTF_MAKE_FAST_ALLOCATED; | |
| 41 public: | |
| 42 CDMFactory(CreateCDM constructor, CDMSupportsKeySystem supportsKeySystem) | |
| 43 : constructor(constructor) | |
| 44 , supportsKeySystem(supportsKeySystem) | |
| 45 { | |
| 46 } | |
| 47 | |
| 48 CreateCDM constructor; | |
| 49 CDMSupportsKeySystem supportsKeySystem; | |
| 50 }; | |
| 51 | |
| 52 static Vector<CDMFactory*>& installedCDMFactories() | |
| 53 { | |
| 54 DEFINE_STATIC_LOCAL(Vector<CDMFactory*>, cdms, ()); | |
| 55 static bool queriedCDMs = false; | |
| 56 if (!queriedCDMs) { | |
| 57 queriedCDMs = true; | |
| 58 | |
| 59 // FIXME: initialize specific UA CDMs. http://webkit.org/b/109318, http:
//webkit.org/b/109320 | |
| 60 } | |
| 61 | |
| 62 return cdms; | |
| 63 } | |
| 64 | |
| 65 void CDM::registerCDMFactory(CreateCDM constructor, CDMSupportsKeySystem support
sKeySystem) | |
| 66 { | |
| 67 installedCDMFactories().append(new CDMFactory(constructor, supportsKeySystem
)); | |
| 68 } | |
| 69 | |
| 70 static CDMFactory* CDMFactoryForKeySystem(const String& keySystem) | |
| 71 { | |
| 72 Vector<CDMFactory*>& cdmFactories = installedCDMFactories(); | |
| 73 for (size_t i = 0; i < cdmFactories.size(); ++i) { | |
| 74 if (cdmFactories[i]->supportsKeySystem(keySystem)) | |
| 75 return cdmFactories[i]; | |
| 76 } | |
| 77 return 0; | |
| 78 } | |
| 79 | |
| 80 bool CDM::supportsKeySystem(const String& keySystem) | |
| 81 { | |
| 82 return CDMFactoryForKeySystem(keySystem); | |
| 83 } | |
| 84 | |
| 85 PassOwnPtr<CDM> CDM::create(const String& keySystem) | |
| 86 { | |
| 87 if (!supportsKeySystem(keySystem)) | |
| 88 return nullptr; | |
| 89 | |
| 90 return adoptPtr(new CDM(keySystem)); | |
| 91 } | |
| 92 | |
| 93 CDM::CDM(const String& keySystem) | |
| 94 : m_keySystem(keySystem) | |
| 95 , m_client(0) | |
| 96 { | |
| 97 m_private = CDMFactoryForKeySystem(keySystem)->constructor(this); | |
| 98 } | |
| 99 | |
| 100 CDM::~CDM() | |
| 101 { | |
| 102 } | |
| 103 | |
| 104 bool CDM::supportsMIMEType(const String& mimeType) const | |
| 105 { | |
| 106 return m_private->supportsMIMEType(mimeType); | |
| 107 } | |
| 108 | |
| 109 PassOwnPtr<CDMSession> CDM::createSession() | |
| 110 { | |
| 111 return m_private->createSession(); | |
| 112 } | |
| 113 | |
| 114 MediaPlayer* CDM::mediaPlayer() const | |
| 115 { | |
| 116 if (!m_client) | |
| 117 return 0; | |
| 118 return m_client->cdmMediaPlayer(this); | |
| 119 } | |
| 120 | |
| 121 } | |
| 122 | |
| 123 #endif // ENABLE(ENCRYPTED_MEDIA_V2) | |
| OLD | NEW |