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" |
| 11 #include "net/base/platform_mime_util.h" | 11 #include "net/base/platform_mime_util.h" |
| 12 | 12 |
| 13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 18 #include "base/strings/sys_string_conversions.h" | |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 19 | 20 |
| 20 using std::string; | 21 using std::string; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 struct MediaType { | 25 struct MediaType { |
| 25 const char name[12]; | 26 const char name[12]; |
| 26 const char matcher[13]; | 27 const char matcher[13]; |
| 27 }; | 28 }; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 return false; | 215 return false; |
| 215 | 216 |
| 216 // We implement the same algorithm as Mozilla for mapping a file extension to | 217 // 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 | 218 // 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. | 219 // 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 | 220 // 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. | 221 // deduce but that we also want to allow the OS to override. |
| 221 | 222 |
| 222 #if defined(OS_WIN) | 223 #if defined(OS_WIN) |
| 223 string ext_narrow_str = WideToUTF8(ext); | 224 string ext_narrow_str = WideToUTF8(ext); |
| 224 #elif defined(OS_POSIX) | 225 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 225 const string& ext_narrow_str = ext; | 226 const string& ext_narrow_str = ext; |
| 227 #else | |
| 228 const string& ext_narrow_str = WideToUTF8(base::SysNativeMBToWide(ext)); | |
|
Bernhard Bauer
2013/05/28 21:26:14
Why don't you just use FilePath::AsUTF8Unsafe? The
mrunal
2013/05/28 21:38:47
Because FilePath::AsUTF8Unsafe() is not a static f
Bernhard Bauer
2013/05/28 22:04:00
Right, just construct a new FilePath (which copies
mrunal
2013/05/28 22:41:02
Yeah that will be bit ugly but I get your point no
| |
| 226 #endif | 229 #endif |
| 227 const char* mime_type; | 230 const char* mime_type; |
| 228 | 231 |
| 229 mime_type = FindMimeType(primary_mappings, arraysize(primary_mappings), | 232 mime_type = FindMimeType(primary_mappings, arraysize(primary_mappings), |
| 230 ext_narrow_str.c_str()); | 233 ext_narrow_str.c_str()); |
| 231 if (mime_type) { | 234 if (mime_type) { |
| 232 *result = mime_type; | 235 *result = mime_type; |
| 233 return true; | 236 return true; |
| 234 } | 237 } |
| 235 | 238 |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 981 return CERTIFICATE_MIME_TYPE_UNKNOWN; | 984 return CERTIFICATE_MIME_TYPE_UNKNOWN; |
| 982 } | 985 } |
| 983 | 986 |
| 984 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | 987 bool IsSupportedCertificateMimeType(const std::string& mime_type) { |
| 985 CertificateMimeType file_type = | 988 CertificateMimeType file_type = |
| 986 GetCertificateMimeTypeForMimeType(mime_type); | 989 GetCertificateMimeTypeForMimeType(mime_type); |
| 987 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; | 990 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; |
| 988 } | 991 } |
| 989 | 992 |
| 990 } // namespace net | 993 } // namespace net |
| OLD | NEW |