Chromium Code Reviews| 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 warning and report UMA if configuration contains a | |
| 121 // container-only contentType string. | |
| 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 allows apps to provide both (one with codecs, one without) | |
|
ddorwin
2016/04/27 23:33:48
Since we don't think this is useful, perhaps we sh
jrummell
2016/04/28 01:32:47
Done.
| |
| 226 // for compatibility reasons, and that will continue to succeed in the | |
| 227 // future once strict checking is enforced. | |
| 228 bool areAllAudioCodecsEmpty = false; | |
| 229 if (config.hasAudioCapabilities && !config.audioCapabilities.isEmpty()) { | |
| 230 areAllAudioCodecsEmpty = std::find_if(config.audioCapabilities.begin(), config.audioCapabilities.end(), AreCodecsSpecified) | |
| 231 == config.audioCapabilities.end(); | |
|
jrummell
2016/04/26 21:23:57
Tried to split this into meaningful lines so that
| |
| 232 | |
| 233 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, emptyAudioCodecsHi stogram, | |
| 234 new EnumerationHistogram("Media.EME.RequestMediaKeySystemAccess.Sele ctedAudioContentTypeWithoutCodecs", 2)); | |
|
ddorwin
2016/04/27 23:33:48
Hmm. This isn't strictly accurate since we are che
jrummell
2016/04/28 01:32:47
Switched to UseCounter.
| |
| 235 emptyAudioCodecsHistogram.count(areAllAudioCodecsEmpty); | |
| 236 } | |
| 237 | |
| 238 bool areAllVideoCodecsEmpty = false; | |
| 239 if (config.hasVideoCapabilities && !config.videoCapabilities.isEmpty()) { | |
| 240 areAllVideoCodecsEmpty = std::find_if(config.videoCapabilities.begin(), config.videoCapabilities.end(), AreCodecsSpecified) | |
| 241 == config.videoCapabilities.end(); | |
| 242 | |
| 243 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, emptyVideoCodecsHi stogram, | |
| 244 new EnumerationHistogram("Media.EME.RequestMediaKeySystemAccess.Sele ctedVideoContentTypeWithoutCodecs", 2)); | |
| 245 emptyVideoCodecsHistogram.count(areAllVideoCodecsEmpty); | |
| 246 } | |
| 247 | |
| 248 if (areAllAudioCodecsEmpty || areAllVideoCodecsEmpty) { | |
| 249 m_resolver->getExecutionContext()->addConsoleMessage(ConsoleMessage::cre ate(JSMessageSource, WarningMessageLevel, | |
|
ddorwin
2016/04/27 23:33:48
Should we use countDeprecation() instead of a sepa
jrummell
2016/04/28 01:32:47
Done (along with counting the successes).
| |
| 250 "contentType strings without codecs will not be supported in the fut ure." | |
| 251 "Please specify the desired codec(s) as part of the contentType.")); | |
| 252 } | |
| 253 } | |
| 254 | |
| 205 } // namespace | 255 } // namespace |
| 206 | 256 |
| 207 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( | 257 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( |
| 208 ScriptState* scriptState, | 258 ScriptState* scriptState, |
| 209 Navigator& navigator, | 259 Navigator& navigator, |
| 210 const String& keySystem, | 260 const String& keySystem, |
| 211 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) | 261 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) |
| 212 { | 262 { |
| 213 WTF_LOG(Media, "NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemA ccess()"); | 263 WTF_LOG(Media, "NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemA ccess()"); |
| 214 | 264 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 // initialize the MediaKeySystemAccess object. | 307 // initialize the MediaKeySystemAccess object. |
| 258 MediaKeysController* controller = MediaKeysController::from(document->page() ); | 308 MediaKeysController* controller = MediaKeysController::from(document->page() ); |
| 259 WebEncryptedMediaClient* mediaClient = controller->encryptedMediaClient(exec utionContext); | 309 WebEncryptedMediaClient* mediaClient = controller->encryptedMediaClient(exec utionContext); |
| 260 mediaClient->requestMediaKeySystemAccess(WebEncryptedMediaRequest(initialize r)); | 310 mediaClient->requestMediaKeySystemAccess(WebEncryptedMediaRequest(initialize r)); |
| 261 | 311 |
| 262 // 8. Return promise. | 312 // 8. Return promise. |
| 263 return promise; | 313 return promise; |
| 264 } | 314 } |
| 265 | 315 |
| 266 } // namespace blink | 316 } // namespace blink |
| OLD | NEW |