Blob references for System Previews don't get a correct file extension
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jan 2019 01:17:41 +0000 (01:17 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jan 2019 01:17:41 +0000 (01:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193268
<rdar://problem/47133037>

Reviewed by Tim Horton.

Source/WebCore:

Apple platforms don't yet have a mapping from the USD MIME type to
file extensions (and we support some non-standard MIME types), which
means that downloads from Blob references don't get correctly named.

Fix this by adding an explicit mapping between System Preview types
and ".usdz".

WebKit API test: _WKDownload.SystemPreviewUSDZBlobNaming

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isSystemPreviewMIMEType): Remove USE(SYSTEM_PREVIEW) since
this applies to macOS and iOS now.
* platform/MIMETypeRegistry.h:
* platform/cocoa/MIMETypeRegistryCocoa.mm:
(WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType): Add a mapping
for USDZ.

Tools:

New test that a Blob download of a USDZ file gets named correctly.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
(-[BlobWithUSDZExtensionDownloadDelegate _download:decideDestinationWithSuggestedFilename:completionHandler:]):
(-[BlobWithUSDZExtensionDownloadDelegate _downloadDidFinish:]):
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/SystemPreviewBlobNaming.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239758 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreviewBlobNaming.html [new file with mode: 0644]

index 0e498f0..17a56b4 100644 (file)
@@ -1,3 +1,28 @@
+2019-01-08  Dean Jackson  <dino@apple.com>
+
+        Blob references for System Previews don't get a correct file extension
+        https://bugs.webkit.org/show_bug.cgi?id=193268
+        <rdar://problem/47133037>
+
+        Reviewed by Tim Horton.
+
+        Apple platforms don't yet have a mapping from the USD MIME type to
+        file extensions (and we support some non-standard MIME types), which
+        means that downloads from Blob references don't get correctly named.
+
+        Fix this by adding an explicit mapping between System Preview types
+        and ".usdz".
+
+        WebKit API test: _WKDownload.SystemPreviewUSDZBlobNaming
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::isSystemPreviewMIMEType): Remove USE(SYSTEM_PREVIEW) since
+        this applies to macOS and iOS now.
+        * platform/MIMETypeRegistry.h:
+        * platform/cocoa/MIMETypeRegistryCocoa.mm:
+        (WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType): Add a mapping
+        for USDZ.
+
 2019-01-08  Tim Horton  <timothy_horton@apple.com>
 
         Editable images sometimes don't become focused when tapped
index 15d3028..fdef56f 100644 (file)
@@ -651,7 +651,6 @@ const String& defaultMIMEType()
     return defaultMIMEType;
 }
 
-#if USE(SYSTEM_PREVIEW)
 const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::systemPreviewMIMETypes()
 {
     static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> systemPreviewMIMETypes = std::initializer_list<String> {
@@ -670,7 +669,6 @@ bool MIMETypeRegistry::isSystemPreviewMIMEType(const String& mimeType)
         return false;
     return systemPreviewMIMETypes().contains(mimeType);
 }
-#endif
 
 #if !USE(CURL)
 
index 19331ba..876c382 100644 (file)
@@ -87,9 +87,7 @@ public:
     static bool isPostScriptMIMEType(const String& mimeType);
     WEBCORE_EXPORT static bool isPDFOrPostScriptMIMEType(const String& mimeType);
 
-#if USE(SYSTEM_PREVIEW)
     WEBCORE_EXPORT static bool isSystemPreviewMIMEType(const String& mimeType);
-#endif
 
     // Check to see if a MIME type is suitable for being shown inside a page.
     // Returns true if any of isSupportedImageMIMEType(), isSupportedNonImageMIMEType(),
@@ -114,10 +112,7 @@ public:
     WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& supportedMediaMIMETypes();
     WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& pdfMIMETypes();
     WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& unsupportedTextMIMETypes();
-
-#if USE(SYSTEM_PREVIEW)
-    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& systemPreviewMIMETypes();
-#endif
+    WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& systemPreviewMIMETypes();
 
     // FIXME: WebKit coding style says we should not have the word "get" in the name of this function.
     // FIXME: Unclear what the concept of a normalized MIME type is; currently it's a platform-specific notion.
index a7306b5..a87cf5c 100644 (file)
@@ -52,6 +52,11 @@ Vector<String> MIMETypeRegistry::getExtensionsForMIMEType(const String& type)
 
 String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
 {
+    // System Previews accept some non-standard MIMETypes, so we can't rely on
+    // the file type mappings.
+    if (isSystemPreviewMIMEType(type))
+        return "usdz"_s;
+
     return [[NSURLFileTypeMappings sharedMappings] preferredExtensionForMIMEType:(NSString *)type];
 }
 
index 61bf0d6..f21329f 100644 (file)
@@ -1,3 +1,20 @@
+2019-01-08  Dean Jackson  <dino@apple.com>
+
+        Blob references for System Previews don't get a correct file extension
+        https://bugs.webkit.org/show_bug.cgi?id=193268
+        <rdar://problem/47133037>
+
+        Reviewed by Tim Horton.
+
+        New test that a Blob download of a USDZ file gets named correctly.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
+        (-[BlobWithUSDZExtensionDownloadDelegate _download:decideDestinationWithSuggestedFilename:completionHandler:]):
+        (-[BlobWithUSDZExtensionDownloadDelegate _downloadDidFinish:]):
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/SystemPreviewBlobNaming.html: Added.
+
 2019-01-08  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebAuthN] Support U2F HID Authenticators on macOS
index 5c33785..3bf2be6 100644 (file)
                2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */; };
                2EFF06D41D8AEDBB0004BB30 /* TestWKWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D31D8AEDBB0004BB30 /* TestWKWebView.mm */; };
                2EFF06D71D8AF34A0004BB30 /* WKWebViewCandidateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */; };
+               313C3A0221E567C300DBA86E /* SystemPreviewBlobNaming.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */; };
                315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; };
                315231CA1EB3B3C700A22A16 /* GPULegacyCommandQueue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 315231C91EB3B3C700A22A16 /* GPULegacyCommandQueue.mm */; };
                3162AE9C1E6F2FF5000E4DBC /* GPULegacyDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3162AE9B1E6F2FCE000E4DBC /* GPULegacyDevice.mm */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
-                               C9C9A91D21DED7A000FDE96E /* video-with-play-button.html in Copy Resources */,
-                               C9C9A91B21DED28700FDE96E /* audio-with-play-button.html in Copy Resources */,
                                55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
                                55A81800218102210004A39A /* 400x400-green.png in Copy Resources */,
                                37137E4B21124D01002BEEA4 /* AttrStyle.html in Copy Resources */,
                                CD9E292E1C90C33F000BB800 /* audio-only.html in Copy Resources */,
                                C944160021430E8900B1EDDA /* audio-with-controls.html in Copy Resources */,
+                               C9C9A91B21DED28700FDE96E /* audio-with-play-button.html in Copy Resources */,
                                CD57779C211CE91F001B371E /* audio-with-web-audio.html in Copy Resources */,
                                76E182DF154767E600F1FADD /* auto-submitting-form.html in Copy Resources */,
                                F41AB99F1EF4696B0083FA08 /* autofocus-contenteditable.html in Copy Resources */,
                                9BD6D3A31F7B218300BD4962 /* sunset-in-cupertino-200px.png in Copy Resources */,
                                9BD6D3A41F7B218300BD4962 /* sunset-in-cupertino-400px.gif in Copy Resources */,
                                9BD6D3A51F7B218300BD4962 /* sunset-in-cupertino-600px.jpg in Copy Resources */,
+                               313C3A0221E567C300DBA86E /* SystemPreviewBlobNaming.html in Copy Resources */,
                                CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */,
                                C95984F71E36BCEF002C0D45 /* test-without-audio-track.mp4 in Copy Resources */,
                                524BBCA119E30C77002F1AF1 /* test.mp4 in Copy Resources */,
                                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */,
                                CDB4115A1E0B00DB00EAD352 /* video-with-muted-audio.html in Copy Resources */,
                                CD758A6F20572EA00071834A /* video-with-paused-audio-and-playing-muted.html in Copy Resources */,
+                               C9C9A91D21DED7A000FDE96E /* video-with-play-button.html in Copy Resources */,
                                CDC8E4961BC6F10800594FEC /* video-without-audio.html in Copy Resources */,
                                CDC8E4971BC6F10800594FEC /* video-without-audio.mp4 in Copy Resources */,
                                2EBD9D0A2134730D002DA758 /* video.html in Copy Resources */,
                2EFF06D21D8AEDBB0004BB30 /* TestWKWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestWKWebView.h; path = cocoa/TestWKWebView.h; sourceTree = "<group>"; };
                2EFF06D31D8AEDBB0004BB30 /* TestWKWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestWKWebView.mm; path = cocoa/TestWKWebView.mm; sourceTree = "<group>"; };
                2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCandidateTests.mm; sourceTree = "<group>"; };
+               313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SystemPreviewBlobNaming.html; sourceTree = "<group>"; };
                3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; };
                315231C91EB3B3C700A22A16 /* GPULegacyCommandQueue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPULegacyCommandQueue.mm; sourceTree = "<group>"; };
                3162AE9B1E6F2FCE000E4DBC /* GPULegacyDevice.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPULegacyDevice.mm; sourceTree = "<group>"; };
                                9BD6D3A01F7B202000BD4962 /* sunset-in-cupertino-200px.png */,
                                9BD6D39F1F7B202000BD4962 /* sunset-in-cupertino-400px.gif */,
                                9BD6D39E1F7B201E00BD4962 /* sunset-in-cupertino-600px.jpg */,
+                               313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */,
                                2E9896141D8F092B00739892 /* text-and-password-inputs.html */,
                                F4CD74C520FDACF500DE3794 /* text-with-async-script.html */,
                                F44C7A0420FAAE320014478C /* text-with-deferred-script.html */,
                                C95984F61E36BCD7002C0D45 /* test-without-audio-track.mp4 */,
                                524BBCA019E30C63002F1AF1 /* test.mp4 */,
                                7AE9E5081AE5AE8B00CF874B /* test.pdf */,
-                               07CD32F72065B72A0064A4BE /* video.html */,
                                C9C9A91C21DED79400FDE96E /* video-with-play-button.html */,
+                               07CD32F72065B72A0064A4BE /* video.html */,
                                1C2B81841C8924A200A5529F /* webfont.html */,
                        );
                        name = Resources;
index 21b35ce..60cc93b 100644 (file)
@@ -621,5 +621,38 @@ TEST(_WKDownload, DownloadCanceledWhileDecidingDestination)
     [TestProtocol unregister];
 }
 
+@interface BlobWithUSDZExtensionDownloadDelegate : NSObject <_WKDownloadDelegate>
+@end
+
+@implementation BlobWithUSDZExtensionDownloadDelegate {
+    String _destinationPath;
+}
+
+- (void)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename completionHandler:(void (^)(BOOL allowOverwrite, NSString *destination))completionHandler
+{
+    EXPECT_TRUE([filename hasSuffix:@".usdz"]);
+
+    WebCore::FileSystem::PlatformFileHandle fileHandle;
+    _destinationPath = WebCore::FileSystem::openTemporaryFile(filename, fileHandle);
+    EXPECT_TRUE(fileHandle != WebCore::FileSystem::invalidPlatformFileHandle);
+    WebCore::FileSystem::closeFile(fileHandle);
+
+    completionHandler(YES, _destinationPath);
+}
+
+- (void)_downloadDidFinish:(_WKDownload *)download
+{
+    WebCore::FileSystem::deleteFile(_destinationPath);
+    isDone = true;
+}
+
+@end
+
+TEST(_WKDownload, SystemPreviewUSDZBlobNaming)
+{
+    NSURL *originalURL = [[NSBundle mainBundle] URLForResource:@"SystemPreviewBlobNaming" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    runTest(adoptNS([[DownloadBlobURLNavigationDelegate alloc] init]).get(), adoptNS([[BlobWithUSDZExtensionDownloadDelegate alloc] init]).get(), originalURL);
+}
+
 #endif
 #endif
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreviewBlobNaming.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/SystemPreviewBlobNaming.html
new file mode 100644 (file)
index 0000000..f0e470e
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<body>
+<a id="href" href="simple.html">download</a>
+<script>
+    var element = document.getElementById("href");
+    var data = "fake data";
+    var blob = new Blob([data], {type: "model/vnd.usdz+zip"});
+    var url = window.URL.createObjectURL(blob);
+
+    element.href = url;
+    element.click();
+</script>
+</body>
+</html>