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