| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 135                      bool* is_ambiguous) const; | 135                      bool* is_ambiguous) const; | 
| 136 | 136 | 
| 137   // Returns true if |codec| is supported by the platform. | 137   // Returns true if |codec| is supported by the platform. | 
| 138   // Note: This method will return false if the platform supports proprietary | 138   // Note: This method will return false if the platform supports proprietary | 
| 139   // codecs but |allow_proprietary_codecs_| is set to false. | 139   // codecs but |allow_proprietary_codecs_| is set to false. | 
| 140   bool IsCodecSupported(Codec codec) const; | 140   bool IsCodecSupported(Codec codec) const; | 
| 141 | 141 | 
| 142   // Returns true if |codec| refers to a proprietary codec. | 142   // Returns true if |codec| refers to a proprietary codec. | 
| 143   bool IsCodecProprietary(Codec codec) const; | 143   bool IsCodecProprietary(Codec codec) const; | 
| 144 | 144 | 
| 145   // Returns true and sets |*default_codec| if |mime_type| has a | 145   // Returns true and sets |*default_codec| if |mime_type| has a  default codec | 
| 146   // default codec associated with it. | 146   // associated with it. Returns false otherwise and the value of | 
| 147   // Returns false otherwise and the value of |*default_codec| is undefined. | 147   // |*default_codec| is undefined. | 
| 148   bool GetDefaultCodec(const std::string& mime_type, | 148   bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, | 
| 149                        Codec* default_codec) const; | 149                                 Codec* default_codec) const; | 
| 150 | 150 | 
| 151   // Returns true if |mime_type| has a default codec associated with it | 151   // Returns true if |mime_type_lower_case| has a default codec associated with | 
| 152   // and IsCodecSupported() returns true for that particular codec. | 152   // it and IsCodecSupported() returns true for that particular codec. | 
| 153   bool IsDefaultCodecSupported(const std::string& mime_type) const; | 153   bool IsDefaultCodecSupportedLowerCase( | 
|  | 154       const std::string& mime_type_lower_case) const; | 
| 154 | 155 | 
| 155   MimeMappings image_map_; | 156   MimeMappings image_map_; | 
| 156   MimeMappings media_map_; | 157   MimeMappings media_map_; | 
| 157   MimeMappings non_image_map_; | 158   MimeMappings non_image_map_; | 
| 158   MimeMappings unsupported_text_map_; | 159   MimeMappings unsupported_text_map_; | 
| 159   MimeMappings javascript_map_; | 160   MimeMappings javascript_map_; | 
| 160 | 161 | 
| 161   // A map of mime_types and hash map of the supported codecs for the mime_type. | 162   // A map of mime_types and hash map of the supported codecs for the mime_type. | 
| 162   StrictMappings strict_format_map_; | 163   StrictMappings strict_format_map_; | 
| 163 | 164 | 
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 469     case MimeUtil::MPEG2_AAC_MAIN: | 470     case MimeUtil::MPEG2_AAC_MAIN: | 
| 470     case MimeUtil::MPEG2_AAC_SSR: | 471     case MimeUtil::MPEG2_AAC_SSR: | 
| 471       // MPEG-2 variants of AAC are not supported on Android. | 472       // MPEG-2 variants of AAC are not supported on Android. | 
| 472       return false; | 473       return false; | 
| 473 | 474 | 
| 474     case MimeUtil::VP9: | 475     case MimeUtil::VP9: | 
| 475       // VP9 is supported only in KitKat+ (API Level 19). | 476       // VP9 is supported only in KitKat+ (API Level 19). | 
| 476       return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 477       return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 
| 477 | 478 | 
| 478     case MimeUtil::OPUS: | 479     case MimeUtil::OPUS: | 
| 479       // TODO(vigneshv): Change this similar to the VP9 check once Opus is | 480       // Opus is supported only in Lollipop+ (API Level 21). | 
| 480       // supported on Android (http://crbug.com/318436). | 481       return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 
| 481       return false; |  | 
| 482 | 482 | 
| 483     case MimeUtil::THEORA: | 483     case MimeUtil::THEORA: | 
| 484       return false; | 484       return false; | 
| 485   } | 485   } | 
| 486 | 486 | 
| 487   return false; | 487   return false; | 
| 488 } | 488 } | 
| 489 | 489 | 
| 490 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { | 490 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { | 
| 491   // HLS codecs are supported in ICS and above (API level 14) | 491   // HLS codecs are supported in ICS and above (API level 14) | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 521 //   avc1.6400xx - H.264 High | 521 //   avc1.6400xx - H.264 High | 
| 522 static const char kMP4AudioCodecsExpression[] = | 522 static const char kMP4AudioCodecsExpression[] = | 
| 523     "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 523     "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 
| 524     "mp4a.40.05,mp4a.40.29"; | 524     "mp4a.40.05,mp4a.40.29"; | 
| 525 static const char kMP4VideoCodecsExpression[] = | 525 static const char kMP4VideoCodecsExpression[] = | 
| 526     "avc1.42E00A,avc1.4D400A,avc1.64000A," | 526     "avc1.42E00A,avc1.4D400A,avc1.64000A," | 
| 527     "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 527     "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 
| 528     "mp4a.40.05,mp4a.40.29"; | 528     "mp4a.40.05,mp4a.40.29"; | 
| 529 | 529 | 
| 530 static const MediaFormatStrict format_codec_mappings[] = { | 530 static const MediaFormatStrict format_codec_mappings[] = { | 
| 531   { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, | 531     {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | 
| 532   { "audio/webm", "opus,vorbis" }, | 532     {"audio/webm", "opus,vorbis"}, | 
| 533   { "audio/wav", "1" }, | 533     {"audio/wav", "1"}, | 
| 534   { "audio/x-wav", "1" }, | 534     {"audio/x-wav", "1"}, | 
| 535   { "video/ogg", "opus,theora,vorbis" }, | 535 // Android does not support Opus in Ogg container. | 
| 536   { "audio/ogg", "opus,vorbis" }, | 536 #if defined(OS_ANDROID) | 
| 537   { "application/ogg", "opus,theora,vorbis" }, | 537     {"video/ogg", "theora,vorbis"}, | 
| 538   { "audio/mpeg", "mp3" }, | 538     {"audio/ogg", "vorbis"}, | 
| 539   { "audio/mp3", "" }, | 539     {"application/ogg", "theora,vorbis"}, | 
| 540   { "audio/x-mp3", "" }, | 540 #else | 
| 541   { "audio/mp4", kMP4AudioCodecsExpression }, | 541     {"video/ogg", "opus,theora,vorbis"}, | 
| 542   { "audio/x-m4a", kMP4AudioCodecsExpression }, | 542     {"audio/ogg", "opus,vorbis"}, | 
| 543   { "video/mp4", kMP4VideoCodecsExpression }, | 543     {"application/ogg", "opus,theora,vorbis"}, | 
| 544   { "video/x-m4v", kMP4VideoCodecsExpression }, | 544 #endif | 
| 545   { "application/x-mpegurl", kMP4VideoCodecsExpression }, | 545     {"audio/mpeg", "mp3"}, | 
| 546   { "application/vnd.apple.mpegurl", kMP4VideoCodecsExpression } | 546     {"audio/mp3", ""}, | 
| 547 }; | 547     {"audio/x-mp3", ""}, | 
|  | 548     {"audio/mp4", kMP4AudioCodecsExpression}, | 
|  | 549     {"audio/x-m4a", kMP4AudioCodecsExpression}, | 
|  | 550     {"video/mp4", kMP4VideoCodecsExpression}, | 
|  | 551     {"video/x-m4v", kMP4VideoCodecsExpression}, | 
|  | 552     {"application/x-mpegurl", kMP4VideoCodecsExpression}, | 
|  | 553     {"application/vnd.apple.mpegurl", kMP4VideoCodecsExpression}}; | 
| 548 | 554 | 
| 549 struct CodecIDMappings { | 555 struct CodecIDMappings { | 
| 550   const char* const codec_id; | 556   const char* const codec_id; | 
| 551   MimeUtil::Codec codec; | 557   MimeUtil::Codec codec; | 
| 552 }; | 558 }; | 
| 553 | 559 | 
| 554 // List of codec IDs that provide enough information to determine the | 560 // List of codec IDs that provide enough information to determine the | 
| 555 // codec and profile being requested. | 561 // codec and profile being requested. | 
| 556 // | 562 // | 
| 557 // The "mp4a" strings come from RFC 6381. | 563 // The "mp4a" strings come from RFC 6381. | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 682       CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); | 688       CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); | 
| 683       DCHECK(!is_ambiguous); | 689       DCHECK(!is_ambiguous); | 
| 684       codecs.insert(codec); | 690       codecs.insert(codec); | 
| 685     } | 691     } | 
| 686 | 692 | 
| 687     strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 693     strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 
| 688   } | 694   } | 
| 689 } | 695 } | 
| 690 | 696 | 
| 691 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 697 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 
| 692   return image_map_.find(mime_type) != image_map_.end(); | 698   return image_map_.find(base::StringToLowerASCII(mime_type)) != | 
|  | 699          image_map_.end(); | 
| 693 } | 700 } | 
| 694 | 701 | 
| 695 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 702 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 
| 696   return media_map_.find(mime_type) != media_map_.end(); | 703   return media_map_.find(base::StringToLowerASCII(mime_type)) != | 
|  | 704          media_map_.end(); | 
| 697 } | 705 } | 
| 698 | 706 | 
| 699 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { | 707 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { | 
| 700   return non_image_map_.find(mime_type) != non_image_map_.end() || | 708   return non_image_map_.find(base::StringToLowerASCII(mime_type)) != | 
| 701       (mime_type.compare(0, 5, "text/") == 0 && | 709              non_image_map_.end() || | 
| 702        !IsUnsupportedTextMimeType(mime_type)) || | 710          (StartsWithASCII(mime_type, "text/", false /* case insensitive */) && | 
| 703       (mime_type.compare(0, 12, "application/") == 0 && | 711           !IsUnsupportedTextMimeType(mime_type)) || | 
| 704        MatchesMimeType("application/*+json", mime_type)); | 712          (StartsWithASCII(mime_type, "application/", false) && | 
|  | 713           MatchesMimeType("application/*+json", mime_type)); | 
| 705 } | 714 } | 
| 706 | 715 | 
| 707 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 716 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 
| 708   return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); | 717   return unsupported_text_map_.find(base::StringToLowerASCII(mime_type)) != | 
|  | 718          unsupported_text_map_.end(); | 
| 709 } | 719 } | 
| 710 | 720 | 
| 711 bool MimeUtil::IsSupportedJavascriptMimeType( | 721 bool MimeUtil::IsSupportedJavascriptMimeType( | 
| 712     const std::string& mime_type) const { | 722     const std::string& mime_type) const { | 
| 713   return javascript_map_.find(mime_type) != javascript_map_.end(); | 723   return javascript_map_.find(mime_type) != javascript_map_.end(); | 
| 714 } | 724 } | 
| 715 | 725 | 
| 716 // Mirrors WebViewImpl::CanShowMIMEType() | 726 // Mirrors WebViewImpl::CanShowMIMEType() | 
| 717 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { | 727 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { | 
| 718   return (mime_type.compare(0, 6, "image/") == 0 && | 728   return (StartsWithASCII(mime_type, "image/", false) && | 
| 719           IsSupportedImageMimeType(mime_type)) || | 729           IsSupportedImageMimeType(mime_type)) || | 
| 720          IsSupportedNonImageMimeType(mime_type); | 730          IsSupportedNonImageMimeType(mime_type); | 
| 721 } | 731 } | 
| 722 | 732 | 
| 723 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| | 733 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| | 
| 724 // must be matched by a parameter in the |mime_type|. If there are no | 734 // must be matched by a parameter in the |mime_type|. If there are no | 
| 725 // parameters in the pattern, the match is a success. | 735 // parameters in the pattern, the match is a success. | 
|  | 736 // | 
|  | 737 // According rfc2045 keys of parameters are case-insensitive, while values may | 
|  | 738 // or may not be case-sensitive, but they are usually case-sensitive. So, this | 
|  | 739 // function matches values in *case-sensitive* manner, however note that this | 
|  | 740 // may produce some false negatives. | 
| 726 bool MatchesMimeTypeParameters(const std::string& mime_type_pattern, | 741 bool MatchesMimeTypeParameters(const std::string& mime_type_pattern, | 
| 727                                const std::string& mime_type) { | 742                                const std::string& mime_type) { | 
|  | 743   typedef std::map<std::string, std::string> StringPairMap; | 
|  | 744 | 
| 728   const std::string::size_type semicolon = mime_type_pattern.find(';'); | 745   const std::string::size_type semicolon = mime_type_pattern.find(';'); | 
| 729   const std::string::size_type test_semicolon = mime_type.find(';'); | 746   const std::string::size_type test_semicolon = mime_type.find(';'); | 
| 730   if (semicolon != std::string::npos) { | 747   if (semicolon != std::string::npos) { | 
| 731     if (test_semicolon == std::string::npos) | 748     if (test_semicolon == std::string::npos) | 
| 732       return false; | 749       return false; | 
| 733 | 750 | 
| 734     std::vector<std::string> pattern_parameters; | 751     base::StringPairs pattern_parameters; | 
| 735     base::SplitString(mime_type_pattern.substr(semicolon + 1), | 752     base::SplitStringIntoKeyValuePairs(mime_type_pattern.substr(semicolon + 1), | 
| 736                       ';', &pattern_parameters); | 753                                        '=', ';', &pattern_parameters); | 
|  | 754     base::StringPairs test_parameters; | 
|  | 755     base::SplitStringIntoKeyValuePairs(mime_type.substr(test_semicolon + 1), | 
|  | 756                                        '=', ';', &test_parameters); | 
| 737 | 757 | 
| 738     std::vector<std::string> test_parameters; | 758     // Put the parameters to maps with the keys converted to lower case. | 
| 739     base::SplitString(mime_type.substr(test_semicolon + 1), | 759     StringPairMap pattern_parameter_map; | 
| 740                       ';', &test_parameters); | 760     for (const auto& pair : pattern_parameters) { | 
|  | 761       pattern_parameter_map[base::StringToLowerASCII(pair.first)] = pair.second; | 
|  | 762     } | 
| 741 | 763 | 
| 742     sort(pattern_parameters.begin(), pattern_parameters.end()); | 764     StringPairMap test_parameter_map; | 
| 743     sort(test_parameters.begin(), test_parameters.end()); | 765     for (const auto& pair : test_parameters) { | 
| 744     std::vector<std::string> difference = | 766       test_parameter_map[base::StringToLowerASCII(pair.first)] = pair.second; | 
| 745       base::STLSetDifference<std::vector<std::string> >(pattern_parameters, | 767     } | 
| 746                                                         test_parameters); | 768 | 
| 747     return difference.size() == 0; | 769     if (pattern_parameter_map.size() > test_parameter_map.size()) | 
|  | 770       return false; | 
|  | 771 | 
|  | 772     for (const auto& parameter_pair : pattern_parameter_map) { | 
|  | 773       const auto& test_parameter_pair_it = | 
|  | 774           test_parameter_map.find(parameter_pair.first); | 
|  | 775       if (test_parameter_pair_it == test_parameter_map.end()) | 
|  | 776         return false; | 
|  | 777       if (parameter_pair.second != test_parameter_pair_it->second) | 
|  | 778         return false; | 
|  | 779     } | 
| 748   } | 780   } | 
|  | 781 | 
| 749   return true; | 782   return true; | 
| 750 } | 783 } | 
| 751 | 784 | 
| 752 // This comparison handles absolute maching and also basic | 785 // This comparison handles absolute maching and also basic | 
| 753 // wildcards.  The plugin mime types could be: | 786 // wildcards.  The plugin mime types could be: | 
| 754 //      application/x-foo | 787 //      application/x-foo | 
| 755 //      application/* | 788 //      application/* | 
| 756 //      application/*+xml | 789 //      application/*+xml | 
| 757 //      * | 790 //      * | 
| 758 // Also tests mime parameters -- all parameters in the pattern must be present | 791 // Also tests mime parameters -- all parameters in the pattern must be present | 
| 759 // in the tested type for a match to succeed. | 792 // in the tested type for a match to succeed. | 
| 760 bool MimeUtil::MatchesMimeType(const std::string& mime_type_pattern, | 793 bool MimeUtil::MatchesMimeType(const std::string& mime_type_pattern, | 
| 761                                const std::string& mime_type) const { | 794                                const std::string& mime_type) const { | 
| 762   // Verify caller is passing lowercase strings. |  | 
| 763   DCHECK_EQ(base::StringToLowerASCII(mime_type_pattern), mime_type_pattern); |  | 
| 764   DCHECK_EQ(base::StringToLowerASCII(mime_type), mime_type); |  | 
| 765 |  | 
| 766   if (mime_type_pattern.empty()) | 795   if (mime_type_pattern.empty()) | 
| 767     return false; | 796     return false; | 
| 768 | 797 | 
| 769   std::string::size_type semicolon = mime_type_pattern.find(';'); | 798   std::string::size_type semicolon = mime_type_pattern.find(';'); | 
| 770   const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); | 799   const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); | 
| 771   semicolon = mime_type.find(';'); | 800   semicolon = mime_type.find(';'); | 
| 772   const std::string base_type(mime_type.substr(0, semicolon)); | 801   const std::string base_type(mime_type.substr(0, semicolon)); | 
| 773 | 802 | 
| 774   if (base_pattern == "*" || base_pattern == "*/*") | 803   if (base_pattern == "*" || base_pattern == "*/*") | 
| 775     return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 804     return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 
| 776 | 805 | 
| 777   const std::string::size_type star = base_pattern.find('*'); | 806   const std::string::size_type star = base_pattern.find('*'); | 
| 778   if (star == std::string::npos) { | 807   if (star == std::string::npos) { | 
| 779     if (base_pattern == base_type) | 808     if (base_pattern.size() == base_type.size() && | 
|  | 809         base::strncasecmp(base_pattern.c_str(), base_type.c_str(), | 
|  | 810                           base_pattern.size()) == 0) { | 
| 780       return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 811       return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 
| 781     else | 812     } else { | 
| 782       return false; | 813       return false; | 
|  | 814     } | 
| 783   } | 815   } | 
| 784 | 816 | 
| 785   // Test length to prevent overlap between |left| and |right|. | 817   // Test length to prevent overlap between |left| and |right|. | 
| 786   if (base_type.length() < base_pattern.length() - 1) | 818   if (base_type.length() < base_pattern.length() - 1) | 
| 787     return false; | 819     return false; | 
| 788 | 820 | 
| 789   const std::string left(base_pattern.substr(0, star)); | 821   const std::string left(base_pattern.substr(0, star)); | 
| 790   const std::string right(base_pattern.substr(star + 1)); | 822   const std::string right(base_pattern.substr(star + 1)); | 
| 791 | 823 | 
| 792   if (base_type.find(left) != 0) | 824   if (!StartsWithASCII(base_type, left, false)) | 
| 793     return false; | 825     return false; | 
| 794 | 826 | 
| 795   if (!right.empty() && | 827   if (!right.empty() && !EndsWith(base_type, right, false)) | 
| 796       base_type.rfind(right) != base_type.length() - right.length()) |  | 
| 797     return false; | 828     return false; | 
| 798 | 829 | 
| 799   return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 830   return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 
| 800 } | 831 } | 
| 801 | 832 | 
| 802 // See http://www.iana.org/assignments/media-types/media-types.xhtml | 833 // See http://www.iana.org/assignments/media-types/media-types.xhtml | 
| 803 static const char* const legal_top_level_types[] = { | 834 static const char* const legal_top_level_types[] = { | 
| 804   "application", | 835   "application", | 
| 805   "audio", | 836   "audio", | 
| 806   "example", | 837   "example", | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 867   for (std::vector<std::string>::iterator it = codecs_out->begin(); | 898   for (std::vector<std::string>::iterator it = codecs_out->begin(); | 
| 868        it != codecs_out->end(); | 899        it != codecs_out->end(); | 
| 869        ++it) { | 900        ++it) { | 
| 870     size_t found = it->find_first_of('.'); | 901     size_t found = it->find_first_of('.'); | 
| 871     if (found != std::string::npos) | 902     if (found != std::string::npos) | 
| 872       it->resize(found); | 903       it->resize(found); | 
| 873   } | 904   } | 
| 874 } | 905 } | 
| 875 | 906 | 
| 876 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { | 907 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { | 
| 877   return strict_format_map_.find(mime_type) != strict_format_map_.end(); | 908   return strict_format_map_.find(base::StringToLowerASCII(mime_type)) != | 
|  | 909          strict_format_map_.end(); | 
| 878 } | 910 } | 
| 879 | 911 | 
| 880 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( | 912 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( | 
| 881     const std::string& mime_type, | 913     const std::string& mime_type, | 
| 882     const std::vector<std::string>& codecs) const { | 914     const std::vector<std::string>& codecs) const { | 
|  | 915   const std::string mime_type_lower_case = base::StringToLowerASCII(mime_type); | 
| 883   StrictMappings::const_iterator it_strict_map = | 916   StrictMappings::const_iterator it_strict_map = | 
| 884       strict_format_map_.find(mime_type); | 917       strict_format_map_.find(mime_type_lower_case); | 
| 885   if (it_strict_map == strict_format_map_.end()) | 918   if (it_strict_map == strict_format_map_.end()) | 
| 886     return codecs.empty() ? MayBeSupported : IsNotSupported; | 919     return codecs.empty() ? MayBeSupported : IsNotSupported; | 
| 887 | 920 | 
| 888   if (it_strict_map->second.empty()) { | 921   if (it_strict_map->second.empty()) { | 
| 889     // We get here if the mimetype does not expect a codecs parameter. | 922     // We get here if the mimetype does not expect a codecs parameter. | 
| 890     return (codecs.empty() && IsDefaultCodecSupported(mime_type)) ? | 923     return (codecs.empty() && | 
| 891         IsSupported : IsNotSupported; | 924             IsDefaultCodecSupportedLowerCase(mime_type_lower_case)) | 
|  | 925                ? IsSupported | 
|  | 926                : IsNotSupported; | 
| 892   } | 927   } | 
| 893 | 928 | 
| 894   if (codecs.empty()) { | 929   if (codecs.empty()) { | 
| 895     // We get here if the mimetype expects to get a codecs parameter, | 930     // We get here if the mimetype expects to get a codecs parameter, | 
| 896     // but didn't get one. If |mime_type| does not have a default codec | 931     // but didn't get one. If |mime_type_lower_case| does not have a default | 
| 897     // the best we can do is say "maybe" because we don't have enough | 932     // codec the best we can do is say "maybe" because we don't have enough | 
| 898     // information. | 933     // information. | 
| 899     Codec default_codec = INVALID_CODEC; | 934     Codec default_codec = INVALID_CODEC; | 
| 900     if (!GetDefaultCodec(mime_type, &default_codec)) | 935     if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 
| 901       return MayBeSupported; | 936       return MayBeSupported; | 
| 902 | 937 | 
| 903     return IsCodecSupported(default_codec) ? IsSupported : IsNotSupported; | 938     return IsCodecSupported(default_codec) ? IsSupported : IsNotSupported; | 
| 904   } | 939   } | 
| 905 | 940 | 
| 906   return AreSupportedCodecs(it_strict_map->second, codecs); | 941   return AreSupportedCodecs(it_strict_map->second, codecs); | 
| 907 } | 942 } | 
| 908 | 943 | 
| 909 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | 944 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | 
| 910   for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { | 945   for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1046     case OPUS: | 1081     case OPUS: | 
| 1047     case VP8: | 1082     case VP8: | 
| 1048     case VP9: | 1083     case VP9: | 
| 1049     case THEORA: | 1084     case THEORA: | 
| 1050       return false; | 1085       return false; | 
| 1051   } | 1086   } | 
| 1052 | 1087 | 
| 1053   return true; | 1088   return true; | 
| 1054 } | 1089 } | 
| 1055 | 1090 | 
| 1056 bool MimeUtil::GetDefaultCodec(const std::string& mime_type, | 1091 bool MimeUtil::GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, | 
| 1057                                Codec* default_codec) const { | 1092                                         Codec* default_codec) const { | 
| 1058   if (mime_type == "audio/mpeg" || | 1093   if (mime_type_lower_case == "audio/mpeg" || | 
| 1059       mime_type == "audio/mp3" || | 1094       mime_type_lower_case == "audio/mp3" || | 
| 1060       mime_type == "audio/x-mp3") { | 1095       mime_type_lower_case == "audio/x-mp3") { | 
| 1061     *default_codec = MimeUtil::MP3; | 1096     *default_codec = MimeUtil::MP3; | 
| 1062     return true; | 1097     return true; | 
| 1063   } | 1098   } | 
| 1064 | 1099 | 
| 1065   return false; | 1100   return false; | 
| 1066 } | 1101 } | 
| 1067 | 1102 | 
| 1068 | 1103 bool MimeUtil::IsDefaultCodecSupportedLowerCase( | 
| 1069 bool MimeUtil::IsDefaultCodecSupported(const std::string& mime_type) const { | 1104     const std::string& mime_type_lower_case) const { | 
| 1070   Codec default_codec = Codec::INVALID_CODEC; | 1105   Codec default_codec = Codec::INVALID_CODEC; | 
| 1071   if (!GetDefaultCodec(mime_type, &default_codec)) | 1106   if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 
| 1072     return false; | 1107     return false; | 
| 1073   return IsCodecSupported(default_codec); | 1108   return IsCodecSupported(default_codec); | 
| 1074 } | 1109 } | 
| 1075 | 1110 | 
| 1076 //---------------------------------------------------------------------------- | 1111 //---------------------------------------------------------------------------- | 
| 1077 // Wrappers for the singleton | 1112 // Wrappers for the singleton | 
| 1078 //---------------------------------------------------------------------------- | 1113 //---------------------------------------------------------------------------- | 
| 1079 | 1114 | 
| 1080 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 1115 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 
| 1081                               std::string* mime_type) { | 1116                               std::string* mime_type) { | 
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1285 // vector. | 1320 // vector. | 
| 1286 template<class T> | 1321 template<class T> | 
| 1287 void HashSetToVector(base::hash_set<T>* source, std::vector<T>* target) { | 1322 void HashSetToVector(base::hash_set<T>* source, std::vector<T>* target) { | 
| 1288   size_t old_target_size = target->size(); | 1323   size_t old_target_size = target->size(); | 
| 1289   target->resize(old_target_size + source->size()); | 1324   target->resize(old_target_size + source->size()); | 
| 1290   size_t i = 0; | 1325   size_t i = 0; | 
| 1291   for (typename base::hash_set<T>::iterator iter = source->begin(); | 1326   for (typename base::hash_set<T>::iterator iter = source->begin(); | 
| 1292        iter != source->end(); ++iter, ++i) | 1327        iter != source->end(); ++iter, ++i) | 
| 1293     (*target)[old_target_size + i] = *iter; | 1328     (*target)[old_target_size + i] = *iter; | 
| 1294 } | 1329 } | 
| 1295 } | 1330 | 
|  | 1331 }  // namespace | 
| 1296 | 1332 | 
| 1297 void GetExtensionsForMimeType( | 1333 void GetExtensionsForMimeType( | 
| 1298     const std::string& unsafe_mime_type, | 1334     const std::string& unsafe_mime_type, | 
| 1299     std::vector<base::FilePath::StringType>* extensions) { | 1335     std::vector<base::FilePath::StringType>* extensions) { | 
| 1300   if (unsafe_mime_type == "*/*" || unsafe_mime_type == "*") | 1336   if (unsafe_mime_type == "*/*" || unsafe_mime_type == "*") | 
| 1301     return; | 1337     return; | 
| 1302 | 1338 | 
| 1303   const std::string mime_type = base::StringToLowerASCII(unsafe_mime_type); | 1339   const std::string mime_type = base::StringToLowerASCII(unsafe_mime_type); | 
| 1304   base::hash_set<base::FilePath::StringType> unique_extensions; | 1340   base::hash_set<base::FilePath::StringType> unique_extensions; | 
| 1305 | 1341 | 
| 1306   if (EndsWith(mime_type, "/*", true)) { | 1342   if (EndsWith(mime_type, "/*", false)) { | 
| 1307     std::string leading_mime_type = mime_type.substr(0, mime_type.length() - 1); | 1343     std::string leading_mime_type = mime_type.substr(0, mime_type.length() - 1); | 
| 1308 | 1344 | 
| 1309     // Find the matching StandardType from within kStandardTypes, or fall | 1345     // Find the matching StandardType from within kStandardTypes, or fall | 
| 1310     // through to the last (default) StandardType. | 1346     // through to the last (default) StandardType. | 
| 1311     const StandardType* type = NULL; | 1347     const StandardType* type = NULL; | 
| 1312     for (size_t i = 0; i < arraysize(kStandardTypes); ++i) { | 1348     for (size_t i = 0; i < arraysize(kStandardTypes); ++i) { | 
| 1313       type = &(kStandardTypes[i]); | 1349       type = &(kStandardTypes[i]); | 
| 1314       if (type->leading_mime_type && | 1350       if (type->leading_mime_type && | 
| 1315           leading_mime_type == type->leading_mime_type) | 1351           leading_mime_type == type->leading_mime_type) | 
| 1316         break; | 1352         break; | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 1342 | 1378 | 
| 1343 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 1379 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 
| 1344   g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 1380   g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 
| 1345 } | 1381 } | 
| 1346 | 1382 | 
| 1347 CertificateMimeType GetCertificateMimeTypeForMimeType( | 1383 CertificateMimeType GetCertificateMimeTypeForMimeType( | 
| 1348     const std::string& mime_type) { | 1384     const std::string& mime_type) { | 
| 1349   // Don't create a map, there is only one entry in the table, | 1385   // Don't create a map, there is only one entry in the table, | 
| 1350   // except on Android. | 1386   // except on Android. | 
| 1351   for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { | 1387   for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { | 
| 1352     if (mime_type == net::supported_certificate_types[i].mime_type) | 1388     if (base::strcasecmp(mime_type.c_str(), | 
|  | 1389                          net::supported_certificate_types[i].mime_type) == 0) { | 
| 1353       return net::supported_certificate_types[i].cert_type; | 1390       return net::supported_certificate_types[i].cert_type; | 
|  | 1391     } | 
| 1354   } | 1392   } | 
| 1355   return CERTIFICATE_MIME_TYPE_UNKNOWN; | 1393   return CERTIFICATE_MIME_TYPE_UNKNOWN; | 
| 1356 } | 1394 } | 
| 1357 | 1395 | 
| 1358 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | 1396 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | 
| 1359   CertificateMimeType file_type = | 1397   CertificateMimeType file_type = | 
| 1360       GetCertificateMimeTypeForMimeType(mime_type); | 1398       GetCertificateMimeTypeForMimeType(mime_type); | 
| 1361   return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; | 1399   return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; | 
| 1362 } | 1400 } | 
| 1363 | 1401 | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 1380   post_data->append("\r\n" + value + "\r\n"); | 1418   post_data->append("\r\n" + value + "\r\n"); | 
| 1381 } | 1419 } | 
| 1382 | 1420 | 
| 1383 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1421 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 
| 1384                                          std::string* post_data) { | 1422                                          std::string* post_data) { | 
| 1385   DCHECK(post_data); | 1423   DCHECK(post_data); | 
| 1386   post_data->append("--" + mime_boundary + "--\r\n"); | 1424   post_data->append("--" + mime_boundary + "--\r\n"); | 
| 1387 } | 1425 } | 
| 1388 | 1426 | 
| 1389 }  // namespace net | 1427 }  // namespace net | 
| OLD | NEW | 
|---|