| 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 // Convenience function. |
| 62 NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type); | 61 NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type); |
| 63 | 62 |
| 64 // Returns true if this the mime_type_pattern matches a given mime-type. | 63 // 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. | 64 // Checks for absolute matching and wildcards. MIME types are case insensitive. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 82 // Returns true if the |type_string| is a top-level type of any media type | 81 // Returns true if the |type_string| is a top-level type of any media type |
| 83 // registered with IANA media types registry at | 82 // registered with IANA media types registry at |
| 84 // http://www.iana.org/assignments/media-types/media-types.xhtml or an | 83 // http://www.iana.org/assignments/media-types/media-types.xhtml or an |
| 85 // experimental type (type with x- prefix). | 84 // experimental type (type with x- prefix). |
| 86 // | 85 // |
| 87 // This method doesn't check that the input conforms to token ABNF, so if input | 86 // 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 | 87 // is experimental type strings, you need to check check that before using |
| 89 // this method. | 88 // this method. |
| 90 NET_EXPORT bool IsValidTopLevelMimeType(const std::string& type_string); | 89 NET_EXPORT bool IsValidTopLevelMimeType(const std::string& type_string); |
| 91 | 90 |
| 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 | 91 // 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", | 92 // multiple extensions for a given mime type, like "html,htm" for "text/html", |
| 141 // or "txt,text,html,..." for "text/*". | 93 // or "txt,text,html,..." for "text/*". |
| 142 // Note that we do not erase the existing elements in the the provided vector. | 94 // Note that we do not erase the existing elements in the the provided vector. |
| 143 // Instead, we append the result to it. | 95 // Instead, we append the result to it. |
| 144 NET_EXPORT void GetExtensionsForMimeType( | 96 NET_EXPORT void GetExtensionsForMimeType( |
| 145 const std::string& mime_type, | 97 const std::string& mime_type, |
| 146 std::vector<base::FilePath::StringType>* extensions); | 98 std::vector<base::FilePath::StringType>* extensions); |
| 147 | 99 |
| 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. | 100 // A list of supported certificate-related mime types. |
| 155 // | 101 // |
| 156 // A Java counterpart will be generated for this enum. | 102 // A Java counterpart will be generated for this enum. |
| 157 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | 103 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
| 158 enum CertificateMimeType { | 104 enum CertificateMimeType { |
| 159 CERTIFICATE_MIME_TYPE_UNKNOWN, | 105 CERTIFICATE_MIME_TYPE_UNKNOWN, |
| 160 CERTIFICATE_MIME_TYPE_X509_USER_CERT, | 106 CERTIFICATE_MIME_TYPE_X509_USER_CERT, |
| 161 CERTIFICATE_MIME_TYPE_X509_CA_CERT, | 107 CERTIFICATE_MIME_TYPE_X509_CA_CERT, |
| 162 CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE, | 108 CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE, |
| 163 }; | 109 }; |
| 164 | 110 |
| 165 NET_EXPORT CertificateMimeType GetCertificateMimeTypeForMimeType( | 111 NET_EXPORT CertificateMimeType GetCertificateMimeTypeForMimeType( |
| 166 const std::string& mime_type); | 112 const std::string& mime_type); |
| 167 | 113 |
| 168 // Prepares one value as part of a multi-part upload request. | 114 // Prepares one value as part of a multi-part upload request. |
| 169 NET_EXPORT void AddMultipartValueForUpload(const std::string& value_name, | 115 NET_EXPORT void AddMultipartValueForUpload(const std::string& value_name, |
| 170 const std::string& value, | 116 const std::string& value, |
| 171 const std::string& mime_boundary, | 117 const std::string& mime_boundary, |
| 172 const std::string& content_type, | 118 const std::string& content_type, |
| 173 std::string* post_data); | 119 std::string* post_data); |
| 174 | 120 |
| 175 // Adds the final delimiter to a multi-part upload request. | 121 // Adds the final delimiter to a multi-part upload request. |
| 176 NET_EXPORT void AddMultipartFinalDelimiterForUpload( | 122 NET_EXPORT void AddMultipartFinalDelimiterForUpload( |
| 177 const std::string& mime_boundary, | 123 const std::string& mime_boundary, |
| 178 std::string* post_data); | 124 std::string* post_data); |
| 179 | 125 |
| 180 } // namespace net | 126 } // namespace net |
| 181 | 127 |
| 182 #endif // NET_BASE_MIME_UTIL_H__ | 128 #endif // NET_BASE_MIME_UTIL_H__ |
| OLD | NEW |