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