| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 void ParseCodecString(const std::string& codecs, | 71 void ParseCodecString(const std::string& codecs, |
| 72 std::vector<std::string>* codecs_out, | 72 std::vector<std::string>* codecs_out, |
| 73 bool strip); | 73 bool strip); |
| 74 | 74 |
| 75 bool IsStrictMediaMimeType(const std::string& mime_type) const; | 75 bool IsStrictMediaMimeType(const std::string& mime_type) const; |
| 76 bool IsSupportedStrictMediaMimeType( | 76 bool IsSupportedStrictMediaMimeType( |
| 77 const std::string& mime_type, | 77 const std::string& mime_type, |
| 78 const std::vector<std::string>& codecs) const; | 78 const std::vector<std::string>& codecs) const; |
| 79 | 79 |
| 80 void RemoveProprietaryMediaTypesAndCodecsForTests(); |
| 81 |
| 80 private: | 82 private: |
| 81 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; | 83 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; |
| 82 | 84 |
| 83 typedef base::hash_set<std::string> MimeMappings; | 85 typedef base::hash_set<std::string> MimeMappings; |
| 84 typedef std::map<std::string, MimeMappings> StrictMappings; | 86 typedef std::map<std::string, MimeMappings> StrictMappings; |
| 85 | 87 |
| 86 MimeUtil(); | 88 MimeUtil(); |
| 87 | 89 |
| 88 // Returns true if |codecs| is nonempty and all the items in it are present in | 90 // Returns true if |codecs| is nonempty and all the items in it are present in |
| 89 // |supported_codecs|. | 91 // |supported_codecs|. |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 } | 670 } |
| 669 | 671 |
| 670 bool MimeUtil::IsSupportedStrictMediaMimeType( | 672 bool MimeUtil::IsSupportedStrictMediaMimeType( |
| 671 const std::string& mime_type, | 673 const std::string& mime_type, |
| 672 const std::vector<std::string>& codecs) const { | 674 const std::vector<std::string>& codecs) const { |
| 673 StrictMappings::const_iterator it = strict_format_map_.find(mime_type); | 675 StrictMappings::const_iterator it = strict_format_map_.find(mime_type); |
| 674 return (it != strict_format_map_.end()) && | 676 return (it != strict_format_map_.end()) && |
| 675 AreSupportedCodecs(it->second, codecs); | 677 AreSupportedCodecs(it->second, codecs); |
| 676 } | 678 } |
| 677 | 679 |
| 680 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
| 681 // Unless/until WebM files are added to the media layout tests, we need to |
| 682 // avoid removing MP4 and H.264 when Theora is not supported (and |
| 683 // proprietary codecs are) so that the media tests can still run. |
| 684 #if defined(ENABLE_MEDIA_CODEC_THEORA) |
| 685 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 686 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { |
| 687 non_image_map_.erase(proprietary_media_types[i]); |
| 688 media_map_.erase(proprietary_media_types[i]); |
| 689 } |
| 690 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
| 691 codecs_map_.erase(proprietary_media_codecs[i]); |
| 692 #endif |
| 693 #endif |
| 694 } |
| 695 |
| 678 //---------------------------------------------------------------------------- | 696 //---------------------------------------------------------------------------- |
| 679 // Wrappers for the singleton | 697 // Wrappers for the singleton |
| 680 //---------------------------------------------------------------------------- | 698 //---------------------------------------------------------------------------- |
| 681 | 699 |
| 682 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 700 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 683 std::string* mime_type) { | 701 std::string* mime_type) { |
| 684 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); | 702 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); |
| 685 } | 703 } |
| 686 | 704 |
| 687 bool GetMimeTypeFromFile(const base::FilePath& file_path, | 705 bool GetMimeTypeFromFile(const base::FilePath& file_path, |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 | 945 |
| 928 GetExtensionsFromHardCodedMappings(secondary_mappings, | 946 GetExtensionsFromHardCodedMappings(secondary_mappings, |
| 929 arraysize(secondary_mappings), | 947 arraysize(secondary_mappings), |
| 930 mime_type, | 948 mime_type, |
| 931 &unique_extensions); | 949 &unique_extensions); |
| 932 } | 950 } |
| 933 | 951 |
| 934 HashSetToVector(&unique_extensions, extensions); | 952 HashSetToVector(&unique_extensions, extensions); |
| 935 } | 953 } |
| 936 | 954 |
| 937 void GetMediaTypesBlacklistedForTests(std::vector<std::string>* types) { | 955 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
| 938 types->clear(); | 956 g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
| 939 | |
| 940 // Unless/until WebM files are added to the media layout tests, we need to avoid | |
| 941 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary | |
| 942 // codecs are) so that the media tests can still run. | |
| 943 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) | |
| 944 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | |
| 945 types->push_back(proprietary_media_types[i]); | |
| 946 #endif | |
| 947 } | |
| 948 | |
| 949 void GetMediaCodecsBlacklistedForTests(std::vector<std::string>* codecs) { | |
| 950 codecs->clear(); | |
| 951 | |
| 952 // Unless/until WebM files are added to the media layout tests, we need to avoid | |
| 953 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary | |
| 954 // codecs are) so that the media tests can still run. | |
| 955 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) | |
| 956 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | |
| 957 codecs->push_back(proprietary_media_codecs[i]); | |
| 958 #endif | |
| 959 } | 957 } |
| 960 | 958 |
| 961 const std::string GetIANAMediaType(const std::string& mime_type) { | 959 const std::string GetIANAMediaType(const std::string& mime_type) { |
| 962 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { | 960 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { |
| 963 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { | 961 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { |
| 964 return kIanaMediaTypes[i].name; | 962 return kIanaMediaTypes[i].name; |
| 965 } | 963 } |
| 966 } | 964 } |
| 967 return std::string(); | 965 return std::string(); |
| 968 } | 966 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 post_data->append("\r\n" + value + "\r\n"); | 1001 post_data->append("\r\n" + value + "\r\n"); |
| 1004 } | 1002 } |
| 1005 | 1003 |
| 1006 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1004 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 1007 std::string* post_data) { | 1005 std::string* post_data) { |
| 1008 DCHECK(post_data); | 1006 DCHECK(post_data); |
| 1009 post_data->append("--" + mime_boundary + "--\r\n"); | 1007 post_data->append("--" + mime_boundary + "--\r\n"); |
| 1010 } | 1008 } |
| 1011 | 1009 |
| 1012 } // namespace net | 1010 } // namespace net |
| OLD | NEW |