| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 "content/child/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 "components/mime_util/mime_util.h" | |
| 12 #include "media/base/mime_util.h" | |
| 13 #include "media/filters/stream_parser_factory.h" | |
| 14 #include "net/base/mime_util.h" | |
| 15 #include "third_party/WebKit/public/platform/FilePathConversion.h" | |
| 16 #include "third_party/WebKit/public/platform/WebString.h" | |
| 17 | |
| 18 using blink::WebString; | |
| 19 using blink::WebMimeRegistry; | |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 23 // static | |
| 24 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) { | |
| 25 return base::IsStringASCII(string) | |
| 26 ? base::UTF16ToASCII(base::StringPiece16(string)) | |
| 27 : std::string(); | |
| 28 } | |
| 29 | |
| 30 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( | |
| 31 const WebString& mime_type) { | |
| 32 return mime_util::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) | |
| 33 ? WebMimeRegistry::IsSupported | |
| 34 : WebMimeRegistry::IsNotSupported; | |
| 35 } | |
| 36 | |
| 37 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( | |
| 38 const WebString& mime_type) { | |
| 39 return mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) | |
| 40 ? WebMimeRegistry::IsSupported | |
| 41 : WebMimeRegistry::IsNotSupported; | |
| 42 } | |
| 43 | |
| 44 WebMimeRegistry::SupportsType | |
| 45 SimpleWebMimeRegistryImpl::supportsImagePrefixedMIMEType( | |
| 46 const WebString& mime_type) { | |
| 47 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type); | |
| 48 return (mime_util::IsSupportedImageMimeType(ascii_mime_type) || | |
| 49 (base::StartsWith(ascii_mime_type, "image/", | |
| 50 base::CompareCase::SENSITIVE) && | |
| 51 mime_util::IsSupportedNonImageMimeType(ascii_mime_type))) | |
| 52 ? WebMimeRegistry::IsSupported | |
| 53 : WebMimeRegistry::IsNotSupported; | |
| 54 } | |
| 55 | |
| 56 WebMimeRegistry::SupportsType | |
| 57 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( | |
| 58 const WebString& mime_type) { | |
| 59 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) | |
| 60 ? WebMimeRegistry::IsSupported | |
| 61 : WebMimeRegistry::IsNotSupported; | |
| 62 } | |
| 63 | |
| 64 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( | |
| 65 const WebString& mime_type, | |
| 66 const WebString& codecs) { | |
| 67 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | |
| 68 std::vector<std::string> codec_vector; | |
| 69 media::ParseCodecString(ToASCIIOrEmpty(codecs), &codec_vector, false); | |
| 70 return static_cast<WebMimeRegistry::SupportsType>( | |
| 71 media::IsSupportedMediaFormat(mime_type_ascii, codec_vector)); | |
| 72 } | |
| 73 | |
| 74 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( | |
| 75 const WebString& mime_type, | |
| 76 const WebString& codecs) { | |
| 77 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | |
| 78 if (mime_type_ascii.empty()) | |
| 79 return false; | |
| 80 std::vector<std::string> parsed_codec_ids; | |
| 81 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); | |
| 82 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii, | |
| 83 parsed_codec_ids); | |
| 84 } | |
| 85 | |
| 86 WebMimeRegistry::SupportsType | |
| 87 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( | |
| 88 const WebString& mime_type) { | |
| 89 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) | |
| 90 ? WebMimeRegistry::IsSupported | |
| 91 : WebMimeRegistry::IsNotSupported; | |
| 92 } | |
| 93 | |
| 94 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( | |
| 95 const WebString& file_extension) { | |
| 96 std::string mime_type; | |
| 97 net::GetMimeTypeFromExtension( | |
| 98 blink::WebStringToFilePath(file_extension).value(), &mime_type); | |
| 99 return WebString::fromUTF8(mime_type); | |
| 100 } | |
| 101 | |
| 102 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension( | |
| 103 const WebString& file_extension) { | |
| 104 std::string mime_type; | |
| 105 net::GetWellKnownMimeTypeFromExtension( | |
| 106 blink::WebStringToFilePath(file_extension).value(), &mime_type); | |
| 107 return WebString::fromUTF8(mime_type); | |
| 108 } | |
| 109 | |
| 110 } // namespace content | |
| OLD | NEW |