Title: [211402] trunk/Source
Revision
211402
Author
aes...@apple.com
Date
2017-01-30 19:06:05 -0800 (Mon, 30 Jan 2017)

Log Message

[QuickLook] FrameLoaderClient should return the new QuickLookHandleClient it creates
https://bugs.webkit.org/show_bug.cgi?id=167625

Reviewed by Andreas Kling.

Source/WebCore:

QuickLookHandleClients were being created by QuickLookHandle calling
FrameLoaderClient::didCreateQuickLookHandle() then having the FrameLoaderClient create a new
QuickLookHandleClient and set it using QuickLookHandle::setClient().

Since all FrameLoaderClient::didCreateQuickLookHandle() does is create a new
QuickLookHandleClient, this patch changes the FrameLoaderClient function to return the new
QuickLookHandleClient directly and removes the API from QuickLookHandle to set a client.
This also removes previewFileName() and previewUTI() from QuickLookHandle and instead passes
these as arguments to the FrameLoaderClient.

No change in behavior. Covered by existing tests.

* loader/EmptyClients.cpp: Added an implementation of createQuickLookHandleClient() that
returns nullptr.
* loader/FrameLoaderClient.h: Declared createQuickLookHandleClient() and removed
didCreateQuickLookHandle().
* loader/ios/QuickLook.h: Removed setClient(), previewFileName(), and previewUTI().
* loader/ios/QuickLook.mm: Removed testingOrEmptyClient().
(-[WebPreviewLoader initWithResourceLoader:resourceResponse:quickLookHandle:]): Set _client
to testingClient() if it exists, otherwise set it to the client returned by
FrameLoaderClient::createQuickLookHandleClient() it non-null, otherwise set it to
emptyClient().
(testingOrEmptyClient): Deleted.
(-[WebPreviewLoader setClient:]): Deleted.
(-[WebPreviewLoader converter]): Deleted.
(WebCore::QuickLookHandle::setClient): Deleted.
(WebCore::QuickLookHandle::previewFileName): Deleted.
(WebCore::QuickLookHandle::previewUTI): Deleted.

Source/WebKit/mac:

* WebCoreSupport/WebFrameLoaderClient.h: Declared createQuickLookHandleClient().
* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::createQuickLookHandleClient): Renamed from didCreateQuickLookHandle().
(WebFrameLoaderClient::didCreateQuickLookHandle): Renamed to createQuickLookHandleClient().

Source/WebKit2:

* WebProcess/WebCoreSupport/WebFrameLoaderClient.h: Declared createQuickLookHandleClient().
* WebProcess/WebCoreSupport/ios/WebFrameLoaderClientIOS.mm:
(WebKit::WebFrameLoaderClient::createQuickLookHandleClient): Renamed from didCreateQuickLookHandle().
(WebKit::WebFrameLoaderClient::didCreateQuickLookHandle): Renamed to createQuickLookHandleClient().
* WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp:
(WebKit::WebQuickLookHandleClient::WebQuickLookHandleClient): Set m_fileName and m_uti from
the constructor arguments instead of from handle.
* WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (211401 => 211402)


--- trunk/Source/WebCore/ChangeLog	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebCore/ChangeLog	2017-01-31 03:06:05 UTC (rev 211402)
@@ -1,3 +1,39 @@
+2017-01-30  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] FrameLoaderClient should return the new QuickLookHandleClient it creates
+        https://bugs.webkit.org/show_bug.cgi?id=167625
+
+        Reviewed by Andreas Kling.
+
+        QuickLookHandleClients were being created by QuickLookHandle calling
+        FrameLoaderClient::didCreateQuickLookHandle() then having the FrameLoaderClient create a new
+        QuickLookHandleClient and set it using QuickLookHandle::setClient().
+
+        Since all FrameLoaderClient::didCreateQuickLookHandle() does is create a new
+        QuickLookHandleClient, this patch changes the FrameLoaderClient function to return the new
+        QuickLookHandleClient directly and removes the API from QuickLookHandle to set a client.
+        This also removes previewFileName() and previewUTI() from QuickLookHandle and instead passes
+        these as arguments to the FrameLoaderClient.
+
+        No change in behavior. Covered by existing tests.
+
+        * loader/EmptyClients.cpp: Added an implementation of createQuickLookHandleClient() that
+        returns nullptr.
+        * loader/FrameLoaderClient.h: Declared createQuickLookHandleClient() and removed
+        didCreateQuickLookHandle().
+        * loader/ios/QuickLook.h: Removed setClient(), previewFileName(), and previewUTI().
+        * loader/ios/QuickLook.mm: Removed testingOrEmptyClient().
+        (-[WebPreviewLoader initWithResourceLoader:resourceResponse:quickLookHandle:]): Set _client
+        to testingClient() if it exists, otherwise set it to the client returned by
+        FrameLoaderClient::createQuickLookHandleClient() it non-null, otherwise set it to
+        emptyClient().
+        (testingOrEmptyClient): Deleted.
+        (-[WebPreviewLoader setClient:]): Deleted.
+        (-[WebPreviewLoader converter]): Deleted.
+        (WebCore::QuickLookHandle::setClient): Deleted.
+        (WebCore::QuickLookHandle::previewFileName): Deleted.
+        (WebCore::QuickLookHandle::previewUTI): Deleted.
+
 2017-01-30  Jer Noble  <jer.no...@apple.com>
 
         NULL-deref crash in TextTrack::removeCue()

Modified: trunk/Source/WebCore/loader/EmptyClients.cpp (211401 => 211402)


--- trunk/Source/WebCore/loader/EmptyClients.cpp	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebCore/loader/EmptyClients.cpp	2017-01-31 03:06:05 UTC (rev 211402)
@@ -67,6 +67,10 @@
 #include "CompiledContentExtension.h"
 #endif
 
+#if USE(QUICK_LOOK)
+#include "QuickLookHandleClient.h"
+#endif
+
 namespace WebCore {
 
 class UserMessageHandlerDescriptor;
@@ -441,6 +445,10 @@
 
     bool isEmptyFrameLoaderClient() final { return true; }
     void prefetchDNS(const String&) final { }
+
+#if USE(QUICK_LOOK)
+    RefPtr<QuickLookHandleClient> createQuickLookHandleClient(const String&, const String&) final { return nullptr; }
+#endif
 };
 
 class EmptyFrameNetworkingContext final : public FrameNetworkingContext {

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (211401 => 211402)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2017-01-31 03:06:05 UTC (rev 211402)
@@ -84,7 +84,7 @@
 class PluginViewBase;
 class PolicyChecker;
 class ProtectionSpace;
-class QuickLookHandle;
+class QuickLookHandleClient;
 class RTCPeerConnectionHandler;
 class ResourceError;
 class ResourceHandle;
@@ -340,7 +340,7 @@
     virtual bool isEmptyFrameLoaderClient() { return false; }
 
 #if USE(QUICK_LOOK)
-    virtual void didCreateQuickLookHandle(QuickLookHandle&) { }
+    virtual RefPtr<QuickLookHandleClient> createQuickLookHandleClient(const String&, const String&) = 0;
 #endif
 
 #if ENABLE(CONTENT_FILTERING)

Modified: trunk/Source/WebCore/loader/ios/QuickLook.h (211401 => 211402)


--- trunk/Source/WebCore/loader/ios/QuickLook.h	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebCore/loader/ios/QuickLook.h	2017-01-31 03:06:05 UTC (rev 211402)
@@ -63,12 +63,8 @@
     bool didFinishLoading();
     void didFail();
 
-    WEBCORE_EXPORT void setClient(Ref<QuickLookHandleClient>&&);
     WEBCORE_EXPORT static void setClientForTesting(RefPtr<QuickLookHandleClient>&&);
 
-    WEBCORE_EXPORT String previewFileName() const;
-    WEBCORE_EXPORT String previewUTI() const;
-
 private:
     friend std::unique_ptr<QuickLookHandle> std::make_unique<QuickLookHandle>(ResourceLoader&, const ResourceResponse&);
     QuickLookHandle(ResourceLoader&, const ResourceResponse&);

Modified: trunk/Source/WebCore/loader/ios/QuickLook.mm (211401 => 211402)


--- trunk/Source/WebCore/loader/ios/QuickLook.mm	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebCore/loader/ios/QuickLook.mm	2017-01-31 03:06:05 UTC (rev 211402)
@@ -134,13 +134,6 @@
     return emptyClient.get();
 }
 
-static QuickLookHandleClient& testingOrEmptyClient()
-{
-    if (testingClient())
-        return *testingClient();
-    return emptyClient();
-}
-
 @interface WebPreviewLoader : NSObject {
     RefPtr<ResourceLoader> _resourceLoader;
     ResourceResponse _response;
@@ -152,13 +145,10 @@
 }
 
 - (instancetype)initWithResourceLoader:(ResourceLoader&)resourceLoader resourceResponse:(const ResourceResponse&)resourceResponse quickLookHandle:(QuickLookHandle&)quickLookHandle;
-- (void)setClient:(Ref<QuickLookHandleClient>&&)client;
 - (void)appendDataArray:(NSArray<NSData *> *)dataArray;
 - (void)finishedAppending;
 - (void)failed;
 
-@property (nonatomic, readonly) PreviewConverter* converter;
-
 @end
 
 @implementation WebPreviewLoader
@@ -172,20 +162,20 @@
     _resourceLoader = &resourceLoader;
     _response = resourceResponse;
     _handle = &quickLookHandle;
-    _client = &testingOrEmptyClient();
     _converter = std::make_unique<PreviewConverter>(self, _response);
     _bufferedDataArray = adoptNS([[NSMutableArray alloc] init]);
 
+    if (testingClient())
+        _client = testingClient();
+    else if (auto client = resourceLoader.frameLoader()->client().createQuickLookHandleClient(_converter->previewFileName(), _converter->previewUTI()))
+        _client = WTFMove(client);
+    else
+        _client = &emptyClient();
+
     LOG(Network, "WebPreviewConverter created with preview file name \"%s\".", _converter->previewFileName().utf8().data());
     return self;
 }
 
-- (void)setClient:(Ref<QuickLookHandleClient>&&)client
-{
-    if (!testingClient())
-        _client = WTFMove(client);
-}
-
 - (void)appendDataArray:(NSArray<NSData *> *)dataArray
 {
     LOG(Network, "WebPreviewConverter appending data array with count %ld.", dataArray.count);
@@ -208,11 +198,6 @@
     _client->didFail();
 }
 
-- (PreviewConverter*)converter
-{
-    return _converter.get();
-}
-
 - (void)_sendDidReceiveResponseIfNecessary
 {
     if (_hasSentDidReceiveResponse)
@@ -326,7 +311,6 @@
 QuickLookHandle::QuickLookHandle(ResourceLoader& loader, const ResourceResponse& response)
     : m_previewLoader { adoptNS([[WebPreviewLoader alloc] initWithResourceLoader:loader resourceResponse:response quickLookHandle:*this]) }
 {
-    loader.frameLoader()->client().didCreateQuickLookHandle(*this);
 }
 
 QuickLookHandle::~QuickLookHandle()
@@ -378,26 +362,11 @@
     m_previewLoader = nullptr;
 }
 
-void QuickLookHandle::setClient(Ref<QuickLookHandleClient>&& client)
-{
-    [m_previewLoader setClient:WTFMove(client)];
-}
-
 void QuickLookHandle::setClientForTesting(RefPtr<QuickLookHandleClient>&& client)
 {
     testingClient() = WTFMove(client);
 }
 
-String QuickLookHandle::previewFileName() const
-{
-    return [m_previewLoader converter]->previewFileName();
 }
 
-String QuickLookHandle::previewUTI() const
-{
-    return [m_previewLoader converter]->previewUTI();
-}
-
-}
-
 #endif // USE(QUICK_LOOK)

Modified: trunk/Source/WebKit/mac/ChangeLog (211401 => 211402)


--- trunk/Source/WebKit/mac/ChangeLog	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit/mac/ChangeLog	2017-01-31 03:06:05 UTC (rev 211402)
@@ -1,3 +1,15 @@
+2017-01-30  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] FrameLoaderClient should return the new QuickLookHandleClient it creates
+        https://bugs.webkit.org/show_bug.cgi?id=167625
+
+        Reviewed by Andreas Kling.
+
+        * WebCoreSupport/WebFrameLoaderClient.h: Declared createQuickLookHandleClient().
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::createQuickLookHandleClient): Renamed from didCreateQuickLookHandle().
+        (WebFrameLoaderClient::didCreateQuickLookHandle): Renamed to createQuickLookHandleClient().
+
 2017-01-30  Chris Dumez  <cdu...@apple.com>
 
         Drop legacy Attributes.isId attribute

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h (211401 => 211402)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h	2017-01-31 03:06:05 UTC (rev 211402)
@@ -246,7 +246,7 @@
     bool shouldPaintBrokenImage(const WebCore::URL&) const final;
 
 #if USE(QUICK_LOOK)
-    void didCreateQuickLookHandle(WebCore::QuickLookHandle&) final;
+    RefPtr<WebCore::QuickLookHandleClient> createQuickLookHandleClient(const String& fileName, const String& uti) final;
 #endif
 
 #if ENABLE(CONTENT_FILTERING)

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm (211401 => 211402)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2017-01-31 03:06:05 UTC (rev 211402)
@@ -2225,7 +2225,7 @@
 #endif
 
 #if USE(QUICK_LOOK)
-void WebFrameLoaderClient::didCreateQuickLookHandle(WebCore::QuickLookHandle& handle)
+RefPtr<QuickLookHandleClient> WebFrameLoaderClient::createQuickLookHandleClient(const String& fileName, const String& uti)
 {
     class QuickLookDocumentWriter : public WebCore::QuickLookHandleClient {
     public:
@@ -2263,14 +2263,14 @@
     };
 
     if (![m_webFrame webView].preferences.quickLookDocumentSavingEnabled)
-        return;
+        return nullptr;
 
-    NSString *filePath = createTemporaryFileForQuickLook(handle.previewFileName());
+    NSString *filePath = createTemporaryFileForQuickLook(fileName);
     if (!filePath)
-        return;
+        return nullptr;
 
-    [m_webFrame provisionalDataSource]._quickLookContent = @{ WebQuickLookFileNameKey : filePath, WebQuickLookUTIKey : handle.previewUTI() };
-    handle.setClient(adoptRef(*new QuickLookDocumentWriter(filePath)));
+    [m_webFrame provisionalDataSource]._quickLookContent = @{ WebQuickLookFileNameKey : filePath, WebQuickLookUTIKey : uti };
+    return adoptRef(*new QuickLookDocumentWriter(filePath));
 }
 #endif
 

Modified: trunk/Source/WebKit2/ChangeLog (211401 => 211402)


--- trunk/Source/WebKit2/ChangeLog	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit2/ChangeLog	2017-01-31 03:06:05 UTC (rev 211402)
@@ -1,3 +1,19 @@
+2017-01-30  Andy Estes  <aes...@apple.com>
+
+        [QuickLook] FrameLoaderClient should return the new QuickLookHandleClient it creates
+        https://bugs.webkit.org/show_bug.cgi?id=167625
+
+        Reviewed by Andreas Kling.
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h: Declared createQuickLookHandleClient().
+        * WebProcess/WebCoreSupport/ios/WebFrameLoaderClientIOS.mm:
+        (WebKit::WebFrameLoaderClient::createQuickLookHandleClient): Renamed from didCreateQuickLookHandle().
+        (WebKit::WebFrameLoaderClient::didCreateQuickLookHandle): Renamed to createQuickLookHandleClient().
+        * WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp:
+        (WebKit::WebQuickLookHandleClient::WebQuickLookHandleClient): Set m_fileName and m_uti from
+        the constructor arguments instead of from handle.
+        * WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h:
+
 2017-01-30  Anders Carlsson  <ander...@apple.com>
 
         Add some more crash reporter information to diagnose a failed mach_msg

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.h (211401 => 211402)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2017-01-31 03:06:05 UTC (rev 211402)
@@ -245,7 +245,7 @@
     void forcePageTransitionIfNeeded() final;
 
 #if USE(QUICK_LOOK)
-    void didCreateQuickLookHandle(WebCore::QuickLookHandle&) final;
+    RefPtr<WebCore::QuickLookHandleClient> createQuickLookHandleClient(const String& fileName, const String& uti) final;
 #endif
 
 #if ENABLE(CONTENT_FILTERING)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebFrameLoaderClientIOS.mm (211401 => 211402)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebFrameLoaderClientIOS.mm	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebFrameLoaderClientIOS.mm	2017-01-31 03:06:05 UTC (rev 211402)
@@ -66,16 +66,16 @@
 }
 
 #if USE(QUICK_LOOK)
-void WebFrameLoaderClient::didCreateQuickLookHandle(WebCore::QuickLookHandle& handle)
+RefPtr<QuickLookHandleClient> WebFrameLoaderClient::createQuickLookHandleClient(const String& fileName, const String& uti)
 {
     if (!m_frame->isMainFrame())
-        return;
+        return nullptr;
 
     WebPage* webPage = m_frame->page();
     if (!webPage)
-        return;
+        return nullptr;
 
-    handle.setClient(WebQuickLookHandleClient::create(handle, webPage->pageID()));
+    return WebQuickLookHandleClient::create(fileName, uti, webPage->pageID());
 }
 #endif
 

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp (211401 => 211402)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp	2017-01-31 03:06:05 UTC (rev 211402)
@@ -44,10 +44,10 @@
     return callbackMap.get();
 }
 
-WebQuickLookHandleClient::WebQuickLookHandleClient(const WebCore::QuickLookHandle& handle, uint64_t pageID)
-    : m_fileName(handle.previewFileName())
-    , m_uti(handle.previewUTI())
-    , m_pageID(pageID)
+WebQuickLookHandleClient::WebQuickLookHandleClient(const String& fileName, const String& uti, uint64_t pageID)
+    : m_fileName { fileName }
+    , m_uti { uti }
+    , m_pageID { pageID }
 {
     WebProcess::singleton().send(Messages::WebPageProxy::DidStartLoadForQuickLookDocumentInMainFrame(m_fileName, m_uti), m_pageID);
 }

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h (211401 => 211402)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h	2017-01-31 02:38:07 UTC (rev 211401)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h	2017-01-31 03:06:05 UTC (rev 211402)
@@ -41,9 +41,9 @@
 
 class WebQuickLookHandleClient final : public WebCore::QuickLookHandleClient {
 public:
-    static Ref<WebQuickLookHandleClient> create(const WebCore::QuickLookHandle& handle, uint64_t pageID)
+    static Ref<WebQuickLookHandleClient> create(const String& fileName, const String& uti, uint64_t pageID)
     {
-        return adoptRef(*new WebQuickLookHandleClient(handle, pageID));
+        return adoptRef(*new WebQuickLookHandleClient(fileName, uti, pageID));
     }
     ~WebQuickLookHandleClient();
 
@@ -50,7 +50,7 @@
     static void didReceivePassword(const String&, uint64_t pageID);
 
 private:
-    WebQuickLookHandleClient(const WebCore::QuickLookHandle&, uint64_t pageID);
+    WebQuickLookHandleClient(const String& fileName, const String& uti, uint64_t pageID);
     void didReceiveDataArray(CFArrayRef) override;
     void didFinishLoading() override;
     void didFail() override;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to