[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / net / base / mime_sniffer.h
blob371a3309ad3190c02f8e38453506a5849e8e0382
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__
8 #include <string>
10 #include "net/base/net_export.h"
12 class GURL;
14 namespace net {
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
18 // |SniffMimeType|.
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,
42 std::string* result);
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,
57 size_t content_size,
58 std::string* result);
60 // Returns true if |content| contains bytes that are control codes that do
61 // not usually appear in plain text.
62 // @param content A buffer contains bytes that may be binary.
63 // @param size The number of bytes in the |content| buffer.
64 // @return Returns true if |content| looks like binary.
65 NET_EXPORT_PRIVATE bool LooksLikeBinary(const char* content, size_t size);
67 } // namespace net
69 #endif // NET_BASE_MIME_SNIFFER_H__