OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/encryptedmedia/MediaKeySystemAccess.h" | 6 #include "modules/encryptedmedia/MediaKeySystemAccess.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // This class wraps the promise resolver used when creating MediaKeys | 25 // This class wraps the promise resolver used when creating MediaKeys |
26 // and is passed to Chromium to fullfill the promise. This implementation of | 26 // and is passed to Chromium to fullfill the promise. This implementation of |
27 // completeWithCdm() will resolve the promise with a new MediaKeys object, | 27 // completeWithCdm() will resolve the promise with a new MediaKeys object, |
28 // while completeWithError() will reject the promise with an exception. | 28 // while completeWithError() will reject the promise with an exception. |
29 // All other complete methods are not expected to be called, and will | 29 // All other complete methods are not expected to be called, and will |
30 // reject the promise. | 30 // reject the promise. |
31 class NewCdmResultPromise : public ContentDecryptionModuleResultPromise { | 31 class NewCdmResultPromise : public ContentDecryptionModuleResultPromise { |
32 WTF_MAKE_NONCOPYABLE(NewCdmResultPromise); | 32 WTF_MAKE_NONCOPYABLE(NewCdmResultPromise); |
33 | 33 |
34 public: | 34 public: |
35 NewCdmResultPromise(ScriptState* scriptState, const String& keySystem) | 35 NewCdmResultPromise(ScriptState* scriptState, const String& keySystem, const
blink::WebVector<blink::WebString>& supportedSessionTypes) |
36 : ContentDecryptionModuleResultPromise(scriptState) | 36 : ContentDecryptionModuleResultPromise(scriptState) |
37 , m_keySystem(keySystem) | 37 , m_keySystem(keySystem) |
| 38 , m_supportedSessionTypes(supportedSessionTypes) |
38 { | 39 { |
39 } | 40 } |
40 | 41 |
41 virtual ~NewCdmResultPromise() | 42 virtual ~NewCdmResultPromise() |
42 { | 43 { |
43 } | 44 } |
44 | 45 |
45 // ContentDecryptionModuleResult implementation. | 46 // ContentDecryptionModuleResult implementation. |
46 virtual void completeWithContentDecryptionModule(WebContentDecryptionModule*
cdm) override | 47 virtual void completeWithContentDecryptionModule(WebContentDecryptionModule*
cdm) override |
47 { | 48 { |
48 // NOTE: Continued from step 2. of createMediaKeys(). | 49 // NOTE: Continued from step 2.8 of createMediaKeys(). |
49 // 2.4 Let media keys be a new MediaKeys object. | 50 // 2.9. Let media keys be a new MediaKeys object. |
50 MediaKeys* mediaKeys = new MediaKeys(executionContext(), m_keySystem, ad
optPtr(cdm)); | 51 MediaKeys* mediaKeys = new MediaKeys(executionContext(), m_keySystem, m_
supportedSessionTypes, adoptPtr(cdm)); |
51 | 52 |
52 // 2.5 Resolve promise with media keys. | 53 // 2.10. Resolve promise with media keys. |
53 resolve(mediaKeys); | 54 resolve(mediaKeys); |
54 } | 55 } |
55 | 56 |
56 private: | 57 private: |
57 const String m_keySystem; | 58 const String m_keySystem; |
| 59 const blink::WebVector<blink::WebString> m_supportedSessionTypes; |
58 }; | 60 }; |
59 | 61 |
60 // These methods are the inverses of those with the same names in | 62 // These methods are the inverses of those with the same names in |
61 // NavigatorRequestMediaKeySystemAccess. | 63 // NavigatorRequestMediaKeySystemAccess. |
62 static Vector<String> convertInitDataTypes(const WebVector<WebString>& initDataT
ypes) | 64 static Vector<String> convertInitDataTypes(const WebVector<WebString>& initDataT
ypes) |
63 { | 65 { |
64 Vector<String> result; | 66 Vector<String> result; |
65 result.reserveCapacity(initDataTypes.size()); | 67 result.reserveCapacity(initDataTypes.size()); |
66 for (size_t i = 0; i < initDataTypes.size(); i++) | 68 for (size_t i = 0; i < initDataTypes.size(); i++) |
67 result.append(initDataTypes[i]); | 69 result.append(initDataTypes[i]); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 WebMediaKeySystemConfiguration configuration = m_access->getConfiguration(); | 115 WebMediaKeySystemConfiguration configuration = m_access->getConfiguration(); |
114 result.setInitDataTypes(convertInitDataTypes(configuration.initDataTypes)); | 116 result.setInitDataTypes(convertInitDataTypes(configuration.initDataTypes)); |
115 result.setAudioCapabilities(convertCapabilities(configuration.audioCapabilit
ies)); | 117 result.setAudioCapabilities(convertCapabilities(configuration.audioCapabilit
ies)); |
116 result.setVideoCapabilities(convertCapabilities(configuration.videoCapabilit
ies)); | 118 result.setVideoCapabilities(convertCapabilities(configuration.videoCapabilit
ies)); |
117 result.setDistinctiveIdentifier(convertMediaKeysRequirement(configuration.di
stinctiveIdentifier)); | 119 result.setDistinctiveIdentifier(convertMediaKeysRequirement(configuration.di
stinctiveIdentifier)); |
118 result.setPersistentState(convertMediaKeysRequirement(configuration.persiste
ntState)); | 120 result.setPersistentState(convertMediaKeysRequirement(configuration.persiste
ntState)); |
119 } | 121 } |
120 | 122 |
121 ScriptPromise MediaKeySystemAccess::createMediaKeys(ScriptState* scriptState) | 123 ScriptPromise MediaKeySystemAccess::createMediaKeys(ScriptState* scriptState) |
122 { | 124 { |
123 // From https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e
ncrypted-media.html#widl-MediaKeySystemAccess-createMediaKeys-Promise-MediaKeys | 125 // From http://w3c.github.io/encrypted-media/#createMediaKeys |
124 // When this method is invoked, the user agent must run the following steps: | 126 // (Reordered to be able to pass values into the promise constructor.) |
| 127 // 2.4 Let configuration be the value of this object's configuration value. |
| 128 // 2.5-2.8. [Set use distinctive identifier and persistent state allowed |
| 129 // based on configuration.] |
| 130 WebMediaKeySystemConfiguration configuration = m_access->getConfiguration(); |
| 131 |
125 // 1. Let promise be a new promise. | 132 // 1. Let promise be a new promise. |
126 NewCdmResultPromise* helper = new NewCdmResultPromise(scriptState, m_keySyst
em); | 133 NewCdmResultPromise* helper = new NewCdmResultPromise(scriptState, m_keySyst
em, configuration.sessionTypes); |
127 ScriptPromise promise = helper->promise(); | 134 ScriptPromise promise = helper->promise(); |
128 | 135 |
129 // 2. Asynchronously create and initialize the MediaKeys object. | 136 // 2. Asynchronously create and initialize the MediaKeys object. |
130 // 2.1 Let cdm be the CDM corresponding to this object. | 137 // 2.1 Let cdm be the CDM corresponding to this object. |
131 // 2.2 Load and initialize the cdm if necessary. | 138 // 2.2 Load and initialize the cdm if necessary. |
132 // 2.3 If cdm fails to load or initialize, reject promise with a new | 139 // 2.3 If cdm fails to load or initialize, reject promise with a new |
133 // DOMException whose name is the appropriate error name. | 140 // DOMException whose name is the appropriate error name. |
134 // (Done if completeWithException() called). | 141 // (Done if completeWithException() called). |
135 m_access->createContentDecryptionModule(helper->result()); | 142 m_access->createContentDecryptionModule(helper->result()); |
136 | 143 |
137 // 3. Return promise. | 144 // 3. Return promise. |
138 return promise; | 145 return promise; |
139 } | 146 } |
140 | 147 |
141 void MediaKeySystemAccess::trace(Visitor*) | 148 void MediaKeySystemAccess::trace(Visitor*) |
142 { | 149 { |
143 } | 150 } |
144 | 151 |
145 } // namespace blink | 152 } // namespace blink |
OLD | NEW |