Bug 259419 - Better type handling in HTMLImageElement resource selection
Summary: Better type handling in HTMLImageElement resource selection
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2023-07-22 13:08 PDT by Ahmad Saleem
Modified: 2024-05-21 07:52 PDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2023-07-22 13:08:22 PDT
Hi Team,

While going through Blink's commit, I came across following commit:

Blink Commit: https://src.chromium.org/viewvc/blink?view=revision&revision=183450

Blink Function (as of today): https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/html_image_element.cc;l=402?q=isSupportedImagePrefixedMIMEType&ss=chromium

bool HTMLImageElement::SupportedImageType(
    const String& type,
    const HashSet<String>* disabled_image_types) {
  String trimmed_type = ContentType(type).GetType();
  // An empty type attribute is implicitly supported.
  if (trimmed_type.empty())
    return true;
  if (disabled_image_types && disabled_image_types->Contains(trimmed_type)) {
    return false;
  }
  return MIMETypeRegistry::IsSupportedImagePrefixedMIMEType(trimmed_type);
}
_______________

WebKit Source: https://searchfox.org/wubkat/source/Source/WebCore/platform/graphics/cg/UTIRegistry.cpp#126

^ If I am not wrong.

_______________

One thing, which is different and for reason, I raised this bug report is that, for 'empty type', Blink is returning 'true', while we are 'false'.

bool isSupportedImageType(const String& imageType)
{
    if (imageType.isEmpty())
        return false;
    return defaultSupportedImageTypes().contains(imageType) || additionalSupportedImageTypes().contains(imageType);
}

__________________

Just wanted to raise, so we can get this sorted and CCed 'Anne' (well-versed in Standards) to get input. Also 'Brent' and 'Tim' - if they have any information.

This was raised on GitHub as following issue: https://github.com/ResponsiveImagesCG/picture-element/issues/238 (Took from Chrome Monorail bug)

__________

Thanks!
Comment 1 Ahmad Saleem 2023-07-22 13:11:12 PDT
Or I am wrong and this is taking care of my question:

https://searchfox.org/wubkat/source/Source/WebCore/html/HTMLImageElement.cpp#268

if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(type))
Comment 2 Anne van Kesteren 2023-07-23 05:32:07 PDT
I recommend looking for tests in web-platform-tests or writing some to see how the type attribute is handled and whether that's consistent between browsers.
Comment 3 Radar WebKit Bug Importer 2023-07-29 13:09:15 PDT
<rdar://problem/113084785>
Comment 4 Karl Dubost 2023-08-20 20:00:50 PDT
Yes probably a couple of tests would help. 
And after quickly checking on WPT, I didn't find anything obvious testing the type attribute on the source element.

Probably testing:


# unknown string
<picture>
  <source type='unknown_type' srcset="something.png 400w, something2.png 800w">
  <img src="working_image.jpg">
</picture>


# unknown string + a known one.
<picture>
  <source type='unknown_type' srcset="something.png 400w, something2.png 800w">
  <source type='image/jpeg' srcset="something.jpg 400w, something2.jpg 800w">
  <img src="working_image.jpg">
</picture>


# empty string
<picture>
  <source type='' srcset="something.png 400w, something2.png 800w">
  <img src="working_image.jpg">
</picture>

# space string
<picture>
  <source type='' srcset="something.png 400w, something2.png 800w">
  <img src="working_image.jpg">
</picture>


# different type
<picture>
  <source type='image/webp' srcset="something.png 400w, something2.png 800w">
  <img src="working_image.jpg">
</picture>

etc.
Comment 5 Karl Dubost 2023-08-20 20:02:39 PDT
Note that there is 
https://wpt.fyi/results/media-source/mediasource-is-type-supported.html