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