| 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" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 return image_types_.find(base::StringToLowerASCII(mime_type)) != | 154 return image_types_.find(base::StringToLowerASCII(mime_type)) != |
| 155 image_types_.end(); | 155 image_types_.end(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { | 158 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { |
| 159 return non_image_types_.find(base::StringToLowerASCII(mime_type)) != | 159 return non_image_types_.find(base::StringToLowerASCII(mime_type)) != |
| 160 non_image_types_.end() || | 160 non_image_types_.end() || |
| 161 #if !defined(OS_IOS) | 161 #if !defined(OS_IOS) |
| 162 media::IsSupportedMediaMimeType(mime_type) || | 162 media::IsSupportedMediaMimeType(mime_type) || |
| 163 #endif | 163 #endif |
| 164 (base::StartsWithASCII(mime_type, "text/", | 164 (base::StartsWith(mime_type, "text/", |
| 165 false /* case insensitive */) && | 165 base::CompareCase::INSENSITIVE_ASCII) && |
| 166 !IsUnsupportedTextMimeType(mime_type)) || | 166 !IsUnsupportedTextMimeType(mime_type)) || |
| 167 (base::StartsWithASCII(mime_type, "application/", false) && | 167 (base::StartsWith(mime_type, "application/", |
| 168 base::CompareCase::INSENSITIVE_ASCII) && |
| 168 net::MatchesMimeType("application/*+json", mime_type)); | 169 net::MatchesMimeType("application/*+json", mime_type)); |
| 169 } | 170 } |
| 170 | 171 |
| 171 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 172 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { |
| 172 return unsupported_text_types_.find(base::StringToLowerASCII(mime_type)) != | 173 return unsupported_text_types_.find(base::StringToLowerASCII(mime_type)) != |
| 173 unsupported_text_types_.end(); | 174 unsupported_text_types_.end(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 bool MimeUtil::IsSupportedJavascriptMimeType( | 177 bool MimeUtil::IsSupportedJavascriptMimeType( |
| 177 const std::string& mime_type) const { | 178 const std::string& mime_type) const { |
| 178 return javascript_types_.find(mime_type) != javascript_types_.end(); | 179 return javascript_types_.find(mime_type) != javascript_types_.end(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { | 182 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { |
| 182 return (base::StartsWithASCII(mime_type, "image/", false) && | 183 return (base::StartsWith(mime_type, "image/", |
| 184 base::CompareCase::INSENSITIVE_ASCII) && |
| 183 IsSupportedImageMimeType(mime_type)) || | 185 IsSupportedImageMimeType(mime_type)) || |
| 184 IsSupportedNonImageMimeType(mime_type); | 186 IsSupportedNonImageMimeType(mime_type); |
| 185 } | 187 } |
| 186 | 188 |
| 187 // This variable is Leaky because it is accessed from WorkerPool threads. | 189 // This variable is Leaky because it is accessed from WorkerPool threads. |
| 188 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = | 190 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
| 189 LAZY_INSTANCE_INITIALIZER; | 191 LAZY_INSTANCE_INITIALIZER; |
| 190 | 192 |
| 191 } // namespace | 193 } // namespace |
| 192 | 194 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 if (base::EqualsCaseInsensitiveASCII( | 226 if (base::EqualsCaseInsensitiveASCII( |
| 225 mime_type, kSupportedCertificateTypes[i].mime_type)) { | 227 mime_type, kSupportedCertificateTypes[i].mime_type)) { |
| 226 return kSupportedCertificateTypes[i].cert_type; | 228 return kSupportedCertificateTypes[i].cert_type; |
| 227 } | 229 } |
| 228 } | 230 } |
| 229 | 231 |
| 230 return net::CERTIFICATE_MIME_TYPE_UNKNOWN; | 232 return net::CERTIFICATE_MIME_TYPE_UNKNOWN; |
| 231 } | 233 } |
| 232 | 234 |
| 233 } // namespace mime_util | 235 } // namespace mime_util |
| OLD | NEW |