| 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 | 16 |
| 16 namespace webkit_glue { | 17 namespace webkit_glue { |
| 17 | 18 |
| 18 bool SimpleWebMimeRegistryImpl::supportsImageMIMEType( | 19 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( |
| 19 const WebString& mime_type) { | 20 const WebString& mime_type) { |
| 20 return net::IsSupportedImageMimeType(UTF16ToASCII(mime_type).c_str()); | 21 if (!net::IsSupportedImageMimeType(UTF16ToASCII(mime_type).c_str())) |
| 22 return WebMimeRegistry::IsNotSupported; |
| 23 return WebMimeRegistry::IsSupported; |
| 21 } | 24 } |
| 22 | 25 |
| 23 bool SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( | 26 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMET
ype( |
| 24 const WebString& mime_type) { | 27 const WebString& mime_type) { |
| 25 return net::IsSupportedJavascriptMimeType(UTF16ToASCII(mime_type).c_str()); | 28 if (!net::IsSupportedJavascriptMimeType(UTF16ToASCII(mime_type).c_str())) |
| 29 return WebMimeRegistry::IsNotSupported; |
| 30 return WebMimeRegistry::IsSupported; |
| 26 } | 31 } |
| 27 | 32 |
| 28 bool SimpleWebMimeRegistryImpl::supportsMediaMIMEType( | 33 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( |
| 29 const WebString& mime_type) { | 34 const WebString& mime_type, const WebString& codecs) { |
| 30 return net::IsSupportedMediaMimeType(UTF16ToASCII(mime_type).c_str()); | 35 // Not supporting the container is a flat-out no. |
| 36 if (!net::IsSupportedMediaMimeType(UTF16ToASCII(mime_type).c_str())) |
| 37 return IsNotSupported; |
| 38 |
| 39 // If we don't recognize the codec, it's possible we support it. |
| 40 std::vector<std::string> parsed_codecs; |
| 41 net::ParseCodecString(UTF16ToASCII(codecs).c_str(), &parsed_codecs); |
| 42 if (!net::AreSupportedMediaCodecs(parsed_codecs)) |
| 43 return MayBeSupported; |
| 44 |
| 45 // Otherwise we have a perfect match. |
| 46 return IsSupported; |
| 31 } | 47 } |
| 32 | 48 |
| 33 bool SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( | 49 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMETyp
e( |
| 34 const WebString& mime_type) { | 50 const WebString& mime_type) { |
| 35 return net::IsSupportedNonImageMimeType(UTF16ToASCII(mime_type).c_str()); | 51 if (!net::IsSupportedNonImageMimeType(UTF16ToASCII(mime_type).c_str())) |
| 52 return WebMimeRegistry::IsNotSupported; |
| 53 return WebMimeRegistry::IsSupported; |
| 36 } | 54 } |
| 37 | 55 |
| 38 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( | 56 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( |
| 39 const WebString& file_extension) { | 57 const WebString& file_extension) { |
| 40 std::string mime_type; | 58 std::string mime_type; |
| 41 net::GetMimeTypeFromExtension( | 59 net::GetMimeTypeFromExtension( |
| 42 WebStringToFilePathString(file_extension), &mime_type); | 60 WebStringToFilePathString(file_extension), &mime_type); |
| 43 return ASCIIToUTF16(mime_type); | 61 return ASCIIToUTF16(mime_type); |
| 44 } | 62 } |
| 45 | 63 |
| 46 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( | 64 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( |
| 47 const WebString& file_path) { | 65 const WebString& file_path) { |
| 48 std::string mime_type; | 66 std::string mime_type; |
| 49 net::GetMimeTypeFromFile( | 67 net::GetMimeTypeFromFile( |
| 50 FilePath(WebStringToFilePathString(file_path)), &mime_type); | 68 FilePath(WebStringToFilePathString(file_path)), &mime_type); |
| 51 return ASCIIToUTF16(mime_type); | 69 return ASCIIToUTF16(mime_type); |
| 52 } | 70 } |
| 53 | 71 |
| 54 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( | 72 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( |
| 55 const WebString& mime_type) { | 73 const WebString& mime_type) { |
| 56 FilePath::StringType file_extension; | 74 FilePath::StringType file_extension; |
| 57 net::GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type), | 75 net::GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type), |
| 58 &file_extension); | 76 &file_extension); |
| 59 return FilePathStringToWebString(file_extension); | 77 return FilePathStringToWebString(file_extension); |
| 60 } | 78 } |
| 61 | 79 |
| 62 } // namespace webkit_glue | 80 } // namespace webkit_glue |
| OLD | NEW |