Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: net/base/mime_util.cc

Issue 11266008: Fix certificate and keychain installation on Android. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 CryptoFileTypeInfo {
348 const char* mime_type;
349 CryptoFileType file_type;
350 };
351
352 static const CryptoFileTypeInfo supported_crypto_types[] = {
353 { "application/x-x509-user-cert", CRYPTO_FILE_TYPE_X509_USER_CERT },
354 #if defined(OS_ANDROID)
355 { "application/x-x509-ca-cert", CRYPTO_FILE_TYPE_X509_CA_CERT },
Ryan Sleevi 2012/10/24 22:01:25 Does Android not also need to handle application/x
digit1 2012/10/25 13:57:38 I've asked the Android folks responsible for this.
356 { "application/x-pkcs12", CRYPTO_FILE_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
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_crypto_types); ++i)
448 non_image_map_.insert(supported_crypto_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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 return false; 557 return false;
543 558
544 if (!right.empty() && 559 if (!right.empty() &&
545 mime_type.rfind(right) != mime_type.length() - right.length()) 560 mime_type.rfind(right) != mime_type.length() - right.length())
546 return false; 561 return false;
547 562
548 return true; 563 return true;
549 } 564 }
550 565
551 // See http://www.iana.org/assignments/media-types/index.html 566 // See http://www.iana.org/assignments/media-types/index.html
552 static const char* legal_top_level_types[] = { 567 static const char* const legal_top_level_types[] = {
Ryan Sleevi 2012/10/24 22:01:25 unrelated change? (but good change none the less,
digit1 2012/10/25 13:57:38 Sure, I've moved this to https://codereview.chromi
553 "application/", 568 "application/",
554 "audio/", 569 "audio/",
555 "example/", 570 "example/",
556 "image/", 571 "image/",
557 "message/", 572 "message/",
558 "model/", 573 "model/",
559 "multipart/", 574 "multipart/",
560 "text/", 575 "text/",
561 "video/", 576 "video/",
562 }; 577 };
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 void ParseCodecString(const std::string& codecs, 722 void ParseCodecString(const std::string& codecs,
708 std::vector<std::string>* codecs_out, 723 std::vector<std::string>* codecs_out,
709 const bool strip) { 724 const bool strip) {
710 g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); 725 g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip);
711 } 726 }
712 727
713 namespace { 728 namespace {
714 729
715 // From http://www.w3schools.com/media/media_mimeref.asp and 730 // From http://www.w3schools.com/media/media_mimeref.asp and
716 // http://plugindoc.mozdev.org/winmime.php 731 // http://plugindoc.mozdev.org/winmime.php
717 static const char* kStandardImageTypes[] = { 732 static const char* const kStandardImageTypes[] = {
718 "image/bmp", 733 "image/bmp",
719 "image/cis-cod", 734 "image/cis-cod",
720 "image/gif", 735 "image/gif",
721 "image/ief", 736 "image/ief",
722 "image/jpeg", 737 "image/jpeg",
723 "image/webp", 738 "image/webp",
724 "image/pict", 739 "image/pict",
725 "image/pipeg", 740 "image/pipeg",
726 "image/png", 741 "image/png",
727 "image/svg+xml", 742 "image/svg+xml",
728 "image/tiff", 743 "image/tiff",
729 "image/x-cmu-raster", 744 "image/x-cmu-raster",
730 "image/x-cmx", 745 "image/x-cmx",
731 "image/x-icon", 746 "image/x-icon",
732 "image/x-portable-anymap", 747 "image/x-portable-anymap",
733 "image/x-portable-bitmap", 748 "image/x-portable-bitmap",
734 "image/x-portable-graymap", 749 "image/x-portable-graymap",
735 "image/x-portable-pixmap", 750 "image/x-portable-pixmap",
736 "image/x-rgb", 751 "image/x-rgb",
737 "image/x-xbitmap", 752 "image/x-xbitmap",
738 "image/x-xpixmap", 753 "image/x-xpixmap",
739 "image/x-xwindowdump" 754 "image/x-xwindowdump"
740 }; 755 };
741 static const char* kStandardAudioTypes[] = { 756 static const char* const kStandardAudioTypes[] = {
742 "audio/aac", 757 "audio/aac",
743 "audio/aiff", 758 "audio/aiff",
744 "audio/amr", 759 "audio/amr",
745 "audio/basic", 760 "audio/basic",
746 "audio/midi", 761 "audio/midi",
747 "audio/mp3", 762 "audio/mp3",
748 "audio/mp4", 763 "audio/mp4",
749 "audio/mpeg", 764 "audio/mpeg",
750 "audio/mpeg3", 765 "audio/mpeg3",
751 "audio/ogg", 766 "audio/ogg",
752 "audio/vorbis", 767 "audio/vorbis",
753 "audio/wav", 768 "audio/wav",
754 "audio/webm", 769 "audio/webm",
755 "audio/x-m4a", 770 "audio/x-m4a",
756 "audio/x-ms-wma", 771 "audio/x-ms-wma",
757 "audio/vnd.rn-realaudio", 772 "audio/vnd.rn-realaudio",
758 "audio/vnd.wave" 773 "audio/vnd.wave"
759 }; 774 };
760 static const char* kStandardVideoTypes[] = { 775 static const char* const kStandardVideoTypes[] = {
761 "video/avi", 776 "video/avi",
762 "video/divx", 777 "video/divx",
763 "video/flc", 778 "video/flc",
764 "video/mp4", 779 "video/mp4",
765 "video/mpeg", 780 "video/mpeg",
766 "video/ogg", 781 "video/ogg",
767 "video/quicktime", 782 "video/quicktime",
768 "video/sd-video", 783 "video/sd-video",
769 "video/webm", 784 "video/webm",
770 "video/x-dv", 785 "video/x-dv",
771 "video/x-m4v", 786 "video/x-m4v",
772 "video/x-mpeg", 787 "video/x-mpeg",
773 "video/x-ms-asf", 788 "video/x-ms-asf",
774 "video/x-ms-wmv" 789 "video/x-ms-wmv"
775 }; 790 };
776 791
777 struct StandardType { 792 struct StandardType {
778 const char* leading_mime_type; 793 const char* leading_mime_type;
779 const char** standard_types; 794 const char* const* standard_types;
780 size_t standard_types_len; 795 size_t standard_types_len;
781 }; 796 };
782 static const StandardType kStandardTypes[] = { 797 static const StandardType kStandardTypes[] = {
783 { "image/", kStandardImageTypes, arraysize(kStandardImageTypes) }, 798 { "image/", kStandardImageTypes, arraysize(kStandardImageTypes) },
784 { "audio/", kStandardAudioTypes, arraysize(kStandardAudioTypes) }, 799 { "audio/", kStandardAudioTypes, arraysize(kStandardAudioTypes) },
785 { "video/", kStandardVideoTypes, arraysize(kStandardVideoTypes) }, 800 { "video/", kStandardVideoTypes, arraysize(kStandardVideoTypes) },
786 { NULL, NULL, 0 } 801 { NULL, NULL, 0 }
787 }; 802 };
788 803
789 void GetExtensionsFromHardCodedMappings( 804 void GetExtensionsFromHardCodedMappings(
(...skipping 12 matching lines...) Expand all
802 FilePath::StringType extension(UTF8ToWide(this_extensions[j])); 817 FilePath::StringType extension(UTF8ToWide(this_extensions[j]));
803 #else 818 #else
804 FilePath::StringType extension(this_extensions[j]); 819 FilePath::StringType extension(this_extensions[j]);
805 #endif 820 #endif
806 extensions->insert(extension); 821 extensions->insert(extension);
807 } 822 }
808 } 823 }
809 } 824 }
810 } 825 }
811 826
812 void GetExtensionsHelper(const char** standard_types, 827 void GetExtensionsHelper(const char* const* standard_types,
813 size_t standard_types_len, 828 size_t standard_types_len,
814 const std::string& leading_mime_type, 829 const std::string& leading_mime_type,
815 base::hash_set<FilePath::StringType>* extensions) { 830 base::hash_set<FilePath::StringType>* extensions) {
816 for (size_t i = 0; i < standard_types_len; ++i) { 831 for (size_t i = 0; i < standard_types_len; ++i) {
817 g_mime_util.Get().GetPlatformExtensionsForMimeType(standard_types[i], 832 g_mime_util.Get().GetPlatformExtensionsForMimeType(standard_types[i],
818 extensions); 833 extensions);
819 } 834 }
820 835
821 // Also look up the extensions from hard-coded mappings in case that some 836 // Also look up the extensions from hard-coded mappings in case that some
822 // supported extensions are not registered in the system registry, like ogg. 837 // supported extensions are not registered in the system registry, like ogg.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 CryptoFileType GetCryptoFileTypeForMimeType(
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_crypto_types); ++i) {
945 if (mime_type == net::supported_crypto_types[i].mime_type)
946 return net::supported_crypto_types[i].file_type;
947 }
948 return CRYPTO_FILE_TYPE_UNKNOWN;
949 }
950
951 bool IsSupportedCryptoMimeType(const std::string& mime_type) {
952 CryptoFileType file_type = GetCryptoFileTypeForMimeType(mime_type);
953 return file_type != CRYPTO_FILE_TYPE_UNKNOWN;
954 }
955
925 } // namespace net 956 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698