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