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 #ifndef NET_BASE_MIME_UTIL_H__ | 5 #ifndef NET_BASE_MIME_UTIL_H__ |
6 #define NET_BASE_MIME_UTIL_H__ | 6 #define NET_BASE_MIME_UTIL_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 // Get the preferred extension (if any) associated with the given mime type. | 34 // Get the preferred extension (if any) associated with the given mime type. |
35 // Returns true if a corresponding file extension exists. The extension is | 35 // Returns true if a corresponding file extension exists. The extension is |
36 // returned without a prefixed dot, ex "html". | 36 // returned without a prefixed dot, ex "html". |
37 NET_EXPORT bool GetPreferredExtensionForMimeType( | 37 NET_EXPORT bool GetPreferredExtensionForMimeType( |
38 const std::string& mime_type, | 38 const std::string& mime_type, |
39 base::FilePath::StringType* extension); | 39 base::FilePath::StringType* extension); |
40 | 40 |
41 // Check to see if a particular MIME type is in our list. | 41 // Check to see if a particular MIME type is in our list. |
42 NET_EXPORT bool IsSupportedImageMimeType(const std::string& mime_type); | 42 NET_EXPORT bool IsSupportedImageMimeType(const std::string& mime_type); |
43 NET_EXPORT bool IsSupportedMediaMimeType(const std::string& mime_type); | |
44 NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type); | 43 NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type); |
45 NET_EXPORT bool IsUnsupportedTextMimeType(const std::string& mime_type); | 44 NET_EXPORT bool IsUnsupportedTextMimeType(const std::string& mime_type); |
46 NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type); | 45 NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type); |
47 NET_EXPORT bool IsSupportedCertificateMimeType(const std::string& mime_type); | 46 NET_EXPORT bool IsSupportedCertificateMimeType(const std::string& mime_type); |
48 | 47 |
49 // Convenience function. | 48 // Convenience function. |
50 NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type); | 49 NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type); |
51 | 50 |
52 // Returns true if this the mime_type_pattern matches a given mime-type. | 51 // Returns true if this the mime_type_pattern matches a given mime-type. |
53 // Checks for absolute matching and wildcards. mime-types should be in | 52 // Checks for absolute matching and wildcards. mime-types should be in |
(...skipping 17 matching lines...) Expand all Loading... |
71 // Returns true if the |type_string| is a top-level type of any media type | 70 // Returns true if the |type_string| is a top-level type of any media type |
72 // registered with IANA media types registry at | 71 // registered with IANA media types registry at |
73 // http://www.iana.org/assignments/media-types/media-types.xhtml or an | 72 // http://www.iana.org/assignments/media-types/media-types.xhtml or an |
74 // experimental type (type with x- prefix). | 73 // experimental type (type with x- prefix). |
75 // | 74 // |
76 // This method doesn't check that the input conforms to token ABNF, so if input | 75 // This method doesn't check that the input conforms to token ABNF, so if input |
77 // is experimental type strings, you need to check check that before using | 76 // is experimental type strings, you need to check check that before using |
78 // this method. | 77 // this method. |
79 NET_EXPORT bool IsValidTopLevelMimeType(const std::string& type_string); | 78 NET_EXPORT bool IsValidTopLevelMimeType(const std::string& type_string); |
80 | 79 |
81 // Returns true if and only if all codecs are supported, false otherwise. | |
82 NET_EXPORT bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs); | |
83 | |
84 // Parses a codec string, populating |codecs_out| with the prefix of each codec | |
85 // in the string |codecs_in|. For example, passed "aaa.b.c,dd.eee", if | |
86 // |strip| == true |codecs_out| will contain {"aaa", "dd"}, if |strip| == false | |
87 // |codecs_out| will contain {"aaa.b.c", "dd.eee"}. | |
88 // See http://www.ietf.org/rfc/rfc4281.txt. | |
89 NET_EXPORT void ParseCodecString(const std::string& codecs, | |
90 std::vector<std::string>* codecs_out, | |
91 bool strip); | |
92 | |
93 // Check to see if a particular MIME type is in our list which only supports a | |
94 // certain subset of codecs. | |
95 NET_EXPORT bool IsStrictMediaMimeType(const std::string& mime_type); | |
96 | |
97 // Indicates that the MIME type and (possible codec string) are supported by the | |
98 // underlying platform. | |
99 enum SupportsType { | |
100 // The underlying platform is known not to support the given MIME type and | |
101 // codec combination. | |
102 IsNotSupported, | |
103 | |
104 // The underlying platform is known to support the given MIME type and codec | |
105 // combination. | |
106 IsSupported, | |
107 | |
108 // The underlying platform is unsure whether the given MIME type and codec | |
109 // combination can be rendered or not before actually trying to play it. | |
110 MayBeSupported | |
111 }; | |
112 | |
113 // Checks the |mime_type| and |codecs| against the MIME types known to support | |
114 // only a particular subset of codecs. | |
115 // * Returns IsSupported if the |mime_type| is supported and all the codecs | |
116 // within the |codecs| are supported for the |mime_type|. | |
117 // * Returns MayBeSupported if the |mime_type| is supported and is known to | |
118 // support only a subset of codecs, but |codecs| was empty. Also returned if | |
119 // all the codecs in |codecs| are supported, but additional codec parameters | |
120 // were supplied (such as profile) for which the support cannot be decided. | |
121 // * Returns IsNotSupported if either the |mime_type| is not supported or the | |
122 // |mime_type| is supported but at least one of the codecs within |codecs| is | |
123 // not supported for the |mime_type|. | |
124 NET_EXPORT SupportsType IsSupportedStrictMediaMimeType( | |
125 const std::string& mime_type, | |
126 const std::vector<std::string>& codecs); | |
127 | |
128 // Get the extensions associated with the given mime type. This should be passed | 80 // Get the extensions associated with the given mime type. This should be passed |
129 // in lower case. There could be multiple extensions for a given mime type, like | 81 // in lower case. There could be multiple extensions for a given mime type, like |
130 // "html,htm" for "text/html", or "txt,text,html,..." for "text/*". | 82 // "html,htm" for "text/html", or "txt,text,html,..." for "text/*". |
131 // Note that we do not erase the existing elements in the the provided vector. | 83 // Note that we do not erase the existing elements in the the provided vector. |
132 // Instead, we append the result to it. | 84 // Instead, we append the result to it. |
133 NET_EXPORT void GetExtensionsForMimeType( | 85 NET_EXPORT void GetExtensionsForMimeType( |
134 const std::string& mime_type, | 86 const std::string& mime_type, |
135 std::vector<base::FilePath::StringType>* extensions); | 87 std::vector<base::FilePath::StringType>* extensions); |
136 | 88 |
137 // Test only method that removes proprietary media types and codecs from the | |
138 // list of supported MIME types and codecs. These types and codecs must be | |
139 // removed to ensure consistent layout test results across all Chromium | |
140 // variations. | |
141 NET_EXPORT void RemoveProprietaryMediaTypesAndCodecsForTests(); | |
142 | |
143 // Returns the IANA media type contained in |mime_type|, or an empty | 89 // Returns the IANA media type contained in |mime_type|, or an empty |
144 // string if |mime_type| does not specifify a known media type. | 90 // string if |mime_type| does not specifify a known media type. |
145 // Supported media types are defined at: | 91 // Supported media types are defined at: |
146 // http://www.iana.org/assignments/media-types/index.html | 92 // http://www.iana.org/assignments/media-types/index.html |
147 NET_EXPORT const std::string GetIANAMediaType(const std::string& mime_type); | 93 NET_EXPORT const std::string GetIANAMediaType(const std::string& mime_type); |
148 | 94 |
149 // A list of supported certificate-related mime types. | 95 // A list of supported certificate-related mime types. |
150 enum CertificateMimeType { | 96 enum CertificateMimeType { |
151 #define CERTIFICATE_MIME_TYPE(name, value) CERTIFICATE_MIME_TYPE_ ## name = valu
e, | 97 #define CERTIFICATE_MIME_TYPE(name, value) CERTIFICATE_MIME_TYPE_ ## name = valu
e, |
152 #include "net/base/mime_util_certificate_type_list.h" | 98 #include "net/base/mime_util_certificate_type_list.h" |
(...skipping 11 matching lines...) Expand all Loading... |
164 std::string* post_data); | 110 std::string* post_data); |
165 | 111 |
166 // Adds the final delimiter to a multi-part upload request. | 112 // Adds the final delimiter to a multi-part upload request. |
167 NET_EXPORT void AddMultipartFinalDelimiterForUpload( | 113 NET_EXPORT void AddMultipartFinalDelimiterForUpload( |
168 const std::string& mime_boundary, | 114 const std::string& mime_boundary, |
169 std::string* post_data); | 115 std::string* post_data); |
170 | 116 |
171 } // namespace net | 117 } // namespace net |
172 | 118 |
173 #endif // NET_BASE_MIME_UTIL_H__ | 119 #endif // NET_BASE_MIME_UTIL_H__ |
OLD | NEW |