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 // This file defines MIME utility functions. All of them assume the MIME type | 8 // This file defines MIME utility functions. All of them assume the MIME type |
9 // to be of the format specified by rfc2045. According to it, MIME types are | 9 // to be of the format specified by rfc2045. According to it, MIME types are |
10 // case strongly insensitive except parameter values, which may or may not be | 10 // case strongly insensitive except parameter values, which may or may not be |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Get the preferred extension (if any) associated with the given mime type. | 46 // Get the preferred extension (if any) associated with the given mime type. |
47 // Returns true if a corresponding file extension exists. The extension is | 47 // Returns true if a corresponding file extension exists. The extension is |
48 // returned without a prefixed dot, ex "html". | 48 // returned without a prefixed dot, ex "html". |
49 NET_EXPORT bool GetPreferredExtensionForMimeType( | 49 NET_EXPORT bool GetPreferredExtensionForMimeType( |
50 const std::string& mime_type, | 50 const std::string& mime_type, |
51 base::FilePath::StringType* extension); | 51 base::FilePath::StringType* extension); |
52 | 52 |
53 // Check to see if a particular MIME type is in our list. | 53 // Check to see if a particular MIME type is in our list. |
54 NET_EXPORT bool IsSupportedImageMimeType(const std::string& mime_type); | 54 NET_EXPORT bool IsSupportedImageMimeType(const std::string& mime_type); |
55 NET_EXPORT bool IsSupportedMediaMimeType(const std::string& mime_type); | |
56 NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type); | 55 NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type); |
57 NET_EXPORT bool IsUnsupportedTextMimeType(const std::string& mime_type); | 56 NET_EXPORT bool IsUnsupportedTextMimeType(const std::string& mime_type); |
58 NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type); | 57 NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type); |
59 NET_EXPORT bool IsSupportedCertificateMimeType(const std::string& mime_type); | 58 NET_EXPORT bool IsSupportedCertificateMimeType(const std::string& mime_type); |
60 | 59 |
61 // Convenience function. | 60 // TODO(servolk): This function is deprecated, use content::IsSupportedMimeType |
62 NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type); | 61 // instead. This one doesn't include supported media mime types. It will |
| 62 // be removed once net::Filter stops using it and the rest of mime_util code |
| 63 // is moved to content/public/common/mime_util |
| 64 NET_EXPORT bool IsSupportedMimeType_deprecated(const std::string& mime_type); |
63 | 65 |
64 // Returns true if this the mime_type_pattern matches a given mime-type. | 66 // Returns true if this the mime_type_pattern matches a given mime-type. |
65 // Checks for absolute matching and wildcards. MIME types are case insensitive. | 67 // Checks for absolute matching and wildcards. MIME types are case insensitive. |
66 NET_EXPORT bool MatchesMimeType(const std::string& mime_type_pattern, | 68 NET_EXPORT bool MatchesMimeType(const std::string& mime_type_pattern, |
67 const std::string& mime_type); | 69 const std::string& mime_type); |
68 | 70 |
69 // Returns true if the |type_string| is a correctly-formed mime type specifier | 71 // Returns true if the |type_string| is a correctly-formed mime type specifier |
70 // with no parameter, i.e. string that matches the following ABNF (see the | 72 // with no parameter, i.e. string that matches the following ABNF (see the |
71 // definition of content ABNF in RFC2045 and media-type ABNF httpbis p2 | 73 // definition of content ABNF in RFC2045 and media-type ABNF httpbis p2 |
72 // semantics). | 74 // semantics). |
73 // | 75 // |
74 // token "/" token | 76 // token "/" token |
75 // | 77 // |
76 // If |top_level_type| is non-NULL, sets it to parsed top-level type string. | 78 // If |top_level_type| is non-NULL, sets it to parsed top-level type string. |
77 // If |subtype| is non-NULL, sets it to parsed subtype string. | 79 // If |subtype| is non-NULL, sets it to parsed subtype string. |
78 NET_EXPORT bool ParseMimeTypeWithoutParameter(const std::string& type_string, | 80 NET_EXPORT bool ParseMimeTypeWithoutParameter(const std::string& type_string, |
79 std::string* top_level_type, | 81 std::string* top_level_type, |
80 std::string* subtype); | 82 std::string* subtype); |
81 | 83 |
82 // Returns true if the |type_string| is a top-level type of any media type | 84 // Returns true if the |type_string| is a top-level type of any media type |
83 // registered with IANA media types registry at | 85 // registered with IANA media types registry at |
84 // http://www.iana.org/assignments/media-types/media-types.xhtml or an | 86 // http://www.iana.org/assignments/media-types/media-types.xhtml or an |
85 // experimental type (type with x- prefix). | 87 // experimental type (type with x- prefix). |
86 // | 88 // |
87 // This method doesn't check that the input conforms to token ABNF, so if input | 89 // This method doesn't check that the input conforms to token ABNF, so if input |
88 // is experimental type strings, you need to check check that before using | 90 // is experimental type strings, you need to check check that before using |
89 // this method. | 91 // this method. |
90 NET_EXPORT bool IsValidTopLevelMimeType(const std::string& type_string); | 92 NET_EXPORT bool IsValidTopLevelMimeType(const std::string& type_string); |
91 | 93 |
92 // Returns true if and only if all codecs are supported, false otherwise. | |
93 NET_EXPORT bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs); | |
94 | |
95 // Parses a codec string, populating |codecs_out| with the prefix of each codec | |
96 // in the string |codecs_in|. For example, passed "aaa.b.c,dd.eee", if | |
97 // |strip| == true |codecs_out| will contain {"aaa", "dd"}, if |strip| == false | |
98 // |codecs_out| will contain {"aaa.b.c", "dd.eee"}. | |
99 // See http://www.ietf.org/rfc/rfc4281.txt. | |
100 NET_EXPORT void ParseCodecString(const std::string& codecs, | |
101 std::vector<std::string>* codecs_out, | |
102 bool strip); | |
103 | |
104 // Check to see if a particular MIME type is in our list which only supports a | |
105 // certain subset of codecs. | |
106 NET_EXPORT bool IsStrictMediaMimeType(const std::string& mime_type); | |
107 | |
108 // Indicates that the MIME type and (possible codec string) are supported by the | |
109 // underlying platform. | |
110 enum SupportsType { | |
111 // The underlying platform is known not to support the given MIME type and | |
112 // codec combination. | |
113 IsNotSupported, | |
114 | |
115 // The underlying platform is known to support the given MIME type and codec | |
116 // combination. | |
117 IsSupported, | |
118 | |
119 // The underlying platform is unsure whether the given MIME type and codec | |
120 // combination can be rendered or not before actually trying to play it. | |
121 MayBeSupported | |
122 }; | |
123 | |
124 // Checks the |mime_type| and |codecs| against the MIME types known to support | |
125 // only a particular subset of codecs. | |
126 // * Returns IsSupported if the |mime_type| is supported and all the codecs | |
127 // within the |codecs| are supported for the |mime_type|. | |
128 // * Returns MayBeSupported if the |mime_type| is supported and is known to | |
129 // support only a subset of codecs, but |codecs| was empty. Also returned if | |
130 // all the codecs in |codecs| are supported, but additional codec parameters | |
131 // were supplied (such as profile) for which the support cannot be decided. | |
132 // * Returns IsNotSupported if either the |mime_type| is not supported or the | |
133 // |mime_type| is supported but at least one of the codecs within |codecs| is | |
134 // not supported for the |mime_type|. | |
135 NET_EXPORT SupportsType IsSupportedStrictMediaMimeType( | |
136 const std::string& mime_type, | |
137 const std::vector<std::string>& codecs); | |
138 | |
139 // Get the extensions associated with the given mime type. There could be | 94 // Get the extensions associated with the given mime type. There could be |
140 // multiple extensions for a given mime type, like "html,htm" for "text/html", | 95 // multiple extensions for a given mime type, like "html,htm" for "text/html", |
141 // or "txt,text,html,..." for "text/*". | 96 // or "txt,text,html,..." for "text/*". |
142 // Note that we do not erase the existing elements in the the provided vector. | 97 // Note that we do not erase the existing elements in the the provided vector. |
143 // Instead, we append the result to it. | 98 // Instead, we append the result to it. |
144 NET_EXPORT void GetExtensionsForMimeType( | 99 NET_EXPORT void GetExtensionsForMimeType( |
145 const std::string& mime_type, | 100 const std::string& mime_type, |
146 std::vector<base::FilePath::StringType>* extensions); | 101 std::vector<base::FilePath::StringType>* extensions); |
147 | 102 |
148 // Test only method that removes proprietary media types and codecs from the | |
149 // list of supported MIME types and codecs. These types and codecs must be | |
150 // removed to ensure consistent layout test results across all Chromium | |
151 // variations. | |
152 NET_EXPORT void RemoveProprietaryMediaTypesAndCodecsForTests(); | |
153 | |
154 // A list of supported certificate-related mime types. | 103 // A list of supported certificate-related mime types. |
155 // | 104 // |
156 // A Java counterpart will be generated for this enum. | 105 // A Java counterpart will be generated for this enum. |
157 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | 106 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
158 enum CertificateMimeType { | 107 enum CertificateMimeType { |
159 CERTIFICATE_MIME_TYPE_UNKNOWN, | 108 CERTIFICATE_MIME_TYPE_UNKNOWN, |
160 CERTIFICATE_MIME_TYPE_X509_USER_CERT, | 109 CERTIFICATE_MIME_TYPE_X509_USER_CERT, |
161 CERTIFICATE_MIME_TYPE_X509_CA_CERT, | 110 CERTIFICATE_MIME_TYPE_X509_CA_CERT, |
162 CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE, | 111 CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE, |
163 }; | 112 }; |
164 | 113 |
165 NET_EXPORT CertificateMimeType GetCertificateMimeTypeForMimeType( | 114 NET_EXPORT CertificateMimeType GetCertificateMimeTypeForMimeType( |
166 const std::string& mime_type); | 115 const std::string& mime_type); |
167 | 116 |
168 // Prepares one value as part of a multi-part upload request. | 117 // Prepares one value as part of a multi-part upload request. |
169 NET_EXPORT void AddMultipartValueForUpload(const std::string& value_name, | 118 NET_EXPORT void AddMultipartValueForUpload(const std::string& value_name, |
170 const std::string& value, | 119 const std::string& value, |
171 const std::string& mime_boundary, | 120 const std::string& mime_boundary, |
172 const std::string& content_type, | 121 const std::string& content_type, |
173 std::string* post_data); | 122 std::string* post_data); |
174 | 123 |
175 // Adds the final delimiter to a multi-part upload request. | 124 // Adds the final delimiter to a multi-part upload request. |
176 NET_EXPORT void AddMultipartFinalDelimiterForUpload( | 125 NET_EXPORT void AddMultipartFinalDelimiterForUpload( |
177 const std::string& mime_boundary, | 126 const std::string& mime_boundary, |
178 std::string* post_data); | 127 std::string* post_data); |
179 | 128 |
180 } // namespace net | 129 } // namespace net |
181 | 130 |
182 #endif // NET_BASE_MIME_UTIL_H__ | 131 #endif // NET_BASE_MIME_UTIL_H__ |
OLD | NEW |