<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[210789] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/210789">210789</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2017-01-16 14:14:27 -0800 (Mon, 16 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[QuickLook] Do some cleanup in QuickLookHandle
https://bugs.webkit.org/show_bug.cgi?id=166864

Reviewed by Darin Adler.

Source/WebCore:

* loader/ios/QuickLook.h: Stopped including QuickLookHandleClient.h and forward-declared
instead; changed setClient() to take a Ref&lt;QuickLookHandleClient&gt;&amp;&amp;; renamed nsResponse() to
previewResponse(); changed QuickLookHandle() to take a ResourceLoader&amp; and const
ResourceResponse&amp;; gave m_delegate a stronger type; removed unused m_quicklookFileHandle;
initialized m_finishedLoadingDataIntoConverter to false.
(WebCore::QuickLookHandle::firstRequestURL): Stopped exporting.
(WebCore::QuickLookHandle::setClient): Moved definition out-of-line.
* loader/ios/QuickLook.mm: Renamed WebResourceLoaderQuickLookDelegate to
WebPreviewConverterDelegate and stopped conforming to NSURLConnectionDelegate and
WebCoreResourceLoaderDelegate; removed @property quickLookHandle and initialized
_quickLookHandle in the initializer instead.
(-[WebPreviewConverter initWithResourceLoader:quickLookHandle:]): Changed to take references
to resourceLoader and quickLookHandle.
(-[WebPreviewConverter _sendDidReceiveResponseIfNecessary]): Stoped checking for a nil
_quickLookHandle, since it is never nil.
(-[WebResourceLoaderQuickLookDelegate connection:didReceiveDataArray:]): Deleted.
QLPreviewConverter never calls this method.
(-[WebPreviewConverter connection:didReceiveData:lengthReceived:]): Stopped checking for a
nil _resourceLoader, since it is never nil.
(-[WebPreviewConverter connectionDidFinishLoading:]): Ditto.
(-[WebPreviewConverter connection:didFailWithError:]): Ditto.
(WebCore::emptyClient): Changed to return a reference.
(WebCore::QuickLookHandle::QuickLookHandle): Moved creation of the delegate,
firstRequestURL, and response to here from QuickLookHandle::create(). Called
ResourceLoader::didCreateQuickLookHandle() here instead of in QuickLookHandle::create().
(WebCore::QuickLookHandle::create): Used std::make_unique to create the QuickLookHandle.
(WebCore::QuickLookHandle::didFinishLoading): Set m_finishedLoadingDataIntoConverter to true
instead of YES.
(WebCore::QuickLookHandle::setClient): Moved the client rvalue reference into m_client.
(WebCore::QuickLookHandle::~QuickLookHandle): Stopped clearing m_converter and calling
-detachHandle.
(WebCore::QuickLookHandle::previewRequestURL): Used dot syntax.
(WebCore::QuickLookHandle::previewResponse): Renamed from nsResponse().

Source/WebKit/mac:

* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::didCreateQuickLookHandle): Changed to pass a
Ref&lt;QuickLookHandleClient&gt;&amp;&amp; to QuickLookHandle::setClient().</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloaderiosQuickLookh">trunk/Source/WebCore/loader/ios/QuickLook.h</a></li>
<li><a href="#trunkSourceWebCoreloaderiosQuickLookmm">trunk/Source/WebCore/loader/ios/QuickLook.mm</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebFrameLoaderClientmm">trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (210788 => 210789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-16 21:11:53 UTC (rev 210788)
+++ trunk/Source/WebCore/ChangeLog        2017-01-16 22:14:27 UTC (rev 210789)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2017-01-16  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [QuickLook] Do some cleanup in QuickLookHandle
+        https://bugs.webkit.org/show_bug.cgi?id=166864
+
+        Reviewed by Darin Adler.
+
+        * loader/ios/QuickLook.h: Stopped including QuickLookHandleClient.h and forward-declared
+        instead; changed setClient() to take a Ref&lt;QuickLookHandleClient&gt;&amp;&amp;; renamed nsResponse() to
+        previewResponse(); changed QuickLookHandle() to take a ResourceLoader&amp; and const
+        ResourceResponse&amp;; gave m_delegate a stronger type; removed unused m_quicklookFileHandle;
+        initialized m_finishedLoadingDataIntoConverter to false.
+        (WebCore::QuickLookHandle::firstRequestURL): Stopped exporting.
+        (WebCore::QuickLookHandle::setClient): Moved definition out-of-line.
+        * loader/ios/QuickLook.mm: Renamed WebResourceLoaderQuickLookDelegate to
+        WebPreviewConverterDelegate and stopped conforming to NSURLConnectionDelegate and
+        WebCoreResourceLoaderDelegate; removed @property quickLookHandle and initialized
+        _quickLookHandle in the initializer instead.
+        (-[WebPreviewConverter initWithResourceLoader:quickLookHandle:]): Changed to take references
+        to resourceLoader and quickLookHandle.
+        (-[WebPreviewConverter _sendDidReceiveResponseIfNecessary]): Stoped checking for a nil
+        _quickLookHandle, since it is never nil.
+        (-[WebResourceLoaderQuickLookDelegate connection:didReceiveDataArray:]): Deleted.
+        QLPreviewConverter never calls this method.
+        (-[WebPreviewConverter connection:didReceiveData:lengthReceived:]): Stopped checking for a
+        nil _resourceLoader, since it is never nil.
+        (-[WebPreviewConverter connectionDidFinishLoading:]): Ditto.
+        (-[WebPreviewConverter connection:didFailWithError:]): Ditto.
+        (WebCore::emptyClient): Changed to return a reference.
+        (WebCore::QuickLookHandle::QuickLookHandle): Moved creation of the delegate,
+        firstRequestURL, and response to here from QuickLookHandle::create(). Called
+        ResourceLoader::didCreateQuickLookHandle() here instead of in QuickLookHandle::create().
+        (WebCore::QuickLookHandle::create): Used std::make_unique to create the QuickLookHandle.
+        (WebCore::QuickLookHandle::didFinishLoading): Set m_finishedLoadingDataIntoConverter to true
+        instead of YES.
+        (WebCore::QuickLookHandle::setClient): Moved the client rvalue reference into m_client.
+        (WebCore::QuickLookHandle::~QuickLookHandle): Stopped clearing m_converter and calling
+        -detachHandle.
+        (WebCore::QuickLookHandle::previewRequestURL): Used dot syntax.
+        (WebCore::QuickLookHandle::previewResponse): Renamed from nsResponse().
+
</ins><span class="cx"> 2017-01-16  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove CSSPropertyNames.in from the project. It's not used any more,
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderiosQuickLookh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ios/QuickLook.h (210788 => 210789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ios/QuickLook.h        2017-01-16 21:11:53 UTC (rev 210788)
+++ trunk/Source/WebCore/loader/ios/QuickLook.h        2017-01-16 22:14:27 UTC (rev 210789)
</span><span class="lines">@@ -27,16 +27,14 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx"> 
</span><del>-#include &quot;QuickLookHandleClient.h&quot;
</del><span class="cx"> #include &lt;objc/objc.h&gt;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><del>-#include &lt;wtf/RefPtr.h&gt;
</del><ins>+#include &lt;wtf/Ref.h&gt;
</ins><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> OBJC_CLASS NSArray;
</span><span class="cx"> OBJC_CLASS NSData;
</span><span class="cx"> OBJC_CLASS NSDictionary;
</span><del>-OBJC_CLASS NSFileHandle;
</del><span class="cx"> OBJC_CLASS NSSet;
</span><span class="cx"> OBJC_CLASS NSString;
</span><span class="cx"> OBJC_CLASS NSURL;
</span><span class="lines">@@ -43,9 +41,11 @@
</span><span class="cx"> OBJC_CLASS NSURLRequest;
</span><span class="cx"> OBJC_CLASS NSURLResponse;
</span><span class="cx"> OBJC_CLASS QLPreviewConverter;
</span><ins>+OBJC_CLASS WebPreviewConverterDelegate;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class QuickLookHandleClient;
</ins><span class="cx"> class ResourceLoader;
</span><span class="cx"> class ResourceResponse;
</span><span class="cx"> class SharedBuffer;
</span><span class="lines">@@ -82,28 +82,27 @@
</span><span class="cx">     bool didFinishLoading();
</span><span class="cx">     void didFail();
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT NSURLResponse *nsResponse();
</del><ins>+    WEBCORE_EXPORT void setClient(Ref&lt;QuickLookHandleClient&gt;&amp;&amp;);
</ins><span class="cx"> 
</span><del>-    void setClient(PassRefPtr&lt;QuickLookHandleClient&gt; client) { m_client = client; }
-
</del><span class="cx">     WEBCORE_EXPORT String previewFileName() const;
</span><span class="cx">     WEBCORE_EXPORT String previewUTI() const;
</span><ins>+    WEBCORE_EXPORT NSURL *previewRequestURL() const;
+    NSURLResponse *previewResponse() const;
</ins><span class="cx">     NSURL *firstRequestURL() const { return m_firstRequestURL.get(); }
</span><del>-    WEBCORE_EXPORT NSURL *previewRequestURL() const;
</del><span class="cx">     QLPreviewConverter *converter() const { return m_converter.get(); }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    QuickLookHandle(NSURL *, NSURLResponse *, id delegate);
</del><ins>+    friend std::unique_ptr&lt;QuickLookHandle&gt; std::make_unique&lt;QuickLookHandle&gt;(ResourceLoader&amp;, const ResourceResponse&amp;);
+    QuickLookHandle(ResourceLoader&amp;, const ResourceResponse&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void didReceiveDataArray(NSArray *);
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;NSURL&gt; m_firstRequestURL;
</span><ins>+    RetainPtr&lt;WebPreviewConverterDelegate&gt; m_delegate;
</ins><span class="cx">     RetainPtr&lt;QLPreviewConverter&gt; m_converter;
</span><del>-    RetainPtr&lt;id&gt; m_delegate;
-    bool m_finishedLoadingDataIntoConverter;
-    RetainPtr&lt;NSFileHandle *&gt; m_quicklookFileHandle;
-    RetainPtr&lt;NSURLResponse&gt; m_nsResponse;
-    RefPtr&lt;QuickLookHandleClient&gt; m_client;
</del><ins>+    RetainPtr&lt;NSURLResponse&gt; m_previewResponse;
+    Ref&lt;QuickLookHandleClient&gt; m_client;
+    bool m_finishedLoadingDataIntoConverter { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderiosQuickLookmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ios/QuickLook.mm (210788 => 210789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ios/QuickLook.mm        2017-01-16 21:11:53 UTC (rev 210788)
+++ trunk/Source/WebCore/loader/ios/QuickLook.mm        2017-01-16 22:14:27 UTC (rev 210789)
</span><span class="lines">@@ -31,11 +31,10 @@
</span><span class="cx"> #import &quot;FileSystemIOS.h&quot;
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;NSFileManagerSPI.h&quot;
</span><ins>+#import &quot;QuickLookHandleClient.h&quot;
</ins><span class="cx"> #import &quot;ResourceError.h&quot;
</span><span class="cx"> #import &quot;ResourceLoader.h&quot;
</span><span class="cx"> #import &quot;SharedBuffer.h&quot;
</span><del>-#import &quot;WebCoreResourceHandleAsDelegate.h&quot;
-#import &lt;Foundation/Foundation.h&gt;
</del><span class="cx"> #import &lt;wtf/NeverDestroyed.h&gt;
</span><span class="cx"> #import &lt;wtf/Vector.h&gt;
</span><span class="cx"> #import &lt;wtf/text/WTFString.h&gt;
</span><span class="lines">@@ -179,41 +178,42 @@
</span><span class="cx">     return previewProtocol.get().data();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-@interface WebResourceLoaderQuickLookDelegate : NSObject &lt;NSURLConnectionDelegate, WebCoreResourceLoaderDelegate&gt; {
</del><ins>+@interface WebPreviewConverterDelegate : NSObject {
</ins><span class="cx">     RefPtr&lt;ResourceLoader&gt; _resourceLoader;
</span><ins>+    QuickLookHandle* _quickLookHandle;
</ins><span class="cx">     BOOL _hasSentDidReceiveResponse;
</span><span class="cx">     BOOL _hasFailed;
</span><span class="cx"> }
</span><del>-@property (nonatomic) QuickLookHandle* quickLookHandle;
</del><span class="cx"> @end
</span><span class="cx"> 
</span><del>-@implementation WebResourceLoaderQuickLookDelegate
</del><ins>+@implementation WebPreviewConverterDelegate
</ins><span class="cx"> 
</span><del>-- (id)initWithResourceLoader:(PassRefPtr&lt;ResourceLoader&gt;)resourceLoader
</del><ins>+- (id)initWithResourceLoader:(ResourceLoader&amp;)resourceLoader quickLookHandle:(QuickLookHandle&amp;)quickLookHandle
</ins><span class="cx"> {
</span><span class="cx">     self = [super init];
</span><span class="cx">     if (!self)
</span><span class="cx">         return nil;
</span><span class="cx"> 
</span><del>-    _resourceLoader = resourceLoader;
</del><ins>+    _resourceLoader = &amp;resourceLoader;
+    _quickLookHandle = &amp;quickLookHandle;
</ins><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)_sendDidReceiveResponseIfNecessary
</span><span class="cx"> {
</span><del>-    if (_hasSentDidReceiveResponse || _hasFailed || !_quickLookHandle)
</del><ins>+    if (_hasSentDidReceiveResponse || _hasFailed)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     // QuickLook might fail to convert a document without calling connection:didFailWithError: (see &lt;rdar://problem/17927972&gt;).
</span><span class="cx">     // A nil MIME type is an indication of such a failure, so stop loading the resource and ignore subsequent delegate messages.
</span><del>-    NSURLResponse *nsResponse = _quickLookHandle-&gt;nsResponse();
-    if (![nsResponse MIMEType]) {
</del><ins>+    NSURLResponse *previewResponse = _quickLookHandle-&gt;previewResponse();
+    if (!previewResponse.MIMEType) {
</ins><span class="cx">         _hasFailed = YES;
</span><span class="cx">         _resourceLoader-&gt;didFail(_resourceLoader-&gt;cannotShowURLError());
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ResourceResponse response(nsResponse);
</del><ins>+    ResourceResponse response { previewResponse };
</ins><span class="cx">     response.setIsQuickLook(true);
</span><span class="cx"> 
</span><span class="cx">     _hasSentDidReceiveResponse = YES;
</span><span class="lines">@@ -220,28 +220,9 @@
</span><span class="cx">     _resourceLoader-&gt;didReceiveResponse(response);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-- (void)connection:(NSURLConnection *)connection didReceiveDataArray:(NSArray *)dataArray
-{
-    UNUSED_PARAM(connection);
-    if (!_resourceLoader)
-        return;
-
-    [self _sendDidReceiveResponseIfNecessary];
-    if (_hasFailed)
-        return;
-
-    if (_resourceLoader)
-        _resourceLoader-&gt;didReceiveDataArray(reinterpret_cast&lt;CFArrayRef&gt;(dataArray));
-}
-#endif
-
</del><span class="cx"> - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(connection);
</span><del>-    if (!_resourceLoader)
-        return;
-
</del><span class="cx">     [self _sendDidReceiveResponseIfNecessary];
</span><span class="cx">     if (_hasFailed)
</span><span class="cx">         return;
</span><span class="lines">@@ -248,17 +229,14 @@
</span><span class="cx"> 
</span><span class="cx">     // QuickLook code sends us a nil data at times. The check below is the same as the one in
</span><span class="cx">     // ResourceHandleMac.cpp added for a different bug.
</span><del>-    if (![data length])
-        return;
-
-    if (_resourceLoader)
-        _resourceLoader-&gt;didReceiveData(reinterpret_cast&lt;const char*&gt;([data bytes]), [data length], lengthReceived, DataPayloadBytes);
</del><ins>+    if (auto dataLength = data.length)
+        _resourceLoader-&gt;didReceiveData(reinterpret_cast&lt;const char*&gt;(data.bytes), dataLength, lengthReceived, DataPayloadBytes);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)connectionDidFinishLoading:(NSURLConnection *)connection
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(connection);
</span><del>-    if (!_resourceLoader || _hasFailed)
</del><ins>+    if (_hasFailed)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     ASSERT(_hasSentDidReceiveResponse);
</span><span class="lines">@@ -268,21 +246,11 @@
</span><span class="cx"> - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
</span><span class="cx"> {
</span><span class="cx">     UNUSED_PARAM(connection);
</span><del>-
</del><span class="cx">     [self _sendDidReceiveResponseIfNecessary];
</span><del>-    if (_hasFailed)
-        return;
-
-    if (_resourceLoader)
-        _resourceLoader-&gt;didFail(ResourceError(error));
</del><ins>+    if (!_hasFailed)
+        _resourceLoader-&gt;didFail(error);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)detachHandle
-{
-    _resourceLoader = nullptr;
-    _quickLookHandle = nullptr;
-}
-
</del><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -305,21 +273,21 @@
</span><span class="cx">     return success ? uniqueContentPath : nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline QuickLookHandleClient* emptyClient()
</del><ins>+static inline QuickLookHandleClient&amp; emptyClient()
</ins><span class="cx"> {
</span><del>-    static NeverDestroyed&lt;QuickLookHandleClient&gt; emptyClient;
-    return &amp;emptyClient.get();
</del><ins>+    static auto&amp; emptyClient = adoptRef(*new QuickLookHandleClient()).leakRef();
+    return emptyClient;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-QuickLookHandle::QuickLookHandle(NSURL *firstRequestURL, NSURLResponse *nsResponse, id delegate)
-    : m_firstRequestURL(firstRequestURL)
-    , m_converter(adoptNS([allocQLPreviewConverterInstance() initWithConnection:nil delegate:delegate response:nsResponse options:nil]))
-    , m_delegate(delegate)
-    , m_finishedLoadingDataIntoConverter(false)
-    , m_nsResponse([m_converter previewResponse])
-    , m_client(emptyClient())
</del><ins>+QuickLookHandle::QuickLookHandle(ResourceLoader&amp; loader, const ResourceResponse&amp; response)
+    : m_firstRequestURL { loader.originalRequest().nsURLRequest(DoNotUpdateHTTPBody).URL }
+    , m_delegate { adoptNS([[WebPreviewConverterDelegate alloc] initWithResourceLoader:loader quickLookHandle:*this]) }
+    , m_converter { adoptNS([allocQLPreviewConverterInstance() initWithConnection:nil delegate:m_delegate.get() response:response.nsURLResponse() options:nil]) }
+    , m_previewResponse { [m_converter previewResponse] }
+    , m_client { emptyClient() }
</ins><span class="cx"> {
</span><span class="cx">     LOG(Network, &quot;QuickLookHandle::QuickLookHandle() - previewFileName: %s&quot;, [m_converter previewFileName]);
</span><ins>+    loader.didCreateQuickLookHandle(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool QuickLookHandle::shouldCreateForMIMEType(const String&amp; mimeType)
</span><span class="lines">@@ -330,19 +298,9 @@
</span><span class="cx"> std::unique_ptr&lt;QuickLookHandle&gt; QuickLookHandle::create(ResourceLoader&amp; loader, const ResourceResponse&amp; response)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(shouldCreateForMIMEType(response.mimeType()));
</span><del>-
-    RetainPtr&lt;WebResourceLoaderQuickLookDelegate&gt; delegate = adoptNS([[WebResourceLoaderQuickLookDelegate alloc] initWithResourceLoader:&amp;loader]);
-    std::unique_ptr&lt;QuickLookHandle&gt; quickLookHandle(new QuickLookHandle([loader.originalRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], response.nsURLResponse(), delegate.get()));
-    [delegate setQuickLookHandle:quickLookHandle.get()];
-    loader.didCreateQuickLookHandle(*quickLookHandle);
-    return quickLookHandle;
</del><ins>+    return std::make_unique&lt;QuickLookHandle&gt;(loader, response);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-NSURLResponse *QuickLookHandle::nsResponse()
-{
-    return m_nsResponse.get();
-}
-
</del><span class="cx"> bool QuickLookHandle::didReceiveData(const char* data, unsigned length)
</span><span class="cx"> {
</span><span class="cx">     if (m_finishedLoadingDataIntoConverter)
</span><span class="lines">@@ -375,7 +333,7 @@
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     LOG(Network, &quot;QuickLookHandle::didFinishLoading()&quot;);
</span><del>-    m_finishedLoadingDataIntoConverter = YES;
</del><ins>+    m_finishedLoadingDataIntoConverter = true;
</ins><span class="cx">     [m_converter finishedAppendingData];
</span><span class="cx">     m_client-&gt;didFinishLoading();
</span><span class="cx">     return true;
</span><span class="lines">@@ -389,12 +347,14 @@
</span><span class="cx">     m_converter = nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void QuickLookHandle::setClient(Ref&lt;QuickLookHandleClient&gt;&amp;&amp; client)
+{
+    m_client = WTFMove(client);
+}
+
</ins><span class="cx"> QuickLookHandle::~QuickLookHandle()
</span><span class="cx"> {
</span><span class="cx">     LOG(Network, &quot;QuickLookHandle::~QuickLookHandle()&quot;);
</span><del>-    m_converter = nullptr;
-
-    [m_delegate detachHandle];
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String QuickLookHandle::previewFileName() const
</span><span class="lines">@@ -409,9 +369,14 @@
</span><span class="cx"> 
</span><span class="cx"> NSURL *QuickLookHandle::previewRequestURL() const
</span><span class="cx"> {
</span><del>-    return [[m_converter previewRequest] URL];
</del><ins>+    return [m_converter previewRequest].URL;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+NSURLResponse *QuickLookHandle::previewResponse() const
+{
+    return m_previewResponse.get();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif // USE(QUICK_LOOK)
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (210788 => 210789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2017-01-16 21:11:53 UTC (rev 210788)
+++ trunk/Source/WebKit/mac/ChangeLog        2017-01-16 22:14:27 UTC (rev 210789)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2017-01-16  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [QuickLook] Do some cleanup in QuickLookHandle
+        https://bugs.webkit.org/show_bug.cgi?id=166864
+
+        Reviewed by Darin Adler.
+
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::didCreateQuickLookHandle): Changed to pass a
+        Ref&lt;QuickLookHandleClient&gt;&amp;&amp; to QuickLookHandle::setClient().
+
</ins><span class="cx"> 2017-01-15  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         De-duplicate more (nearly) identical code in Editor(Mac|IOS).mm
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebFrameLoaderClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm (210788 => 210789)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm        2017-01-16 21:11:53 UTC (rev 210788)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm        2017-01-16 22:14:27 UTC (rev 210789)
</span><span class="lines">@@ -152,6 +152,7 @@
</span><span class="cx"> #import &lt;WebCore/FileSystemIOS.h&gt;
</span><span class="cx"> #import &lt;WebCore/NSFileManagerSPI.h&gt;
</span><span class="cx"> #import &lt;WebCore/QuickLook.h&gt;
</span><ins>+#import &lt;WebCore/QuickLookHandleClient.h&gt;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if HAVE(APP_LINKS)
</span><span class="lines">@@ -2283,7 +2284,7 @@
</span><span class="cx">             removeQLPreviewConverterForURL(m_firstRequestURL.get());
</span><span class="cx">         }
</span><span class="cx">     };
</span><del>-    handle.setClient(adoptRef(new QuickLookDocumentWriter(handle)));
</del><ins>+    handle.setClient(adoptRef(*new QuickLookDocumentWriter(handle)));
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>