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 CertificateMimeTypeInfo { | |
350 const char* mime_type; | |
351 CertificateMimeType cert_type; | |
352 }; | |
353 | |
354 static const CertificateMimeTypeInfo supported_certificate_types[] = { | |
355 { "application/x-x509-user-cert", | |
darin (slow to review)
2012/11/27 05:24:34
nit: indentation is wrong
digit1
2012/11/27 10:19:48
I treated this a a line-continuation indent. Do yo
darin (slow to review)
2012/11/27 21:27:53
It's an array, much like supported_non_image_types
digit1
2012/11/27 22:33:04
Oh snap. Of course, I wasn't looking at the right
| |
356 CERTIFICATE_MIME_TYPE_X509_USER_CERT }, | |
357 #if defined(OS_ANDROID) | |
358 { "application/x-x509-ca-cert", CERTIFICATE_MIME_TYPE_X509_CA_CERT }, | |
359 { "application/x-pkcs12", | |
360 CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE }, | |
361 #endif | |
362 }; | |
363 | |
349 // These types are excluded from the logic that allows all text/ types because | 364 // 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 | 365 // while they are technically text, it's very unlikely that a user expects to |
351 // see them rendered in text form. | 366 // see them rendered in text form. |
352 static const char* const unsupported_text_types[] = { | 367 static const char* const unsupported_text_types[] = { |
353 "text/calendar", | 368 "text/calendar", |
354 "text/x-calendar", | 369 "text/x-calendar", |
355 "text/x-vcalendar", | 370 "text/x-vcalendar", |
356 "text/vcalendar", | 371 "text/vcalendar", |
357 "text/vcard", | 372 "text/vcard", |
358 "text/x-vcard", | 373 "text/x-vcard", |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 return !codecs.empty(); | 441 return !codecs.empty(); |
427 } | 442 } |
428 | 443 |
429 void MimeUtil::InitializeMimeTypeMaps() { | 444 void MimeUtil::InitializeMimeTypeMaps() { |
430 for (size_t i = 0; i < arraysize(supported_image_types); ++i) | 445 for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
431 image_map_.insert(supported_image_types[i]); | 446 image_map_.insert(supported_image_types[i]); |
432 | 447 |
433 // Initialize the supported non-image types. | 448 // Initialize the supported non-image types. |
434 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 449 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
435 non_image_map_.insert(supported_non_image_types[i]); | 450 non_image_map_.insert(supported_non_image_types[i]); |
451 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) | |
452 non_image_map_.insert(supported_certificate_types[i].mime_type); | |
436 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) | 453 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) |
437 unsupported_text_map_.insert(unsupported_text_types[i]); | 454 unsupported_text_map_.insert(unsupported_text_types[i]); |
438 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 455 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
439 non_image_map_.insert(supported_javascript_types[i]); | 456 non_image_map_.insert(supported_javascript_types[i]); |
440 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 457 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
441 non_image_map_.insert(common_media_types[i]); | 458 non_image_map_.insert(common_media_types[i]); |
442 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 459 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
443 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 460 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
444 non_image_map_.insert(proprietary_media_types[i]); | 461 non_image_map_.insert(proprietary_media_types[i]); |
445 #endif | 462 #endif |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 | 978 |
962 const std::string GetIANAMediaType(const std::string& mime_type) { | 979 const std::string GetIANAMediaType(const std::string& mime_type) { |
963 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { | 980 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { |
964 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { | 981 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { |
965 return kIanaMediaTypes[i].name; | 982 return kIanaMediaTypes[i].name; |
966 } | 983 } |
967 } | 984 } |
968 return ""; | 985 return ""; |
969 } | 986 } |
970 | 987 |
988 CertificateMimeType GetCertificateMimeTypeForMimeType( | |
989 const std::string& mime_type) { | |
990 // Don't create a map, there is only one entry in the table, | |
991 // except on Android. | |
992 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { | |
993 if (mime_type == net::supported_certificate_types[i].mime_type) | |
994 return net::supported_certificate_types[i].cert_type; | |
995 } | |
996 return CERTIFICATE_MIME_TYPE_UNKNOWN; | |
997 } | |
998 | |
999 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | |
1000 CertificateMimeType file_type = | |
1001 GetCertificateMimeTypeForMimeType(mime_type); | |
1002 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; | |
1003 } | |
1004 | |
971 } // namespace net | 1005 } // namespace net |
OLD | NEW |