Title: [167207] trunk/Source
Revision
167207
Author
aes...@apple.com
Date
2014-04-13 19:57:33 -0700 (Sun, 13 Apr 2014)

Log Message

[QuickLook] Move file system-related code into WebKit
https://bugs.webkit.org/show_bug.cgi?id=131597

Reviewed by Dan Bernstein.

Source/WebCore:

QuickLookHandle should not be responsible for saving a copy of the
original document to disk as it might be running in a process that
either can't write to disk or can only write into a sandboxed
container. To account for this, we need to separate the concern of
quick look conversion from that of original document saving so that
each activity can run in the appropriate process.

Created a new interface between WebCore and WebKit by adding a client
(QuickLookHandleClient) to QuickLookHandle which is notified of incoming
bytes. A new function on FrameLoaderClient tells WebKit when a new
QuickLookHandle is created, giving WebKit the opportunity to register a
handle client. Moved the existing file system-related code as well as
code only needed by WebKit1 in QuickLookHandle into a new WebKit1
QuickLookHandleClient subclass.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj: Made QuickLookHandleClient.h Private.
* loader/FrameLoaderClient.h:
(WebCore::FrameLoaderClient::didCreateQuickLookHandle): Added.
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::didCreateQuickLookHandle): Called FrameLoaderClient::didCreateQuickLookHandle().
* loader/ResourceLoader.h:
* platform/network/ResourceHandle.h: Made m_quickLook a unique_ptr.
(WebCore::ResourceHandle::setQuickLookHandle): Changed to take a unique_ptr.
* platform/network/ResourceHandleClient.h:
(WebCore::ResourceHandleClient::didCreateQuickLookHandle): Added.
* platform/network/ios/QuickLook.h: Added m_client, gave m_converter a stronger type, and made m_nsResponse a RetainPtr.
(WebCore::QuickLookHandle::setClient): Added.
(WebCore::QuickLookHandle::firstRequestURL): Added.
(WebCore::QuickLookHandle::converter): Added.
* platform/network/ios/QuickLook.mm:
(WebCore::registerQLPreviewConverterIfNeeded):
(WebCore::createTemporaryFileForQuickLook): Made non-static.
(WebCore::emptyClient): Returned a shared empty QuickLookHandleClient.
(WebCore::QuickLookHandle::QuickLookHandle): Removed file system and WebKit1-only code.
(WebCore::QuickLookHandle::create): Changed to return a unique_ptr.
(WebCore::QuickLookHandle::nsResponse):
(WebCore::QuickLookHandle::didReceiveDataArray): Removed file system code and called QuickLookHandleClient::didReceiveDataArray() instead.
(WebCore::QuickLookHandle::didReceiveData): Removed file system code and called QuickLookHandleClient::didReceiveData() instead.
(WebCore::QuickLookHandle::didFinishLoading): Removed file system code and called QuickLookHandleClient::didFinishLoading() instead.
(WebCore::QuickLookHandle::didFail): Removed file system and WebKit1-only code, calling QuickLookHandleClient::didFail() instead.
(WebCore::QuickLookHandle::~QuickLookHandle): Removed file system and WebKit1-only code. Cleared our reference to m_client.
(WebCore::QuickLookHandle::previewFileName): Retrieved from m_converter.
(WebCore::QuickLookHandle::previewRequestURL): Ditto.
* platform/network/ios/QuickLookHandleClient.h: Added.
(WebCore::QuickLookHandleClient::~QuickLookHandleClient):
(WebCore::QuickLookHandleClient::didReceiveDataArray):
(WebCore::QuickLookHandleClient::didReceiveData):
(WebCore::QuickLookHandleClient::didFinishLoading):
(WebCore::QuickLookHandleClient::didFail):

Source/WebKit/mac:

Moved file system and WebKit1-only code from QuickLookHandle into a new
QuickLookHandleClient subclass.

* WebCoreSupport/WebFrameLoaderClient.h:
* WebCoreSupport/WebFrameLoaderClient.mm:

Source/WebKit2:

* WebProcess/Network/WebResourceLoader.h: Made m_quickLookHandle a unique_ptr.
* WebProcess/ios/WebResourceLoaderIOS.mm:
(WebKit::WebResourceLoader::setUpQuickLookHandleIfNeeded):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167206 => 167207)


--- trunk/Source/WebCore/ChangeLog	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/ChangeLog	2014-04-14 02:57:33 UTC (rev 167207)
@@ -1,3 +1,61 @@
+2014-04-13  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] Move file system-related code into WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=131597
+
+        Reviewed by Dan Bernstein.
+
+        QuickLookHandle should not be responsible for saving a copy of the
+        original document to disk as it might be running in a process that
+        either can't write to disk or can only write into a sandboxed
+        container. To account for this, we need to separate the concern of
+        quick look conversion from that of original document saving so that
+        each activity can run in the appropriate process.
+
+        Created a new interface between WebCore and WebKit by adding a client
+        (QuickLookHandleClient) to QuickLookHandle which is notified of incoming
+        bytes. A new function on FrameLoaderClient tells WebKit when a new
+        QuickLookHandle is created, giving WebKit the opportunity to register a
+        handle client. Moved the existing file system-related code as well as
+        code only needed by WebKit1 in QuickLookHandle into a new WebKit1
+        QuickLookHandleClient subclass.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj: Made QuickLookHandleClient.h Private.
+        * loader/FrameLoaderClient.h:
+        (WebCore::FrameLoaderClient::didCreateQuickLookHandle): Added.
+        * loader/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::didCreateQuickLookHandle): Called FrameLoaderClient::didCreateQuickLookHandle().
+        * loader/ResourceLoader.h:
+        * platform/network/ResourceHandle.h: Made m_quickLook a unique_ptr.
+        (WebCore::ResourceHandle::setQuickLookHandle): Changed to take a unique_ptr.
+        * platform/network/ResourceHandleClient.h:
+        (WebCore::ResourceHandleClient::didCreateQuickLookHandle): Added.
+        * platform/network/ios/QuickLook.h: Added m_client, gave m_converter a stronger type, and made m_nsResponse a RetainPtr.
+        (WebCore::QuickLookHandle::setClient): Added.
+        (WebCore::QuickLookHandle::firstRequestURL): Added.
+        (WebCore::QuickLookHandle::converter): Added.
+        * platform/network/ios/QuickLook.mm:
+        (WebCore::registerQLPreviewConverterIfNeeded):
+        (WebCore::createTemporaryFileForQuickLook): Made non-static.
+        (WebCore::emptyClient): Returned a shared empty QuickLookHandleClient.
+        (WebCore::QuickLookHandle::QuickLookHandle): Removed file system and WebKit1-only code.
+        (WebCore::QuickLookHandle::create): Changed to return a unique_ptr.
+        (WebCore::QuickLookHandle::nsResponse):
+        (WebCore::QuickLookHandle::didReceiveDataArray): Removed file system code and called QuickLookHandleClient::didReceiveDataArray() instead.
+        (WebCore::QuickLookHandle::didReceiveData): Removed file system code and called QuickLookHandleClient::didReceiveData() instead.
+        (WebCore::QuickLookHandle::didFinishLoading): Removed file system code and called QuickLookHandleClient::didFinishLoading() instead.
+        (WebCore::QuickLookHandle::didFail): Removed file system and WebKit1-only code, calling QuickLookHandleClient::didFail() instead.
+        (WebCore::QuickLookHandle::~QuickLookHandle): Removed file system and WebKit1-only code. Cleared our reference to m_client.
+        (WebCore::QuickLookHandle::previewFileName): Retrieved from m_converter.
+        (WebCore::QuickLookHandle::previewRequestURL): Ditto.
+        * platform/network/ios/QuickLookHandleClient.h: Added.
+        (WebCore::QuickLookHandleClient::~QuickLookHandleClient):
+        (WebCore::QuickLookHandleClient::didReceiveDataArray):
+        (WebCore::QuickLookHandleClient::didReceiveData):
+        (WebCore::QuickLookHandleClient::didFinishLoading):
+        (WebCore::QuickLookHandleClient::didFail):
+
 2014-04-10  Pratik Solanki  <psola...@apple.com>
 
         Move early return out of dispatch_async() block so we can return from willSendRequest quickly

Modified: trunk/Source/WebCore/WebCore.exp.in (167206 => 167207)


--- trunk/Source/WebCore/WebCore.exp.in	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-04-14 02:57:33 UTC (rev 167207)
@@ -3218,9 +3218,13 @@
 #if USE(QUICK_LOOK)
 __ZN7WebCore27qlPreviewConverterUTIForURLEP5NSURL
 __ZN7WebCore30removeQLPreviewConverterForURLEP5NSURL
+__ZN7WebCore31createTemporaryFileForQuickLookEP8NSString
 __ZN7WebCore32qlPreviewConverterFileNameForURLEP5NSURL
 __ZN7WebCore33QLPreviewGetSupportedMIMETypesSetEv
 __ZN7WebCore34registerQLPreviewConverterIfNeededEP5NSURLP8NSStringP6NSData
+__ZN7WebCore35addQLPreviewConverterWithFileForURLEP5NSURLP11objc_objectP8NSString
+__ZNK7WebCore15QuickLookHandle15previewFileNameEv
+__ZNK7WebCore15QuickLookHandle17previewRequestURLEv
 #endif
 
 #if ENABLE(REMOTE_INSPECTOR)

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (167206 => 167207)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-04-14 02:57:33 UTC (rev 167207)
@@ -3607,6 +3607,7 @@
 		A104F24414C71F7A009E2C23 /* CachedSVGDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = A104F24214C71F7A009E2C23 /* CachedSVGDocument.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A10BB5851484E3A700B2E87A /* RenderSVGRect.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5831484E3A700B2E87A /* RenderSVGRect.h */; };
 		A10BB58B1484E3B300B2E87A /* RenderSVGShape.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5891484E3B300B2E87A /* RenderSVGShape.h */; };
+		A10DBF4718F92317000D70C6 /* QuickLookHandleClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A10DBF4618F92317000D70C6 /* QuickLookHandleClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A10DC76A14747BAB005E2471 /* StyleGridData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10DC76814747BAB005E2471 /* StyleGridData.cpp */; };
 		A10DC76B14747BAB005E2471 /* StyleGridData.h in Headers */ = {isa = PBXBuildFile; fileRef = A10DC76914747BAB005E2471 /* StyleGridData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A110DB9B14F5DF7700A03B93 /* StyleGridItemData.h in Headers */ = {isa = PBXBuildFile; fileRef = A110DB9A14F5DF7700A03B93 /* StyleGridItemData.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -10667,6 +10668,7 @@
 		A10BB5831484E3A700B2E87A /* RenderSVGRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGRect.h; sourceTree = "<group>"; };
 		A10BB5881484E3B300B2E87A /* RenderSVGShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGShape.cpp; sourceTree = "<group>"; };
 		A10BB5891484E3B300B2E87A /* RenderSVGShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGShape.h; sourceTree = "<group>"; };
+		A10DBF4618F92317000D70C6 /* QuickLookHandleClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLookHandleClient.h; sourceTree = "<group>"; };
 		A10DC76814747BAB005E2471 /* StyleGridData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleGridData.cpp; path = style/StyleGridData.cpp; sourceTree = "<group>"; };
 		A10DC76914747BAB005E2471 /* StyleGridData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleGridData.h; path = style/StyleGridData.h; sourceTree = "<group>"; };
 		A110DB9A14F5DF7700A03B93 /* StyleGridItemData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleGridItemData.h; path = style/StyleGridItemData.h; sourceTree = "<group>"; };
@@ -15482,6 +15484,7 @@
 				443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */,
 				442AF7A7102CDDEA008FD4D3 /* QuickLook.h */,
 				442AF7A8102CDDEA008FD4D3 /* QuickLook.mm */,
+				A10DBF4618F92317000D70C6 /* QuickLookHandleClient.h */,
 				7E428CE413E3407F003B661C /* ResourceHandleIOS.mm */,
 				44A20DB80F84166C00B3E1FE /* WebCoreURLResponseIOS.h */,
 				444D4E210F708B2E003158E0 /* WebCoreURLResponseIOS.mm */,
@@ -25807,6 +25810,7 @@
 				B2227A540D00BF220071B782 /* SVGPaint.h in Headers */,
 				B2227A570D00BF220071B782 /* SVGParserUtilities.h in Headers */,
 				2D3A0E3613A7D76100E85AF0 /* SVGParsingError.h in Headers */,
+				A10DBF4718F92317000D70C6 /* QuickLookHandleClient.h in Headers */,
 				84C6784D1214814700A92902 /* SVGPathBlender.h in Headers */,
 				8476C9EB11DF6A2900555B02 /* SVGPathBuilder.h in Headers */,
 				8419D2A7120D92D000141F8F /* SVGPathByteStream.h in Headers */,

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (167206 => 167207)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -97,6 +97,10 @@
     class SubstituteData;
     class Widget;
 
+#if USE(QUICK_LOOK)
+    class QuickLookHandle;
+#endif
+
     typedef std::function<void (PolicyAction)> FramePolicyFunction;
 
     class FrameLoaderClient {
@@ -334,6 +338,10 @@
 
         // FIXME (bug 116233): We need to get rid of EmptyFrameLoaderClient completely, then this will no longer be needed.
         virtual bool isEmptyFrameLoaderClient() { return false; }
+
+#if USE(QUICK_LOOK)
+        virtual void didCreateQuickLookHandle(QuickLookHandle&) { }
+#endif
     };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (167206 => 167207)


--- trunk/Source/WebCore/loader/ResourceLoader.cpp	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/loader/ResourceLoader.cpp	2014-04-14 02:57:33 UTC (rev 167207)
@@ -606,4 +606,11 @@
 
 #endif
 
+#if USE(QUICK_LOOK)
+void ResourceLoader::didCreateQuickLookHandle(QuickLookHandle& handle)
+{
+    frameLoader()->client().didCreateQuickLookHandle(handle);
 }
+#endif
+
+}

Modified: trunk/Source/WebCore/loader/ResourceLoader.h (167206 => 167207)


--- trunk/Source/WebCore/loader/ResourceLoader.h	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/loader/ResourceLoader.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -49,6 +49,10 @@
 class URL;
 class ResourceBuffer;
 
+#if USE(QUICK_LOOK)
+class QuickLookHandle;
+#endif
+
 class ResourceLoader : public RefCounted<ResourceLoader>, protected ResourceHandleClient {
 public:
     virtual ~ResourceLoader();
@@ -146,6 +150,10 @@
     virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*) override;
 #endif
 
+#if USE(QUICK_LOOK)
+    virtual void didCreateQuickLookHandle(QuickLookHandle&) override;
+#endif
+
     const URL& url() const { return m_request.url(); }
     ResourceHandle* handle() const { return m_handle.get(); }
     bool shouldSendResourceLoadCallbacks() const { return m_options.sendLoadCallbacks == SendCallbacks; }

Modified: trunk/Source/WebCore/platform/network/ResourceHandle.h (167206 => 167207)


--- trunk/Source/WebCore/platform/network/ResourceHandle.h	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/platform/network/ResourceHandle.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -150,7 +150,7 @@
 
 #if USE(QUICK_LOOK)
     QuickLookHandle* quickLookHandle() { return m_quickLook.get(); }
-    void setQuickLookHandle(PassOwnPtr<QuickLookHandle> handle) { m_quickLook = handle; }
+    void setQuickLookHandle(std::unique_ptr<QuickLookHandle> handle) { m_quickLook = std::move(handle); }
 #endif
 
 #if PLATFORM(WIN) && USE(CURL)
@@ -292,7 +292,7 @@
     OwnPtr<ResourceHandleInternal> d;
 
 #if USE(QUICK_LOOK)
-    OwnPtr<QuickLookHandle> m_quickLook;
+    std::unique_ptr<QuickLookHandle> m_quickLook;
 #endif
 };
 

Modified: trunk/Source/WebCore/platform/network/ResourceHandleClient.h (167206 => 167207)


--- trunk/Source/WebCore/platform/network/ResourceHandleClient.h	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/platform/network/ResourceHandleClient.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -50,6 +50,10 @@
     class ResourceResponse;
     class SharedBuffer;
 
+#if USE(QUICK_LOOK)
+    class QuickLookHandle;
+#endif
+
     enum CacheStoragePolicy {
         StorageAllowed,
         StorageAllowedInMemoryOnly,
@@ -124,6 +128,9 @@
         virtual NSCachedURLResponse *willCacheResponse(ResourceHandle*, NSCachedURLResponse *response) { return response; }
 #endif
 
+#if USE(QUICK_LOOK)
+        virtual void didCreateQuickLookHandle(QuickLookHandle&) { }
+#endif
     };
 
 }

Modified: trunk/Source/WebCore/platform/network/ios/QuickLook.h (167206 => 167207)


--- trunk/Source/WebCore/platform/network/ios/QuickLook.h	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/platform/network/ios/QuickLook.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -28,29 +28,21 @@
 
 #if USE(QUICK_LOOK)
 
+#import "QuickLookHandleClient.h"
 #import "ResourceRequest.h"
 #import <objc/objc-runtime.h>
 #import <wtf/PassOwnPtr.h>
+#import <wtf/RefPtr.h>
 
-#ifdef __OBJC__
-@class NSData;
-@class NSDictionary;
-@class NSFileHandle;
-@class NSSet;
-@class NSString;
-@class NSURL;
-@class NSURLConnection;
-@class NSURLResponse;
-#else
-class NSData;
-class NSDictionary;
-class NSFileHandle;
-class NSSet;
-class NSString;
-class NSURL;
-class NSURLConnection;
-class NSURLResponse;
-#endif
+OBJC_CLASS NSData;
+OBJC_CLASS NSDictionary;
+OBJC_CLASS NSFileHandle;
+OBJC_CLASS NSSet;
+OBJC_CLASS NSString;
+OBJC_CLASS NSURL;
+OBJC_CLASS NSURLConnection;
+OBJC_CLASS NSURLResponse;
+OBJC_CLASS QLPreviewConverter;
 
 #if USE(CFNETWORK)
 typedef struct _CFURLResponse* CFURLResponseRef;
@@ -59,6 +51,7 @@
 
 namespace WebCore {
 
+class QuickLookHandleClient;
 class ResourceHandle;
 class ResourceLoader;
 class SynchronousResourceHandleCFURLConnectionDelegate;
@@ -84,15 +77,16 @@
 
 const char* QLPreviewProtocol();
 
+NSString *createTemporaryFileForQuickLook(NSString *fileName);
 
 class QuickLookHandle {
     WTF_MAKE_NONCOPYABLE(QuickLookHandle);
 public:
-    static PassOwnPtr<QuickLookHandle> create(ResourceHandle*, NSURLConnection *, NSURLResponse *, id delegate);
+    static std::unique_ptr<QuickLookHandle> create(ResourceHandle*, NSURLConnection *, NSURLResponse *, id delegate);
 #if USE(CFNETWORK)
-    static PassOwnPtr<QuickLookHandle> create(ResourceHandle*, SynchronousResourceHandleCFURLConnectionDelegate*, CFURLResponseRef);
+    static std::unique_ptr<QuickLookHandle> create(ResourceHandle*, SynchronousResourceHandleCFURLConnectionDelegate*, CFURLResponseRef);
 #endif
-    static PassOwnPtr<QuickLookHandle> create(ResourceLoader*, NSURLResponse *, id delegate);
+    static std::unique_ptr<QuickLookHandle> create(ResourceLoader*, NSURLResponse *, id delegate);
     ~QuickLookHandle();
 
     bool didReceiveDataArray(CFArrayRef);
@@ -105,15 +99,23 @@
     CFURLResponseRef cfResponse();
 #endif
 
+    void setClient(PassRefPtr<QuickLookHandleClient> client) { m_client = client; }
+
+    NSString *previewFileName() const;
+    NSURL *firstRequestURL() const { return m_firstRequestURL.get(); }
+    NSURL *previewRequestURL() const;
+    QLPreviewConverter *converter() const { return m_converter.get(); }
+
 private:
     QuickLookHandle(NSURL *, NSURLConnection *, NSURLResponse *, id delegate);
 
     RetainPtr<NSURL> m_firstRequestURL;
-    RetainPtr<id> m_converter;
+    RetainPtr<QLPreviewConverter> m_converter;
     RetainPtr<id> m_delegate;
     bool m_finishedLoadingDataIntoConverter;
     RetainPtr<NSFileHandle *> m_quicklookFileHandle;
-    NSURLResponse *m_nsResponse;
+    RetainPtr<NSURLResponse> m_nsResponse;
+    RefPtr<QuickLookHandleClient> m_client;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/network/ios/QuickLook.mm (167206 => 167207)


--- trunk/Source/WebCore/platform/network/ios/QuickLook.mm	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebCore/platform/network/ios/QuickLook.mm	2014-04-14 02:57:33 UTC (rev 167207)
@@ -195,7 +195,7 @@
         RetainPtr<NSString> uti = adoptNS(WebCore::QLTypeCopyUTIForURLAndMimeType(url, updatedMIMEType.get()));
 
         RetainPtr<id> converter = adoptNS([[QLPreviewConverterClass() alloc] initWithData:data name:nil uti:uti.get() options:nil]);
-        NSURLRequest *request = [converter.get() previewRequest];
+        NSURLRequest *request = [converter previewRequest];
 
         // We use [request URL] here instead of url since it will be
         // the URL that the WebDataSource will see during -dealloc.
@@ -321,7 +321,7 @@
 
 namespace WebCore {
 
-static NSString *createTemporaryFileForQuickLook(NSString *fileName)
+NSString *createTemporaryFileForQuickLook(NSString *fileName)
 {
     NSString *downloadDirectory = createTemporaryDirectory(@"QuickLookContent");
     if (!downloadDirectory)
@@ -339,52 +339,46 @@
     return success ? uniqueContentPath : nil;
 }
 
+static inline QuickLookHandleClient* emptyClient()
+{
+    static NeverDestroyed<QuickLookHandleClient> emptyClient;
+    return &emptyClient.get();
+}
 
 QuickLookHandle::QuickLookHandle(NSURL *firstRequestURL, NSURLConnection *connection, NSURLResponse *nsResponse, id delegate)
     : m_firstRequestURL(firstRequestURL)
     , m_converter(adoptNS([[QLPreviewConverterClass() alloc] initWithConnection:connection delegate:delegate response:nsResponse options:nil]))
-    , m_delegate(adoptNS([delegate retain]))
+    , m_delegate(delegate)
     , m_finishedLoadingDataIntoConverter(false)
-    , m_nsResponse([m_converter.get() previewResponse])
+    , m_nsResponse([m_converter previewResponse])
+    , m_client(emptyClient())
 {
-    NSURL *previewRequestURL = [[m_converter.get() previewRequest] URL];
-    if (!applicationIsMobileSafari()) {
-        // This keeps the QLPreviewConverter alive to serve any subresource requests.
-        // It is removed by -[WebDataSource dealloc].
-        addQLPreviewConverterWithFileForURL(previewRequestURL, m_converter.get(), 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([m_converter.get() previewFileName]);
-    LOG(Network, "QuickLookHandle::QuickLookHandle() - quicklookContentPath: %s", [quicklookContentPath UTF8String]);
-
-    if (quicklookContentPath) {
-        m_quicklookFileHandle = adoptNS([[NSFileHandle fileHandleForWritingAtPath:quicklookContentPath] retain]);
-        // We must use the generated URL from m_converter's NSURLRequest object
-        // so that it matches the URL removed from -[WebDataSource dealloc].
-        addQLPreviewConverterWithFileForURL(previewRequestURL, m_converter.get(), quicklookContentPath);
-    }
+    LOG(Network, "QuickLookHandle::QuickLookHandle() - previewFileName: %s", [m_converter previewFileName]);
 }
 
-PassOwnPtr<QuickLookHandle> QuickLookHandle::create(ResourceHandle* handle, NSURLConnection *connection, NSURLResponse *nsResponse, id delegate)
+std::unique_ptr<QuickLookHandle> QuickLookHandle::create(ResourceHandle* handle, NSURLConnection *connection, NSURLResponse *nsResponse, id delegate)
 {
-    if (handle->firstRequest().isMainResourceRequest() && [WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[nsResponse MIMEType]])
-        return adoptPtr(new QuickLookHandle([handle->firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], connection, nsResponse, delegate));
+    ASSERT_ARG(handle, handle);
+    if (!handle->firstRequest().isMainResourceRequest() || ![WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[nsResponse MIMEType]])
+        return nullptr;
 
-    return nullptr;
+    std::unique_ptr<QuickLookHandle> quickLookHandle(new QuickLookHandle([handle->firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], connection, nsResponse, delegate));
+    handle->client()->didCreateQuickLookHandle(*quickLookHandle);
+    return std::move(quickLookHandle);
 }
 
 #if USE(CFNETWORK)
-PassOwnPtr<QuickLookHandle> QuickLookHandle::create(ResourceHandle* handle, SynchronousResourceHandleCFURLConnectionDelegate* connectionDelegate, CFURLResponseRef cfResponse)
+std::unique_ptr<QuickLookHandle> QuickLookHandle::create(ResourceHandle* handle, SynchronousResourceHandleCFURLConnectionDelegate* connectionDelegate, CFURLResponseRef cfResponse)
 {
-    if (handle->firstRequest().isMainResourceRequest() && [WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:(NSString *)CFURLResponseGetMIMEType(cfResponse)]) {
-        NSURLResponse *nsResponse = [NSURLResponse _responseWithCFURLResponse:cfResponse];
-        WebQuickLookHandleAsDelegate *delegate = [[[WebQuickLookHandleAsDelegate alloc] initWithConnectionDelegate:connectionDelegate] autorelease];
-        return adoptPtr(new QuickLookHandle([handle->firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, nsResponse, delegate));
-    }
+    ASSERT_ARG(handle, handle);
+    if (!handle->firstRequest().isMainResourceRequest() || ![WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:(NSString *)CFURLResponseGetMIMEType(cfResponse)])
+        return nullptr;
 
-    return nullptr;
+    NSURLResponse *nsResponse = [NSURLResponse _responseWithCFURLResponse:cfResponse];
+    WebQuickLookHandleAsDelegate *delegate = [[[WebQuickLookHandleAsDelegate alloc] initWithConnectionDelegate:connectionDelegate] autorelease];
+    std::unique_ptr<QuickLookHandle> quickLookHandle(new QuickLookHandle([handle->firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, nsResponse, delegate));
+    handle->client()->didCreateQuickLookHandle(*quickLookHandle);
+    return std::move(quickLookHandle);
 }
 
 CFURLResponseRef QuickLookHandle::cfResponse()
@@ -393,47 +387,39 @@
 }
 #endif
 
-PassOwnPtr<QuickLookHandle> QuickLookHandle::create(ResourceLoader* loader, NSURLResponse *response, id delegate)
+std::unique_ptr<QuickLookHandle> QuickLookHandle::create(ResourceLoader* loader, NSURLResponse *response, id delegate)
 {
-    if (loader->request().isMainResourceRequest() && [WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[response MIMEType]])
-        return adoptPtr(new QuickLookHandle([loader->originalRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, response, delegate));
+    ASSERT_ARG(loader, loader);
+    if (!loader->request().isMainResourceRequest() || ![WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[response MIMEType]])
+        return nullptr;
 
-    return nullptr;
+    std::unique_ptr<QuickLookHandle> quickLookHandle(new QuickLookHandle([loader->originalRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, response, delegate));
+    loader->didCreateQuickLookHandle(*quickLookHandle);
+    return std::move(quickLookHandle);
 }
 
 NSURLResponse *QuickLookHandle::nsResponse()
 {
-    return m_nsResponse;
+    return m_nsResponse.get();
 }
 
 bool QuickLookHandle::didReceiveDataArray(CFArrayRef cfDataArray)
 {
-    NSArray * const dataArray = (NSArray *)cfDataArray;
-
     if (m_finishedLoadingDataIntoConverter)
         return false;
 
     LOG(Network, "QuickLookHandle::didReceiveDataArray()");
-    [m_converter.get() appendDataArray:dataArray];
-    if (m_quicklookFileHandle) {
-        for (NSData *data in dataArray)
-            [m_quicklookFileHandle.get() writeData:data];
-    }
+    [m_converter appendDataArray:(NSArray *)cfDataArray];
+    m_client->didReceiveDataArray(cfDataArray);
     return true;
 }
 
 bool QuickLookHandle::didReceiveData(CFDataRef cfData)
 {
-    NSData * const data = "" *)cfData;
-
     if (m_finishedLoadingDataIntoConverter)
         return false;
-
-    LOG(Network, "QuickLookHandle::didReceiveData()");
-    [m_converter.get() appendData:data];
-    if (m_quicklookFileHandle)
-        [m_quicklookFileHandle.get() writeData:data];
-    return true;
+    
+    return didReceiveDataArray(adoptCF(CFArrayCreate(kCFAllocatorDefault, (const void**)&cfData, 1, &kCFTypeArrayCallBacks)).get());
 }
 
 bool QuickLookHandle::didFinishLoading()
@@ -443,34 +429,37 @@
 
     LOG(Network, "QuickLookHandle::didFinishLoading()");
     m_finishedLoadingDataIntoConverter = YES;
-    [m_converter.get() finishedAppendingData];
-    if (m_quicklookFileHandle)
-        [m_quicklookFileHandle.get() closeFile];
+    [m_converter finishedAppendingData];
+    m_client->didFinishLoading();
     return true;
 }
 
 void QuickLookHandle::didFail()
 {
     LOG(Network, "QuickLookHandle::didFail()");
-    m_quicklookFileHandle = nullptr;
-    // removeQLPreviewConverterForURL deletes the temporary file created.
-    removeQLPreviewConverterForURL(m_firstRequestURL.get());
-    [m_converter.get() finishConverting];
+    m_client->didFail();
+    [m_converter finishConverting];
     m_converter = nullptr;
 }
 
 QuickLookHandle::~QuickLookHandle()
 {
     LOG(Network, "QuickLookHandle::~QuickLookHandle()");
-    if (m_quicklookFileHandle) {
-        m_quicklookFileHandle = nullptr;
-        removeQLPreviewConverterForURL(m_firstRequestURL.get());
-    }
     m_converter = nullptr;
 
-    [m_delegate.get() clearHandle];
+    [m_delegate clearHandle];
 }
 
+NSString *QuickLookHandle::previewFileName() const
+{
+    return [m_converter previewFileName];
 }
 
+NSURL *QuickLookHandle::previewRequestURL() const
+{
+    return [[m_converter previewRequest] URL];
+}
+
+}
+
 #endif // USE(QUICK_LOOK)

Added: trunk/Source/WebCore/platform/network/ios/QuickLookHandleClient.h (0 => 167207)


--- trunk/Source/WebCore/platform/network/ios/QuickLookHandleClient.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/ios/QuickLookHandleClient.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef QuickLookHandleClient_h
+#define QuickLookHandleClient_h
+
+#if USE(QUICK_LOOK)
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class QuickLookHandleClient : public RefCounted<QuickLookHandleClient> {
+public:
+    virtual ~QuickLookHandleClient() { }
+    virtual void didReceiveDataArray(CFArrayRef) { }
+    virtual void didFinishLoading() { }
+    virtual void didFail() { }
+};
+
+} // namespace WebCore
+
+#endif // USE(QUICK_LOOK)
+
+#endif // QuickLookHandleClient_h

Modified: trunk/Source/WebKit/mac/ChangeLog (167206 => 167207)


--- trunk/Source/WebKit/mac/ChangeLog	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebKit/mac/ChangeLog	2014-04-14 02:57:33 UTC (rev 167207)
@@ -1,3 +1,16 @@
+2014-04-13  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] Move file system-related code into WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=131597
+
+        Reviewed by Dan Bernstein.
+
+        Moved file system and WebKit1-only code from QuickLookHandle into a new
+        QuickLookHandleClient subclass.
+
+        * WebCoreSupport/WebFrameLoaderClient.h:
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+
 2014-04-09  Alexey Proskuryakov  <a...@apple.com>
 
         Eliminate DragSession structure

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h (167206 => 167207)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -238,6 +238,10 @@
 
     virtual bool shouldPaintBrokenImage(const WebCore::URL&) const;
 
+#if USE(QUICK_LOOK)
+    virtual void didCreateQuickLookHandle(WebCore::QuickLookHandle&) override;
+#endif
+
     RetainPtr<WebFrame> m_webFrame;
 
     RetainPtr<WebFramePolicyListener> m_policyListener;

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm (167206 => 167207)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2014-04-14 02:57:33 UTC (rev 167207)
@@ -152,6 +152,13 @@
 #import "WebUIKitDelegate.h"
 #endif
 
+#if USE(QUICK_LOOK)
+#import <Foundation/NSFileManager_NSURLExtras.h>
+#import <WebCore/FileSystemIOS.h>
+#import <WebCore/QuickLook.h>
+#import <WebCore/RuntimeApplicationChecksIOS.h>
+#endif
+
 using namespace WebCore;
 using namespace HTMLNames;
 
@@ -2392,6 +2399,66 @@
 }
 #endif
 
+#if USE(QUICK_LOOK)
+void WebFrameLoaderClient::didCreateQuickLookHandle(WebCore::QuickLookHandle& handle)
+{
+    class QuickLookDocumentWriter : public WebCore::QuickLookHandleClient {
+    public:
+        explicit QuickLookDocumentWriter(const WebCore::QuickLookHandle& handle)
+            : m_firstRequestURL(handle.firstRequestURL())
+        {
+            NSURL *previewRequestURL = handle.previewRequestURL();
+            if (!applicationIsMobileSafari()) {
+                // 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);
+            }
+        }
+
+        virtual ~QuickLookDocumentWriter()
+        {
+            if (m_fileHandle)
+                removeQLPreviewConverterForURL(m_firstRequestURL.get());
+        }
+
+    private:
+        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];
+            }
+        }
+
+        void didFinishLoading() override
+        {
+            [m_fileHandle closeFile];
+        }
+
+        void didFail() override
+        {
+            m_fileHandle = nil;
+            // removeQLPreviewConverterForURL deletes the temporary file created.
+            removeQLPreviewConverterForURL(m_firstRequestURL.get());
+        }
+    };
+    handle.setClient(adoptRef(new QuickLookDocumentWriter(handle)));
+}
+#endif
+
 @implementation WebFramePolicyListener
 
 + (void)initialize

Modified: trunk/Source/WebKit2/ChangeLog (167206 => 167207)


--- trunk/Source/WebKit2/ChangeLog	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebKit2/ChangeLog	2014-04-14 02:57:33 UTC (rev 167207)
@@ -1,5 +1,16 @@
 2014-04-13  Andy Estes  <aes...@apple.com>
 
+        [QuickLook] Move file system-related code into WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=131597
+
+        Reviewed by Dan Bernstein.
+
+        * WebProcess/Network/WebResourceLoader.h: Made m_quickLookHandle a unique_ptr.
+        * WebProcess/ios/WebResourceLoaderIOS.mm:
+        (WebKit::WebResourceLoader::setUpQuickLookHandleIfNeeded):
+
+2014-04-13  Andy Estes  <aes...@apple.com>
+
         REGRESSION (r167164): -[WKNSURLSessionLocal _getCookieHeadersForTask:completionHandler:] _block_invoke can access a deallocated completionHandler
         https://bugs.webkit.org/show_bug.cgi?id=131595
 

Modified: trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.h (167206 => 167207)


--- trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.h	2014-04-14 01:35:27 UTC (rev 167206)
+++ trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.h	2014-04-14 02:57:33 UTC (rev 167207)
@@ -95,7 +95,7 @@
 #if USE(QUICK_LOOK)
     void setUpQuickLookHandleIfNeeded(const WebCore::ResourceResponse&);
 
-    OwnPtr<WebCore::QuickLookHandle> m_quickLookHandle;
+    std::unique_ptr<WebCore::QuickLookHandle> m_quickLookHandle;
 #endif
 
     RefPtr<WebCore::ResourceLoader> m_coreLoader;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to