Title: [255119] trunk
Revision
255119
Author
[email protected]
Date
2020-01-25 08:51:34 -0800 (Sat, 25 Jan 2020)

Log Message

[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.

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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (255118 => 255119)


--- trunk/Source/WebCore/ChangeLog	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebCore/ChangeLog	2020-01-25 16:51:34 UTC (rev 255119)
@@ -1,3 +1,27 @@
+2020-01-25  Per Arne Vollan  <[email protected]>
+
+        [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  <[email protected]>
 
         [LFC][IFC] Layout logic should be driven by the type of the inline box

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (255118 => 255119)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2020-01-25 16:51:34 UTC (rev 255119)
@@ -274,98 +274,104 @@
     return unsupportedTextMIMETypes;
 }
 
-static const Vector<String>* typesForCommonExtension(const String& extension)
+Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>>& overriddenMimeTypesMap()
 {
-    static const auto map = makeNeverDestroyed([] {
-        struct TypeExtensionPair {
-            ASCIILiteral type;
-            ASCIILiteral extension;
-        };
+    static NeverDestroyed<Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>>> map;
+    return map;
+}
 
-        // 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 },
+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 },
+        // 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 },
+        // 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
+        { "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 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 },
+        // 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 },
+        // 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 },
+        // 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 },
+        // 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 },
+        // 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 },
+        // 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 },
-        };
+        // 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 @@
             }).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;
 }

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.h (255118 => 255119)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.h	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.h	2020-01-25 16:51:34 UTC (rev 255119)
@@ -31,6 +31,16 @@
 
 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 @@
     // 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);

Modified: trunk/Source/WebCore/testing/Internals.cpp (255118 => 255119)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-01-25 16:51:34 UTC (rev 255119)
@@ -118,6 +118,7 @@
 #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 @@
 #endif
 }
 
+String Internals::mediaMIMETypeForExtension(const String& extension)
+{
+    return MIMETypeRegistry::getMediaMIMETypeForExtension(extension);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.h (255118 => 255119)


--- trunk/Source/WebCore/testing/Internals.h	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebCore/testing/Internals.h	2020-01-25 16:51:34 UTC (rev 255119)
@@ -930,6 +930,8 @@
 
     bool systemHasBattery() const;
 
+    String mediaMIMETypeForExtension(const String& extension);
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (255118 => 255119)


--- trunk/Source/WebCore/testing/Internals.idl	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-01-25 16:51:34 UTC (rev 255119)
@@ -837,4 +837,6 @@
     DOMString systemColorForCSSValue(DOMString cssValue, boolean useDarkModeAppearance, boolean useElevatedUserInterfaceLevel);
 
     boolean systemHasBattery();
+
+    DOMString mediaMIMETypeForExtension(DOMString extension);
 };

Modified: trunk/Source/WebKit/ChangeLog (255118 => 255119)


--- trunk/Source/WebKit/ChangeLog	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebKit/ChangeLog	2020-01-25 16:51:34 UTC (rev 255119)
@@ -1,3 +1,22 @@
+2020-01-25  Per Arne Vollan  <[email protected]>
+
+        [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  <[email protected]>
 
         [LFC][Integration] Re-enable line layout integration

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (255118 => 255119)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-01-25 16:51:34 UTC (rev 255119)
@@ -167,6 +167,7 @@
     encoder << neHelperExtensionHandle;
     encoder << neSessionManagerExtensionHandle;
     encoder << systemHasBattery;
+    encoder << mimeTypesMap;
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -440,6 +441,12 @@
     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)

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (255118 => 255119)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-01-25 16:51:34 UTC (rev 255119)
@@ -209,6 +209,7 @@
     Optional<SandboxExtension::Handle> neHelperExtensionHandle;
     Optional<SandboxExtension::Handle> neSessionManagerExtensionHandle;
     bool systemHasBattery { false };
+    Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>> mimeTypesMap;
 #endif
 
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (255118 => 255119)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-01-25 16:51:34 UTC (rev 255119)
@@ -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 @@
         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 (255118 => 255119)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-01-25 16:51:34 UTC (rev 255119)
@@ -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 @@
         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)

Modified: trunk/Tools/ChangeLog (255118 => 255119)


--- trunk/Tools/ChangeLog	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Tools/ChangeLog	2020-01-25 16:51:34 UTC (rev 255119)
@@ -1,3 +1,14 @@
+2020-01-25  Per Arne Vollan  <[email protected]>
+
+        [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  <[email protected]>
 
         [LFC][Integration] Re-enable line layout integration

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (255118 => 255119)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-01-25 15:57:09 UTC (rev 255118)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-01-25 16:51:34 UTC (rev 255119)
@@ -862,6 +862,7 @@
 		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 */; };
@@ -2385,6 +2386,7 @@
 		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; };
@@ -2826,6 +2828,7 @@
 			isa = PBXGroup;
 			children = (
 				C1692DC923D10DAE006E88F7 /* Battery.mm */,
+				C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */,
 				0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
 			);
 			name = cocoa;
@@ -4809,6 +4812,7 @@
 				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 */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/MimeTypes.mm (0 => 255119)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/MimeTypes.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/MimeTypes.mm	2020-01-25 16:51:34 UTC (rev 255119)
@@ -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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to