OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "net/base/mime_util.h" | 8 #include "net/base/mime_util.h" |
9 #include "net/base/platform_mime_util.h" | 9 #include "net/base/platform_mime_util.h" |
10 | 10 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (!*extensions) | 131 if (!*extensions) |
132 break; | 132 break; |
133 extensions += 1; // skip over comma | 133 extensions += 1; // skip over comma |
134 } | 134 } |
135 } | 135 } |
136 return NULL; | 136 return NULL; |
137 } | 137 } |
138 | 138 |
139 bool MimeUtil::GetMimeTypeFromExtension(const FilePath::StringType& ext, | 139 bool MimeUtil::GetMimeTypeFromExtension(const FilePath::StringType& ext, |
140 string* result) const { | 140 string* result) const { |
| 141 // Fixes a crash when xdg_mime library is unable to handle a long file path. |
| 142 const unsigned kMaxFilePathSize = 65536; |
| 143 if (ext.length() > kMaxFilePathSize) |
| 144 return false; |
| 145 |
141 // We implement the same algorithm as Mozilla for mapping a file extension to | 146 // We implement the same algorithm as Mozilla for mapping a file extension to |
142 // a mime type. That is, we first check a hard-coded list (that cannot be | 147 // a mime type. That is, we first check a hard-coded list (that cannot be |
143 // overridden), and then if not found there, we defer to the system registry. | 148 // overridden), and then if not found there, we defer to the system registry. |
144 // Finally, we scan a secondary hard-coded list to catch types that we can | 149 // Finally, we scan a secondary hard-coded list to catch types that we can |
145 // deduce but that we also want to allow the OS to override. | 150 // deduce but that we also want to allow the OS to override. |
146 | 151 |
147 #if defined(OS_WIN) | 152 #if defined(OS_WIN) |
148 string ext_narrow_str = WideToUTF8(ext); | 153 string ext_narrow_str = WideToUTF8(ext); |
149 #elif defined(OS_POSIX) | 154 #elif defined(OS_POSIX) |
150 const string& ext_narrow_str = ext; | 155 const string& ext_narrow_str = ext; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 return GetMimeUtil()->IsSupportedStrictMediaMimeType(mime_type, codecs); | 525 return GetMimeUtil()->IsSupportedStrictMediaMimeType(mime_type, codecs); |
521 } | 526 } |
522 | 527 |
523 void ParseCodecString(const std::string& codecs, | 528 void ParseCodecString(const std::string& codecs, |
524 std::vector<std::string>* codecs_out, | 529 std::vector<std::string>* codecs_out, |
525 const bool strip) { | 530 const bool strip) { |
526 GetMimeUtil()->ParseCodecString(codecs, codecs_out, strip); | 531 GetMimeUtil()->ParseCodecString(codecs, codecs_out, strip); |
527 } | 532 } |
528 | 533 |
529 } // namespace net | 534 } // namespace net |
OLD | NEW |