Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <iterator> | 6 #include <iterator> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "net/base/mime_util.h" | 10 #include "net/base/mime_util.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 const unsigned kMaxFilePathSize = 65536; | 212 const unsigned kMaxFilePathSize = 65536; |
| 213 if (ext.length() > kMaxFilePathSize) | 213 if (ext.length() > kMaxFilePathSize) |
| 214 return false; | 214 return false; |
| 215 | 215 |
| 216 // We implement the same algorithm as Mozilla for mapping a file extension to | 216 // We implement the same algorithm as Mozilla for mapping a file extension to |
| 217 // a mime type. That is, we first check a hard-coded list (that cannot be | 217 // a mime type. That is, we first check a hard-coded list (that cannot be |
| 218 // overridden), and then if not found there, we defer to the system registry. | 218 // overridden), and then if not found there, we defer to the system registry. |
| 219 // Finally, we scan a secondary hard-coded list to catch types that we can | 219 // Finally, we scan a secondary hard-coded list to catch types that we can |
| 220 // deduce but that we also want to allow the OS to override. | 220 // deduce but that we also want to allow the OS to override. |
| 221 | 221 |
| 222 #if defined(OS_WIN) | 222 base::FilePath path_ext(ext); |
| 223 string ext_narrow_str = WideToUTF8(ext); | 223 const string& ext_narrow_str = path_ext.AsUTF8Unsafe(); |
|
Bernhard Bauer
2013/05/28 23:26:41
You should not take a reference here! The returned
| |
| 224 #elif defined(OS_POSIX) | |
| 225 const string& ext_narrow_str = ext; | |
| 226 #endif | |
| 227 const char* mime_type; | 224 const char* mime_type; |
| 228 | 225 |
| 229 mime_type = FindMimeType(primary_mappings, arraysize(primary_mappings), | 226 mime_type = FindMimeType(primary_mappings, arraysize(primary_mappings), |
| 230 ext_narrow_str.c_str()); | 227 ext_narrow_str.c_str()); |
| 231 if (mime_type) { | 228 if (mime_type) { |
| 232 *result = mime_type; | 229 *result = mime_type; |
| 233 return true; | 230 return true; |
| 234 } | 231 } |
| 235 | 232 |
| 236 if (include_platform_types && GetPlatformMimeTypeFromExtension(ext, result)) | 233 if (include_platform_types && GetPlatformMimeTypeFromExtension(ext, result)) |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 981 return CERTIFICATE_MIME_TYPE_UNKNOWN; | 978 return CERTIFICATE_MIME_TYPE_UNKNOWN; |
| 982 } | 979 } |
| 983 | 980 |
| 984 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | 981 bool IsSupportedCertificateMimeType(const std::string& mime_type) { |
| 985 CertificateMimeType file_type = | 982 CertificateMimeType file_type = |
| 986 GetCertificateMimeTypeForMimeType(mime_type); | 983 GetCertificateMimeTypeForMimeType(mime_type); |
| 987 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; | 984 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; |
| 988 } | 985 } |
| 989 | 986 |
| 990 } // namespace net | 987 } // namespace net |
| OLD | NEW |