Bug 465007. Harmonize content sniffing in HTML5 and Firefox. r=jdrew,sr=bzbarsky

This commit is contained in:
Adam Barth 2009-04-06 12:30:03 +12:00
Родитель 814ccae327
Коммит 859398b84c
2 изменённых файлов: 10 добавлений и 5 удалений

Просмотреть файл

@ -1459,15 +1459,21 @@ NS_IMETHODIMP imgLoader::GetMIMETypeFromContent(nsIRequest* aRequest,
nsresult imgLoader::GetMimeTypeFromContent(const char* aContents, PRUint32 aLength, nsACString& aContentType)
{
/* Is it a GIF? */
if (aLength >= 4 && !nsCRT::strncmp(aContents, "GIF8", 4)) {
if (aLength >= 6 && (!nsCRT::strncmp(aContents, "GIF87a", 6) ||
!nsCRT::strncmp(aContents, "GIF89a", 6)))
{
aContentType.AssignLiteral("image/gif");
}
/* or a PNG? */
else if (aLength >= 4 && ((unsigned char)aContents[0]==0x89 &&
else if (aLength >= 8 && ((unsigned char)aContents[0]==0x89 &&
(unsigned char)aContents[1]==0x50 &&
(unsigned char)aContents[2]==0x4E &&
(unsigned char)aContents[3]==0x47))
(unsigned char)aContents[3]==0x47 &&
(unsigned char)aContents[4]==0x0D &&
(unsigned char)aContents[5]==0x0A &&
(unsigned char)aContents[6]==0x1A &&
(unsigned char)aContents[7]==0x0A))
{
aContentType.AssignLiteral("image/png");
}

Просмотреть файл

@ -60,7 +60,7 @@
#include "nsNetCID.h"
#define MAX_BUFFER_SIZE 1024
#define MAX_BUFFER_SIZE 512
nsUnknownDecoder::nsUnknownDecoder()
: mBuffer(nsnull)
@ -313,7 +313,6 @@ nsUnknownDecoder::nsSnifferEntry nsUnknownDecoder::sSnifferEntries[] = {
SNIFFER_ENTRY("%PDF-", APPLICATION_PDF),
SNIFFER_ENTRY("%!PS-Adobe-", APPLICATION_POSTSCRIPT),
SNIFFER_ENTRY("%! PS-Adobe-", APPLICATION_POSTSCRIPT),
// Files that start with mailbox delimiters let's provisionally call
// text/plain