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

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

Issue 2349813002: EME: Update MediaKeySystemConfiguration defaults; require non-empty capabilities (Closed)
Patch Set: Created 4 years, 3 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
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 "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"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // TODO(xhwang): Remove after we handle empty robustness correctly. 115 // TODO(xhwang): Remove after we handle empty robustness correctly.
116 // See http://crbug.com/482277 116 // See http://crbug.com/482277
117 void checkVideoCapabilityRobustness() const; 117 void checkVideoCapabilityRobustness() const;
118 118
119 // Generate deprecation warning and log UseCounter if configuration 119 // Generate deprecation warning and log UseCounter if configuration
120 // contains only container-only contentType strings. 120 // contains only container-only contentType strings.
121 // TODO(jrummell): Remove once this is no longer allowed. 121 // TODO(jrummell): Remove once this is no longer allowed.
122 // See http://crbug.com/605661. 122 // See http://crbug.com/605661.
123 void checkEmptyCodecs(const WebMediaKeySystemConfiguration&); 123 void checkEmptyCodecs(const WebMediaKeySystemConfiguration&);
124 124
125 // Generate deprecation warning and log UseCounter if configuration does
126 // not have at least one of 'audioCapabilities' and 'videoCapabilities'
127 // non-empty.
128 // TODO(jrummell): Remove once this is enforced.
129 // See http://crbug.com/616233.
130 void checkCapabilitiesProvided(const WebMediaKeySystemConfiguration&);
131
125 Member<ScriptPromiseResolver> m_resolver; 132 Member<ScriptPromiseResolver> m_resolver;
126 const String m_keySystem; 133 const String m_keySystem;
127 WebVector<WebMediaKeySystemConfiguration> m_supportedConfigurations; 134 WebVector<WebMediaKeySystemConfiguration> m_supportedConfigurations;
128 }; 135 };
129 136
130 MediaKeySystemAccessInitializer::MediaKeySystemAccessInitializer(ScriptState* sc riptState, const String& keySystem, const HeapVector<MediaKeySystemConfiguration >& supportedConfigurations) 137 MediaKeySystemAccessInitializer::MediaKeySystemAccessInitializer(ScriptState* sc riptState, const String& keySystem, const HeapVector<MediaKeySystemConfiguration >& supportedConfigurations)
131 : m_resolver(ScriptPromiseResolver::create(scriptState)) 138 : m_resolver(ScriptPromiseResolver::create(scriptState))
132 , m_keySystem(keySystem) 139 , m_keySystem(keySystem)
133 , m_supportedConfigurations(supportedConfigurations.size()) 140 , m_supportedConfigurations(supportedConfigurations.size())
134 { 141 {
135 for (size_t i = 0; i < supportedConfigurations.size(); ++i) { 142 for (size_t i = 0; i < supportedConfigurations.size(); ++i) {
136 const MediaKeySystemConfiguration& config = supportedConfigurations[i]; 143 const MediaKeySystemConfiguration& config = supportedConfigurations[i];
137 WebMediaKeySystemConfiguration webConfig; 144 WebMediaKeySystemConfiguration webConfig;
138 if (config.hasInitDataTypes()) { 145
139 webConfig.hasInitDataTypes = true; 146 DCHECK(config.hasInitDataTypes());
140 webConfig.initDataTypes = convertInitDataTypes(config.initDataTypes( )); 147 webConfig.initDataTypes = convertInitDataTypes(config.initDataTypes());
141 } 148
142 if (config.hasAudioCapabilities()) { 149 DCHECK(config.hasAudioCapabilities());
143 webConfig.hasAudioCapabilities = true; 150 webConfig.audioCapabilities = convertCapabilities(config.audioCapabiliti es());
144 webConfig.audioCapabilities = convertCapabilities(config.audioCapabi lities()); 151
145 } 152 DCHECK(config.hasVideoCapabilities());
146 if (config.hasVideoCapabilities()) { 153 webConfig.videoCapabilities = convertCapabilities(config.videoCapabiliti es());
147 webConfig.hasVideoCapabilities = true; 154
148 webConfig.videoCapabilities = convertCapabilities(config.videoCapabi lities()); 155 checkCapabilitiesProvided(webConfig);
149 } 156
150 DCHECK(config.hasDistinctiveIdentifier()); 157 DCHECK(config.hasDistinctiveIdentifier());
151 webConfig.distinctiveIdentifier = convertMediaKeysRequirement(config.dis tinctiveIdentifier()); 158 webConfig.distinctiveIdentifier = convertMediaKeysRequirement(config.dis tinctiveIdentifier());
159
152 DCHECK(config.hasPersistentState()); 160 DCHECK(config.hasPersistentState());
153 webConfig.persistentState = convertMediaKeysRequirement(config.persisten tState()); 161 webConfig.persistentState = convertMediaKeysRequirement(config.persisten tState());
162
154 if (config.hasSessionTypes()) { 163 if (config.hasSessionTypes()) {
155 webConfig.hasSessionTypes = true; 164 webConfig.hasSessionTypes = true;
156 webConfig.sessionTypes = convertSessionTypes(config.sessionTypes()); 165 webConfig.sessionTypes = convertSessionTypes(config.sessionTypes());
157 } 166 }
167
158 // If |label| is not present, it will be a null string. 168 // If |label| is not present, it will be a null string.
159 webConfig.label = config.label(); 169 webConfig.label = config.label();
160 m_supportedConfigurations[i] = webConfig; 170 m_supportedConfigurations[i] = webConfig;
161 } 171 }
162 172
163 checkVideoCapabilityRobustness(); 173 checkVideoCapabilityRobustness();
164 } 174 }
165 175
166 void MediaKeySystemAccessInitializer::requestSucceeded(WebContentDecryptionModul eAccess* access) 176 void MediaKeySystemAccessInitializer::requestSucceeded(WebContentDecryptionModul eAccess* access)
167 { 177 {
(...skipping 12 matching lines...) Expand all
180 void MediaKeySystemAccessInitializer::checkVideoCapabilityRobustness() const 190 void MediaKeySystemAccessInitializer::checkVideoCapabilityRobustness() const
181 { 191 {
182 // Only check for widevine key system. 192 // Only check for widevine key system.
183 if (keySystem() != "com.widevine.alpha") 193 if (keySystem() != "com.widevine.alpha")
184 return; 194 return;
185 195
186 bool hasVideoCapabilities = false; 196 bool hasVideoCapabilities = false;
187 bool hasEmptyRobustness = false; 197 bool hasEmptyRobustness = false;
188 198
189 for (const auto& config : m_supportedConfigurations) { 199 for (const auto& config : m_supportedConfigurations) {
190 if (!config.hasVideoCapabilities)
191 continue;
192
193 hasVideoCapabilities = true;
194
195 for (const auto& capability : config.videoCapabilities) { 200 for (const auto& capability : config.videoCapabilities) {
201 hasVideoCapabilities = true;
196 if (capability.robustness.isEmpty()) { 202 if (capability.robustness.isEmpty()) {
197 hasEmptyRobustness = true; 203 hasEmptyRobustness = true;
198 break; 204 break;
199 } 205 }
200 } 206 }
201 207
202 if (hasEmptyRobustness) 208 if (hasEmptyRobustness)
203 break; 209 break;
204 } 210 }
205 211
(...skipping 11 matching lines...) Expand all
217 223
218 void MediaKeySystemAccessInitializer::checkEmptyCodecs(const WebMediaKeySystemCo nfiguration& config) 224 void MediaKeySystemAccessInitializer::checkEmptyCodecs(const WebMediaKeySystemCo nfiguration& config)
219 { 225 {
220 // This is only checking for empty codecs in the selected configuration, 226 // This is only checking for empty codecs in the selected configuration,
221 // as apps may pass container only contentType strings for compatibility 227 // as apps may pass container only contentType strings for compatibility
222 // with other implementations. 228 // with other implementations.
223 // This will only check that all returned capabilities do not contain 229 // This will only check that all returned capabilities do not contain
224 // codecs. This avoids alerting on configurations that will continue 230 // codecs. This avoids alerting on configurations that will continue
225 // to succeed in the future once strict checking is enforced. 231 // to succeed in the future once strict checking is enforced.
226 bool areAllAudioCodecsEmpty = false; 232 bool areAllAudioCodecsEmpty = false;
227 if (config.hasAudioCapabilities && !config.audioCapabilities.isEmpty()) { 233 if (!config.audioCapabilities.isEmpty()) {
228 areAllAudioCodecsEmpty = std::find_if(config.audioCapabilities.begin(), config.audioCapabilities.end(), AreCodecsSpecified) 234 areAllAudioCodecsEmpty = std::find_if(config.audioCapabilities.begin(), config.audioCapabilities.end(), AreCodecsSpecified)
229 == config.audioCapabilities.end(); 235 == config.audioCapabilities.end();
230 } 236 }
231 237
232 bool areAllVideoCodecsEmpty = false; 238 bool areAllVideoCodecsEmpty = false;
233 if (config.hasVideoCapabilities && !config.videoCapabilities.isEmpty()) { 239 if (!config.videoCapabilities.isEmpty()) {
234 areAllVideoCodecsEmpty = std::find_if(config.videoCapabilities.begin(), config.videoCapabilities.end(), AreCodecsSpecified) 240 areAllVideoCodecsEmpty = std::find_if(config.videoCapabilities.begin(), config.videoCapabilities.end(), AreCodecsSpecified)
235 == config.videoCapabilities.end(); 241 == config.videoCapabilities.end();
236 } 242 }
237 243
238 if (areAllAudioCodecsEmpty || areAllVideoCodecsEmpty) { 244 if (areAllAudioCodecsEmpty || areAllVideoCodecsEmpty) {
239 Deprecation::countDeprecation(m_resolver->getExecutionContext(), UseCoun ter::EncryptedMediaAllSelectedContentTypesMissingCodecs); 245 Deprecation::countDeprecation(m_resolver->getExecutionContext(), UseCoun ter::EncryptedMediaAllSelectedContentTypesMissingCodecs);
240 } else { 246 } else {
241 UseCounter::count(m_resolver->getExecutionContext(), UseCounter::Encrypt edMediaAllSelectedContentTypesHaveCodecs); 247 UseCounter::count(m_resolver->getExecutionContext(), UseCounter::Encrypt edMediaAllSelectedContentTypesHaveCodecs);
242 } 248 }
243 } 249 }
244 250
251 void MediaKeySystemAccessInitializer::checkCapabilitiesProvided(const WebMediaKe ySystemConfiguration& config)
252 {
253 bool atLeastOneAudioCapability = config.audioCapabilities.size() > 0;
254 bool atLeastOneVideoCapability = config.videoCapabilities.size() > 0;
255
256 if (atLeastOneAudioCapability || atLeastOneVideoCapability) {
257 UseCounter::count(m_resolver->getExecutionContext(), UseCounter::Encrypt edMediaCapabilityProvided);
258 } else {
259 Deprecation::countDeprecation(m_resolver->getExecutionContext(), UseCoun ter::EncryptedMediaCapabilityNotProvided);
260 }
261 }
262
245 } // namespace 263 } // namespace
246 264
247 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( 265 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess(
248 ScriptState* scriptState, 266 ScriptState* scriptState,
249 Navigator& navigator, 267 Navigator& navigator,
250 const String& keySystem, 268 const String& keySystem,
251 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) 269 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations)
252 { 270 {
253 DVLOG(3) << __func__; 271 DVLOG(3) << __func__;
254 272
255 // From https://w3c.github.io/encrypted-media/#requestMediaKeySystemAccess 273 // From https://w3c.github.io/encrypted-media/#requestMediaKeySystemAccess
256 // When this method is invoked, the user agent must run the following steps: 274 // When this method is invoked, the user agent must run the following steps:
257 // 1. If keySystem is an empty string, return a promise rejected with a 275 // 1. If keySystem is an empty string, return a promise rejected with a
258 // new DOMException whose name is InvalidAccessError. 276 // new DOMException whose name is InvalidAccessError.
259 if (keySystem.isEmpty()) { 277 if (keySystem.isEmpty()) {
260 return ScriptPromise::rejectWithDOMException( 278 return ScriptPromise::rejectWithDOMException(
261 scriptState, DOMException::create(InvalidAccessError, "The keySystem parameter is empty.")); 279 scriptState, DOMException::create(InvalidAccessError, "The keySystem parameter is empty."));
262 } 280 }
263 281
264 // 2. If supportedConfigurations was provided and is empty, return a 282 // 2. If supportedConfigurations was provided and is empty, return a
265 // promise rejected with a new DOMException whose name is 283 // promise rejected with a new DOMException whose name is
266 // InvalidAccessError. 284 // InvalidAccessError.
267 if (!supportedConfigurations.size()) { 285 if (!supportedConfigurations.size()) {
268 return ScriptPromise::rejectWithDOMException( 286 return ScriptPromise::rejectWithDOMException(
269 scriptState, DOMException::create(InvalidAccessError, "The supported Configurations parameter is empty.")); 287 scriptState, DOMException::create(InvalidAccessError, "The supported Configurations parameter is empty."));
270 } 288 }
271 289
272 // 3-4. 'May Document use powerful features?' check. 290 // Note: This method should only be exposed to secure contexts as indicated
291 // by the [SecureContext] IDL attribute. Since that will break some existing
292 // sites, we simply keep track of sites that aren't secure and output a
293 // deprecation message.
273 ExecutionContext* executionContext = scriptState->getExecutionContext(); 294 ExecutionContext* executionContext = scriptState->getExecutionContext();
274 String errorMessage; 295 String errorMessage;
275 if (executionContext->isSecureContext(errorMessage)) { 296 if (executionContext->isSecureContext(errorMessage)) {
276 UseCounter::count(executionContext, UseCounter::EncryptedMediaSecureOrig in); 297 UseCounter::count(executionContext, UseCounter::EncryptedMediaSecureOrig in);
277 } else { 298 } else {
278 Deprecation::countDeprecation(executionContext, UseCounter::EncryptedMed iaInsecureOrigin); 299 Deprecation::countDeprecation(executionContext, UseCounter::EncryptedMed iaInsecureOrigin);
279 // TODO(ddorwin): Implement the following: 300 // TODO(ddorwin): Implement the following:
280 // Reject promise with a new DOMException whose name is NotSupportedErro r. 301 // Reject promise with a new DOMException whose name is NotSupportedErro r.
281 } 302 }
282 303
283 // 5. Let origin be the origin of document. 304 // 3. Let document be the calling context's Document.
284 // (Passed with the execution context in step 7.)
285
286 // 6. Let promise be a new promise.
287 Document* document = toDocument(executionContext); 305 Document* document = toDocument(executionContext);
288 if (!document->page()) { 306 if (!document->page()) {
289 return ScriptPromise::rejectWithDOMException( 307 return ScriptPromise::rejectWithDOMException(
290 scriptState, DOMException::create(InvalidStateError, "The context pr ovided is not associated with a page.")); 308 scriptState, DOMException::create(InvalidStateError, "The context pr ovided is not associated with a page."));
291 } 309 }
292 310
311 // 4. Let origin be the origin of document.
312 // (Passed with the execution context.)
313
314 // 5. Let promise be a new promise.
293 MediaKeySystemAccessInitializer* initializer = new MediaKeySystemAccessIniti alizer(scriptState, keySystem, supportedConfigurations); 315 MediaKeySystemAccessInitializer* initializer = new MediaKeySystemAccessIniti alizer(scriptState, keySystem, supportedConfigurations);
294 ScriptPromise promise = initializer->promise(); 316 ScriptPromise promise = initializer->promise();
295 317
296 // 7. Asynchronously determine support, and if allowed, create and 318 // 6. Asynchronously determine support, and if allowed, create and
297 // initialize the MediaKeySystemAccess object. 319 // initialize the MediaKeySystemAccess object.
298 MediaKeysController* controller = MediaKeysController::from(document->page() ); 320 MediaKeysController* controller = MediaKeysController::from(document->page() );
299 WebEncryptedMediaClient* mediaClient = controller->encryptedMediaClient(exec utionContext); 321 WebEncryptedMediaClient* mediaClient = controller->encryptedMediaClient(exec utionContext);
300 mediaClient->requestMediaKeySystemAccess(WebEncryptedMediaRequest(initialize r)); 322 mediaClient->requestMediaKeySystemAccess(WebEncryptedMediaRequest(initialize r));
301 323
302 // 8. Return promise. 324 // 7. Return promise.
303 return promise; 325 return promise;
304 } 326 }
305 327
306 } // namespace blink 328 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698