| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/crypto/key_systems.h" | 5 #include "webkit/media/crypto/key_systems.h" |
| 6 | 6 |
| 7 #include "media/base/decryptor.h" | 7 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
| 8 #include "media/crypto/aes_decryptor.h" | |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 10 | 9 |
| 11 namespace webkit_media { | 10 namespace webkit_media { |
| 12 | 11 |
| 13 namespace { | 12 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
| 14 | 13 static const char kExternalClearKeyKeySystem[] = |
| 15 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 14 "org.chromium.externalclearkey"; |
| 16 | 15 |
| 17 struct MediaFormatAndKeySystem { | 16 struct MediaFormatAndKeySystem { |
| 18 const char* mime_type; | 17 const char* mime_type; |
| 19 const char* codec; | 18 const char* codec; |
| 20 const char* key_system; | 19 const char* key_system; |
| 21 }; | 20 }; |
| 22 | 21 |
| 22 struct KeySystemPluginTypePair { |
| 23 const char* key_system; |
| 24 const char* plugin_type; |
| 25 }; |
| 26 |
| 23 static const MediaFormatAndKeySystem | 27 static const MediaFormatAndKeySystem |
| 24 supported_format_key_system_combinations[] = { | 28 supported_format_key_system_combinations[] = { |
| 25 // TODO(ddorwin): Reconsider based on how usage of this class evolves. | 29 // TODO(ddorwin): Reconsider based on how usage of this class evolves. |
| 26 // For now, this class is stateless, so we do not have the opportunity to | 30 // For now, this class is stateless, so we do not have the opportunity to |
| 27 // build a list using ParseCodecString() like | 31 // build a list using ParseCodecString() like |
| 28 // net::MimeUtil::InitializeMimeTypeMaps(). Therfore, the following line must | 32 // net::MimeUtil::InitializeMimeTypeMaps(). Therefore, the following line must |
| 29 // be separate entries. | 33 // be separate entries. |
| 30 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, | 34 // { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, |
| 31 { "video/webm", "vorbis", kClearKeyKeySystem }, | 35 { "video/webm", "vorbis", kClearKeyKeySystem }, |
| 32 { "video/webm", "vp8", kClearKeyKeySystem }, | 36 { "video/webm", "vp8", kClearKeyKeySystem }, |
| 33 { "video/webm", "vp8.0", kClearKeyKeySystem }, | 37 { "video/webm", "vp8.0", kClearKeyKeySystem }, |
| 34 { "audio/webm", "vorbis", kClearKeyKeySystem }, | 38 { "audio/webm", "vorbis", kClearKeyKeySystem }, |
| 35 { "video/webm", "", kClearKeyKeySystem }, | 39 { "video/webm", "", kClearKeyKeySystem }, |
| 36 { "audio/webm", "", kClearKeyKeySystem } | 40 { "audio/webm", "", kClearKeyKeySystem }, |
| 41 { "video/webm", "vorbis", kExternalClearKeyKeySystem }, |
| 42 { "video/webm", "vp8", kExternalClearKeyKeySystem }, |
| 43 { "video/webm", "vp8.0", kExternalClearKeyKeySystem }, |
| 44 { "audio/webm", "vorbis", kExternalClearKeyKeySystem }, |
| 45 { "video/webm", "", kExternalClearKeyKeySystem }, |
| 46 { "audio/webm", "", kExternalClearKeyKeySystem } |
| 37 }; | 47 }; |
| 38 | 48 |
| 39 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, | 49 static const KeySystemPluginTypePair key_system_to_plugin_type_mapping[] = { |
| 40 const std::string& codec, | 50 // TODO(xhwang): Update this with the real plugin name. |
| 41 const std::string& key_system) { | 51 { kExternalClearKeyKeySystem, "application/x-ppapi-example" } |
| 52 }; |
| 53 |
| 54 static bool IsSupportedKeySystemWithContainerAndCodec( |
| 55 const std::string& mime_type, |
| 56 const std::string& codec, |
| 57 const std::string& key_system) { |
| 42 for (size_t i = 0; | 58 for (size_t i = 0; |
| 43 i < arraysize(supported_format_key_system_combinations); | 59 i < arraysize(supported_format_key_system_combinations); |
| 44 ++i) { | 60 ++i) { |
| 45 const MediaFormatAndKeySystem& combination = | 61 const MediaFormatAndKeySystem& combination = |
| 46 supported_format_key_system_combinations[i]; | 62 supported_format_key_system_combinations[i]; |
| 47 if (combination.mime_type == mime_type && | 63 if (combination.mime_type == mime_type && |
| 48 combination.codec == codec && | 64 combination.codec == codec && |
| 49 combination.key_system == key_system) | 65 combination.key_system == key_system) |
| 50 return true; | 66 return true; |
| 51 } | 67 } |
| 52 | 68 |
| 53 return false; | 69 return false; |
| 54 } | 70 } |
| 55 | 71 |
| 56 } // namespace | |
| 57 | |
| 58 bool IsSupportedKeySystem(const WebKit::WebString& key_system) { | 72 bool IsSupportedKeySystem(const WebKit::WebString& key_system) { |
| 59 if (key_system == kClearKeyKeySystem) | 73 return CanUseAesDecryptor(key_system.utf8().data()) || |
| 60 return true; | 74 !GetPluginType(key_system.utf8().data()).empty(); |
| 61 return false; | |
| 62 } | 75 } |
| 63 | 76 |
| 64 bool IsSupportedKeySystemWithMediaMimeType( | 77 bool IsSupportedKeySystemWithMediaMimeType( |
| 65 const std::string& mime_type, | 78 const std::string& mime_type, |
| 66 const std::vector<std::string>& codecs, | 79 const std::vector<std::string>& codecs, |
| 67 const std::string& key_system) { | 80 const std::string& key_system) { |
| 68 if (codecs.empty()) | 81 if (codecs.empty()) |
| 69 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system); | 82 return IsSupportedKeySystemWithContainerAndCodec(mime_type, "", key_system); |
| 70 | 83 |
| 71 for (size_t i = 0; i < codecs.size(); ++i) { | 84 for (size_t i = 0; i < codecs.size(); ++i) { |
| 72 if (!IsSupportedKeySystemWithContainerAndCodec( | 85 if (!IsSupportedKeySystemWithContainerAndCodec( |
| 73 mime_type, codecs[i], key_system)) | 86 mime_type, codecs[i], key_system)) |
| 74 return false; | 87 return false; |
| 75 } | 88 } |
| 76 | 89 |
| 77 return true; | 90 return true; |
| 78 } | 91 } |
| 79 | 92 |
| 80 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system, | 93 bool CanUseAesDecryptor(const std::string& key_system) { |
| 81 media::DecryptorClient* client) { | 94 return key_system == kClearKeyKeySystem; |
| 82 if (key_system == kClearKeyKeySystem) | 95 } |
| 83 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(client)); | 96 |
| 84 return scoped_ptr<media::Decryptor>(); | 97 std::string GetPluginType(const std::string& key_system) { |
| 98 for (size_t i = 0; i < arraysize(key_system_to_plugin_type_mapping); ++i) { |
| 99 if (key_system_to_plugin_type_mapping[i].key_system == key_system) |
| 100 return key_system_to_plugin_type_mapping[i].plugin_type; |
| 101 } |
| 102 |
| 103 return std::string(); |
| 85 } | 104 } |
| 86 | 105 |
| 87 } // namespace webkit_media | 106 } // namespace webkit_media |
| OLD | NEW |