[Mac] Enable MacViews bookmark editor behind --enable-mac-views-dialogs.
[chromium-blink-merge.git] / net / base / mime_util.h
blob34fcedafaa37f3af9c640172b57790bf7bf6abbc
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
3 // found in the LICENSE file.
5 #ifndef NET_BASE_MIME_UTIL_H__
6 #define NET_BASE_MIME_UTIL_H__
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.
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.
17 // All constants in mime_util.cc must be written in lower case, except parameter
18 // values, which can be any case.
20 #include <string>
21 #include <vector>
23 #include "base/files/file_path.h"
24 #include "net/base/net_export.h"
26 namespace net {
28 // Get the mime type (if any) that is associated with the given file extension.
29 // Returns true if a corresponding mime type exists.
30 NET_EXPORT bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
31 std::string* mime_type);
33 // Get the mime type (if any) that is associated with the given file extension.
34 // Returns true if a corresponding mime type exists. In this method,
35 // the search for a mime type is constrained to a limited set of
36 // types known to the net library, the OS/registry is not consulted.
37 NET_EXPORT bool GetWellKnownMimeTypeFromExtension(
38 const base::FilePath::StringType& ext,
39 std::string* mime_type);
41 // Get the mime type (if any) that is associated with the given file. Returns
42 // true if a corresponding mime type exists.
43 NET_EXPORT bool GetMimeTypeFromFile(const base::FilePath& file_path,
44 std::string* 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
48 // returned without a prefixed dot, ex "html".
49 NET_EXPORT bool GetPreferredExtensionForMimeType(
50 const std::string& mime_type,
51 base::FilePath::StringType* extension);
53 // Returns true if this the mime_type_pattern matches a given mime-type.
54 // Checks for absolute matching and wildcards. MIME types are case insensitive.
55 NET_EXPORT bool MatchesMimeType(const std::string& mime_type_pattern,
56 const std::string& mime_type);
58 // 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
60 // definition of content ABNF in RFC2045 and media-type ABNF httpbis p2
61 // semantics).
63 // token "/" token
65 // If |top_level_type| is non-NULL, sets it to parsed top-level type string.
66 // If |subtype| is non-NULL, sets it to parsed subtype string.
67 NET_EXPORT bool ParseMimeTypeWithoutParameter(const std::string& type_string,
68 std::string* top_level_type,
69 std::string* subtype);
71 // Returns true if the |type_string| is a top-level type of any media type
72 // registered with IANA media types registry at
73 // http://www.iana.org/assignments/media-types/media-types.xhtml or an
74 // experimental type (type with x- prefix).
76 // This method doesn't check that the input conforms to token ABNF, so if input
77 // is experimental type strings, you need to check check that before using
78 // this method.
79 NET_EXPORT bool IsValidTopLevelMimeType(const std::string& type_string);
81 // Get the extensions associated with the given mime type. There could be
82 // multiple extensions for a given mime type, like "html,htm" for "text/html",
83 // or "txt,text,html,..." for "text/*".
84 // Note that we do not erase the existing elements in the the provided vector.
85 // Instead, we append the result to it.
86 NET_EXPORT void GetExtensionsForMimeType(
87 const std::string& mime_type,
88 std::vector<base::FilePath::StringType>* extensions);
90 // A list of supported certificate-related mime types.
92 // A Java counterpart will be generated for this enum.
93 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
94 enum CertificateMimeType {
95 CERTIFICATE_MIME_TYPE_UNKNOWN,
96 CERTIFICATE_MIME_TYPE_X509_USER_CERT,
97 CERTIFICATE_MIME_TYPE_X509_CA_CERT,
98 CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE,
101 // Prepares one value as part of a multi-part upload request.
102 NET_EXPORT void AddMultipartValueForUpload(const std::string& value_name,
103 const std::string& value,
104 const std::string& mime_boundary,
105 const std::string& content_type,
106 std::string* post_data);
108 // Adds the final delimiter to a multi-part upload request.
109 NET_EXPORT void AddMultipartFinalDelimiterForUpload(
110 const std::string& mime_boundary,
111 std::string* post_data);
113 struct MimeInfo {
114 const char* const mime_type;
115 const char* const extensions; // comma separated list
118 // Finds mime type of |ext| from |mappings|.
119 const char* FindMimeType(const MimeInfo* mappings,
120 size_t mappings_len,
121 const std::string& ext);
123 } // namespace net
125 #endif // NET_BASE_MIME_UTIL_H__