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_SNIFFER_H__ 6#define NET_BASE_MIME_SNIFFER_H__ 7#pragma once 8 9#include <string> 10 11class GURL; 12 13namespace net { 14 15// 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 17// |SniffMimeType|. 18// This must be updated if any internal sniffing routine needs more bytes. 19const int kMaxBytesToSniff = 1024; 20 21// Examine the URL and the mime_type and decide whether we should sniff a 22// replacement mime type from the content. 23// 24// @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. 26// @return Returns true if we should sniff the mime type. 27bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type); 28 29// 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. 31// 32// @param content A buffer containing the bytes to sniff. 33// @param content_size The number of bytes in the |content| buffer. 34// @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. 36// @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. 38bool SniffMimeType(const char* content, size_t content_size, 39 const GURL& url, const std::string& type_hint, 40 std::string* result); 41 42} // namespace net 43 44#endif // NET_BASE_MIME_SNIFFER_H__ 45