| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // 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/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "net/base/mime_util.h" | 9 #include "net/base/mime_util.h" |
| 10 #include "webkit/api/public/WebString.h" | 10 #include "webkit/api/public/WebString.h" |
| 11 #include "webkit/glue/glue_util.h" | 11 #include "webkit/glue/glue_util.h" |
| 12 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
| 13 | 13 |
| 14 using WebKit::WebString; | 14 using WebKit::WebString; |
| 15 using WebKit::WebMimeRegistry; | 15 using WebKit::WebMimeRegistry; |
| 16 | 16 |
| 17 namespace { |
| 18 |
| 19 // Convert a WebString to ASCII, falling back on an empty string in the case |
| 20 // of a non-ASCII string. |
| 21 std::string AsASCII(const WebString& string) { |
| 22 if (!IsStringASCII(string)) |
| 23 return EmptyString(); |
| 24 return UTF16ToASCII(string); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 17 namespace webkit_glue { | 29 namespace webkit_glue { |
| 18 | 30 |
| 19 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( | 31 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( |
| 20 const WebString& mime_type) { | 32 const WebString& mime_type) { |
| 21 if (!net::IsSupportedImageMimeType(UTF16ToASCII(mime_type).c_str())) | 33 if (!net::IsSupportedImageMimeType(AsASCII(mime_type).c_str())) |
| 22 return WebMimeRegistry::IsNotSupported; | 34 return WebMimeRegistry::IsNotSupported; |
| 23 return WebMimeRegistry::IsSupported; | 35 return WebMimeRegistry::IsSupported; |
| 24 } | 36 } |
| 25 | 37 |
| 26 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMET
ype( | 38 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMET
ype( |
| 27 const WebString& mime_type) { | 39 const WebString& mime_type) { |
| 28 if (!net::IsSupportedJavascriptMimeType(UTF16ToASCII(mime_type).c_str())) | 40 if (!net::IsSupportedJavascriptMimeType(AsASCII(mime_type).c_str())) |
| 29 return WebMimeRegistry::IsNotSupported; | 41 return WebMimeRegistry::IsNotSupported; |
| 30 return WebMimeRegistry::IsSupported; | 42 return WebMimeRegistry::IsSupported; |
| 31 } | 43 } |
| 32 | 44 |
| 33 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( | 45 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( |
| 34 const WebString& mime_type, const WebString& codecs) { | 46 const WebString& mime_type, const WebString& codecs) { |
| 35 // Not supporting the container is a flat-out no. | 47 // Not supporting the container is a flat-out no. |
| 36 if (!net::IsSupportedMediaMimeType(UTF16ToASCII(mime_type).c_str())) | 48 if (!net::IsSupportedMediaMimeType(AsASCII(mime_type).c_str())) |
| 37 return IsNotSupported; | 49 return IsNotSupported; |
| 38 | 50 |
| 39 // If we don't recognize the codec, it's possible we support it. | 51 // If we don't recognize the codec, it's possible we support it. |
| 40 std::vector<std::string> parsed_codecs; | 52 std::vector<std::string> parsed_codecs; |
| 41 net::ParseCodecString(UTF16ToASCII(codecs).c_str(), &parsed_codecs); | 53 net::ParseCodecString(AsASCII(codecs).c_str(), &parsed_codecs); |
| 42 if (!net::AreSupportedMediaCodecs(parsed_codecs)) | 54 if (!net::AreSupportedMediaCodecs(parsed_codecs)) |
| 43 return MayBeSupported; | 55 return MayBeSupported; |
| 44 | 56 |
| 45 // Otherwise we have a perfect match. | 57 // Otherwise we have a perfect match. |
| 46 return IsSupported; | 58 return IsSupported; |
| 47 } | 59 } |
| 48 | 60 |
| 49 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMETyp
e( | 61 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMETyp
e( |
| 50 const WebString& mime_type) { | 62 const WebString& mime_type) { |
| 51 if (!net::IsSupportedNonImageMimeType(UTF16ToASCII(mime_type).c_str())) | 63 if (!net::IsSupportedNonImageMimeType(AsASCII(mime_type).c_str())) |
| 52 return WebMimeRegistry::IsNotSupported; | 64 return WebMimeRegistry::IsNotSupported; |
| 53 return WebMimeRegistry::IsSupported; | 65 return WebMimeRegistry::IsSupported; |
| 54 } | 66 } |
| 55 | 67 |
| 56 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( | 68 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( |
| 57 const WebString& file_extension) { | 69 const WebString& file_extension) { |
| 58 std::string mime_type; | 70 std::string mime_type; |
| 59 net::GetMimeTypeFromExtension( | 71 net::GetMimeTypeFromExtension( |
| 60 WebStringToFilePathString(file_extension), &mime_type); | 72 WebStringToFilePathString(file_extension), &mime_type); |
| 61 return ASCIIToUTF16(mime_type); | 73 return ASCIIToUTF16(mime_type); |
| 62 } | 74 } |
| 63 | 75 |
| 64 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( | 76 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( |
| 65 const WebString& file_path) { | 77 const WebString& file_path) { |
| 66 std::string mime_type; | 78 std::string mime_type; |
| 67 net::GetMimeTypeFromFile( | 79 net::GetMimeTypeFromFile( |
| 68 FilePath(WebStringToFilePathString(file_path)), &mime_type); | 80 FilePath(WebStringToFilePathString(file_path)), &mime_type); |
| 69 return ASCIIToUTF16(mime_type); | 81 return ASCIIToUTF16(mime_type); |
| 70 } | 82 } |
| 71 | 83 |
| 72 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( | 84 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( |
| 73 const WebString& mime_type) { | 85 const WebString& mime_type) { |
| 74 FilePath::StringType file_extension; | 86 FilePath::StringType file_extension; |
| 75 net::GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type), | 87 net::GetPreferredExtensionForMimeType(AsASCII(mime_type), |
| 76 &file_extension); | 88 &file_extension); |
| 77 return FilePathStringToWebString(file_extension); | 89 return FilePathStringToWebString(file_extension); |
| 78 } | 90 } |
| 79 | 91 |
| 80 } // namespace webkit_glue | 92 } // namespace webkit_glue |
| OLD | NEW |