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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // behavior - css files will be displayed: | 332 // behavior - css files will be displayed: |
333 "text/css", | 333 "text/css", |
334 "text/vnd.chromium.ftp-dir", | 334 "text/vnd.chromium.ftp-dir", |
335 "text/", | 335 "text/", |
336 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type | 336 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type |
337 "application/xml", | 337 "application/xml", |
338 "application/atom+xml", | 338 "application/atom+xml", |
339 "application/rss+xml", | 339 "application/rss+xml", |
340 "application/xhtml+xml", | 340 "application/xhtml+xml", |
341 "application/json", | 341 "application/json", |
342 "application/x-x509-user-cert", | |
343 "multipart/related", // For MHTML support. | 342 "multipart/related", // For MHTML support. |
344 "multipart/x-mixed-replace" | 343 "multipart/x-mixed-replace" |
345 // Note: ADDING a new type here will probably render it AS HTML. This can | 344 // Note: ADDING a new type here will probably render it AS HTML. This can |
346 // result in cross site scripting. | 345 // result in cross site scripting. |
347 }; | 346 }; |
348 | 347 |
| 348 // Dictionary of cryptographic file mime types. |
| 349 struct CertificateTypeInfo { |
| 350 const char* mime_type; |
| 351 CertificateType cert_type; |
| 352 }; |
| 353 |
| 354 static const CertificateTypeInfo supported_certificate_types[] = { |
| 355 { "application/x-x509-user-cert", CERTIFICATE_TYPE_X509_USER_CERT }, |
| 356 #if defined(OS_ANDROID) |
| 357 { "application/x-x509-ca-cert", CERTIFICATE_TYPE_X509_CA_CERT }, |
| 358 { "application/x-pkcs12", CERTIFICATE_TYPE_PKCS12_ARCHIVE }, |
| 359 #endif |
| 360 }; |
| 361 |
349 // These types are excluded from the logic that allows all text/ types because | 362 // These types are excluded from the logic that allows all text/ types because |
350 // while they are technically text, it's very unlikely that a user expects to | 363 // while they are technically text, it's very unlikely that a user expects to |
351 // see them rendered in text form. | 364 // see them rendered in text form. |
352 static const char* const unsupported_text_types[] = { | 365 static const char* const unsupported_text_types[] = { |
353 "text/calendar", | 366 "text/calendar", |
354 "text/x-calendar", | 367 "text/x-calendar", |
355 "text/x-vcalendar", | 368 "text/x-vcalendar", |
356 "text/vcalendar", | 369 "text/vcalendar", |
357 "text/vcard", | 370 "text/vcard", |
358 "text/x-vcard", | 371 "text/x-vcard", |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 return !codecs.empty(); | 439 return !codecs.empty(); |
427 } | 440 } |
428 | 441 |
429 void MimeUtil::InitializeMimeTypeMaps() { | 442 void MimeUtil::InitializeMimeTypeMaps() { |
430 for (size_t i = 0; i < arraysize(supported_image_types); ++i) | 443 for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
431 image_map_.insert(supported_image_types[i]); | 444 image_map_.insert(supported_image_types[i]); |
432 | 445 |
433 // Initialize the supported non-image types. | 446 // Initialize the supported non-image types. |
434 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 447 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
435 non_image_map_.insert(supported_non_image_types[i]); | 448 non_image_map_.insert(supported_non_image_types[i]); |
| 449 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) |
| 450 non_image_map_.insert(supported_certificate_types[i].mime_type); |
436 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) | 451 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) |
437 unsupported_text_map_.insert(unsupported_text_types[i]); | 452 unsupported_text_map_.insert(unsupported_text_types[i]); |
438 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 453 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
439 non_image_map_.insert(supported_javascript_types[i]); | 454 non_image_map_.insert(supported_javascript_types[i]); |
440 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 455 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
441 non_image_map_.insert(common_media_types[i]); | 456 non_image_map_.insert(common_media_types[i]); |
442 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 457 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
443 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 458 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
444 non_image_map_.insert(proprietary_media_types[i]); | 459 non_image_map_.insert(proprietary_media_types[i]); |
445 #endif | 460 #endif |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 976 |
962 const std::string GetIANAMediaType(const std::string& mime_type) { | 977 const std::string GetIANAMediaType(const std::string& mime_type) { |
963 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { | 978 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { |
964 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { | 979 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { |
965 return kIanaMediaTypes[i].name; | 980 return kIanaMediaTypes[i].name; |
966 } | 981 } |
967 } | 982 } |
968 return ""; | 983 return ""; |
969 } | 984 } |
970 | 985 |
| 986 CertificateType GetCertificateTypeForMimeType( |
| 987 const std::string& mime_type) { |
| 988 // Don't create a map, there is only one entry in the table, |
| 989 // except on Android. |
| 990 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { |
| 991 if (mime_type == net::supported_certificate_types[i].mime_type) |
| 992 return net::supported_certificate_types[i].cert_type; |
| 993 } |
| 994 return CERTIFICATE_TYPE_UNKNOWN; |
| 995 } |
| 996 |
| 997 bool IsSupportedCertificateMimeType(const std::string& mime_type) { |
| 998 CertificateType file_type = GetCertificateTypeForMimeType(mime_type); |
| 999 return file_type != CERTIFICATE_TYPE_UNKNOWN; |
| 1000 } |
| 1001 |
971 } // namespace net | 1002 } // namespace net |
OLD | NEW |