Title: [211355] trunk
Revision
211355
Author
aes...@apple.com
Date
2017-01-29 17:40:29 -0800 (Sun, 29 Jan 2017)

Log Message

[QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
https://bugs.webkit.org/show_bug.cgi?id=167563
<rdar://problem/30253207>

Reviewed by Andreas Kling.

Source/WebCore:

* loader/ios/QuickLook.h: Removed unused declarations.
(WebCore::QuickLookHandle::firstRequestURL): Deleted.
* loader/ios/QuickLook.mm:
(WebCore::removeQLPreviewConverterForURL): Stopped deleting the temporary file here; that's
now done in QuickLookDocumentWriter.
(addQLPreviewConverterWithFileForURL): Changed from an exported function to a static
function since it's now only called inside QuickLook.mm.
(WebCore::QuickLookHandle::QuickLookHandle): Stopped initializing m_firstRequestURL.
(WebCore::addQLPreviewConverterWithFileForURL): Deleted.
(WebCore::qlPreviewConverterFileNameForURL): Deleted.
(WebCore::qlPreviewConverterUTIForURL): Deleted.
(WebCore::QuickLookHandle::previewRequestURL): Deleted.
(WebCore::QuickLookHandle::converter): Deleted.

Source/WebKit/mac:

Instead of only saving QuickLook documents to a temporary file when the client is
MobileSafari, base this decision on a WebPreference that clients can choose to enable.

This also changes the SPI for accessing the temporary file path and UTI. Instead of
-[WebView quickLookContentForURL:], which requires the client to pass the response URL of
the frame that saved the QuickLook document, the content dictionary is now stored as a
property of WebDataSource.

This also removes the manual lifetime management of the QLPreviewConverter from
QuickLookDocumentWriter. The QLPreviewConverter is kept alive by DocumentLoader these days,
which ensures it lives long enough to respond to subresource requests.

New API test: QuickLook.LegacyQuickLookContent

* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::didCreateQuickLookHandle): Moved the logic of deciding whether to
write a temporary file to here from the QuickLookDocumentWriter constructor.
* WebView/WebDataSource.mm: Declared _quickLookContent.
(-[WebDataSource _quickLookContent]):
(-[WebDataSource _setQuickLookContent:]):
* WebView/WebDataSourceInternal.h: Overrode _quickLookContent as a read/write property.
* WebView/WebDataSourcePrivate.h: Declared _quickLookContent as a readonly property.
* WebView/WebPreferenceKeysPrivate.h: Defined WebKitQuickLookDocumentSavingPreferenceKey.
* WebView/WebPreferences.mm:
(-[WebPreferences quickLookDocumentSavingEnabled]):
(-[WebPreferences setQuickLookDocumentSavingEnabled:]):
* WebView/WebPreferencesPrivate.h: Declared property quickLookDocumentSavingEnabled.
* WebView/WebView.mm:
(-[WebView quickLookContentForURL:]): Changed to always return nil.
* WebView/WebViewPrivate.h: Added a comment stating that clients should use
-[WebDataSource _quickLookContent] instead.

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm:
(-[QuickLookNavigationDelegate _webView:didStartLoadForQuickLookDocumentInMainFrameWithFileName:uti:]):
(-[QuickLookNavigationDelegate _webView:didFinishLoadForQuickLookDocumentInMainFrame:]):
(runTest):
(-[QuickLookFrameLoadDelegate webView:didFinishLoadForFrame:]):
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (211354 => 211355)


--- trunk/Source/WebCore/ChangeLog	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebCore/ChangeLog	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,3 +1,25 @@
+2017-01-29  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
+        https://bugs.webkit.org/show_bug.cgi?id=167563
+        <rdar://problem/30253207>
+
+        Reviewed by Andreas Kling.
+
+        * loader/ios/QuickLook.h: Removed unused declarations.
+        (WebCore::QuickLookHandle::firstRequestURL): Deleted.
+        * loader/ios/QuickLook.mm:
+        (WebCore::removeQLPreviewConverterForURL): Stopped deleting the temporary file here; that's
+        now done in QuickLookDocumentWriter.
+        (addQLPreviewConverterWithFileForURL): Changed from an exported function to a static
+        function since it's now only called inside QuickLook.mm.
+        (WebCore::QuickLookHandle::QuickLookHandle): Stopped initializing m_firstRequestURL.
+        (WebCore::addQLPreviewConverterWithFileForURL): Deleted.
+        (WebCore::qlPreviewConverterFileNameForURL): Deleted.
+        (WebCore::qlPreviewConverterUTIForURL): Deleted.
+        (WebCore::QuickLookHandle::previewRequestURL): Deleted.
+        (WebCore::QuickLookHandle::converter): Deleted.
+
 2017-01-29  Zalan Bujtas  <za...@apple.com>
 
         Simple line layout: PerformanceTests/Layout/simple-line-layout-innertext.html regressed at r211108

Modified: trunk/Source/WebCore/loader/ios/QuickLook.h (211354 => 211355)


--- trunk/Source/WebCore/loader/ios/QuickLook.h	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebCore/loader/ios/QuickLook.h	2017-01-30 01:40:29 UTC (rev 211355)
@@ -31,15 +31,11 @@
 #include <wtf/Forward.h>
 #include <wtf/RetainPtr.h>
 
-OBJC_CLASS NSArray;
 OBJC_CLASS NSData;
-OBJC_CLASS NSDictionary;
 OBJC_CLASS NSSet;
 OBJC_CLASS NSString;
 OBJC_CLASS NSURL;
 OBJC_CLASS NSURLRequest;
-OBJC_CLASS NSURLResponse;
-OBJC_CLASS QLPreviewConverter;
 OBJC_CLASS WebPreviewConverter;
 
 namespace WebCore {
@@ -49,19 +45,11 @@
 class ResourceRequest;
 class ResourceResponse;
 class SharedBuffer;
-class URL;
 
 WEBCORE_EXPORT NSSet *QLPreviewGetSupportedMIMETypesSet();
-
-WEBCORE_EXPORT void addQLPreviewConverterWithFileForURL(NSURL *, id converter, NSString *fileName);
-WEBCORE_EXPORT NSString *qlPreviewConverterFileNameForURL(NSURL *);
-WEBCORE_EXPORT NSString *qlPreviewConverterUTIForURL(NSURL *);
 WEBCORE_EXPORT void removeQLPreviewConverterForURL(NSURL *);
-
 WEBCORE_EXPORT RetainPtr<NSURLRequest> registerQLPreviewConverterIfNeeded(NSURL *, NSString *mimeType, NSData *);
-
 WEBCORE_EXPORT const char* QLPreviewProtocol();
-
 WEBCORE_EXPORT NSString *createTemporaryFileForQuickLook(NSString *fileName);
 
 class QuickLookHandle {
@@ -82,15 +70,11 @@
 
     WEBCORE_EXPORT String previewFileName() const;
     WEBCORE_EXPORT String previewUTI() const;
-    WEBCORE_EXPORT NSURL *previewRequestURL() const;
-    WEBCORE_EXPORT QLPreviewConverter *converter() const;
-    NSURL *firstRequestURL() const { return m_firstRequestURL.get(); }
 
 private:
     friend std::unique_ptr<QuickLookHandle> std::make_unique<QuickLookHandle>(ResourceLoader&, const ResourceResponse&);
     QuickLookHandle(ResourceLoader&, const ResourceResponse&);
 
-    RetainPtr<NSURL> m_firstRequestURL;
     RetainPtr<WebPreviewConverter> m_converter;
     bool m_finishedLoadingDataIntoConverter { false };
 };

Modified: trunk/Source/WebCore/loader/ios/QuickLook.mm (211354 => 211355)


--- trunk/Source/WebCore/loader/ios/QuickLook.mm	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebCore/loader/ios/QuickLook.mm	2017-01-30 01:40:29 UTC (rev 211355)
@@ -68,8 +68,15 @@
     return contentDictionary;
 }
 
-void WebCore::addQLPreviewConverterWithFileForURL(NSURL *url, id converter, NSString *fileName)
+void WebCore::removeQLPreviewConverterForURL(NSURL *url)
 {
+    LockHolder lock(qlPreviewConverterDictionaryMutex());
+    [QLPreviewConverterDictionary() removeObjectForKey:url];
+    [QLContentDictionary() removeObjectForKey:url];
+}
+
+static void addQLPreviewConverterWithFileForURL(NSURL *url, id converter, NSString *fileName)
+{
     ASSERT(url);
     ASSERT(converter);
     LockHolder lock(qlPreviewConverterDictionaryMutex());
@@ -77,35 +84,6 @@
     [QLContentDictionary() setObject:(fileName ? fileName : @"") forKey:url];
 }
 
-NSString *WebCore::qlPreviewConverterFileNameForURL(NSURL *url)
-{
-    return [QLContentDictionary() objectForKey:url];
-}
-
-NSString *WebCore::qlPreviewConverterUTIForURL(NSURL *url)
-{
-    id converter = nil;
-    {
-        LockHolder lock(qlPreviewConverterDictionaryMutex());
-        converter = [QLPreviewConverterDictionary() objectForKey:url];
-    }
-    if (!converter)
-        return nil;
-    return [converter previewUTI];
-}
-
-void WebCore::removeQLPreviewConverterForURL(NSURL *url)
-{
-    LockHolder lock(qlPreviewConverterDictionaryMutex());
-    [QLPreviewConverterDictionary() removeObjectForKey:url];
-
-    // Delete the file when we remove the preview converter
-    NSString *filename = qlPreviewConverterFileNameForURL(url);
-    if ([filename length])
-        [[NSFileManager defaultManager] _web_removeFileOnlyAtPath:filename];
-    [QLContentDictionary() removeObjectForKey:url];
-}
-
 RetainPtr<NSURLRequest> WebCore::registerQLPreviewConverterIfNeeded(NSURL *url, NSString *mimeType, NSData *data)
 {
     RetainPtr<NSString> updatedMIMEType = adoptNS(QLTypeCopyBestMimeTypeForURLAndMimeType(url, mimeType));
@@ -340,8 +318,7 @@
 }
 
 QuickLookHandle::QuickLookHandle(ResourceLoader& loader, const ResourceResponse& response)
-    : m_firstRequestURL { loader.originalRequest().nsURLRequest(DoNotUpdateHTTPBody).URL }
-    , m_converter { adoptNS([[WebPreviewConverter alloc] initWithResourceLoader:loader resourceResponse:response quickLookHandle:*this]) }
+    : m_converter { adoptNS([[WebPreviewConverter alloc] initWithResourceLoader:loader resourceResponse:response quickLookHandle:*this]) }
 {
     loader.didCreateQuickLookHandle(*this);
 }
@@ -421,16 +398,6 @@
     return [m_converter platformConverter].previewUTI;
 }
 
-NSURL *QuickLookHandle::previewRequestURL() const
-{
-    return [m_converter platformConverter].previewRequest.URL;
 }
 
-QLPreviewConverter *QuickLookHandle::converter() const
-{
-    return [m_converter platformConverter];
-}
-
-}
-
 #endif // USE(QUICK_LOOK)

Modified: trunk/Source/WebKit/mac/ChangeLog (211354 => 211355)


--- trunk/Source/WebKit/mac/ChangeLog	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/ChangeLog	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,3 +1,43 @@
+2017-01-29  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
+        https://bugs.webkit.org/show_bug.cgi?id=167563
+        <rdar://problem/30253207>
+
+        Reviewed by Andreas Kling.
+
+        Instead of only saving QuickLook documents to a temporary file when the client is
+        MobileSafari, base this decision on a WebPreference that clients can choose to enable.
+
+        This also changes the SPI for accessing the temporary file path and UTI. Instead of
+        -[WebView quickLookContentForURL:], which requires the client to pass the response URL of
+        the frame that saved the QuickLook document, the content dictionary is now stored as a
+        property of WebDataSource.
+
+        This also removes the manual lifetime management of the QLPreviewConverter from
+        QuickLookDocumentWriter. The QLPreviewConverter is kept alive by DocumentLoader these days,
+        which ensures it lives long enough to respond to subresource requests.
+
+        New API test: QuickLook.LegacyQuickLookContent
+
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::didCreateQuickLookHandle): Moved the logic of deciding whether to
+        write a temporary file to here from the QuickLookDocumentWriter constructor.
+        * WebView/WebDataSource.mm: Declared _quickLookContent.
+        (-[WebDataSource _quickLookContent]):
+        (-[WebDataSource _setQuickLookContent:]):
+        * WebView/WebDataSourceInternal.h: Overrode _quickLookContent as a read/write property.
+        * WebView/WebDataSourcePrivate.h: Declared _quickLookContent as a readonly property.
+        * WebView/WebPreferenceKeysPrivate.h: Defined WebKitQuickLookDocumentSavingPreferenceKey.
+        * WebView/WebPreferences.mm:
+        (-[WebPreferences quickLookDocumentSavingEnabled]):
+        (-[WebPreferences setQuickLookDocumentSavingEnabled:]):
+        * WebView/WebPreferencesPrivate.h: Declared property quickLookDocumentSavingEnabled.
+        * WebView/WebView.mm:
+        (-[WebView quickLookContentForURL:]): Changed to always return nil.
+        * WebView/WebViewPrivate.h: Added a comment stating that clients should use
+        -[WebDataSource _quickLookContent] instead.
+
 2017-01-28  Yoav Weiss  <y...@yoav.ws>
 
         Add Link Preload as an off-by-default experimental feature menu item.

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm (211354 => 211355)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2017-01-30 01:40:29 UTC (rev 211355)
@@ -149,7 +149,6 @@
 #endif
 
 #if USE(QUICK_LOOK)
-#import <WebCore/FileSystemIOS.h>
 #import <WebCore/NSFileManagerSPI.h>
 #import <WebCore/QuickLook.h>
 #import <WebCore/QuickLookHandleClient.h>
@@ -2230,43 +2229,26 @@
 {
     class QuickLookDocumentWriter : public WebCore::QuickLookHandleClient {
     public:
-        explicit QuickLookDocumentWriter(const WebCore::QuickLookHandle& handle)
-            : m_firstRequestURL(handle.firstRequestURL())
+        explicit QuickLookDocumentWriter(NSString *filePath)
+            : m_filePath { filePath }
+            , m_fileHandle { [NSFileHandle fileHandleForWritingAtPath:filePath] }
         {
-            NSURL *previewRequestURL = handle.previewRequestURL();
-            if (!IOSApplication::isMobileSafari()) {
-                // This keeps the QLPreviewConverter alive to serve any subresource requests.
-                // It is removed by -[WebDataSource dealloc].
-                addQLPreviewConverterWithFileForURL(previewRequestURL, handle.converter(), nil);
-                return;
-            }
-
-            // QuickLook consumes the incoming data, we need to store it so that it can be opened in the handling application.
-            NSString *quicklookContentPath = createTemporaryFileForQuickLook(handle.previewFileName());
-
-            if (quicklookContentPath) {
-                m_fileHandle = [NSFileHandle fileHandleForWritingAtPath:quicklookContentPath];
-                // previewRequestURL should match the URL removed from -[WebDataSource dealloc].
-                addQLPreviewConverterWithFileForURL(previewRequestURL, handle.converter(), quicklookContentPath);
-            }
+            ASSERT(filePath.length);
         }
 
-        virtual ~QuickLookDocumentWriter()
+        ~QuickLookDocumentWriter()
         {
-            if (m_fileHandle)
-                removeQLPreviewConverterForURL(m_firstRequestURL.get());
+            [[NSFileManager defaultManager] _web_removeFileOnlyAtPath:m_filePath.get()];
         }
 
     private:
+        RetainPtr<NSString> m_filePath;
         RetainPtr<NSFileHandle> m_fileHandle;
-        RetainPtr<NSURL> m_firstRequestURL;
 
         void didReceiveDataArray(CFArrayRef dataArray) override
         {
-            if (m_fileHandle) {
-                for (NSData *data in (NSArray *)dataArray)
-                    [m_fileHandle writeData:data];
-            }
+            for (NSData *data in (NSArray *)dataArray)
+                [m_fileHandle writeData:data];
         }
 
         void didFinishLoading() override
@@ -2276,12 +2258,19 @@
 
         void didFail() override
         {
-            m_fileHandle = nil;
-            // removeQLPreviewConverterForURL deletes the temporary file created.
-            removeQLPreviewConverterForURL(m_firstRequestURL.get());
+            [m_fileHandle closeFile];
         }
     };
-    handle.setClient(adoptRef(*new QuickLookDocumentWriter(handle)));
+
+    if (![m_webFrame webView].preferences.quickLookDocumentSavingEnabled)
+        return;
+
+    NSString *filePath = createTemporaryFileForQuickLook(handle.previewFileName());
+    if (!filePath)
+        return;
+
+    [m_webFrame provisionalDataSource]._quickLookContent = @{ WebQuickLookFileNameKey : filePath, WebQuickLookUTIKey : handle.previewUTI() };
+    handle.setClient(adoptRef(*new QuickLookDocumentWriter(filePath)));
 }
 #endif
 

Modified: trunk/Source/WebKit/mac/WebView/WebDataSource.mm (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebDataSource.mm	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebDataSource.mm	2017-01-30 01:40:29 UTC (rev 211355)
@@ -109,6 +109,9 @@
 #if PLATFORM(IOS)
     NSObject<WebDataSourcePrivateDelegate> *_dataSourceDelegate;
 #endif
+#if USE(QUICK_LOOK)
+    RetainPtr<NSDictionary> _quickLookContent;
+#endif
 };
 
 static inline WebDataSourcePrivate* toPrivate(void* privateAttribute)
@@ -225,6 +228,17 @@
     return nullptr;
 }
 
+#if PLATFORM(IOS)
+- (NSDictionary *)_quickLookContent
+{
+#if USE(QUICK_LOOK)
+    return toPrivate(_private)->_quickLookContent.get();
+#else
+    return nil;
+#endif
+}
+#endif
+
 @end
 
 @implementation WebDataSource (WebInternal)
@@ -410,6 +424,13 @@
     return self;
 }
 
+#if USE(QUICK_LOOK)
+- (void)_setQuickLookContent:(NSDictionary *)quickLookContent
+{
+    toPrivate(_private)->_quickLookContent = adoptNS([quickLookContent copy]);
+}
+#endif
+
 @end
 
 @implementation WebDataSource

Modified: trunk/Source/WebKit/mac/WebView/WebDataSourceInternal.h (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebDataSourceInternal.h	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebDataSourceInternal.h	2017-01-30 01:40:29 UTC (rev 211355)
@@ -57,4 +57,7 @@
 - (void)_revertToProvisionalState;
 - (void)_setMainDocumentError:(NSError *)error;
 - (WebCore::DocumentLoader*)_documentLoader;
+#if USE(QUICK_LOOK)
+@property (nonatomic, copy, setter=_setQuickLookContent:) NSDictionary *_quickLookContent;
+#endif
 @end

Modified: trunk/Source/WebKit/mac/WebView/WebDataSourcePrivate.h (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebDataSourcePrivate.h	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebDataSourcePrivate.h	2017-01-30 01:40:29 UTC (rev 211355)
@@ -52,4 +52,8 @@
 - (void)setDataSourceDelegate:(NSObject<WebDataSourcePrivateDelegate> *)dataSourceDelegate;
 - (NSObject<WebDataSourcePrivateDelegate> *)dataSourceDelegate;
 
+#if TARGET_OS_IPHONE
+@property (nonatomic, readonly) NSDictionary *_quickLookContent;
+#endif
+
 @end

Modified: trunk/Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2016 Apple Inc.  All rights reserved.
+ * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -215,6 +215,7 @@
 #define WebKitPasswordEchoDurationPreferenceKey @"WebKitPasswordEchoDurationPreferenceKey"
 #define WebKitNetworkDataUsageTrackingEnabledPreferenceKey @"WebKitNetworkDataUsageTrackingEnabledPreferenceKey"
 #define WebKitNetworkInterfaceNamePreferenceKey @"WebKitNetworkInterfaceNamePreferenceKey"
+#define WebKitQuickLookDocumentSavingPreferenceKey @"WebKitQuickLookDocumentSavingPreferenceKey"
 #endif
 
 #define WebKitEnableInheritURIQueryComponentPreferenceKey @"WebKitEnableInheritURIQueryComponent"

Modified: trunk/Source/WebKit/mac/WebView/WebPreferences.mm (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebPreferences.mm	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebPreferences.mm	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
  *           (C) 2006 Graham Dennis (graham.den...@gmail.com)
  *
  * Redistribution and use in source and binary forms, with or without
@@ -2945,6 +2945,18 @@
     [self _setBoolValue:flag forKey:WebKitUserTimingEnabledPreferenceKey];
 }
 
+#if PLATFORM(IOS)
+- (BOOL)quickLookDocumentSavingEnabled
+{
+    return [self _boolValueForKey:WebKitQuickLookDocumentSavingPreferenceKey];
+}
+
+- (void)setQuickLookDocumentSavingEnabled:(BOOL)flag
+{
+    [self _setBoolValue:flag forKey:WebKitQuickLookDocumentSavingPreferenceKey];
+}
+#endif
+
 @end
 
 @implementation WebPreferences (WebInternal)

Modified: trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2016 Apple Inc.  All rights reserved.
+ * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -531,4 +531,8 @@
 @property (nonatomic) BOOL userTimingEnabled;
 @property (nonatomic) BOOL linkPreloadEnabled;
 
+#if TARGET_OS_IPHONE
+@property (nonatomic) BOOL quickLookDocumentSavingEnabled;
+#endif
+
 @end

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2017 Apple Inc. All rights reserved.
  * Copyright (C) 2006 David Smith (catfish....@gmail.com)
  * Copyright (C) 2010 Igalia S.L
  *
@@ -4030,19 +4030,7 @@
 #if PLATFORM(IOS)
 - (NSDictionary *)quickLookContentForURL:(NSURL *)url
 {
-#if USE(QUICK_LOOK)
-    NSString *uti = qlPreviewConverterUTIForURL(url);
-    if (!uti)
-        return nil;
-
-    NSString *fileName = qlPreviewConverterFileNameForURL(url);
-    if (!fileName)
-        return nil;
-
-    return [NSDictionary dictionaryWithObjectsAndKeys: fileName, WebQuickLookFileNameKey, uti, WebQuickLookUTIKey, nil];
-#else
     return nil;
-#endif
 }
 
 - (BOOL)_isStopping

Modified: trunk/Source/WebKit/mac/WebView/WebViewPrivate.h (211354 => 211355)


--- trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2017-01-30 01:40:29 UTC (rev 211355)
@@ -462,6 +462,7 @@
 #endif // PLATFORM(IOS)
 
 #if TARGET_OS_IPHONE
+// Deprecated. Use -[WebDataSource _quickLookContent] instead.
 - (NSDictionary *)quickLookContentForURL:(NSURL *)url;
 #endif
 

Modified: trunk/Tools/ChangeLog (211354 => 211355)


--- trunk/Tools/ChangeLog	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Tools/ChangeLog	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,3 +1,18 @@
+2017-01-29  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] Add a WebPreference to enable saving QuickLook documents in WebKitLegacy
+        https://bugs.webkit.org/show_bug.cgi?id=167563
+        <rdar://problem/30253207>
+
+        Reviewed by Andreas Kling.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm:
+        (-[QuickLookNavigationDelegate _webView:didStartLoadForQuickLookDocumentInMainFrameWithFileName:uti:]):
+        (-[QuickLookNavigationDelegate _webView:didFinishLoadForQuickLookDocumentInMainFrame:]):
+        (runTest):
+        (-[QuickLookFrameLoadDelegate webView:didFinishLoadForFrame:]):
+        (TEST):
+
 2017-01-29  Dan Bernstein  <m...@apple.com>
 
         [iOS] Expose WebCore::DataDetection::detectContentInRange WKWebProcessPlugInRangeHandle

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm (211354 => 211355)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm	2017-01-30 00:26:36 UTC (rev 211354)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm	2017-01-30 01:40:29 UTC (rev 211355)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,14 +28,27 @@
 #if PLATFORM(IOS)
 
 #import "PlatformUtilities.h"
+#import "Test.h"
+#import <WebCore/WebCoreThread.h>
 #import <WebKit/WKNavigationDelegatePrivate.h>
-#import <WebKit/WKWebView.h>
+#import <WebKit/WebDataSourcePrivate.h>
+#import <WebKit/WebKit.h>
+#import <WebKit/WebPreferencesPrivate.h>
+#import <WebKit/WebUIKitSupport.h>
+#import <WebKit/WebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
+using namespace TestWebKitAPI;
+
 static bool isDone;
 static bool didStartQuickLookLoad;
 static bool didFinishQuickLookLoad;
 
+static const NSUInteger expectedFileSize = 274143;
+static NSString * const expectedFileName = @"pages.pages";
+static NSString * const expectedUTI = @"com.apple.iwork.pages.sffpages";
+static NSURLRequest * const pagesDocumentRequest = [[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"pages" withExtension:@"pages" subdirectory:@"TestWebKitAPI.resources"]] retain];
+
 @interface QuickLookNavigationDelegate : NSObject <WKNavigationDelegatePrivate>
 @end
 
@@ -43,14 +56,14 @@
 
 - (void)_webView:(WKWebView *)webView didStartLoadForQuickLookDocumentInMainFrameWithFileName:(NSString *)fileName uti:(NSString *)uti
 {
-    EXPECT_WK_STREQ(fileName, @"pages.pages");
-    EXPECT_WK_STREQ(uti, @"com.apple.iwork.pages.sffpages");
+    EXPECT_WK_STREQ(expectedFileName, fileName);
+    EXPECT_WK_STREQ(expectedUTI, uti);
     didStartQuickLookLoad = true;
 }
 
 - (void)_webView:(WKWebView *)webView didFinishLoadForQuickLookDocumentInMainFrame:(NSData *)documentData
 {
-    EXPECT_EQ(documentData.length, 274143U);
+    EXPECT_EQ(expectedFileSize, documentData.length);
     didFinishQuickLookLoad = true;
 }
 
@@ -66,10 +79,10 @@
     auto webView = adoptNS([[WKWebView alloc] init]);
     auto navigationDelegate = adoptNS([[navigationDelegateClass alloc] init]);
     [webView setNavigationDelegate:navigationDelegate.get()];
-    [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"pages" withExtension:@"pages" subdirectory:@"TestWebKitAPI.resources"]]];
+    [webView loadRequest:pagesDocumentRequest];
 
     isDone = false;
-    TestWebKitAPI::Util::run(&isDone);
+    Util::run(&isDone);
 }
 
 TEST(QuickLook, NavigationDelegate)
@@ -96,9 +109,59 @@
 
 @end
 
+@interface QuickLookFrameLoadDelegate : NSObject <WebFrameLoadDelegate>
+@end
+
+@implementation QuickLookFrameLoadDelegate
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    isDone = true;
+}
+
+@end
+
 TEST(QuickLook, CancelNavigationAfterResponse)
 {
     runTest([QuickLookDecidePolicyDelegate class]);
 }
 
+TEST(QuickLook, LegacyQuickLookContent)
+{
+    WebKitInitialize();
+    WebThreadLock();
+
+    auto webView = adoptNS([[WebView alloc] init]);
+
+    auto frameLoadDelegate = adoptNS([[QuickLookFrameLoadDelegate alloc] init]);
+    [webView setFrameLoadDelegate:frameLoadDelegate.get()];
+
+    auto webPreferences = adoptNS([[WebPreferences alloc] initWithIdentifier:@"LegacyQuickLookContent"]);
+    [webPreferences setQuickLookDocumentSavingEnabled:YES];
+    [webView setPreferences:webPreferences.get()];
+
+    WebFrame *mainFrame = [webView mainFrame];
+
+    isDone = false;
+    [mainFrame loadRequest:pagesDocumentRequest];
+    Util::run(&isDone);
+    WebThreadLock();
+
+    NSDictionary *quickLookContent = mainFrame.dataSource._quickLookContent;
+    NSString *filePath = quickLookContent[WebQuickLookFileNameKey];
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
+    EXPECT_WK_STREQ(expectedFileName, filePath.lastPathComponent);
+    EXPECT_WK_STREQ(expectedUTI, quickLookContent[WebQuickLookUTIKey]);
+
+    NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
+    EXPECT_EQ(expectedFileSize, [fileAttributes[NSFileSize] unsignedIntegerValue]);
+
+    isDone = false;
+    [mainFrame loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
+    Util::run(&isDone);
+    WebThreadLock();
+
+    EXPECT_NULL(mainFrame.dataSource._quickLookContent);
+}
+
 #endif // PLATFORM(IOS)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to