Chromium Code Reviews| Index: media/blink/webencryptedmediaclient_impl.cc |
| diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/webencryptedmediaclient_impl.cc |
| index ed364775f8c09526f73613e7731138d02657be01..45be57a1d7159ffbd1c8447c3dbde10d1faed015 100644 |
| --- a/media/blink/webencryptedmediaclient_impl.cc |
| +++ b/media/blink/webencryptedmediaclient_impl.cc |
| @@ -142,14 +142,27 @@ static EmeRobustness ConvertRobustness(const blink::WebString& robustness) { |
| return EmeRobustness::INVALID; |
| } |
| -static bool IsSupportedContentType(const std::string& key_system, |
| - const std::string& mime_type, |
| - const std::string& codecs) { |
| +static bool IsSupportedContentType( |
| + const KeySystems& key_systems, |
| + const std::string& key_system, |
| + EmeMediaType media_type, |
| + const std::string& container_mime_type, |
| + const std::string& codecs) { |
| // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
| // parameters can be rejected. http://crbug.com/417561 |
| - // TODO(sandersd): Pass in the media type (audio or video) and check that the |
| - // container type matches. http://crbug.com/457384 |
| - std::string container = base::StringToLowerASCII(mime_type); |
| + std::string container_lower = base::StringToLowerASCII(container_mime_type); |
| + |
| + // Make sure the container matches |media_type|. |
| + switch (media_type) { |
| + case EmeMediaType::AUDIO: |
| + if (!StartsWithASCII(container_lower, "audio/", true)) |
| + return false; |
| + break; |
| + case EmeMediaType::VIDEO: |
| + if (!StartsWithASCII(container_lower, "video/", true)) |
| + return false; |
| + break; |
| + } |
| // Check that |codecs| are supported by the CDM. This check does not handle |
| // extended codecs, so extended codec information is stripped. |
| @@ -157,8 +170,8 @@ static bool IsSupportedContentType(const std::string& key_system, |
| // http://crbug.com/457386 |
| std::vector<std::string> codec_vector; |
| net::ParseCodecString(codecs, &codec_vector, true); |
| - if (!IsSupportedKeySystemWithMediaMimeType(container, codec_vector, |
| - key_system)) { |
| + if (!key_systems.IsSupportedCodecCombination( |
| + key_system, media_type, container_lower, codec_vector)) { |
| return false; |
| } |
| @@ -174,13 +187,14 @@ static bool IsSupportedContentType(const std::string& key_system, |
| } |
| static bool GetSupportedCapabilities( |
| + const KeySystems& key_systems, |
| const std::string& key_system, |
| + EmeMediaType media_type, |
| const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
| capabilities, |
|
ddorwin
2015/03/20 00:55:03
rename this requested_ and l197 supported_capabili
sandersd (OOO until July 31)
2015/03/20 22:53:19
I'm not sure, this exactly matches the names from
|
| - EmeMediaType media_type, |
| + ConfigState* config_state, |
| std::vector<blink::WebMediaKeySystemMediaCapability>* |
| - media_type_capabilities, |
| - ConfigState* config_state) { |
| + media_type_capabilities) { |
| // From |
| // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media-type |
| // 1. Let accumulated capabilities be partial configuration. |
| @@ -201,7 +215,7 @@ static bool GetSupportedCapabilities( |
| // 3.4-3.11. (Implemented by IsSupportedContentType().) |
| if (!base::IsStringASCII(capability.mimeType) || |
| !base::IsStringASCII(capability.codecs) || |
| - !IsSupportedContentType(key_system, |
| + !IsSupportedContentType(key_systems, key_system, media_type, |
| base::UTF16ToASCII(capability.mimeType), |
| base::UTF16ToASCII(capability.codecs))) { |
| continue; |
| @@ -211,7 +225,7 @@ static bool GetSupportedCapabilities( |
| // 3.12.1. If robustness is an unrecognized value or not supported by |
| // implementation, continue to the next iteration. String |
| // comparison is case-sensitive. |
| - EmeConfigRule robustness_rule = GetRobustnessConfigRule( |
| + EmeConfigRule robustness_rule = key_systems.GetRobustnessConfigRule( |
| key_system, media_type, ConvertRobustness(capability.robustness)); |
| if (!config_state->IsRuleSupported(robustness_rule)) |
| continue; |
| @@ -259,6 +273,7 @@ static EmeFeatureRequirement ConvertRequirement( |
| } |
| static ConfigurationSupport GetSupportedConfiguration( |
| + const KeySystems& key_systems, |
| const std::string& key_system, |
| const blink::WebMediaKeySystemConfiguration& candidate, |
| bool was_permission_requested, |
| @@ -330,7 +345,7 @@ static ConfigurationSupport GetSupportedConfiguration( |
| // null. |
| // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and |
| // permission has already been denied. This would happen anyway at step 11. |
| - EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule( |
| + EmeConfigRule di_rule = key_systems.GetDistinctiveIdentifierConfigRule( |
| key_system, ConvertRequirement(candidate.distinctiveIdentifier)); |
| if (!config_state.IsRuleSupported(di_rule)) { |
| DVLOG(2) << "Rejecting requested configuration because " |
| @@ -351,7 +366,7 @@ static ConfigurationSupport GetSupportedConfiguration( |
| // - "optional": Continue. |
| // - "not-allowed": If the implementation requires persisting state in |
| // combination with accumulated configuration, return null. |
| - EmeConfigRule ps_rule = GetPersistentStateConfigRule( |
| + EmeConfigRule ps_rule = key_systems.GetPersistentStateConfigRule( |
| key_system, ConvertRequirement(candidate.persistentState)); |
| if (!config_state.IsRuleSupported(ps_rule)) { |
| DVLOG(2) << "Rejecting requested configuration because " |
| @@ -373,9 +388,9 @@ static ConfigurationSupport GetSupportedConfiguration( |
| // configuration. |
| // 7.2. If video capabilities is null, return null. |
| std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; |
| - if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, |
| - EmeMediaType::VIDEO, &video_capabilities, |
| - &config_state)) { |
| + if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::VIDEO, |
| + candidate.videoCapabilities, |
| + &config_state, &video_capabilities)) { |
| return CONFIGURATION_NOT_SUPPORTED; |
| } |
| @@ -392,9 +407,9 @@ static ConfigurationSupport GetSupportedConfiguration( |
| // configuration. |
| // 8.2. If audio capabilities is null, return null. |
| std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
| - if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, |
| - EmeMediaType::AUDIO, &audio_capabilities, |
| - &config_state)) { |
| + if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::AUDIO, |
| + candidate.audioCapabilities, |
| + &config_state, &audio_capabilities)) { |
| return CONFIGURATION_NOT_SUPPORTED; |
| } |
| @@ -413,9 +428,11 @@ static ConfigurationSupport GetSupportedConfiguration( |
| if (accumulated_configuration->distinctiveIdentifier == |
| blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| EmeConfigRule not_allowed_rule = |
| - GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
| + key_systems.GetDistinctiveIdentifierConfigRule( |
| + key_system, EME_FEATURE_NOT_ALLOWED); |
| EmeConfigRule required_rule = |
| - GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED); |
| + key_systems.GetDistinctiveIdentifierConfigRule( |
| + key_system, EME_FEATURE_REQUIRED); |
| bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); |
| bool required_supported = config_state.IsRuleSupported(required_rule); |
| if (not_allowed_supported) { |
| @@ -465,9 +482,11 @@ static ConfigurationSupport GetSupportedConfiguration( |
| if (accumulated_configuration->persistentState == |
| blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| EmeConfigRule not_allowed_rule = |
| - GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
| + key_systems.GetPersistentStateConfigRule( |
| + key_system, EME_FEATURE_NOT_ALLOWED); |
| EmeConfigRule required_rule = |
| - GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED); |
| + key_systems.GetPersistentStateConfigRule( |
| + key_system, EME_FEATURE_REQUIRED); |
| // Now that distinctiveIdentifier has been resolved, it is too late to allow |
| // persistentState to affect the configuration. |
| bool not_allowed_supported = |
| @@ -510,12 +529,13 @@ static ConfigurationSupport GetSupportedConfiguration( |
| if (accumulated_configuration->persistentState == |
| blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
| if (config_state.IsRuleSupportedWithCurrentState( |
| - GetPersistentLicenseSessionConfigRule(key_system))) { |
| + key_systems.GetPersistentLicenseSessionConfigRule(key_system))) { |
| session_types.push_back( |
| blink::WebEncryptedMediaSessionType::PersistentLicense); |
| } |
| if (config_state.IsRuleSupportedWithCurrentState( |
| - GetPersistentReleaseMessageSessionConfigRule(key_system))) { |
| + key_systems.GetPersistentReleaseMessageSessionConfigRule( |
| + key_system))) { |
| session_types.push_back( |
| blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); |
| } |
| @@ -576,9 +596,12 @@ class WebEncryptedMediaClientImpl::Reporter { |
| }; |
| WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( |
| + const KeySystems& key_systems, |
| scoped_ptr<CdmFactory> cdm_factory, |
| MediaPermission* media_permission) |
| - : cdm_factory_(cdm_factory.Pass()), media_permission_(media_permission), |
| + : key_systems_(key_systems), |
| + cdm_factory_(cdm_factory.Pass()), |
| + media_permission_(media_permission), |
| weak_factory_(this) { |
| DCHECK(media_permission); |
| } |
| @@ -639,8 +662,9 @@ void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( |
| // new MediaKeySystemAccess object.] |
| blink::WebMediaKeySystemConfiguration accumulated_configuration; |
| ConfigurationSupport supported = GetSupportedConfiguration( |
| - key_system, candidate_configuration, was_permission_requested, |
| - is_permission_granted, &accumulated_configuration); |
| + key_systems_, key_system, candidate_configuration, |
| + was_permission_requested, is_permission_granted, |
| + &accumulated_configuration); |
| switch (supported) { |
| case CONFIGURATION_NOT_SUPPORTED: |
| continue; |