Changeset 211402 in webkit


Ignore:
Timestamp:
Jan 30, 2017 7:06:05 PM (7 years ago)
Author:
aestes@apple.com
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:
Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211401 r211402  
     12017-01-30  Andy Estes  <aestes@apple.com>
     2
     3        [QuickLook] FrameLoaderClient should return the new QuickLookHandleClient it creates
     4        https://bugs.webkit.org/show_bug.cgi?id=167625
     5
     6        Reviewed by Andreas Kling.
     7
     8        QuickLookHandleClients were being created by QuickLookHandle calling
     9        FrameLoaderClient::didCreateQuickLookHandle() then having the FrameLoaderClient create a new
     10        QuickLookHandleClient and set it using QuickLookHandle::setClient().
     11
     12        Since all FrameLoaderClient::didCreateQuickLookHandle() does is create a new
     13        QuickLookHandleClient, this patch changes the FrameLoaderClient function to return the new
     14        QuickLookHandleClient directly and removes the API from QuickLookHandle to set a client.
     15        This also removes previewFileName() and previewUTI() from QuickLookHandle and instead passes
     16        these as arguments to the FrameLoaderClient.
     17
     18        No change in behavior. Covered by existing tests.
     19
     20        * loader/EmptyClients.cpp: Added an implementation of createQuickLookHandleClient() that
     21        returns nullptr.
     22        * loader/FrameLoaderClient.h: Declared createQuickLookHandleClient() and removed
     23        didCreateQuickLookHandle().
     24        * loader/ios/QuickLook.h: Removed setClient(), previewFileName(), and previewUTI().
     25        * loader/ios/QuickLook.mm: Removed testingOrEmptyClient().
     26        (-[WebPreviewLoader initWithResourceLoader:resourceResponse:quickLookHandle:]): Set _client
     27        to testingClient() if it exists, otherwise set it to the client returned by
     28        FrameLoaderClient::createQuickLookHandleClient() it non-null, otherwise set it to
     29        emptyClient().
     30        (testingOrEmptyClient): Deleted.
     31        (-[WebPreviewLoader setClient:]): Deleted.
     32        (-[WebPreviewLoader converter]): Deleted.
     33        (WebCore::QuickLookHandle::setClient): Deleted.
     34        (WebCore::QuickLookHandle::previewFileName): Deleted.
     35        (WebCore::QuickLookHandle::previewUTI): Deleted.
     36
    1372017-01-30  Jer Noble  <jer.noble@apple.com>
    238
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r211376 r211402  
    6868#endif
    6969
     70#if USE(QUICK_LOOK)
     71#include "QuickLookHandleClient.h"
     72#endif
     73
    7074namespace WebCore {
    7175
     
    442446    bool isEmptyFrameLoaderClient() final { return true; }
    443447    void prefetchDNS(const String&) final { }
     448
     449#if USE(QUICK_LOOK)
     450    RefPtr<QuickLookHandleClient> createQuickLookHandleClient(const String&, const String&) final { return nullptr; }
     451#endif
    444452};
    445453
  • trunk/Source/WebCore/loader/FrameLoaderClient.h

    r210859 r211402  
    8585class PolicyChecker;
    8686class ProtectionSpace;
    87 class QuickLookHandle;
     87class QuickLookHandleClient;
    8888class RTCPeerConnectionHandler;
    8989class ResourceError;
     
    341341
    342342#if USE(QUICK_LOOK)
    343     virtual void didCreateQuickLookHandle(QuickLookHandle&) { }
     343    virtual RefPtr<QuickLookHandleClient> createQuickLookHandleClient(const String&, const String&) = 0;
    344344#endif
    345345
  • trunk/Source/WebCore/loader/ios/QuickLook.h

    r211398 r211402  
    6464    void didFail();
    6565
    66     WEBCORE_EXPORT void setClient(Ref<QuickLookHandleClient>&&);
    6766    WEBCORE_EXPORT static void setClientForTesting(RefPtr<QuickLookHandleClient>&&);
    68 
    69     WEBCORE_EXPORT String previewFileName() const;
    70     WEBCORE_EXPORT String previewUTI() const;
    7167
    7268private:
  • trunk/Source/WebCore/loader/ios/QuickLook.mm

    r211398 r211402  
    135135}
    136136
    137 static QuickLookHandleClient& testingOrEmptyClient()
    138 {
    139     if (testingClient())
    140         return *testingClient();
    141     return emptyClient();
    142 }
    143 
    144137@interface WebPreviewLoader : NSObject {
    145138    RefPtr<ResourceLoader> _resourceLoader;
     
    153146
    154147- (instancetype)initWithResourceLoader:(ResourceLoader&)resourceLoader resourceResponse:(const ResourceResponse&)resourceResponse quickLookHandle:(QuickLookHandle&)quickLookHandle;
    155 - (void)setClient:(Ref<QuickLookHandleClient>&&)client;
    156148- (void)appendDataArray:(NSArray<NSData *> *)dataArray;
    157149- (void)finishedAppending;
    158150- (void)failed;
    159151
    160 @property (nonatomic, readonly) PreviewConverter* converter;
    161 
    162152@end
    163153
     
    173163    _response = resourceResponse;
    174164    _handle = &quickLookHandle;
    175     _client = &testingOrEmptyClient();
    176165    _converter = std::make_unique<PreviewConverter>(self, _response);
    177166    _bufferedDataArray = adoptNS([[NSMutableArray alloc] init]);
    178167
     168    if (testingClient())
     169        _client = testingClient();
     170    else if (auto client = resourceLoader.frameLoader()->client().createQuickLookHandleClient(_converter->previewFileName(), _converter->previewUTI()))
     171        _client = WTFMove(client);
     172    else
     173        _client = &emptyClient();
     174
    179175    LOG(Network, "WebPreviewConverter created with preview file name \"%s\".", _converter->previewFileName().utf8().data());
    180176    return self;
    181 }
    182 
    183 - (void)setClient:(Ref<QuickLookHandleClient>&&)client
    184 {
    185     if (!testingClient())
    186         _client = WTFMove(client);
    187177}
    188178
     
    207197    [_converter->platformConverter() finishConverting];
    208198    _client->didFail();
    209 }
    210 
    211 - (PreviewConverter*)converter
    212 {
    213     return _converter.get();
    214199}
    215200
     
    327312    : m_previewLoader { adoptNS([[WebPreviewLoader alloc] initWithResourceLoader:loader resourceResponse:response quickLookHandle:*this]) }
    328313{
    329     loader.frameLoader()->client().didCreateQuickLookHandle(*this);
    330314}
    331315
     
    379363}
    380364
    381 void QuickLookHandle::setClient(Ref<QuickLookHandleClient>&& client)
    382 {
    383     [m_previewLoader setClient:WTFMove(client)];
    384 }
    385 
    386365void QuickLookHandle::setClientForTesting(RefPtr<QuickLookHandleClient>&& client)
    387366{
     
    389368}
    390369
    391 String QuickLookHandle::previewFileName() const
    392 {
    393     return [m_previewLoader converter]->previewFileName();
    394 }
    395 
    396 String QuickLookHandle::previewUTI() const
    397 {
    398     return [m_previewLoader converter]->previewUTI();
    399 }
    400 
    401370}
    402371
  • trunk/Source/WebKit/mac/ChangeLog

    r211395 r211402  
     12017-01-30  Andy Estes  <aestes@apple.com>
     2
     3        [QuickLook] FrameLoaderClient should return the new QuickLookHandleClient it creates
     4        https://bugs.webkit.org/show_bug.cgi?id=167625
     5
     6        Reviewed by Andreas Kling.
     7
     8        * WebCoreSupport/WebFrameLoaderClient.h: Declared createQuickLookHandleClient().
     9        * WebCoreSupport/WebFrameLoaderClient.mm:
     10        (WebFrameLoaderClient::createQuickLookHandleClient): Renamed from didCreateQuickLookHandle().
     11        (WebFrameLoaderClient::didCreateQuickLookHandle): Renamed to createQuickLookHandleClient().
     12
    1132017-01-30  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h

    r210859 r211402  
    247247
    248248#if USE(QUICK_LOOK)
    249     void didCreateQuickLookHandle(WebCore::QuickLookHandle&) final;
     249    RefPtr<WebCore::QuickLookHandleClient> createQuickLookHandleClient(const String& fileName, const String& uti) final;
    250250#endif
    251251
  • trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm

    r211355 r211402  
    22262226
    22272227#if USE(QUICK_LOOK)
    2228 void WebFrameLoaderClient::didCreateQuickLookHandle(WebCore::QuickLookHandle& handle)
     2228RefPtr<QuickLookHandleClient> WebFrameLoaderClient::createQuickLookHandleClient(const String& fileName, const String& uti)
    22292229{
    22302230    class QuickLookDocumentWriter : public WebCore::QuickLookHandleClient {
     
    22642264
    22652265    if (![m_webFrame webView].preferences.quickLookDocumentSavingEnabled)
    2266         return;
    2267 
    2268     NSString *filePath = createTemporaryFileForQuickLook(handle.previewFileName());
     2266        return nullptr;
     2267
     2268    NSString *filePath = createTemporaryFileForQuickLook(fileName);
    22692269    if (!filePath)
    2270         return;
    2271 
    2272     [m_webFrame provisionalDataSource]._quickLookContent = @{ WebQuickLookFileNameKey : filePath, WebQuickLookUTIKey : handle.previewUTI() };
    2273     handle.setClient(adoptRef(*new QuickLookDocumentWriter(filePath)));
     2270        return nullptr;
     2271
     2272    [m_webFrame provisionalDataSource]._quickLookContent = @{ WebQuickLookFileNameKey : filePath, WebQuickLookUTIKey : uti };
     2273    return adoptRef(*new QuickLookDocumentWriter(filePath));
    22742274}
    22752275#endif
  • trunk/Source/WebKit2/ChangeLog

    r211390 r211402  
     12017-01-30  Andy Estes  <aestes@apple.com>
     2
     3        [QuickLook] FrameLoaderClient should return the new QuickLookHandleClient it creates
     4        https://bugs.webkit.org/show_bug.cgi?id=167625
     5
     6        Reviewed by Andreas Kling.
     7
     8        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h: Declared createQuickLookHandleClient().
     9        * WebProcess/WebCoreSupport/ios/WebFrameLoaderClientIOS.mm:
     10        (WebKit::WebFrameLoaderClient::createQuickLookHandleClient): Renamed from didCreateQuickLookHandle().
     11        (WebKit::WebFrameLoaderClient::didCreateQuickLookHandle): Renamed to createQuickLookHandleClient().
     12        * WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp:
     13        (WebKit::WebQuickLookHandleClient::WebQuickLookHandleClient): Set m_fileName and m_uti from
     14        the constructor arguments instead of from handle.
     15        * WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h:
     16
    1172017-01-30  Anders Carlsson  <andersca@apple.com>
    218
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.h

    r210859 r211402  
    246246
    247247#if USE(QUICK_LOOK)
    248     void didCreateQuickLookHandle(WebCore::QuickLookHandle&) final;
     248    RefPtr<WebCore::QuickLookHandleClient> createQuickLookHandleClient(const String& fileName, const String& uti) final;
    249249#endif
    250250
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebFrameLoaderClientIOS.mm

    r174380 r211402  
    6767
    6868#if USE(QUICK_LOOK)
    69 void WebFrameLoaderClient::didCreateQuickLookHandle(WebCore::QuickLookHandle& handle)
     69RefPtr<QuickLookHandleClient> WebFrameLoaderClient::createQuickLookHandleClient(const String& fileName, const String& uti)
    7070{
    7171    if (!m_frame->isMainFrame())
    72         return;
     72        return nullptr;
    7373
    7474    WebPage* webPage = m_frame->page();
    7575    if (!webPage)
    76         return;
     76        return nullptr;
    7777
    78     handle.setClient(WebQuickLookHandleClient::create(handle, webPage->pageID()));
     78    return WebQuickLookHandleClient::create(fileName, uti, webPage->pageID());
    7979}
    8080#endif
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp

    r211165 r211402  
    4545}
    4646
    47 WebQuickLookHandleClient::WebQuickLookHandleClient(const WebCore::QuickLookHandle& handle, uint64_t pageID)
    48     : m_fileName(handle.previewFileName())
    49     , m_uti(handle.previewUTI())
    50     , m_pageID(pageID)
     47WebQuickLookHandleClient::WebQuickLookHandleClient(const String& fileName, const String& uti, uint64_t pageID)
     48    : m_fileName { fileName }
     49    , m_uti { uti }
     50    , m_pageID { pageID }
    5151{
    5252    WebProcess::singleton().send(Messages::WebPageProxy::DidStartLoadForQuickLookDocumentInMainFrame(m_fileName, m_uti), m_pageID);
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h

    r211172 r211402  
    4242class WebQuickLookHandleClient final : public WebCore::QuickLookHandleClient {
    4343public:
    44     static Ref<WebQuickLookHandleClient> create(const WebCore::QuickLookHandle& handle, uint64_t pageID)
     44    static Ref<WebQuickLookHandleClient> create(const String& fileName, const String& uti, uint64_t pageID)
    4545    {
    46         return adoptRef(*new WebQuickLookHandleClient(handle, pageID));
     46        return adoptRef(*new WebQuickLookHandleClient(fileName, uti, pageID));
    4747    }
    4848    ~WebQuickLookHandleClient();
     
    5151
    5252private:
    53     WebQuickLookHandleClient(const WebCore::QuickLookHandle&, uint64_t pageID);
     53    WebQuickLookHandleClient(const String& fileName, const String& uti, uint64_t pageID);
    5454    void didReceiveDataArray(CFArrayRef) override;
    5555    void didFinishLoading() override;
Note: See TracChangeset for help on using the changeset viewer.