Changeset 257725 in webkit


Ignore:
Timestamp:
Mar 2, 2020 12:21:33 PM (4 years ago)
Author:
pvollan@apple.com
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):

Location:
trunk
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r257722 r257725  
     12020-03-02  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=208415
     5
     6        Reviewed by Brent Fulgham.
     7
     8        This is currently done in the WebContent process, but since this is using a system service which will be closed,
     9        this mapping should be moved to the UI process. The UI process will create this mapping for a set of mime types,
     10        and send it to the WebContent process.
     11
     12        API test: WebKit.UTIFromMIMEType
     13
     14        * platform/network/mac/UTIUtilities.h:
     15        * platform/network/mac/UTIUtilities.mm:
     16        (WebCore::mapUTIFromMIMEType):
     17        (WebCore::UTIFromMIMETypeCachePolicy::createValueForKey):
     18        (WebCore::cacheUTIFromMimeType):
     19        (WebCore::UTIFromMIMEType):
     20        (WebCore::mimeTypes):
     21        (WebCore::createUTIFromMIMETypeMap):
     22        (WebCore::setUTIFromMIMETypeMap):
     23        * testing/Internals.cpp:
     24        (WebCore::Internals::getUTIFromMIMEType):
     25        * testing/Internals.mm:
     26        (WebCore::Internals::getUTIFromMIMEType):
     27        * testing/Internals.h:
     28        * testing/Internals.idl:
     29
    1302020-03-02  Daniel Bates  <dabates@apple.com>
    231
  • trunk/Source/WebCore/platform/network/mac/UTIUtilities.h

    r257713 r257725  
    2424 */
    2525
    26 #ifndef UTIUtilities_h
    27 #define UTIUtilities_h
     26#pragma once
    2827
    29 #import <wtf/Forward.h>
    30 #import <wtf/RetainPtr.h>
     28#include <wtf/text/WTFString.h>
    3129
    3230namespace WebCore {
     31
    3332WEBCORE_EXPORT String MIMETypeFromUTI(const String&);
    3433String MIMETypeFromUTITree(const String&);
    3534WEBCORE_EXPORT String UTIFromMIMEType(const String&);
    3635bool isDeclaredUTI(const String&);
     36
     37WEBCORE_EXPORT void setUTIFromMIMETypeMap(HashMap<String, String>&&);
     38WEBCORE_EXPORT const HashMap<String, String>& createUTIFromMIMETypeMap();
     39WEBCORE_EXPORT const Vector<String>& mimeTypes();
    3740}
    38 
    39 #endif // UTIUtilities_h
  • trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm

    r257713 r257725  
    4141#endif
    4242
     43#define EMPTY_MIME_TYPE_STRING "emptyMimeType"_s
     44
    4345namespace WebCore {
    4446
     
    114116}
    115117
     118static Optional<HashMap<String, String>>& mapUTIFromMIMEType()
     119{
     120    static NeverDestroyed<Optional<HashMap<String, String>>> map;
     121    return map;
     122}
     123
    116124struct UTIFromMIMETypeCachePolicy : TinyLRUCachePolicy<String, String> {
    117125public:
    118     static String createValueForKey(const String& key)
     126    static String createValueForKey(const String& mimeType)
    119127    {
     128        String key = mimeType;
     129        if (mapUTIFromMIMEType().hasValue()) {
     130            if (key.isEmpty())
     131                key = EMPTY_MIME_TYPE_STRING;
     132            const auto& it = mapUTIFromMIMEType()->find(key);
     133            if (it != mapUTIFromMIMEType()->end())
     134                return it->value;
     135            WTFLogAlways("UTI for MIME type %s not found.", key.utf8().data());
     136            ASSERT_NOT_REACHED();
     137        }
    120138        auto type = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, key.createCFString().get(), 0));
    121139        if (type)
     
    125143};
    126144
     145static TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>& cacheUTIFromMimeType()
     146{
     147    static NeverDestroyed<TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>> cache;
     148    return cache;
     149}
     150
    127151String UTIFromMIMEType(const String& mimeType)
    128152{
    129153    ASSERT(isMainThread());
    130     static NeverDestroyed<TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>> cache;
    131     return cache.get().get(mimeType);
     154    return cacheUTIFromMimeType().get(mimeType);
    132155}
    133156
     
    137160}
    138161
    139 }
     162const Vector<String>& mimeTypes()
     163{
     164    static NeverDestroyed<Vector<String>> mimeTypes = std::initializer_list<String> {
     165        "application/ogg"_s,
     166        "audio/ogg"_s,
     167        "video/ogg"_s,
     168        "application/annodex"_s,
     169        "audio/annodex"_s,
     170        "video/annodex"_s,
     171        "audio/speex"_s,
     172        "video/webm"_s,
     173        "audio/webm"_s,
     174        "audio/mpeg"_s,
     175        "video/mpeg"_s,
     176        "application/vnd.apple.mpegurl"_s,
     177        "application/mpegurl"_s,
     178        "application/x-mpegurl"_s,
     179        "audio/mpegurl"_s,
     180        "audio/x-mpegurl"_s,
     181        "audio/mpegurl"_s,
     182        "video/x-m4v"_s,
     183        "audio/x-m4a"_s,
     184        "audio/x-m4b"_s,
     185        "audio/x-m4p"_s,
     186        "video/mp4"_s,
     187        "audio/mp4"_s,
     188        "audio/mp3"_s,
     189        "audio/x-mp3"_s,
     190        "audio/x-mpeg"_s,
     191        "video/x-mpeg2"_s,
     192        "video/mpeg2"_s,
     193        "video/m2ts"_s,
     194        "video/x-m2ts"_s,
     195        "audio/3gpp"_s,
     196        "audio/3gpp2"_s,
     197        "application/x-mpeg"_s,
     198        "audio/aac"_s,
     199        "audio/x-aac"_s,
     200        "audio/x-caf"_s,
     201        "audio/x-gsm"_s,
     202        "audio/x-wav"_s,
     203        "audio/vnd.wave"_s,
     204        "audio/wav"_s,
     205
     206        "image/gif"_s,
     207        "image/jpeg"_s,
     208        "image/png"_s,
     209
     210        "multipart/x-folder"_s,
     211
     212        "text/html"_s,
     213        "text/plain"_s,
     214    };
     215    return mimeTypes;
     216};
     217
     218const HashMap<String, String>& createUTIFromMIMETypeMap()
     219{
     220    static NeverDestroyed<HashMap<String, String>> map = [] {
     221        HashMap<String, String> cache;
     222        for (auto mimeType : mimeTypes())
     223            cache.add(mimeType, UTIFromMIMEType(mimeType));
     224        cache.add(EMPTY_MIME_TYPE_STRING, UTIFromMIMEType(emptyString()));
     225        return cache;
     226    }();
     227    return map;
     228}
     229
     230void setUTIFromMIMETypeMap(HashMap<String, String>&& map)
     231{
     232    mapUTIFromMIMEType() = WTFMove(map);
     233}
     234
     235}
  • trunk/Source/WebCore/testing/Internals.cpp

    r257713 r257725  
    54755475    return emptyString();
    54765476}
     5477
     5478String Internals::getUTIFromMIMEType(const String& mimeType)
     5479{
     5480    return emptyString();
     5481}
    54775482#endif
    54785483
  • trunk/Source/WebCore/testing/Internals.h

    r257713 r257725  
    939939    String mediaMIMETypeForExtension(const String& extension);
    940940
     941    String getUTIFromMIMEType(const String& mimeType);
     942
    941943    bool supportsPictureInPicture();
    942944
  • trunk/Source/WebCore/testing/Internals.idl

    r257713 r257725  
    847847
    848848    DOMString mediaMIMETypeForExtension(DOMString extension);
    849    
     849
     850    DOMString getUTIFromMIMEType(DOMString mimeType);
     851
    850852    boolean supportsPictureInPicture();
    851853};
  • trunk/Source/WebCore/testing/Internals.mm

    r257713 r257725  
    3535#import "MediaPlayerPrivate.h"
    3636#import "Range.h"
     37#import "UTIUtilities.h"
    3738#import <AVFoundation/AVPlayer.h>
    3839#import <wtf/cocoa/NSURLExtras.h>
     
    101102}
    102103
     104String Internals::getUTIFromMIMEType(const String& mimeType)
     105{
     106    return UTIFromMIMEType(mimeType);
    103107}
     108
     109}
  • trunk/Source/WebKit/ChangeLog

    r257724 r257725  
     12020-03-02  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=208415
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Send the mapping between MIME types and UTI types to the WebContent process as part of the Web
     9        process creation parameters.
     10
     11        * Shared/WebProcessCreationParameters.cpp:
     12        (WebKit::WebProcessCreationParameters::encode const):
     13        (WebKit::WebProcessCreationParameters::decode):
     14        * Shared/WebProcessCreationParameters.h:
     15        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     16        (WebKit::WebProcessPool::platformInitializeWebProcess):
     17        * WebProcess/cocoa/WebProcessCocoa.mm:
     18        (WebKit::WebProcess::platformInitializeWebProcess):
     19
    1202020-03-02  Eric Carlson  <eric.carlson@apple.com>
    221
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp

    r257713 r257725  
    172172    encoder << systemHasBattery;
    173173    encoder << mimeTypesMap;
     174    encoder << mapUTIFromMIMEType;
    174175#endif
    175176
     
    461462        return false;
    462463    parameters.mimeTypesMap = WTFMove(*mimeTypesMap);
     464
     465    Optional<HashMap<String, String>> mapUTIFromMIMEType;
     466    decoder >> mapUTIFromMIMEType;
     467    if (!mapUTIFromMIMEType)
     468        return false;
     469    parameters.mapUTIFromMIMEType = WTFMove(*mapUTIFromMIMEType);
    463470#endif
    464471
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.h

    r257713 r257725  
    214214    bool systemHasBattery { false };
    215215    Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>> mimeTypesMap;
     216    HashMap<String, String> mapUTIFromMIMEType;
    216217#endif
    217218
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r257713 r257725  
    5757#import <WebCore/RuntimeApplicationChecks.h>
    5858#import <WebCore/SharedBuffer.h>
     59#import <WebCore/UTIUtilities.h>
    5960#import <objc/runtime.h>
    6061#import <pal/spi/cf/CFNetworkSPI.h>
     
    407408    }
    408409    parameters.systemHasBattery = systemHasBattery();
     410    parameters.mimeTypesMap = commonMimeTypesMap();
     411    parameters.mapUTIFromMIMEType = createUTIFromMIMETypeMap();
    409412#endif
    410413   
     
    415418        parameters.contentFilterExtensionHandle = WTFMove(handle);
    416419    }
    417     parameters.mimeTypesMap = commonMimeTypesMap();
    418420#endif
    419421   
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r257713 r257725  
    6868#import <WebCore/RuntimeApplicationChecks.h>
    6969#import <WebCore/SWContextManager.h>
     70#import <WebCore/UTIUtilities.h>
    7071#import <algorithm>
    7172#import <dispatch/dispatch.h>
     
    275276    if (parameters.mimeTypesMap)
    276277        overriddenMimeTypesMap() = WTFMove(parameters.mimeTypesMap);
     278
     279    setUTIFromMIMETypeMap(WTFMove(parameters.mapUTIFromMIMEType));
    277280#endif
    278281
  • trunk/Tools/ChangeLog

    r257722 r257725  
     12020-03-02  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Cocoa] Mapping from MIME type to UTI type should be done in the UI process
     4        https://bugs.webkit.org/show_bug.cgi?id=208415
     5
     6        Reviewed by Brent Fulgham.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WebKit/UTIFromMIMEType.mm: Added.
     10        (TEST):
     11
    1122020-03-02  Daniel Bates  <dabates@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r257713 r257725  
    884884                C15CBB3F23FB177A00300CC7 /* PreferenceChanges.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */; };
    885885                C1692DCA23D10DAE006E88F7 /* Battery.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1692DC923D10DAE006E88F7 /* Battery.mm */; };
     886                C194E31D2409DF43002939ED /* UTIFromMIMEType.mm in Sources */ = {isa = PBXBuildFile; fileRef = C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */; };
    886887                C20F88A72295B96700D610FA /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20F88A62295B96700D610FA /* CoreText.framework */; };
    887888                C22FA32B228F8708009D7988 /* TextWidth.mm in Sources */ = {isa = PBXBuildFile; fileRef = C22FA32A228F8708009D7988 /* TextWidth.mm */; };
     
    24492450                C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferenceChanges.mm; sourceTree = "<group>"; };
    24502451                C1692DC923D10DAE006E88F7 /* Battery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Battery.mm; sourceTree = "<group>"; };
     2452                C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UTIFromMIMEType.mm; sourceTree = "<group>"; };
    24512453                C1D8EE212028E8E3008EB141 /* WebProcessTerminate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessTerminate.mm; sourceTree = "<group>"; };
    24522454                C20F88A62295B96700D610FA /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; };
     
    29012903                                E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */,
    29022904                                C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */,
     2905                                C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */,
    29032906                                0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
    29042907                        );
     
    50975100                                7CCE7F181A411AE600447C4C /* UserMessage.cpp in Sources */,
    50985101                                2EB242B821D4140B0055C1C0 /* UseSelectionAsFindString.mm in Sources */,
     5102                                C194E31D2409DF43002939ED /* UTIFromMIMEType.mm in Sources */,
    50995103                                7C83E03A1D0A602700FEBCF3 /* UtilitiesCocoa.mm in Sources */,
    51005104                                7C83E0C61D0A654E00FEBCF3 /* VideoControlsManager.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.