Diff
Modified: trunk/LayoutTests/ChangeLog (235625 => 235626)
--- trunk/LayoutTests/ChangeLog 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/LayoutTests/ChangeLog 2018-09-04 19:38:33 UTC (rev 235626)
@@ -1,3 +1,15 @@
+2018-09-03 Dean Jackson <[email protected]>
+
+ 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 <[email protected]>
[Modern Media Controls] Disabling both fullscreen and picture-in-picture shows an empty top left container
Modified: trunk/LayoutTests/system-preview/detection.html (235625 => 235626)
--- trunk/LayoutTests/system-preview/detection.html 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/LayoutTests/system-preview/detection.html 2018-09-04 19:38:33 UTC (rev 235626)
@@ -25,15 +25,11 @@
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 @@
<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 @@
<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 @@
<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 @@
<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 @@
<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 @@
<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 @@
<div id="invalid-4">
<p>Invalid system preview (no children)</p>
-<a href="" rel="">
+<a href="" rel="ar">
</a>
<p>Result: </p>
</div>
Modified: trunk/Source/WebCore/ChangeLog (235625 => 235626)
--- trunk/Source/WebCore/ChangeLog 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/ChangeLog 2018-09-04 19:38:33 UTC (rev 235626)
@@ -1,3 +1,35 @@
+2018-09-03 Dean Jackson <[email protected]>
+
+ 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 <[email protected]>
[Payment Request] PaymentResponse should have an onpayerdetailchange event handler
Modified: trunk/Source/WebCore/html/HTMLAnchorElement.cpp (235625 => 235626)
--- trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2018-09-04 19:38:33 UTC (rev 235626)
@@ -53,10 +53,6 @@
#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,13 +310,8 @@
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();
+ return equalIgnoringASCIICase(token, "noreferrer") || equalIgnoringASCIICase(token, "noopener") || equalIgnoringASCIICase(token, "ar");
#else
- auto systemPreviewRelValue = "system-preview"_s;
-#endif
- return equalIgnoringASCIICase(token, "noreferrer") || equalIgnoringASCIICase(token, "noopener") || equalIgnoringASCIICase(token, systemPreviewRelValue);
-#else
return equalIgnoringASCIICase(token, "noreferrer") || equalIgnoringASCIICase(token, "noopener");
#endif
});
@@ -383,11 +374,7 @@
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 @@
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;
}
}
Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (235625 => 235626)
--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp 2018-09-04 19:38:33 UTC (rev 235626)
@@ -64,6 +64,10 @@
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 @@
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
Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.h (235625 => 235626)
--- trunk/Source/WebCore/platform/MIMETypeRegistry.h 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.h 2018-09-04 19:38:33 UTC (rev 235626)
@@ -88,6 +88,10 @@
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 @@
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&);
Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (235625 => 235626)
--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm 2018-09-04 19:38:33 UTC (rev 235626)
@@ -77,10 +77,6 @@
#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 @@
#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 = "" 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 @@
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 @@
CGContextScaleCTM(ctx, scaleX, scaleY);
CGContextDrawPDFPage(ctx, logo);
}
-#endif
CGContextFlush(ctx);
CGContextRestoreGState(ctx);
Modified: trunk/Source/WebCore/testing/Internals.cpp (235625 => 235626)
--- trunk/Source/WebCore/testing/Internals.cpp 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/testing/Internals.cpp 2018-09-04 19:38:33 UTC (rev 235626)
@@ -4626,15 +4626,6 @@
}
#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)
Modified: trunk/Source/WebCore/testing/Internals.h (235625 => 235626)
--- trunk/Source/WebCore/testing/Internals.h 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/testing/Internals.h 2018-09-04 19:38:33 UTC (rev 235626)
@@ -700,7 +700,6 @@
MockCredentialsMessenger& mockCredentialsMessenger() const;
#endif
- String systemPreviewRelType();
bool isSystemPreviewLink(Element&) const;
bool isSystemPreviewImage(Element&) const;
Modified: trunk/Source/WebCore/testing/Internals.idl (235625 => 235626)
--- trunk/Source/WebCore/testing/Internals.idl 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebCore/testing/Internals.idl 2018-09-04 19:38:33 UTC (rev 235626)
@@ -648,7 +648,6 @@
[Conditional=APPLE_PAY] readonly attribute MockPaymentCoordinator mockPaymentCoordinator;
[Conditional=WEB_AUTHN] readonly attribute MockCredentialsMessenger mockCredentialsMessenger;
- DOMString systemPreviewRelType();
boolean isSystemPreviewLink(Element element);
boolean isSystemPreviewImage(Element element);
Modified: trunk/Source/WebKit/ChangeLog (235625 => 235626)
--- trunk/Source/WebKit/ChangeLog 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebKit/ChangeLog 2018-09-04 19:38:33 UTC (rev 235626)
@@ -1,3 +1,28 @@
+2018-09-03 Dean Jackson <[email protected]>
+
+ 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 <[email protected]>
Bug 189190 - REGRESSION(r235398) ASSERTION failure !m_client.didFinishDocumentLoadForFrame
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm (235625 => 235626)
--- trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm 2018-09-04 19:38:33 UTC (rev 235626)
@@ -33,18 +33,27 @@
#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 @@
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];
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm (235625 => 235626)
--- trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm 2018-09-04 19:38:33 UTC (rev 235626)
@@ -42,10 +42,6 @@
#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
Modified: trunk/Source/WebKit/UIProcess/SystemPreviewController.cpp (235625 => 235626)
--- trunk/Source/WebKit/UIProcess/SystemPreviewController.cpp 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebKit/UIProcess/SystemPreviewController.cpp 2018-09-04 19:38:33 UTC (rev 235626)
@@ -29,11 +29,8 @@
#if USE(SYSTEM_PREVIEW)
#include "WebPageProxy.h"
+#include <WebCore/MIMETypeRegistry.h>
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/SystemPreviewTypes.cpp>
-#endif
-
namespace WebKit {
SystemPreviewController::SystemPreviewController(WebPageProxy& webPageProxy)
@@ -43,12 +40,7 @@
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);
}
}
Modified: trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm (235625 => 235626)
--- trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm 2018-09-04 19:14:23 UTC (rev 235625)
+++ trunk/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm 2018-09-04 19:38:33 UTC (rev 235626)
@@ -35,6 +35,7 @@
#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>
@@ -41,10 +42,6 @@
#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);
@@ -51,6 +48,18 @@
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 @@
_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];