Title: [257687] trunk
Revision
257687
Author
pvol...@apple.com
Date
2020-02-29 19:32:16 -0800 (Sat, 29 Feb 2020)

Log Message

[Cocoa] Mapping from MIME type to UTI type should be done in the UI process
https://bugs.webkit.org/show_bug.cgi?id=208415

Reviewed by Brent Fulgham.

Source/WebCore:

This is currently done in the WebContent process, but since this is using a system service which will be closed,
this mapping should be moved to the UI process. The UI process will create this mapping for a set of mime types,
and send it to the WebContent process.

API test: WebKit.UTIFromMIMEType

* platform/network/mac/UTIUtilities.h:
* platform/network/mac/UTIUtilities.mm:
(WebCore::mapUTIFromMIMEType):
(WebCore::UTIFromMIMETypeCachePolicy::createValueForKey):
(WebCore::cacheUTIFromMimeType):
(WebCore::UTIFromMIMEType):
(WebCore::mimeTypes):
(WebCore::createUTIFromMIMETypeMap):
(WebCore::setUTIFromMIMETypeMap):
* testing/Internals.cpp:
(WebCore::Internals::getUTIFromMIMEType):
* testing/Internals.mm:
(WebCore::Internals::getUTIFromMIMEType):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Send the mapping between MIME types and UTI types to the WebContent process as part of the Web
process creation parameters.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/UTIFromMIMEType.mm: Added.
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (257686 => 257687)


--- trunk/Source/WebCore/ChangeLog	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebCore/ChangeLog	2020-03-01 03:32:16 UTC (rev 257687)
@@ -1,3 +1,32 @@
+2020-02-29  Per Arne Vollan  <pvol...@apple.com>
+
+        [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208415
+
+        Reviewed by Brent Fulgham.
+
+        This is currently done in the WebContent process, but since this is using a system service which will be closed,
+        this mapping should be moved to the UI process. The UI process will create this mapping for a set of mime types,
+        and send it to the WebContent process.
+
+        API test: WebKit.UTIFromMIMEType
+
+        * platform/network/mac/UTIUtilities.h:
+        * platform/network/mac/UTIUtilities.mm:
+        (WebCore::mapUTIFromMIMEType):
+        (WebCore::UTIFromMIMETypeCachePolicy::createValueForKey):
+        (WebCore::cacheUTIFromMimeType):
+        (WebCore::UTIFromMIMEType):
+        (WebCore::mimeTypes):
+        (WebCore::createUTIFromMIMETypeMap):
+        (WebCore::setUTIFromMIMETypeMap):
+        * testing/Internals.cpp:
+        (WebCore::Internals::getUTIFromMIMEType):
+        * testing/Internals.mm:
+        (WebCore::Internals::getUTIFromMIMEType):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2020-02-29  Zalan Bujtas  <za...@apple.com>
 
         [LFC][BFC] Consolidate precomputeVerticalPositionForAncestors and precomputeVerticalPosition

Modified: trunk/Source/WebCore/platform/network/mac/UTIUtilities.h (257686 => 257687)


--- trunk/Source/WebCore/platform/network/mac/UTIUtilities.h	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebCore/platform/network/mac/UTIUtilities.h	2020-03-01 03:32:16 UTC (rev 257687)
@@ -23,17 +23,18 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef UTIUtilities_h
-#define UTIUtilities_h
+#pragma once
 
-#import <wtf/Forward.h>
-#import <wtf/RetainPtr.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
+
 WEBCORE_EXPORT String MIMETypeFromUTI(const String&);
 String MIMETypeFromUTITree(const String&);
 WEBCORE_EXPORT String UTIFromMIMEType(const String&);
 bool isDeclaredUTI(const String&);
+
+WEBCORE_EXPORT void setUTIFromMIMETypeMap(HashMap<String, String>&&);
+WEBCORE_EXPORT const HashMap<String, String>& createUTIFromMIMETypeMap();
+WEBCORE_EXPORT const Vector<String>& mimeTypes();
 }
-
-#endif // UTIUtilities_h

Modified: trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm (257686 => 257687)


--- trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm	2020-03-01 03:32:16 UTC (rev 257687)
@@ -40,6 +40,8 @@
 #define ADDITIONAL_UTI_MAPPINGS
 #endif
 
+#define EMPTY_MIME_TYPE_STRING "emptyMimeType"_s
+
 namespace WebCore {
 
 String MIMETypeFromUTI(const String& uti)
@@ -113,10 +115,26 @@
     return mapEntry->value;
 }
 
+static Optional<HashMap<String, String>>& mapUTIFromMIMEType()
+{
+    static NeverDestroyed<Optional<HashMap<String, String>>> map;
+    return map;
+}
+
 struct UTIFromMIMETypeCachePolicy : TinyLRUCachePolicy<String, String> {
 public:
-    static String createValueForKey(const String& key)
+    static String createValueForKey(const String& mimeType)
     {
+        String key = mimeType;
+        if (mapUTIFromMIMEType().hasValue()) {
+            if (key.isEmpty())
+                key = EMPTY_MIME_TYPE_STRING;
+            const auto& it = mapUTIFromMIMEType()->find(key);
+            if (it != mapUTIFromMIMEType()->end())
+                return it->value;
+            WTFLogAlways("UTI for MIME type %s not found.", key.utf8().data());
+            ASSERT_NOT_REACHED();
+        }
         auto type = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, key.createCFString().get(), 0));
         if (type)
             return type.get();
@@ -124,11 +142,16 @@
     }
 };
 
+static TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>& cacheUTIFromMimeType()
+{
+    static NeverDestroyed<TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>> cache;
+    return cache;
+}
+
 String UTIFromMIMEType(const String& mimeType)
 {
     ASSERT(isMainThread());
-    static NeverDestroyed<TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>> cache;
-    return cache.get().get(mimeType);
+    return cacheUTIFromMimeType().get(mimeType);
 }
 
 bool isDeclaredUTI(const String& UTI)
@@ -136,4 +159,66 @@
     return UTTypeIsDeclared(UTI.createCFString().get());
 }
 
+const Vector<String>& mimeTypes()
+{
+    static NeverDestroyed<Vector<String>> mimeTypes = std::initializer_list<String> {
+        "application/ogg"_s,
+        "audio/ogg"_s,
+        "video/ogg"_s,
+        "application/annodex"_s,
+        "audio/annodex"_s,
+        "video/annodex"_s,
+        "audio/speex"_s,
+        "video/webm"_s,
+        "audio/webm"_s,
+        "audio/mpeg"_s,
+        "video/mpeg"_s,
+        "application/vnd.apple.mpegurl"_s,
+        "application/mpegurl"_s,
+        "application/x-mpegurl"_s,
+        "audio/mpegurl"_s,
+        "audio/x-mpegurl"_s,
+        "audio/mpegurl"_s,
+        "video/x-m4v"_s,
+        "audio/x-m4a"_s,
+        "audio/x-m4b"_s,
+        "audio/x-m4p"_s,
+        "audio/mp4"_s,
+        "audio/mp3"_s,
+        "audio/x-mp3"_s,
+        "audio/x-mpeg"_s,
+        "video/x-mpeg2"_s,
+        "video/mpeg2"_s,
+        "video/m2ts"_s,
+        "video/x-m2ts"_s,
+        "audio/3gpp"_s,
+        "audio/3gpp2"_s,
+        "application/x-mpeg"_s,
+        "audio/aac"_s,
+        "audio/x-aac"_s,
+        "audio/x-caf"_s,
+        "audio/x-gsm"_s,
+        "audio/x-wav"_s,
+        "audio/vnd.wave"_s,
+    };
+    return mimeTypes;
+};
+
+const HashMap<String, String>& createUTIFromMIMETypeMap()
+{
+    static NeverDestroyed<HashMap<String, String>> map = [] {
+        HashMap<String, String> cache;
+        for (auto mimeType : mimeTypes())
+            cache.add(mimeType, UTIFromMIMEType(mimeType));
+        cache.add(EMPTY_MIME_TYPE_STRING, UTIFromMIMEType(emptyString()));
+        return cache;
+    }();
+    return map;
 }
+
+void setUTIFromMIMETypeMap(HashMap<String, String>&& map)
+{
+    mapUTIFromMIMEType() = WTFMove(map);
+}
+
+}

Modified: trunk/Source/WebCore/testing/Internals.cpp (257686 => 257687)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-03-01 03:32:16 UTC (rev 257687)
@@ -5474,6 +5474,11 @@
 {
     return emptyString();
 }
+
+String Internals::getUTIFromMIMEType(const String& mimeType)
+{
+    return emptyString();
+}
 #endif
 
 String Internals::mediaMIMETypeForExtension(const String& extension)

Modified: trunk/Source/WebCore/testing/Internals.h (257686 => 257687)


--- trunk/Source/WebCore/testing/Internals.h	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebCore/testing/Internals.h	2020-03-01 03:32:16 UTC (rev 257687)
@@ -938,6 +938,8 @@
 
     String mediaMIMETypeForExtension(const String& extension);
 
+    String getUTIFromMIMEType(const String& mimeType);
+
     bool supportsPictureInPicture();
 
     String focusRingColor();

Modified: trunk/Source/WebCore/testing/Internals.idl (257686 => 257687)


--- trunk/Source/WebCore/testing/Internals.idl	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-03-01 03:32:16 UTC (rev 257687)
@@ -846,6 +846,8 @@
     DOMString encodedPreferenceValue(DOMString domain, DOMString key);
 
     DOMString mediaMIMETypeForExtension(DOMString extension);
-    
+
+    DOMString getUTIFromMIMEType(DOMString mimeType);
+
     boolean supportsPictureInPicture();
 };

Modified: trunk/Source/WebCore/testing/Internals.mm (257686 => 257687)


--- trunk/Source/WebCore/testing/Internals.mm	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebCore/testing/Internals.mm	2020-03-01 03:32:16 UTC (rev 257687)
@@ -34,6 +34,7 @@
 #import "HitTestResult.h"
 #import "MediaPlayerPrivate.h"
 #import "Range.h"
+#import "UTIUtilities.h"
 #import <AVFoundation/AVPlayer.h>
 #import <wtf/cocoa/NSURLExtras.h>
 
@@ -100,4 +101,9 @@
     return encodedString;
 }
 
+String Internals::getUTIFromMIMEType(const String& mimeType)
+{
+    return UTIFromMIMEType(mimeType);
 }
+
+}

Modified: trunk/Source/WebKit/ChangeLog (257686 => 257687)


--- trunk/Source/WebKit/ChangeLog	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebKit/ChangeLog	2020-03-01 03:32:16 UTC (rev 257687)
@@ -1,3 +1,22 @@
+2020-02-29  Per Arne Vollan  <pvol...@apple.com>
+
+        [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208415
+
+        Reviewed by Brent Fulgham.
+
+        Send the mapping between MIME types and UTI types to the WebContent process as part of the Web
+        process creation parameters.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2020-02-29  Jer Noble  <jer.no...@apple.com>
 
         Unreviewed unified build fix; add include macro for LayerHostingContext.

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (257686 => 257687)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-03-01 03:32:16 UTC (rev 257687)
@@ -171,6 +171,7 @@
     encoder << neSessionManagerExtensionHandle;
     encoder << systemHasBattery;
     encoder << mimeTypesMap;
+    encoder << mapUTIFromMIMEType;
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -460,6 +461,12 @@
     if (!mimeTypesMap)
         return false;
     parameters.mimeTypesMap = WTFMove(*mimeTypesMap);
+
+    Optional<HashMap<String, String>> mapUTIFromMIMEType;
+    decoder >> mapUTIFromMIMEType;
+    if (!mapUTIFromMIMEType)
+        return false;
+    parameters.mapUTIFromMIMEType = WTFMove(*mapUTIFromMIMEType);
 #endif
 
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (257686 => 257687)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-03-01 03:32:16 UTC (rev 257687)
@@ -213,6 +213,7 @@
     Optional<SandboxExtension::Handle> neSessionManagerExtensionHandle;
     bool systemHasBattery { false };
     Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>> mimeTypesMap;
+    HashMap<String, String> mapUTIFromMIMEType;
 #endif
 
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (257686 => 257687)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-03-01 03:32:16 UTC (rev 257687)
@@ -56,6 +56,7 @@
 #import <WebCore/PlatformPasteboard.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SharedBuffer.h>
+#import <WebCore/UTIUtilities.h>
 #import <objc/runtime.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <sys/param.h>
@@ -406,6 +407,8 @@
         parameters.neSessionManagerExtensionHandle = WTFMove(managerHandle);
     }
     parameters.systemHasBattery = systemHasBattery();
+    parameters.mimeTypesMap = commonMimeTypesMap();
+    parameters.mapUTIFromMIMEType = createUTIFromMIMETypeMap();
 #endif
     
 #if PLATFORM(IOS)
@@ -414,7 +417,6 @@
         SandboxExtension::createHandleForMachLookup("com.apple.uikit.viewservice.com.apple.WebContentFilter.remoteUI", WTF::nullopt, handle);
         parameters.contentFilterExtensionHandle = WTFMove(handle);
     }
-    parameters.mimeTypesMap = commonMimeTypesMap();
 #endif
     
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (257686 => 257687)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-03-01 03:32:16 UTC (rev 257687)
@@ -67,6 +67,7 @@
 #import <WebCore/PictureInPictureSupport.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SWContextManager.h>
+#import <WebCore/UTIUtilities.h>
 #import <algorithm>
 #import <dispatch/dispatch.h>
 #import <objc/runtime.h>
@@ -274,6 +275,8 @@
 
     if (parameters.mimeTypesMap)
         overriddenMimeTypesMap() = WTFMove(parameters.mimeTypesMap);
+
+    setUTIFromMIMETypeMap(WTFMove(parameters.mapUTIFromMIMEType));
 #endif
 
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/ChangeLog (257686 => 257687)


--- trunk/Tools/ChangeLog	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Tools/ChangeLog	2020-03-01 03:32:16 UTC (rev 257687)
@@ -1,3 +1,14 @@
+2020-02-29  Per Arne Vollan  <pvol...@apple.com>
+
+        [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208415
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/UTIFromMIMEType.mm: Added.
+        (TEST):
+
 2020-02-28  Fujii Hironori  <hironori.fu...@sony.com>
 
         Unreviewed, rolling out r257565.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (257686 => 257687)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-03-01 01:36:29 UTC (rev 257686)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-03-01 03:32:16 UTC (rev 257687)
@@ -883,6 +883,7 @@
 		C15CBB3023F1FF1A00300CC7 /* BacklightLevelNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB2F23F1FF1A00300CC7 /* BacklightLevelNotification.mm */; };
 		C15CBB3F23FB177A00300CC7 /* PreferenceChanges.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */; };
 		C1692DCA23D10DAE006E88F7 /* Battery.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1692DC923D10DAE006E88F7 /* Battery.mm */; };
+		C194E31D2409DF43002939ED /* UTIFromMIMEType.mm in Sources */ = {isa = PBXBuildFile; fileRef = C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */; };
 		C20F88A72295B96700D610FA /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20F88A62295B96700D610FA /* CoreText.framework */; };
 		C22FA32B228F8708009D7988 /* TextWidth.mm in Sources */ = {isa = PBXBuildFile; fileRef = C22FA32A228F8708009D7988 /* TextWidth.mm */; };
 		C22FA32D228F8AEB009D7988 /* TextWidth.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C22FA32C228F877A009D7988 /* TextWidth.html */; };
@@ -2448,6 +2449,7 @@
 		C15CBB2F23F1FF1A00300CC7 /* BacklightLevelNotification.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BacklightLevelNotification.mm; sourceTree = "<group>"; };
 		C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferenceChanges.mm; sourceTree = "<group>"; };
 		C1692DC923D10DAE006E88F7 /* Battery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Battery.mm; sourceTree = "<group>"; };
+		C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UTIFromMIMEType.mm; sourceTree = "<group>"; };
 		C1D8EE212028E8E3008EB141 /* WebProcessTerminate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessTerminate.mm; sourceTree = "<group>"; };
 		C20F88A62295B96700D610FA /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; };
 		C22FA32A228F8708009D7988 /* TextWidth.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TextWidth.mm; sourceTree = "<group>"; };
@@ -2900,6 +2902,7 @@
 				C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */,
 				E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */,
 				C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */,
+				C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */,
 				0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
 			);
 			name = cocoa;
@@ -5096,6 +5099,7 @@
 				07F4E92E20AF59E2002E3803 /* UserMediaSimulateFailedSandbox.mm in Sources */,
 				7CCE7F181A411AE600447C4C /* UserMessage.cpp in Sources */,
 				2EB242B821D4140B0055C1C0 /* UseSelectionAsFindString.mm in Sources */,
+				C194E31D2409DF43002939ED /* UTIFromMIMEType.mm in Sources */,
 				7C83E03A1D0A602700FEBCF3 /* UtilitiesCocoa.mm in Sources */,
 				7C83E0C61D0A654E00FEBCF3 /* VideoControlsManager.mm in Sources */,
 				CD3065E02165682E00E895DF /* VideoQualityDisplayCompositing.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/UTIFromMIMEType.mm (0 => 257687)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/UTIFromMIMEType.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/UTIFromMIMEType.mm	2020-03-01 03:32:16 UTC (rev 257687)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebCore/UTIUtilities.h>
+
+TEST(WebKit, UTIFromMIMEType)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+    configuration.get().processPool = (WKProcessPool *)context.get();
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
+
+    for (auto& mimeType : WebCore::mimeTypes()) {
+        auto js = [NSString stringWithFormat:@"window.internals.getUTIFromMIMEType(\"%s\")", mimeType.utf8().data()];
+
+        auto uti = [webView stringByEvaluatingJavaScript:js];
+
+        ASSERT_TRUE(WebCore::UTIFromMIMEType(mimeType) == String(uti));
+    }
+}
+
+#endif // WK_HAVE_C_SPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to