Move SystemPreview code from WebKitAdditions to WebKit
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Sep 2018 19:38:33 +0000 (19:38 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Sep 2018 19:38:33 +0000 (19:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189252
<rdar://problem/44080245>

Reviewed by Wenson Hsieh.

Source/WebCore:

Move the WebKitAdditions code into WebKit/WebCore.

* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::relList const): Look for "ar".
(WebCore::HTMLAnchorElement::isSystemPreviewLink const): Ditto.

* platform/MIMETypeRegistry.cpp: Add a couple of new static methods
for System Preview MIME types.
(WebCore::initializeSystemPreviewMIMETypes):
(WebCore::MIMETypeRegistry::getSystemPreviewMIMETypes):
(WebCore::MIMETypeRegistry::isSystemPreviewMIMEType):
* platform/MIMETypeRegistry.h:

* rendering/RenderThemeIOS.mm: Load the ARKit artwork from the framework.
(WebCore::arKitBundle):
(WebCore::loadARKitPDFPage):
(WebCore::systemPreviewLogo):
(WebCore::RenderThemeIOS::paintSystemPreviewBadge):

* testing/Internals.cpp: Remove internal helper.
(WebCore::Internals::systemPreviewRelType): Deleted.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Move the WebKitAdditions code into WebKit/WebCore.

* UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
(getUTIForMIMEType): Helper to get the system UTI for USDZ files.
(-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):

* UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm: Use the new methods
in MIMETypeRegistry.
(-[WKWebViewContentProviderRegistry initWithConfiguration:]):

* UIProcess/SystemPreviewController.cpp: Ditto.
(WebKit::SystemPreviewController::canPreview const):

* UIProcess/ios/WKSystemPreviewView.mm:
(getUTIForMIMEType): Similar helper to above.
(-[WKSystemPreviewView web_setContentProviderData:suggestedFilename:]):

LayoutTests:

This test no longer needs an internal helper.

* system-preview/detection.html:

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/system-preview/detection.html
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm
Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm
Source/WebKit/UIProcess/SystemPreviewController.cpp
Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm

index 17eb593..aa3dd20 100644 (file)
@@ -1,3 +1,15 @@
+2018-09-03  Dean Jackson  <dino@apple.com>
+
+        Move SystemPreview code from WebKitAdditions to WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=189252
+        <rdar://problem/44080245>
+
+        Reviewed by Wenson Hsieh.
+
+        This test no longer needs an internal helper.
+
+        * system-preview/detection.html:
+
 2018-09-04  Antoine Quint  <graouts@apple.com>
 
         [Modern Media Controls] Disabling both fullscreen and picture-in-picture shows an empty top left container
index d10db86..a1bbb9a 100644 (file)
@@ -25,15 +25,11 @@ window.addEventListener("load", () => {
     if (!window.internals)
         return;
 
-    const relValue = internals.systemPreviewRelType();
     TESTS.forEach(id => {
         const [link, children, result] = getSystemPreviewData(id);
         if (link) {
             addResult(result, "Link element present.");
 
-            if (id != "invalid-1")
-                link.rel += " " + relValue;
-
             if (internals.isSystemPreviewLink(link))
                 addResult(result, " Identified as system preview.");
             else
@@ -65,7 +61,7 @@ window.addEventListener("load", () => {
 <p>This test only works in WKTR or DRT.</p>
 <div id="valid-1">
 <p>Valid system preview</p>
-<a href="/" rel="">
+<a href="/" rel="ar">
     <img>
 </a>
 <p>Result: </p>
@@ -73,7 +69,7 @@ window.addEventListener("load", () => {
 
 <div id="valid-2">
 <p>Valid system preview (multiple rel values)</p>
-<a href="/" rel="foo">
+<a href="/" rel="foo ar">
     <img>
 </a>
 <p>Result: </p>
@@ -81,7 +77,7 @@ window.addEventListener("load", () => {
 
 <div id="valid-3">
 <p>Valid system preview (picture child)</p>
-<a href="/" rel="">
+<a href="/" rel="ar">
     <picture></picture>
 </a>
 <p>Result: </p>
@@ -89,7 +85,7 @@ window.addEventListener("load", () => {
 
 <div id="invalid-1">
 <p>Invalid system preview (wrong rel value)</p>
-<a href="/" rel="">
+<a href="/" rel="arfoo">
     <img>
 </a>
 <p>Result: </p>
@@ -97,7 +93,7 @@ window.addEventListener("load", () => {
 
 <div id="invalid-2">
 <p>Invalid system preview (wrong children)</p>
-<a href="/" rel="">
+<a href="/" rel="ar">
     <span>hello</span>
 </a>
 <p>Result: </p>
@@ -105,7 +101,7 @@ window.addEventListener("load", () => {
 
 <div id="invalid-3">
 <p>Invalid system preview (too many children)</p>
-<a href="/" rel="">
+<a href="/" rel="ar">
     <span>hello</span>
     <img>
 </a>
@@ -114,7 +110,7 @@ window.addEventListener("load", () => {
 
 <div id="invalid-4">
 <p>Invalid system preview (no children)</p>
-<a href="/" rel="">
+<a href="/" rel="ar">
 </a>
 <p>Result: </p>
 </div>
index fc93ef8..8a8b6c1 100644 (file)
@@ -1,3 +1,35 @@
+2018-09-03  Dean Jackson  <dino@apple.com>
+
+        Move SystemPreview code from WebKitAdditions to WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=189252
+        <rdar://problem/44080245>
+
+        Reviewed by Wenson Hsieh.
+
+        Move the WebKitAdditions code into WebKit/WebCore.
+
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::relList const): Look for "ar".
+        (WebCore::HTMLAnchorElement::isSystemPreviewLink const): Ditto.
+
+        * platform/MIMETypeRegistry.cpp: Add a couple of new static methods
+        for System Preview MIME types.
+        (WebCore::initializeSystemPreviewMIMETypes):
+        (WebCore::MIMETypeRegistry::getSystemPreviewMIMETypes):
+        (WebCore::MIMETypeRegistry::isSystemPreviewMIMEType):
+        * platform/MIMETypeRegistry.h:
+
+        * rendering/RenderThemeIOS.mm: Load the ARKit artwork from the framework.
+        (WebCore::arKitBundle):
+        (WebCore::loadARKitPDFPage):
+        (WebCore::systemPreviewLogo):
+        (WebCore::RenderThemeIOS::paintSystemPreviewBadge):
+
+        * testing/Internals.cpp: Remove internal helper.
+        (WebCore::Internals::systemPreviewRelType): Deleted.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2018-09-04  Andy Estes  <aestes@apple.com>
 
         [Payment Request] PaymentResponse should have an onpayerdetailchange event handler
index c310cf2..27c0a0d 100644 (file)
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/text/StringBuilder.h>
 
-#if USE(SYSTEM_PREVIEW) && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/SystemPreviewDetection.cpp>
-#endif
-
 namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLAnchorElement);
@@ -314,12 +310,7 @@ DOMTokenList& HTMLAnchorElement::relList() const
     if (!m_relList) {
         m_relList = std::make_unique<DOMTokenList>(const_cast<HTMLAnchorElement&>(*this), HTMLNames::relAttr, [](Document&, StringView token) {
 #if USE(SYSTEM_PREVIEW)
-#if USE(APPLE_INTERNAL_SDK)
-            auto systemPreviewRelValue = getSystemPreviewRelValue();
-#else
-            auto systemPreviewRelValue = "system-preview"_s;
-#endif
-            return equalIgnoringASCIICase(token, "noreferrer") || equalIgnoringASCIICase(token, "noopener") || equalIgnoringASCIICase(token, systemPreviewRelValue);
+            return equalIgnoringASCIICase(token, "noreferrer") || equalIgnoringASCIICase(token, "noopener") || equalIgnoringASCIICase(token, "ar");
 #else
             return equalIgnoringASCIICase(token, "noreferrer") || equalIgnoringASCIICase(token, "noopener");
 #endif
@@ -383,11 +374,7 @@ bool HTMLAnchorElement::isSystemPreviewLink() const
     if (!RuntimeEnabledFeatures::sharedFeatures().systemPreviewEnabled())
         return false;
 
-#if USE(APPLE_INTERNAL_SDK)
-    auto systemPreviewRelValue = getSystemPreviewRelValue();
-#else
-    auto systemPreviewRelValue = String { "system-preview"_s };
-#endif
+    static NeverDestroyed<AtomicString> systemPreviewRelValue("ar", AtomicString::ConstructFromLiteral);
 
     if (!relList().contains(systemPreviewRelValue))
         return false;
@@ -395,7 +382,7 @@ bool HTMLAnchorElement::isSystemPreviewLink() const
     if (auto* child = firstElementChild()) {
         if (is<HTMLImageElement>(child) || is<HTMLPictureElement>(child)) {
             auto numChildren = childElementCount();
-            // FIXME: Should only be 1.
+            // FIXME: We've documented that it should be the only child, but some early demos have two children.
             return numChildren == 1 || numChildren == 2;
         }
     }
index 76c63b7..829bf0d 100644 (file)
@@ -64,6 +64,10 @@ static HashSet<String, ASCIICaseInsensitiveHash>* supportedMediaMIMETypes;
 static HashSet<String, ASCIICaseInsensitiveHash>* pdfMIMETypes;
 static HashSet<String, ASCIICaseInsensitiveHash>* unsupportedTextMIMETypes;
 
+#if USE(SYSTEM_PREVIEW)
+static HashSet<String, ASCIICaseInsensitiveHash>* systemPreviewMIMETypes;
+#endif
+
 static void initializeSupportedImageMIMETypes()
 {
     supportedImageResourceMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
@@ -700,6 +704,37 @@ const String& defaultMIMEType()
     return defaultMIMEType;
 }
 
+#if USE(SYSTEM_PREVIEW)
+static void initializeSystemPreviewMIMETypes()
+{
+    const char* const types[] = {
+        // The official type: https://www.iana.org/assignments/media-types/model/vnd.usdz+zip
+        "model/vnd.usdz+zip",
+        // Unofficial, but supported because we documented them.
+        "model/usd",
+        "model/vnd.pixar.usd"
+    };
+
+    systemPreviewMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
+    for (auto& type : types)
+        systemPreviewMIMETypes->add(type);
+}
+
+const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getSystemPreviewMIMETypes()
+{
+    if (!systemPreviewMIMETypes)
+        initializeSystemPreviewMIMETypes();
+    return *systemPreviewMIMETypes;
+}
+
+bool MIMETypeRegistry::isSystemPreviewMIMEType(const String& mimeType)
+{
+    if (mimeType.isEmpty())
+        return false;
+    return getSystemPreviewMIMETypes().contains(mimeType);
+}
+#endif
+
 #if !USE(CURL)
 
 // FIXME: Not sure why it makes sense to have a cross-platform function when only CURL has the concept
index 9244973..8d5a0dd 100644 (file)
@@ -88,6 +88,10 @@ public:
     static bool isPostScriptMIMEType(const String& mimeType);
     WEBCORE_EXPORT static bool isPDFOrPostScriptMIMEType(const String& mimeType);
 
+#if USE(SYSTEM_PREVIEW)
+    WEBCORE_EXPORT static bool isSystemPreviewMIMEType(const String& mimeType);
+#endif
+
     // Check to see if a MIME type is suitable for being shown inside a page.
     // Returns true if any of isSupportedImageMIMEType(), isSupportedNonImageMIMEType(),
     // isSupportedMediaMIMEType(), isSupportedJavaScriptMIMEType(), isSupportedJSONMIMEType(),
@@ -114,6 +118,10 @@ public:
     WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getPDFMIMETypes();
     WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getUnsupportedTextMIMETypes();
 
+#if USE(SYSTEM_PREVIEW)
+    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getSystemPreviewMIMETypes();
+#endif
+
     // FIXME: WebKit coding style says we should not have the word "get" in the name of this function.
     // FIXME: Unclear what the concept of a normalized MIME type is; currently it's a platform-specific notion.
     static String getNormalizedMIMEType(const String&);
index b862734..2737882 100644 (file)
 #import <wtf/SoftLinking.h>
 #import <wtf/StdLibExtras.h>
 
-#if USE(SYSTEM_PREVIEW) && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/SystemPreviewArtwork.cpp>
-#endif
-
 SOFT_LINK_FRAMEWORK(UIKit)
 SOFT_LINK_CLASS(UIKit, UIApplication)
 SOFT_LINK_CLASS(UIKit, UIColor)
@@ -1857,6 +1853,50 @@ String RenderThemeIOS::extraDefaultStyleSheet()
 #endif
 
 #if USE(SYSTEM_PREVIEW)
+static NSBundle *arKitBundle()
+{
+    static NSBundle *arKitBundle;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+#if PLATFORM(IOS_SIMULATOR)
+        dlopen("/System/Library/PrivateFrameworks/AssetViewer.framework/AssetViewer", RTLD_NOW);
+        arKitBundle = [NSBundle bundleForClass:NSClassFromString(@"ASVThumbnailView")];
+#else
+        arKitBundle = [NSBundle bundleWithURL:[NSURL fileURLWithPath:@"/System/Library/PrivateFrameworks/AssetViewer.framework"]];
+#endif
+    });
+
+    return arKitBundle;
+}
+
+static RetainPtr<CGPDFPageRef> loadARKitPDFPage(NSString *imageName)
+{
+    NSURL *url = [arKitBundle() URLForResource:imageName withExtension:@"pdf"];
+
+    if (!url)
+        return nullptr;
+
+    auto document = adoptCF(CGPDFDocumentCreateWithURL((CFURLRef)url));
+    if (!document)
+        return nullptr;
+
+    if (!CGPDFDocumentGetNumberOfPages(document.get()))
+        return nullptr;
+
+    return CGPDFDocumentGetPage(document.get(), 1);
+};
+
+static CGPDFPageRef systemPreviewLogo()
+{
+    static CGPDFPageRef logoPage;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        logoPage = loadARKitPDFPage(@"ARKitBadge").leakRef();
+    });
+
+    return logoPage;
+};
+
 void RenderThemeIOS::paintSystemPreviewBadge(Image& image, const PaintInfo& paintInfo, const FloatRect& rect)
 {
     static const int largeBadgeDimension = 70;
@@ -1990,7 +2030,6 @@ void RenderThemeIOS::paintSystemPreviewBadge(Image& image, const PaintInfo& pain
     CGContextScaleCTM(ctx, 1, -1);
     CGContextDrawImage(ctx, badgeRect, cgImage.get());
 
-#if USE(APPLE_INTERNAL_SDK)
     if (auto logo = systemPreviewLogo()) {
         CGSize pdfSize = CGPDFPageGetBoxRect(logo, kCGPDFMediaBox).size;
         CGFloat scaleX = badgeDimension / pdfSize.width;
@@ -1998,7 +2037,6 @@ void RenderThemeIOS::paintSystemPreviewBadge(Image& image, const PaintInfo& pain
         CGContextScaleCTM(ctx, scaleX, scaleY);
         CGContextDrawPDFPage(ctx, logo);
     }
-#endif
 
     CGContextFlush(ctx);
     CGContextRestoreGState(ctx);
index 413291a..f543d23 100644 (file)
@@ -4626,15 +4626,6 @@ MockCredentialsMessenger& Internals::mockCredentialsMessenger() const
 }
 #endif
 
-String Internals::systemPreviewRelType()
-{
-#if USE(SYSTEM_PREVIEW) && USE(APPLE_INTERNAL_SDK)
-    return getSystemPreviewRelValue();
-#else
-    return "system-preview"_s;
-#endif
-}
-
 bool Internals::isSystemPreviewLink(Element& element) const
 {
 #if USE(SYSTEM_PREVIEW)
index 74119c5..b4a50ba 100644 (file)
@@ -700,7 +700,6 @@ public:
     MockCredentialsMessenger& mockCredentialsMessenger() const;
 #endif
 
-    String systemPreviewRelType();
     bool isSystemPreviewLink(Element&) const;
     bool isSystemPreviewImage(Element&) const;
 
index 7cc1f48..078846e 100644 (file)
@@ -648,7 +648,6 @@ enum CompositingPolicy {
     [Conditional=APPLE_PAY] readonly attribute MockPaymentCoordinator mockPaymentCoordinator;
     [Conditional=WEB_AUTHN] readonly attribute MockCredentialsMessenger mockCredentialsMessenger;
 
-    DOMString systemPreviewRelType();
     boolean isSystemPreviewLink(Element element);
     boolean isSystemPreviewImage(Element element);
 
index bf5ae18..c6aee48 100644 (file)
@@ -1,3 +1,28 @@
+2018-09-03  Dean Jackson  <dino@apple.com>
+
+        Move SystemPreview code from WebKitAdditions to WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=189252
+        <rdar://problem/44080245>
+
+        Reviewed by Wenson Hsieh.
+
+        Move the WebKitAdditions code into WebKit/WebCore.
+
+        * UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
+        (getUTIForMIMEType): Helper to get the system UTI for USDZ files.
+        (-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):
+
+        * UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm: Use the new methods
+        in MIMETypeRegistry.
+        (-[WKWebViewContentProviderRegistry initWithConfiguration:]):
+
+        * UIProcess/SystemPreviewController.cpp: Ditto.
+        (WebKit::SystemPreviewController::canPreview const):
+
+        * UIProcess/ios/WKSystemPreviewView.mm:
+        (getUTIForMIMEType): Similar helper to above.
+        (-[WKSystemPreviewView web_setContentProviderData:suggestedFilename:]):
+
 2018-09-04  Frederic Wang  <fwang@igalia.com>
 
         Bug 189190 - REGRESSION(r235398) ASSERTION failure !m_client.didFinishDocumentLoadForFrame
index dfc828e..eb4af1d 100644 (file)
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <QuickLook/QuickLook.h>
 #import <UIKit/UIViewController.h>
+#import <WebCore/MIMETypeRegistry.h>
 #import <pal/spi/ios/QuickLookSPI.h>
 #import <wtf/SoftLinking.h>
 #import <wtf/WeakObjCPtr.h>
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/SystemPreviewTypes.cpp>
-#endif
-
 SOFT_LINK_FRAMEWORK(QuickLook)
 SOFT_LINK_CLASS(QuickLook, QLPreviewController);
 SOFT_LINK_CLASS(QuickLook, QLItem);
 
+// FIXME: At the moment we only have one supported UTI, but
+// if we start supporting more types, then we'll need a table.
+static String getUTIForMIMEType(const String& mimeType)
+{
+    static const NeverDestroyed<String> uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, CFSTR("usdz"), nil)).get();
+
+    if (!WebCore::MIMETypeRegistry::isSystemPreviewMIMEType(mimeType))
+        return emptyString();
+
+    return uti;
+}
+
 @interface _WKPreviewControllerDataSource : NSObject <QLPreviewControllerDataSource> {
     RetainPtr<NSItemProvider> _itemProvider;
     RetainPtr<QLItem> _item;
@@ -85,12 +94,10 @@ SOFT_LINK_CLASS(QuickLook, QLItem);
         return _item.get();
 
     _itemProvider = adoptNS([[NSItemProvider alloc] init]);
-    NSString *contentType = @"public.content";
-#if USE(APPLE_INTERNAL_SDK)
     // FIXME: We are launching the preview controller before getting a response from the resource, which
     // means we don't actually know the real MIME type yet. Assume it is one of those that we registered.
-    contentType = WebKit::getUTIForMIMEType(*WebKit::getSystemPreviewMIMETypes().begin());
-#endif
+    NSString *contentType = getUTIForMIMEType(*WebCore::MIMETypeRegistry::getSystemPreviewMIMETypes().begin());
+
     _item = adoptNS([allocQLItemInstance() initWithPreviewItemProvider:_itemProvider.get() contentType:contentType previewTitle:@"Preview" fileSize:@(0)]);
     [_item setUseLoadingTimeout:NO];
 
index 6a5df4c..23e373c 100644 (file)
 #import <wtf/text/StringHash.h>
 #import <wtf/text/WTFString.h>
 
-#if USE(SYSTEM_PREVIEW) && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/SystemPreviewTypes.cpp>
-#endif
-
 @implementation WKWebViewContentProviderRegistry {
     HashMap<String, Class <WKWebViewContentProvider>, ASCIICaseInsensitiveHash> _contentProviderForMIMEType;
     HashCountedSet<WebKit::WebPageProxy*> _pages;
@@ -64,9 +60,9 @@
         [self registerProvider:[WKLegacyPDFView class] forMIMEType:mimeType];
 #endif
 
-#if USE(SYSTEM_PREVIEW) && USE(APPLE_INTERNAL_SDK)
+#if USE(SYSTEM_PREVIEW)
     if (configuration._systemPreviewEnabled) {
-        for (auto& mimeType : WebKit::getSystemPreviewMIMETypes())
+        for (auto& mimeType : WebCore::MIMETypeRegistry::getSystemPreviewMIMETypes())
             [self registerProvider:[WKSystemPreviewView class] forMIMEType:mimeType];
     }
 #endif
index c7212dc..b8bbf2b 100644 (file)
 #if USE(SYSTEM_PREVIEW)
 
 #include "WebPageProxy.h"
-
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/SystemPreviewTypes.cpp>
-#endif
+#include <WebCore/MIMETypeRegistry.h>
 
 namespace WebKit {
 
@@ -43,12 +40,7 @@ SystemPreviewController::SystemPreviewController(WebPageProxy& webPageProxy)
 
 bool SystemPreviewController::canPreview(const String& mimeType) const
 {
-#if USE(APPLE_INTERNAL_SDK)
-    return canShowSystemPreviewForMIMEType(mimeType);
-#else
-    UNUSED_PARAM(mimeType);
-    return false;
-#endif
+    return WebCore::MIMETypeRegistry::isSystemPreviewMIMEType(mimeType);
 }
 
 }
index 94d6264..b8a5405 100644 (file)
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <WebCore/FloatRect.h>
 #import <WebCore/LocalizedStrings.h>
+#import <WebCore/MIMETypeRegistry.h>
 #import <pal/spi/cg/CoreGraphicsSPI.h>
 #import <pal/spi/ios/SystemPreviewSPI.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/SoftLinking.h>
 #import <wtf/Vector.h>
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/SystemPreviewTypes.cpp>
-#endif
-
 SOFT_LINK_FRAMEWORK(QuickLook);
 SOFT_LINK_CLASS(QuickLook, QLItem);
 
 SOFT_LINK_PRIVATE_FRAMEWORK(AssetViewer);
 SOFT_LINK_CLASS(AssetViewer, ASVThumbnailView);
 
+// FIXME: At the moment we only have one supported UTI, but
+// if we start supporting more types, then we'll need a table.
+static String getUTIForMIMEType(const String& mimeType)
+{
+    static const NeverDestroyed<String> uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, CFSTR("usdz"), nil)).get();
+
+    if (!WebCore::MIMETypeRegistry::isSystemPreviewMIMEType(mimeType))
+        return emptyString();
+
+    return uti;
+}
+
 @interface WKSystemPreviewView () <ASVThumbnailViewDelegate>
 @end
 
@@ -95,13 +104,7 @@ SOFT_LINK_CLASS(AssetViewer, ASVThumbnailView);
     _data = adoptNS([data copy]);
 
     NSString *contentType;
-#if USE(APPLE_INTERNAL_SDK)
-    contentType = WebKit::getUTIForMIMEType(_mimeType.get());
-#else
-    NSString *extension = [[_suggestedFilename.get() pathExtension] lowercaseString];
-    RetainPtr<CFStringRef> contentTypeCF = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, nil));
-    contentType = (NSString *)contentTypeCF.get();
-#endif
+    contentType = getUTIForMIMEType(_mimeType.get());
 
     _item = adoptNS([allocQLItemInstance() initWithDataProvider:self contentType:contentType previewTitle:_suggestedFilename.get()]);
     [_item setUseLoadingTimeout:NO];