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