| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "net/base/net_api.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 // Get the mime type (if any) that is associated with the given file extension. | 17 // Get the mime type (if any) that is associated with the given file extension. |
| 17 // Returns true if a corresponding mime type exists. | 18 // Returns true if a corresponding mime type exists. |
| 18 bool GetMimeTypeFromExtension(const FilePath::StringType& ext, | 19 NET_API bool GetMimeTypeFromExtension(const FilePath::StringType& ext, |
| 19 std::string* mime_type); | 20 std::string* mime_type); |
| 20 | 21 |
| 21 // Get the mime type (if any) that is associated with the given file. Returns | 22 // Get the mime type (if any) that is associated with the given file. Returns |
| 22 // true if a corresponding mime type exists. | 23 // true if a corresponding mime type exists. |
| 23 bool GetMimeTypeFromFile(const FilePath& file_path, std::string* mime_type); | 24 NET_API bool GetMimeTypeFromFile(const FilePath& file_path, |
| 25 std::string* mime_type); |
| 24 | 26 |
| 25 // Get the preferred extension (if any) associated with the given mime type. | 27 // Get the preferred extension (if any) associated with the given mime type. |
| 26 // Returns true if a corresponding file extension exists. The extension is | 28 // Returns true if a corresponding file extension exists. The extension is |
| 27 // returned without a prefixed dot, ex "html". | 29 // returned without a prefixed dot, ex "html". |
| 28 bool GetPreferredExtensionForMimeType(const std::string& mime_type, | 30 NET_API bool GetPreferredExtensionForMimeType(const std::string& mime_type, |
| 29 FilePath::StringType* extension); | 31 FilePath::StringType* extension); |
| 30 | 32 |
| 31 // Check to see if a particular MIME type is in our list. | 33 // Check to see if a particular MIME type is in our list. |
| 32 bool IsSupportedImageMimeType(const char* mime_type); | 34 NET_API bool IsSupportedImageMimeType(const char* mime_type); |
| 33 bool IsSupportedMediaMimeType(const char* mime_type); | 35 NET_API bool IsSupportedMediaMimeType(const char* mime_type); |
| 34 bool IsSupportedNonImageMimeType(const char* mime_type); | 36 NET_API bool IsSupportedNonImageMimeType(const char* mime_type); |
| 35 bool IsSupportedJavascriptMimeType(const char* mime_type); | 37 NET_API bool IsSupportedJavascriptMimeType(const char* mime_type); |
| 36 | 38 |
| 37 // Get whether this mime type should be displayed in view-source mode. | 39 // Get whether this mime type should be displayed in view-source mode. |
| 38 // (For example, XML.) | 40 // (For example, XML.) |
| 39 bool IsViewSourceMimeType(const char* mime_type); | 41 NET_API bool IsViewSourceMimeType(const char* mime_type); |
| 40 | 42 |
| 41 // Convenience function. | 43 // Convenience function. |
| 42 bool IsSupportedMimeType(const std::string& mime_type); | 44 NET_API bool IsSupportedMimeType(const std::string& mime_type); |
| 43 | 45 |
| 44 // Returns true if this the mime_type_pattern matches a given mime-type. | 46 // Returns true if this the mime_type_pattern matches a given mime-type. |
| 45 // Checks for absolute matching and wildcards. mime-types should be in | 47 // Checks for absolute matching and wildcards. mime-types should be in |
| 46 // lower case. | 48 // lower case. |
| 47 bool MatchesMimeType(const std::string &mime_type_pattern, | 49 NET_API bool MatchesMimeType(const std::string &mime_type_pattern, |
| 48 const std::string &mime_type); | 50 const std::string &mime_type); |
| 49 | 51 |
| 50 // Returns true if and only if all codecs are supported, false otherwise. | 52 // Returns true if and only if all codecs are supported, false otherwise. |
| 51 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs); | 53 NET_API bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs); |
| 52 | 54 |
| 53 // Parses a codec string, populating |codecs_out| with the prefix of each codec | 55 // Parses a codec string, populating |codecs_out| with the prefix of each codec |
| 54 // in the string |codecs_in|. For example, passed "aaa.b.c,dd.eee", if | 56 // in the string |codecs_in|. For example, passed "aaa.b.c,dd.eee", if |
| 55 // |strip| == true |codecs_out| will contain {"aaa", "dd"}, if |strip| == false | 57 // |strip| == true |codecs_out| will contain {"aaa", "dd"}, if |strip| == false |
| 56 // |codecs_out| will contain {"aaa.b.c", "dd.eee"}. | 58 // |codecs_out| will contain {"aaa.b.c", "dd.eee"}. |
| 57 // See http://www.ietf.org/rfc/rfc4281.txt. | 59 // See http://www.ietf.org/rfc/rfc4281.txt. |
| 58 void ParseCodecString(const std::string& codecs, | 60 NET_API void ParseCodecString(const std::string& codecs, |
| 59 std::vector<std::string>* codecs_out, | 61 std::vector<std::string>* codecs_out, |
| 60 bool strip); | 62 bool strip); |
| 61 | 63 |
| 62 // Check to see if a particular MIME type is in our list which only supports a | 64 // Check to see if a particular MIME type is in our list which only supports a |
| 63 // certain subset of codecs. | 65 // certain subset of codecs. |
| 64 bool IsStrictMediaMimeType(const std::string& mime_type); | 66 NET_API bool IsStrictMediaMimeType(const std::string& mime_type); |
| 65 | 67 |
| 66 // Check to see if a particular MIME type is in our list which only supports a | 68 // Check to see if a particular MIME type is in our list which only supports a |
| 67 // certain subset of codecs. Returns true if and only if all codecs are | 69 // certain subset of codecs. Returns true if and only if all codecs are |
| 68 // supported for that specific MIME type, false otherwise. If this returns | 70 // supported for that specific MIME type, false otherwise. If this returns |
| 69 // false you will still need to check if the media MIME tpyes and codecs are | 71 // false you will still need to check if the media MIME tpyes and codecs are |
| 70 // supported. | 72 // supported. |
| 71 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, | 73 NET_API bool IsSupportedStrictMediaMimeType( |
| 74 const std::string& mime_type, |
| 72 const std::vector<std::string>& codecs); | 75 const std::vector<std::string>& codecs); |
| 73 | 76 |
| 74 // Get the extensions for images files. | 77 // Get the extensions for images files. |
| 75 // Note that we do not erase the existing elements in the the provided vector. | 78 // Note that we do not erase the existing elements in the the provided vector. |
| 76 // Instead, we append the result to it. | 79 // Instead, we append the result to it. |
| 77 void GetImageExtensions(std::vector<FilePath::StringType>* extensions); | 80 NET_API void GetImageExtensions(std::vector<FilePath::StringType>* extensions); |
| 78 | 81 |
| 79 // Get the extensions for audio files. | 82 // Get the extensions for audio files. |
| 80 // 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. |
| 81 // Instead, we append the result to it. | 84 // Instead, we append the result to it. |
| 82 void GetAudioExtensions(std::vector<FilePath::StringType>* extensions); | 85 NET_API void GetAudioExtensions(std::vector<FilePath::StringType>* extensions); |
| 83 | 86 |
| 84 // Get the extensions for video files. | 87 // Get the extensions for video files. |
| 85 // Note that we do not erase the existing elements in the the provided vector. | 88 // Note that we do not erase the existing elements in the the provided vector. |
| 86 // Instead, we append the result to it. | 89 // Instead, we append the result to it. |
| 87 void GetVideoExtensions(std::vector<FilePath::StringType>* extensions); | 90 NET_API void GetVideoExtensions(std::vector<FilePath::StringType>* extensions); |
| 88 | 91 |
| 89 // Get the extensions associated with the given mime type. | 92 // Get the extensions associated with the given mime type. |
| 90 // There could be multiple extensions for a given mime type, like "html,htm" | 93 // There could be multiple extensions for a given mime type, like "html,htm" |
| 91 // for "text/html". | 94 // for "text/html". |
| 92 // Note that we do not erase the existing elements in the the provided vector. | 95 // Note that we do not erase the existing elements in the the provided vector. |
| 93 // Instead, we append the result to it. | 96 // Instead, we append the result to it. |
| 94 void GetExtensionsForMimeType(const std::string& mime_type, | 97 NET_API void GetExtensionsForMimeType( |
| 95 std::vector<FilePath::StringType>* extensions); | 98 const std::string& mime_type, |
| 99 std::vector<FilePath::StringType>* extensions); |
| 96 | 100 |
| 97 } // namespace net | 101 } // namespace net |
| 98 | 102 |
| 99 #endif // NET_BASE_MIME_UTIL_H__ | 103 #endif // NET_BASE_MIME_UTIL_H__ |
| OLD | NEW |