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 <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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 // behavior - css files will be displayed: | 330 // behavior - css files will be displayed: |
331 "text/css", | 331 "text/css", |
332 "text/vnd.chromium.ftp-dir", | 332 "text/vnd.chromium.ftp-dir", |
333 "text/", | 333 "text/", |
334 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type | 334 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type |
335 "application/xml", | 335 "application/xml", |
336 "application/atom+xml", | 336 "application/atom+xml", |
337 "application/rss+xml", | 337 "application/rss+xml", |
338 "application/xhtml+xml", | 338 "application/xhtml+xml", |
339 "application/json", | 339 "application/json", |
340 "application/x-x509-user-cert", | |
341 "multipart/related", // For MHTML support. | 340 "multipart/related", // For MHTML support. |
342 "multipart/x-mixed-replace" | 341 "multipart/x-mixed-replace" |
343 // Note: ADDING a new type here will probably render it AS HTML. This can | 342 // Note: ADDING a new type here will probably render it AS HTML. This can |
344 // result in cross site scripting. | 343 // result in cross site scripting. |
345 }; | 344 }; |
346 | 345 |
346 // Dictionary of cryptographic file mime types. | |
347 struct CertificateTypeInfo { | |
348 const char* mime_type; | |
349 CertificateType cert_type; | |
350 }; | |
351 | |
352 static const CertificateTypeInfo supported_certificate_types[] = { | |
Ryan Sleevi
2012/11/13 19:37:50
nit: whitespace (" " should be " ")
| |
353 { "application/x-x509-user-cert", CERTIFICATE_TYPE_X509_USER_CERT }, | |
354 #if defined(OS_ANDROID) | |
355 { "application/x-x509-ca-cert", CERTIFICATE_TYPE_X509_CA_CERT }, | |
356 { "application/x-pkcs12", CERTIFICATE_TYPE_PKCS12_KEYCHAIN }, | |
357 #endif | |
358 }; | |
359 | |
347 // These types are excluded from the logic that allows all text/ types because | 360 // These types are excluded from the logic that allows all text/ types because |
348 // while they are technically text, it's very unlikely that a user expects to | 361 // while they are technically text, it's very unlikely that a user expects to |
349 // see them rendered in text form. | 362 // see them rendered in text form. |
350 static const char* const unsupported_text_types[] = { | 363 static const char* const unsupported_text_types[] = { |
351 "text/calendar", | 364 "text/calendar", |
352 "text/x-calendar", | 365 "text/x-calendar", |
353 "text/x-vcalendar", | 366 "text/x-vcalendar", |
354 "text/vcalendar", | 367 "text/vcalendar", |
355 "text/vcard", | 368 "text/vcard", |
356 "text/x-vcard", | 369 "text/x-vcard", |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 return !codecs.empty(); | 437 return !codecs.empty(); |
425 } | 438 } |
426 | 439 |
427 void MimeUtil::InitializeMimeTypeMaps() { | 440 void MimeUtil::InitializeMimeTypeMaps() { |
428 for (size_t i = 0; i < arraysize(supported_image_types); ++i) | 441 for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
429 image_map_.insert(supported_image_types[i]); | 442 image_map_.insert(supported_image_types[i]); |
430 | 443 |
431 // Initialize the supported non-image types. | 444 // Initialize the supported non-image types. |
432 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 445 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
433 non_image_map_.insert(supported_non_image_types[i]); | 446 non_image_map_.insert(supported_non_image_types[i]); |
447 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) | |
448 non_image_map_.insert(supported_certificate_types[i].mime_type); | |
434 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) | 449 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) |
435 unsupported_text_map_.insert(unsupported_text_types[i]); | 450 unsupported_text_map_.insert(unsupported_text_types[i]); |
436 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 451 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
437 non_image_map_.insert(supported_javascript_types[i]); | 452 non_image_map_.insert(supported_javascript_types[i]); |
438 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 453 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
439 non_image_map_.insert(common_media_types[i]); | 454 non_image_map_.insert(common_media_types[i]); |
440 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 455 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
441 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 456 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
442 non_image_map_.insert(proprietary_media_types[i]); | 457 non_image_map_.insert(proprietary_media_types[i]); |
443 #endif | 458 #endif |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 | 930 |
916 const std::string GetIANAMediaType(const std::string& mime_type) { | 931 const std::string GetIANAMediaType(const std::string& mime_type) { |
917 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { | 932 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { |
918 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { | 933 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { |
919 return kIanaMediaTypes[i].name; | 934 return kIanaMediaTypes[i].name; |
920 } | 935 } |
921 } | 936 } |
922 return ""; | 937 return ""; |
923 } | 938 } |
924 | 939 |
940 CertificateType GetCertificateTypeForMimeType( | |
941 const std::string& mime_type) { | |
942 // Don't create a map, there is only one entry in the table, | |
943 // except on Android. | |
944 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { | |
945 if (mime_type == net::supported_certificate_types[i].mime_type) | |
946 return net::supported_certificate_types[i].cert_type; | |
Ryan Sleevi
2012/11/13 19:37:50
nit: indentation
| |
947 } | |
948 return CERTIFICATE_TYPE_UNKNOWN; | |
949 } | |
950 | |
951 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | |
952 CertificateType file_type = GetCertificateTypeForMimeType(mime_type); | |
953 return file_type != CERTIFICATE_TYPE_UNKNOWN; | |
954 } | |
955 | |
925 } // namespace net | 956 } // namespace net |
OLD | NEW |