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

Side by Side Diff: media/blink/webencryptedmediaclient_impl.cc

Issue 1023863002: Create an interface for KeySystems, migrate WebEncryptedMediaClientImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@robustness
Patch Set: Rebase. Created 5 years, 9 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 | « media/blink/webencryptedmediaclient_impl.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 "webencryptedmediaclient_impl.h" 5 #include "webencryptedmediaclient_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Whether permission to use a distinctive identifier has been granted. 119 // Whether permission to use a distinctive identifier has been granted.
120 const bool is_permission_granted_; 120 const bool is_permission_granted_;
121 121
122 // Whether a rule has been added that requires a distinctive identifier. 122 // Whether a rule has been added that requires a distinctive identifier.
123 bool is_identifier_required_; 123 bool is_identifier_required_;
124 124
125 // Whether a rule has been added that recommends a distinctive identifier. 125 // Whether a rule has been added that recommends a distinctive identifier.
126 bool is_identifier_recommended_; 126 bool is_identifier_recommended_;
127 }; 127 };
128 128
129 static bool IsSupportedContentType(const std::string& key_system, 129 static bool IsSupportedContentType(
130 const std::string& mime_type, 130 const KeySystems& key_systems,
131 const std::string& codecs) { 131 const std::string& key_system,
132 EmeMediaType media_type,
133 const std::string& container_mime_type,
134 const std::string& codecs) {
132 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid 135 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid
133 // parameters can be rejected. http://crbug.com/417561 136 // parameters can be rejected. http://crbug.com/417561
134 // TODO(sandersd): Pass in the media type (audio or video) and check that the 137 std::string container_lower = base::StringToLowerASCII(container_mime_type);
135 // container type matches. http://crbug.com/457384
136 std::string container = base::StringToLowerASCII(mime_type);
137 138
138 // Check that |codecs| are supported by the CDM. This check does not handle 139 // Check that |codecs| are supported by the CDM. This check does not handle
139 // extended codecs, so extended codec information is stripped. 140 // extended codecs, so extended codec information is stripped.
140 // TODO(sandersd): Reject codecs that do not match the media type.
141 // http://crbug.com/457386
142 std::vector<std::string> codec_vector; 141 std::vector<std::string> codec_vector;
143 net::ParseCodecString(codecs, &codec_vector, true); 142 net::ParseCodecString(codecs, &codec_vector, true);
144 if (!IsSupportedKeySystemWithMediaMimeType(container, codec_vector, 143 if (!key_systems.IsSupportedCodecCombination(
145 key_system)) { 144 key_system, media_type, container_lower, codec_vector)) {
146 return false; 145 return false;
147 } 146 }
148 147
149 // Check that |codecs| are supported by Chrome. This is done primarily to 148 // Check that |codecs| are supported by Chrome. This is done primarily to
150 // validate extended codecs, but it also ensures that the CDM cannot support 149 // validate extended codecs, but it also ensures that the CDM cannot support
151 // codecs that Chrome does not (which would be bad because it would require 150 // codecs that Chrome does not (which would be bad because it would require
152 // considering the accumulated configuration, and could affect whether secure 151 // considering the accumulated configuration, and could affect whether secure
153 // decode is required). 152 // decode is required).
154 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751
155 codec_vector.clear(); 153 codec_vector.clear();
156 net::ParseCodecString(codecs, &codec_vector, false); 154 net::ParseCodecString(codecs, &codec_vector, false);
157 return net::AreSupportedMediaCodecs(codec_vector); 155 return (net::IsSupportedStrictMediaMimeType(container_lower, codec_vector) ==
156 net::IsSupported);
158 } 157 }
159 158
160 static bool GetSupportedCapabilities( 159 static bool GetSupportedCapabilities(
160 const KeySystems& key_systems,
161 const std::string& key_system, 161 const std::string& key_system,
162 EmeMediaType media_type,
162 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& 163 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>&
163 requested_media_capabilities, 164 requested_media_capabilities,
164 EmeMediaType media_type, 165 ConfigState* config_state,
165 std::vector<blink::WebMediaKeySystemMediaCapability>* 166 std::vector<blink::WebMediaKeySystemMediaCapability>*
166 supported_media_capabilities, 167 supported_media_capabilities) {
167 ConfigState* config_state) {
168 // From 168 // From
169 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type 169 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type
170 // 1. Let local accumulated capabilities be a local copy of partial 170 // 1. Let local accumulated capabilities be a local copy of partial
171 // configuration. 171 // configuration.
172 // (Skipped as we directly update |config_state|. This is safe because we 172 // (Skipped as we directly update |config_state|. This is safe because we
173 // only do so when at least one requested media capability is supported.) 173 // only do so when at least one requested media capability is supported.)
174 // 2. Let supported media capabilities be empty. 174 // 2. Let supported media capabilities be empty.
175 DCHECK_EQ(supported_media_capabilities->size(), 0ul); 175 DCHECK_EQ(supported_media_capabilities->size(), 0ul);
176 // 3. For each value in requested media capabilities: 176 // 3. For each value in requested media capabilities:
177 for (size_t i = 0; i < requested_media_capabilities.size(); i++) { 177 for (size_t i = 0; i < requested_media_capabilities.size(); i++) {
178 // 3.1. Let contentType be the value's contentType member. 178 // 3.1. Let contentType be the value's contentType member.
179 // 3.2. Let robustness be the value's robustness member. 179 // 3.2. Let robustness be the value's robustness member.
180 const blink::WebMediaKeySystemMediaCapability& capability = 180 const blink::WebMediaKeySystemMediaCapability& capability =
181 requested_media_capabilities[i]; 181 requested_media_capabilities[i];
182 // 3.3. If contentType is the empty string, return null. 182 // 3.3. If contentType is the empty string, return null.
183 if (capability.mimeType.isEmpty()) { 183 if (capability.mimeType.isEmpty()) {
184 DVLOG(2) << "Rejecting requested configuration because " 184 DVLOG(2) << "Rejecting requested configuration because "
185 << "a capability contentType was empty."; 185 << "a capability contentType was empty.";
186 return false; 186 return false;
187 } 187 }
188 // 3.4-3.11. (Implemented by IsSupportedContentType().) 188 // 3.4-3.11. (Implemented by IsSupportedContentType().)
189 if (!base::IsStringASCII(capability.mimeType) || 189 if (!base::IsStringASCII(capability.mimeType) ||
190 !base::IsStringASCII(capability.codecs) || 190 !base::IsStringASCII(capability.codecs) ||
191 !IsSupportedContentType(key_system, 191 !IsSupportedContentType(key_systems, key_system, media_type,
192 base::UTF16ToASCII(capability.mimeType), 192 base::UTF16ToASCII(capability.mimeType),
193 base::UTF16ToASCII(capability.codecs))) { 193 base::UTF16ToASCII(capability.codecs))) {
194 continue; 194 continue;
195 } 195 }
196 // 3.12. If robustness is not the empty string, run the following steps: 196 // 3.12. If robustness is not the empty string, run the following steps:
197 if (!capability.robustness.isEmpty()) { 197 if (!capability.robustness.isEmpty()) {
198 // 3.12.1. If robustness is an unrecognized value or not supported by 198 // 3.12.1. If robustness is an unrecognized value or not supported by
199 // implementation, continue to the next iteration. String 199 // implementation, continue to the next iteration. String
200 // comparison is case-sensitive. 200 // comparison is case-sensitive.
201 if (!base::IsStringASCII(capability.robustness)) 201 if (!base::IsStringASCII(capability.robustness))
202 continue; 202 continue;
203 EmeConfigRule robustness_rule = GetRobustnessConfigRule( 203 EmeConfigRule robustness_rule = key_systems.GetRobustnessConfigRule(
204 key_system, media_type, base::UTF16ToASCII(capability.robustness)); 204 key_system, media_type, base::UTF16ToASCII(capability.robustness));
205 if (!config_state->IsRuleSupported(robustness_rule)) 205 if (!config_state->IsRuleSupported(robustness_rule))
206 continue; 206 continue;
207 config_state->AddRule(robustness_rule); 207 config_state->AddRule(robustness_rule);
208 // 3.12.2. Add robustness to configuration. 208 // 3.12.2. Add robustness to configuration.
209 // (It's already added, we use capability as configuration.) 209 // (It's already added, we use capability as configuration.)
210 } 210 }
211 // 3.13. If the user agent and implementation do not support playback of 211 // 3.13. If the user agent and implementation do not support playback of
212 // encrypted media data as specified by configuration, including all 212 // encrypted media data as specified by configuration, including all
213 // media types, in combination with local accumulated capabilities, 213 // media types, in combination with local accumulated capabilities,
(...skipping 23 matching lines...) Expand all
237 return EME_FEATURE_OPTIONAL; 237 return EME_FEATURE_OPTIONAL;
238 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: 238 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed:
239 return EME_FEATURE_NOT_ALLOWED; 239 return EME_FEATURE_NOT_ALLOWED;
240 } 240 }
241 241
242 NOTREACHED(); 242 NOTREACHED();
243 return EME_FEATURE_NOT_ALLOWED; 243 return EME_FEATURE_NOT_ALLOWED;
244 } 244 }
245 245
246 static ConfigurationSupport GetSupportedConfiguration( 246 static ConfigurationSupport GetSupportedConfiguration(
247 const KeySystems& key_systems,
247 const std::string& key_system, 248 const std::string& key_system,
248 const blink::WebMediaKeySystemConfiguration& candidate, 249 const blink::WebMediaKeySystemConfiguration& candidate,
249 bool was_permission_requested, 250 bool was_permission_requested,
250 bool is_permission_granted, 251 bool is_permission_granted,
251 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { 252 blink::WebMediaKeySystemConfiguration* accumulated_configuration) {
252 ConfigState config_state(was_permission_requested, is_permission_granted); 253 ConfigState config_state(was_permission_requested, is_permission_granted);
253 254
254 // From https://w3c.github.io/encrypted-media/#get-supported-configuration 255 // From https://w3c.github.io/encrypted-media/#get-supported-configuration
255 // 1. Let accumulated configuration be empty. (Done by caller.) 256 // 1. Let accumulated configuration be empty. (Done by caller.)
256 // 2. If candidate configuration's initDataTypes attribute is not empty, run 257 // 2. If candidate configuration's initDataTypes attribute is not empty, run
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // distinctiveIdentifier attribute from the following list: 309 // distinctiveIdentifier attribute from the following list:
309 // - "required": If the implementation does not support a persistent 310 // - "required": If the implementation does not support a persistent
310 // Distinctive Identifier in combination with accumulated configuration, 311 // Distinctive Identifier in combination with accumulated configuration,
311 // return null. 312 // return null.
312 // - "optional": Continue. 313 // - "optional": Continue.
313 // - "not-allowed": If the implementation requires a Distinctive 314 // - "not-allowed": If the implementation requires a Distinctive
314 // Identifier in combination with accumulated configuration, return 315 // Identifier in combination with accumulated configuration, return
315 // null. 316 // null.
316 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and 317 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and
317 // permission has already been denied. This would happen anyway at step 11. 318 // permission has already been denied. This would happen anyway at step 11.
318 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule( 319 EmeConfigRule di_rule = key_systems.GetDistinctiveIdentifierConfigRule(
319 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); 320 key_system, ConvertRequirement(candidate.distinctiveIdentifier));
320 if (!config_state.IsRuleSupported(di_rule)) { 321 if (!config_state.IsRuleSupported(di_rule)) {
321 DVLOG(2) << "Rejecting requested configuration because " 322 DVLOG(2) << "Rejecting requested configuration because "
322 << "the distinctiveIdentifier requirement was not supported."; 323 << "the distinctiveIdentifier requirement was not supported.";
323 return CONFIGURATION_NOT_SUPPORTED; 324 return CONFIGURATION_NOT_SUPPORTED;
324 } 325 }
325 config_state.AddRule(di_rule); 326 config_state.AddRule(di_rule);
326 327
327 // 4. Add the value of the candidate configuration's distinctiveIdentifier 328 // 4. Add the value of the candidate configuration's distinctiveIdentifier
328 // attribute to accumulated configuration. 329 // attribute to accumulated configuration.
329 accumulated_configuration->distinctiveIdentifier = 330 accumulated_configuration->distinctiveIdentifier =
330 candidate.distinctiveIdentifier; 331 candidate.distinctiveIdentifier;
331 332
332 // 5. Follow the steps for the value of candidate configuration's 333 // 5. Follow the steps for the value of candidate configuration's
333 // persistentState attribute from the following list: 334 // persistentState attribute from the following list:
334 // - "required": If the implementation does not support persisting state 335 // - "required": If the implementation does not support persisting state
335 // in combination with accumulated configuration, return null. 336 // in combination with accumulated configuration, return null.
336 // - "optional": Continue. 337 // - "optional": Continue.
337 // - "not-allowed": If the implementation requires persisting state in 338 // - "not-allowed": If the implementation requires persisting state in
338 // combination with accumulated configuration, return null. 339 // combination with accumulated configuration, return null.
339 EmeConfigRule ps_rule = GetPersistentStateConfigRule( 340 EmeConfigRule ps_rule = key_systems.GetPersistentStateConfigRule(
340 key_system, ConvertRequirement(candidate.persistentState)); 341 key_system, ConvertRequirement(candidate.persistentState));
341 if (!config_state.IsRuleSupported(ps_rule)) { 342 if (!config_state.IsRuleSupported(ps_rule)) {
342 DVLOG(2) << "Rejecting requested configuration because " 343 DVLOG(2) << "Rejecting requested configuration because "
343 << "the persistentState requirement was not supported."; 344 << "the persistentState requirement was not supported.";
344 return CONFIGURATION_NOT_SUPPORTED; 345 return CONFIGURATION_NOT_SUPPORTED;
345 } 346 }
346 config_state.AddRule(ps_rule); 347 config_state.AddRule(ps_rule);
347 348
348 // 6. Add the value of the candidate configuration's persistentState 349 // 6. Add the value of the candidate configuration's persistentState
349 // attribute to accumulated configuration. 350 // attribute to accumulated configuration.
350 accumulated_configuration->persistentState = candidate.persistentState; 351 accumulated_configuration->persistentState = candidate.persistentState;
351 352
352 // 7. If candidate configuration's videoCapabilities attribute is not empty, 353 // 7. If candidate configuration's videoCapabilities attribute is not empty,
353 // run the following steps: 354 // run the following steps:
354 if (!candidate.videoCapabilities.isEmpty()) { 355 if (!candidate.videoCapabilities.isEmpty()) {
355 // 7.1. Let video capabilities be the result of executing the Get Supported 356 // 7.1. Let video capabilities be the result of executing the Get Supported
356 // Capabilities for Media Type algorithm on Video, candidate 357 // Capabilities for Media Type algorithm on Video, candidate
357 // configuration's videoCapabilities attribute, and accumulated 358 // configuration's videoCapabilities attribute, and accumulated
358 // configuration. 359 // configuration.
359 // 7.2. If video capabilities is null, return null. 360 // 7.2. If video capabilities is null, return null.
360 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; 361 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities;
361 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, 362 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::VIDEO,
362 EmeMediaType::VIDEO, &video_capabilities, 363 candidate.videoCapabilities,
363 &config_state)) { 364 &config_state, &video_capabilities)) {
364 return CONFIGURATION_NOT_SUPPORTED; 365 return CONFIGURATION_NOT_SUPPORTED;
365 } 366 }
366 367
367 // 7.3. Add video capabilities to accumulated configuration. 368 // 7.3. Add video capabilities to accumulated configuration.
368 accumulated_configuration->videoCapabilities = video_capabilities; 369 accumulated_configuration->videoCapabilities = video_capabilities;
369 } 370 }
370 371
371 // 8. If candidate configuration's audioCapabilities attribute is not empty, 372 // 8. If candidate configuration's audioCapabilities attribute is not empty,
372 // run the following steps: 373 // run the following steps:
373 if (!candidate.audioCapabilities.isEmpty()) { 374 if (!candidate.audioCapabilities.isEmpty()) {
374 // 8.1. Let audio capabilities be the result of executing the Get Supported 375 // 8.1. Let audio capabilities be the result of executing the Get Supported
375 // Capabilities for Media Type algorithm on Audio, candidate 376 // Capabilities for Media Type algorithm on Audio, candidate
376 // configuration's audioCapabilities attribute, and accumulated 377 // configuration's audioCapabilities attribute, and accumulated
377 // configuration. 378 // configuration.
378 // 8.2. If audio capabilities is null, return null. 379 // 8.2. If audio capabilities is null, return null.
379 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; 380 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities;
380 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, 381 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::AUDIO,
381 EmeMediaType::AUDIO, &audio_capabilities, 382 candidate.audioCapabilities,
382 &config_state)) { 383 &config_state, &audio_capabilities)) {
383 return CONFIGURATION_NOT_SUPPORTED; 384 return CONFIGURATION_NOT_SUPPORTED;
384 } 385 }
385 386
386 // 8.3. Add audio capabilities to accumulated configuration. 387 // 8.3. Add audio capabilities to accumulated configuration.
387 accumulated_configuration->audioCapabilities = audio_capabilities; 388 accumulated_configuration->audioCapabilities = audio_capabilities;
388 } 389 }
389 390
390 // 9. If accumulated configuration's distinctiveIdentifier value is 391 // 9. If accumulated configuration's distinctiveIdentifier value is
391 // "optional", follow the steps for the first matching condition from the 392 // "optional", follow the steps for the first matching condition from the
392 // following list: 393 // following list:
393 // - If the implementation requires a Distinctive Identifier for any of 394 // - If the implementation requires a Distinctive Identifier for any of
394 // the combinations in accumulated configuration, change accumulated 395 // the combinations in accumulated configuration, change accumulated
395 // configuration's distinctiveIdentifier value to "required". 396 // configuration's distinctiveIdentifier value to "required".
396 // - Otherwise, change accumulated configuration's distinctiveIdentifier 397 // - Otherwise, change accumulated configuration's distinctiveIdentifier
397 // value to "not-allowed". 398 // value to "not-allowed".
398 if (accumulated_configuration->distinctiveIdentifier == 399 if (accumulated_configuration->distinctiveIdentifier ==
399 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 400 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
400 EmeConfigRule not_allowed_rule = 401 EmeConfigRule not_allowed_rule =
401 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); 402 key_systems.GetDistinctiveIdentifierConfigRule(
403 key_system, EME_FEATURE_NOT_ALLOWED);
402 EmeConfigRule required_rule = 404 EmeConfigRule required_rule =
403 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED); 405 key_systems.GetDistinctiveIdentifierConfigRule(
406 key_system, EME_FEATURE_REQUIRED);
404 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); 407 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule);
405 bool required_supported = config_state.IsRuleSupported(required_rule); 408 bool required_supported = config_state.IsRuleSupported(required_rule);
406 if (not_allowed_supported) { 409 if (not_allowed_supported) {
407 bool prefer_required = config_state.IsIdentifierRequired() || 410 bool prefer_required = config_state.IsIdentifierRequired() ||
408 (config_state.IsIdentifierRecommended() && 411 (config_state.IsIdentifierRecommended() &&
409 config_state.IsPermissionPossible()); 412 config_state.IsPermissionPossible());
410 if (required_supported && prefer_required) { 413 if (required_supported && prefer_required) {
411 accumulated_configuration->distinctiveIdentifier = 414 accumulated_configuration->distinctiveIdentifier =
412 blink::WebMediaKeySystemConfiguration::Requirement::Required; 415 blink::WebMediaKeySystemConfiguration::Requirement::Required;
413 config_state.AddRule(required_rule); 416 config_state.AddRule(required_rule);
(...skipping 29 matching lines...) Expand all
443 // follow the steps for the first matching condition from the following 446 // follow the steps for the first matching condition from the following
444 // list: 447 // list:
445 // - If the implementation requires persisting state for any of the 448 // - If the implementation requires persisting state for any of the
446 // combinations in accumulated configuration, change accumulated 449 // combinations in accumulated configuration, change accumulated
447 // configuration's persistentState value to "required". 450 // configuration's persistentState value to "required".
448 // - Otherwise, change accumulated configuration's persistentState value 451 // - Otherwise, change accumulated configuration's persistentState value
449 // to "not-allowed". 452 // to "not-allowed".
450 if (accumulated_configuration->persistentState == 453 if (accumulated_configuration->persistentState ==
451 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { 454 blink::WebMediaKeySystemConfiguration::Requirement::Optional) {
452 EmeConfigRule not_allowed_rule = 455 EmeConfigRule not_allowed_rule =
453 GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); 456 key_systems.GetPersistentStateConfigRule(
457 key_system, EME_FEATURE_NOT_ALLOWED);
454 EmeConfigRule required_rule = 458 EmeConfigRule required_rule =
455 GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED); 459 key_systems.GetPersistentStateConfigRule(
460 key_system, EME_FEATURE_REQUIRED);
456 // Now that distinctiveIdentifier has been resolved, it is too late to allow 461 // Now that distinctiveIdentifier has been resolved, it is too late to allow
457 // persistentState to affect the configuration. 462 // persistentState to affect the configuration.
458 bool not_allowed_supported = 463 bool not_allowed_supported =
459 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule); 464 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule);
460 bool required_supported = 465 bool required_supported =
461 config_state.IsRuleSupportedWithCurrentState(required_rule); 466 config_state.IsRuleSupportedWithCurrentState(required_rule);
462 if (not_allowed_supported) { 467 if (not_allowed_supported) {
463 accumulated_configuration->persistentState = 468 accumulated_configuration->persistentState =
464 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; 469 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
465 } else if (required_supported) { 470 } else if (required_supported) {
(...skipping 21 matching lines...) Expand all
487 492
488 // 13. Return accumulated configuration. 493 // 13. Return accumulated configuration.
489 // 494 //
490 // We also record the available session types so that createSession() can be 495 // We also record the available session types so that createSession() can be
491 // synchronous. 496 // synchronous.
492 std::vector<blink::WebEncryptedMediaSessionType> session_types; 497 std::vector<blink::WebEncryptedMediaSessionType> session_types;
493 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); 498 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary);
494 if (accumulated_configuration->persistentState == 499 if (accumulated_configuration->persistentState ==
495 blink::WebMediaKeySystemConfiguration::Requirement::Required) { 500 blink::WebMediaKeySystemConfiguration::Requirement::Required) {
496 if (config_state.IsRuleSupportedWithCurrentState( 501 if (config_state.IsRuleSupportedWithCurrentState(
497 GetPersistentLicenseSessionConfigRule(key_system))) { 502 key_systems.GetPersistentLicenseSessionConfigRule(key_system))) {
498 session_types.push_back( 503 session_types.push_back(
499 blink::WebEncryptedMediaSessionType::PersistentLicense); 504 blink::WebEncryptedMediaSessionType::PersistentLicense);
500 } 505 }
501 if (config_state.IsRuleSupportedWithCurrentState( 506 if (config_state.IsRuleSupportedWithCurrentState(
502 GetPersistentReleaseMessageSessionConfigRule(key_system))) { 507 key_systems.GetPersistentReleaseMessageSessionConfigRule(
508 key_system))) {
503 session_types.push_back( 509 session_types.push_back(
504 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); 510 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage);
505 } 511 }
506 } 512 }
507 accumulated_configuration->sessionTypes = session_types; 513 accumulated_configuration->sessionTypes = session_types;
508 514
509 return CONFIGURATION_SUPPORTED; 515 return CONFIGURATION_SUPPORTED;
510 } 516 }
511 517
512 // Report usage of key system to UMA. There are 2 different counts logged: 518 // Report usage of key system to UMA. There are 2 different counts logged:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 561 }
556 562
557 const std::string uma_name_; 563 const std::string uma_name_;
558 bool is_request_reported_; 564 bool is_request_reported_;
559 bool is_support_reported_; 565 bool is_support_reported_;
560 }; 566 };
561 567
562 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( 568 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl(
563 scoped_ptr<CdmFactory> cdm_factory, 569 scoped_ptr<CdmFactory> cdm_factory,
564 MediaPermission* media_permission) 570 MediaPermission* media_permission)
565 : cdm_factory_(cdm_factory.Pass()), media_permission_(media_permission), 571 : key_systems_(KeySystems::GetInstance()),
572 cdm_factory_(cdm_factory.Pass()),
573 media_permission_(media_permission),
566 weak_factory_(this) { 574 weak_factory_(this) {
567 DCHECK(media_permission); 575 DCHECK(media_permission);
568 } 576 }
569 577
570 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { 578 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() {
571 } 579 }
572 580
573 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( 581 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
574 blink::WebEncryptedMediaRequest request) { 582 blink::WebEncryptedMediaRequest request) {
575 // TODO(jrummell): This should be asynchronous, ideally not on the main 583 // TODO(jrummell): This should be asynchronous, ideally not on the main
576 // thread. 584 // thread.
577 585
578 // Continued from requestMediaKeySystemAccess(), step 7, from 586 // Continued from requestMediaKeySystemAccess(), step 7, from
579 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess 587 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess
580 // 588 //
581 // 7.1. If keySystem is not one of the Key Systems supported by the user 589 // 7.1. If keySystem is not one of the Key Systems supported by the user
582 // agent, reject promise with with a new DOMException whose name is 590 // agent, reject promise with with a new DOMException whose name is
583 // NotSupportedError. String comparison is case-sensitive. 591 // NotSupportedError. String comparison is case-sensitive.
584 if (!base::IsStringASCII(request.keySystem())) { 592 if (!base::IsStringASCII(request.keySystem())) {
585 request.requestNotSupported("Only ASCII keySystems are supported"); 593 request.requestNotSupported("Only ASCII keySystems are supported");
586 return; 594 return;
587 } 595 }
588 596
589 // Report this request to the UMA. 597 // Report this request to the UMA.
590 std::string key_system = base::UTF16ToASCII(request.keySystem()); 598 std::string key_system = base::UTF16ToASCII(request.keySystem());
591 GetReporter(key_system)->ReportRequested(); 599 GetReporter(key_system)->ReportRequested();
592 600
593 if (!IsSupportedKeySystem(key_system)) { 601 if (!key_systems_.IsSupportedKeySystem(key_system)) {
594 request.requestNotSupported("Unsupported keySystem"); 602 request.requestNotSupported("Unsupported keySystem");
595 return; 603 return;
596 } 604 }
597 605
598 // 7.2-7.4. Implemented by SelectSupportedConfiguration(). 606 // 7.2-7.4. Implemented by SelectSupportedConfiguration().
599 SelectSupportedConfiguration(request, false, false); 607 SelectSupportedConfiguration(request, false, false);
600 } 608 }
601 609
602 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( 610 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration(
603 blink::WebEncryptedMediaRequest request, 611 blink::WebEncryptedMediaRequest request,
(...skipping 12 matching lines...) Expand all
616 // 7.3.1. Let candidate configuration be the value. 624 // 7.3.1. Let candidate configuration be the value.
617 const blink::WebMediaKeySystemConfiguration& candidate_configuration = 625 const blink::WebMediaKeySystemConfiguration& candidate_configuration =
618 configurations[i]; 626 configurations[i];
619 // 7.3.2. Let supported configuration be the result of executing the Get 627 // 7.3.2. Let supported configuration be the result of executing the Get
620 // Supported Configuration algorithm on implementation, candidate 628 // Supported Configuration algorithm on implementation, candidate
621 // configuration, and origin. 629 // configuration, and origin.
622 // 7.3.3. If supported configuration is not null, [initialize and return a 630 // 7.3.3. If supported configuration is not null, [initialize and return a
623 // new MediaKeySystemAccess object.] 631 // new MediaKeySystemAccess object.]
624 blink::WebMediaKeySystemConfiguration accumulated_configuration; 632 blink::WebMediaKeySystemConfiguration accumulated_configuration;
625 ConfigurationSupport supported = GetSupportedConfiguration( 633 ConfigurationSupport supported = GetSupportedConfiguration(
626 key_system, candidate_configuration, was_permission_requested, 634 key_systems_, key_system, candidate_configuration,
627 is_permission_granted, &accumulated_configuration); 635 was_permission_requested, is_permission_granted,
636 &accumulated_configuration);
628 switch (supported) { 637 switch (supported) {
629 case CONFIGURATION_NOT_SUPPORTED: 638 case CONFIGURATION_NOT_SUPPORTED:
630 continue; 639 continue;
631 case CONFIGURATION_REQUIRES_PERMISSION: 640 case CONFIGURATION_REQUIRES_PERMISSION:
632 if (was_permission_requested) { 641 if (was_permission_requested) {
633 DVLOG(2) << "Rejecting requested configuration because " 642 DVLOG(2) << "Rejecting requested configuration because "
634 << "permission was denied."; 643 << "permission was denied.";
635 continue; 644 continue;
636 } 645 }
637 media_permission_->RequestPermission( 646 media_permission_->RequestPermission(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 return reporter; 689 return reporter;
681 690
682 // Reporter not found, so create one. 691 // Reporter not found, so create one.
683 auto result = 692 auto result =
684 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); 693 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name)));
685 DCHECK(result.second); 694 DCHECK(result.second);
686 return result.first->second; 695 return result.first->second;
687 } 696 }
688 697
689 } // namespace media 698 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webencryptedmediaclient_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698