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 #include "media/base/mime_util.h" | |
11 | 12 |
12 namespace mime_util { | 13 namespace mime_util { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Dictionary of cryptographic file mime types. | 17 // Dictionary of cryptographic file mime types. |
17 struct CertificateMimeTypeInfo { | 18 struct CertificateMimeTypeInfo { |
18 const char* const mime_type; | 19 const char* const mime_type; |
19 net::CertificateMimeType cert_type; | 20 net::CertificateMimeType cert_type; |
20 }; | 21 }; |
21 | 22 |
22 const CertificateMimeTypeInfo kSupportedCertificateTypes[] = { | 23 const CertificateMimeTypeInfo kSupportedCertificateTypes[] = { |
23 {"application/x-x509-user-cert", net::CERTIFICATE_MIME_TYPE_X509_USER_CERT}, | 24 {"application/x-x509-user-cert", net::CERTIFICATE_MIME_TYPE_X509_USER_CERT}, |
24 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
ddorwin
2015/05/08 16:29:18
#include "build/build_config.h"
servolk
2015/05/08 17:33:04
Already included in this file.
| |
25 {"application/x-x509-ca-cert", net::CERTIFICATE_MIME_TYPE_X509_CA_CERT}, | 26 {"application/x-x509-ca-cert", net::CERTIFICATE_MIME_TYPE_X509_CA_CERT}, |
26 {"application/x-pkcs12", net::CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE}, | 27 {"application/x-pkcs12", net::CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE}, |
27 #endif | 28 #endif |
28 }; | 29 }; |
29 | 30 |
30 // From WebKit's WebCore/platform/MIMETypeRegistry.cpp: | 31 // From WebKit's WebCore/platform/MIMETypeRegistry.cpp: |
31 | 32 |
32 const char* const kSupportedImageTypes[] = {"image/jpeg", | 33 const char* const kSupportedImageTypes[] = {"image/jpeg", |
33 "image/pjpeg", | 34 "image/pjpeg", |
34 "image/jpg", | 35 "image/jpg", |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 image_types_.end(); | 151 image_types_.end(); |
151 } | 152 } |
152 | 153 |
153 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { | 154 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { |
154 return non_image_types_.find(base::StringToLowerASCII(mime_type)) != | 155 return non_image_types_.find(base::StringToLowerASCII(mime_type)) != |
155 non_image_types_.end() || | 156 non_image_types_.end() || |
156 (StartsWithASCII(mime_type, "text/", false /* case insensitive */) && | 157 (StartsWithASCII(mime_type, "text/", false /* case insensitive */) && |
157 !IsUnsupportedTextMimeType(mime_type)) || | 158 !IsUnsupportedTextMimeType(mime_type)) || |
158 (StartsWithASCII(mime_type, "application/", false) && | 159 (StartsWithASCII(mime_type, "application/", false) && |
159 net::MatchesMimeType("application/*+json", mime_type)) || | 160 net::MatchesMimeType("application/*+json", mime_type)) || |
160 net::IsSupportedMediaMimeType(mime_type); | 161 media::IsSupportedMediaMimeType(mime_type); |
161 } | 162 } |
162 | 163 |
163 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 164 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { |
164 return unsupported_text_types_.find(base::StringToLowerASCII(mime_type)) != | 165 return unsupported_text_types_.find(base::StringToLowerASCII(mime_type)) != |
165 unsupported_text_types_.end(); | 166 unsupported_text_types_.end(); |
166 } | 167 } |
167 | 168 |
168 bool MimeUtil::IsSupportedJavascriptMimeType( | 169 bool MimeUtil::IsSupportedJavascriptMimeType( |
169 const std::string& mime_type) const { | 170 const std::string& mime_type) const { |
170 return javascript_types_.find(mime_type) != javascript_types_.end(); | 171 return javascript_types_.find(mime_type) != javascript_types_.end(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 if (base::strcasecmp(mime_type.c_str(), | 217 if (base::strcasecmp(mime_type.c_str(), |
217 kSupportedCertificateTypes[i].mime_type) == 0) { | 218 kSupportedCertificateTypes[i].mime_type) == 0) { |
218 return kSupportedCertificateTypes[i].cert_type; | 219 return kSupportedCertificateTypes[i].cert_type; |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 return net::CERTIFICATE_MIME_TYPE_UNKNOWN; | 223 return net::CERTIFICATE_MIME_TYPE_UNKNOWN; |
223 } | 224 } |
224 | 225 |
225 } // namespace mime_util | 226 } // namespace mime_util |
OLD | NEW |