OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mime_util/mime_util.h" | 5 #include "components/mime_util/mime_util.h" |
6 | 6 |
7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 | 11 |
12 #if !defined(OS_IOS) | 12 #if !defined(OS_IOS) |
13 // iOS doesn't use and must not depend on //media | 13 // iOS doesn't use and must not depend on //media |
14 #include "media/base/mime_util.h" | 14 #include "media/base/mime_util.h" |
15 #endif | 15 #endif |
16 | 16 |
17 namespace mime_util { | 17 namespace mime_util { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Dictionary of cryptographic file mime types. | |
22 struct CertificateMimeTypeInfo { | |
23 const char* const mime_type; | |
24 net::CertificateMimeType cert_type; | |
25 }; | |
26 | |
27 const CertificateMimeTypeInfo kSupportedCertificateTypes[] = { | |
28 {"application/x-x509-user-cert", net::CERTIFICATE_MIME_TYPE_X509_USER_CERT}, | |
29 #if defined(OS_ANDROID) | |
30 {"application/x-x509-ca-cert", net::CERTIFICATE_MIME_TYPE_X509_CA_CERT}, | |
31 {"application/x-pkcs12", net::CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE}, | |
32 #endif | |
33 }; | |
34 | |
35 // From WebKit's WebCore/platform/MIMETypeRegistry.cpp: | 21 // From WebKit's WebCore/platform/MIMETypeRegistry.cpp: |
36 | 22 |
37 const char* const kSupportedImageTypes[] = {"image/jpeg", | 23 const char* const kSupportedImageTypes[] = {"image/jpeg", |
38 "image/pjpeg", | 24 "image/pjpeg", |
39 "image/jpg", | 25 "image/jpg", |
40 "image/webp", | 26 "image/webp", |
41 "image/png", | 27 "image/png", |
42 "image/gif", | 28 "image/gif", |
43 "image/bmp", | 29 "image/bmp", |
44 "image/vnd.microsoft.icon", // ico | 30 "image/vnd.microsoft.icon", // ico |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 for (size_t i = 0; i < arraysize(kSupportedNonImageTypes); ++i) | 125 for (size_t i = 0; i < arraysize(kSupportedNonImageTypes); ++i) |
140 non_image_types_.insert(kSupportedNonImageTypes[i]); | 126 non_image_types_.insert(kSupportedNonImageTypes[i]); |
141 for (size_t i = 0; i < arraysize(kSupportedImageTypes); ++i) | 127 for (size_t i = 0; i < arraysize(kSupportedImageTypes); ++i) |
142 image_types_.insert(kSupportedImageTypes[i]); | 128 image_types_.insert(kSupportedImageTypes[i]); |
143 for (size_t i = 0; i < arraysize(kUnsupportedTextTypes); ++i) | 129 for (size_t i = 0; i < arraysize(kUnsupportedTextTypes); ++i) |
144 unsupported_text_types_.insert(kUnsupportedTextTypes[i]); | 130 unsupported_text_types_.insert(kUnsupportedTextTypes[i]); |
145 for (size_t i = 0; i < arraysize(kSupportedJavascriptTypes); ++i) { | 131 for (size_t i = 0; i < arraysize(kSupportedJavascriptTypes); ++i) { |
146 javascript_types_.insert(kSupportedJavascriptTypes[i]); | 132 javascript_types_.insert(kSupportedJavascriptTypes[i]); |
147 non_image_types_.insert(kSupportedJavascriptTypes[i]); | 133 non_image_types_.insert(kSupportedJavascriptTypes[i]); |
148 } | 134 } |
149 for (size_t i = 0; i < arraysize(kSupportedCertificateTypes); ++i) | |
150 non_image_types_.insert(kSupportedCertificateTypes[i].mime_type); | |
151 } | 135 } |
152 | 136 |
153 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 137 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
154 return image_types_.find(base::ToLowerASCII(mime_type)) != image_types_.end(); | 138 return image_types_.find(base::ToLowerASCII(mime_type)) != image_types_.end(); |
155 } | 139 } |
156 | 140 |
157 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { | 141 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { |
158 return non_image_types_.find(base::ToLowerASCII(mime_type)) != | 142 return non_image_types_.find(base::ToLowerASCII(mime_type)) != |
159 non_image_types_.end() || | 143 non_image_types_.end() || |
160 #if !defined(OS_IOS) | 144 #if !defined(OS_IOS) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 184 } |
201 | 185 |
202 bool IsUnsupportedTextMimeType(const std::string& mime_type) { | 186 bool IsUnsupportedTextMimeType(const std::string& mime_type) { |
203 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); | 187 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); |
204 } | 188 } |
205 | 189 |
206 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { | 190 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { |
207 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); | 191 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); |
208 } | 192 } |
209 | 193 |
210 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | |
211 net::CertificateMimeType file_type = | |
212 GetCertificateMimeTypeForMimeType(mime_type); | |
213 return file_type != net::CERTIFICATE_MIME_TYPE_UNKNOWN; | |
214 } | |
215 | |
216 bool IsSupportedMimeType(const std::string& mime_type) { | 194 bool IsSupportedMimeType(const std::string& mime_type) { |
217 return g_mime_util.Get().IsSupportedMimeType(mime_type); | 195 return g_mime_util.Get().IsSupportedMimeType(mime_type); |
218 } | 196 } |
219 | 197 |
220 net::CertificateMimeType GetCertificateMimeTypeForMimeType( | |
221 const std::string& mime_type) { | |
222 // Don't create a map, there is only one entry in the table, | |
223 // except on Android. | |
224 for (size_t i = 0; i < arraysize(kSupportedCertificateTypes); ++i) { | |
225 if (base::EqualsCaseInsensitiveASCII( | |
226 mime_type, kSupportedCertificateTypes[i].mime_type)) { | |
227 return kSupportedCertificateTypes[i].cert_type; | |
228 } | |
229 } | |
230 | |
231 return net::CERTIFICATE_MIME_TYPE_UNKNOWN; | |
232 } | |
233 | |
234 } // namespace mime_util | 198 } // namespace mime_util |
OLD | NEW |