| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/glue/simple_webmimeregistry_impl.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/strings/string_util.h" | |
| 9 #include "base/strings/sys_string_conversions.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "net/base/mime_util.h" | |
| 12 #include "third_party/WebKit/public/platform/WebString.h" | |
| 13 | |
| 14 using blink::WebString; | |
| 15 using blink::WebMimeRegistry; | |
| 16 | |
| 17 namespace webkit_glue { | |
| 18 | |
| 19 //static | |
| 20 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) { | |
| 21 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); | |
| 22 } | |
| 23 | |
| 24 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( | |
| 25 const WebString& mime_type) { | |
| 26 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? | |
| 27 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | |
| 28 } | |
| 29 | |
| 30 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( | |
| 31 const WebString& mime_type) { | |
| 32 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? | |
| 33 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | |
| 34 } | |
| 35 | |
| 36 WebMimeRegistry::SupportsType | |
| 37 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( | |
| 38 const WebString& mime_type) { | |
| 39 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ? | |
| 40 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | |
| 41 } | |
| 42 | |
| 43 // When debugging layout tests failures in the test shell, | |
| 44 // see TestShellWebMimeRegistryImpl. | |
| 45 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( | |
| 46 const WebString& mime_type, | |
| 47 const WebString& codecs, | |
| 48 const WebString& key_system) { | |
| 49 // Media features are only supported at the content/ layer. | |
| 50 return IsNotSupported; | |
| 51 } | |
| 52 | |
| 53 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( | |
| 54 const WebString& mime_type, | |
| 55 const WebString& codecs) { | |
| 56 // Media features are only supported at the content/ layer. | |
| 57 return IsNotSupported; | |
| 58 } | |
| 59 | |
| 60 WebMimeRegistry::SupportsType | |
| 61 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( | |
| 62 const WebString& mime_type) { | |
| 63 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? | |
| 64 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; | |
| 65 } | |
| 66 | |
| 67 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( | |
| 68 const WebString& file_extension) { | |
| 69 std::string mime_type; | |
| 70 net::GetMimeTypeFromExtension( | |
| 71 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); | |
| 72 return WebString::fromUTF8(mime_type); | |
| 73 } | |
| 74 | |
| 75 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension( | |
| 76 const WebString& file_extension) { | |
| 77 std::string mime_type; | |
| 78 net::GetWellKnownMimeTypeFromExtension( | |
| 79 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); | |
| 80 return WebString::fromUTF8(mime_type); | |
| 81 } | |
| 82 | |
| 83 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( | |
| 84 const WebString& file_path) { | |
| 85 std::string mime_type; | |
| 86 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path), | |
| 87 &mime_type); | |
| 88 return WebString::fromUTF8(mime_type); | |
| 89 } | |
| 90 | |
| 91 } // namespace webkit_glue | |
| OLD | NEW |