| 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/glue/simple_webmimeregistry_impl.h" | 5 #include "webkit/glue/simple_webmimeregistry_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "media/filters/stream_parser_factory.h" | |
| 11 #include "net/base/mime_util.h" | 10 #include "net/base/mime_util.h" |
| 12 #include "third_party/WebKit/public/platform/WebString.h" | 11 #include "third_party/WebKit/public/platform/WebString.h" |
| 13 #include "webkit/base/file_path_string_conversions.h" | 12 #include "webkit/base/file_path_string_conversions.h" |
| 14 #include "webkit/renderer/media/crypto/key_systems.h" | |
| 15 | 13 |
| 16 using WebKit::WebString; | 14 using WebKit::WebString; |
| 17 using WebKit::WebMimeRegistry; | 15 using WebKit::WebMimeRegistry; |
| 18 | 16 |
| 19 namespace { | 17 namespace webkit_glue { |
| 20 | 18 |
| 21 // Convert a WebString to ASCII, falling back on an empty string in the case | 19 // static |
| 22 // of a non-ASCII string. | 20 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) { |
| 23 std::string ToASCIIOrEmpty(const WebString& string) { | |
| 24 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); | 21 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); |
| 25 } | 22 } |
| 26 | 23 |
| 27 } // namespace | |
| 28 | |
| 29 namespace webkit_glue { | |
| 30 | |
| 31 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( | 24 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( |
| 32 const WebString& mime_type) { | 25 const WebString& mime_type) { |
| 33 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? | 26 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? |
| 34 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | 27 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; |
| 35 } | 28 } |
| 36 | 29 |
| 37 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( | 30 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( |
| 38 const WebString& mime_type) { | 31 const WebString& mime_type) { |
| 39 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? | 32 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? |
| 40 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | 33 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; |
| 41 } | 34 } |
| 42 | 35 |
| 43 WebMimeRegistry::SupportsType | 36 WebMimeRegistry::SupportsType |
| 44 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( | 37 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( |
| 45 const WebString& mime_type) { | 38 const WebString& mime_type) { |
| 46 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ? | 39 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ? |
| 47 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | 40 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; |
| 48 } | 41 } |
| 49 | 42 |
| 50 // When debugging layout tests failures in the test shell, | |
| 51 // see TestShellWebMimeRegistryImpl. | |
| 52 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( | 43 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( |
| 53 const WebString& mime_type, const WebString& codecs) { | 44 const WebString& mime_type, const WebString& codecs) { |
| 54 return supportsMediaMIMEType(mime_type, codecs, WebString()); | 45 return supportsMediaMIMEType(mime_type, codecs, WebString()); |
| 55 } | 46 } |
| 56 | 47 |
| 57 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( | 48 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( |
| 58 const WebString& mime_type, | 49 const WebString& mime_type, |
| 59 const WebString& codecs, | 50 const WebString& codecs, |
| 60 const WebString& key_system) { | 51 const WebString& key_system) { |
| 61 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | 52 // Media features are only supported at the content/ layer. |
| 62 // Not supporting the container is a flat-out no. | 53 return IsNotSupported; |
| 63 if (!net::IsSupportedMediaMimeType(mime_type_ascii)) | |
| 64 return IsNotSupported; | |
| 65 | |
| 66 if (!key_system.isEmpty()) { | |
| 67 // Check whether the key system is supported with the mime_type and codecs. | |
| 68 | |
| 69 // Not supporting the key system is a flat-out no. | |
| 70 if (!webkit_media::IsSupportedKeySystem(key_system)) | |
| 71 return IsNotSupported; | |
| 72 | |
| 73 std::vector<std::string> strict_codecs; | |
| 74 bool strip_suffix = !net::IsStrictMediaMimeType(mime_type_ascii); | |
| 75 net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, strip_suffix); | |
| 76 | |
| 77 if (!webkit_media::IsSupportedKeySystemWithMediaMimeType( | |
| 78 mime_type_ascii, strict_codecs, ToASCIIOrEmpty(key_system))) | |
| 79 return IsNotSupported; | |
| 80 | |
| 81 // Continue processing the mime_type and codecs. | |
| 82 } | |
| 83 | |
| 84 // Check list of strict codecs to see if it is supported. | |
| 85 if (net::IsStrictMediaMimeType(mime_type_ascii)) { | |
| 86 // We support the container, but no codecs were specified. | |
| 87 if (codecs.isNull()) | |
| 88 return MayBeSupported; | |
| 89 | |
| 90 // Check if the codecs are a perfect match. | |
| 91 std::vector<std::string> strict_codecs; | |
| 92 net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false); | |
| 93 if (!net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs)) | |
| 94 return IsNotSupported; | |
| 95 | |
| 96 // Good to go! | |
| 97 return IsSupported; | |
| 98 } | |
| 99 | |
| 100 // If we don't recognize the codec, it's possible we support it. | |
| 101 std::vector<std::string> parsed_codecs; | |
| 102 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); | |
| 103 if (!net::AreSupportedMediaCodecs(parsed_codecs)) | |
| 104 return MayBeSupported; | |
| 105 | |
| 106 // Otherwise we have a perfect match. | |
| 107 return IsSupported; | |
| 108 } | 54 } |
| 109 | 55 |
| 110 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( | 56 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( |
| 111 const WebKit::WebString& mime_type, | 57 const WebKit::WebString& mime_type, |
| 112 const WebString& codecs) { | 58 const WebString& codecs) { |
| 113 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | 59 // Media features are only supported at the content/ layer. |
| 114 std::vector<std::string> parsed_codec_ids; | 60 return false; |
| 115 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); | |
| 116 if (mime_type_ascii.empty() || parsed_codec_ids.size() == 0) | |
| 117 return false; | |
| 118 return media::StreamParserFactory::IsTypeSupported( | |
| 119 mime_type_ascii, parsed_codec_ids); | |
| 120 } | 61 } |
| 121 | 62 |
| 122 WebMimeRegistry::SupportsType | 63 WebMimeRegistry::SupportsType |
| 123 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( | 64 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( |
| 124 const WebString& mime_type) { | 65 const WebString& mime_type) { |
| 125 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? | 66 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? |
| 126 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | 67 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; |
| 127 } | 68 } |
| 128 | 69 |
| 129 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( | 70 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 152 | 93 |
| 153 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( | 94 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( |
| 154 const WebString& mime_type) { | 95 const WebString& mime_type) { |
| 155 base::FilePath::StringType file_extension; | 96 base::FilePath::StringType file_extension; |
| 156 net::GetPreferredExtensionForMimeType(ToASCIIOrEmpty(mime_type), | 97 net::GetPreferredExtensionForMimeType(ToASCIIOrEmpty(mime_type), |
| 157 &file_extension); | 98 &file_extension); |
| 158 return webkit_base::FilePathStringToWebString(file_extension); | 99 return webkit_base::FilePathStringToWebString(file_extension); |
| 159 } | 100 } |
| 160 | 101 |
| 161 } // namespace webkit_glue | 102 } // namespace webkit_glue |
| OLD | NEW |