| 1 | /* |
| 2 | * Copyright (C) 2016 Metrological Group B.V. |
| 3 | * Copyright (C) 2016 Igalia S.L. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following |
| 13 | * disclaimer in the documentation and/or other materials provided |
| 14 | * with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #pragma once |
| 30 | |
| 31 | #if ENABLE(ENCRYPTED_MEDIA) |
| 32 | |
| 33 | #include "CDMFactory.h" |
| 34 | #include "CDMInstance.h" |
| 35 | #include "CDMInstanceSession.h" |
| 36 | #include "CDMPrivate.h" |
| 37 | #include "SharedBuffer.h" |
| 38 | #include <wtf/WeakPtr.h> |
| 39 | |
| 40 | namespace WebCore { |
| 41 | |
| 42 | class CDMFactoryClearKey final : public CDMFactory { |
| 43 | public: |
| 44 | static CDMFactoryClearKey& singleton(); |
| 45 | |
| 46 | virtual ~CDMFactoryClearKey(); |
| 47 | |
| 48 | std::unique_ptr<CDMPrivate> createCDM(const String&) final; |
| 49 | bool supportsKeySystem(const String&) final; |
| 50 | |
| 51 | private: |
| 52 | friend class NeverDestroyed<CDMFactoryClearKey>; |
| 53 | CDMFactoryClearKey(); |
| 54 | }; |
| 55 | |
| 56 | class CDMPrivateClearKey final : public CDMPrivate { |
| 57 | public: |
| 58 | CDMPrivateClearKey(); |
| 59 | virtual ~CDMPrivateClearKey(); |
| 60 | |
| 61 | bool supportsInitDataType(const AtomicString&) const final; |
| 62 | bool supportsConfiguration(const CDMKeySystemConfiguration&) const final; |
| 63 | bool supportsConfigurationWithRestrictions(const CDMKeySystemConfiguration&, const CDMRestrictions&) const final; |
| 64 | bool supportsSessionTypeWithConfiguration(CDMSessionType&, const CDMKeySystemConfiguration&) const final; |
| 65 | bool supportsRobustness(const String&) const final; |
| 66 | CDMRequirement distinctiveIdentifiersRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const final; |
| 67 | CDMRequirement persistentStateRequirement(const CDMKeySystemConfiguration&, const CDMRestrictions&) const final; |
| 68 | bool distinctiveIdentifiersAreUniquePerOriginAndClearable(const CDMKeySystemConfiguration&) const final; |
| 69 | RefPtr<CDMInstance> createInstance() final; |
| 70 | void loadAndInitialize() final; |
| 71 | bool supportsServerCertificates() const final; |
| 72 | bool supportsSessions() const final; |
| 73 | bool supportsInitData(const AtomicString&, const SharedBuffer&) const final; |
| 74 | RefPtr<SharedBuffer> sanitizeResponse(const SharedBuffer&) const final; |
| 75 | Optional<String> sanitizeSessionId(const String&) const final; |
| 76 | }; |
| 77 | |
| 78 | class CDMInstanceClearKey final : public CDMInstance, public CanMakeWeakPtr<CDMInstanceClearKey> { |
| 79 | public: |
| 80 | CDMInstanceClearKey(); |
| 81 | virtual ~CDMInstanceClearKey(); |
| 82 | |
| 83 | ImplementationType implementationType() const final { return ImplementationType::ClearKey; } |
| 84 | |
| 85 | SuccessValue initializeWithConfiguration(const CDMKeySystemConfiguration&) final; |
| 86 | SuccessValue setDistinctiveIdentifiersAllowed(bool) final; |
| 87 | SuccessValue setPersistentStateAllowed(bool) final; |
| 88 | SuccessValue setServerCertificate(Ref<SharedBuffer>&&) final; |
| 89 | SuccessValue setStorageDirectory(const String&) final; |
| 90 | const String& keySystem() const final; |
| 91 | RefPtr<CDMInstanceSession> createSession() final; |
| 92 | |
| 93 | struct Key { |
| 94 | CDMInstanceSession::KeyStatus status; |
| 95 | RefPtr<SharedBuffer> keyIDData; |
| 96 | RefPtr<SharedBuffer> keyValueData; |
| 97 | }; |
| 98 | |
| 99 | const Vector<Key> keys() const; |
| 100 | |
| 101 | private: |
| 102 | mutable Lock m_keysMutex; |
| 103 | }; |
| 104 | |
| 105 | class CDMInstanceSessionClearKey final : public CDMInstanceSession, public CanMakeWeakPtr<CDMInstanceSessionClearKey> { |
| 106 | public: |
| 107 | void requestLicense(LicenseType, const AtomicString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback&&) final; |
| 108 | void updateLicense(const String&, LicenseType, const SharedBuffer&, LicenseUpdateCallback&&) final; |
| 109 | void loadSession(LicenseType, const String&, const String&, LoadSessionCallback&&) final; |
| 110 | void closeSession(const String&, CloseSessionCallback&&) final; |
| 111 | void removeSessionData(const String&, LicenseType, RemoveSessionDataCallback&&) final; |
| 112 | void storeRecordOfKeyUsage(const String&) final; |
| 113 | }; |
| 114 | |
| 115 | } // namespace WebCore |
| 116 | |
| 117 | SPECIALIZE_TYPE_TRAITS_CDM_INSTANCE(WebCore::CDMInstanceClearKey, WebCore::CDMInstance::ImplementationType::ClearKey); |
| 118 | |
| 119 | #endif // ENABLE(ENCRYPTED_MEDIA) |
| 120 | |