| 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 |
| 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 |
| 11 // case sensitive. |
| 12 // |
| 13 // These utilities perform a *case-sensitive* matching for parameter values, |
| 14 // which may produce some false negatives. Except that, matching is |
| 15 // case-insensitive. |
| 16 // |
| 17 // All constants in mime_util.cc must be written in lower case, except parameter |
| 18 // values, which can be any case. |
| 19 |
| 8 #include <string> | 20 #include <string> |
| 9 #include <vector> | 21 #include <vector> |
| 10 | 22 |
| 11 #include "base/files/file_path.h" | 23 #include "base/files/file_path.h" |
| 12 #include "net/base/net_export.h" | 24 #include "net/base/net_export.h" |
| 13 | 25 |
| 14 namespace net { | 26 namespace net { |
| 15 | 27 |
| 16 // Get the mime type (if any) that is associated with the given file extension. | 28 // Get the mime type (if any) that is associated with the given file extension. |
| 17 // Returns true if a corresponding mime type exists. | 29 // Returns true if a corresponding mime type exists. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 43 NET_EXPORT bool IsSupportedMediaMimeType(const std::string& mime_type); | 55 NET_EXPORT bool IsSupportedMediaMimeType(const std::string& mime_type); |
| 44 NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type); | 56 NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type); |
| 45 NET_EXPORT bool IsUnsupportedTextMimeType(const std::string& mime_type); | 57 NET_EXPORT bool IsUnsupportedTextMimeType(const std::string& mime_type); |
| 46 NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type); | 58 NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type); |
| 47 NET_EXPORT bool IsSupportedCertificateMimeType(const std::string& mime_type); | 59 NET_EXPORT bool IsSupportedCertificateMimeType(const std::string& mime_type); |
| 48 | 60 |
| 49 // Convenience function. | 61 // Convenience function. |
| 50 NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type); | 62 NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type); |
| 51 | 63 |
| 52 // Returns true if this the mime_type_pattern matches a given mime-type. | 64 // 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 | 65 // Checks for absolute matching and wildcards. MIME types are case insensitive. |
| 54 // lower case. | |
| 55 NET_EXPORT bool MatchesMimeType(const std::string& mime_type_pattern, | 66 NET_EXPORT bool MatchesMimeType(const std::string& mime_type_pattern, |
| 56 const std::string& mime_type); | 67 const std::string& mime_type); |
| 57 | 68 |
| 58 // Returns true if the |type_string| is a correctly-formed mime type specifier | 69 // Returns true if the |type_string| is a correctly-formed mime type specifier |
| 59 // with no parameter, i.e. string that matches the following ABNF (see the | 70 // with no parameter, i.e. string that matches the following ABNF (see the |
| 60 // definition of content ABNF in RFC2045 and media-type ABNF httpbis p2 | 71 // definition of content ABNF in RFC2045 and media-type ABNF httpbis p2 |
| 61 // semantics). | 72 // semantics). |
| 62 // | 73 // |
| 63 // token "/" token | 74 // token "/" token |
| 64 // | 75 // |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // support only a subset of codecs, but |codecs| was empty. Also returned if | 129 // 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 | 130 // all the codecs in |codecs| are supported, but additional codec parameters |
| 120 // were supplied (such as profile) for which the support cannot be decided. | 131 // 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 | 132 // * 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 | 133 // |mime_type| is supported but at least one of the codecs within |codecs| is |
| 123 // not supported for the |mime_type|. | 134 // not supported for the |mime_type|. |
| 124 NET_EXPORT SupportsType IsSupportedStrictMediaMimeType( | 135 NET_EXPORT SupportsType IsSupportedStrictMediaMimeType( |
| 125 const std::string& mime_type, | 136 const std::string& mime_type, |
| 126 const std::vector<std::string>& codecs); | 137 const std::vector<std::string>& codecs); |
| 127 | 138 |
| 128 // Get the extensions associated with the given mime type. This should be passed | 139 // Get the extensions associated with the given mime type. There could be |
| 129 // in lower case. There could be multiple extensions for a given mime type, like | 140 // multiple extensions for a given mime type, like "html,htm" for "text/html", |
| 130 // "html,htm" for "text/html", or "txt,text,html,..." for "text/*". | 141 // or "txt,text,html,..." for "text/*". |
| 131 // Note that we do not erase the existing elements in the the provided vector. | 142 // Note that we do not erase the existing elements in the the provided vector. |
| 132 // Instead, we append the result to it. | 143 // Instead, we append the result to it. |
| 133 NET_EXPORT void GetExtensionsForMimeType( | 144 NET_EXPORT void GetExtensionsForMimeType( |
| 134 const std::string& mime_type, | 145 const std::string& mime_type, |
| 135 std::vector<base::FilePath::StringType>* extensions); | 146 std::vector<base::FilePath::StringType>* extensions); |
| 136 | 147 |
| 137 // Test only method that removes proprietary media types and codecs from the | 148 // 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 | 149 // list of supported MIME types and codecs. These types and codecs must be |
| 139 // removed to ensure consistent layout test results across all Chromium | 150 // removed to ensure consistent layout test results across all Chromium |
| 140 // variations. | 151 // variations. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 162 std::string* post_data); | 173 std::string* post_data); |
| 163 | 174 |
| 164 // Adds the final delimiter to a multi-part upload request. | 175 // Adds the final delimiter to a multi-part upload request. |
| 165 NET_EXPORT void AddMultipartFinalDelimiterForUpload( | 176 NET_EXPORT void AddMultipartFinalDelimiterForUpload( |
| 166 const std::string& mime_boundary, | 177 const std::string& mime_boundary, |
| 167 std::string* post_data); | 178 std::string* post_data); |
| 168 | 179 |
| 169 } // namespace net | 180 } // namespace net |
| 170 | 181 |
| 171 #endif // NET_BASE_MIME_UTIL_H__ | 182 #endif // NET_BASE_MIME_UTIL_H__ |
| OLD | NEW |