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

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

Issue 1110833003: Move the IsSupported* mime functions out of //net and into //components/mime_util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 7 months 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
« no previous file with comments | « net/base/mime_util.h ('k') | net/base/mime_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 53 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
54 std::string* mime_type) const; 54 std::string* mime_type) const;
55 55
56 bool GetMimeTypeFromFile(const base::FilePath& file_path, 56 bool GetMimeTypeFromFile(const base::FilePath& file_path,
57 std::string* mime_type) const; 57 std::string* mime_type) const;
58 58
59 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, 59 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext,
60 std::string* mime_type) const; 60 std::string* mime_type) const;
61 61
62 bool IsSupportedImageMimeType(const std::string& mime_type) const;
63 bool IsSupportedMediaMimeType(const std::string& mime_type) const; 62 bool IsSupportedMediaMimeType(const std::string& mime_type) const;
64 bool IsSupportedNonImageMimeType(const std::string& mime_type) const;
65 bool IsUnsupportedTextMimeType(const std::string& mime_type) const;
66 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const;
67
68 bool IsSupportedMimeType(const std::string& mime_type) const;
69 63
70 bool MatchesMimeType(const std::string &mime_type_pattern, 64 bool MatchesMimeType(const std::string &mime_type_pattern,
71 const std::string &mime_type) const; 65 const std::string &mime_type) const;
72 66
73 bool ParseMimeTypeWithoutParameter(const std::string& type_string, 67 bool ParseMimeTypeWithoutParameter(const std::string& type_string,
74 std::string* top_level_type, 68 std::string* top_level_type,
75 std::string* subtype) const; 69 std::string* subtype) const;
76 70
77 bool IsValidTopLevelMimeType(const std::string& type_string) const; 71 bool IsValidTopLevelMimeType(const std::string& type_string) const;
78 72
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // associated with it. Returns false otherwise and the value of 140 // associated with it. Returns false otherwise and the value of
147 // |*default_codec| is undefined. 141 // |*default_codec| is undefined.
148 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, 142 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case,
149 Codec* default_codec) const; 143 Codec* default_codec) const;
150 144
151 // Returns true if |mime_type_lower_case| has a default codec associated with 145 // Returns true if |mime_type_lower_case| has a default codec associated with
152 // it and IsCodecSupported() returns true for that particular codec. 146 // it and IsCodecSupported() returns true for that particular codec.
153 bool IsDefaultCodecSupportedLowerCase( 147 bool IsDefaultCodecSupportedLowerCase(
154 const std::string& mime_type_lower_case) const; 148 const std::string& mime_type_lower_case) const;
155 149
156 MimeMappings image_map_;
157 MimeMappings media_map_; 150 MimeMappings media_map_;
158 MimeMappings non_image_map_;
159 MimeMappings unsupported_text_map_;
160 MimeMappings javascript_map_;
161 151
162 // A map of mime_types and hash map of the supported codecs for the mime_type. 152 // A map of mime_types and hash map of the supported codecs for the mime_type.
163 StrictMappings strict_format_map_; 153 StrictMappings strict_format_map_;
164 154
165 // Keeps track of whether proprietary codec support should be 155 // Keeps track of whether proprietary codec support should be
166 // advertised to callers. 156 // advertised to callers.
167 bool allow_proprietary_codecs_; 157 bool allow_proprietary_codecs_;
168 158
169 // Lookup table for string compare based string -> Codec mappings. 159 // Lookup table for string compare based string -> Codec mappings.
170 StringToCodecMappings string_to_codec_map_; 160 StringToCodecMappings string_to_codec_map_;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 mime_type = FindMimeType(secondary_mappings, arraysize(secondary_mappings), 290 mime_type = FindMimeType(secondary_mappings, arraysize(secondary_mappings),
301 ext_narrow_str.c_str()); 291 ext_narrow_str.c_str());
302 if (mime_type) { 292 if (mime_type) {
303 *result = mime_type; 293 *result = mime_type;
304 return true; 294 return true;
305 } 295 }
306 296
307 return false; 297 return false;
308 } 298 }
309 299
310 // From WebKit's WebCore/platform/MIMETypeRegistry.cpp:
311
312 static const char* const supported_image_types[] = {
313 "image/jpeg",
314 "image/pjpeg",
315 "image/jpg",
316 "image/webp",
317 "image/png",
318 "image/gif",
319 "image/bmp",
320 "image/vnd.microsoft.icon", // ico
321 "image/x-icon", // ico
322 "image/x-xbitmap", // xbm
323 "image/x-png"
324 };
325
326 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type 300 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type
327 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php 301 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php
328 // This set of codecs is supported by all variations of Chromium. 302 // This set of codecs is supported by all variations of Chromium.
329 static const char* const common_media_types[] = { 303 static const char* const common_media_types[] = {
330 // Ogg. 304 // Ogg.
331 "audio/ogg", 305 "audio/ogg",
332 "application/ogg", 306 "application/ogg",
333 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. 307 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
334 "video/ogg", 308 "video/ogg",
335 #endif 309 #endif
(...skipping 26 matching lines...) Expand all
362 "audio/x-mp3", 336 "audio/x-mp3",
363 "audio/mpeg", 337 "audio/mpeg",
364 "audio/aac", 338 "audio/aac",
365 339
366 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) 340 #if defined(ENABLE_MPEG2TS_STREAM_PARSER)
367 // MPEG-2 TS. 341 // MPEG-2 TS.
368 "video/mp2t", 342 "video/mp2t",
369 #endif 343 #endif
370 }; 344 };
371 345
372 // Note:
373 // - does not include javascript types list (see supported_javascript_types)
374 // - does not include types starting with "text/" (see
375 // IsSupportedNonImageMimeType())
376 static const char* const supported_non_image_types[] = {
377 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type
378 "application/xml",
379 "application/atom+xml",
380 "application/rss+xml",
381 "application/xhtml+xml",
382 "application/json",
383 "multipart/related", // For MHTML support.
384 "multipart/x-mixed-replace"
385 // Note: ADDING a new type here will probably render it AS HTML. This can
386 // result in cross site scripting.
387 };
388
389 // Dictionary of cryptographic file mime types.
390 struct CertificateMimeTypeInfo {
391 const char* const mime_type;
392 CertificateMimeType cert_type;
393 };
394
395 static const CertificateMimeTypeInfo supported_certificate_types[] = {
396 { "application/x-x509-user-cert",
397 CERTIFICATE_MIME_TYPE_X509_USER_CERT },
398 #if defined(OS_ANDROID)
399 { "application/x-x509-ca-cert", CERTIFICATE_MIME_TYPE_X509_CA_CERT },
400 { "application/x-pkcs12", CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE },
401 #endif
402 };
403
404 // These types are excluded from the logic that allows all text/ types because
405 // while they are technically text, it's very unlikely that a user expects to
406 // see them rendered in text form.
407 static const char* const unsupported_text_types[] = {
408 "text/calendar",
409 "text/x-calendar",
410 "text/x-vcalendar",
411 "text/vcalendar",
412 "text/vcard",
413 "text/x-vcard",
414 "text/directory",
415 "text/ldif",
416 "text/qif",
417 "text/x-qif",
418 "text/x-csv",
419 "text/x-vcf",
420 "text/rtf",
421 "text/comma-separated-values",
422 "text/csv",
423 "text/tab-separated-values",
424 "text/tsv",
425 "text/ofx", // http://crbug.com/162238
426 "text/vnd.sun.j2me.app-descriptor" // http://crbug.com/176450
427 };
428
429 // Mozilla 1.8 and WinIE 7 both accept text/javascript and text/ecmascript.
430 // Mozilla 1.8 accepts application/javascript, application/ecmascript, and
431 // application/x-javascript, but WinIE 7 doesn't.
432 // WinIE 7 accepts text/javascript1.1 - text/javascript1.3, text/jscript, and
433 // text/livescript, but Mozilla 1.8 doesn't.
434 // Mozilla 1.8 allows leading and trailing whitespace, but WinIE 7 doesn't.
435 // Mozilla 1.8 and WinIE 7 both accept the empty string, but neither accept a
436 // whitespace-only string.
437 // We want to accept all the values that either of these browsers accept, but
438 // not other values.
439 static const char* const supported_javascript_types[] = {
440 "text/javascript",
441 "text/ecmascript",
442 "application/javascript",
443 "application/ecmascript",
444 "application/x-javascript",
445 "text/javascript1.1",
446 "text/javascript1.2",
447 "text/javascript1.3",
448 "text/jscript",
449 "text/livescript"
450 };
451
452 #if defined(OS_ANDROID) 346 #if defined(OS_ANDROID)
453 static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { 347 static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) {
454 switch (codec) { 348 switch (codec) {
455 case MimeUtil::INVALID_CODEC: 349 case MimeUtil::INVALID_CODEC:
456 return false; 350 return false;
457 351
458 case MimeUtil::PCM: 352 case MimeUtil::PCM:
459 case MimeUtil::MP3: 353 case MimeUtil::MP3:
460 case MimeUtil::MPEG4_AAC_LC: 354 case MimeUtil::MPEG4_AAC_LC:
461 case MimeUtil::MPEG4_AAC_SBR_v1: 355 case MimeUtil::MPEG4_AAC_SBR_v1:
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 510 }
617 511
618 if (is_ambiguous) 512 if (is_ambiguous)
619 result = MayBeSupported; 513 result = MayBeSupported;
620 } 514 }
621 515
622 return result; 516 return result;
623 } 517 }
624 518
625 void MimeUtil::InitializeMimeTypeMaps() { 519 void MimeUtil::InitializeMimeTypeMaps() {
626 for (size_t i = 0; i < arraysize(supported_image_types); ++i) 520 // Initialize the supported media types.
627 image_map_.insert(supported_image_types[i]); 521 for (size_t i = 0; i < arraysize(common_media_types); ++i)
628 522 media_map_.insert(common_media_types[i]);
629 // Initialize the supported non-image types.
630 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i)
631 non_image_map_.insert(supported_non_image_types[i]);
632 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i)
633 non_image_map_.insert(supported_certificate_types[i].mime_type);
634 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i)
635 unsupported_text_map_.insert(unsupported_text_types[i]);
636 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
637 non_image_map_.insert(supported_javascript_types[i]);
638 for (size_t i = 0; i < arraysize(common_media_types); ++i) {
639 non_image_map_.insert(common_media_types[i]);
640 }
641 #if defined(USE_PROPRIETARY_CODECS) 523 #if defined(USE_PROPRIETARY_CODECS)
642 allow_proprietary_codecs_ = true; 524 allow_proprietary_codecs_ = true;
643 525
644 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) 526 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
645 non_image_map_.insert(proprietary_media_types[i]);
646 #endif
647
648 // Initialize the supported media types.
649 for (size_t i = 0; i < arraysize(common_media_types); ++i) {
650 media_map_.insert(common_media_types[i]);
651 }
652 #if defined(USE_PROPRIETARY_CODECS)
653 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
654 media_map_.insert(proprietary_media_types[i]); 527 media_map_.insert(proprietary_media_types[i]);
655 #endif 528 #endif
656 529
657 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
658 javascript_map_.insert(supported_javascript_types[i]);
659
660 for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) { 530 for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) {
661 string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] = 531 string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] =
662 CodecEntry(kUnambiguousCodecStringMap[i].codec, false); 532 CodecEntry(kUnambiguousCodecStringMap[i].codec, false);
663 } 533 }
664 534
665 for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) { 535 for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) {
666 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = 536 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] =
667 CodecEntry(kAmbiguousCodecStringMap[i].codec, true); 537 CodecEntry(kAmbiguousCodecStringMap[i].codec, true);
668 } 538 }
669 539
(...skipping 10 matching lines...) Expand all
680 bool is_ambiguous = true; 550 bool is_ambiguous = true;
681 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); 551 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous));
682 DCHECK(!is_ambiguous); 552 DCHECK(!is_ambiguous);
683 codecs.insert(codec); 553 codecs.insert(codec);
684 } 554 }
685 555
686 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; 556 strict_format_map_[format_codec_mappings[i].mime_type] = codecs;
687 } 557 }
688 } 558 }
689 559
690 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const {
691 return image_map_.find(base::StringToLowerASCII(mime_type)) !=
692 image_map_.end();
693 }
694
695 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { 560 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const {
696 return media_map_.find(base::StringToLowerASCII(mime_type)) != 561 return media_map_.find(base::StringToLowerASCII(mime_type)) !=
697 media_map_.end(); 562 media_map_.end();
698 } 563 }
699 564
700 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const {
701 return non_image_map_.find(base::StringToLowerASCII(mime_type)) !=
702 non_image_map_.end() ||
703 (StartsWithASCII(mime_type, "text/", false /* case insensitive */) &&
704 !IsUnsupportedTextMimeType(mime_type)) ||
705 (StartsWithASCII(mime_type, "application/", false) &&
706 MatchesMimeType("application/*+json", mime_type));
707 }
708
709 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const {
710 return unsupported_text_map_.find(base::StringToLowerASCII(mime_type)) !=
711 unsupported_text_map_.end();
712 }
713
714 bool MimeUtil::IsSupportedJavascriptMimeType(
715 const std::string& mime_type) const {
716 return javascript_map_.find(mime_type) != javascript_map_.end();
717 }
718
719 // Mirrors WebViewImpl::CanShowMIMEType()
720 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const {
721 return (StartsWithASCII(mime_type, "image/", false) &&
722 IsSupportedImageMimeType(mime_type)) ||
723 IsSupportedNonImageMimeType(mime_type);
724 }
725
726 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| 565 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern|
727 // must be matched by a parameter in the |mime_type|. If there are no 566 // must be matched by a parameter in the |mime_type|. If there are no
728 // parameters in the pattern, the match is a success. 567 // parameters in the pattern, the match is a success.
729 // 568 //
730 // According rfc2045 keys of parameters are case-insensitive, while values may 569 // According rfc2045 keys of parameters are case-insensitive, while values may
731 // or may not be case-sensitive, but they are usually case-sensitive. So, this 570 // or may not be case-sensitive, but they are usually case-sensitive. So, this
732 // function matches values in *case-sensitive* manner, however note that this 571 // function matches values in *case-sensitive* manner, however note that this
733 // may produce some false negatives. 572 // may produce some false negatives.
734 bool MatchesMimeTypeParameters(const std::string& mime_type_pattern, 573 bool MatchesMimeTypeParameters(const std::string& mime_type_pattern,
735 const std::string& mime_type) { 574 const std::string& mime_type) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) 767 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec))
929 return MayBeSupported; 768 return MayBeSupported;
930 769
931 return IsCodecSupported(default_codec) ? IsSupported : IsNotSupported; 770 return IsCodecSupported(default_codec) ? IsSupported : IsNotSupported;
932 } 771 }
933 772
934 return AreSupportedCodecs(it_strict_map->second, codecs); 773 return AreSupportedCodecs(it_strict_map->second, codecs);
935 } 774 }
936 775
937 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { 776 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() {
938 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { 777 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
939 non_image_map_.erase(proprietary_media_types[i]);
940 media_map_.erase(proprietary_media_types[i]); 778 media_map_.erase(proprietary_media_types[i]);
941 }
942 allow_proprietary_codecs_ = false; 779 allow_proprietary_codecs_ = false;
943 } 780 }
944 781
945 // Returns true iff |profile_str| conforms to hex string "42y0", where y is one 782 // Returns true iff |profile_str| conforms to hex string "42y0", where y is one
946 // of [8..F]. Requiring constraint_set0_flag be set and profile_idc be 0x42 is 783 // of [8..F]. Requiring constraint_set0_flag be set and profile_idc be 0x42 is
947 // taken from ISO-14496-10 7.3.2.1, 7.4.2.1, and Annex A.2.1. 784 // taken from ISO-14496-10 7.3.2.1, 7.4.2.1, and Annex A.2.1.
948 // 785 //
949 // |profile_str| is the first four characters of the H.264 suffix string 786 // |profile_str| is the first four characters of the H.264 suffix string
950 // (ignoring the last 2 characters of the full 6 character suffix that are 787 // (ignoring the last 2 characters of the full 6 character suffix that are
951 // level_idc). From ISO-14496-10 7.3.2.1, it consists of: 788 // level_idc). From ISO-14496-10 7.3.2.1, it consists of:
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 std::string* mime_type) { 956 std::string* mime_type) {
1120 return g_mime_util.Get().GetWellKnownMimeTypeFromExtension(ext, mime_type); 957 return g_mime_util.Get().GetWellKnownMimeTypeFromExtension(ext, mime_type);
1121 } 958 }
1122 959
1123 bool GetPreferredExtensionForMimeType(const std::string& mime_type, 960 bool GetPreferredExtensionForMimeType(const std::string& mime_type,
1124 base::FilePath::StringType* extension) { 961 base::FilePath::StringType* extension) {
1125 return g_mime_util.Get().GetPreferredExtensionForMimeType(mime_type, 962 return g_mime_util.Get().GetPreferredExtensionForMimeType(mime_type,
1126 extension); 963 extension);
1127 } 964 }
1128 965
1129 bool IsSupportedImageMimeType(const std::string& mime_type) {
1130 return g_mime_util.Get().IsSupportedImageMimeType(mime_type);
1131 }
1132
1133 bool IsSupportedMediaMimeType(const std::string& mime_type) { 966 bool IsSupportedMediaMimeType(const std::string& mime_type) {
1134 return g_mime_util.Get().IsSupportedMediaMimeType(mime_type); 967 return g_mime_util.Get().IsSupportedMediaMimeType(mime_type);
1135 } 968 }
1136 969
1137 bool IsSupportedNonImageMimeType(const std::string& mime_type) {
1138 return g_mime_util.Get().IsSupportedNonImageMimeType(mime_type);
1139 }
1140
1141 bool IsUnsupportedTextMimeType(const std::string& mime_type) {
1142 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type);
1143 }
1144
1145 bool IsSupportedJavascriptMimeType(const std::string& mime_type) {
1146 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type);
1147 }
1148
1149 bool IsSupportedMimeType(const std::string& mime_type) {
1150 return g_mime_util.Get().IsSupportedMimeType(mime_type);
1151 }
1152
1153 bool MatchesMimeType(const std::string& mime_type_pattern, 970 bool MatchesMimeType(const std::string& mime_type_pattern,
1154 const std::string& mime_type) { 971 const std::string& mime_type) {
1155 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); 972 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type);
1156 } 973 }
1157 974
1158 bool ParseMimeTypeWithoutParameter(const std::string& type_string, 975 bool ParseMimeTypeWithoutParameter(const std::string& type_string,
1159 std::string* top_level_type, 976 std::string* top_level_type,
1160 std::string* subtype) { 977 std::string* subtype) {
1161 return g_mime_util.Get().ParseMimeTypeWithoutParameter( 978 return g_mime_util.Get().ParseMimeTypeWithoutParameter(
1162 type_string, top_level_type, subtype); 979 type_string, top_level_type, subtype);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 &unique_extensions); 1182 &unique_extensions);
1366 } 1183 }
1367 1184
1368 HashSetToVector(&unique_extensions, extensions); 1185 HashSetToVector(&unique_extensions, extensions);
1369 } 1186 }
1370 1187
1371 void RemoveProprietaryMediaTypesAndCodecsForTests() { 1188 void RemoveProprietaryMediaTypesAndCodecsForTests() {
1372 g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); 1189 g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests();
1373 } 1190 }
1374 1191
1375 CertificateMimeType GetCertificateMimeTypeForMimeType(
1376 const std::string& mime_type) {
1377 // Don't create a map, there is only one entry in the table,
1378 // except on Android.
1379 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) {
1380 if (base::strcasecmp(mime_type.c_str(),
1381 supported_certificate_types[i].mime_type) == 0) {
1382 return supported_certificate_types[i].cert_type;
1383 }
1384 }
1385 return CERTIFICATE_MIME_TYPE_UNKNOWN;
1386 }
1387
1388 bool IsSupportedCertificateMimeType(const std::string& mime_type) {
1389 CertificateMimeType file_type =
1390 GetCertificateMimeTypeForMimeType(mime_type);
1391 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN;
1392 }
1393
1394 void AddMultipartValueForUpload(const std::string& value_name, 1192 void AddMultipartValueForUpload(const std::string& value_name,
1395 const std::string& value, 1193 const std::string& value,
1396 const std::string& mime_boundary, 1194 const std::string& mime_boundary,
1397 const std::string& content_type, 1195 const std::string& content_type,
1398 std::string* post_data) { 1196 std::string* post_data) {
1399 DCHECK(post_data); 1197 DCHECK(post_data);
1400 // First line is the boundary. 1198 // First line is the boundary.
1401 post_data->append("--" + mime_boundary + "\r\n"); 1199 post_data->append("--" + mime_boundary + "\r\n");
1402 // Next line is the Content-disposition. 1200 // Next line is the Content-disposition.
1403 post_data->append("Content-Disposition: form-data; name=\"" + 1201 post_data->append("Content-Disposition: form-data; name=\"" +
1404 value_name + "\"\r\n"); 1202 value_name + "\"\r\n");
1405 if (!content_type.empty()) { 1203 if (!content_type.empty()) {
1406 // If Content-type is specified, the next line is that. 1204 // If Content-type is specified, the next line is that.
1407 post_data->append("Content-Type: " + content_type + "\r\n"); 1205 post_data->append("Content-Type: " + content_type + "\r\n");
1408 } 1206 }
1409 // Leave an empty line and append the value. 1207 // Leave an empty line and append the value.
1410 post_data->append("\r\n" + value + "\r\n"); 1208 post_data->append("\r\n" + value + "\r\n");
1411 } 1209 }
1412 1210
1413 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1211 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1414 std::string* post_data) { 1212 std::string* post_data) {
1415 DCHECK(post_data); 1213 DCHECK(post_data);
1416 post_data->append("--" + mime_boundary + "--\r\n"); 1214 post_data->append("--" + mime_boundary + "--\r\n");
1417 } 1215 }
1418 1216
1419 } // namespace net 1217 } // namespace net
OLDNEW
« no previous file with comments | « net/base/mime_util.h ('k') | net/base/mime_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698