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
3 // found in the LICENSE file.
5 #ifndef NET_BASE_MIME_SNIFFER_H__
6 #define NET_BASE_MIME_SNIFFER_H__
10 #include "net/base/net_export.h"
16 // The maximum number of bytes used by any internal mime sniffing routine. May
17 // be useful for callers to determine an efficient buffer size to pass to
19 // This must be updated if any internal sniffing routine needs more bytes.
20 const int kMaxBytesToSniff
= 1024;
22 // Examine the URL and the mime_type and decide whether we should sniff a
23 // replacement mime type from the content.
25 // @param url The URL from which we obtained the content.
26 // @param mime_type The current mime type, e.g. from the Content-Type header.
27 // @return Returns true if we should sniff the mime type.
28 NET_EXPORT
bool ShouldSniffMimeType(const GURL
& url
,
29 const std::string
& mime_type
);
31 // Guess a mime type from the first few bytes of content an its URL. Always
32 // assigns |result| with its best guess of a mime type.
34 // @param content A buffer containing the bytes to sniff.
35 // @param content_size The number of bytes in the |content| buffer.
36 // @param url The URL from which we obtained this content.
37 // @param type_hint The current mime type, e.g. from the Content-Type header.
38 // @param result Address at which to place the sniffed mime type.
39 // @return Returns true if we have enough content to guess the mime type.
40 NET_EXPORT
bool SniffMimeType(const char* content
, size_t content_size
,
41 const GURL
& url
, const std::string
& type_hint
,
44 // Attempt to identify a MIME type from the first few bytes of content only.
45 // Uses a bigger set of media file searches than |SniffMimeType()|.
46 // If finds a match, fills in |result| and returns true,
47 // otherwise returns false.
49 // The caller should understand the security ramifications of trusting
50 // uncontrolled data before accepting the results of this function.
52 // @param content A buffer containing the bytes to sniff.
53 // @param content_size The number of bytes in the |content| buffer.
54 // @param result Address at which to place the sniffed mime type.
55 // @return Returns true if a MIME type match was found.
56 NET_EXPORT
bool SniffMimeTypeFromLocalData(const char* content
,
62 #endif // NET_BASE_MIME_SNIFFER_H__