1 | /* |
2 | * Copyright (C) 2016 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 | #pragma once |
27 | |
28 | #if ENABLE(ENCRYPTED_MEDIA) |
29 | |
30 | #include "ContextDestructionObserver.h" |
31 | #include "MediaKeySessionType.h" |
32 | #include "MediaKeySystemConfiguration.h" |
33 | #include "MediaKeySystemMediaCapability.h" |
34 | #include "MediaKeysRestrictions.h" |
35 | #include "SharedBuffer.h" |
36 | #include <wtf/Function.h> |
37 | #include <wtf/HashSet.h> |
38 | #include <wtf/Ref.h> |
39 | #include <wtf/RefCounted.h> |
40 | #include <wtf/WeakPtr.h> |
41 | #include <wtf/text/WTFString.h> |
42 | |
43 | namespace WebCore { |
44 | |
45 | class CDMFactory; |
46 | class CDMInstance; |
47 | class CDMPrivate; |
48 | class Document; |
49 | class ScriptExecutionContext; |
50 | class SharedBuffer; |
51 | |
52 | class CDM : public RefCounted<CDM>, public CanMakeWeakPtr<CDM>, private ContextDestructionObserver { |
53 | public: |
54 | static bool supportsKeySystem(const String&); |
55 | static bool isPersistentType(MediaKeySessionType); |
56 | |
57 | static Ref<CDM> create(Document&, const String& keySystem); |
58 | ~CDM(); |
59 | |
60 | using SupportedConfigurationCallback = WTF::Function<void(Optional<MediaKeySystemConfiguration>)>; |
61 | void getSupportedConfiguration(MediaKeySystemConfiguration&& candidateConfiguration, SupportedConfigurationCallback&&); |
62 | |
63 | const String& keySystem() const { return m_keySystem; } |
64 | |
65 | void loadAndInitialize(); |
66 | RefPtr<CDMInstance> createInstance(); |
67 | bool supportsServerCertificates() const; |
68 | bool supportsSessions() const; |
69 | bool supportsInitDataType(const AtomicString&) const; |
70 | |
71 | RefPtr<SharedBuffer> sanitizeInitData(const AtomicString& initDataType, const SharedBuffer&); |
72 | bool supportsInitData(const AtomicString& initDataType, const SharedBuffer&); |
73 | |
74 | RefPtr<SharedBuffer> sanitizeResponse(const SharedBuffer&); |
75 | |
76 | Optional<String> sanitizeSessionId(const String& sessionId); |
77 | |
78 | String storageDirectory() const; |
79 | |
80 | private: |
81 | CDM(Document&, const String& keySystem); |
82 | |
83 | enum class ConfigurationStatus { |
84 | Supported, |
85 | NotSupported, |
86 | ConsentDenied, |
87 | }; |
88 | |
89 | enum class ConsentStatus { |
90 | ConsentDenied, |
91 | InformUser, |
92 | Allowed, |
93 | }; |
94 | |
95 | enum class AudioVideoType { |
96 | Audio, |
97 | Video, |
98 | }; |
99 | |
100 | void doSupportedConfigurationStep(MediaKeySystemConfiguration&& candidateConfiguration, MediaKeysRestrictions&&, SupportedConfigurationCallback&&); |
101 | Optional<MediaKeySystemConfiguration> getSupportedConfiguration(const MediaKeySystemConfiguration& candidateConfiguration, MediaKeysRestrictions&); |
102 | Optional<Vector<MediaKeySystemMediaCapability>> getSupportedCapabilitiesForAudioVideoType(AudioVideoType, const Vector<MediaKeySystemMediaCapability>& requestedCapabilities, const MediaKeySystemConfiguration& partialConfiguration, MediaKeysRestrictions&); |
103 | |
104 | using ConsentStatusCallback = WTF::Function<void(ConsentStatus, MediaKeySystemConfiguration&&, MediaKeysRestrictions&&)>; |
105 | void getConsentStatus(MediaKeySystemConfiguration&& accumulatedConfiguration, MediaKeysRestrictions&&, ConsentStatusCallback&&); |
106 | String m_keySystem; |
107 | std::unique_ptr<CDMPrivate> m_private; |
108 | }; |
109 | |
110 | } |
111 | |
112 | #endif |
113 | |