1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

LibWeb/MimeSniff: Add sniffing in an audio or video context

This commit is contained in:
Kemal Zebari 2023-11-09 15:32:34 -08:00 committed by Andrew Kaster
parent 02ea85da2c
commit 3a820ddbdf
3 changed files with 86 additions and 7 deletions

View file

@ -540,6 +540,8 @@ ErrorOr<void> Resource::context_specific_sniffing_algorithm(SniffingContext snif
if (sniffing_context == SniffingContext::Image)
return rules_for_sniffing_images_specifically();
if (sniffing_context == SniffingContext::AudioOrVideo)
return rules_for_sniffing_audio_or_video_specifically();
return {};
}
@ -576,4 +578,36 @@ ErrorOr<void> Resource::rules_for_sniffing_images_specifically()
return {};
}
// https://mimesniff.spec.whatwg.org/#sniffing-in-an-audio-or-video-context
ErrorOr<void> Resource::rules_for_sniffing_audio_or_video_specifically()
{
// 1. If the supplied MIME type is an XML MIME type, the computed MIME type is the supplied MIME type.
// Abort these steps.
// NOTE: Non-standard but due to the mime type detection algorithm we need this sanity check.
if (m_supplied_mime_type.has_value() && m_supplied_mime_type->is_xml()) {
m_computed_mime_type = m_supplied_mime_type.value();
return {};
}
// 2. Let audio-or-video-type-matched be the result of executing the audio or video type pattern matching
// algorithm with the resource header as the byte sequence to be matched.
auto audio_or_video_type_matched = TRY(match_an_audio_or_video_type_pattern(resource_header()));
// 3. If audio-or-video-type-matched is not undefined, the computed MIME type is audio-or-video-type-matched.
// Abort these steps.
if (audio_or_video_type_matched.has_value()) {
m_computed_mime_type = audio_or_video_type_matched.release_value();
return {};
}
// 4. The computed MIME type is the supplied MIME type.
// NOTE: Non-standard but due to the mime type detection algorithm we need this sanity check.
if (m_supplied_mime_type.has_value()) {
m_computed_mime_type = m_supplied_mime_type.value();
}
// NOTE: Non-standard but if the supplied mime type is undefined, we use computed mime type's default value.
return {};
}
}