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" | |
| 9 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 12 #include "media/base/key_systems.h" | 11 #include "media/base/key_systems.h" |
| 13 #include "media/base/media_permission.h" | 12 #include "media/base/media_permission.h" |
| 14 #include "media/blink/webcontentdecryptionmodule_impl.h" | 13 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 15 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h" | 14 #include "media/blink/webcontentdecryptionmoduleaccess_impl.h" |
| 16 #include "media/blink/webmediaplayer_util.h" | 15 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
| 17 #include "net/base/mime_util.h" | |
| 18 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" | 16 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" |
| 19 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" | 17 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" |
| 20 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 21 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 22 | 19 |
| 23 namespace media { | 20 namespace media { |
| 24 | 21 |
| 25 // These names are used by UMA. | 22 namespace { |
| 23 | |
| 24 // Used to name UMAs in Reporter. | |
| 26 const char kKeySystemSupportUMAPrefix[] = | 25 const char kKeySystemSupportUMAPrefix[] = |
| 27 "Media.EME.RequestMediaKeySystemAccess."; | 26 "Media.EME.RequestMediaKeySystemAccess."; |
| 28 | 27 |
| 29 enum ConfigurationSupport { | 28 } // namespace |
| 30 CONFIGURATION_NOT_SUPPORTED, | |
| 31 CONFIGURATION_REQUIRES_PERMISSION, | |
| 32 CONFIGURATION_SUPPORTED, | |
| 33 }; | |
| 34 | |
| 35 // Accumulates configuration rules to determine if a feature (additional | |
| 36 // configuration rule) can be added to an accumulated configuration. | |
| 37 class ConfigState { | |
| 38 public: | |
| 39 ConfigState(bool was_permission_requested, bool is_permission_granted) | |
| 40 : was_permission_requested_(was_permission_requested), | |
| 41 is_permission_granted_(is_permission_granted) { | |
| 42 } | |
| 43 | |
| 44 bool IsPermissionGranted() const { | |
| 45 return is_permission_granted_; | |
| 46 } | |
| 47 | |
| 48 // Permission is possible if it has not been denied. | |
| 49 bool IsPermissionPossible() const { | |
| 50 return is_permission_granted_ || !was_permission_requested_; | |
| 51 } | |
| 52 | |
| 53 bool IsIdentifierRequired() const { | |
| 54 return is_identifier_required_; | |
| 55 } | |
| 56 | |
| 57 bool IsIdentifierRecommended() const { | |
| 58 return is_identifier_recommended_; | |
| 59 } | |
| 60 | |
| 61 // Checks whether a rule is compatible with all previously added rules. | |
| 62 bool IsRuleSupported(EmeConfigRule rule) const { | |
| 63 switch (rule) { | |
| 64 case EmeConfigRule::NOT_SUPPORTED: | |
| 65 return false; | |
| 66 case EmeConfigRule::IDENTIFIER_NOT_ALLOWED: | |
| 67 return !is_identifier_required_; | |
| 68 case EmeConfigRule::IDENTIFIER_REQUIRED: | |
| 69 // TODO(sandersd): Confirm if we should be refusing these rules when | |
| 70 // permission has been denied (as the spec currently says). | |
| 71 return !is_identifier_not_allowed_ && IsPermissionPossible(); | |
| 72 case EmeConfigRule::IDENTIFIER_RECOMMENDED: | |
| 73 return true; | |
| 74 case EmeConfigRule::PERSISTENCE_NOT_ALLOWED: | |
| 75 return !is_persistence_required_; | |
| 76 case EmeConfigRule::PERSISTENCE_REQUIRED: | |
| 77 return !is_persistence_not_allowed_; | |
| 78 case EmeConfigRule::IDENTIFIER_AND_PERSISTENCE_REQUIRED: | |
| 79 return (!is_identifier_not_allowed_ && IsPermissionPossible() && | |
| 80 !is_persistence_not_allowed_); | |
| 81 case EmeConfigRule::SUPPORTED: | |
| 82 return true; | |
| 83 } | |
| 84 NOTREACHED(); | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 // Add a rule to the accumulated configuration state. | |
| 89 void AddRule(EmeConfigRule rule) { | |
| 90 DCHECK(IsRuleSupported(rule)); | |
| 91 switch (rule) { | |
| 92 case EmeConfigRule::NOT_SUPPORTED: | |
| 93 return; | |
| 94 case EmeConfigRule::IDENTIFIER_NOT_ALLOWED: | |
| 95 is_identifier_not_allowed_ = true; | |
| 96 return; | |
| 97 case EmeConfigRule::IDENTIFIER_REQUIRED: | |
| 98 is_identifier_required_ = true; | |
| 99 return; | |
| 100 case EmeConfigRule::IDENTIFIER_RECOMMENDED: | |
| 101 is_identifier_recommended_ = true; | |
| 102 return; | |
| 103 case EmeConfigRule::PERSISTENCE_NOT_ALLOWED: | |
| 104 is_persistence_not_allowed_ = true; | |
| 105 return; | |
| 106 case EmeConfigRule::PERSISTENCE_REQUIRED: | |
| 107 is_persistence_required_ = true; | |
| 108 return; | |
| 109 case EmeConfigRule::IDENTIFIER_AND_PERSISTENCE_REQUIRED: | |
| 110 is_identifier_required_ = true; | |
| 111 is_persistence_required_ = true; | |
| 112 return; | |
| 113 case EmeConfigRule::SUPPORTED: | |
| 114 return; | |
| 115 } | |
| 116 NOTREACHED(); | |
| 117 } | |
| 118 | |
| 119 private: | |
| 120 // Whether permission to use a distinctive identifier was requested. If set, | |
| 121 // |is_permission_granted_| represents the final decision. | |
| 122 const bool was_permission_requested_; | |
| 123 | |
| 124 // Whether permission to use a distinctive identifier has been granted. | |
| 125 const bool is_permission_granted_; | |
| 126 | |
| 127 // Whether a rule has been added that requires or blocks a distinctive | |
| 128 // identifier. | |
| 129 bool is_identifier_required_ = false; | |
| 130 bool is_identifier_not_allowed_ = false; | |
| 131 | |
| 132 // Whether a rule has been added that recommends a distinctive identifier. | |
| 133 bool is_identifier_recommended_ = false; | |
| 134 | |
| 135 // Whether a rule has been added that requires or blocks persistent state. | |
| 136 bool is_persistence_required_ = false; | |
| 137 bool is_persistence_not_allowed_ = false; | |
| 138 }; | |
| 139 | |
| 140 static bool IsSupportedContentType( | |
| 141 const KeySystems& key_systems, | |
| 142 const std::string& key_system, | |
| 143 EmeMediaType media_type, | |
| 144 const std::string& container_mime_type, | |
| 145 const std::string& codecs) { | |
| 146 // TODO(sandersd): Move contentType parsing from Blink to here so that invalid | |
| 147 // parameters can be rejected. http://crbug.com/417561 | |
| 148 std::string container_lower = base::StringToLowerASCII(container_mime_type); | |
| 149 | |
| 150 // Check that |container_mime_type| and |codecs| are supported by the CDM. | |
| 151 // This check does not handle extended codecs, so extended codec information | |
| 152 // is stripped. | |
| 153 std::vector<std::string> codec_vector; | |
| 154 net::ParseCodecString(codecs, &codec_vector, true); | |
| 155 if (!key_systems.IsSupportedCodecCombination( | |
| 156 key_system, media_type, container_lower, codec_vector)) { | |
| 157 return false; | |
| 158 } | |
| 159 | |
| 160 // Check that |container_mime_type| is supported by Chrome. This can only | |
| 161 // happen if the CDM declares support for a container that Chrome does not. | |
| 162 if (!net::IsSupportedMediaMimeType(container_lower)) { | |
| 163 NOTREACHED(); | |
| 164 return false; | |
| 165 } | |
| 166 | |
| 167 // Check that |codecs| are supported by Chrome. This is done primarily to | |
| 168 // validate extended codecs, but it also ensures that the CDM cannot support | |
| 169 // codecs that Chrome does not (which could complicate the robustness | |
| 170 // algorithm). | |
| 171 if (codec_vector.empty()) | |
| 172 return true; | |
| 173 codec_vector.clear(); | |
| 174 net::ParseCodecString(codecs, &codec_vector, false); | |
| 175 return (net::IsSupportedStrictMediaMimeType(container_lower, codec_vector) == | |
| 176 net::IsSupported); | |
| 177 } | |
| 178 | |
| 179 static bool GetSupportedCapabilities( | |
| 180 const KeySystems& key_systems, | |
| 181 const std::string& key_system, | |
| 182 EmeMediaType media_type, | |
| 183 const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& | |
| 184 requested_media_capabilities, | |
| 185 ConfigState* config_state, | |
| 186 std::vector<blink::WebMediaKeySystemMediaCapability>* | |
| 187 supported_media_capabilities) { | |
| 188 // From | |
| 189 // https://w3c.github.io/encrypted-media/#get-supported-capabilities-for-media -type | |
| 190 // 1. Let local accumulated capabilities be a local copy of partial | |
| 191 // configuration. | |
| 192 // (Skipped as we directly update |config_state|. This is safe because we | |
| 193 // only do so when at least one requested media capability is supported.) | |
| 194 // 2. Let supported media capabilities be empty. | |
| 195 DCHECK_EQ(supported_media_capabilities->size(), 0ul); | |
| 196 // 3. For each value in requested media capabilities: | |
| 197 for (size_t i = 0; i < requested_media_capabilities.size(); i++) { | |
| 198 // 3.1. Let contentType be the value's contentType member. | |
| 199 // 3.2. Let robustness be the value's robustness member. | |
| 200 const blink::WebMediaKeySystemMediaCapability& capability = | |
| 201 requested_media_capabilities[i]; | |
| 202 // 3.3. If contentType is the empty string, return null. | |
| 203 if (capability.mimeType.isEmpty()) { | |
| 204 DVLOG(2) << "Rejecting requested configuration because " | |
| 205 << "a capability contentType was empty."; | |
| 206 return false; | |
| 207 } | |
| 208 // 3.4-3.11. (Implemented by IsSupportedContentType().) | |
| 209 if (!base::IsStringASCII(capability.mimeType) || | |
| 210 !base::IsStringASCII(capability.codecs) || | |
| 211 !IsSupportedContentType(key_systems, key_system, media_type, | |
| 212 base::UTF16ToASCII(capability.mimeType), | |
| 213 base::UTF16ToASCII(capability.codecs))) { | |
| 214 continue; | |
| 215 } | |
| 216 // 3.12. If robustness is not the empty string, run the following steps: | |
| 217 if (!capability.robustness.isEmpty()) { | |
| 218 // 3.12.1. If robustness is an unrecognized value or not supported by | |
| 219 // implementation, continue to the next iteration. String | |
| 220 // comparison is case-sensitive. | |
| 221 if (!base::IsStringASCII(capability.robustness)) | |
| 222 continue; | |
| 223 EmeConfigRule robustness_rule = key_systems.GetRobustnessConfigRule( | |
| 224 key_system, media_type, base::UTF16ToASCII(capability.robustness)); | |
| 225 if (!config_state->IsRuleSupported(robustness_rule)) | |
| 226 continue; | |
| 227 config_state->AddRule(robustness_rule); | |
| 228 // 3.12.2. Add robustness to configuration. | |
| 229 // (It's already added, we use capability as configuration.) | |
| 230 } | |
| 231 // 3.13. If the user agent and implementation do not support playback of | |
| 232 // encrypted media data as specified by configuration, including all | |
| 233 // media types, in combination with local accumulated capabilities, | |
| 234 // continue to the next iteration. | |
| 235 // (This is handled when adding rules to |config_state|.) | |
| 236 // 3.14. Add configuration to supported media capabilities. | |
| 237 supported_media_capabilities->push_back(capability); | |
| 238 // 3.15. Add configuration to local accumulated capabilities. | |
| 239 // (Skipped as we directly update |config_state|.) | |
| 240 } | |
| 241 // 4. If supported media capabilities is empty, return null. | |
| 242 if (supported_media_capabilities->empty()) { | |
| 243 DVLOG(2) << "Rejecting requested configuration because " | |
| 244 << "no capabilities were supported."; | |
| 245 return false; | |
| 246 } | |
| 247 // 5. Return media type capabilities. | |
| 248 return true; | |
| 249 } | |
| 250 | |
| 251 static EmeFeatureRequirement ConvertRequirement( | |
| 252 blink::WebMediaKeySystemConfiguration::Requirement requirement) { | |
| 253 switch (requirement) { | |
| 254 case blink::WebMediaKeySystemConfiguration::Requirement::Required: | |
| 255 return EME_FEATURE_REQUIRED; | |
| 256 case blink::WebMediaKeySystemConfiguration::Requirement::Optional: | |
| 257 return EME_FEATURE_OPTIONAL; | |
| 258 case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: | |
| 259 return EME_FEATURE_NOT_ALLOWED; | |
| 260 } | |
| 261 | |
| 262 NOTREACHED(); | |
| 263 return EME_FEATURE_NOT_ALLOWED; | |
| 264 } | |
| 265 | |
| 266 static ConfigurationSupport GetSupportedConfiguration( | |
| 267 const KeySystems& key_systems, | |
| 268 const std::string& key_system, | |
| 269 const blink::WebMediaKeySystemConfiguration& candidate, | |
| 270 bool was_permission_requested, | |
| 271 bool is_permission_granted, | |
| 272 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { | |
| 273 ConfigState config_state(was_permission_requested, is_permission_granted); | |
| 274 | |
| 275 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | |
| 276 // 1. Let accumulated configuration be empty. (Done by caller.) | |
| 277 // 2. If the initDataTypes member is present in candidate configuration, run | |
| 278 // the following steps: | |
| 279 if (candidate.hasInitDataTypes) { | |
| 280 // 2.1. Let supported types be empty. | |
| 281 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; | |
| 282 | |
| 283 // 2.2. For each value in candidate configuration's initDataTypes member: | |
| 284 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { | |
| 285 // 2.2.1. Let initDataType be the value. | |
| 286 blink::WebEncryptedMediaInitDataType init_data_type = | |
| 287 candidate.initDataTypes[i]; | |
| 288 // 2.2.2. If the implementation supports generating requests based on | |
| 289 // initDataType, add initDataType to supported types. String | |
| 290 // comparison is case-sensitive. The empty string is never | |
| 291 // supported. | |
| 292 if (init_data_type == blink::WebEncryptedMediaInitDataType::Unknown) | |
| 293 continue; | |
| 294 if (key_systems.IsSupportedInitDataType( | |
| 295 key_system, ConvertToEmeInitDataType(init_data_type))) { | |
| 296 supported_types.push_back(init_data_type); | |
| 297 } | |
| 298 } | |
| 299 | |
| 300 // 2.3. If supported types is empty, return null. | |
| 301 if (supported_types.empty()) { | |
| 302 DVLOG(2) << "Rejecting requested configuration because " | |
| 303 << "no initDataType values were supported."; | |
| 304 return CONFIGURATION_NOT_SUPPORTED; | |
| 305 } | |
| 306 | |
| 307 // 2.4. Add supported types to accumulated configuration. | |
| 308 accumulated_configuration->initDataTypes = supported_types; | |
| 309 } | |
| 310 | |
| 311 // 3. Follow the steps for the value of candidate configuration's | |
| 312 // distinctiveIdentifier member from the following list: | |
| 313 // - "required": If the implementation does not support a persistent | |
| 314 // Distinctive Identifier in combination with accumulated | |
| 315 // configuration, return null. | |
| 316 // - "optional": Continue. | |
| 317 // - "not-allowed": If the implementation requires a Distinctive | |
| 318 // Identifier in combination with accumulated configuration, return | |
| 319 // null. | |
| 320 // We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and | |
| 321 // permission has already been denied. This would happen anyway at step 11. | |
| 322 EmeConfigRule di_rule = key_systems.GetDistinctiveIdentifierConfigRule( | |
| 323 key_system, ConvertRequirement(candidate.distinctiveIdentifier)); | |
| 324 if (!config_state.IsRuleSupported(di_rule)) { | |
| 325 DVLOG(2) << "Rejecting requested configuration because " | |
| 326 << "the distinctiveIdentifier requirement was not supported."; | |
| 327 return CONFIGURATION_NOT_SUPPORTED; | |
| 328 } | |
| 329 config_state.AddRule(di_rule); | |
| 330 | |
| 331 // 4. Add the value of the candidate configuration's distinctiveIdentifier | |
| 332 // member to accumulated configuration. | |
| 333 accumulated_configuration->distinctiveIdentifier = | |
| 334 candidate.distinctiveIdentifier; | |
| 335 | |
| 336 // 5. Follow the steps for the value of candidate configuration's | |
| 337 // persistentState member from the following list: | |
| 338 // - "required": If the implementation does not support persisting state | |
| 339 // in combination with accumulated configuration, return null. | |
| 340 // - "optional": Continue. | |
| 341 // - "not-allowed": If the implementation requires persisting state in | |
| 342 // combination with accumulated configuration, return null. | |
| 343 EmeConfigRule ps_rule = key_systems.GetPersistentStateConfigRule( | |
| 344 key_system, ConvertRequirement(candidate.persistentState)); | |
| 345 if (!config_state.IsRuleSupported(ps_rule)) { | |
| 346 DVLOG(2) << "Rejecting requested configuration because " | |
| 347 << "the persistentState requirement was not supported."; | |
| 348 return CONFIGURATION_NOT_SUPPORTED; | |
| 349 } | |
| 350 config_state.AddRule(ps_rule); | |
| 351 | |
| 352 // 6. Add the value of the candidate configuration's persistentState | |
| 353 // member to accumulated configuration. | |
| 354 accumulated_configuration->persistentState = candidate.persistentState; | |
| 355 | |
| 356 // 7. Follow the steps for the first matching condition from the following | |
| 357 // list: | |
| 358 // - If the sessionTypes member is present in candidate configuration, | |
| 359 // let session types be candidate configuration's sessionTypes member. | |
| 360 // - Otherwise, let session types be [ "temporary" ]. | |
| 361 blink::WebVector<blink::WebEncryptedMediaSessionType> session_types; | |
| 362 if (candidate.hasSessionTypes) { | |
| 363 session_types = candidate.sessionTypes; | |
| 364 } else { | |
| 365 std::vector<blink::WebEncryptedMediaSessionType> temporary(1); | |
| 366 temporary[0] = blink::WebEncryptedMediaSessionType::Temporary; | |
| 367 session_types = temporary; | |
| 368 } | |
| 369 | |
| 370 // 8. For each value in session types: | |
| 371 for (size_t i = 0; i < session_types.size(); i++) { | |
| 372 // 8.1. Let session type be the value. | |
| 373 blink::WebEncryptedMediaSessionType session_type = session_types[i]; | |
| 374 // 8.2. If the implementation does not support session type in combination | |
| 375 // with accumulated configuration, return null. | |
| 376 // 8.3. If session type is "persistent-license" or | |
| 377 // "persistent-release-message", follow the steps for accumulated | |
| 378 // configuration's persistentState value from the following list: | |
| 379 // - "required": Continue. | |
| 380 // - "optional": Change accumulated configuration's persistentState | |
| 381 // value to "required". | |
| 382 // - "not-allowed": Return null. | |
| 383 EmeConfigRule session_type_rule = EmeConfigRule::NOT_SUPPORTED; | |
| 384 switch (session_type) { | |
| 385 case blink::WebEncryptedMediaSessionType::Unknown: | |
| 386 DVLOG(2) << "Rejecting requested configuration because " | |
| 387 << "a required session type was not recognized."; | |
| 388 return CONFIGURATION_NOT_SUPPORTED; | |
| 389 case blink::WebEncryptedMediaSessionType::Temporary: | |
| 390 session_type_rule = EmeConfigRule::SUPPORTED; | |
| 391 break; | |
| 392 case blink::WebEncryptedMediaSessionType::PersistentLicense: | |
| 393 session_type_rule = | |
| 394 key_systems.GetPersistentLicenseSessionConfigRule(key_system); | |
| 395 break; | |
| 396 case blink::WebEncryptedMediaSessionType::PersistentReleaseMessage: | |
| 397 session_type_rule = | |
| 398 key_systems.GetPersistentReleaseMessageSessionConfigRule( | |
| 399 key_system); | |
| 400 break; | |
| 401 } | |
| 402 if (!config_state.IsRuleSupported(session_type_rule)) { | |
| 403 DVLOG(2) << "Rejecting requested configuration because " | |
| 404 << "a required session type was not supported."; | |
| 405 return CONFIGURATION_NOT_SUPPORTED; | |
| 406 } | |
| 407 config_state.AddRule(session_type_rule); | |
| 408 } | |
| 409 | |
| 410 // 9. Add session types to accumulated configuration. | |
| 411 accumulated_configuration->sessionTypes = session_types; | |
| 412 | |
| 413 // 10. If the videoCapabilities member is present in candidate configuration: | |
| 414 if (candidate.hasVideoCapabilities) { | |
| 415 // 10.1. Let video capabilities be the result of executing the Get Supported | |
| 416 // Capabilities for Media Type algorithm on Video, candidate | |
| 417 // configuration's videoCapabilities member, and accumulated | |
| 418 // configuration. | |
| 419 // 10.2. If video capabilities is null, return null. | |
| 420 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; | |
| 421 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::VIDEO, | |
| 422 candidate.videoCapabilities, | |
| 423 &config_state, &video_capabilities)) { | |
| 424 return CONFIGURATION_NOT_SUPPORTED; | |
| 425 } | |
| 426 | |
| 427 // 10.3. Add video capabilities to accumulated configuration. | |
| 428 accumulated_configuration->videoCapabilities = video_capabilities; | |
| 429 } | |
| 430 | |
| 431 // 11. If the audioCapabilities member is present in candidate configuration: | |
| 432 if (candidate.hasAudioCapabilities) { | |
| 433 // 11.1. Let audio capabilities be the result of executing the Get Supported | |
| 434 // Capabilities for Media Type algorithm on Audio, candidate | |
| 435 // configuration's audioCapabilities member, and accumulated | |
| 436 // configuration. | |
| 437 // 11.2. If audio capabilities is null, return null. | |
| 438 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; | |
| 439 if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::AUDIO, | |
| 440 candidate.audioCapabilities, | |
| 441 &config_state, &audio_capabilities)) { | |
| 442 return CONFIGURATION_NOT_SUPPORTED; | |
| 443 } | |
| 444 | |
| 445 // 11.3. Add audio capabilities to accumulated configuration. | |
| 446 accumulated_configuration->audioCapabilities = audio_capabilities; | |
| 447 } | |
| 448 | |
| 449 // 12. If accumulated configuration's distinctiveIdentifier value is | |
| 450 // "optional", follow the steps for the first matching condition from the | |
| 451 // following list: | |
| 452 // - If the implementation requires a Distinctive Identifier for any of | |
| 453 // the combinations in accumulated configuration, change accumulated | |
| 454 // configuration's distinctiveIdentifier value to "required". | |
| 455 // - Otherwise, change accumulated configuration's distinctiveIdentifier | |
| 456 // value to "not-allowed". | |
| 457 if (accumulated_configuration->distinctiveIdentifier == | |
| 458 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | |
| 459 EmeConfigRule not_allowed_rule = | |
| 460 key_systems.GetDistinctiveIdentifierConfigRule( | |
| 461 key_system, EME_FEATURE_NOT_ALLOWED); | |
| 462 EmeConfigRule required_rule = | |
| 463 key_systems.GetDistinctiveIdentifierConfigRule( | |
| 464 key_system, EME_FEATURE_REQUIRED); | |
| 465 bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); | |
| 466 bool required_supported = config_state.IsRuleSupported(required_rule); | |
| 467 // If a distinctive identifier is recommend and that is a possible outcome, | |
| 468 // prefer that. | |
| 469 if (required_supported && | |
| 470 config_state.IsIdentifierRecommended() && | |
| 471 config_state.IsPermissionPossible()) { | |
| 472 not_allowed_supported = false; | |
| 473 } | |
| 474 if (not_allowed_supported) { | |
| 475 accumulated_configuration->distinctiveIdentifier = | |
| 476 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
| 477 config_state.AddRule(not_allowed_rule); | |
| 478 } else if (required_supported) { | |
| 479 accumulated_configuration->distinctiveIdentifier = | |
| 480 blink::WebMediaKeySystemConfiguration::Requirement::Required; | |
| 481 config_state.AddRule(required_rule); | |
| 482 } else { | |
| 483 // We should not have passed step 3. | |
| 484 NOTREACHED(); | |
| 485 return CONFIGURATION_NOT_SUPPORTED; | |
| 486 } | |
| 487 } | |
| 488 | |
| 489 // 13. If accumulated configuration's persistentState value is "optional", | |
| 490 // follow the steps for the first matching condition from the following | |
| 491 // list: | |
| 492 // - If the implementation requires persisting state for any of the | |
| 493 // combinations in accumulated configuration, change accumulated | |
| 494 // configuration's persistentState value to "required". | |
| 495 // - Otherwise, change accumulated configuration's persistentState value | |
| 496 // to "not-allowed". | |
| 497 if (accumulated_configuration->persistentState == | |
| 498 blink::WebMediaKeySystemConfiguration::Requirement::Optional) { | |
| 499 EmeConfigRule not_allowed_rule = | |
| 500 key_systems.GetPersistentStateConfigRule( | |
| 501 key_system, EME_FEATURE_NOT_ALLOWED); | |
| 502 EmeConfigRule required_rule = | |
| 503 key_systems.GetPersistentStateConfigRule( | |
| 504 key_system, EME_FEATURE_REQUIRED); | |
| 505 // |distinctiveIdentifier| should not be affected after it is decided. | |
| 506 DCHECK(not_allowed_rule == EmeConfigRule::NOT_SUPPORTED || | |
| 507 not_allowed_rule == EmeConfigRule::PERSISTENCE_NOT_ALLOWED); | |
| 508 DCHECK(required_rule == EmeConfigRule::NOT_SUPPORTED || | |
| 509 required_rule == EmeConfigRule::PERSISTENCE_REQUIRED); | |
| 510 bool not_allowed_supported = | |
| 511 config_state.IsRuleSupported(not_allowed_rule); | |
| 512 bool required_supported = | |
| 513 config_state.IsRuleSupported(required_rule); | |
| 514 if (not_allowed_supported) { | |
| 515 accumulated_configuration->persistentState = | |
| 516 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; | |
| 517 config_state.AddRule(not_allowed_rule); | |
| 518 } else if (required_supported) { | |
| 519 accumulated_configuration->persistentState = | |
| 520 blink::WebMediaKeySystemConfiguration::Requirement::Required; | |
| 521 config_state.AddRule(required_rule); | |
| 522 } else { | |
| 523 // We should not have passed step 5. | |
| 524 NOTREACHED(); | |
| 525 return CONFIGURATION_NOT_SUPPORTED; | |
| 526 } | |
| 527 } | |
| 528 | |
| 529 // 14. If implementation in the configuration specified by the combination of | |
| 530 // the values in accumulated configuration is not supported or not allowed | |
| 531 // in the origin, return null. | |
| 532 // 15. If accumulated configuration's distinctiveIdentifier value is | |
| 533 // "required", [prompt the user for consent]. | |
| 534 if (accumulated_configuration->distinctiveIdentifier == | |
| 535 blink::WebMediaKeySystemConfiguration::Requirement::Required) { | |
| 536 // The caller is responsible for resolving what to do if permission is | |
| 537 // required but has been denied (it should treat it as NOT_SUPPORTED). | |
| 538 if (!config_state.IsPermissionGranted()) | |
| 539 return CONFIGURATION_REQUIRES_PERMISSION; | |
| 540 } | |
| 541 | |
| 542 // 16. If the label member is present in candidate configuration, add the | |
| 543 // value of the candidate configuration's label member to accumulated | |
| 544 // configuration. | |
| 545 accumulated_configuration->label = candidate.label; | |
| 546 | |
| 547 // 17. Return accumulated configuration. | |
| 548 return CONFIGURATION_SUPPORTED; | |
| 549 } | |
| 550 | 29 |
| 551 // Report usage of key system to UMA. There are 2 different counts logged: | 30 // Report usage of key system to UMA. There are 2 different counts logged: |
| 552 // 1. The key system is requested. | 31 // 1. The key system is requested. |
| 553 // 2. The requested key system and options are supported. | 32 // 2. The requested key system and options are supported. |
| 554 // Each stat is only reported once per renderer frame per key system. | 33 // Each stat is only reported once per renderer frame per key system. |
| 555 // Note that WebEncryptedMediaClientImpl is only created once by each | 34 // Note that WebEncryptedMediaClientImpl is only created once by each |
| 556 // renderer frame. | 35 // renderer frame. |
| 557 class WebEncryptedMediaClientImpl::Reporter { | 36 class WebEncryptedMediaClientImpl::Reporter { |
| 558 public: | 37 public: |
| 559 enum KeySystemSupportStatus { | 38 enum KeySystemSupportStatus { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 } | 73 } |
| 595 | 74 |
| 596 const std::string uma_name_; | 75 const std::string uma_name_; |
| 597 bool is_request_reported_; | 76 bool is_request_reported_; |
| 598 bool is_support_reported_; | 77 bool is_support_reported_; |
| 599 }; | 78 }; |
| 600 | 79 |
| 601 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( | 80 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( |
| 602 CdmFactory* cdm_factory, | 81 CdmFactory* cdm_factory, |
| 603 MediaPermission* media_permission) | 82 MediaPermission* media_permission) |
| 604 : key_systems_(KeySystems::GetInstance()), | 83 : cdm_factory_(cdm_factory), |
| 605 cdm_factory_(cdm_factory), | 84 key_system_config_selector_(&KeySystems::GetInstance(), media_permission), |
| 606 media_permission_(media_permission), | |
| 607 weak_factory_(this) { | 85 weak_factory_(this) { |
| 608 DCHECK(media_permission); | 86 DCHECK(cdm_factory_); |
| 609 } | 87 } |
| 610 | 88 |
| 611 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { | 89 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { |
| 612 } | 90 } |
| 613 | 91 |
| 614 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( | 92 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
| 615 blink::WebEncryptedMediaRequest request) { | 93 blink::WebEncryptedMediaRequest request) { |
| 616 // TODO(jrummell): This should be asynchronous, ideally not on the main | 94 GetReporter(request.keySystem())->ReportRequested(); |
| 617 // thread. | 95 key_system_config_selector_.SelectConfig( |
| 618 | 96 request.keySystem(), |
| 619 // Continued from requestMediaKeySystemAccess(), step 7, from | 97 request.supportedConfigurations(), |
| 620 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | 98 request.securityOrigin(), |
| 621 // | 99 base::Bind(&WebEncryptedMediaClientImpl::OnRequestSucceeded, |
| 622 // 7.1. If keySystem is not one of the Key Systems supported by the user | 100 weak_factory_.GetWeakPtr(), request), |
| 623 // agent, reject promise with with a new DOMException whose name is | 101 base::Bind(&WebEncryptedMediaClientImpl::OnRequestNotSupported, |
| 624 // NotSupportedError. String comparison is case-sensitive. | 102 weak_factory_.GetWeakPtr(), request)); |
| 625 if (!base::IsStringASCII(request.keySystem())) { | |
| 626 request.requestNotSupported("Only ASCII keySystems are supported"); | |
| 627 return; | |
| 628 } | |
| 629 | |
| 630 // Report this request to the UMA. | |
| 631 std::string key_system = base::UTF16ToASCII(request.keySystem()); | |
| 632 GetReporter(key_system)->ReportRequested(); | |
| 633 | |
| 634 if (!key_systems_.IsSupportedKeySystem(key_system)) { | |
| 635 request.requestNotSupported("Unsupported keySystem"); | |
| 636 return; | |
| 637 } | |
| 638 | |
| 639 // 7.2-7.4. Implemented by SelectSupportedConfiguration(). | |
| 640 SelectSupportedConfiguration(request, false, false); | |
| 641 } | |
| 642 | |
| 643 void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( | |
| 644 blink::WebEncryptedMediaRequest request, | |
| 645 bool was_permission_requested, | |
| 646 bool is_permission_granted) { | |
| 647 // Continued from requestMediaKeySystemAccess(), step 7.1, from | |
| 648 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | |
| 649 // | |
| 650 // 7.2. Let implementation be the implementation of keySystem. | |
| 651 std::string key_system = base::UTF16ToASCII(request.keySystem()); | |
| 652 | |
| 653 // 7.3. For each value in supportedConfigurations: | |
| 654 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& | |
| 655 configurations = request.supportedConfigurations(); | |
| 656 for (size_t i = 0; i < configurations.size(); i++) { | |
| 657 // 7.3.1. Let candidate configuration be the value. | |
| 658 const blink::WebMediaKeySystemConfiguration& candidate_configuration = | |
| 659 configurations[i]; | |
| 660 // 7.3.2. Let supported configuration be the result of executing the Get | |
| 661 // Supported Configuration algorithm on implementation, candidate | |
| 662 // configuration, and origin. | |
| 663 // 7.3.3. If supported configuration is not null, [initialize and return a | |
| 664 // new MediaKeySystemAccess object.] | |
| 665 blink::WebMediaKeySystemConfiguration accumulated_configuration; | |
| 666 ConfigurationSupport supported = GetSupportedConfiguration( | |
| 667 key_systems_, key_system, candidate_configuration, | |
| 668 was_permission_requested, is_permission_granted, | |
| 669 &accumulated_configuration); | |
| 670 switch (supported) { | |
| 671 case CONFIGURATION_NOT_SUPPORTED: | |
| 672 continue; | |
| 673 case CONFIGURATION_REQUIRES_PERMISSION: | |
| 674 if (was_permission_requested) { | |
| 675 DVLOG(2) << "Rejecting requested configuration because " | |
| 676 << "permission was denied."; | |
| 677 continue; | |
| 678 } | |
| 679 media_permission_->RequestPermission( | |
| 680 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, | |
| 681 GURL(request.securityOrigin().toString()), | |
| 682 // Try again with |was_permission_requested| true and | |
| 683 // |is_permission_granted| the value of the permission. | |
| 684 base::Bind( | |
| 685 &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, | |
| 686 weak_factory_.GetWeakPtr(), request, true)); | |
| 687 return; | |
| 688 case CONFIGURATION_SUPPORTED: | |
| 689 // Report that this request succeeded to the UMA. | |
| 690 GetReporter(key_system)->ReportSupported(); | |
| 691 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | |
| 692 request.keySystem(), accumulated_configuration, | |
| 693 request.securityOrigin(), weak_factory_.GetWeakPtr())); | |
| 694 return; | |
| 695 } | |
| 696 } | |
| 697 | |
| 698 // 7.4. Reject promise with a new DOMException whose name is | |
| 699 // NotSupportedError. | |
| 700 request.requestNotSupported( | |
| 701 "None of the requested configurations were supported."); | |
| 702 } | 103 } |
| 703 | 104 |
| 704 void WebEncryptedMediaClientImpl::CreateCdm( | 105 void WebEncryptedMediaClientImpl::CreateCdm( |
| 705 const blink::WebString& key_system, | 106 const blink::WebString& key_system, |
| 706 bool allow_distinctive_identifier, | 107 bool allow_distinctive_identifier, |
| 707 bool allow_persistent_state, | 108 bool allow_persistent_state, |
| 708 const blink::WebSecurityOrigin& security_origin, | 109 const blink::WebSecurityOrigin& security_origin, |
| 709 blink::WebContentDecryptionModuleResult result) { | 110 blink::WebContentDecryptionModuleResult result) { |
| 710 WebContentDecryptionModuleImpl::Create( | 111 WebContentDecryptionModuleImpl::Create( |
| 711 cdm_factory_, key_system, allow_distinctive_identifier, | 112 cdm_factory_, key_system, allow_distinctive_identifier, |
| 712 allow_persistent_state, security_origin, result); | 113 allow_persistent_state, security_origin, result); |
| 713 } | 114 } |
| 714 | 115 |
| 715 // Lazily create Reporters. | 116 void WebEncryptedMediaClientImpl::OnRequestSucceeded( |
| 117 blink::WebEncryptedMediaRequest request, | |
| 118 const blink::WebMediaKeySystemConfiguration& accumulated_configuration) { | |
| 119 GetReporter(request.keySystem())->ReportSupported(); | |
| 120 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | |
| 121 request.keySystem(), accumulated_configuration, request.securityOrigin(), | |
| 122 weak_factory_.GetWeakPtr())); | |
| 123 } | |
| 124 | |
| 125 void WebEncryptedMediaClientImpl::OnRequestNotSupported( | |
| 126 blink::WebEncryptedMediaRequest request, | |
| 127 const blink::WebString& error_message) { | |
| 128 request.requestNotSupported(error_message); | |
| 129 } | |
| 130 | |
| 716 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( | 131 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( |
| 717 const std::string& key_system) { | 132 const blink::WebString& key_system) { |
| 718 std::string uma_name = GetKeySystemNameForUMA(key_system); | 133 // Assumes that empty will not be found by GetKeySystemNameForUMA(). |
| 134 // TODO(sandersd): Avoid doing ASCII conversion more than once. | |
|
ddorwin
2015/04/03 22:09:18
+1
Is there a reason the Selector does not accept
sandersd (OOO until July 31)
2015/04/03 22:44:57
Only because there was nowhere to store the conver
| |
| 135 std::string key_system_ascii; | |
| 136 if (base::IsStringASCII(key_system)) | |
| 137 key_system_ascii = base::UTF16ToASCII(key_system); | |
| 138 | |
| 139 // Return a singleton so that UMA reports will be once-per-frame. | |
|
ddorwin
2015/04/03 22:09:18
per frame or per process?
sandersd (OOO until July 31)
2015/04/03 22:44:57
Done.
| |
| 140 std::string uma_name = GetKeySystemNameForUMA(key_system_ascii); | |
| 719 Reporter* reporter = reporters_.get(uma_name); | 141 Reporter* reporter = reporters_.get(uma_name); |
| 720 if (reporter != nullptr) | 142 if (!reporter) { |
| 721 return reporter; | 143 reporter = new Reporter(uma_name); |
| 722 | 144 reporters_.add(uma_name, make_scoped_ptr(reporter)); |
| 723 // Reporter not found, so create one. | 145 } |
| 724 auto result = | 146 return reporter; |
| 725 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | |
| 726 DCHECK(result.second); | |
| 727 return result.first->second; | |
| 728 } | 147 } |
| 729 | 148 |
| 730 } // namespace media | 149 } // namespace media |
| OLD | NEW |