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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 bool GetWellKnownMimeTypeFromExtension(const FilePath::StringType& ext, | 54 bool GetWellKnownMimeTypeFromExtension(const FilePath::StringType& ext, |
55 std::string* mime_type) const; | 55 std::string* mime_type) const; |
56 | 56 |
57 bool IsSupportedImageMimeType(const std::string& mime_type) const; | 57 bool IsSupportedImageMimeType(const std::string& mime_type) const; |
58 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 58 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
59 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; | 59 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; |
60 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; | 60 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; |
61 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; | 61 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; |
62 | 62 |
63 bool IsViewSourceMimeType(const std::string& mime_type) const; | |
64 | |
65 bool IsSupportedMimeType(const std::string& mime_type) const; | 63 bool IsSupportedMimeType(const std::string& mime_type) const; |
66 | 64 |
67 bool MatchesMimeType(const std::string &mime_type_pattern, | 65 bool MatchesMimeType(const std::string &mime_type_pattern, |
68 const std::string &mime_type) const; | 66 const std::string &mime_type) const; |
69 | 67 |
70 bool IsMimeType(const std::string& type_string) const; | 68 bool IsMimeType(const std::string& type_string) const; |
71 | 69 |
72 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; | 70 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; |
73 | 71 |
74 void ParseCodecString(const std::string& codecs, | 72 void ParseCodecString(const std::string& codecs, |
(...skipping 23 matching lines...) Expand all Loading... |
98 | 96 |
99 bool GetMimeTypeFromExtensionHelper(const FilePath::StringType& ext, | 97 bool GetMimeTypeFromExtensionHelper(const FilePath::StringType& ext, |
100 bool include_platform_types, | 98 bool include_platform_types, |
101 std::string* mime_type) const; | 99 std::string* mime_type) const; |
102 | 100 |
103 MimeMappings image_map_; | 101 MimeMappings image_map_; |
104 MimeMappings media_map_; | 102 MimeMappings media_map_; |
105 MimeMappings non_image_map_; | 103 MimeMappings non_image_map_; |
106 MimeMappings unsupported_text_map_; | 104 MimeMappings unsupported_text_map_; |
107 MimeMappings javascript_map_; | 105 MimeMappings javascript_map_; |
108 MimeMappings view_source_map_; | |
109 MimeMappings codecs_map_; | 106 MimeMappings codecs_map_; |
110 | 107 |
111 StrictMappings strict_format_map_; | 108 StrictMappings strict_format_map_; |
112 }; // class MimeUtil | 109 }; // class MimeUtil |
113 | 110 |
114 // This variable is Leaky because we need to access it from WorkerPool threads. | 111 // This variable is Leaky because we need to access it from WorkerPool threads. |
115 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = | 112 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
116 LAZY_INSTANCE_INITIALIZER; | 113 LAZY_INSTANCE_INITIALIZER; |
117 | 114 |
118 struct MimeInfo { | 115 struct MimeInfo { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 "application/javascript", | 396 "application/javascript", |
400 "application/ecmascript", | 397 "application/ecmascript", |
401 "application/x-javascript", | 398 "application/x-javascript", |
402 "text/javascript1.1", | 399 "text/javascript1.1", |
403 "text/javascript1.2", | 400 "text/javascript1.2", |
404 "text/javascript1.3", | 401 "text/javascript1.3", |
405 "text/jscript", | 402 "text/jscript", |
406 "text/livescript" | 403 "text/livescript" |
407 }; | 404 }; |
408 | 405 |
409 static const char* const view_source_types[] = { | |
410 "text/xml", | |
411 "text/xsl", | |
412 "application/xml", | |
413 "application/rss+xml", | |
414 "application/atom+xml", | |
415 "image/svg+xml" | |
416 }; | |
417 | |
418 struct MediaFormatStrict { | 406 struct MediaFormatStrict { |
419 const char* mime_type; | 407 const char* mime_type; |
420 const char* codecs_list; | 408 const char* codecs_list; |
421 }; | 409 }; |
422 | 410 |
423 static const MediaFormatStrict format_codec_mappings[] = { | 411 static const MediaFormatStrict format_codec_mappings[] = { |
424 { "video/webm", "vorbis,vp8,vp8.0" }, | 412 { "video/webm", "vorbis,vp8,vp8.0" }, |
425 { "audio/webm", "vorbis" }, | 413 { "audio/webm", "vorbis" }, |
426 { "audio/wav", "1" } | 414 { "audio/wav", "1" } |
427 }; | 415 }; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 452 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
465 media_map_.insert(common_media_types[i]); | 453 media_map_.insert(common_media_types[i]); |
466 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 454 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
467 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 455 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
468 media_map_.insert(proprietary_media_types[i]); | 456 media_map_.insert(proprietary_media_types[i]); |
469 #endif | 457 #endif |
470 | 458 |
471 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 459 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
472 javascript_map_.insert(supported_javascript_types[i]); | 460 javascript_map_.insert(supported_javascript_types[i]); |
473 | 461 |
474 for (size_t i = 0; i < arraysize(view_source_types); ++i) | |
475 view_source_map_.insert(view_source_types[i]); | |
476 | |
477 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) | 462 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) |
478 codecs_map_.insert(common_media_codecs[i]); | 463 codecs_map_.insert(common_media_codecs[i]); |
479 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 464 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
480 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 465 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
481 codecs_map_.insert(proprietary_media_codecs[i]); | 466 codecs_map_.insert(proprietary_media_codecs[i]); |
482 #endif | 467 #endif |
483 | 468 |
484 // Initialize the strict supported media types. | 469 // Initialize the strict supported media types. |
485 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { | 470 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { |
486 std::vector<std::string> mime_type_codecs; | 471 std::vector<std::string> mime_type_codecs; |
(...skipping 24 matching lines...) Expand all Loading... |
511 | 496 |
512 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 497 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { |
513 return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); | 498 return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); |
514 } | 499 } |
515 | 500 |
516 bool MimeUtil::IsSupportedJavascriptMimeType( | 501 bool MimeUtil::IsSupportedJavascriptMimeType( |
517 const std::string& mime_type) const { | 502 const std::string& mime_type) const { |
518 return javascript_map_.find(mime_type) != javascript_map_.end(); | 503 return javascript_map_.find(mime_type) != javascript_map_.end(); |
519 } | 504 } |
520 | 505 |
521 bool MimeUtil::IsViewSourceMimeType(const std::string& mime_type) const { | |
522 return view_source_map_.find(mime_type) != view_source_map_.end(); | |
523 } | |
524 | |
525 // Mirrors WebViewImpl::CanShowMIMEType() | 506 // Mirrors WebViewImpl::CanShowMIMEType() |
526 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { | 507 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { |
527 return (mime_type.compare(0, 6, "image/") == 0 && | 508 return (mime_type.compare(0, 6, "image/") == 0 && |
528 IsSupportedImageMimeType(mime_type)) || | 509 IsSupportedImageMimeType(mime_type)) || |
529 IsSupportedNonImageMimeType(mime_type); | 510 IsSupportedNonImageMimeType(mime_type); |
530 } | 511 } |
531 | 512 |
532 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| | 513 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| |
533 // must be matched by a parameter in the |mime_type|. If there are no | 514 // must be matched by a parameter in the |mime_type|. If there are no |
534 // parameters in the pattern, the match is a success. | 515 // parameters in the pattern, the match is a success. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 } | 710 } |
730 | 711 |
731 bool IsUnsupportedTextMimeType(const std::string& mime_type) { | 712 bool IsUnsupportedTextMimeType(const std::string& mime_type) { |
732 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); | 713 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); |
733 } | 714 } |
734 | 715 |
735 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { | 716 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { |
736 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); | 717 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); |
737 } | 718 } |
738 | 719 |
739 bool IsViewSourceMimeType(const std::string& mime_type) { | |
740 return g_mime_util.Get().IsViewSourceMimeType(mime_type); | |
741 } | |
742 | |
743 bool IsSupportedMimeType(const std::string& mime_type) { | 720 bool IsSupportedMimeType(const std::string& mime_type) { |
744 return g_mime_util.Get().IsSupportedMimeType(mime_type); | 721 return g_mime_util.Get().IsSupportedMimeType(mime_type); |
745 } | 722 } |
746 | 723 |
747 bool MatchesMimeType(const std::string& mime_type_pattern, | 724 bool MatchesMimeType(const std::string& mime_type_pattern, |
748 const std::string& mime_type) { | 725 const std::string& mime_type) { |
749 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); | 726 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); |
750 } | 727 } |
751 | 728 |
752 bool IsMimeType(const std::string& type_string) { | 729 bool IsMimeType(const std::string& type_string) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 return CERTIFICATE_MIME_TYPE_UNKNOWN; | 972 return CERTIFICATE_MIME_TYPE_UNKNOWN; |
996 } | 973 } |
997 | 974 |
998 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | 975 bool IsSupportedCertificateMimeType(const std::string& mime_type) { |
999 CertificateMimeType file_type = | 976 CertificateMimeType file_type = |
1000 GetCertificateMimeTypeForMimeType(mime_type); | 977 GetCertificateMimeTypeForMimeType(mime_type); |
1001 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; | 978 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; |
1002 } | 979 } |
1003 | 980 |
1004 } // namespace net | 981 } // namespace net |
OLD | NEW |