Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Camera RAW files picked via file input are returned as PNG on change
https://bugs.webkit.org/show_bug.cgi?id=258467 rdar://111231838 Reviewed by Cameron McCormack. Camera RAW type identifiers are registered with the system via the RawCamera bundle. While the list of supported RAW types is fairly comprehensive, many type identifiers are missing an associated MIME type. Consequently, when choosing a RAW file (such as NEF) for an input that supports RAW files and PNGs, the lack of correct information in the RawCamera bundle results in ".nef" getting mapped to a nil MIME type. WebKit also contains logic to automatically transcode images selected in file inputs to an accepted MIME type, if the current MIME type is unsupported, and the file is an image type. For file inputs that specify `accept` values in the form of extensions, the extensions are normalized to MIME types. For an input that supports RAW files and PNGs, WebKit attempts to transcode the image, as "image/png" is the only recognized MIME type, following the system lookup. Transcoding then succeeds, since ImageIO knows about the RAW type, and is able to convert it to a PNG. To fix, workaround the missing MIME type mappings in RawCamera.bundle, by explicitly declaring them in WebKit. * LayoutTests/TestExpectations: * LayoutTests/fast/forms/file/entries-api/png-raw-open-panel-expected.txt: Added. * LayoutTests/fast/forms/file/entries-api/png-raw-open-panel.html: Added. * LayoutTests/fast/forms/file/entries-api/resources/images/image.nef: Added. * LayoutTests/platform/mac-wk2/TestExpectations: * Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm: (WebCore::additionalMimeTypesMap): (WebCore::additionalExtensionsMap): (WebCore::MIMETypeRegistry::mimeTypeForExtension): (WebCore::MIMETypeRegistry::extensionsForMIMEType): (WebCore::MIMETypeRegistry::preferredExtensionForMIMEType): Canonical link: https://commits.webkit.org/266049@main
- Loading branch information
Showing
6 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
LayoutTests/fast/forms/file/entries-api/png-raw-open-panel-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
OPEN FILE PANEL | ||
Tests that a camera RAW file, chosen via the file picker which accepts RAW files and PNG images, does not transcode the file to PNG. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS fileList.length is 1 | ||
PASS file.name is "image.nef" | ||
PASS file.type is "image/x-nikon-nef" | ||
PASS file.size is 1955729 | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
36 changes: 36 additions & 0 deletions
36
LayoutTests/fast/forms/file/entries-api/png-raw-open-panel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../../../resources/js-test.js"></script> | ||
<script src="../../../../resources/ui-helper.js"></script> | ||
</head> | ||
<body> | ||
<input id="input" type="file" accept=".png, .nef"> | ||
</body> | ||
<script> | ||
|
||
jsTestIsAsync = true; | ||
|
||
addEventListener("load", async () => { | ||
description("Tests that a camera RAW file, chosen via the file picker which accepts RAW files and PNG images, does not transcode the file to PNG."); | ||
|
||
if (window.testRunner) | ||
testRunner.setOpenPanelFiles(['resources/images/image.nef']); | ||
|
||
input.addEventListener("change", (event) => { | ||
fileList = event.target.files; | ||
shouldBe("fileList.length", "1"); | ||
|
||
file = fileList[0]; | ||
shouldBeEqualToString("file.name", "image.nef"); | ||
shouldBeEqualToString("file.type", "image/x-nikon-nef"); | ||
shouldBe("file.size", "1955729"); | ||
|
||
finishJSTest(); | ||
}); | ||
|
||
UIHelper.activateElement(input); | ||
}); | ||
|
||
</script> | ||
</html> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters