Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 // These names are used by UMA. | 24 // These names are used by UMA. |
| 25 const char kKeySystemSupportUMAPrefix[] = | 25 const char kKeySystemSupportUMAPrefix[] = |
| 26 "Media.EME.RequestMediaKeySystemAccess."; | 26 "Media.EME.RequestMediaKeySystemAccess."; |
| 27 | 27 |
| 28 enum ConfigurationSupport { | 28 enum ConfigurationSupport { |
| 29 CONFIGURATION_NOT_SUPPORTED, | 29 CONFIGURATION_NOT_SUPPORTED, |
| 30 CONFIGURATION_REQUIRES_PERMISSION, | 30 CONFIGURATION_REQUIRES_PERMISSION, |
| 31 CONFIGURATION_SUPPORTED, | 31 CONFIGURATION_SUPPORTED, |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Accumulates configuration rules to determine if a feature (additional | |
| 35 // configuration rule) can be added to an accumulated configuration. | |
| 36 class ConfigState { | |
| 37 public: | |
| 38 ConfigState(bool was_permission_requested, bool is_permission_granted) | |
| 39 : was_permission_requested_(was_permission_requested), | |
| 40 is_permission_granted_(is_permission_granted), | |
| 41 is_identifier_required_(false), | |
| 42 is_identifier_recommended_(false){ | |
| 43 } | |
| 44 | |
| 45 bool IsPermissionGranted() const { | |
| 46 return is_permission_granted_; | |
| 47 } | |
| 48 | |
| 49 // Permission is possible if it has not been denied. | |
| 50 bool IsPermissionPossible() const { | |
| 51 return is_permission_granted_ || !was_permission_requested_; | |
| 52 } | |
| 53 | |
| 54 bool IsIdentifierRequired() const { | |
| 55 return is_identifier_required_; | |
| 56 } | |
| 57 | |
| 58 bool IsIdentifierRecommended() const { | |
| 59 return is_identifier_recommended_; | |
| 60 } | |
| 61 | |
| 62 // Checks whether a rule is compatible with all previously added rules. | |
| 63 bool IsRuleSupported(EmeConfigRule rule) const { | |
| 64 switch (rule) { | |
| 65 case EmeConfigRule::NOT_SUPPORTED: | |
| 66 return false; | |
| 67 case EmeConfigRule::IDENTIFIER_REQUIRED: | |
| 68 return IsPermissionPossible(); | |
| 69 case EmeConfigRule::IDENTIFIER_RECOMMENDED: | |
| 70 return true; | |
| 71 case EmeConfigRule::SUPPORTED: | |
| 72 return true; | |
| 73 } | |
| 74 NOTREACHED(); | |
| 75 return false; | |
| 76 } | |
| 77 | |
| 78 // Checks whether a rule is compatible with all previously added rules, and | |
| 79 // can be accepted without needing to add it to the configuration state. This | |
| 80 // allows considering more rules after the configuration state is final (that | |
| 81 // is, after distinctiveIdentifier has been resolved). | |
| 82 bool IsRuleSupportedWithCurrentState(EmeConfigRule rule) const { | |
| 83 switch (rule) { | |
| 84 case EmeConfigRule::NOT_SUPPORTED: | |
| 85 return false; | |
| 86 case EmeConfigRule::IDENTIFIER_REQUIRED: | |
| 87 return is_permission_granted_; | |
| 88 case EmeConfigRule::IDENTIFIER_RECOMMENDED: | |
| 89 return true; | |
| 90 case EmeConfigRule::SUPPORTED: | |
| 91 return true; | |
| 92 } | |
| 93 NOTREACHED(); | |
| 94 return false; | |
| 95 } | |
| 96 | |
| 97 // Add a rule to the accumulated configuration state. | |
| 98 void AddRule(EmeConfigRule rule) { | |
| 99 switch (rule) { | |
| 100 case EmeConfigRule::NOT_SUPPORTED: | |
| 101 return; | |
| 102 case EmeConfigRule::IDENTIFIER_REQUIRED: | |
| 103 is_identifier_required_ = true; | |
| 104 return; | |
| 105 case EmeConfigRule::IDENTIFIER_RECOMMENDED: | |
| 106 is_identifier_recommended_ = true; | |
| 107 return; | |
| 108 case EmeConfigRule::SUPPORTED: | |
| 109 return; | |
| 110 } | |
| 111 NOTREACHED(); | |
| 112 } | |
| 113 | |
| 114 private: | |
| 115 // Whether permission to use a distinctive identifier was requested. If set, | |
| 116 // |is_permission_granted_| represents the final decision. | |
| 117 const bool was_permission_requested_; | |
| 118 | |
| 119 // Whether permission to use a distinctive identifier has been granted. | |
| 120 const bool is_permission_granted_; | |
| 121 | |
| 122 // Whether a rule has been added that requires a distinctive identifier. | |
| 123 bool is_identifier_required_; | |
| 124 | |
| 125 // Whether a rule has been added that recommends a distinctive identifier. | |
| 126 bool is_identifier_recommended_; | |
| 127 }; | |
| 128 | |
| 129 static EmeRobustness ConvertRobustness(const blink::WebString& robustness) { | |
| 130 if (robustness.isEmpty()) | |
| 131 return EmeRobustness::EMPTY; | |
| 132 if (robustness == "SW_SECURE_CRYPTO") | |
| 133 return EmeRobustness::SW_SECURE_CRYPTO; | |
| 134 if (robustness == "SW_SECURE_DECODE") | |
| 135 return EmeRobustness::SW_SECURE_DECODE; | |
| 136 if (robustness == "HW_SECURE_CRYPTO") | |
| 137 return EmeRobustness::HW_SECURE_CRYPTO; | |
| 138 if (robustness == "HW_SECURE_DECODE") | |
| 139 return EmeRobustness::HW_SECURE_DECODE; | |
| 140 if (robustness == "HW_SECURE_ALL") | |
| 141 return EmeRobustness::HW_SECURE_ALL; | |
| 142 return EmeRobustness::INVALID; | |
| 143 } | |
| 144 | |
| 34 static bool IsSupportedContentType(const std::string& key_system, | 145 static bool IsSupportedContentType(const std::string& key_system, |
| 35 const std::string& mime_type, | 146 const std::string& mime_type, |
| 36 const std::string& codecs) { | 147 const std::string& codecs) { |
| 37 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid | 148 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid |
| 38 // parameters can be rejected. http://crbug.com/417561 | 149 // parameters can be rejected. http://crbug.com/417561 |
| 39 // TODO(sandersd): Pass in the media type (audio or video) and check that the | 150 // TODO(sandersd): Pass in the media type (audio or video) and check that the |
| 40 // container type matches. http://crbug.com/457384 | 151 // container type matches. http://crbug.com/457384 |
| 41 std::string container = base::StringToLowerASCII(mime_type); | 152 std::string container = base::StringToLowerASCII(mime_type); |
| 42 | 153 |
| 43 // Check that |codecs| are supported by the CDM. This check does not handle | 154 // Check that |codecs| are supported by the CDM. This check does not handle |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 59 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 | 170 // TODO(sandersd): Reject ambiguous codecs. http://crbug.com/374751 |
| 60 codec_vector.clear(); | 171 codec_vector.clear(); |
| 61 net::ParseCodecString(codecs, &codec_vector, false); | 172 net::ParseCodecString(codecs, &codec_vector, false); |
| 62 return net::AreSupportedMediaCodecs(codec_vector); | 173 return net::AreSupportedMediaCodecs(codec_vector); |
| 63 } | 174 } |
| 64 | 175 |
| 65 static bool GetSupportedCapabilities( | 176 static bool GetSupportedCapabilities( |
| 66 const std::string& key_system, | 177 const std::string& key_system, |
| 67 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& | 178 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
| 68 capabilities, | 179 capabilities, |
| 180 EmeMediaType media_type, | |
| 69 std::vector<blink::WebMediaKeySystemMediaCapability>* | 181 std::vector<blink::WebMediaKeySystemMediaCapability>* |
| 70 media_type_capabilities) { | 182 media_type_capabilities, |
| 183 ConfigState* config_state) { | |
| 71 // From | 184 // From |
| 72 // 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 |
| 73 // 1. Let accumulated capabilities be partial configuration. | 186 // 1. Let accumulated capabilities be partial configuration. |
| 74 // (Skipped as there are no configuration-based codec restrictions.) | 187 // (Skipped as there are no configuration-based codec restrictions.) |
| 75 // 2. Let media type capabilities be empty. | 188 // 2. Let media type capabilities be empty. |
| 76 DCHECK_EQ(media_type_capabilities->size(), 0ul); | 189 DCHECK_EQ(media_type_capabilities->size(), 0ul); |
| 77 // 3. For each value in capabilities: | 190 // 3. For each value in capabilities: |
| 78 for (size_t i = 0; i < capabilities.size(); i++) { | 191 for (size_t i = 0; i < capabilities.size(); i++) { |
| 79 // 3.1. Let contentType be the value's contentType member. | 192 // 3.1. Let contentType be the value's contentType member. |
| 80 // 3.2. Let robustness be the value's robustness member. | 193 // 3.2. Let robustness be the value's robustness member. |
| 81 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; | 194 const blink::WebMediaKeySystemMediaCapability& capability = capabilities[i]; |
| 82 // 3.3. If contentType is the empty string, return null. | 195 // 3.3. If contentType is the empty string, return null. |
| 83 if (capability.mimeType.isEmpty()) | 196 if (capability.mimeType.isEmpty()) { |
| 197 DVLOG(2) << "Rejecting requested configuration because " | |
| 198 << "a capability contentType was empty."; | |
| 84 return false; | 199 return false; |
| 200 } | |
| 85 // 3.4-3.11. (Implemented by IsSupportedContentType().) | 201 // 3.4-3.11. (Implemented by IsSupportedContentType().) |
| 86 if (!base::IsStringASCII(capability.mimeType) || | 202 if (!base::IsStringASCII(capability.mimeType) || |
| 87 !base::IsStringASCII(capability.codecs) || | 203 !base::IsStringASCII(capability.codecs) || |
| 88 !IsSupportedContentType(key_system, | 204 !IsSupportedContentType(key_system, |
| 89 base::UTF16ToASCII(capability.mimeType), | 205 base::UTF16ToASCII(capability.mimeType), |
| 90 base::UTF16ToASCII(capability.codecs))) { | 206 base::UTF16ToASCII(capability.codecs))) { |
| 91 continue; | 207 continue; |
| 92 } | 208 } |
| 93 // 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: |
| 94 // (Robustness is not supported.) | |
| 95 // TODO(sandersd): Implement robustness. http://crbug.com/442586 | |
| 96 if (!capability.robustness.isEmpty()) { | 210 if (!capability.robustness.isEmpty()) { |
| 97 LOG(WARNING) << "Configuration rejected because rubustness strings are " | 211 // 3.12.1. If robustness is an unrecognized value or not supported by |
| 98 << "not yet supported."; | 212 // implementation, continue to the next iteration. String |
| 99 continue; | 213 // comparison is case-sensitive. |
| 214 EmeConfigRule robustness_rule = GetRobustnessConfigRule( | |
| 215 key_system, media_type, ConvertRobustness(capability.robustness)); | |
| 216 if (!config_state->IsRuleSupported(robustness_rule)) | |
| 217 continue; | |
| 218 config_state->AddRule(robustness_rule); | |
| 219 // 3.12.2. Add robustness to configuration. | |
| 220 // (It's already added, we use capability as the configuration.) | |
| 100 } | 221 } |
| 101 // 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 |
| 102 // encrypted media data as specified by configuration, including all | 223 // encrypted media data as specified by configuration, including all |
| 103 // media types, in combination with accumulated capabilities, | 224 // media types, in combination with accumulated capabilities, |
| 104 // continue to the next iteration. | 225 // continue to the next iteration. |
| 105 // (Skipped as there are no configuration-based codec restrictions.) | 226 // (Skipped as there are no configuration-based codec restrictions. |
| 227 // There will be when the Android security level becomes configurable | |
| 228 // based on robustness. http://crbug.com/467779) | |
| 106 // 3.14. Add configuration to media type capabilities. | 229 // 3.14. Add configuration to media type capabilities. |
| 107 media_type_capabilities->push_back(capability); | 230 media_type_capabilities->push_back(capability); |
| 108 // 3.15. Add configuration to accumulated capabilities. | 231 // 3.15. Add configuration to accumulated capabilities. |
| 109 // (Skipped as there are no configuration-based codec restrictions.) | 232 // (Skipped as there are no configuration-based codec restrictions. |
| 233 // Note that this is the local accumulated capabilities, the global | |
| 234 // one is updated by the caller.) | |
| 110 } | 235 } |
| 111 // 4. If media type capabilities is empty, return null. | 236 // 4. If media type capabilities is empty, return null. |
| 112 // 5. Return media type capabilities. | 237 // 5. Return media type capabilities. |
| 238 if (media_type_capabilities->empty()) { | |
|
ddorwin
2015/03/19 22:11:57
Move up under 4.
sandersd (OOO until July 31)
2015/03/19 23:05:43
Done.
| |
| 239 DVLOG(2) << "Rejecting requested configuration because " | |
| 240 << "no capabilities were supported."; | |
| 241 return false; | |
| 242 } | |
| 113 return !media_type_capabilities->empty(); | 243 return !media_type_capabilities->empty(); |
|
ddorwin
2015/03/19 22:11:57
Just return true.
sandersd (OOO until July 31)
2015/03/19 23:05:44
Done.
| |
| 114 } | 244 } |
| 115 | 245 |
| 116 static EmeFeatureRequirement ConvertRequirement( | 246 static EmeFeatureRequirement ConvertRequirement( |
| 117 blink::WebMediaKeySystemConfiguration::Requirement requirement) { | 247 blink::WebMediaKeySystemConfiguration::Requirement requirement) { |
| 118 switch (requirement) { | 248 switch (requirement) { |
| 119 case blink::WebMediaKeySystemConfiguration::Requirement::Required: | 249 case blink::WebMediaKeySystemConfiguration::Requirement::Required: |
| 120 return EME_FEATURE_REQUIRED; | 250 return EME_FEATURE_REQUIRED; |
| 121 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: | 251 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: |
| 122 return EME_FEATURE_OPTIONAL; | 252 return EME_FEATURE_OPTIONAL; |
| 123 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | 253 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
| 124 return EME_FEATURE_NOT_ALLOWED; | 254 return EME_FEATURE_NOT_ALLOWED; |
| 125 } | 255 } |
| 126 | 256 |
| 127 NOTREACHED(); | 257 NOTREACHED(); |
| 128 return EME_FEATURE_NOT_ALLOWED; | 258 return EME_FEATURE_NOT_ALLOWED; |
| 129 } | 259 } |
| 130 | 260 |
| 131 static ConfigurationSupport GetSupportedConfiguration( | 261 static ConfigurationSupport GetSupportedConfiguration( |
| 132 const std::string& key_system, | 262 const std::string& key_system, |
| 133 const blink::WebMediaKeySystemConfiguration& candidate, | 263 const blink::WebMediaKeySystemConfiguration& candidate, |
| 134 blink::WebMediaKeySystemConfiguration* accumulated_configuration, | |
| 135 bool was_permission_requested, | 264 bool was_permission_requested, |
| 136 bool is_permission_granted) { | 265 bool is_permission_granted, |
| 137 DCHECK(was_permission_requested || !is_permission_granted); | 266 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
| 138 | 267 ConfigState config_state(was_permission_requested, is_permission_granted); |
| 139 // It is possible to obtain user permission unless permission was already | |
| 140 // requested and denied. | |
| 141 bool is_permission_possible = | |
| 142 !was_permission_requested || is_permission_granted; | |
| 143 | 268 |
| 144 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | 269 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
| 145 // 1. Let accumulated configuration be empty. (Done by caller.) | 270 // 1. Let accumulated configuration be empty. (Done by caller.) |
| 146 // 2. If candidate configuration's initDataTypes attribute is not empty, run | 271 // 2. If candidate configuration's initDataTypes attribute is not empty, run |
| 147 // the following steps: | 272 // the following steps: |
| 148 if (!candidate.initDataTypes.isEmpty()) { | 273 if (!candidate.initDataTypes.isEmpty()) { |
| 149 // 2.1. Let supported types be empty. | 274 // 2.1. Let supported types be empty. |
| 150 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; | 275 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; |
| 151 | 276 |
| 152 // 2.2. For each value in candidate configuration's initDataTypes attribute: | 277 // 2.2. For each value in candidate configuration's initDataTypes attribute: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 177 NOTREACHED(); | 302 NOTREACHED(); |
| 178 break; | 303 break; |
| 179 } | 304 } |
| 180 if (IsSupportedKeySystemWithInitDataType(key_system, | 305 if (IsSupportedKeySystemWithInitDataType(key_system, |
| 181 init_data_type_as_ascii)) { | 306 init_data_type_as_ascii)) { |
| 182 supported_types.push_back(init_data_type); | 307 supported_types.push_back(init_data_type); |
| 183 } | 308 } |
| 184 } | 309 } |
| 185 | 310 |
| 186 // 2.3. If supported types is empty, return null. | 311 // 2.3. If supported types is empty, return null. |
| 187 if (supported_types.empty()) | 312 if (supported_types.empty()) { |
| 313 DVLOG(2) << "Rejecting requested configuration because " | |
| 314 << "no initDataType values were supported."; | |
| 188 return CONFIGURATION_NOT_SUPPORTED; | 315 return CONFIGURATION_NOT_SUPPORTED; |
| 316 } | |
| 189 | 317 |
| 190 // 2.4. Add supported types to accumulated configuration. | 318 // 2.4. Add supported types to accumulated configuration. |
| 191 accumulated_configuration->initDataTypes = supported_types; | 319 accumulated_configuration->initDataTypes = supported_types; |
| 192 } | 320 } |
| 193 | 321 |
| 194 // 3. Follow the steps for the value of candidate configuration's | 322 // 3. Follow the steps for the value of candidate configuration's |
| 195 // distinctiveIdentifier attribute from the following list: | 323 // distinctiveIdentifier attribute from the following list: |
| 196 // - "required": If the implementation does not support a persistent | 324 // - "required": If the implementation does not support a persistent |
| 197 // Distinctive Identifier in combination with accumulated configuration, | 325 // Distinctive Identifier in combination with accumulated configuration, |
| 198 // return null. | 326 // return null. |
| 199 // - "optional": Continue. | 327 // - "optional": Continue. |
| 200 // - "not-allowed": If the implementation requires a Distinctive | 328 // - "not-allowed": If the implementation requires a Distinctive |
| 201 // Identifier in combination with accumulated configuration, return | 329 // Identifier in combination with accumulated configuration, return |
| 202 // null. | 330 // null. |
| 203 EmeFeatureRequirement di_requirement = | 331 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and |
| 204 ConvertRequirement(candidate.distinctiveIdentifier); | 332 // permission has already been denied. This would happen anyway at step 11. |
| 205 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 333 EmeConfigRule di_rule = GetDistinctiveIdentifierConfigRule( |
| 206 is_permission_possible)) { | 334 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); |
| 335 if (!config_state.IsRuleSupported(di_rule)) { | |
| 336 DVLOG(2) << "Rejecting requested configuration because " | |
| 337 << "the distinctiveIdentifier requirement was not supported."; | |
| 207 return CONFIGURATION_NOT_SUPPORTED; | 338 return CONFIGURATION_NOT_SUPPORTED; |
| 208 } | 339 } |
| 340 config_state.AddRule(di_rule); | |
| 209 | 341 |
| 210 // 4. Add the value of the candidate configuration's distinctiveIdentifier | 342 // 4. Add the value of the candidate configuration's distinctiveIdentifier |
| 211 // attribute to accumulated configuration. | 343 // attribute to accumulated configuration. |
| 212 accumulated_configuration->distinctiveIdentifier = | 344 accumulated_configuration->distinctiveIdentifier = |
| 213 candidate.distinctiveIdentifier; | 345 candidate.distinctiveIdentifier; |
| 214 | 346 |
| 215 // 5. Follow the steps for the value of candidate configuration's | 347 // 5. Follow the steps for the value of candidate configuration's |
| 216 // persistentState attribute from the following list: | 348 // persistentState attribute from the following list: |
| 217 // - "required": If the implementation does not support persisting state | 349 // - "required": If the implementation does not support persisting state |
| 218 // in combination with accumulated configuration, return null. | 350 // in combination with accumulated configuration, return null. |
| 219 // - "optional": Continue. | 351 // - "optional": Continue. |
| 220 // - "not-allowed": If the implementation requires persisting state in | 352 // - "not-allowed": If the implementation requires persisting state in |
| 221 // combination with accumulated configuration, return null. | 353 // combination with accumulated configuration, return null. |
| 222 EmeFeatureRequirement ps_requirement = | 354 EmeConfigRule ps_rule = GetPersistentStateConfigRule( |
| 223 ConvertRequirement(candidate.persistentState); | 355 key_system, ConvertRequirement(candidate.persistentState)); |
| 224 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | 356 if (!config_state.IsRuleSupported(ps_rule)) { |
| 225 is_permission_possible)) { | 357 DVLOG(2) << "Rejecting requested configuration because " |
| 358 << "the persistentState requirement was not supported."; | |
| 226 return CONFIGURATION_NOT_SUPPORTED; | 359 return CONFIGURATION_NOT_SUPPORTED; |
| 227 } | 360 } |
| 361 config_state.AddRule(ps_rule); | |
| 228 | 362 |
| 229 // 6. Add the value of the candidate configuration's persistentState | 363 // 6. Add the value of the candidate configuration's persistentState |
| 230 // attribute to accumulated configuration. | 364 // attribute to accumulated configuration. |
| 231 accumulated_configuration->persistentState = candidate.persistentState; | 365 accumulated_configuration->persistentState = candidate.persistentState; |
| 232 | 366 |
| 233 // 7. If candidate configuration's videoCapabilities attribute is not empty, | 367 // 7. If candidate configuration's videoCapabilities attribute is not empty, |
| 234 // run the following steps: | 368 // run the following steps: |
| 235 if (!candidate.videoCapabilities.isEmpty()) { | 369 if (!candidate.videoCapabilities.isEmpty()) { |
| 236 // 7.1. Let video capabilities be the result of executing the Get Supported | 370 // 7.1. Let video capabilities be the result of executing the Get Supported |
| 237 // Capabilities for Media Type algorithm on Video, candidate | 371 // Capabilities for Media Type algorithm on Video, candidate |
| 238 // configuration's videoCapabilities attribute, and accumulated | 372 // configuration's videoCapabilities attribute, and accumulated |
| 239 // configuration. | 373 // configuration. |
| 240 // 7.2. If video capabilities is null, return null. | 374 // 7.2. If video capabilities is null, return null. |
| 241 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | 375 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; |
| 242 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, | 376 if (!GetSupportedCapabilities(key_system, candidate.videoCapabilities, |
| 243 &video_capabilities)) { | 377 EmeMediaType::VIDEO, &video_capabilities, |
| 378 &config_state)) { | |
| 244 return CONFIGURATION_NOT_SUPPORTED; | 379 return CONFIGURATION_NOT_SUPPORTED; |
| 245 } | 380 } |
| 246 | 381 |
| 247 // 7.3. Add video capabilities to accumulated configuration. | 382 // 7.3. Add video capabilities to accumulated configuration. |
| 248 accumulated_configuration->videoCapabilities = video_capabilities; | 383 accumulated_configuration->videoCapabilities = video_capabilities; |
| 249 } | 384 } |
| 250 | 385 |
| 251 // 8. If candidate configuration's audioCapabilities attribute is not empty, | 386 // 8. If candidate configuration's audioCapabilities attribute is not empty, |
| 252 // run the following steps: | 387 // run the following steps: |
| 253 if (!candidate.audioCapabilities.isEmpty()) { | 388 if (!candidate.audioCapabilities.isEmpty()) { |
| 254 // 8.1. Let audio capabilities be the result of executing the Get Supported | 389 // 8.1. Let audio capabilities be the result of executing the Get Supported |
| 255 // Capabilities for Media Type algorithm on Audio, candidate | 390 // Capabilities for Media Type algorithm on Audio, candidate |
| 256 // configuration's audioCapabilities attribute, and accumulated | 391 // configuration's audioCapabilities attribute, and accumulated |
| 257 // configuration. | 392 // configuration. |
| 258 // 8.2. If audio capabilities is null, return null. | 393 // 8.2. If audio capabilities is null, return null. |
| 259 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | 394 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
| 260 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, | 395 if (!GetSupportedCapabilities(key_system, candidate.audioCapabilities, |
| 261 &audio_capabilities)) { | 396 EmeMediaType::AUDIO, &audio_capabilities, |
| 397 &config_state)) { | |
| 262 return CONFIGURATION_NOT_SUPPORTED; | 398 return CONFIGURATION_NOT_SUPPORTED; |
| 263 } | 399 } |
| 264 | 400 |
| 265 // 8.3. Add audio capabilities to accumulated configuration. | 401 // 8.3. Add audio capabilities to accumulated configuration. |
| 266 accumulated_configuration->audioCapabilities = audio_capabilities; | 402 accumulated_configuration->audioCapabilities = audio_capabilities; |
| 267 } | 403 } |
| 268 | 404 |
| 269 // 9. If accumulated configuration's distinctiveIdentifier value is | 405 // 9. If accumulated configuration's distinctiveIdentifier value is |
| 270 // "optional", follow the steps for the first matching condition from the | 406 // "optional", follow the steps for the first matching condition from the |
| 271 // following list: | 407 // following list: |
| 272 // - If the implementation requires a Distinctive Identifier for any of | 408 // - If the implementation requires a Distinctive Identifier for any of |
| 273 // the combinations in accumulated configuration, change accumulated | 409 // the combinations in accumulated configuration, change accumulated |
| 274 // configuration's distinctiveIdentifier value to "required". | 410 // configuration's distinctiveIdentifier value to "required". |
| 275 // - Otherwise, change accumulated configuration's distinctiveIdentifier | 411 // - Otherwise, change accumulated configuration's distinctiveIdentifier |
| 276 // value to "not-allowed". | 412 // value to "not-allowed". |
| 277 // (Without robustness support, capabilities do not affect this.) | |
| 278 // TODO(sandersd): Implement robustness. http://crbug.com/442586 | |
| 279 if (accumulated_configuration->distinctiveIdentifier == | 413 if (accumulated_configuration->distinctiveIdentifier == |
| 280 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 414 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| 281 if (IsDistinctiveIdentifierRequirementSupported( | 415 EmeConfigRule not_allowed_rule = |
| 282 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { | 416 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
| 283 accumulated_configuration->distinctiveIdentifier = | 417 EmeConfigRule required_rule = |
| 284 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 418 GetDistinctiveIdentifierConfigRule(key_system, EME_FEATURE_REQUIRED); |
| 285 } else { | 419 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); |
| 420 bool required_supported = config_state.IsRuleSupported(required_rule); | |
| 421 if (not_allowed_supported) { | |
| 422 bool prefer_required = config_state.IsIdentifierRequired() || | |
| 423 (config_state.IsIdentifierRecommended() && | |
| 424 config_state.IsPermissionPossible()); | |
| 425 if (required_supported && prefer_required) { | |
| 426 accumulated_configuration->distinctiveIdentifier = | |
| 427 blink::WebMediaKeySystemConfiguration::Requirement::Required; | |
| 428 config_state.AddRule(required_rule); | |
| 429 DCHECK(config_state.IsIdentifierRequired()); | |
| 430 } else { | |
| 431 accumulated_configuration->distinctiveIdentifier = | |
| 432 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
| 433 config_state.AddRule(not_allowed_rule); | |
| 434 } | |
| 435 } else if (required_supported) { | |
| 286 accumulated_configuration->distinctiveIdentifier = | 436 accumulated_configuration->distinctiveIdentifier = |
| 287 blink::WebMediaKeySystemConfiguration::Requirement::Required; | 437 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 438 config_state.AddRule(required_rule); | |
| 439 } else { | |
| 440 // We should not have passed step 3. | |
| 441 NOTREACHED(); | |
| 442 return CONFIGURATION_NOT_SUPPORTED; | |
| 288 } | 443 } |
| 289 } | 444 } |
| 290 | 445 |
| 446 // If permission is required but we couldn't enable it, reject the | |
| 447 // configuration. | |
| 448 if (config_state.IsIdentifierRequired() && | |
| 449 accumulated_configuration->distinctiveIdentifier != | |
| 450 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | |
| 451 DVLOG(2) << "Rejecting requested configuration because " | |
| 452 << "distinctiveIdentifier was both not allowed and " | |
|
ddorwin
2015/03/19 22:11:57
nit: I think the logic above is in the opposite or
sandersd (OOO until July 31)
2015/03/19 23:05:43
Done.
| |
| 453 << "implicitly required."; | |
| 454 return CONFIGURATION_NOT_SUPPORTED; | |
| 455 } | |
| 456 | |
| 291 // 10. If accumulated configuration's persistentState value is "optional", | 457 // 10. If accumulated configuration's persistentState value is "optional", |
| 292 // follow the steps for the first matching condition from the following | 458 // follow the steps for the first matching condition from the following |
| 293 // list: | 459 // list: |
| 294 // - If the implementation requires persisting state for any of the | 460 // - If the implementation requires persisting state for any of the |
| 295 // combinations in accumulated configuration, change accumulated | 461 // combinations in accumulated configuration, change accumulated |
| 296 // configuration's persistentState value to "required". | 462 // configuration's persistentState value to "required". |
| 297 // - Otherwise, change accumulated configuration's persistentState value | 463 // - Otherwise, change accumulated configuration's persistentState value |
| 298 // to "not-allowed". | 464 // to "not-allowed". |
| 299 if (accumulated_configuration->persistentState == | 465 if (accumulated_configuration->persistentState == |
| 300 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | 466 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
| 301 if (IsPersistentStateRequirementSupported( | 467 EmeConfigRule not_allowed_rule = |
| 302 key_system, EME_FEATURE_NOT_ALLOWED, is_permission_possible)) { | 468 GetPersistentStateConfigRule(key_system, EME_FEATURE_NOT_ALLOWED); |
| 469 EmeConfigRule required_rule = | |
| 470 GetPersistentStateConfigRule(key_system, EME_FEATURE_REQUIRED); | |
| 471 bool not_allowed_supported = | |
| 472 config_state.IsRuleSupportedWithCurrentState(not_allowed_rule); | |
| 473 bool required_supported = | |
| 474 config_state.IsRuleSupportedWithCurrentState(required_rule); | |
| 475 if (not_allowed_supported) { | |
| 303 accumulated_configuration->persistentState = | 476 accumulated_configuration->persistentState = |
| 304 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | 477 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
| 305 } else { | 478 } else if (required_supported) { |
| 306 accumulated_configuration->persistentState = | 479 accumulated_configuration->persistentState = |
| 307 blink::WebMediaKeySystemConfiguration::Requirement::Required; | 480 blink::WebMediaKeySystemConfiguration::Requirement::Required; |
| 481 } else { | |
| 482 // We should not have passed step 5. | |
| 483 NOTREACHED(); | |
| 484 return CONFIGURATION_NOT_SUPPORTED; | |
| 308 } | 485 } |
| 309 } | 486 } |
| 310 | 487 |
| 311 // 11. If implementation in the configuration specified by the combination of | 488 // 11. If implementation in the configuration specified by the combination of |
| 312 // the values in accumulated configuration is not supported or not allowed | 489 // the values in accumulated configuration is not supported or not allowed |
| 313 // in the origin, return null. | 490 // in the origin, return null. |
| 314 di_requirement = | 491 // |
| 315 ConvertRequirement(accumulated_configuration->distinctiveIdentifier); | 492 // If accumulated configuration's distinctiveIdentifier value is |
| 316 if (!IsDistinctiveIdentifierRequirementSupported(key_system, di_requirement, | 493 // "required", [request user consent]. |
| 317 is_permission_granted)) { | 494 if (accumulated_configuration->distinctiveIdentifier == |
| 318 if (was_permission_requested) { | 495 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
| 319 // The optional permission was requested and denied. | 496 if (!config_state.IsPermissionGranted()) |
| 320 // TODO(sandersd): Avoid the need for this logic - crbug.com/460616. | |
| 321 DCHECK(candidate.distinctiveIdentifier == | |
| 322 blink::WebMediaKeySystemConfiguration::Requirement::Optional); | |
| 323 DCHECK(di_requirement == EME_FEATURE_REQUIRED); | |
| 324 DCHECK(!is_permission_granted); | |
| 325 accumulated_configuration->distinctiveIdentifier = | |
| 326 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
| 327 } else { | |
| 328 return CONFIGURATION_REQUIRES_PERMISSION; | 497 return CONFIGURATION_REQUIRES_PERMISSION; |
| 329 } | |
| 330 } | |
| 331 | |
| 332 ps_requirement = | |
| 333 ConvertRequirement(accumulated_configuration->persistentState); | |
| 334 if (!IsPersistentStateRequirementSupported(key_system, ps_requirement, | |
| 335 is_permission_granted)) { | |
| 336 DCHECK(!was_permission_requested); // Should have failed at step 5. | |
| 337 return CONFIGURATION_REQUIRES_PERMISSION; | |
| 338 } | 498 } |
| 339 | 499 |
| 340 // 12. Return accumulated configuration. | 500 // 12. Return accumulated configuration. |
| 341 // (As an extra step, we record the available session types so that | 501 // |
| 342 // createSession() can be synchronous.) | 502 // We also record the available session types so that createSession() can be |
| 503 // synchronous. | |
| 343 std::vector<blink::WebEncryptedMediaSessionType> session_types; | 504 std::vector<blink::WebEncryptedMediaSessionType> session_types; |
| 344 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); | 505 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary); |
| 345 if (accumulated_configuration->persistentState == | 506 if (accumulated_configuration->persistentState == |
| 346 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | 507 blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
| 347 if (IsPersistentLicenseSessionSupported(key_system, | 508 if (config_state.IsRuleSupportedWithCurrentState( |
| 348 is_permission_granted)) { | 509 GetPersistentLicenseSessionConfigRule(key_system))) { |
| 349 session_types.push_back( | 510 session_types.push_back( |
| 350 blink::WebEncryptedMediaSessionType::PersistentLicense); | 511 blink::WebEncryptedMediaSessionType::PersistentLicense); |
| 351 } | 512 } |
| 352 if (IsPersistentReleaseMessageSessionSupported(key_system, | 513 if (config_state.IsRuleSupportedWithCurrentState( |
| 353 is_permission_granted)) { | 514 GetPersistentReleaseMessageSessionConfigRule(key_system))) { |
| 354 session_types.push_back( | 515 session_types.push_back( |
| 355 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); | 516 blink::WebEncryptedMediaSessionType::PersistentReleaseMessage); |
| 356 } | 517 } |
| 357 } | 518 } |
| 358 accumulated_configuration->sessionTypes = session_types; | 519 accumulated_configuration->sessionTypes = session_types; |
| 359 | 520 |
| 360 return CONFIGURATION_SUPPORTED; | 521 return CONFIGURATION_SUPPORTED; |
| 361 } | 522 } |
| 362 | 523 |
| 363 // Report usage of key system to UMA. There are 2 different counts logged: | 524 // Report usage of key system to UMA. There are 2 different counts logged: |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 // 7.3.1. Let candidate configuration be the value. | 628 // 7.3.1. Let candidate configuration be the value. |
| 468 const blink::WebMediaKeySystemConfiguration& candidate_configuration = | 629 const blink::WebMediaKeySystemConfiguration& candidate_configuration = |
| 469 configurations[i]; | 630 configurations[i]; |
| 470 // 7.3.2. Let supported configuration be the result of executing the Get | 631 // 7.3.2. Let supported configuration be the result of executing the Get |
| 471 // Supported Configuration algorithm on implementation, candidate | 632 // Supported Configuration algorithm on implementation, candidate |
| 472 // configuration, and origin. | 633 // configuration, and origin. |
| 473 // 7.3.3. If supported configuration is not null, [initialize and return a | 634 // 7.3.3. If supported configuration is not null, [initialize and return a |
| 474 // new MediaKeySystemAccess object.] | 635 // new MediaKeySystemAccess object.] |
| 475 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 636 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
| 476 ConfigurationSupport supported = GetSupportedConfiguration( | 637 ConfigurationSupport supported = GetSupportedConfiguration( |
| 477 key_system, candidate_configuration, &accumulated_configuration, | 638 key_system, candidate_configuration, was_permission_requested, |
| 478 was_permission_requested, is_permission_granted); | 639 is_permission_granted, &accumulated_configuration); |
| 479 switch (supported) { | 640 switch (supported) { |
| 480 case CONFIGURATION_NOT_SUPPORTED: | 641 case CONFIGURATION_NOT_SUPPORTED: |
| 481 continue; | 642 continue; |
| 482 case CONFIGURATION_REQUIRES_PERMISSION: | 643 case CONFIGURATION_REQUIRES_PERMISSION: |
| 483 DCHECK(!was_permission_requested); | 644 if (was_permission_requested) { |
| 645 DVLOG(2) << "Rejecting requested configuration because " | |
| 646 << "permission was denied."; | |
| 647 continue; | |
| 648 } | |
| 484 media_permission_->RequestPermission( | 649 media_permission_->RequestPermission( |
| 485 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, | 650 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, |
| 486 GURL(request.securityOrigin().toString()), | 651 GURL(request.securityOrigin().toString()), |
| 487 // Try again with |was_permission_requested| true and | 652 // Try again with |was_permission_requested| true and |
| 488 // |is_permission_granted| the value of the permission. | 653 // |is_permission_granted| the value of the permission. |
| 489 base::Bind( | 654 base::Bind( |
| 490 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, | 655 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, |
| 491 weak_factory_.GetWeakPtr(), request, true)); | 656 weak_factory_.GetWeakPtr(), request, true)); |
| 492 return; | 657 return; |
| 493 case CONFIGURATION_SUPPORTED: | 658 case CONFIGURATION_SUPPORTED: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 return reporter; | 692 return reporter; |
| 528 | 693 |
| 529 // Reporter not found, so create one. | 694 // Reporter not found, so create one. |
| 530 auto result = | 695 auto result = |
| 531 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 696 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
| 532 DCHECK(result.second); | 697 DCHECK(result.second); |
| 533 return result.first->second; | 698 return result.first->second; |
| 534 } | 699 } |
| 535 | 700 |
| 536 } // namespace media | 701 } // namespace media |
| OLD | NEW |