Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1286)

Side by Side Diff: third_party/WebKit/Source/modules/encryptedmedia/NavigatorRequestMediaKeySystemAccess.cpp

Issue 2686133002: EME: Require codecs parameter for audio/videoCapabilities (Closed)
Patch Set: changes + additional test fixes Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 static WebVector<WebEncryptedMediaSessionType> convertSessionTypes( 80 static WebVector<WebEncryptedMediaSessionType> convertSessionTypes(
81 const Vector<String>& sessionTypes) { 81 const Vector<String>& sessionTypes) {
82 WebVector<WebEncryptedMediaSessionType> result(sessionTypes.size()); 82 WebVector<WebEncryptedMediaSessionType> result(sessionTypes.size());
83 for (size_t i = 0; i < sessionTypes.size(); ++i) 83 for (size_t i = 0; i < sessionTypes.size(); ++i)
84 result[i] = EncryptedMediaUtils::convertToSessionType(sessionTypes[i]); 84 result[i] = EncryptedMediaUtils::convertToSessionType(sessionTypes[i]);
85 return result; 85 return result;
86 } 86 }
87 87
88 static bool AreCodecsSpecified(
89 const WebMediaKeySystemMediaCapability& capability) {
90 return !capability.codecs.isEmpty();
91 }
92
93 // This class allows capabilities to be checked and a MediaKeySystemAccess 88 // This class allows capabilities to be checked and a MediaKeySystemAccess
94 // object to be created asynchronously. 89 // object to be created asynchronously.
95 class MediaKeySystemAccessInitializer final : public EncryptedMediaRequest { 90 class MediaKeySystemAccessInitializer final : public EncryptedMediaRequest {
96 WTF_MAKE_NONCOPYABLE(MediaKeySystemAccessInitializer); 91 WTF_MAKE_NONCOPYABLE(MediaKeySystemAccessInitializer);
97 92
98 public: 93 public:
99 MediaKeySystemAccessInitializer( 94 MediaKeySystemAccessInitializer(
100 ScriptState*, 95 ScriptState*,
101 const String& keySystem, 96 const String& keySystem,
102 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations); 97 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations);
(...skipping 18 matching lines...) Expand all
121 116
122 private: 117 private:
123 // Returns true if the ExecutionContext is valid, false otherwise. 118 // Returns true if the ExecutionContext is valid, false otherwise.
124 bool isExecutionContextValid() const; 119 bool isExecutionContextValid() const;
125 120
126 // For widevine key system, generate warning and report to UMA if 121 // For widevine key system, generate warning and report to UMA if
127 // |m_supportedConfigurations| contains any video capability with empty 122 // |m_supportedConfigurations| contains any video capability with empty
128 // robustness string. 123 // robustness string.
129 void checkVideoCapabilityRobustness() const; 124 void checkVideoCapabilityRobustness() const;
130 125
131 // Generate deprecation warning and log UseCounter if configuration
132 // contains only container-only contentType strings.
133 // TODO(jrummell): Remove once this is no longer allowed.
134 // See http://crbug.com/605661.
135 void checkEmptyCodecs(const WebMediaKeySystemConfiguration&);
136
137 Member<ScriptPromiseResolver> m_resolver; 126 Member<ScriptPromiseResolver> m_resolver;
138 const String m_keySystem; 127 const String m_keySystem;
139 WebVector<WebMediaKeySystemConfiguration> m_supportedConfigurations; 128 WebVector<WebMediaKeySystemConfiguration> m_supportedConfigurations;
140 }; 129 };
141 130
142 MediaKeySystemAccessInitializer::MediaKeySystemAccessInitializer( 131 MediaKeySystemAccessInitializer::MediaKeySystemAccessInitializer(
143 ScriptState* scriptState, 132 ScriptState* scriptState,
144 const String& keySystem, 133 const String& keySystem,
145 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) 134 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations)
146 : m_resolver(ScriptPromiseResolver::create(scriptState)), 135 : m_resolver(ScriptPromiseResolver::create(scriptState)),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 181 }
193 182
194 SecurityOrigin* MediaKeySystemAccessInitializer::getSecurityOrigin() const { 183 SecurityOrigin* MediaKeySystemAccessInitializer::getSecurityOrigin() const {
195 return isExecutionContextValid() 184 return isExecutionContextValid()
196 ? m_resolver->getExecutionContext()->getSecurityOrigin() 185 ? m_resolver->getExecutionContext()->getSecurityOrigin()
197 : nullptr; 186 : nullptr;
198 } 187 }
199 188
200 void MediaKeySystemAccessInitializer::requestSucceeded( 189 void MediaKeySystemAccessInitializer::requestSucceeded(
201 WebContentDecryptionModuleAccess* access) { 190 WebContentDecryptionModuleAccess* access) {
202 checkEmptyCodecs(access->getConfiguration());
203
204 if (!isExecutionContextValid()) 191 if (!isExecutionContextValid())
205 return; 192 return;
206 193
207 m_resolver->resolve( 194 m_resolver->resolve(
208 new MediaKeySystemAccess(m_keySystem, WTF::wrapUnique(access))); 195 new MediaKeySystemAccess(m_keySystem, WTF::wrapUnique(access)));
209 m_resolver.clear(); 196 m_resolver.clear();
210 } 197 }
211 198
212 void MediaKeySystemAccessInitializer::requestNotSupported( 199 void MediaKeySystemAccessInitializer::requestNotSupported(
213 const WebString& errorMessage) { 200 const WebString& errorMessage) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 244
258 if (hasEmptyRobustness) { 245 if (hasEmptyRobustness) {
259 m_resolver->getExecutionContext()->addConsoleMessage(ConsoleMessage::create( 246 m_resolver->getExecutionContext()->addConsoleMessage(ConsoleMessage::create(
260 JSMessageSource, WarningMessageLevel, 247 JSMessageSource, WarningMessageLevel,
261 "It is recommended that a robustness level be specified. Not " 248 "It is recommended that a robustness level be specified. Not "
262 "specifying the robustness level could result in unexpected behavior, " 249 "specifying the robustness level could result in unexpected behavior, "
263 "potentially including failure to play.")); 250 "potentially including failure to play."));
264 } 251 }
265 } 252 }
266 253
267 void MediaKeySystemAccessInitializer::checkEmptyCodecs(
268 const WebMediaKeySystemConfiguration& config) {
269 // This is only checking for empty codecs in the selected configuration,
270 // as apps may pass container only contentType strings for compatibility
271 // with other implementations.
272 // This will only check that all returned capabilities do not contain
273 // codecs. This avoids alerting on configurations that will continue
274 // to succeed in the future once strict checking is enforced.
275 bool areAllAudioCodecsEmpty = false;
276 if (!config.audioCapabilities.isEmpty()) {
277 areAllAudioCodecsEmpty =
278 std::find_if(config.audioCapabilities.begin(),
279 config.audioCapabilities.end(),
280 AreCodecsSpecified) == config.audioCapabilities.end();
281 }
282
283 bool areAllVideoCodecsEmpty = false;
284 if (!config.videoCapabilities.isEmpty()) {
285 areAllVideoCodecsEmpty =
286 std::find_if(config.videoCapabilities.begin(),
287 config.videoCapabilities.end(),
288 AreCodecsSpecified) == config.videoCapabilities.end();
289 }
290
291 if (areAllAudioCodecsEmpty || areAllVideoCodecsEmpty) {
292 Deprecation::countDeprecation(
293 m_resolver->getExecutionContext(),
294 UseCounter::EncryptedMediaAllSelectedContentTypesMissingCodecs);
295 } else {
296 UseCounter::count(
297 m_resolver->getExecutionContext(),
298 UseCounter::EncryptedMediaAllSelectedContentTypesHaveCodecs);
299 }
300 }
301
302 } // namespace 254 } // namespace
303 255
304 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( 256 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess(
305 ScriptState* scriptState, 257 ScriptState* scriptState,
306 Navigator& navigator, 258 Navigator& navigator,
307 const String& keySystem, 259 const String& keySystem,
308 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) { 260 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) {
309 DVLOG(3) << __func__; 261 DVLOG(3) << __func__;
310 262
311 ExecutionContext* executionContext = scriptState->getExecutionContext(); 263 ExecutionContext* executionContext = scriptState->getExecutionContext();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 WebEncryptedMediaClient* mediaClient = 329 WebEncryptedMediaClient* mediaClient =
378 controller->encryptedMediaClient(executionContext); 330 controller->encryptedMediaClient(executionContext);
379 mediaClient->requestMediaKeySystemAccess( 331 mediaClient->requestMediaKeySystemAccess(
380 WebEncryptedMediaRequest(initializer)); 332 WebEncryptedMediaRequest(initializer));
381 333
382 // 7. Return promise. 334 // 7. Return promise.
383 return promise; 335 return promise;
384 } 336 }
385 337
386 } // namespace blink 338 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698