[Cocoa] Media mime types map should be created in the UI process
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 25 Jan 2020 16:51:34 +0000 (16:51 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 25 Jan 2020 16:51:34 +0000 (16:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206478

Reviewed by Darin Adler.

Source/WebCore:

Creating this map in the WebContent process will access the launch services daemon, which will be blocked.
This patch creates the map in the UI process and sends it to the WebContent process as part of the WebProcess
creation parameters.

API test: WebKit.MimeTypes

* platform/MIMETypeRegistry.cpp:
(WebCore::overriddenMimeTypesMap):
(WebCore::commonMediaTypes):
(WebCore::commonMimeTypesMap):
(WebCore::typesForCommonExtension):
* platform/MIMETypeRegistry.h:
* testing/Internals.cpp:
(WebCore::Internals::mediaMIMETypeForExtension):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Send the mime type map from the UI process to the WebContent process as part of the
WebProcess 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/MimeTypes.mm: Added.
(TEST):

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

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebProcessCreationParameters.cpp
Source/WebKit/Shared/WebProcessCreationParameters.h
Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit/MimeTypes.mm [new file with mode: 0644]

index 1e99a2b..5ec4edd 100644 (file)
@@ -1,3 +1,27 @@
+2020-01-25  Per Arne Vollan  <pvollan@apple.com>
+
+        [Cocoa] Media mime types map should be created in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=206478
+
+        Reviewed by Darin Adler.
+
+        Creating this map in the WebContent process will access the launch services daemon, which will be blocked.
+        This patch creates the map in the UI process and sends it to the WebContent process as part of the WebProcess
+        creation parameters.
+
+        API test: WebKit.MimeTypes
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::overriddenMimeTypesMap):
+        (WebCore::commonMediaTypes):
+        (WebCore::commonMimeTypesMap):
+        (WebCore::typesForCommonExtension):
+        * platform/MIMETypeRegistry.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::mediaMIMETypeForExtension):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2020-01-25  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Layout logic should be driven by the type of the inline box
index 3fa4c26..636123e 100644 (file)
@@ -274,98 +274,104 @@ const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::unsupportedTe
     return unsupportedTextMIMETypes;
 }
 
-static const Vector<String>* typesForCommonExtension(const String& extension)
-{
-    static const auto map = makeNeverDestroyed([] {
-        struct TypeExtensionPair {
-            ASCIILiteral type;
-            ASCIILiteral extension;
-        };
-
-        // A table of common media MIME types and file extentions used when a platform's
-        // specific MIME type lookup doesn't have a match for a media file extension.
-        static const TypeExtensionPair commonMediaTypes[] = {
-            // Ogg
-            { "application/ogg"_s, "ogx"_s },
-            { "audio/ogg"_s, "ogg"_s },
-            { "audio/ogg"_s, "oga"_s },
-            { "video/ogg"_s, "ogv"_s },
-
-            // Annodex
-            { "application/annodex"_s, "anx"_s },
-            { "audio/annodex"_s, "axa"_s },
-            { "video/annodex"_s, "axv"_s },
-            { "audio/speex"_s, "spx"_s },
-
-            // WebM
-            { "video/webm"_s, "webm"_s },
-            { "audio/webm"_s, "webm"_s },
-
-            // MPEG
-            { "audio/mpeg"_s, "m1a"_s },
-            { "audio/mpeg"_s, "m2a"_s },
-            { "audio/mpeg"_s, "m1s"_s },
-            { "audio/mpeg"_s, "mpa"_s },
-            { "video/mpeg"_s, "mpg"_s },
-            { "video/mpeg"_s, "m15"_s },
-            { "video/mpeg"_s, "m1s"_s },
-            { "video/mpeg"_s, "m1v"_s },
-            { "video/mpeg"_s, "m75"_s },
-            { "video/mpeg"_s, "mpa"_s },
-            { "video/mpeg"_s, "mpeg"_s },
-            { "video/mpeg"_s, "mpm"_s },
-            { "video/mpeg"_s, "mpv"_s },
-
-            // MPEG playlist
-            { "application/vnd.apple.mpegurl"_s, "m3u8"_s },
-            { "application/mpegurl"_s, "m3u8"_s },
-            { "application/x-mpegurl"_s, "m3u8"_s },
-            { "audio/mpegurl"_s, "m3url"_s },
-            { "audio/x-mpegurl"_s, "m3url"_s },
-            { "audio/mpegurl"_s, "m3u"_s },
-            { "audio/x-mpegurl"_s, "m3u"_s },
-
-            // MPEG-4
-            { "video/x-m4v"_s, "m4v"_s },
-            { "audio/x-m4a"_s, "m4a"_s },
-            { "audio/x-m4b"_s, "m4b"_s },
-            { "audio/x-m4p"_s, "m4p"_s },
-            { "audio/mp4"_s, "m4a"_s },
-
-            // MP3
-            { "audio/mp3"_s, "mp3"_s },
-            { "audio/x-mp3"_s, "mp3"_s },
-            { "audio/x-mpeg"_s, "mp3"_s },
-
-            // MPEG-2
-            { "video/x-mpeg2"_s, "mp2"_s },
-            { "video/mpeg2"_s, "vob"_s },
-            { "video/mpeg2"_s, "mod"_s },
-            { "video/m2ts"_s, "m2ts"_s },
-            { "video/x-m2ts"_s, "m2t"_s },
-            { "video/x-m2ts"_s, "ts"_s },
-
-            // 3GP/3GP2
-            { "audio/3gpp"_s, "3gpp"_s },
-            { "audio/3gpp2"_s, "3g2"_s },
-            { "application/x-mpeg"_s, "amc"_s },
-
-            // AAC
-            { "audio/aac"_s, "aac"_s },
-            { "audio/aac"_s, "adts"_s },
-            { "audio/x-aac"_s, "m4r"_s },
-
-            // CoreAudio File
-            { "audio/x-caf"_s, "caf"_s },
-            { "audio/x-gsm"_s, "gsm"_s },
-
-            // ADPCM
-            { "audio/x-wav"_s, "wav"_s },
-            { "audio/vnd.wave"_s, "wav"_s },
-        };
+Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>>& overriddenMimeTypesMap()
+{
+    static NeverDestroyed<Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>>> map;
+    return map;
+}
+
+const std::initializer_list<TypeExtensionPair>& commonMediaTypes()
+{
+    // A table of common media MIME types and file extensions used when a platform's
+    // specific MIME type lookup doesn't have a match for a media file extension.
+    static std::initializer_list<TypeExtensionPair> commonMediaTypes = {
+        // Ogg
+        { "application/ogg"_s, "ogx"_s },
+        { "audio/ogg"_s, "ogg"_s },
+        { "audio/ogg"_s, "oga"_s },
+        { "video/ogg"_s, "ogv"_s },
+
+        // Annodex
+        { "application/annodex"_s, "anx"_s },
+        { "audio/annodex"_s, "axa"_s },
+        { "video/annodex"_s, "axv"_s },
+        { "audio/speex"_s, "spx"_s },
+
+        // WebM
+        { "video/webm"_s, "webm"_s },
+        { "audio/webm"_s, "webm"_s },
+
+        // MPEG
+        { "audio/mpeg"_s, "m1a"_s },
+        { "audio/mpeg"_s, "m2a"_s },
+        { "audio/mpeg"_s, "m1s"_s },
+        { "audio/mpeg"_s, "mpa"_s },
+        { "video/mpeg"_s, "mpg"_s },
+        { "video/mpeg"_s, "m15"_s },
+        { "video/mpeg"_s, "m1s"_s },
+        { "video/mpeg"_s, "m1v"_s },
+        { "video/mpeg"_s, "m75"_s },
+        { "video/mpeg"_s, "mpa"_s },
+        { "video/mpeg"_s, "mpeg"_s },
+        { "video/mpeg"_s, "mpm"_s },
+        { "video/mpeg"_s, "mpv"_s },
+
+        // MPEG playlist
+        { "application/vnd.apple.mpegurl"_s, "m3u8"_s },
+        { "application/mpegurl"_s, "m3u8"_s },
+        { "application/x-mpegurl"_s, "m3u8"_s },
+        { "audio/mpegurl"_s, "m3url"_s },
+        { "audio/x-mpegurl"_s, "m3url"_s },
+        { "audio/mpegurl"_s, "m3u"_s },
+        { "audio/x-mpegurl"_s, "m3u"_s },
+
+        // MPEG-4
+        { "video/x-m4v"_s, "m4v"_s },
+        { "audio/x-m4a"_s, "m4a"_s },
+        { "audio/x-m4b"_s, "m4b"_s },
+        { "audio/x-m4p"_s, "m4p"_s },
+        { "audio/mp4"_s, "m4a"_s },
+
+        // MP3
+        { "audio/mp3"_s, "mp3"_s },
+        { "audio/x-mp3"_s, "mp3"_s },
+        { "audio/x-mpeg"_s, "mp3"_s },
+
+        // MPEG-2
+        { "video/x-mpeg2"_s, "mp2"_s },
+        { "video/mpeg2"_s, "vob"_s },
+        { "video/mpeg2"_s, "mod"_s },
+        { "video/m2ts"_s, "m2ts"_s },
+        { "video/x-m2ts"_s, "m2t"_s },
+        { "video/x-m2ts"_s, "ts"_s },
+
+        // 3GP/3GP2
+        { "audio/3gpp"_s, "3gpp"_s },
+        { "audio/3gpp2"_s, "3g2"_s },
+        { "application/x-mpeg"_s, "amc"_s },
+
+        // AAC
+        { "audio/aac"_s, "aac"_s },
+        { "audio/aac"_s, "adts"_s },
+        { "audio/x-aac"_s, "m4r"_s },
+
+        // CoreAudio File
+        { "audio/x-caf"_s, "caf"_s },
+        { "audio/x-gsm"_s, "gsm"_s },
+
+        // ADPCM
+        { "audio/x-wav"_s, "wav"_s },
+        { "audio/vnd.wave"_s, "wav"_s },
+    };
+    return commonMediaTypes;
+}
 
+const HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>& commonMimeTypesMap()
+{
+    ASSERT(isMainThread());
+    static NeverDestroyed<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>> mimeTypesMap = [] {
         HashMap<String, Vector<String>, ASCIICaseInsensitiveHash> map;
-        for (auto& pair : commonMediaTypes) {
+        for (auto& pair : commonMediaTypes()) {
             ASCIILiteral type = pair.type;
             ASCIILiteral extension = pair.extension;
             map.ensure(extension, [type, extension] {
@@ -379,9 +385,20 @@ static const Vector<String>* typesForCommonExtension(const String& extension)
             }).iterator->value.append(type);
         }
         return map;
-    }());
-    auto mapEntry = map.get().find(extension);
-    if (mapEntry == map.get().end())
+    }();
+    return mimeTypesMap;
+}
+
+static const Vector<String>* typesForCommonExtension(const String& extension)
+{
+    if (overriddenMimeTypesMap().hasValue()) {
+        auto mapEntry = overriddenMimeTypesMap()->find(extension);
+        if (mapEntry == overriddenMimeTypesMap()->end())
+            return nullptr;
+        return &mapEntry->value;
+    }
+    auto mapEntry = commonMimeTypesMap().find(extension);
+    if (mapEntry == commonMimeTypesMap().end())
         return nullptr;
     return &mapEntry->value;
 }
index 1ae2b49..c9c40ba 100644 (file)
 
 namespace WebCore {
 
+WEBCORE_EXPORT Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>>& overriddenMimeTypesMap();
+WEBCORE_EXPORT const HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>& commonMimeTypesMap();
+
+struct TypeExtensionPair {
+    ASCIILiteral type;
+    ASCIILiteral extension;
+};
+
+WEBCORE_EXPORT const std::initializer_list<TypeExtensionPair>& commonMediaTypes();
+
 struct MIMETypeRegistryThreadGlobalData {
     WTF_MAKE_NONCOPYABLE(MIMETypeRegistryThreadGlobalData);
     WTF_MAKE_FAST_ALLOCATED;
@@ -52,7 +62,7 @@ public:
     // FIXME: WebKit coding style says we should not have the word "get" in the names of these functions.
     static Vector<String> getExtensionsForMIMEType(const String& type);
     WEBCORE_EXPORT static String getPreferredExtensionForMIMEType(const String& type);
-    static String getMediaMIMETypeForExtension(const String& extension);
+    WEBCORE_EXPORT static String getMediaMIMETypeForExtension(const String& extension);
     static Vector<String> getMediaMIMETypesForExtension(const String& extension);
 
     static String getMIMETypeForPath(const String& path);
index e8ea6d3..f481d81 100644 (file)
 #include "LibWebRTCProvider.h"
 #include "LoaderStrategy.h"
 #include "Location.h"
+#include "MIMETypeRegistry.h"
 #include "MallocStatistics.h"
 #include "MediaDevices.h"
 #include "MediaEngineConfigurationFactory.h"
@@ -5440,4 +5441,9 @@ bool Internals::systemHasBattery() const
 #endif
 }
 
+String Internals::mediaMIMETypeForExtension(const String& extension)
+{
+    return MIMETypeRegistry::getMediaMIMETypeForExtension(extension);
+}
+
 } // namespace WebCore
index 752de7a..4edba26 100644 (file)
@@ -930,6 +930,8 @@ public:
 
     bool systemHasBattery() const;
 
+    String mediaMIMETypeForExtension(const String& extension);
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;
index f5b3a3a..b52c880 100644 (file)
@@ -837,4 +837,6 @@ enum CompositingPolicy {
     DOMString systemColorForCSSValue(DOMString cssValue, boolean useDarkModeAppearance, boolean useElevatedUserInterfaceLevel);
 
     boolean systemHasBattery();
+
+    DOMString mediaMIMETypeForExtension(DOMString extension);
 };
index 98f5ecf..8289f01 100644 (file)
@@ -1,3 +1,22 @@
+2020-01-25  Per Arne Vollan  <pvollan@apple.com>
+
+        [Cocoa] Media mime types map should be created in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=206478
+
+        Reviewed by Darin Adler.
+
+        Send the mime type map from the UI process to the WebContent process as part of the
+        WebProcess 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-01-25  Antti Koivisto  <antti@apple.com>
 
         [LFC][Integration] Re-enable line layout integration
index bb9ae45..d04a47f 100644 (file)
@@ -167,6 +167,7 @@ void WebProcessCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << neHelperExtensionHandle;
     encoder << neSessionManagerExtensionHandle;
     encoder << systemHasBattery;
+    encoder << mimeTypesMap;
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -440,6 +441,12 @@ bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreat
     if (!systemHasBattery)
         return false;
     parameters.systemHasBattery = WTFMove(*systemHasBattery);
+
+    Optional<Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>>> mimeTypesMap;
+    decoder >> mimeTypesMap;
+    if (!mimeTypesMap)
+        return false;
+    parameters.mimeTypesMap = WTFMove(*mimeTypesMap);
 #endif
 
 #if PLATFORM(IOS_FAMILY)
index d7aefee..a8cc197 100644 (file)
@@ -209,6 +209,7 @@ struct WebProcessCreationParameters {
     Optional<SandboxExtension::Handle> neHelperExtensionHandle;
     Optional<SandboxExtension::Handle> neSessionManagerExtensionHandle;
     bool systemHasBattery { false };
+    Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>> mimeTypesMap;
 #endif
 
 #if PLATFORM(IOS_FAMILY)
index 5b6e066..60852bc 100644 (file)
@@ -47,6 +47,7 @@
 #import "WebProcessMessages.h"
 #import "WindowServerConnection.h"
 #import <WebCore/Color.h>
+#import <WebCore/MIMETypeRegistry.h>
 #import <WebCore/NetworkStorageSession.h>
 #import <WebCore/NotImplemented.h>
 #import <WebCore/PlatformPasteboard.h>
@@ -353,6 +354,7 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
         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)
index 0c5ffa2..9d49fa2 100644 (file)
@@ -59,6 +59,7 @@
 #import <WebCore/HistoryItem.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/LogInitialization.h>
+#import <WebCore/MIMETypeRegistry.h>
 #import <WebCore/MemoryRelease.h>
 #import <WebCore/NSScrollerImpDetails.h>
 #import <WebCore/PerformanceLogging.h>
@@ -260,6 +261,9 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& para
         SandboxExtension::consumePermanently(*parameters.neSessionManagerExtensionHandle);
     NetworkExtensionContentFilter::setHasConsumedSandboxExtensions(parameters.neHelperExtensionHandle.hasValue() && parameters.neSessionManagerExtensionHandle.hasValue());
     setSystemHasBattery(parameters.systemHasBattery);
+
+    if (parameters.mimeTypesMap)
+        overriddenMimeTypesMap() = WTFMove(parameters.mimeTypesMap);
 #endif
 
 #if PLATFORM(IOS_FAMILY)
index 23a119d..abcceaf 100644 (file)
@@ -1,3 +1,14 @@
+2020-01-25  Per Arne Vollan  <pvollan@apple.com>
+
+        [Cocoa] Media mime types map should be created in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=206478
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/MimeTypes.mm: Added.
+        (TEST):
+
 2020-01-25  Antti Koivisto  <antti@apple.com>
 
         [LFC][Integration] Re-enable line layout integration
index 5badd91..a55cc33 100644 (file)
                C0ADBE9612FCA79B00D2C129 /* simple-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C0ADBE8412FCA6B600D2C129 /* simple-form.html */; };
                C0BD669F131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */; };
                C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */; };
+               C145CC0C23DA5A1F003A5EEB /* MimeTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */; };
                C1692DCA23D10DAE006E88F7 /* Battery.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1692DC923D10DAE006E88F7 /* Battery.mm */; };
                C20F88A72295B96700D610FA /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20F88A62295B96700D610FA /* CoreText.framework */; };
                C22FA32B228F8708009D7988 /* TextWidth.mm in Sources */ = {isa = PBXBuildFile; fileRef = C22FA32A228F8708009D7988 /* TextWidth.mm */; };
                C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResponsivenessTimerDoesntFireEarly_Bundle.cpp; sourceTree = "<group>"; };
                C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor.mm; sourceTree = "<group>"; };
                C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor_Bundle.mm; sourceTree = "<group>"; };
+               C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MimeTypes.mm; sourceTree = "<group>"; };
                C1692DC923D10DAE006E88F7 /* Battery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Battery.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; };
                        isa = PBXGroup;
                        children = (
                                C1692DC923D10DAE006E88F7 /* Battery.mm */,
+                               C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */,
                                0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
                        );
                        name = cocoa;
                                5C0BF8941DD599C900B00328 /* MenuTypesForMouseEvents.mm in Sources */,
                                5165FE04201EE620009F7EC3 /* MessagePortProviders.mm in Sources */,
                                A5B149DE1F5A19EA00C6DAFF /* MIMETypeRegistry.cpp in Sources */,
+                               C145CC0C23DA5A1F003A5EEB /* MimeTypes.mm in Sources */,
                                51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */,
                                7C83E0B61D0A64B300FEBCF3 /* ModalAlertsSPI.cpp in Sources */,
                                7CCE7F011A411AE600447C4C /* MouseMoveAfterCrash.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit/MimeTypes.mm b/Tools/TestWebKitAPI/Tests/WebKit/MimeTypes.mm
new file mode 100644 (file)
index 0000000..a10f85a
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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/MIMETypeRegistry.h>
+
+TEST(WebKit, MimeTypes)
+{
+    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& pair : WebCore::commonMediaTypes()) {
+        ASCIILiteral extension = pair.extension;
+
+        auto js = [NSString stringWithFormat:@"window.internals.mediaMIMETypeForExtension(\"%s\")", extension.characters()];
+
+        auto mimeType = [webView stringByEvaluatingJavaScript:js];
+
+        ASSERT_TRUE(WebCore::MIMETypeRegistry::getMediaMIMETypeForExtension(extension) == String(mimeType));
+    }
+}
+
+#endif // WK_HAVE_C_SPI