| 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 "chrome/renderer/media/chrome_key_systems.h" | 5 #include "chrome/renderer/media/chrome_key_systems.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "components/cdm/renderer/external_clear_key_key_system_properties.h" |
| 18 #include "components/cdm/renderer/widevine_key_system_properties.h" | 19 #include "components/cdm/renderer/widevine_key_system_properties.h" |
| 19 #include "content/public/renderer/render_thread.h" | 20 #include "content/public/renderer/render_thread.h" |
| 20 #include "media/base/eme_constants.h" | 21 #include "media/base/eme_constants.h" |
| 21 #include "media/base/key_system_properties.h" | 22 #include "media/base/key_system_properties.h" |
| 22 | 23 |
| 23 #if defined(OS_ANDROID) | 24 #if defined(OS_ANDROID) |
| 24 #include "components/cdm/renderer/android_key_systems.h" | 25 #include "components/cdm/renderer/android_key_systems.h" |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 #if defined(ENABLE_PEPPER_CDMS) | 28 #if defined(ENABLE_PEPPER_CDMS) |
| 28 #include "base/feature_list.h" | 29 #include "base/feature_list.h" |
| 29 #include "media/base/media_switches.h" | 30 #include "media/base/media_switches.h" |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 33 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 33 | 34 |
| 34 // The following must be after widevine_cdm_version.h. | 35 // The following must be after widevine_cdm_version.h. |
| 35 | 36 |
| 36 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 37 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 37 #include <gnu/libc-version.h> | 38 #include <gnu/libc-version.h> |
| 38 #include "base/version.h" | 39 #include "base/version.h" |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 using media::KeySystemProperties; | 42 using media::KeySystemProperties; |
| 42 using media::SupportedCodecs; | 43 using media::SupportedCodecs; |
| 43 | 44 |
| 44 #if defined(ENABLE_PEPPER_CDMS) | 45 #if defined(ENABLE_PEPPER_CDMS) |
| 45 static const char kExternalClearKeyPepperType[] = | |
| 46 "application/x-ppapi-clearkey-cdm"; | |
| 47 | |
| 48 static bool IsPepperCdmAvailable( | 46 static bool IsPepperCdmAvailable( |
| 49 const std::string& pepper_type, | 47 const std::string& pepper_type, |
| 50 std::vector<base::string16>* additional_param_names, | 48 std::vector<base::string16>* additional_param_names, |
| 51 std::vector<base::string16>* additional_param_values) { | 49 std::vector<base::string16>* additional_param_values) { |
| 52 bool is_available = false; | 50 bool is_available = false; |
| 53 content::RenderThread::Get()->Send( | 51 content::RenderThread::Get()->Send( |
| 54 new ChromeViewHostMsg_IsInternalPluginAvailableForMimeType( | 52 new ChromeViewHostMsg_IsInternalPluginAvailableForMimeType( |
| 55 pepper_type, | 53 pepper_type, |
| 56 &is_available, | 54 &is_available, |
| 57 additional_param_names, | 55 additional_param_names, |
| 58 additional_param_values)); | 56 additional_param_values)); |
| 59 | 57 |
| 60 return is_available; | 58 return is_available; |
| 61 } | 59 } |
| 62 | 60 |
| 63 // KeySystemProperties implementation for external Clear Key systems. | |
| 64 class ExternalClearKeyProperties : public KeySystemProperties { | |
| 65 public: | |
| 66 explicit ExternalClearKeyProperties(const std::string& key_system_name) | |
| 67 : key_system_name_(key_system_name) {} | |
| 68 | |
| 69 std::string GetKeySystemName() const override { return key_system_name_; } | |
| 70 bool IsSupportedInitDataType( | |
| 71 media::EmeInitDataType init_data_type) const override { | |
| 72 switch (init_data_type) { | |
| 73 case media::EmeInitDataType::WEBM: | |
| 74 case media::EmeInitDataType::KEYIDS: | |
| 75 return true; | |
| 76 | |
| 77 case media::EmeInitDataType::CENC: | |
| 78 #if defined(USE_PROPRIETARY_CODECS) | |
| 79 return true; | |
| 80 #else | |
| 81 return false; | |
| 82 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 83 | |
| 84 case media::EmeInitDataType::UNKNOWN: | |
| 85 return false; | |
| 86 } | |
| 87 NOTREACHED(); | |
| 88 return false; | |
| 89 } | |
| 90 | |
| 91 SupportedCodecs GetSupportedCodecs() const override { | |
| 92 #if defined(USE_PROPRIETARY_CODECS) | |
| 93 return media::EME_CODEC_MP4_ALL | media::EME_CODEC_WEBM_ALL; | |
| 94 #else | |
| 95 return media::EME_CODEC_WEBM_ALL; | |
| 96 #endif | |
| 97 } | |
| 98 | |
| 99 media::EmeConfigRule GetRobustnessConfigRule( | |
| 100 media::EmeMediaType media_type, | |
| 101 const std::string& requested_robustness) const override { | |
| 102 return requested_robustness.empty() ? media::EmeConfigRule::SUPPORTED | |
| 103 : media::EmeConfigRule::NOT_SUPPORTED; | |
| 104 } | |
| 105 | |
| 106 // Persistent license sessions are faked. | |
| 107 media::EmeSessionTypeSupport GetPersistentLicenseSessionSupport() | |
| 108 const override { | |
| 109 return media::EmeSessionTypeSupport::SUPPORTED; | |
| 110 } | |
| 111 | |
| 112 media::EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport() | |
| 113 const override { | |
| 114 return media::EmeSessionTypeSupport::NOT_SUPPORTED; | |
| 115 } | |
| 116 | |
| 117 media::EmeFeatureSupport GetPersistentStateSupport() const override { | |
| 118 return media::EmeFeatureSupport::REQUESTABLE; | |
| 119 } | |
| 120 | |
| 121 media::EmeFeatureSupport GetDistinctiveIdentifierSupport() const override { | |
| 122 return media::EmeFeatureSupport::NOT_SUPPORTED; | |
| 123 } | |
| 124 | |
| 125 std::string GetPepperType() const override { | |
| 126 return kExternalClearKeyPepperType; | |
| 127 } | |
| 128 | |
| 129 private: | |
| 130 const std::string key_system_name_; | |
| 131 }; | |
| 132 | |
| 133 // External Clear Key (used for testing). | 61 // External Clear Key (used for testing). |
| 134 static void AddExternalClearKey( | 62 static void AddExternalClearKey( |
| 135 std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) { | 63 std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) { |
| 136 static const char kExternalClearKeyKeySystem[] = | 64 static const char kExternalClearKeyKeySystem[] = |
| 137 "org.chromium.externalclearkey"; | 65 "org.chromium.externalclearkey"; |
| 138 static const char kExternalClearKeyDecryptOnlyKeySystem[] = | 66 static const char kExternalClearKeyDecryptOnlyKeySystem[] = |
| 139 "org.chromium.externalclearkey.decryptonly"; | 67 "org.chromium.externalclearkey.decryptonly"; |
| 140 static const char kExternalClearKeyRenewalKeySystem[] = | 68 static const char kExternalClearKeyRenewalKeySystem[] = |
| 141 "org.chromium.externalclearkey.renewal"; | 69 "org.chromium.externalclearkey.renewal"; |
| 142 static const char kExternalClearKeyFileIOTestKeySystem[] = | 70 static const char kExternalClearKeyFileIOTestKeySystem[] = |
| 143 "org.chromium.externalclearkey.fileiotest"; | 71 "org.chromium.externalclearkey.fileiotest"; |
| 144 static const char kExternalClearKeyOutputProtectionTestKeySystem[] = | 72 static const char kExternalClearKeyOutputProtectionTestKeySystem[] = |
| 145 "org.chromium.externalclearkey.outputprotectiontest"; | 73 "org.chromium.externalclearkey.outputprotectiontest"; |
| 146 static const char kExternalClearKeyInitializeFailKeySystem[] = | 74 static const char kExternalClearKeyInitializeFailKeySystem[] = |
| 147 "org.chromium.externalclearkey.initializefail"; | 75 "org.chromium.externalclearkey.initializefail"; |
| 148 static const char kExternalClearKeyCrashKeySystem[] = | 76 static const char kExternalClearKeyCrashKeySystem[] = |
| 149 "org.chromium.externalclearkey.crash"; | 77 "org.chromium.externalclearkey.crash"; |
| 150 | 78 |
| 151 std::vector<base::string16> additional_param_names; | 79 std::vector<base::string16> additional_param_names; |
| 152 std::vector<base::string16> additional_param_values; | 80 std::vector<base::string16> additional_param_values; |
| 153 if (!IsPepperCdmAvailable(kExternalClearKeyPepperType, | 81 if (!IsPepperCdmAvailable(cdm::kExternalClearKeyPepperType, |
| 154 &additional_param_names, | 82 &additional_param_names, |
| 155 &additional_param_values)) { | 83 &additional_param_values)) { |
| 156 return; | 84 return; |
| 157 } | 85 } |
| 158 | 86 |
| 159 concrete_key_systems->emplace_back( | 87 concrete_key_systems->emplace_back( |
| 160 new ExternalClearKeyProperties(kExternalClearKeyKeySystem)); | 88 new cdm::ExternalClearKeyProperties(kExternalClearKeyKeySystem)); |
| 161 | 89 |
| 162 // Add support of decrypt-only mode in ClearKeyCdm. | 90 // Add support of decrypt-only mode in ClearKeyCdm. |
| 163 concrete_key_systems->emplace_back( | 91 concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties( |
| 164 new ExternalClearKeyProperties(kExternalClearKeyDecryptOnlyKeySystem)); | 92 kExternalClearKeyDecryptOnlyKeySystem)); |
| 165 | 93 |
| 166 // A key system that triggers renewal message in ClearKeyCdm. | 94 // A key system that triggers renewal message in ClearKeyCdm. |
| 167 concrete_key_systems->emplace_back( | 95 concrete_key_systems->emplace_back( |
| 168 new ExternalClearKeyProperties(kExternalClearKeyRenewalKeySystem)); | 96 new cdm::ExternalClearKeyProperties(kExternalClearKeyRenewalKeySystem)); |
| 169 | 97 |
| 170 // A key system that triggers the FileIO test in ClearKeyCdm. | 98 // A key system that triggers the FileIO test in ClearKeyCdm. |
| 171 concrete_key_systems->emplace_back( | 99 concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties( |
| 172 new ExternalClearKeyProperties(kExternalClearKeyFileIOTestKeySystem)); | 100 kExternalClearKeyFileIOTestKeySystem)); |
| 173 | 101 |
| 174 // A key system that triggers the output protection test in ClearKeyCdm. | 102 // A key system that triggers the output protection test in ClearKeyCdm. |
| 175 concrete_key_systems->emplace_back(new ExternalClearKeyProperties( | 103 concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties( |
| 176 kExternalClearKeyOutputProtectionTestKeySystem)); | 104 kExternalClearKeyOutputProtectionTestKeySystem)); |
| 177 | 105 |
| 178 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually | 106 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually |
| 179 // will be refused by ClearKeyCdm. This is to test the CDM initialization | 107 // will be refused by ClearKeyCdm. This is to test the CDM initialization |
| 180 // failure case. | 108 // failure case. |
| 181 concrete_key_systems->emplace_back( | 109 concrete_key_systems->emplace_back(new cdm::ExternalClearKeyProperties( |
| 182 new ExternalClearKeyProperties(kExternalClearKeyInitializeFailKeySystem)); | 110 kExternalClearKeyInitializeFailKeySystem)); |
| 183 | 111 |
| 184 // A key system that triggers a crash in ClearKeyCdm. | 112 // A key system that triggers a crash in ClearKeyCdm. |
| 185 concrete_key_systems->emplace_back( | 113 concrete_key_systems->emplace_back( |
| 186 new ExternalClearKeyProperties(kExternalClearKeyCrashKeySystem)); | 114 new cdm::ExternalClearKeyProperties(kExternalClearKeyCrashKeySystem)); |
| 187 } | 115 } |
| 188 | 116 |
| 189 #if defined(WIDEVINE_CDM_AVAILABLE) | 117 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 190 // This function finds "codecs" and parses the value into the vector |codecs|. | 118 // This function finds "codecs" and parses the value into the vector |codecs|. |
| 191 // Converts the codec strings to UTF-8 since we only expect ASCII strings and | 119 // Converts the codec strings to UTF-8 since we only expect ASCII strings and |
| 192 // this simplifies the rest of the code in this file. | 120 // this simplifies the rest of the code in this file. |
| 193 void GetSupportedCodecsForPepperCdm( | 121 void GetSupportedCodecsForPepperCdm( |
| 194 const std::vector<base::string16>& additional_param_names, | 122 const std::vector<base::string16>& additional_param_names, |
| 195 const std::vector<base::string16>& additional_param_values, | 123 const std::vector<base::string16>& additional_param_values, |
| 196 std::vector<std::string>* codecs) { | 124 std::vector<std::string>* codecs) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 #if defined(WIDEVINE_CDM_AVAILABLE) | 224 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 297 AddPepperBasedWidevine(key_systems_properties); | 225 AddPepperBasedWidevine(key_systems_properties); |
| 298 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 226 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 299 | 227 |
| 300 #endif // defined(ENABLE_PEPPER_CDMS) | 228 #endif // defined(ENABLE_PEPPER_CDMS) |
| 301 | 229 |
| 302 #if defined(OS_ANDROID) | 230 #if defined(OS_ANDROID) |
| 303 cdm::AddAndroidWidevine(key_systems_properties); | 231 cdm::AddAndroidWidevine(key_systems_properties); |
| 304 #endif // defined(OS_ANDROID) | 232 #endif // defined(OS_ANDROID) |
| 305 } | 233 } |
| OLD | NEW |