| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/base/key_systems.h" | 5 #include "media/base/key_systems.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "media/base/key_system_names.h" | 19 #include "media/base/key_system_names.h" |
| 20 #include "media/base/key_system_properties.h" | 20 #include "media/base/key_system_properties.h" |
| 21 #include "media/base/media.h" | 21 #include "media/base/media.h" |
| 22 #include "media/base/media_switches.h" |
| 22 #include "ppapi/features/features.h" | 23 #include "ppapi/features/features.h" |
| 23 #include "media/base/media_client.h" | 24 #include "media/base/media_client.h" |
| 24 #include "third_party/widevine/cdm/widevine_cdm_common.h" | 25 #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 25 | 26 |
| 26 namespace media { | 27 namespace media { |
| 27 | 28 |
| 28 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 29 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
| 29 | 30 |
| 30 // These names are used by UMA. Do not change them! | 31 // These names are used by UMA. Do not change them! |
| 31 const char kClearKeyKeySystemNameForUMA[] = "ClearKey"; | 32 const char kClearKeyKeySystemNameForUMA[] = "ClearKey"; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // Add key systems supported by the MediaClient implementation. | 345 // Add key systems supported by the MediaClient implementation. |
| 345 if (GetMediaClient()) | 346 if (GetMediaClient()) |
| 346 GetMediaClient()->AddSupportedKeySystems(&key_systems_properties); | 347 GetMediaClient()->AddSupportedKeySystems(&key_systems_properties); |
| 347 | 348 |
| 348 // Clear Key is always supported. | 349 // Clear Key is always supported. |
| 349 key_systems_properties.emplace_back(new ClearKeyProperties()); | 350 key_systems_properties.emplace_back(new ClearKeyProperties()); |
| 350 | 351 |
| 351 AddSupportedKeySystems(&key_systems_properties); | 352 AddSupportedKeySystems(&key_systems_properties); |
| 352 } | 353 } |
| 353 | 354 |
| 355 // Returns whether distinctive identifiers and persistent state can be reliably |
| 356 // blocked for |properties| (and therefore be safely configurable). |
| 357 static bool CanBlock(const KeySystemProperties& properties) { |
| 358 #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
| 359 // Distinctive identifiers and persistent state can be reliably blocked for |
| 360 // Pepper-hosted key systems. |
| 361 DCHECK_EQ(properties.UseAesDecryptor(), properties.GetPepperType().empty()); |
| 362 if (!properties.GetPepperType().empty()) |
| 363 return true; |
| 364 #endif |
| 365 |
| 366 // When AesDecryptor is used, we are sure we can block. |
| 367 if (properties.UseAesDecryptor()) |
| 368 return true; |
| 369 |
| 370 // For External Clear Key, it is either implemented as a pepper CDM (Clear Key |
| 371 // CDM), which is covered above, or by using AesDecryptor remotely, e.g. via |
| 372 // MojoCdm. In both cases, we can block. This is only used for testing. |
| 373 if (base::FeatureList::IsEnabled(media::kExternalClearKeyForTesting) && |
| 374 IsExternalClearKey(properties.GetKeySystemName())) |
| 375 return true; |
| 376 |
| 377 // For other platforms assume the CDM can and will do anything. So we cannot |
| 378 // block. |
| 379 return false; |
| 380 } |
| 381 |
| 354 void KeySystemsImpl::AddSupportedKeySystems( | 382 void KeySystemsImpl::AddSupportedKeySystems( |
| 355 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) { | 383 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) { |
| 356 DCHECK(thread_checker_.CalledOnValidThread()); | 384 DCHECK(thread_checker_.CalledOnValidThread()); |
| 357 DCHECK(key_system_properties_map_.empty()); | 385 DCHECK(key_system_properties_map_.empty()); |
| 358 | 386 |
| 359 for (auto& properties : *key_systems) { | 387 for (auto& properties : *key_systems) { |
| 360 DCHECK(!properties->GetKeySystemName().empty()); | 388 DCHECK(!properties->GetKeySystemName().empty()); |
| 361 DCHECK(properties->GetPersistentLicenseSessionSupport() != | 389 DCHECK(properties->GetPersistentLicenseSessionSupport() != |
| 362 EmeSessionTypeSupport::INVALID); | 390 EmeSessionTypeSupport::INVALID); |
| 363 DCHECK(properties->GetPersistentReleaseMessageSessionSupport() != | 391 DCHECK(properties->GetPersistentReleaseMessageSessionSupport() != |
| (...skipping 28 matching lines...) Expand all Loading... |
| 392 // If distinctive identifiers are not supported, then no other features can | 420 // If distinctive identifiers are not supported, then no other features can |
| 393 // require them. | 421 // require them. |
| 394 if (properties->GetDistinctiveIdentifierSupport() == | 422 if (properties->GetDistinctiveIdentifierSupport() == |
| 395 EmeFeatureSupport::NOT_SUPPORTED) { | 423 EmeFeatureSupport::NOT_SUPPORTED) { |
| 396 DCHECK(properties->GetPersistentLicenseSessionSupport() != | 424 DCHECK(properties->GetPersistentLicenseSessionSupport() != |
| 397 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER); | 425 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER); |
| 398 DCHECK(properties->GetPersistentReleaseMessageSessionSupport() != | 426 DCHECK(properties->GetPersistentReleaseMessageSessionSupport() != |
| 399 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER); | 427 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER); |
| 400 } | 428 } |
| 401 | 429 |
| 402 // Distinctive identifiers and persistent state can only be reliably blocked | 430 if (!CanBlock(*properties)) { |
| 403 // (and therefore be safely configurable) for Pepper-hosted key systems. For | |
| 404 // other platforms assume the CDM can and will do anything, except for the | |
| 405 // following two cases: | |
| 406 // 1) AES decryptor, and | |
| 407 // 2) External Clear Key key system on Android, only enabled for testing. | |
| 408 bool can_block = properties->UseAesDecryptor(); | |
| 409 #if BUILDFLAG(ENABLE_PEPPER_CDMS) | |
| 410 DCHECK_EQ(properties->UseAesDecryptor(), | |
| 411 properties->GetPepperType().empty()); | |
| 412 if (!properties->GetPepperType().empty()) | |
| 413 can_block = true; | |
| 414 #elif defined(OS_ANDROID) | |
| 415 if (IsExternalClearKey(properties->GetKeySystemName())) | |
| 416 can_block = true; | |
| 417 #endif | |
| 418 if (!can_block) { | |
| 419 DCHECK(properties->GetDistinctiveIdentifierSupport() == | 431 DCHECK(properties->GetDistinctiveIdentifierSupport() == |
| 420 EmeFeatureSupport::ALWAYS_ENABLED); | 432 EmeFeatureSupport::ALWAYS_ENABLED); |
| 421 DCHECK(properties->GetPersistentStateSupport() == | 433 DCHECK(properties->GetPersistentStateSupport() == |
| 422 EmeFeatureSupport::ALWAYS_ENABLED); | 434 EmeFeatureSupport::ALWAYS_ENABLED); |
| 423 } | 435 } |
| 424 | 436 |
| 425 DCHECK_EQ(key_system_properties_map_.count(properties->GetKeySystemName()), | 437 DCHECK_EQ(key_system_properties_map_.count(properties->GetKeySystemName()), |
| 426 0u) | 438 0u) |
| 427 << "Key system '" << properties->GetKeySystemName() | 439 << "Key system '" << properties->GetKeySystemName() |
| 428 << "' already registered"; | 440 << "' already registered"; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 uint32_t mask) { | 735 uint32_t mask) { |
| 724 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); | 736 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
| 725 } | 737 } |
| 726 | 738 |
| 727 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, | 739 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, |
| 728 uint32_t mask) { | 740 uint32_t mask) { |
| 729 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); | 741 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); |
| 730 } | 742 } |
| 731 | 743 |
| 732 } // namespace media | 744 } // namespace media |
| OLD | NEW |