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 "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 std::string* mime_type) const; | 56 std::string* mime_type) const; |
57 | 57 |
58 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, | 58 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, |
59 std::string* mime_type) const; | 59 std::string* mime_type) const; |
60 | 60 |
61 bool IsSupportedImageMimeType(const std::string& mime_type) const; | 61 bool IsSupportedImageMimeType(const std::string& mime_type) const; |
62 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 62 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
63 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; | 63 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; |
64 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; | 64 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; |
65 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; | 65 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; |
66 bool IsSupportedDartMimeType(const std::string& mime_type) const; | |
67 | 66 |
68 bool IsSupportedMimeType(const std::string& mime_type) const; | 67 bool IsSupportedMimeType(const std::string& mime_type) const; |
69 | 68 |
70 bool MatchesMimeType(const std::string &mime_type_pattern, | 69 bool MatchesMimeType(const std::string &mime_type_pattern, |
71 const std::string &mime_type) const; | 70 const std::string &mime_type) const; |
72 | 71 |
73 bool IsMimeType(const std::string& type_string) const; | 72 bool IsMimeType(const std::string& type_string) const; |
74 | 73 |
75 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; | 74 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; |
76 | 75 |
(...skipping 26 matching lines...) Expand all Loading... |
103 | 102 |
104 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext, | 103 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext, |
105 bool include_platform_types, | 104 bool include_platform_types, |
106 std::string* mime_type) const; | 105 std::string* mime_type) const; |
107 | 106 |
108 MimeMappings image_map_; | 107 MimeMappings image_map_; |
109 MimeMappings media_map_; | 108 MimeMappings media_map_; |
110 MimeMappings non_image_map_; | 109 MimeMappings non_image_map_; |
111 MimeMappings unsupported_text_map_; | 110 MimeMappings unsupported_text_map_; |
112 MimeMappings javascript_map_; | 111 MimeMappings javascript_map_; |
113 MimeMappings dart_map_; | |
114 MimeMappings codecs_map_; | 112 MimeMappings codecs_map_; |
115 | 113 |
116 StrictMappings strict_format_map_; | 114 StrictMappings strict_format_map_; |
117 }; // class MimeUtil | 115 }; // class MimeUtil |
118 | 116 |
119 // This variable is Leaky because we need to access it from WorkerPool threads. | 117 // This variable is Leaky because we need to access it from WorkerPool threads. |
120 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = | 118 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
121 LAZY_INSTANCE_INITIALIZER; | 119 LAZY_INSTANCE_INITIALIZER; |
122 | 120 |
123 struct MimeInfo { | 121 struct MimeInfo { |
(...skipping 21 matching lines...) Expand all Loading... |
145 { "application/x-chrome-extension", "crx" }, | 143 { "application/x-chrome-extension", "crx" }, |
146 { "multipart/related", "mhtml,mht" } | 144 { "multipart/related", "mhtml,mht" } |
147 }; | 145 }; |
148 | 146 |
149 static const MimeInfo secondary_mappings[] = { | 147 static const MimeInfo secondary_mappings[] = { |
150 { "application/octet-stream", "exe,com,bin" }, | 148 { "application/octet-stream", "exe,com,bin" }, |
151 { "application/gzip", "gz" }, | 149 { "application/gzip", "gz" }, |
152 { "application/pdf", "pdf" }, | 150 { "application/pdf", "pdf" }, |
153 { "application/postscript", "ps,eps,ai" }, | 151 { "application/postscript", "ps,eps,ai" }, |
154 { "application/javascript", "js" }, | 152 { "application/javascript", "js" }, |
155 { "application/dart", "dart" }, | |
156 { "application/font-woff", "woff" }, | 153 { "application/font-woff", "woff" }, |
157 { "image/bmp", "bmp" }, | 154 { "image/bmp", "bmp" }, |
158 { "image/x-icon", "ico" }, | 155 { "image/x-icon", "ico" }, |
159 { "image/vnd.microsoft.icon", "ico" }, | 156 { "image/vnd.microsoft.icon", "ico" }, |
160 { "image/jpeg", "jfif,pjpeg,pjp" }, | 157 { "image/jpeg", "jfif,pjpeg,pjp" }, |
161 { "image/tiff", "tiff,tif" }, | 158 { "image/tiff", "tiff,tif" }, |
162 { "image/x-xbitmap", "xbm" }, | 159 { "image/x-xbitmap", "xbm" }, |
163 { "image/svg+xml", "svg,svgz" }, | 160 { "image/svg+xml", "svg,svgz" }, |
164 { "message/rfc822", "eml" }, | 161 { "message/rfc822", "eml" }, |
165 { "text/plain", "txt,text" }, | 162 { "text/plain", "txt,text" }, |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 419 |
423 // TODO(vigneshv): Change this similar to the VP9 check once Opus is | 420 // TODO(vigneshv): Change this similar to the VP9 check once Opus is |
424 // supported on Android (http://crbug.com/318436). | 421 // supported on Android (http://crbug.com/318436). |
425 if (!codec.compare("opus")) { | 422 if (!codec.compare("opus")) { |
426 return false; | 423 return false; |
427 } | 424 } |
428 return true; | 425 return true; |
429 } | 426 } |
430 #endif | 427 #endif |
431 | 428 |
432 static const char* const supported_dart_types[] = { | |
433 "application/dart", | |
434 }; | |
435 | |
436 struct MediaFormatStrict { | 429 struct MediaFormatStrict { |
437 const char* mime_type; | 430 const char* mime_type; |
438 const char* codecs_list; | 431 const char* codecs_list; |
439 }; | 432 }; |
440 | 433 |
441 static const MediaFormatStrict format_codec_mappings[] = { | 434 static const MediaFormatStrict format_codec_mappings[] = { |
442 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, | 435 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, |
443 { "audio/webm", "opus,vorbis" }, | 436 { "audio/webm", "opus,vorbis" }, |
444 { "audio/wav", "1" }, | 437 { "audio/wav", "1" }, |
445 { "audio/x-wav", "1" }, | 438 { "audio/x-wav", "1" }, |
(...skipping 22 matching lines...) Expand all Loading... |
468 | 461 |
469 // Initialize the supported non-image types. | 462 // Initialize the supported non-image types. |
470 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 463 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
471 non_image_map_.insert(supported_non_image_types[i]); | 464 non_image_map_.insert(supported_non_image_types[i]); |
472 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) | 465 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) |
473 non_image_map_.insert(supported_certificate_types[i].mime_type); | 466 non_image_map_.insert(supported_certificate_types[i].mime_type); |
474 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) | 467 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) |
475 unsupported_text_map_.insert(unsupported_text_types[i]); | 468 unsupported_text_map_.insert(unsupported_text_types[i]); |
476 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 469 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
477 non_image_map_.insert(supported_javascript_types[i]); | 470 non_image_map_.insert(supported_javascript_types[i]); |
478 for (size_t i = 0; i < arraysize(supported_dart_types); ++i) | |
479 non_image_map_.insert(supported_dart_types[i]); | |
480 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 471 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
481 non_image_map_.insert(common_media_types[i]); | 472 non_image_map_.insert(common_media_types[i]); |
482 #if defined(USE_PROPRIETARY_CODECS) | 473 #if defined(USE_PROPRIETARY_CODECS) |
483 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 474 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
484 non_image_map_.insert(proprietary_media_types[i]); | 475 non_image_map_.insert(proprietary_media_types[i]); |
485 #endif | 476 #endif |
486 | 477 |
487 // Initialize the supported media types. | 478 // Initialize the supported media types. |
488 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 479 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
489 media_map_.insert(common_media_types[i]); | 480 media_map_.insert(common_media_types[i]); |
490 #if defined(USE_PROPRIETARY_CODECS) | 481 #if defined(USE_PROPRIETARY_CODECS) |
491 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 482 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
492 media_map_.insert(proprietary_media_types[i]); | 483 media_map_.insert(proprietary_media_types[i]); |
493 #endif | 484 #endif |
494 | 485 |
495 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 486 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
496 javascript_map_.insert(supported_javascript_types[i]); | 487 javascript_map_.insert(supported_javascript_types[i]); |
497 for (size_t i = 0; i < arraysize(supported_dart_types); ++i) | |
498 dart_map_.insert(supported_dart_types[i]); | |
499 | 488 |
500 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { | 489 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { |
501 #if defined(OS_ANDROID) | 490 #if defined(OS_ANDROID) |
502 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) | 491 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) |
503 continue; | 492 continue; |
504 #endif | 493 #endif |
505 codecs_map_.insert(common_media_codecs[i]); | 494 codecs_map_.insert(common_media_codecs[i]); |
506 } | 495 } |
507 #if defined(USE_PROPRIETARY_CODECS) | 496 #if defined(USE_PROPRIETARY_CODECS) |
508 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 497 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 535 |
547 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 536 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { |
548 return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); | 537 return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); |
549 } | 538 } |
550 | 539 |
551 bool MimeUtil::IsSupportedJavascriptMimeType( | 540 bool MimeUtil::IsSupportedJavascriptMimeType( |
552 const std::string& mime_type) const { | 541 const std::string& mime_type) const { |
553 return javascript_map_.find(mime_type) != javascript_map_.end(); | 542 return javascript_map_.find(mime_type) != javascript_map_.end(); |
554 } | 543 } |
555 | 544 |
556 bool MimeUtil::IsSupportedDartMimeType( | |
557 const std::string& mime_type) const { | |
558 return dart_map_.find(mime_type) != dart_map_.end(); | |
559 } | |
560 | |
561 // Mirrors WebViewImpl::CanShowMIMEType() | 545 // Mirrors WebViewImpl::CanShowMIMEType() |
562 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { | 546 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { |
563 return (mime_type.compare(0, 6, "image/") == 0 && | 547 return (mime_type.compare(0, 6, "image/") == 0 && |
564 IsSupportedImageMimeType(mime_type)) || | 548 IsSupportedImageMimeType(mime_type)) || |
565 IsSupportedNonImageMimeType(mime_type); | 549 IsSupportedNonImageMimeType(mime_type); |
566 } | 550 } |
567 | 551 |
568 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| | 552 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| |
569 // must be matched by a parameter in the |mime_type|. If there are no | 553 // must be matched by a parameter in the |mime_type|. If there are no |
570 // parameters in the pattern, the match is a success. | 554 // parameters in the pattern, the match is a success. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 } | 757 } |
774 | 758 |
775 bool IsUnsupportedTextMimeType(const std::string& mime_type) { | 759 bool IsUnsupportedTextMimeType(const std::string& mime_type) { |
776 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); | 760 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); |
777 } | 761 } |
778 | 762 |
779 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { | 763 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { |
780 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); | 764 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); |
781 } | 765 } |
782 | 766 |
783 bool IsSupportedDartMimeType(const std::string& mime_type) { | |
784 return g_mime_util.Get().IsSupportedDartMimeType(mime_type); | |
785 } | |
786 | |
787 bool IsSupportedMimeType(const std::string& mime_type) { | 767 bool IsSupportedMimeType(const std::string& mime_type) { |
788 return g_mime_util.Get().IsSupportedMimeType(mime_type); | 768 return g_mime_util.Get().IsSupportedMimeType(mime_type); |
789 } | 769 } |
790 | 770 |
791 bool MatchesMimeType(const std::string& mime_type_pattern, | 771 bool MatchesMimeType(const std::string& mime_type_pattern, |
792 const std::string& mime_type) { | 772 const std::string& mime_type) { |
793 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); | 773 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); |
794 } | 774 } |
795 | 775 |
796 bool IsMimeType(const std::string& type_string) { | 776 bool IsMimeType(const std::string& type_string) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 post_data->append("\r\n" + value + "\r\n"); | 1028 post_data->append("\r\n" + value + "\r\n"); |
1049 } | 1029 } |
1050 | 1030 |
1051 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1031 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
1052 std::string* post_data) { | 1032 std::string* post_data) { |
1053 DCHECK(post_data); | 1033 DCHECK(post_data); |
1054 post_data->append("--" + mime_boundary + "--\r\n"); | 1034 post_data->append("--" + mime_boundary + "--\r\n"); |
1055 } | 1035 } |
1056 | 1036 |
1057 } // namespace net | 1037 } // namespace net |
OLD | NEW |