Add WebP content sniffing code.

This commit is contained in:
wolfbeast 2017-07-24 13:31:07 +02:00 committed by Roy Tam
commit 8b0dd2f40b
3 changed files with 90 additions and 0 deletions

View file

@ -2558,6 +2558,11 @@ imgLoader::GetMimeTypeFromContent(const char* aContents,
!memcmp(aContents, "\000\000\002\000", 4))) {
aContentType.AssignLiteral(IMAGE_ICO);
// WebPs always begin with RIFF, a 32-bit length, and WEBP.
} else if (aLength >= 12 && !memcmp(aContents, "RIFF", 4) &&
!memcmp(aContents + 8, "WEBP", 4)) {
aContentType.AssignLiteral(IMAGE_WEBP);
} else {
/* none of the above? I give up */
return NS_ERROR_NOT_AVAILABLE;