WebKit Bugzilla
Attachment 348796 Details for
Bug 189252
: Move SystemPreview code from WebKitAdditions to WebKit
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189252-20180904095904.patch (text/plain), 17.93 KB, created by
Dean Jackson
on 2018-09-03 16:59:06 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Dean Jackson
Created:
2018-09-03 16:59:06 PDT
Size:
17.93 KB
patch
obsolete
>Subversion Revision: 235601 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 52544211ce30a096636aa4bf5f737b6efc01acb4..281d45046751f70220a81bc7866d5bd5d10afdd8 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,30 @@ >+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 NOBODY (OOPS!). >+ >+ 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): >+ > 2018-09-03 Andy Estes <aestes@apple.com> > > [Payment Request] Implement the MerchantValidationEvent constructor >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index a4397d2fd644ffd11e207a299e4392c493217a05..263521e427ecbb1499a336437dd981c3b17c863b 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -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 NOBODY (OOPS!). >+ >+ 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-01 Darin Adler <darin@apple.com> > > [CFNetwork] Update CFNetwork SPI use to use CFNetworkSPI.h more consistently >diff --git a/Source/WebCore/html/HTMLAnchorElement.cpp b/Source/WebCore/html/HTMLAnchorElement.cpp >index c310cf23e7ad0a58520f0eb7d90306875a9c1960..27c0a0d23a7f05781ee402b3e1176a59c2d949b7 100644 >--- a/Source/WebCore/html/HTMLAnchorElement.cpp >+++ b/Source/WebCore/html/HTMLAnchorElement.cpp >@@ -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,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; > } > } >diff --git a/Source/WebCore/platform/MIMETypeRegistry.cpp b/Source/WebCore/platform/MIMETypeRegistry.cpp >index 76c63b76184bf76eb0ab07fe103bb6889646001a..829bf0de31f2fdd98e609868cedb443ed3d73993 100644 >--- a/Source/WebCore/platform/MIMETypeRegistry.cpp >+++ b/Source/WebCore/platform/MIMETypeRegistry.cpp >@@ -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 >diff --git a/Source/WebCore/platform/MIMETypeRegistry.h b/Source/WebCore/platform/MIMETypeRegistry.h >index 9244973e1ddf4ad2a0b35d594d4567fa293140e0..8d5a0ddc5c9464c0e55869b11c2db237fac4c3f7 100644 >--- a/Source/WebCore/platform/MIMETypeRegistry.h >+++ b/Source/WebCore/platform/MIMETypeRegistry.h >@@ -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&); >diff --git a/Source/WebCore/rendering/RenderThemeIOS.mm b/Source/WebCore/rendering/RenderThemeIOS.mm >index b862734126fbd1d53ede25f9f1381cdd62c4417a..27378821e66970fbbb49441395adaa534895b38a 100644 >--- a/Source/WebCore/rendering/RenderThemeIOS.mm >+++ b/Source/WebCore/rendering/RenderThemeIOS.mm >@@ -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 @@ 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); >diff --git a/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm b/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm >index dfc828eaeb9afa87ab77e9c2627ce9d309a07600..eb4af1df3feef0ed275d092eb8adbe3246a8b37d 100644 >--- a/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm >+++ b/Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm >@@ -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 @@ 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]; > >diff --git a/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm b/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm >index 6a5df4c04576256d3c47856d3db53fb2b8eedaed..23e373c22c88824a23fb00bb32f3f942879cb4aa 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm >+++ b/Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm >@@ -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 >diff --git a/Source/WebKit/UIProcess/SystemPreviewController.cpp b/Source/WebKit/UIProcess/SystemPreviewController.cpp >index c7212dc7d0ea578988308d8cb087def9d05611a9..b8bbf2b7aa05357e843e30a49ed6152596b5ce29 100644 >--- a/Source/WebKit/UIProcess/SystemPreviewController.cpp >+++ b/Source/WebKit/UIProcess/SystemPreviewController.cpp >@@ -29,10 +29,7 @@ > #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); > } > > } >diff --git a/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm b/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm >index 94d6264dc838c6a3f171a6e3ac5c2f189e132cfa..b8a540544868bdb42d093f83b2e33085f00d27cf 100644 >--- a/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm >+++ b/Source/WebKit/UIProcess/ios/WKSystemPreviewView.mm >@@ -35,22 +35,31 @@ > #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];
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
wenson_hsieh
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189252
: 348796