Changeset 257828 in webkit


Ignore:
Timestamp:
Mar 3, 2020 9:13:01 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

    r257820 r257828  
     12020-03-03  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-03  Wenson Hsieh  <wenson_hsieh@apple.com>
    231
  • trunk/Source/WebCore/platform/network/mac/UTIUtilities.h

    r257777 r257828  
    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();
    3739}
    38 
    39 #endif // UTIUtilities_h
  • trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm

    r257777 r257828  
    2626#import "config.h"
    2727#import "UTIUtilities.h"
     28
     29#import "MIMETypeRegistry.h"
    2830#import <wtf/MainThread.h>
    2931#import <wtf/TinyLRUCache.h>
     
    4042#define ADDITIONAL_UTI_MAPPINGS
    4143#endif
     44
     45#define EMPTY_MIME_TYPE_STRING "emptyMimeType"_s
    4246
    4347namespace WebCore {
     
    114118}
    115119
     120static Optional<HashMap<String, String>>& mapUTIFromMIMEType()
     121{
     122    static NeverDestroyed<Optional<HashMap<String, String>>> map;
     123    return map;
     124}
     125
    116126struct UTIFromMIMETypeCachePolicy : TinyLRUCachePolicy<String, String> {
    117127public:
    118     static String createValueForKey(const String& key)
     128    static String createValueForKey(const String& mimeType)
    119129    {
     130        String key = mimeType;
     131        if (mapUTIFromMIMEType().hasValue()) {
     132            if (key.isEmpty())
     133                key = EMPTY_MIME_TYPE_STRING;
     134            const auto& it = mapUTIFromMIMEType()->find(key);
     135            if (it != mapUTIFromMIMEType()->end())
     136                return it->value;
     137            WTFLogAlways("UTI for MIME type %s not found.", key.utf8().data());
     138            return UTIFromUnknownMIMEType(key);
     139        }
    120140        auto type = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, key.createCFString().get(), 0));
    121141        if (type)
     
    125145};
    126146
     147static TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>& cacheUTIFromMimeType()
     148{
     149    static NeverDestroyed<TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>> cache;
     150    return cache;
     151}
     152
    127153String UTIFromMIMEType(const String& mimeType)
    128154{
    129155    ASSERT(isMainThread());
    130     static NeverDestroyed<TinyLRUCache<String, String, 16, UTIFromMIMETypeCachePolicy>> cache;
    131     return cache.get().get(mimeType);
     156    return cacheUTIFromMimeType().get(mimeType);
    132157}
    133158
     
    137162}
    138163
     164static const Vector<String>& additionalMIMETypes()
     165{
     166    static NeverDestroyed<Vector<String>> mimeTypes = std::initializer_list<String> {
     167        "application/zip"_s,
     168    };
     169    return mimeTypes;
    139170}
     171
     172const HashMap<String, String>& createUTIFromMIMETypeMap()
     173{
     174    static NeverDestroyed<HashMap<String, String>> map = [] {
     175        HashMap<String, String> cache;
     176        for (auto mimeType : MIMETypeRegistry::supportedImageMIMETypes())
     177            cache.add(mimeType, UTIFromMIMEType(mimeType));
     178        for (auto mimeType : MIMETypeRegistry::supportedNonImageMIMETypes())
     179            cache.add(mimeType, UTIFromMIMEType(mimeType));
     180        for (auto mimeType : MIMETypeRegistry::unsupportedTextMIMETypes())
     181            cache.add(mimeType, UTIFromMIMEType(mimeType));
     182        for (auto mimeType : MIMETypeRegistry::supportedMediaMIMETypes())
     183            cache.add(mimeType, UTIFromMIMEType(mimeType));
     184        for (auto mimeType : MIMETypeRegistry::pdfMIMETypes())
     185            cache.add(mimeType, UTIFromMIMEType(mimeType));
     186        for (auto mimeType : additionalMIMETypes())
     187            cache.add(mimeType, UTIFromMIMEType(mimeType));
     188        cache.add(EMPTY_MIME_TYPE_STRING, UTIFromMIMEType(emptyString()));
     189        return cache;
     190    }();
     191    return map;
     192}
     193
     194void setUTIFromMIMETypeMap(HashMap<String, String>&& map)
     195{
     196    mapUTIFromMIMEType() = WTFMove(map);
     197}
     198
     199}
  • trunk/Source/WebCore/testing/Internals.cpp

    r257811 r257828  
    54845484    return emptyString();
    54855485}
     5486
     5487String Internals::getUTIFromMIMEType(const String& mimeType)
     5488{
     5489    return emptyString();
     5490}
    54865491#endif
    54875492
  • trunk/Source/WebCore/testing/Internals.h

    r257811 r257828  
    940940    String mediaMIMETypeForExtension(const String& extension);
    941941
     942    String getUTIFromMIMEType(const String& mimeType);
     943
    942944    bool supportsPictureInPicture();
    943945
  • trunk/Source/WebCore/testing/Internals.idl

    r257811 r257828  
    849849
    850850    DOMString mediaMIMETypeForExtension(DOMString extension);
    851    
     851
     852    DOMString getUTIFromMIMEType(DOMString mimeType);
     853
    852854    boolean supportsPictureInPicture();
    853855};
  • trunk/Source/WebCore/testing/Internals.mm

    r257777 r257828  
    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

    r257819 r257828  
     12020-03-03  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-03  James Savage  <james.savage@apple.com>
    221
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp

    r257777 r257828  
    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

    r257777 r257828  
    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

    r257777 r257828  
    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

    r257777 r257828  
    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

    r257818 r257828  
     12020-03-03  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-03  Alex Christensen  <achristensen@webkit.org>
    213
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r257780 r257828  
    887887                C15CBB3F23FB177A00300CC7 /* PreferenceChanges.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */; };
    888888                C1692DCA23D10DAE006E88F7 /* Battery.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1692DC923D10DAE006E88F7 /* Battery.mm */; };
     889                C194E31D2409DF43002939ED /* UTIFromMIMEType.mm in Sources */ = {isa = PBXBuildFile; fileRef = C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */; };
    889890                C20F88A72295B96700D610FA /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20F88A62295B96700D610FA /* CoreText.framework */; };
    890891                C22FA32B228F8708009D7988 /* TextWidth.mm in Sources */ = {isa = PBXBuildFile; fileRef = C22FA32A228F8708009D7988 /* TextWidth.mm */; };
     
    24572458                C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferenceChanges.mm; sourceTree = "<group>"; };
    24582459                C1692DC923D10DAE006E88F7 /* Battery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Battery.mm; sourceTree = "<group>"; };
     2460                C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UTIFromMIMEType.mm; sourceTree = "<group>"; };
    24592461                C1D8EE212028E8E3008EB141 /* WebProcessTerminate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessTerminate.mm; sourceTree = "<group>"; };
    24602462                C20F88A62295B96700D610FA /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; };
     
    29092911                                E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */,
    29102912                                C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */,
     2913                                C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */,
    29112914                                0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
    29122915                        );
     
    51095112                                7CCE7F181A411AE600447C4C /* UserMessage.cpp in Sources */,
    51105113                                2EB242B821D4140B0055C1C0 /* UseSelectionAsFindString.mm in Sources */,
     5114                                C194E31D2409DF43002939ED /* UTIFromMIMEType.mm in Sources */,
    51115115                                7C83E03A1D0A602700FEBCF3 /* UtilitiesCocoa.mm in Sources */,
    51125116                                7C83E0C61D0A654E00FEBCF3 /* VideoControlsManager.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.