| 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 "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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return EmeRobustness::SW_SECURE_DECODE; | 135 return EmeRobustness::SW_SECURE_DECODE; |
| 136 if (robustness == "HW_SECURE_CRYPTO") | 136 if (robustness == "HW_SECURE_CRYPTO") |
| 137 return EmeRobustness::HW_SECURE_CRYPTO; | 137 return EmeRobustness::HW_SECURE_CRYPTO; |
| 138 if (robustness == "HW_SECURE_DECODE") | 138 if (robustness == "HW_SECURE_DECODE") |
| 139 return EmeRobustness::HW_SECURE_DECODE; | 139 return EmeRobustness::HW_SECURE_DECODE; |
| 140 if (robustness == "HW_SECURE_ALL") | 140 if (robustness == "HW_SECURE_ALL") |
| 141 return EmeRobustness::HW_SECURE_ALL; | 141 return EmeRobustness::HW_SECURE_ALL; |
| 142 return EmeRobustness::INVALID; | 142 return EmeRobustness::INVALID; |
| 143 } | 143 } |
| 144 | 144 |
| 145 static bool IsSupportedContentType(const std::string& key_system, | 145 static bool IsSupportedContentType( |
| 146 const std::string& mime_type, | 146 const KeySystems& key_systems, |
| 147 const std::string& codecs) { | 147 const std::string& key_system, |
| 148 EmeMediaType media_type, |
| 149 const std::string& container_mime_type, |
| 150 const std::string& codecs) { |
| 148 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid | 151 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
| 149 // parameters can be rejected. http://crbug.com/417561 | 152 // parameters can be rejected. http://crbug.com/417561 |
| 150 // TODO(sandersd): Pass in the media type (audio or video) and check that the | 153 std::string container_lower = base::StringToLowerASCII(container_mime_type); |
| 151 // container type matches. http://crbug.com/457384 | |
| 152 std::string container = base::StringToLowerASCII(mime_type); | |
| 153 | 154 |
| 154 // Check that |codecs| are supported by the CDM. This check does not handle | 155 // Check that |codecs| are supported by the CDM. This check does not handle |
| 155 // extended codecs, so extended codec information is stripped. | 156 // extended codecs, so extended codec information is stripped. |
| 156 // TODO(sandersd): Reject codecs that do not match the media type. | |
| 157 // http://crbug.com/457386 | |
| 158 std::vector<std::string> codec_vector; | 157 std::vector<std::string> codec_vector; |
| 159 net::ParseCodecString(codecs, &codec_vector, true); | 158 net::ParseCodecString(codecs, &codec_vector, true); |
| 160 if (!IsSupportedKeySystemWithMediaMimeType(container, codec_vector, | 159 if (!key_systems.IsSupportedCodecCombination( |
| 161 key_system)) { | 160 key_system, media_type, container_lower, codec_vector)) { |
| 162 return false; | 161 return false; |
| 163 } | 162 } |
| 164 | 163 |
| 165 // Check that |codecs| are supported by Chrome. This is done primarily to | 164 // Check that |codecs| are supported by Chrome. This is done primarily to |
| 166 // validate extended codecs, but it also ensures that the CDM cannot support | 165 // validate extended codecs, but it also ensures that the CDM cannot support |
| 167 // codecs that Chrome does not (which would be bad because it would require | 166 // codecs that Chrome does not (which would be bad because it would require |
| 168 // considering the accumulated configuration, and could affect whether secure | 167 // considering the accumulated configuration, and could affect whether secure |
| 169 // decode is required). | 168 // decode is required). |
| 170 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 | 169 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 |
| 171 codec_vector.clear(); | 170 codec_vector.clear(); |
| 172 net::ParseCodecString(codecs, &codec_vector, false); | 171 net::ParseCodecString(codecs, &codec_vector, false); |
| 173 return net::AreSupportedMediaCodecs(codec_vector); | 172 return net::AreSupportedMediaCodecs(codec_vector); |
| 174 } | 173 } |
| 175 | 174 |
| 176 static bool GetSupportedCapabilities( | 175 static bool GetSupportedCapabilities( |
| 176 const KeySystems& key_systems, |
| 177 const std::string& key_system, | 177 const std::string& key_system, |
| 178 EmeMediaType media_type, |
| 178 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& | 179 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
| 179 capabilities, | 180 capabilities, |
| 180 EmeMediaType media_type, | 181 ConfigState* config_state, |
| 181 std::vector<blink::WebMediaKeySystemMediaCapability>* | 182 std::vector<blink::WebMediaKeySystemMediaCapability>* |
| 182 media_type_capabilities, | 183 media_type_capabilities) { |
| 183 ConfigState* config_state) { | |
| 184 // From | 184 // From |
| 185 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media
-type | 185 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media
-type |
| 186 // 1. Let accumulated capabilities be partial configuration. | 186 // 1. Let accumulated capabilities be partial configuration. |
| 187 // (Skipped as there are no configuration-based codec restrictions.) | 187 // (Skipped as there are no configuration-based codec restrictions.) |
| 188 // 2. Let media type capabilities be empty. | 188 // 2. Let media type capabilities be empty. |
| 189 DCHECK_EQ(media_type_capabilities->size(), 0ul); | 189 DCHECK_EQ(media_type_capabilities->size(), 0ul); |
| 190 // 3. For each value in capabilities: | 190 // 3. For each value in capabilities: |
| 191 for (size_t i = 0; i < capabilities.size(); i++) { | 191 for (size_t i = 0; i < capabilities.size(); i++) { |
| 192 // 3.1. Let contentType be the value's contentType member. | 192 // 3.1. Let contentType be the value's contentType member. |
| 193 // 3.2. Let robustness be the value's robustness member. | 193 // 3.2. Let robustness be the value's robustness member. |
| 194 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; | 194 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; |
| 195 // 3.3. If contentType is the empty string, return null. | 195 // 3.3. If contentType is the empty string, return null. |
| 196 if (capability.mimeType.isEmpty()) { | 196 if (capability.mimeType.isEmpty()) { |
| 197 DVLOG(2) << "Rejecting requested configuration because " | 197 DVLOG(2) << "Rejecting requested configuration because " |
| 198 << "a capability contentType was empty."; | 198 << "a capability contentType was empty."; |
| 199 return false; | 199 return false; |
| 200 } | 200 } |
| 201 // 3.4-3.11. (Implemented by IsSupportedContentType().) | 201 // 3.4-3.11. (Implemented by IsSupportedContentType().) |
| 202 if (!base::IsStringASCII(capability.mimeType) || | 202 if (!base::IsStringASCII(capability.mimeType) || |
| 203 !base::IsStringASCII(capability.codecs) || | 203 !base::IsStringASCII(capability.codecs) || |
| 204 !IsSupportedContentType(key_system, | 204 !IsSupportedContentType(key_systems, key_system, media_type, |
| 205 base::UTF16ToASCII(capability.mimeType), | 205 base::UTF16ToASCII(capability.mimeType), |
| 206 base::UTF16ToASCII(capability.codecs))) { | 206 base::UTF16ToASCII(capability.codecs))) { |
| 207 continue; | 207 continue; |
| 208 } | 208 } |
| 209 // 3.12. If robustness is not the empty string, run the following steps: | 209 // 3.12. If robustness is not the empty string, run the following steps: |
| 210 if (!capability.robustness.isEmpty()) { | 210 if (!capability.robustness.isEmpty()) { |
| 211 // 3.12.1. If robustness is an unrecognized value or not supported by | 211 // 3.12.1. If robustness is an unrecognized value or not supported by |
| 212 // implementation, continue to the next iteration. String | 212 // implementation, continue to the next iteration. String |
| 213 // comparison is case-sensitive. | 213 // comparison is case-sensitive. |
| 214 EmeConfigRule robustness_rule = GetRobustnessConfigRule( | 214 EmeConfigRule robustness_rule = key_systems.GetRobustnessConfigRule( |
| 215 key_system, media_type, ConvertRobustness(capability.robustness)); | 215 key_system, media_type, ConvertRobustness(capability.robustness)); |
| 216 if (!config_state->IsRuleSupported(robustness_rule)) | 216 if (!config_state->IsRuleSupported(robustness_rule)) |
| 217 continue; | 217 continue; |
| 218 config_state->AddRule(robustness_rule); | 218 config_state->AddRule(robustness_rule); |
| 219 // 3.12.2. Add robustness to configuration. | 219 // 3.12.2. Add robustness to configuration. |
| 220 // (It's already added, we use capability as the configuration.) | 220 // (It's already added, we use capability as the configuration.) |
| 221 } | 221 } |
| 222 // 3.13. If the user agent and implementation do not support playback of | 222 // 3.13. If the user agent and implementation do not support playback of |
| 223 // encrypted media data as specified by configuration, including all | 223 // encrypted media data as specified by configuration, including all |
| 224 // media types, in combination with accumulated capabilities, | 224 // media types, in combination with accumulated capabilities, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 252 return EME_FEATURE_OPTIONAL; | 252 return EME_FEATURE_OPTIONAL; |
| 253 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | 253 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
| 254 return EME_FEATURE_NOT_ALLOWED; | 254 return EME_FEATURE_NOT_ALLOWED; |
| 255 } | 255 } |
| 256 | 256 |
| 257 NOTREACHED(); | 257 NOTREACHED(); |
| 258 return EME_FEATURE_NOT_ALLOWED; | 258 return EME_FEATURE_NOT_ALLOWED; |
| 259 } | 259 } |
| 260 | 260 |
| 261 static ConfigurationSupport GetSupportedConfiguration( | 261 static ConfigurationSupport GetSupportedConfiguration( |
| 262 const KeySystems& key_systems, |
| 262 const std::string& key_system, | 263 const std::string& key_system, |
| 263 const blink::WebMediaKeySystemConfiguration& candidate, | 264 const blink::WebMediaKeySystemConfiguration& candidate, |
| 264 bool was_permission_requested, | 265 bool was_permission_requested, |
| 265 bool is_permission_granted, | 266 bool is_permission_granted, |
| 266 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { | 267 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
| 267 ConfigState config_state(was_permission_requested, is_permission_granted); | 268 ConfigState config_state(was_permission_requested, is_permission_granted); |
| 268 | 269 |
| 269 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | 270 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
| 270 // 1. Let accumulated configuration be empty. (Done by caller.) | 271 // 1. Let accumulated configuration be empty. (Done by caller.) |
| 271 // 2. If candidate configuration's initDataTypes attribute is not empty, run | 272 // 2. If candidate configuration's initDataTypes attribute is not empty, run |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // distinctiveIdentifier attribute from the following list: | 324 // distinctiveIdentifier attribute from the following list: |
| 324 // - "required": If the implementation does not support a persistent | 325 // - "required": If the implementation does not support a persistent |
| 325 // Distinctive Identifier in combination with accumulated configuration, | 326 // Distinctive Identifier in combination with accumulated configuration, |
| 326 // return null. | 327 // return null. |
| 327 // - "optional": Continue. | 328 // - "optional": Continue. |
| 328 // - "not-allowed": If the implementation requires a Distinctive | 329 // - "not-allowed": If the implementation requires a Distinctive |
| 329 // Identifier in combination with accumulated configuration, return | 330 // Identifier in combination with accumulated configuration, return |
| 330 // null. | 331 // null. |
| 331 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and | 332 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and |
| 332 // permission has already been denied. This would happen anyway at step 11. | 333 // permission has already been denied. This would happen anyway at step 11. |
| 333 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule( | 334 EmeConfigRule di_rule = key_systems.GetDistinctiveIdentifierConfigRule( |
| 334 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); | 335 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); |
| 335 if (!config_state.IsRuleSupported(di_rule)) { | 336 if (!config_state.IsRuleSupported(di_rule)) { |
| 336 DVLOG(2) << "Rejecting requested configuration because " | 337 DVLOG(2) << "Rejecting requested configuration because " |
| 337 << "the distinctiveIdentifier requirement was not supported."; | 338 << "the distinctiveIdentifier requirement was not supported."; |
| 338 return CONFIGURATION_NOT_SUPPORTED; | 339 return CONFIGURATION_NOT_SUPPORTED; |
| 339 } | 340 } |
| 340 config_state.AddRule(di_rule); | 341 config_state.AddRule(di_rule); |
| 341 | 342 |
| 342 // 4. Add the value of the candidate configuration's distinctiveIdentifier | 343 // 4. Add the value of the candidate configuration's distinctiveIdentifier |
| 343 // attribute to accumulated configuration. | 344 // attribute to accumulated configuration. |
| 344 accumulated_configuration->distinctiveIdentifier = | 345 accumulated_configuration->distinctiveIdentifier = |
| 345 candidate.distinctiveIdentifier; | 346 candidate.distinctiveIdentifier; |
| 346 | 347 |
| 347 // 5. Follow the steps for the value of candidate configuration's | 348 // 5. Follow the steps for the value of candidate configuration's |
| 348 // persistentState attribute from the following list: | 349 // persistentState attribute from the following list: |
| 349 // - "required": If the implementation does not support persisting state | 350 // - "required": If the implementation does not support persisting state |
| 350 // in combination with accumulated configuration, return null. | 351 // in combination with accumulated configuration, return null. |
| 351 // - "optional": Continue. | 352 // - "optional": Continue. |
| 352 // - "not-allowed": If the implementation requires persisting state in | 353 // - "not-allowed": If the implementation requires persisting state in |
| 353 // combination with accumulated configuration, return null. | 354 // combination with accumulated configuration, return null. |
| 354 EmeConfigRule ps_rule = GetPersistentStateConfigRule( | 355 EmeConfigRule ps_rule = key_systems.GetPersistentStateConfigRule( |
| 355 key_system, ConvertRequirement(candidate.persistentState)); | 356 key_system, ConvertRequirement(candidate.persistentState)); |
| 356 if (!config_state.IsRuleSupported(ps_rule)) { | 357 if (!config_state.IsRuleSupported(ps_rule)) { |
| 357 DVLOG(2) << "Rejecting requested configuration because " | 358 DVLOG(2) << "Rejecting requested configuration because " |
| 358 << "the persistentState requirement was not supported."; | 359 << "the persistentState requirement was not supported."; |
| 359 return CONFIGURATION_NOT_SUPPORTED; | 360 return CONFIGURATION_NOT_SUPPORTED; |
| 360 } | 361 } |
| 361 config_state.AddRule(ps_rule); | 362 config_state.AddRule(ps_rule); |
| 362 | 363 |
| 363 // 6. Add the value of the candidate configuration's persistentState | 364 // 6. Add the value of the candidate configuration's persistentState |
| 364 // attribute to accumulated configuration. | 365 // attribute to accumulated configuration. |
| 365 accumulated_configuration->persistentState = candidate.persistentState; | 366 accumulated_configuration->persistentState = candidate.persistentState; |
| 366 | 367 |
| 367 // 7. If candidate configuration's videoCapabilities attribute is not empty, | 368 // 7. If candidate configuration's videoCapabilities attribute is not empty, |
| 368 // run the following steps: | 369 // run the following steps: |
| 369 if (!candidate.videoCapabilities.isEmpty()) { | 370 if (!candidate.videoCapabilities.isEmpty()) { |
| 370 // 7.1. Let video capabilities be the result of executing the Get Supported | 371 // 7.1. Let video capabilities be the result of executing the Get Supported |
| 371 // Capabilities for Media Type algorithm on Video, candidate | 372 // Capabilities for Media Type algorithm on Video, candidate |
| 372 // configuration's videoCapabilities attribute, and accumulated | 373 // configuration's videoCapabilities attribute, and accumulated |
| 373 // configuration. | 374 // configuration. |
| 374 // 7.2. If video capabilities is null, return null. | 375 // 7.2. If video capabilities is null, return null. |
| 375 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | 376 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; |
| 376 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, | 377 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::VIDEO, |
| 377 EmeMediaType::VIDEO, &video_capabilities, | 378 candidate.videoCapabilities, |
| 378 &config_state)) { | 379 &config_state, &video_capabilities)) { |
| 379 return CONFIGURATION_NOT_SUPPORTED; | 380 return CONFIGURATION_NOT_SUPPORTED; |
| 380 } | 381 } |
| 381 | 382 |
| 382 // 7.3. Add video capabilities to accumulated configuration. | 383 // 7.3. Add video capabilities to accumulated configuration. |
| 383 accumulated_configuration->videoCapabilities = video_capabilities; | 384 accumulated_configuration->videoCapabilities = video_capabilities; |
| 384 } | 385 } |
| 385 | 386 |
| 386 // 8. If candidate configuration's audioCapabilities attribute is not empty, | 387 // 8. If candidate configuration's audioCapabilities attribute is not empty, |
| 387 // run the following steps: | 388 // run the following steps: |
| 388 if (!candidate.audioCapabilities.isEmpty()) { | 389 if (!candidate.audioCapabilities.isEmpty()) { |
| 389 // 8.1. Let audio capabilities be the result of executing the Get Supported | 390 // 8.1. Let audio capabilities be the result of executing the Get Supported |
| 390 // Capabilities for Media Type algorithm on Audio, candidate | 391 // Capabilities for Media Type algorithm on Audio, candidate |
| 391 // configuration's audioCapabilities attribute, and accumulated | 392 // configuration's audioCapabilities attribute, and accumulated |
| 392 // configuration. | 393 // configuration. |
| 393 // 8.2. If audio capabilities is null, return null. | 394 // 8.2. If audio capabilities is null, return null. |
| 394 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | 395 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
| 395 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, | 396 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::AUDIO, |
| 396 EmeMediaType::AUDIO, &audio_capabilities, | 397 candidate.audioCapabilities, |
| 397 &config_state)) { | 398 &config_state, &audio_capabilities)) { |
| 398 return CONFIGURATION_NOT_SUPPORTED; | 399 return CONFIGURATION_NOT_SUPPORTED; |
| 399 } | 400 } |
| 400 | 401 |
| 401 // 8.3. Add audio capabilities to accumulated configuration. | 402 // 8.3. Add audio capabilities to accumulated configuration. |
| 402 accumulated_configuration->audioCapabilities = audio_capabilities; | 403 accumulated_configuration->audioCapabilities = audio_capabilities; |
| 403 } | 404 } |
| 404 | 405 |
| 405 // 9. If accumulated configuration's distinctiveIdentifier value is | 406 // 9. If accumulated configuration's distinctiveIdentifier value is |
| 406 // "optional", follow the steps for the first matching condition from the | 407 // "optional", follow the steps for the first matching condition from the |
| 407 // following list: | 408 // following list: |
| 408 // - If the implementation requires a Distinctive Identifier for any of | 409 // - If the implementation requires a Distinctive Identifier for any of |
| 409 // the combinations in accumulated configuration, change accumulated | 410 // the combinations in accumulated configuration, change accumulated |
| 410 // configuration's distinctiveIdentifier value to "required". | 411 // configuration's distinctiveIdentifier value to "required". |
| 411 // - Otherwise, change accumulated configuration's distinctiveIdentifier | 412 // - Otherwise, change accumulated configuration's distinctiveIdentifier |
| 412 // value to "not-allowed". | 413 // value to "not-allowed". |
| 413 if (accumulated_configuration->distinctiveIdentifier == | 414 if (accumulated_configuration->distinctiveIdentifier == |
| 414 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 415 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| 415 EmeConfigRule not_allowed_rule = | 416 EmeConfigRule not_allowed_rule = |
| 416 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); | 417 key_systems.GetDistinctiveIdentifierConfigRule( |
| 418 key_system, EME_FEATURE_NOT_ALLOWED); |
| 417 EmeConfigRule required_rule = | 419 EmeConfigRule required_rule = |
| 418 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED); | 420 key_systems.GetDistinctiveIdentifierConfigRule( |
| 421 key_system, EME_FEATURE_REQUIRED); |
| 419 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); | 422 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); |
| 420 bool required_supported = config_state.IsRuleSupported(required_rule); | 423 bool required_supported = config_state.IsRuleSupported(required_rule); |
| 421 if (not_allowed_supported) { | 424 if (not_allowed_supported) { |
| 422 bool prefer_required = config_state.IsIdentifierRequired() || | 425 bool prefer_required = config_state.IsIdentifierRequired() || |
| 423 (config_state.IsIdentifierRecommended() && | 426 (config_state.IsIdentifierRecommended() && |
| 424 config_state.IsPermissionPossible()); | 427 config_state.IsPermissionPossible()); |
| 425 if (required_supported && prefer_required) { | 428 if (required_supported && prefer_required) { |
| 426 accumulated_configuration->distinctiveIdentifier = | 429 accumulated_configuration->distinctiveIdentifier = |
| 427 blink::WebMediaKeySystemConfiguration::Requirement::Required; | 430 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 428 config_state.AddRule(required_rule); | 431 config_state.AddRule(required_rule); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 458 // follow the steps for the first matching condition from the following | 461 // follow the steps for the first matching condition from the following |
| 459 // list: | 462 // list: |
| 460 // - If the implementation requires persisting state for any of the | 463 // - If the implementation requires persisting state for any of the |
| 461 // combinations in accumulated configuration, change accumulated | 464 // combinations in accumulated configuration, change accumulated |
| 462 // configuration's persistentState value to "required". | 465 // configuration's persistentState value to "required". |
| 463 // - Otherwise, change accumulated configuration's persistentState value | 466 // - Otherwise, change accumulated configuration's persistentState value |
| 464 // to "not-allowed". | 467 // to "not-allowed". |
| 465 if (accumulated_configuration->persistentState == | 468 if (accumulated_configuration->persistentState == |
| 466 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 469 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| 467 EmeConfigRule not_allowed_rule = | 470 EmeConfigRule not_allowed_rule = |
| 468 GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); | 471 key_systems.GetPersistentStateConfigRule( |
| 472 key_system, EME_FEATURE_NOT_ALLOWED); |
| 469 EmeConfigRule required_rule = | 473 EmeConfigRule required_rule = |
| 470 GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED); | 474 key_systems.GetPersistentStateConfigRule( |
| 475 key_system, EME_FEATURE_REQUIRED); |
| 471 // Now that distinctiveIdentifier has been resolved, it is too late to allow | 476 // Now that distinctiveIdentifier has been resolved, it is too late to allow |
| 472 // persistentState to affect the configuration. | 477 // persistentState to affect the configuration. |
| 473 bool not_allowed_supported = | 478 bool not_allowed_supported = |
| 474 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule); | 479 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule); |
| 475 bool required_supported = | 480 bool required_supported = |
| 476 config_state.IsRuleSupportedWithCurrentState(required_rule); | 481 config_state.IsRuleSupportedWithCurrentState(required_rule); |
| 477 if (not_allowed_supported) { | 482 if (not_allowed_supported) { |
| 478 accumulated_configuration->persistentState = | 483 accumulated_configuration->persistentState = |
| 479 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 484 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
| 480 } else if (required_supported) { | 485 } else if (required_supported) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 503 | 508 |
| 504 // 12. Return accumulated configuration. | 509 // 12. Return accumulated configuration. |
| 505 // | 510 // |
| 506 // We also record the available session types so that createSession() can be | 511 // We also record the available session types so that createSession() can be |
| 507 // synchronous. | 512 // synchronous. |
| 508 std::vector<blink::WebEncryptedMediaSessionType> session_types; | 513 std::vector<blink::WebEncryptedMediaSessionType> session_types; |
| 509 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); | 514 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); |
| 510 if (accumulated_configuration->persistentState == | 515 if (accumulated_configuration->persistentState == |
| 511 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | 516 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
| 512 if (config_state.IsRuleSupportedWithCurrentState( | 517 if (config_state.IsRuleSupportedWithCurrentState( |
| 513 GetPersistentLicenseSessionConfigRule(key_system))) { | 518 key_systems.GetPersistentLicenseSessionConfigRule(key_system))) { |
| 514 session_types.push_back( | 519 session_types.push_back( |
| 515 blink::WebEncryptedMediaSessionType::PersistentLicense); | 520 blink::WebEncryptedMediaSessionType::PersistentLicense); |
| 516 } | 521 } |
| 517 if (config_state.IsRuleSupportedWithCurrentState( | 522 if (config_state.IsRuleSupportedWithCurrentState( |
| 518 GetPersistentReleaseMessageSessionConfigRule(key_system))) { | 523 key_systems.GetPersistentReleaseMessageSessionConfigRule( |
| 524 key_system))) { |
| 519 session_types.push_back( | 525 session_types.push_back( |
| 520 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); | 526 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); |
| 521 } | 527 } |
| 522 } | 528 } |
| 523 accumulated_configuration->sessionTypes = session_types; | 529 accumulated_configuration->sessionTypes = session_types; |
| 524 | 530 |
| 525 return CONFIGURATION_SUPPORTED; | 531 return CONFIGURATION_SUPPORTED; |
| 526 } | 532 } |
| 527 | 533 |
| 528 // Report usage of key system to UMA. There are 2 different counts logged: | 534 // 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 Loading... |
| 571 } | 577 } |
| 572 | 578 |
| 573 const std::string uma_name_; | 579 const std::string uma_name_; |
| 574 bool is_request_reported_; | 580 bool is_request_reported_; |
| 575 bool is_support_reported_; | 581 bool is_support_reported_; |
| 576 }; | 582 }; |
| 577 | 583 |
| 578 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( | 584 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( |
| 579 scoped_ptr<CdmFactory> cdm_factory, | 585 scoped_ptr<CdmFactory> cdm_factory, |
| 580 MediaPermission* media_permission) | 586 MediaPermission* media_permission) |
| 581 : cdm_factory_(cdm_factory.Pass()), media_permission_(media_permission), | 587 : key_systems_(KeySystems::GetInstance()), |
| 588 cdm_factory_(cdm_factory.Pass()), |
| 589 media_permission_(media_permission), |
| 582 weak_factory_(this) { | 590 weak_factory_(this) { |
| 583 DCHECK(media_permission); | 591 DCHECK(media_permission); |
| 584 } | 592 } |
| 585 | 593 |
| 586 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { | 594 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { |
| 587 } | 595 } |
| 588 | 596 |
| 589 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( | 597 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
| 590 blink::WebEncryptedMediaRequest request) { | 598 blink::WebEncryptedMediaRequest request) { |
| 591 // TODO(jrummell): This should be asynchronous, ideally not on the main | 599 // TODO(jrummell): This should be asynchronous, ideally not on the main |
| 592 // thread. | 600 // thread. |
| 593 | 601 |
| 594 // Continued from requestMediaKeySystemAccess(), step 7, from | 602 // Continued from requestMediaKeySystemAccess(), step 7, from |
| 595 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | 603 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
| 596 // | 604 // |
| 597 // 7.1. If keySystem is not one of the Key Systems supported by the user | 605 // 7.1. If keySystem is not one of the Key Systems supported by the user |
| 598 // agent, reject promise with with a new DOMException whose name is | 606 // agent, reject promise with with a new DOMException whose name is |
| 599 // NotSupportedError. String comparison is case-sensitive. | 607 // NotSupportedError. String comparison is case-sensitive. |
| 600 if (!base::IsStringASCII(request.keySystem())) { | 608 if (!base::IsStringASCII(request.keySystem())) { |
| 601 request.requestNotSupported("Only ASCII keySystems are supported"); | 609 request.requestNotSupported("Only ASCII keySystems are supported"); |
| 602 return; | 610 return; |
| 603 } | 611 } |
| 604 | 612 |
| 605 // Report this request to the UMA. | 613 // Report this request to the UMA. |
| 606 std::string key_system = base::UTF16ToASCII(request.keySystem()); | 614 std::string key_system = base::UTF16ToASCII(request.keySystem()); |
| 607 GetReporter(key_system)->ReportRequested(); | 615 GetReporter(key_system)->ReportRequested(); |
| 608 | 616 |
| 609 if (!IsSupportedKeySystem(key_system)) { | 617 if (!key_systems_.IsSupportedKeySystem(key_system)) { |
| 610 request.requestNotSupported("Unsupported keySystem"); | 618 request.requestNotSupported("Unsupported keySystem"); |
| 611 return; | 619 return; |
| 612 } | 620 } |
| 613 | 621 |
| 614 // 7.2-7.4. Implemented by SelectSupportedConfiguration(). | 622 // 7.2-7.4. Implemented by SelectSupportedConfiguration(). |
| 615 SelectSupportedConfiguration(request, false, false); | 623 SelectSupportedConfiguration(request, false, false); |
| 616 } | 624 } |
| 617 | 625 |
| 618 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( | 626 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( |
| 619 blink::WebEncryptedMediaRequest request, | 627 blink::WebEncryptedMediaRequest request, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 632 // 7.3.1. Let candidate configuration be the value. | 640 // 7.3.1. Let candidate configuration be the value. |
| 633 const blink::WebMediaKeySystemConfiguration& candidate_configuration = | 641 const blink::WebMediaKeySystemConfiguration& candidate_configuration = |
| 634 configurations[i]; | 642 configurations[i]; |
| 635 // 7.3.2. Let supported configuration be the result of executing the Get | 643 // 7.3.2. Let supported configuration be the result of executing the Get |
| 636 // Supported Configuration algorithm on implementation, candidate | 644 // Supported Configuration algorithm on implementation, candidate |
| 637 // configuration, and origin. | 645 // configuration, and origin. |
| 638 // 7.3.3. If supported configuration is not null, [initialize and return a | 646 // 7.3.3. If supported configuration is not null, [initialize and return a |
| 639 // new MediaKeySystemAccess object.] | 647 // new MediaKeySystemAccess object.] |
| 640 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 648 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
| 641 ConfigurationSupport supported = GetSupportedConfiguration( | 649 ConfigurationSupport supported = GetSupportedConfiguration( |
| 642 key_system, candidate_configuration, was_permission_requested, | 650 key_systems_, key_system, candidate_configuration, |
| 643 is_permission_granted, &accumulated_configuration); | 651 was_permission_requested, is_permission_granted, |
| 652 &accumulated_configuration); |
| 644 switch (supported) { | 653 switch (supported) { |
| 645 case CONFIGURATION_NOT_SUPPORTED: | 654 case CONFIGURATION_NOT_SUPPORTED: |
| 646 continue; | 655 continue; |
| 647 case CONFIGURATION_REQUIRES_PERMISSION: | 656 case CONFIGURATION_REQUIRES_PERMISSION: |
| 648 if (was_permission_requested) { | 657 if (was_permission_requested) { |
| 649 DVLOG(2) << "Rejecting requested configuration because " | 658 DVLOG(2) << "Rejecting requested configuration because " |
| 650 << "permission was denied."; | 659 << "permission was denied."; |
| 651 continue; | 660 continue; |
| 652 } | 661 } |
| 653 media_permission_->RequestPermission( | 662 media_permission_->RequestPermission( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 return reporter; | 705 return reporter; |
| 697 | 706 |
| 698 // Reporter not found, so create one. | 707 // Reporter not found, so create one. |
| 699 auto result = | 708 auto result = |
| 700 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 709 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
| 701 DCHECK(result.second); | 710 DCHECK(result.second); |
| 702 return result.first->second; | 711 return result.first->second; |
| 703 } | 712 } |
| 704 | 713 |
| 705 } // namespace media | 714 } // namespace media |
| OLD | NEW |