Changeset 244201 in webkit


Ignore:
Timestamp:
Apr 11, 2019 4:13:44 PM (5 years ago)
Author:
dino@apple.com
Message:

Extract UTI mapping and allow for additions
https://bugs.webkit.org/show_bug.cgi?id=196822
<rdar://problem/49822339>

Reviewed by Tim Horton.

Source/WebCore:

Add an ADDITIONAL_SYSTEM_PREVIEW_TYPES macro to the list
of accepted MIME types. And add a new helper to map
MIME types to UTI types when the system was unable to
find an existing type.

  • platform/MIMETypeRegistry.cpp:

(WebCore::MIMETypeRegistry::systemPreviewMIMETypes):

  • platform/network/mac/UTIUtilities.mm:

(WebCore::UTIFromUnknownMIMEType):
(WebCore::UTIFromMIMETypeCachePolicy::createValueForKey):

Source/WebKit:

Use the new helper to map MIME type to UTI.

  • UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:

(-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):

  • UIProcess/ios/WKSystemPreviewView.mm:

(getUTIForSystemPreviewMIMEType):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r244200 r244201  
     12019-04-11  Dean Jackson  <dino@apple.com>
     2
     3        Extract UTI mapping and allow for additions
     4        https://bugs.webkit.org/show_bug.cgi?id=196822
     5        <rdar://problem/49822339>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add an ADDITIONAL_SYSTEM_PREVIEW_TYPES macro to the list
     10        of accepted MIME types. And add a new helper to map
     11        MIME types to UTI types when the system was unable to
     12        find an existing type.
     13
     14        * platform/MIMETypeRegistry.cpp:
     15        (WebCore::MIMETypeRegistry::systemPreviewMIMETypes):
     16        * platform/network/mac/UTIUtilities.mm:
     17        (WebCore::UTIFromUnknownMIMEType):
     18        (WebCore::UTIFromMIMETypeCachePolicy::createValueForKey):
     19
    1202019-04-09  Ryosuke Niwa  <rniwa@webkit.org>
    221
  • trunk/Source/WebCore/platform/MIMETypeRegistry.cpp

    r243682 r244201  
    5656#if USE(QUICK_LOOK)
    5757#include "PreviewConverter.h"
     58#endif
     59
     60#if USE(APPLE_INTERNAL_SDK)
     61#include <WebKitAdditions/AdditionalSystemPreviewTypes.h>
     62#else
     63#define ADDITIONAL_SYSTEM_PREVIEW_TYPES
    5864#endif
    5965
     
    672678        // Unofficial, but supported because we documented them.
    673679        "model/usd",
    674         "model/vnd.pixar.usd"
     680        "model/vnd.pixar.usd",
     681        ADDITIONAL_SYSTEM_PREVIEW_TYPES
    675682    };
    676683    return systemPreviewMIMETypes;
  • trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm

    r237266 r244201  
    3232#if PLATFORM(IOS_FAMILY)
    3333#import <MobileCoreServices/MobileCoreServices.h>
     34#endif
     35
     36#if USE(APPLE_INTERNAL_SDK)
     37#import <WebKitAdditions/AdditionalUTIMappings.h>
     38#else
     39#define ADDITIONAL_UTI_MAPPINGS
    3440#endif
    3541
     
    7985}
    8086
     87static String UTIFromUnknownMIMEType(const String& mimeType)
     88{
     89    static const auto map = makeNeverDestroyed([] {
     90        struct TypeExtensionPair {
     91            ASCIILiteral type;
     92            ASCIILiteral uti;
     93        };
     94
     95        static const TypeExtensionPair pairs[] = {
     96            { "model/vnd.usdz+zip"_s, "com.pixar.universal-scene-description-mobile"_s },
     97            { "model/usd"_s, "com.pixar.universal-scene-description-mobile"_s },
     98            { "model/vnd.pixar.usd"_s, "com.pixar.universal-scene-description-mobile"_s },
     99            ADDITIONAL_UTI_MAPPINGS
     100        };
     101
     102        HashMap<String, String, ASCIICaseInsensitiveHash> map;
     103        for (auto& pair : pairs)
     104            map.add(pair.type, pair.uti);
     105        return map;
     106    }());
     107
     108    auto mapEntry = map.get().find(mimeType);
     109    if (mapEntry == map.get().end())
     110        return emptyString();
     111
     112    return mapEntry->value;
     113}
     114
    81115struct UTIFromMIMETypeCachePolicy : TinyLRUCachePolicy<String, String> {
    82116public:
    83117    static String createValueForKey(const String& key)
    84118    {
    85         return String(adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, key.createCFString().get(), 0)).get());
     119        auto type = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, key.createCFString().get(), 0));
     120        if (type)
     121            return String(type.get());
     122        return UTIFromUnknownMIMEType(key);
    86123    }
    87124};
  • trunk/Source/WebKit/ChangeLog

    r244198 r244201  
     12019-04-11  Dean Jackson  <dino@apple.com>
     2
     3        Extract UTI mapping and allow for additions
     4        https://bugs.webkit.org/show_bug.cgi?id=196822
     5        <rdar://problem/49822339>
     6
     7        Reviewed by Tim Horton.
     8
     9        Use the new helper to map MIME type to UTI.
     10
     11        * UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
     12        (-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):
     13        * UIProcess/ios/WKSystemPreviewView.mm:
     14        (getUTIForSystemPreviewMIMEType):
     15
     16
    1172019-04-11  Said Abou-Hallawa  <sabouhallawa@apple.com>
    218
  • trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm

    r241730 r244201  
    3535#import <UIKit/UIViewController.h>
    3636#import <WebCore/MIMETypeRegistry.h>
     37#import <WebCore/UTIUtilities.h>
    3738#import <pal/ios/QuickLookSoftLink.h>
    3839#import <pal/spi/ios/QuickLookSPI.h>
     
    8283    // FIXME: We are launching the preview controller before getting a response from the resource, which
    8384    // means we don't actually know the real MIME type yet.
    84     // FIXME: At the moment we only have one supported UTI, but if we start supporting more types,
    85     // then we'll need a table.
    86     static NSString *contentType = (__bridge NSString *) UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, CFSTR("usdz"), nil);
     85    NSString *contentType = WebCore::UTIFromMIMEType("model/vnd.usdz+zip"_s);
    8786
    8887    _item = adoptNS([PAL::allocQLItemInstance() initWithPreviewItemProvider:_itemProvider.get() contentType:contentType previewTitle:@"Preview" fileSize:@(0)]);
  • trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm

    r243595 r244201  
    3737#import <WebCore/LocalizedStrings.h>
    3838#import <WebCore/MIMETypeRegistry.h>
     39#import <WebCore/UTIUtilities.h>
    3940#import <pal/ios/QuickLookSoftLink.h>
    4041#import <pal/spi/cg/CoreGraphicsSPI.h>
     
    4647SOFT_LINK_CLASS(AssetViewer, ASVThumbnailView);
    4748
    48 // FIXME: At the moment we only have one supported UTI, but
    49 // if we start supporting more types, then we'll need a table.
    5049static NSString *getUTIForSystemPreviewMIMEType(const String& mimeType)
    5150{
    52     static NSString *uti = (__bridge NSString *) UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, CFSTR("usdz"), nil);
    53 
    5451    if (!WebCore::MIMETypeRegistry::isSystemPreviewMIMEType(mimeType))
    5552        return nil;
    5653
    57     return uti;
     54    return WebCore::UTIFromMIMEType(mimeType);
    5855}
    5956
Note: See TracChangeset for help on using the changeset viewer.