| 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 "content/renderer/media/crypto/key_systems.h" | 5 #include "content/renderer/media/crypto/key_systems.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 bool IsSupportedKeySystemWithMediaMimeType( | 60 bool IsSupportedKeySystemWithMediaMimeType( |
| 61 const std::string& mime_type, | 61 const std::string& mime_type, |
| 62 const std::vector<std::string>& codecs, | 62 const std::vector<std::string>& codecs, |
| 63 const std::string& key_system); | 63 const std::string& key_system); |
| 64 | 64 |
| 65 bool UseAesDecryptor(const std::string& concrete_key_system); | 65 bool UseAesDecryptor(const std::string& concrete_key_system); |
| 66 | 66 |
| 67 #if defined(ENABLE_PEPPER_CDMS) | 67 #if defined(ENABLE_PEPPER_CDMS) |
| 68 std::string GetPepperType(const std::string& concrete_key_system); | 68 std::string GetPepperType(const std::string& concrete_key_system); |
| 69 #elif defined(OS_ANDROID) | |
| 70 std::vector<uint8> GetUUID(const std::string& concrete_key_system); | |
| 71 #endif | 69 #endif |
| 72 | 70 |
| 73 private: | 71 private: |
| 74 void AddConcreteSupportedKeySystems( | 72 void AddConcreteSupportedKeySystems( |
| 75 const std::vector<KeySystemInfo>& concrete_key_systems); | 73 const std::vector<KeySystemInfo>& concrete_key_systems); |
| 76 | 74 |
| 77 void AddConcreteSupportedKeySystem( | 75 void AddConcreteSupportedKeySystem( |
| 78 const std::string& key_system, | 76 const std::string& key_system, |
| 79 bool use_aes_decryptor, | 77 bool use_aes_decryptor, |
| 80 #if defined(ENABLE_PEPPER_CDMS) | 78 #if defined(ENABLE_PEPPER_CDMS) |
| 81 const std::string& pepper_type, | 79 const std::string& pepper_type, |
| 82 #elif defined(OS_ANDROID) | |
| 83 const std::vector<uint8>& uuid, | |
| 84 #endif | 80 #endif |
| 85 const std::vector<KeySystemInfo::ContainerCodecsPair>& supported_types, | 81 const std::vector<KeySystemInfo::ContainerCodecsPair>& supported_types, |
| 86 const std::string& parent_key_system); | 82 const std::string& parent_key_system); |
| 87 | 83 |
| 88 | |
| 89 friend struct base::DefaultLazyInstanceTraits<KeySystems>; | 84 friend struct base::DefaultLazyInstanceTraits<KeySystems>; |
| 90 | 85 |
| 91 typedef base::hash_set<std::string> CodecSet; | 86 typedef base::hash_set<std::string> CodecSet; |
| 92 typedef std::map<std::string, CodecSet> MimeTypeMap; | 87 typedef std::map<std::string, CodecSet> MimeTypeMap; |
| 93 | 88 |
| 94 struct KeySystemProperties { | 89 struct KeySystemProperties { |
| 95 KeySystemProperties() : use_aes_decryptor(false) {} | 90 KeySystemProperties() : use_aes_decryptor(false) {} |
| 96 | 91 |
| 97 bool use_aes_decryptor; | 92 bool use_aes_decryptor; |
| 98 #if defined(ENABLE_PEPPER_CDMS) | 93 #if defined(ENABLE_PEPPER_CDMS) |
| 99 std::string pepper_type; | 94 std::string pepper_type; |
| 100 #elif defined(OS_ANDROID) | |
| 101 std::vector<uint8> uuid; | |
| 102 #endif | 95 #endif |
| 103 MimeTypeMap types; | 96 MimeTypeMap types; |
| 104 }; | 97 }; |
| 105 | 98 |
| 106 typedef std::map<std::string, KeySystemProperties> KeySystemPropertiesMap; | 99 typedef std::map<std::string, KeySystemProperties> KeySystemPropertiesMap; |
| 107 | 100 |
| 108 typedef std::map<std::string, std::string> ParentKeySystemMap; | 101 typedef std::map<std::string, std::string> ParentKeySystemMap; |
| 109 | 102 |
| 110 KeySystems(); | 103 KeySystems(); |
| 111 ~KeySystems() {} | 104 ~KeySystems() {} |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 143 } |
| 151 | 144 |
| 152 void KeySystems::AddConcreteSupportedKeySystems( | 145 void KeySystems::AddConcreteSupportedKeySystems( |
| 153 const std::vector<KeySystemInfo>& concrete_key_systems) { | 146 const std::vector<KeySystemInfo>& concrete_key_systems) { |
| 154 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { | 147 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { |
| 155 const KeySystemInfo& key_system_info = concrete_key_systems[i]; | 148 const KeySystemInfo& key_system_info = concrete_key_systems[i]; |
| 156 AddConcreteSupportedKeySystem(key_system_info.key_system, | 149 AddConcreteSupportedKeySystem(key_system_info.key_system, |
| 157 key_system_info.use_aes_decryptor, | 150 key_system_info.use_aes_decryptor, |
| 158 #if defined(ENABLE_PEPPER_CDMS) | 151 #if defined(ENABLE_PEPPER_CDMS) |
| 159 key_system_info.pepper_type, | 152 key_system_info.pepper_type, |
| 160 #elif defined(OS_ANDROID) | |
| 161 key_system_info.uuid, | |
| 162 #endif | 153 #endif |
| 163 key_system_info.supported_types, | 154 key_system_info.supported_types, |
| 164 key_system_info.parent_key_system); | 155 key_system_info.parent_key_system); |
| 165 } | 156 } |
| 166 } | 157 } |
| 167 | 158 |
| 168 void KeySystems::AddConcreteSupportedKeySystem( | 159 void KeySystems::AddConcreteSupportedKeySystem( |
| 169 const std::string& concrete_key_system, | 160 const std::string& concrete_key_system, |
| 170 bool use_aes_decryptor, | 161 bool use_aes_decryptor, |
| 171 #if defined(ENABLE_PEPPER_CDMS) | 162 #if defined(ENABLE_PEPPER_CDMS) |
| 172 const std::string& pepper_type, | 163 const std::string& pepper_type, |
| 173 #elif defined(OS_ANDROID) | |
| 174 const std::vector<uint8>& uuid, | |
| 175 #endif | 164 #endif |
| 176 const std::vector<KeySystemInfo::ContainerCodecsPair>& supported_types, | 165 const std::vector<KeySystemInfo::ContainerCodecsPair>& supported_types, |
| 177 const std::string& parent_key_system) { | 166 const std::string& parent_key_system) { |
| 178 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) | 167 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) |
| 179 << "Key system '" << concrete_key_system << "' already registered"; | 168 << "Key system '" << concrete_key_system << "' already registered"; |
| 180 DCHECK(parent_key_system_map_.find(concrete_key_system) == | 169 DCHECK(parent_key_system_map_.find(concrete_key_system) == |
| 181 parent_key_system_map_.end()) | 170 parent_key_system_map_.end()) |
| 182 << "'" << concrete_key_system << " is already registered as a parent"; | 171 << "'" << concrete_key_system << " is already registered as a parent"; |
| 183 | 172 |
| 184 KeySystemProperties properties; | 173 KeySystemProperties properties; |
| 185 properties.use_aes_decryptor = use_aes_decryptor; | 174 properties.use_aes_decryptor = use_aes_decryptor; |
| 186 #if defined(ENABLE_PEPPER_CDMS) | 175 #if defined(ENABLE_PEPPER_CDMS) |
| 187 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); | 176 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); |
| 188 properties.pepper_type = pepper_type; | 177 properties.pepper_type = pepper_type; |
| 189 #elif defined(OS_ANDROID) | |
| 190 DCHECK_EQ(use_aes_decryptor, uuid.empty()); | |
| 191 DCHECK(use_aes_decryptor || uuid.size() == 16); | |
| 192 properties.uuid = uuid; | |
| 193 #endif | 178 #endif |
| 194 | 179 |
| 195 for (size_t i = 0; i < supported_types.size(); ++i) { | 180 for (size_t i = 0; i < supported_types.size(); ++i) { |
| 196 const KeySystemInfo::ContainerCodecsPair& pair = supported_types[i]; | 181 const KeySystemInfo::ContainerCodecsPair& pair = supported_types[i]; |
| 197 const std::string& mime_type = pair.first; | 182 const std::string& mime_type = pair.first; |
| 198 const std::string& codecs_list = pair.second; | 183 const std::string& codecs_list = pair.second; |
| 199 AddSupportedType(mime_type, codecs_list, &properties); | 184 AddSupportedType(mime_type, codecs_list, &properties); |
| 200 } | 185 } |
| 201 | 186 |
| 202 concrete_key_system_map_[concrete_key_system] = properties; | 187 concrete_key_system_map_[concrete_key_system] = properties; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 concrete_key_system_map_.find(concrete_key_system); | 298 concrete_key_system_map_.find(concrete_key_system); |
| 314 if (key_system_iter == concrete_key_system_map_.end()) { | 299 if (key_system_iter == concrete_key_system_map_.end()) { |
| 315 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; | 300 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; |
| 316 return std::string(); | 301 return std::string(); |
| 317 } | 302 } |
| 318 | 303 |
| 319 const std::string& type = key_system_iter->second.pepper_type; | 304 const std::string& type = key_system_iter->second.pepper_type; |
| 320 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; | 305 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; |
| 321 return type; | 306 return type; |
| 322 } | 307 } |
| 323 #elif defined(OS_ANDROID) | |
| 324 std::vector<uint8> KeySystems::GetUUID(const std::string& concrete_key_system) { | |
| 325 KeySystemPropertiesMap::iterator key_system_iter = | |
| 326 concrete_key_system_map_.find(concrete_key_system); | |
| 327 if (key_system_iter == concrete_key_system_map_.end()) { | |
| 328 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; | |
| 329 return std::vector<uint8>(); | |
| 330 } | |
| 331 | |
| 332 return key_system_iter->second.uuid; | |
| 333 } | |
| 334 #endif | 308 #endif |
| 335 | 309 |
| 336 //------------------------------------------------------------------------------ | 310 //------------------------------------------------------------------------------ |
| 337 | 311 |
| 338 std::string GetUnprefixedKeySystemName(const std::string& key_system) { | 312 std::string GetUnprefixedKeySystemName(const std::string& key_system) { |
| 339 if (key_system == kClearKeyKeySystem) | 313 if (key_system == kClearKeyKeySystem) |
| 340 return kUnsupportedClearKeyKeySystem; | 314 return kUnsupportedClearKeyKeySystem; |
| 341 | 315 |
| 342 if (key_system == kPrefixedClearKeyKeySystem) | 316 if (key_system == kPrefixedClearKeyKeySystem) |
| 343 return kClearKeyKeySystem; | 317 return kClearKeyKeySystem; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 351 } |
| 378 | 352 |
| 379 bool CanUseAesDecryptor(const std::string& concrete_key_system) { | 353 bool CanUseAesDecryptor(const std::string& concrete_key_system) { |
| 380 return KeySystems::GetInstance().UseAesDecryptor(concrete_key_system); | 354 return KeySystems::GetInstance().UseAesDecryptor(concrete_key_system); |
| 381 } | 355 } |
| 382 | 356 |
| 383 #if defined(ENABLE_PEPPER_CDMS) | 357 #if defined(ENABLE_PEPPER_CDMS) |
| 384 std::string GetPepperType(const std::string& concrete_key_system) { | 358 std::string GetPepperType(const std::string& concrete_key_system) { |
| 385 return KeySystems::GetInstance().GetPepperType(concrete_key_system); | 359 return KeySystems::GetInstance().GetPepperType(concrete_key_system); |
| 386 } | 360 } |
| 387 #elif defined(OS_ANDROID) | |
| 388 std::vector<uint8> GetUUID(const std::string& concrete_key_system) { | |
| 389 return KeySystems::GetInstance().GetUUID(concrete_key_system); | |
| 390 } | |
| 391 #endif | 361 #endif |
| 392 | 362 |
| 393 } // namespace content | 363 } // namespace content |
| OLD | NEW |