<!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>[167207] 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/167207">167207</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2014-04-13 19:57:33 -0700 (Sun, 13 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoaderClienth">trunk/Source/WebCore/loader/FrameLoaderClient.h</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadercpp">trunk/Source/WebCore/loader/ResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoaderh">trunk/Source/WebCore/loader/ResourceLoader.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceHandleh">trunk/Source/WebCore/platform/network/ResourceHandle.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceHandleClienth">trunk/Source/WebCore/platform/network/ResourceHandleClient.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkiosQuickLookh">trunk/Source/WebCore/platform/network/ios/QuickLook.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkiosQuickLookmm">trunk/Source/WebCore/platform/network/ios/QuickLook.mm</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebFrameLoaderClienth">trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebFrameLoaderClientmm">trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessNetworkWebResourceLoaderh">trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformnetworkiosQuickLookHandleClienth">trunk/Source/WebCore/platform/network/ios/QuickLookHandleClient.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,61 @@
</span><ins>+2014-04-13  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [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):
+
</ins><span class="cx"> 2014-04-10  Pratik Solanki  &lt;psolanki@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Move early return out of dispatch_async() block so we can return from willSendRequest quickly
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -3218,9 +3218,13 @@
</span><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx"> __ZN7WebCore27qlPreviewConverterUTIForURLEP5NSURL
</span><span class="cx"> __ZN7WebCore30removeQLPreviewConverterForURLEP5NSURL
</span><ins>+__ZN7WebCore31createTemporaryFileForQuickLookEP8NSString
</ins><span class="cx"> __ZN7WebCore32qlPreviewConverterFileNameForURLEP5NSURL
</span><span class="cx"> __ZN7WebCore33QLPreviewGetSupportedMIMETypesSetEv
</span><span class="cx"> __ZN7WebCore34registerQLPreviewConverterIfNeededEP5NSURLP8NSStringP6NSData
</span><ins>+__ZN7WebCore35addQLPreviewConverterWithFileForURLEP5NSURLP11objc_objectP8NSString
+__ZNK7WebCore15QuickLookHandle15previewFileNameEv
+__ZNK7WebCore15QuickLookHandle17previewRequestURLEv
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -3607,6 +3607,7 @@
</span><span class="cx">                 A104F24414C71F7A009E2C23 /* CachedSVGDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = A104F24214C71F7A009E2C23 /* CachedSVGDocument.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A10BB5851484E3A700B2E87A /* RenderSVGRect.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5831484E3A700B2E87A /* RenderSVGRect.h */; };
</span><span class="cx">                 A10BB58B1484E3B300B2E87A /* RenderSVGShape.h in Headers */ = {isa = PBXBuildFile; fileRef = A10BB5891484E3B300B2E87A /* RenderSVGShape.h */; };
</span><ins>+                A10DBF4718F92317000D70C6 /* QuickLookHandleClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A10DBF4618F92317000D70C6 /* QuickLookHandleClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 A10DC76A14747BAB005E2471 /* StyleGridData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10DC76814747BAB005E2471 /* StyleGridData.cpp */; };
</span><span class="cx">                 A10DC76B14747BAB005E2471 /* StyleGridData.h in Headers */ = {isa = PBXBuildFile; fileRef = A10DC76914747BAB005E2471 /* StyleGridData.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A110DB9B14F5DF7700A03B93 /* StyleGridItemData.h in Headers */ = {isa = PBXBuildFile; fileRef = A110DB9A14F5DF7700A03B93 /* StyleGridItemData.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -10667,6 +10668,7 @@
</span><span class="cx">                 A10BB5831484E3A700B2E87A /* RenderSVGRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGRect.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 A10BB5881484E3B300B2E87A /* RenderSVGShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGShape.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 A10BB5891484E3B300B2E87A /* RenderSVGShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGShape.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                A10DBF4618F92317000D70C6 /* QuickLookHandleClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLookHandleClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 A10DC76814747BAB005E2471 /* StyleGridData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleGridData.cpp; path = style/StyleGridData.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 A10DC76914747BAB005E2471 /* StyleGridData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleGridData.h; path = style/StyleGridData.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 A110DB9A14F5DF7700A03B93 /* StyleGridItemData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleGridItemData.h; path = style/StyleGridItemData.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -15482,6 +15484,7 @@
</span><span class="cx">                                 443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */,
</span><span class="cx">                                 442AF7A7102CDDEA008FD4D3 /* QuickLook.h */,
</span><span class="cx">                                 442AF7A8102CDDEA008FD4D3 /* QuickLook.mm */,
</span><ins>+                                A10DBF4618F92317000D70C6 /* QuickLookHandleClient.h */,
</ins><span class="cx">                                 7E428CE413E3407F003B661C /* ResourceHandleIOS.mm */,
</span><span class="cx">                                 44A20DB80F84166C00B3E1FE /* WebCoreURLResponseIOS.h */,
</span><span class="cx">                                 444D4E210F708B2E003158E0 /* WebCoreURLResponseIOS.mm */,
</span><span class="lines">@@ -25807,6 +25810,7 @@
</span><span class="cx">                                 B2227A540D00BF220071B782 /* SVGPaint.h in Headers */,
</span><span class="cx">                                 B2227A570D00BF220071B782 /* SVGParserUtilities.h in Headers */,
</span><span class="cx">                                 2D3A0E3613A7D76100E85AF0 /* SVGParsingError.h in Headers */,
</span><ins>+                                A10DBF4718F92317000D70C6 /* QuickLookHandleClient.h in Headers */,
</ins><span class="cx">                                 84C6784D1214814700A92902 /* SVGPathBlender.h in Headers */,
</span><span class="cx">                                 8476C9EB11DF6A2900555B02 /* SVGPathBuilder.h in Headers */,
</span><span class="cx">                                 8419D2A7120D92D000141F8F /* SVGPathByteStream.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoaderClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -97,6 +97,10 @@
</span><span class="cx">     class SubstituteData;
</span><span class="cx">     class Widget;
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+    class QuickLookHandle;
+#endif
+
</ins><span class="cx">     typedef std::function&lt;void (PolicyAction)&gt; FramePolicyFunction;
</span><span class="cx"> 
</span><span class="cx">     class FrameLoaderClient {
</span><span class="lines">@@ -334,6 +338,10 @@
</span><span class="cx"> 
</span><span class="cx">         // FIXME (bug 116233): We need to get rid of EmptyFrameLoaderClient completely, then this will no longer be needed.
</span><span class="cx">         virtual bool isEmptyFrameLoaderClient() { return false; }
</span><ins>+
+#if USE(QUICK_LOOK)
+        virtual void didCreateQuickLookHandle(QuickLookHandle&amp;) { }
+#endif
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -606,4 +606,11 @@
</span><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+void ResourceLoader::didCreateQuickLookHandle(QuickLookHandle&amp; handle)
+{
+    frameLoader()-&gt;client().didCreateQuickLookHandle(handle);
</ins><span class="cx"> }
</span><ins>+#endif
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoader.h (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -49,6 +49,10 @@
</span><span class="cx"> class URL;
</span><span class="cx"> class ResourceBuffer;
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+class QuickLookHandle;
+#endif
+
</ins><span class="cx"> class ResourceLoader : public RefCounted&lt;ResourceLoader&gt;, protected ResourceHandleClient {
</span><span class="cx"> public:
</span><span class="cx">     virtual ~ResourceLoader();
</span><span class="lines">@@ -146,6 +150,10 @@
</span><span class="cx">     virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*) override;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+    virtual void didCreateQuickLookHandle(QuickLookHandle&amp;) override;
+#endif
+
</ins><span class="cx">     const URL&amp; url() const { return m_request.url(); }
</span><span class="cx">     ResourceHandle* handle() const { return m_handle.get(); }
</span><span class="cx">     bool shouldSendResourceLoadCallbacks() const { return m_options.sendLoadCallbacks == SendCallbacks; }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceHandle.h (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -150,7 +150,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx">     QuickLookHandle* quickLookHandle() { return m_quickLook.get(); }
</span><del>-    void setQuickLookHandle(PassOwnPtr&lt;QuickLookHandle&gt; handle) { m_quickLook = handle; }
</del><ins>+    void setQuickLookHandle(std::unique_ptr&lt;QuickLookHandle&gt; handle) { m_quickLook = std::move(handle); }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(WIN) &amp;&amp; USE(CURL)
</span><span class="lines">@@ -292,7 +292,7 @@
</span><span class="cx">     OwnPtr&lt;ResourceHandleInternal&gt; d;
</span><span class="cx"> 
</span><span class="cx"> #if USE(QUICK_LOOK)
</span><del>-    OwnPtr&lt;QuickLookHandle&gt; m_quickLook;
</del><ins>+    std::unique_ptr&lt;QuickLookHandle&gt; m_quickLook;
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceHandleClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceHandleClient.h (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -50,6 +50,10 @@
</span><span class="cx">     class ResourceResponse;
</span><span class="cx">     class SharedBuffer;
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+    class QuickLookHandle;
+#endif
+
</ins><span class="cx">     enum CacheStoragePolicy {
</span><span class="cx">         StorageAllowed,
</span><span class="cx">         StorageAllowedInMemoryOnly,
</span><span class="lines">@@ -124,6 +128,9 @@
</span><span class="cx">         virtual NSCachedURLResponse *willCacheResponse(ResourceHandle*, NSCachedURLResponse *response) { return response; }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+        virtual void didCreateQuickLookHandle(QuickLookHandle&amp;) { }
+#endif
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkiosQuickLookh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ios/QuickLook.h (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -28,29 +28,21 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx"> 
</span><ins>+#import &quot;QuickLookHandleClient.h&quot;
</ins><span class="cx"> #import &quot;ResourceRequest.h&quot;
</span><span class="cx"> #import &lt;objc/objc-runtime.h&gt;
</span><span class="cx"> #import &lt;wtf/PassOwnPtr.h&gt;
</span><ins>+#import &lt;wtf/RefPtr.h&gt;
</ins><span class="cx"> 
</span><del>-#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
</del><ins>+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;
</ins><span class="cx"> 
</span><span class="cx"> #if USE(CFNETWORK)
</span><span class="cx"> typedef struct _CFURLResponse* CFURLResponseRef;
</span><span class="lines">@@ -59,6 +51,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class QuickLookHandleClient;
</ins><span class="cx"> class ResourceHandle;
</span><span class="cx"> class ResourceLoader;
</span><span class="cx"> class SynchronousResourceHandleCFURLConnectionDelegate;
</span><span class="lines">@@ -84,15 +77,16 @@
</span><span class="cx"> 
</span><span class="cx"> const char* QLPreviewProtocol();
</span><span class="cx"> 
</span><ins>+NSString *createTemporaryFileForQuickLook(NSString *fileName);
</ins><span class="cx"> 
</span><span class="cx"> class QuickLookHandle {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(QuickLookHandle);
</span><span class="cx"> public:
</span><del>-    static PassOwnPtr&lt;QuickLookHandle&gt; create(ResourceHandle*, NSURLConnection *, NSURLResponse *, id delegate);
</del><ins>+    static std::unique_ptr&lt;QuickLookHandle&gt; create(ResourceHandle*, NSURLConnection *, NSURLResponse *, id delegate);
</ins><span class="cx"> #if USE(CFNETWORK)
</span><del>-    static PassOwnPtr&lt;QuickLookHandle&gt; create(ResourceHandle*, SynchronousResourceHandleCFURLConnectionDelegate*, CFURLResponseRef);
</del><ins>+    static std::unique_ptr&lt;QuickLookHandle&gt; create(ResourceHandle*, SynchronousResourceHandleCFURLConnectionDelegate*, CFURLResponseRef);
</ins><span class="cx"> #endif
</span><del>-    static PassOwnPtr&lt;QuickLookHandle&gt; create(ResourceLoader*, NSURLResponse *, id delegate);
</del><ins>+    static std::unique_ptr&lt;QuickLookHandle&gt; create(ResourceLoader*, NSURLResponse *, id delegate);
</ins><span class="cx">     ~QuickLookHandle();
</span><span class="cx"> 
</span><span class="cx">     bool didReceiveDataArray(CFArrayRef);
</span><span class="lines">@@ -105,15 +99,23 @@
</span><span class="cx">     CFURLResponseRef cfResponse();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    void setClient(PassRefPtr&lt;QuickLookHandleClient&gt; client) { m_client = client; }
+
+    NSString *previewFileName() const;
+    NSURL *firstRequestURL() const { return m_firstRequestURL.get(); }
+    NSURL *previewRequestURL() const;
+    QLPreviewConverter *converter() const { return m_converter.get(); }
+
</ins><span class="cx"> private:
</span><span class="cx">     QuickLookHandle(NSURL *, NSURLConnection *, NSURLResponse *, id delegate);
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;NSURL&gt; m_firstRequestURL;
</span><del>-    RetainPtr&lt;id&gt; m_converter;
</del><ins>+    RetainPtr&lt;QLPreviewConverter&gt; m_converter;
</ins><span class="cx">     RetainPtr&lt;id&gt; m_delegate;
</span><span class="cx">     bool m_finishedLoadingDataIntoConverter;
</span><span class="cx">     RetainPtr&lt;NSFileHandle *&gt; m_quicklookFileHandle;
</span><del>-    NSURLResponse *m_nsResponse;
</del><ins>+    RetainPtr&lt;NSURLResponse&gt; m_nsResponse;
+    RefPtr&lt;QuickLookHandleClient&gt; m_client;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkiosQuickLookmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ios/QuickLook.mm (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -195,7 +195,7 @@
</span><span class="cx">         RetainPtr&lt;NSString&gt; uti = adoptNS(WebCore::QLTypeCopyUTIForURLAndMimeType(url, updatedMIMEType.get()));
</span><span class="cx"> 
</span><span class="cx">         RetainPtr&lt;id&gt; converter = adoptNS([[QLPreviewConverterClass() alloc] initWithData:data name:nil uti:uti.get() options:nil]);
</span><del>-        NSURLRequest *request = [converter.get() previewRequest];
</del><ins>+        NSURLRequest *request = [converter previewRequest];
</ins><span class="cx"> 
</span><span class="cx">         // We use [request URL] here instead of url since it will be
</span><span class="cx">         // the URL that the WebDataSource will see during -dealloc.
</span><span class="lines">@@ -321,7 +321,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-static NSString *createTemporaryFileForQuickLook(NSString *fileName)
</del><ins>+NSString *createTemporaryFileForQuickLook(NSString *fileName)
</ins><span class="cx"> {
</span><span class="cx">     NSString *downloadDirectory = createTemporaryDirectory(@&quot;QuickLookContent&quot;);
</span><span class="cx">     if (!downloadDirectory)
</span><span class="lines">@@ -339,52 +339,46 @@
</span><span class="cx">     return success ? uniqueContentPath : nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static inline QuickLookHandleClient* emptyClient()
+{
+    static NeverDestroyed&lt;QuickLookHandleClient&gt; emptyClient;
+    return &amp;emptyClient.get();
+}
</ins><span class="cx"> 
</span><span class="cx"> QuickLookHandle::QuickLookHandle(NSURL *firstRequestURL, NSURLConnection *connection, NSURLResponse *nsResponse, id delegate)
</span><span class="cx">     : m_firstRequestURL(firstRequestURL)
</span><span class="cx">     , m_converter(adoptNS([[QLPreviewConverterClass() alloc] initWithConnection:connection delegate:delegate response:nsResponse options:nil]))
</span><del>-    , m_delegate(adoptNS([delegate retain]))
</del><ins>+    , m_delegate(delegate)
</ins><span class="cx">     , m_finishedLoadingDataIntoConverter(false)
</span><del>-    , m_nsResponse([m_converter.get() previewResponse])
</del><ins>+    , m_nsResponse([m_converter previewResponse])
+    , m_client(emptyClient())
</ins><span class="cx"> {
</span><del>-    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, &quot;QuickLookHandle::QuickLookHandle() - quicklookContentPath: %s&quot;, [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);
-    }
</del><ins>+    LOG(Network, &quot;QuickLookHandle::QuickLookHandle() - previewFileName: %s&quot;, [m_converter previewFileName]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassOwnPtr&lt;QuickLookHandle&gt; QuickLookHandle::create(ResourceHandle* handle, NSURLConnection *connection, NSURLResponse *nsResponse, id delegate)
</del><ins>+std::unique_ptr&lt;QuickLookHandle&gt; QuickLookHandle::create(ResourceHandle* handle, NSURLConnection *connection, NSURLResponse *nsResponse, id delegate)
</ins><span class="cx"> {
</span><del>-    if (handle-&gt;firstRequest().isMainResourceRequest() &amp;&amp; [WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[nsResponse MIMEType]])
-        return adoptPtr(new QuickLookHandle([handle-&gt;firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], connection, nsResponse, delegate));
</del><ins>+    ASSERT_ARG(handle, handle);
+    if (!handle-&gt;firstRequest().isMainResourceRequest() || ![WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[nsResponse MIMEType]])
+        return nullptr;
</ins><span class="cx"> 
</span><del>-    return nullptr;
</del><ins>+    std::unique_ptr&lt;QuickLookHandle&gt; quickLookHandle(new QuickLookHandle([handle-&gt;firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], connection, nsResponse, delegate));
+    handle-&gt;client()-&gt;didCreateQuickLookHandle(*quickLookHandle);
+    return std::move(quickLookHandle);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if USE(CFNETWORK)
</span><del>-PassOwnPtr&lt;QuickLookHandle&gt; QuickLookHandle::create(ResourceHandle* handle, SynchronousResourceHandleCFURLConnectionDelegate* connectionDelegate, CFURLResponseRef cfResponse)
</del><ins>+std::unique_ptr&lt;QuickLookHandle&gt; QuickLookHandle::create(ResourceHandle* handle, SynchronousResourceHandleCFURLConnectionDelegate* connectionDelegate, CFURLResponseRef cfResponse)
</ins><span class="cx"> {
</span><del>-    if (handle-&gt;firstRequest().isMainResourceRequest() &amp;&amp; [WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:(NSString *)CFURLResponseGetMIMEType(cfResponse)]) {
-        NSURLResponse *nsResponse = [NSURLResponse _responseWithCFURLResponse:cfResponse];
-        WebQuickLookHandleAsDelegate *delegate = [[[WebQuickLookHandleAsDelegate alloc] initWithConnectionDelegate:connectionDelegate] autorelease];
-        return adoptPtr(new QuickLookHandle([handle-&gt;firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, nsResponse, delegate));
-    }
</del><ins>+    ASSERT_ARG(handle, handle);
+    if (!handle-&gt;firstRequest().isMainResourceRequest() || ![WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:(NSString *)CFURLResponseGetMIMEType(cfResponse)])
+        return nullptr;
</ins><span class="cx"> 
</span><del>-    return nullptr;
</del><ins>+    NSURLResponse *nsResponse = [NSURLResponse _responseWithCFURLResponse:cfResponse];
+    WebQuickLookHandleAsDelegate *delegate = [[[WebQuickLookHandleAsDelegate alloc] initWithConnectionDelegate:connectionDelegate] autorelease];
+    std::unique_ptr&lt;QuickLookHandle&gt; quickLookHandle(new QuickLookHandle([handle-&gt;firstRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, nsResponse, delegate));
+    handle-&gt;client()-&gt;didCreateQuickLookHandle(*quickLookHandle);
+    return std::move(quickLookHandle);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CFURLResponseRef QuickLookHandle::cfResponse()
</span><span class="lines">@@ -393,47 +387,39 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-PassOwnPtr&lt;QuickLookHandle&gt; QuickLookHandle::create(ResourceLoader* loader, NSURLResponse *response, id delegate)
</del><ins>+std::unique_ptr&lt;QuickLookHandle&gt; QuickLookHandle::create(ResourceLoader* loader, NSURLResponse *response, id delegate)
</ins><span class="cx"> {
</span><del>-    if (loader-&gt;request().isMainResourceRequest() &amp;&amp; [WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[response MIMEType]])
-        return adoptPtr(new QuickLookHandle([loader-&gt;originalRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, response, delegate));
</del><ins>+    ASSERT_ARG(loader, loader);
+    if (!loader-&gt;request().isMainResourceRequest() || ![WebCore::QLPreviewGetSupportedMIMETypesSet() containsObject:[response MIMEType]])
+        return nullptr;
</ins><span class="cx"> 
</span><del>-    return nullptr;
</del><ins>+    std::unique_ptr&lt;QuickLookHandle&gt; quickLookHandle(new QuickLookHandle([loader-&gt;originalRequest().nsURLRequest(DoNotUpdateHTTPBody) URL], nil, response, delegate));
+    loader-&gt;didCreateQuickLookHandle(*quickLookHandle);
+    return std::move(quickLookHandle);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> NSURLResponse *QuickLookHandle::nsResponse()
</span><span class="cx"> {
</span><del>-    return m_nsResponse;
</del><ins>+    return m_nsResponse.get();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool QuickLookHandle::didReceiveDataArray(CFArrayRef cfDataArray)
</span><span class="cx"> {
</span><del>-    NSArray * const dataArray = (NSArray *)cfDataArray;
-
</del><span class="cx">     if (m_finishedLoadingDataIntoConverter)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     LOG(Network, &quot;QuickLookHandle::didReceiveDataArray()&quot;);
</span><del>-    [m_converter.get() appendDataArray:dataArray];
-    if (m_quicklookFileHandle) {
-        for (NSData *data in dataArray)
-            [m_quicklookFileHandle.get() writeData:data];
-    }
</del><ins>+    [m_converter appendDataArray:(NSArray *)cfDataArray];
+    m_client-&gt;didReceiveDataArray(cfDataArray);
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool QuickLookHandle::didReceiveData(CFDataRef cfData)
</span><span class="cx"> {
</span><del>-    NSData * const data = (NSData *)cfData;
-
</del><span class="cx">     if (m_finishedLoadingDataIntoConverter)
</span><span class="cx">         return false;
</span><del>-
-    LOG(Network, &quot;QuickLookHandle::didReceiveData()&quot;);
-    [m_converter.get() appendData:data];
-    if (m_quicklookFileHandle)
-        [m_quicklookFileHandle.get() writeData:data];
-    return true;
</del><ins>+    
+    return didReceiveDataArray(adoptCF(CFArrayCreate(kCFAllocatorDefault, (const void**)&amp;cfData, 1, &amp;kCFTypeArrayCallBacks)).get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool QuickLookHandle::didFinishLoading()
</span><span class="lines">@@ -443,34 +429,37 @@
</span><span class="cx"> 
</span><span class="cx">     LOG(Network, &quot;QuickLookHandle::didFinishLoading()&quot;);
</span><span class="cx">     m_finishedLoadingDataIntoConverter = YES;
</span><del>-    [m_converter.get() finishedAppendingData];
-    if (m_quicklookFileHandle)
-        [m_quicklookFileHandle.get() closeFile];
</del><ins>+    [m_converter finishedAppendingData];
+    m_client-&gt;didFinishLoading();
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void QuickLookHandle::didFail()
</span><span class="cx"> {
</span><span class="cx">     LOG(Network, &quot;QuickLookHandle::didFail()&quot;);
</span><del>-    m_quicklookFileHandle = nullptr;
-    // removeQLPreviewConverterForURL deletes the temporary file created.
-    removeQLPreviewConverterForURL(m_firstRequestURL.get());
-    [m_converter.get() finishConverting];
</del><ins>+    m_client-&gt;didFail();
+    [m_converter finishConverting];
</ins><span class="cx">     m_converter = nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> QuickLookHandle::~QuickLookHandle()
</span><span class="cx"> {
</span><span class="cx">     LOG(Network, &quot;QuickLookHandle::~QuickLookHandle()&quot;);
</span><del>-    if (m_quicklookFileHandle) {
-        m_quicklookFileHandle = nullptr;
-        removeQLPreviewConverterForURL(m_firstRequestURL.get());
-    }
</del><span class="cx">     m_converter = nullptr;
</span><span class="cx"> 
</span><del>-    [m_delegate.get() clearHandle];
</del><ins>+    [m_delegate clearHandle];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+NSString *QuickLookHandle::previewFileName() const
+{
+    return [m_converter previewFileName];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+NSURL *QuickLookHandle::previewRequestURL() const
+{
+    return [[m_converter previewRequest] URL];
+}
+
+}
+
</ins><span class="cx"> #endif // USE(QUICK_LOOK)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkiosQuickLookHandleClienth"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/network/ios/QuickLookHandleClient.h (0 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+/*
+ * 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 &lt;CoreFoundation/CoreFoundation.h&gt;
+#include &lt;wtf/RefCounted.h&gt;
+
+namespace WebCore {
+
+class QuickLookHandleClient : public RefCounted&lt;QuickLookHandleClient&gt; {
+public:
+    virtual ~QuickLookHandleClient() { }
+    virtual void didReceiveDataArray(CFArrayRef) { }
+    virtual void didFinishLoading() { }
+    virtual void didFail() { }
+};
+
+} // namespace WebCore
+
+#endif // USE(QUICK_LOOK)
+
+#endif // QuickLookHandleClient_h
</ins></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-04-13  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [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:
+
</ins><span class="cx"> 2014-04-09  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Eliminate DragSession structure
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebFrameLoaderClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -238,6 +238,10 @@
</span><span class="cx"> 
</span><span class="cx">     virtual bool shouldPaintBrokenImage(const WebCore::URL&amp;) const;
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+    virtual void didCreateQuickLookHandle(WebCore::QuickLookHandle&amp;) override;
+#endif
+
</ins><span class="cx">     RetainPtr&lt;WebFrame&gt; m_webFrame;
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;WebFramePolicyListener&gt; m_policyListener;
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebFrameLoaderClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -152,6 +152,13 @@
</span><span class="cx"> #import &quot;WebUIKitDelegate.h&quot;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+#import &lt;Foundation/NSFileManager_NSURLExtras.h&gt;
+#import &lt;WebCore/FileSystemIOS.h&gt;
+#import &lt;WebCore/QuickLook.h&gt;
+#import &lt;WebCore/RuntimeApplicationChecksIOS.h&gt;
+#endif
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> using namespace HTMLNames;
</span><span class="cx"> 
</span><span class="lines">@@ -2392,6 +2399,66 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+void WebFrameLoaderClient::didCreateQuickLookHandle(WebCore::QuickLookHandle&amp; handle)
+{
+    class QuickLookDocumentWriter : public WebCore::QuickLookHandleClient {
+    public:
+        explicit QuickLookDocumentWriter(const WebCore::QuickLookHandle&amp; 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&lt;NSFileHandle&gt; m_fileHandle;
+        RetainPtr&lt;NSURL&gt; 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
+
</ins><span class="cx"> @implementation WebFramePolicyListener
</span><span class="cx"> 
</span><span class="cx"> + (void)initialize
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,16 @@
</span><span class="cx"> 2014-04-13  Andy Estes  &lt;aestes@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        [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  &lt;aestes@apple.com&gt;
+
</ins><span class="cx">         REGRESSION (r167164): -[WKNSURLSessionLocal _getCookieHeadersForTask:completionHandler:] _block_invoke can access a deallocated completionHandler
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=131595
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessNetworkWebResourceLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.h (167206 => 167207)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx">     void setUpQuickLookHandleIfNeeded(const WebCore::ResourceResponse&amp;);
</span><span class="cx"> 
</span><del>-    OwnPtr&lt;WebCore::QuickLookHandle&gt; m_quickLookHandle;
</del><ins>+    std::unique_ptr&lt;WebCore::QuickLookHandle&gt; m_quickLookHandle;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;WebCore::ResourceLoader&gt; m_coreLoader;
</span></span></pre>
</div>
</div>

</body>
</html>