OLD | NEW |
1 // Copyright (c) 2010 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_SNIFFER_H__ | 5 #ifndef NET_BASE_MIME_SNIFFER_H__ |
6 #define NET_BASE_MIME_SNIFFER_H__ | 6 #define NET_BASE_MIME_SNIFFER_H__ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
| 11 #include "net/base/net_api.h" |
| 12 |
11 class GURL; | 13 class GURL; |
12 | 14 |
13 namespace net { | 15 namespace net { |
14 | 16 |
15 // The maximum number of bytes used by any internal mime sniffing routine. May | 17 // The maximum number of bytes used by any internal mime sniffing routine. May |
16 // be useful for callers to determine an efficient buffer size to pass to | 18 // be useful for callers to determine an efficient buffer size to pass to |
17 // |SniffMimeType|. | 19 // |SniffMimeType|. |
18 // This must be updated if any internal sniffing routine needs more bytes. | 20 // This must be updated if any internal sniffing routine needs more bytes. |
19 const int kMaxBytesToSniff = 1024; | 21 const int kMaxBytesToSniff = 1024; |
20 | 22 |
21 // Examine the URL and the mime_type and decide whether we should sniff a | 23 // Examine the URL and the mime_type and decide whether we should sniff a |
22 // replacement mime type from the content. | 24 // replacement mime type from the content. |
23 // | 25 // |
24 // @param url The URL from which we obtained the content. | 26 // @param url The URL from which we obtained the content. |
25 // @param mime_type The current mime type, e.g. from the Content-Type header. | 27 // @param mime_type The current mime type, e.g. from the Content-Type header. |
26 // @return Returns true if we should sniff the mime type. | 28 // @return Returns true if we should sniff the mime type. |
27 bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type); | 29 NET_API bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type); |
28 | 30 |
29 // Guess a mime type from the first few bytes of content an its URL. Always | 31 // Guess a mime type from the first few bytes of content an its URL. Always |
30 // assigns |result| with its best guess of a mime type. | 32 // assigns |result| with its best guess of a mime type. |
31 // | 33 // |
32 // @param content A buffer containing the bytes to sniff. | 34 // @param content A buffer containing the bytes to sniff. |
33 // @param content_size The number of bytes in the |content| buffer. | 35 // @param content_size The number of bytes in the |content| buffer. |
34 // @param url The URL from which we obtained this content. | 36 // @param url The URL from which we obtained this content. |
35 // @param type_hint The current mime type, e.g. from the Content-Type header. | 37 // @param type_hint The current mime type, e.g. from the Content-Type header. |
36 // @param result Address at which to place the sniffed mime type. | 38 // @param result Address at which to place the sniffed mime type. |
37 // @return Returns true if we have enough content to guess the mime type. | 39 // @return Returns true if we have enough content to guess the mime type. |
38 bool SniffMimeType(const char* content, size_t content_size, | 40 NET_API bool SniffMimeType(const char* content, size_t content_size, |
39 const GURL& url, const std::string& type_hint, | 41 const GURL& url, const std::string& type_hint, |
40 std::string* result); | 42 std::string* result); |
41 | 43 |
42 } // namespace net | 44 } // namespace net |
43 | 45 |
44 #endif // NET_BASE_MIME_SNIFFER_H__ | 46 #endif // NET_BASE_MIME_SNIFFER_H__ |
OLD | NEW |