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 "modules/encryptedmedia/NavigatorRequestMediaKeySystemAccess.h" | 5 #include "modules/encryptedmedia/NavigatorRequestMediaKeySystemAccess.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
12 #include "core/frame/Deprecation.h" | 12 #include "core/frame/Deprecation.h" |
13 #include "core/frame/OriginsUsingFeatures.h" | 13 #include "core/frame/OriginsUsingFeatures.h" |
14 #include "core/inspector/ConsoleMessage.h" | 14 #include "core/inspector/ConsoleMessage.h" |
15 #include "modules/encryptedmedia/EncryptedMediaUtils.h" | 15 #include "modules/encryptedmedia/EncryptedMediaUtils.h" |
16 #include "modules/encryptedmedia/MediaKeySession.h" | 16 #include "modules/encryptedmedia/MediaKeySession.h" |
17 #include "modules/encryptedmedia/MediaKeySystemAccess.h" | 17 #include "modules/encryptedmedia/MediaKeySystemAccess.h" |
18 #include "modules/encryptedmedia/MediaKeysController.h" | 18 #include "modules/encryptedmedia/MediaKeysController.h" |
19 #include "platform/EncryptedMediaRequest.h" | 19 #include "platform/EncryptedMediaRequest.h" |
20 #include "platform/Histogram.h" | 20 #include "platform/Histogram.h" |
21 #include "platform/Logging.h" | 21 #include "platform/Logging.h" |
22 #include "platform/network/ParsedContentType.h" | 22 #include "platform/network/ParsedContentType.h" |
23 #include "public/platform/WebEncryptedMediaClient.h" | 23 #include "public/platform/WebEncryptedMediaClient.h" |
24 #include "public/platform/WebEncryptedMediaRequest.h" | 24 #include "public/platform/WebEncryptedMediaRequest.h" |
25 #include "public/platform/WebMediaKeySystemConfiguration.h" | 25 #include "public/platform/WebMediaKeySystemConfiguration.h" |
26 #include "public/platform/WebMediaKeySystemMediaCapability.h" | 26 #include "public/platform/WebMediaKeySystemMediaCapability.h" |
27 #include "public/platform/WebVector.h" | 27 #include "public/platform/WebVector.h" |
28 #include "wtf/Vector.h" | 28 #include "wtf/Vector.h" |
29 #include "wtf/text/WTFString.h" | 29 #include "wtf/text/WTFString.h" |
30 #include <algorithm> | |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 static WebVector<WebEncryptedMediaInitDataType> convertInitDataTypes(const Vecto r<String>& initDataTypes) | 36 static WebVector<WebEncryptedMediaInitDataType> convertInitDataTypes(const Vecto r<String>& initDataTypes) |
36 { | 37 { |
37 WebVector<WebEncryptedMediaInitDataType> result(initDataTypes.size()); | 38 WebVector<WebEncryptedMediaInitDataType> result(initDataTypes.size()); |
38 for (size_t i = 0; i < initDataTypes.size(); ++i) | 39 for (size_t i = 0; i < initDataTypes.size(); ++i) |
39 result[i] = EncryptedMediaUtils::convertToInitDataType(initDataTypes[i]) ; | 40 result[i] = EncryptedMediaUtils::convertToInitDataType(initDataTypes[i]) ; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 } | 73 } |
73 | 74 |
74 static WebVector<WebEncryptedMediaSessionType> convertSessionTypes(const Vector< String>& sessionTypes) | 75 static WebVector<WebEncryptedMediaSessionType> convertSessionTypes(const Vector< String>& sessionTypes) |
75 { | 76 { |
76 WebVector<WebEncryptedMediaSessionType> result(sessionTypes.size()); | 77 WebVector<WebEncryptedMediaSessionType> result(sessionTypes.size()); |
77 for (size_t i = 0; i < sessionTypes.size(); ++i) | 78 for (size_t i = 0; i < sessionTypes.size(); ++i) |
78 result[i] = EncryptedMediaUtils::convertToSessionType(sessionTypes[i]); | 79 result[i] = EncryptedMediaUtils::convertToSessionType(sessionTypes[i]); |
79 return result; | 80 return result; |
80 } | 81 } |
81 | 82 |
83 static bool AreCodecsSpecified(const WebMediaKeySystemMediaCapability& capabilit y) | |
84 { | |
85 return !capability.codecs.isEmpty(); | |
86 } | |
87 | |
82 // This class allows capabilities to be checked and a MediaKeySystemAccess | 88 // This class allows capabilities to be checked and a MediaKeySystemAccess |
83 // object to be created asynchronously. | 89 // object to be created asynchronously. |
84 class MediaKeySystemAccessInitializer final : public EncryptedMediaRequest { | 90 class MediaKeySystemAccessInitializer final : public EncryptedMediaRequest { |
85 WTF_MAKE_NONCOPYABLE(MediaKeySystemAccessInitializer); | 91 WTF_MAKE_NONCOPYABLE(MediaKeySystemAccessInitializer); |
86 | 92 |
87 public: | 93 public: |
88 MediaKeySystemAccessInitializer(ScriptState*, const String& keySystem, const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations); | 94 MediaKeySystemAccessInitializer(ScriptState*, const String& keySystem, const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations); |
89 ~MediaKeySystemAccessInitializer() override { } | 95 ~MediaKeySystemAccessInitializer() override { } |
90 | 96 |
91 // EncryptedMediaRequest implementation. | 97 // EncryptedMediaRequest implementation. |
(...skipping 12 matching lines...) Expand all Loading... | |
104 } | 110 } |
105 | 111 |
106 private: | 112 private: |
107 // For widevine key system, generate warning and report to UMA if | 113 // For widevine key system, generate warning and report to UMA if |
108 // |m_supportedConfigurations| contains any video capability with empty | 114 // |m_supportedConfigurations| contains any video capability with empty |
109 // robustness string. | 115 // robustness string. |
110 // TODO(xhwang): Remove after we handle empty robustness correctly. | 116 // TODO(xhwang): Remove after we handle empty robustness correctly. |
111 // See http://crbug.com/482277 | 117 // See http://crbug.com/482277 |
112 void checkVideoCapabilityRobustness() const; | 118 void checkVideoCapabilityRobustness() const; |
113 | 119 |
120 // Generate deprecation warning and log UseCounter if configuration | |
121 // contains only container-only contentType strings. | |
122 // TODO(jrummell): Remove once this is no longer allowed. | |
123 // See http://crbug.com/605661. | |
124 void checkEmptyCodecs(const WebMediaKeySystemConfiguration&); | |
125 | |
114 Member<ScriptPromiseResolver> m_resolver; | 126 Member<ScriptPromiseResolver> m_resolver; |
115 const String m_keySystem; | 127 const String m_keySystem; |
116 WebVector<WebMediaKeySystemConfiguration> m_supportedConfigurations; | 128 WebVector<WebMediaKeySystemConfiguration> m_supportedConfigurations; |
117 }; | 129 }; |
118 | 130 |
119 MediaKeySystemAccessInitializer::MediaKeySystemAccessInitializer(ScriptState* sc riptState, const String& keySystem, const HeapVector<MediaKeySystemConfiguration >& supportedConfigurations) | 131 MediaKeySystemAccessInitializer::MediaKeySystemAccessInitializer(ScriptState* sc riptState, const String& keySystem, const HeapVector<MediaKeySystemConfiguration >& supportedConfigurations) |
120 : m_resolver(ScriptPromiseResolver::create(scriptState)) | 132 : m_resolver(ScriptPromiseResolver::create(scriptState)) |
121 , m_keySystem(keySystem) | 133 , m_keySystem(keySystem) |
122 , m_supportedConfigurations(supportedConfigurations.size()) | 134 , m_supportedConfigurations(supportedConfigurations.size()) |
123 { | 135 { |
(...skipping 23 matching lines...) Expand all Loading... | |
147 // If |label| is not present, it will be a null string. | 159 // If |label| is not present, it will be a null string. |
148 webConfig.label = config.label(); | 160 webConfig.label = config.label(); |
149 m_supportedConfigurations[i] = webConfig; | 161 m_supportedConfigurations[i] = webConfig; |
150 } | 162 } |
151 | 163 |
152 checkVideoCapabilityRobustness(); | 164 checkVideoCapabilityRobustness(); |
153 } | 165 } |
154 | 166 |
155 void MediaKeySystemAccessInitializer::requestSucceeded(WebContentDecryptionModul eAccess* access) | 167 void MediaKeySystemAccessInitializer::requestSucceeded(WebContentDecryptionModul eAccess* access) |
156 { | 168 { |
169 checkEmptyCodecs(access->getConfiguration()); | |
170 | |
157 m_resolver->resolve(new MediaKeySystemAccess(m_keySystem, adoptPtr(access))) ; | 171 m_resolver->resolve(new MediaKeySystemAccess(m_keySystem, adoptPtr(access))) ; |
158 m_resolver.clear(); | 172 m_resolver.clear(); |
159 } | 173 } |
160 | 174 |
161 void MediaKeySystemAccessInitializer::requestNotSupported(const WebString& error Message) | 175 void MediaKeySystemAccessInitializer::requestNotSupported(const WebString& error Message) |
162 { | 176 { |
163 m_resolver->reject(DOMException::create(NotSupportedError, errorMessage)); | 177 m_resolver->reject(DOMException::create(NotSupportedError, errorMessage)); |
164 m_resolver.clear(); | 178 m_resolver.clear(); |
165 } | 179 } |
166 | 180 |
(...skipping 28 matching lines...) Expand all Loading... | |
195 emptyRobustnessHistogram.count(hasEmptyRobustness); | 209 emptyRobustnessHistogram.count(hasEmptyRobustness); |
196 } | 210 } |
197 | 211 |
198 if (hasEmptyRobustness) { | 212 if (hasEmptyRobustness) { |
199 m_resolver->getExecutionContext()->addConsoleMessage(ConsoleMessage::cre ate(JSMessageSource, WarningMessageLevel, | 213 m_resolver->getExecutionContext()->addConsoleMessage(ConsoleMessage::cre ate(JSMessageSource, WarningMessageLevel, |
200 "It is recommended that a robustness level be specified. Not specify ing the robustness level could " | 214 "It is recommended that a robustness level be specified. Not specify ing the robustness level could " |
201 "result in unexpected behavior in the future, potentially including failure to play.")); | 215 "result in unexpected behavior in the future, potentially including failure to play.")); |
202 } | 216 } |
203 } | 217 } |
204 | 218 |
219 void MediaKeySystemAccessInitializer::checkEmptyCodecs(const WebMediaKeySystemCo nfiguration& config) | |
220 { | |
221 // This is only checking for empty codecs in the selected configuration, | |
222 // as apps may pass container only contentType strings for compatibility | |
223 // with other implementations. | |
224 // This will only check that all returned capabilities do not contain | |
225 // codecs. This avoids alerting on configurations that will continue | |
226 // to succeed in the future once strict checking is enforced. | |
227 bool areAllAudioCodecsEmpty = false; | |
228 if (config.hasAudioCapabilities && !config.audioCapabilities.isEmpty()) { | |
229 areAllAudioCodecsEmpty = std::find_if(config.audioCapabilities.begin(), config.audioCapabilities.end(), AreCodecsSpecified) | |
230 == config.audioCapabilities.end(); | |
231 } | |
232 | |
233 bool areAllVideoCodecsEmpty = false; | |
234 if (config.hasVideoCapabilities && !config.videoCapabilities.isEmpty()) { | |
235 areAllVideoCodecsEmpty = std::find_if(config.videoCapabilities.begin(), config.videoCapabilities.end(), AreCodecsSpecified) | |
236 == config.videoCapabilities.end(); | |
237 } | |
238 | |
239 if (areAllAudioCodecsEmpty || areAllVideoCodecsEmpty) { | |
240 Deprecation::countDeprecation(m_resolver->getExecutionContext(), UseCoun ter::EncryptedMediaAllSelectedContentTypesMissingCodecs); | |
ddorwin
2016/04/28 02:30:05
This name isn't strictly correct since one type co
| |
241 } else { | |
242 UseCounter::count(m_resolver->getExecutionContext(), UseCounter::Encrypt edMediaAllSelectedContentTypesHaveCodecs); | |
243 } | |
244 } | |
245 | |
205 } // namespace | 246 } // namespace |
206 | 247 |
207 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( | 248 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( |
208 ScriptState* scriptState, | 249 ScriptState* scriptState, |
209 Navigator& navigator, | 250 Navigator& navigator, |
210 const String& keySystem, | 251 const String& keySystem, |
211 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) | 252 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) |
212 { | 253 { |
213 WTF_LOG(Media, "NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemA ccess()"); | 254 WTF_LOG(Media, "NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemA ccess()"); |
214 | 255 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 // initialize the MediaKeySystemAccess object. | 298 // initialize the MediaKeySystemAccess object. |
258 MediaKeysController* controller = MediaKeysController::from(document->page() ); | 299 MediaKeysController* controller = MediaKeysController::from(document->page() ); |
259 WebEncryptedMediaClient* mediaClient = controller->encryptedMediaClient(exec utionContext); | 300 WebEncryptedMediaClient* mediaClient = controller->encryptedMediaClient(exec utionContext); |
260 mediaClient->requestMediaKeySystemAccess(WebEncryptedMediaRequest(initialize r)); | 301 mediaClient->requestMediaKeySystemAccess(WebEncryptedMediaRequest(initialize r)); |
261 | 302 |
262 // 8. Return promise. | 303 // 8. Return promise. |
263 return promise; | 304 return promise; |
264 } | 305 } |
265 | 306 |
266 } // namespace blink | 307 } // namespace blink |
OLD | NEW |