OLD | NEW |
1 // Copyright (c) 2011 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" | 11 #include "net/base/net_export.h" |
12 | 12 |
13 class GURL; | 13 class GURL; |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 // 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 |
18 // 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 |
19 // |SniffMimeType|. | 19 // |SniffMimeType|. |
20 // 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. |
21 const int kMaxBytesToSniff = 1024; | 21 const int kMaxBytesToSniff = 1024; |
22 | 22 |
23 // 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 |
24 // replacement mime type from the content. | 24 // replacement mime type from the content. |
25 // | 25 // |
26 // @param url The URL from which we obtained the content. | 26 // @param url The URL from which we obtained the content. |
27 // @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. |
28 // @return Returns true if we should sniff the mime type. | 28 // @return Returns true if we should sniff the mime type. |
29 NET_API bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type); | 29 NET_EXPORT bool ShouldSniffMimeType(const GURL& url, |
| 30 const std::string& mime_type); |
30 | 31 |
31 // Guess a mime type from the first few bytes of content an its URL. Always | 32 // 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. | 33 // assigns |result| with its best guess of a mime type. |
33 // | 34 // |
34 // @param content A buffer containing the bytes to sniff. | 35 // @param content A buffer containing the bytes to sniff. |
35 // @param content_size The number of bytes in the |content| buffer. | 36 // @param content_size The number of bytes in the |content| buffer. |
36 // @param url The URL from which we obtained this content. | 37 // @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 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 // @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 // @return Returns true if we have enough content to guess the mime type. |
40 NET_API bool SniffMimeType(const char* content, size_t content_size, | 41 NET_EXPORT bool SniffMimeType(const char* content, size_t content_size, |
41 const GURL& url, const std::string& type_hint, | 42 const GURL& url, const std::string& type_hint, |
42 std::string* result); | 43 std::string* result); |
43 | 44 |
44 } // namespace net | 45 } // namespace net |
45 | 46 |
46 #endif // NET_BASE_MIME_SNIFFER_H__ | 47 #endif // NET_BASE_MIME_SNIFFER_H__ |
OLD | NEW |