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 "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
19 #include "net/base/platform_mime_util.h" | 19 #include "net/base/platform_mime_util.h" |
20 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
21 | 21 |
22 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
23 #include "base/android/build_info.h" | 23 #include "base/android/build_info.h" |
24 #endif | 24 #endif |
25 | 25 |
26 using std::string; | 26 using std::string; |
27 | 27 |
28 namespace { | |
29 | |
30 struct MediaType { | |
31 const char name[12]; | |
32 const char matcher[13]; | |
33 }; | |
34 | |
35 static const MediaType kIanaMediaTypes[] = { | |
36 { "application", "application/" }, | |
37 { "audio", "audio/" }, | |
38 { "example", "example/" }, | |
39 { "image", "image/" }, | |
40 { "message", "message/" }, | |
41 { "model", "model/" }, | |
42 { "multipart", "multipart/" }, | |
43 { "text", "text/" }, | |
44 { "video", "video/" }, | |
45 }; | |
46 | |
47 } // namespace | |
48 | |
49 namespace net { | 28 namespace net { |
50 | 29 |
51 // Singleton utility class for mime types. | 30 // Singleton utility class for mime types. |
52 class MimeUtil : public PlatformMimeUtil { | 31 class MimeUtil : public PlatformMimeUtil { |
53 public: | 32 public: |
54 enum Codec { | 33 enum Codec { |
55 INVALID_CODEC, | 34 INVALID_CODEC, |
56 PCM, | 35 PCM, |
57 MP3, | 36 MP3, |
58 MPEG2_AAC_LC, | 37 MPEG2_AAC_LC, |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 &unique_extensions); | 1336 &unique_extensions); |
1358 } | 1337 } |
1359 | 1338 |
1360 HashSetToVector(&unique_extensions, extensions); | 1339 HashSetToVector(&unique_extensions, extensions); |
1361 } | 1340 } |
1362 | 1341 |
1363 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 1342 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
1364 g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 1343 g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
1365 } | 1344 } |
1366 | 1345 |
1367 const std::string GetIANAMediaType(const std::string& mime_type) { | |
1368 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { | |
1369 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { | |
1370 return kIanaMediaTypes[i].name; | |
1371 } | |
1372 } | |
1373 return std::string(); | |
1374 } | |
1375 | |
1376 CertificateMimeType GetCertificateMimeTypeForMimeType( | 1346 CertificateMimeType GetCertificateMimeTypeForMimeType( |
1377 const std::string& mime_type) { | 1347 const std::string& mime_type) { |
1378 // Don't create a map, there is only one entry in the table, | 1348 // Don't create a map, there is only one entry in the table, |
1379 // except on Android. | 1349 // except on Android. |
1380 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { | 1350 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { |
1381 if (mime_type == net::supported_certificate_types[i].mime_type) | 1351 if (mime_type == net::supported_certificate_types[i].mime_type) |
1382 return net::supported_certificate_types[i].cert_type; | 1352 return net::supported_certificate_types[i].cert_type; |
1383 } | 1353 } |
1384 return CERTIFICATE_MIME_TYPE_UNKNOWN; | 1354 return CERTIFICATE_MIME_TYPE_UNKNOWN; |
1385 } | 1355 } |
(...skipping 23 matching lines...) Expand all Loading... |
1409 post_data->append("\r\n" + value + "\r\n"); | 1379 post_data->append("\r\n" + value + "\r\n"); |
1410 } | 1380 } |
1411 | 1381 |
1412 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1382 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
1413 std::string* post_data) { | 1383 std::string* post_data) { |
1414 DCHECK(post_data); | 1384 DCHECK(post_data); |
1415 post_data->append("--" + mime_boundary + "--\r\n"); | 1385 post_data->append("--" + mime_boundary + "--\r\n"); |
1416 } | 1386 } |
1417 | 1387 |
1418 } // namespace net | 1388 } // namespace net |
OLD | NEW |