<!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>[211248] trunk</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/211248">211248</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2017-01-26 18:00:17 -0800 (Thu, 26 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[QuickLook] REGRESSION (WebKit2): Requests are made to invalid x-apple-ql-id: URLs
https://bugs.webkit.org/show_bug.cgi?id=167453

Reviewed by Brent Fulgham.

Source/WebCore:

Requests to x-apple-ql-id: URLs should be filtered by
-[QLPreviewConverter safeRequestForRequest:]. This method checks that the URL is one of the
ones generated for the current preview, and changes it to &quot;about:&quot; if it isn't.

WebCore::safeQLURLForDocumentURLAndResourceURL() was responsible for finding the
QLPreviewConverter instance to use by looking it up in an NSMutableDictionary using the
document URL as a key. In WebKit1, this dictionary was populated by the
QuickLookHandleClient when new QuickLookHandles were created, but the WebKit2
QuickLookHandleClient never did this. As a result, requests to invalid URLs were not being
rewritten.

An easy way to load a QuickLook document with invalid URLs is to create an HTML file with a
Microsoft Office extension (e.g. .xls); QuickLook, iWork, and Office support opening HTML
files with Office document extensions. In <a href="http://trac.webkit.org/projects/webkit/changeset/207155">r207155</a> we applied a Content Security Policy to
QuickLook documents that only allows x-apple-ql-id: resources to load. This blocked
cross-origin requests from loading, but same-origin requests to URLs that weren't generated
by QLPreviewConverter were still allowed to load.

This change blocks these URLs by calling -[QLPreviewConverter safeRequestForRequest:] in a
way that works for both WebKit1 and WebKit2.

After implementing QuickLook for WebKit2, we found a bug when loading HTML-as-Office
documents (webkit.org/b/135651) that presented as a nil MIME type in the preview
NSURLResponse returned by QLPreviewConverter. Unfortunately <a href="http://trac.webkit.org/projects/webkit/changeset/172159">r172159</a> papered over the actual
bug by failing to load previews with nil MIME types.

The real issue was that we were asking for the preview response before QuickLook had
received enough data to determine a MIME type, so this change also removes the bad fix from
<a href="http://trac.webkit.org/projects/webkit/changeset/172159">r172159</a> and instead waits until QuickLook has converted the document to ask for its preview
response. This restores the ability to load HTML files with Office document extensions.
These two fixes are combined in a single patch because I don't know how to create an invalid
QuickLook URL for testing without loading an HTML-as-Office document.

Test: quicklook/invalid-ql-id-url.html

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::willSendRequestInternal): Called
QuickLookHandle::willSendRequest() if m_documentLoader has a QuickLookHandle.
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::load): Removed the call to
WebCore::safeQLURLForDocumentURLAndResourceURL().
* loader/ios/QuickLook.h: Removed safeQLURLForDocumentURLAndResourceURL() and declared
QuickLookHandle::willSendRequest().
* loader/ios/QuickLook.mm: Removed _previewResponse and _hasFailed ivars from
WebPreviewConverter.
(-[WebPreviewConverter initWithResourceLoader:resourceResponse:quickLookHandle:]): Stopped
setting _previewResponse.
(-[WebPreviewConverter _sendDidReceiveResponseIfNecessary]): Only emptied _bufferedDataArray
if we haven't already called -_sendDidReceiveResponseIfNecessary; removed the check for a
nil _previewResponse MIME type; accessed -[QLPreviewConverter previewResponse] now that the
document has been converted and asserted its MIME type is non-nil.
(-[WebPreviewConverter connection:didReceiveData:lengthReceived:]): Removed _hasFailed check.
(-[WebPreviewConverter connectionDidFinishLoading:]): Ditto.
(isQuickLookPasswordError): Moved the check for password failure errors to here from
-connection:didFailWithError: for better readability.
(-[WebPreviewConverter connection:didFailWithError:]): Removed _hasFailed check and used
more early returns.
(WebCore::QuickLookHandle::willSendRequest): Filtered the request through
-[QLPreviewConverter safeRequestWithRequest:] if the request URL's scheme is x-apple-ql-id:.
(WebCore::safeQLURLForDocumentURLAndResourceURL): Deleted.

LayoutTests:

* quicklook/invalid-ql-id-url-expected.txt: Added.
* quicklook/invalid-ql-id-url.html: Added.
* quicklook/nil-response-mime-type-expected.txt: Removed.
* quicklook/nil-response-mime-type.html: Removed.
* quicklook/resources/invalid-ql-id-url.xls: Added.
* quicklook/resources/nil-response-mime-type.xls: Removed.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadercpp">trunk/Source/WebCore/loader/ResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourcecpp">trunk/Source/WebCore/loader/cache/CachedResource.cpp</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>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsquicklookinvalidqlidurlexpectedtxt">trunk/LayoutTests/quicklook/invalid-ql-id-url-expected.txt</a></li>
<li><a href="#trunkLayoutTestsquicklookinvalidqlidurlhtml">trunk/LayoutTests/quicklook/invalid-ql-id-url.html</a></li>
<li><a href="#trunkLayoutTestsquicklookresourcesinvalidqlidurlxls">trunk/LayoutTests/quicklook/resources/invalid-ql-id-url.xls</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsquicklooknilresponsemimetypeexpectedtxt">trunk/LayoutTests/quicklook/nil-response-mime-type-expected.txt</a></li>
<li><a href="#trunkLayoutTestsquicklooknilresponsemimetypehtml">trunk/LayoutTests/quicklook/nil-response-mime-type.html</a></li>
<li><a href="#trunkLayoutTestsquicklookresourcesnilresponsemimetypexls">trunk/LayoutTests/quicklook/resources/nil-response-mime-type.xls</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/LayoutTests/ChangeLog        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2017-01-26  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [QuickLook] REGRESSION (WebKit2): Requests are made to invalid x-apple-ql-id: URLs
+        https://bugs.webkit.org/show_bug.cgi?id=167453
+
+        Reviewed by Brent Fulgham.
+
+        * quicklook/invalid-ql-id-url-expected.txt: Added.
+        * quicklook/invalid-ql-id-url.html: Added.
+        * quicklook/nil-response-mime-type-expected.txt: Removed.
+        * quicklook/nil-response-mime-type.html: Removed.
+        * quicklook/resources/invalid-ql-id-url.xls: Added.
+        * quicklook/resources/nil-response-mime-type.xls: Removed.
+
</ins><span class="cx"> 2017-01-26  Jeremy Jones  &lt;jeremyj@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Pointer lock events should be delivered directly to the target element
</span></span></pre></div>
<a id="trunkLayoutTestsquicklookinvalidqlidurlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/quicklook/invalid-ql-id-url-expected.txt (0 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/quicklook/invalid-ql-id-url-expected.txt                                (rev 0)
+++ trunk/LayoutTests/quicklook/invalid-ql-id-url-expected.txt        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+resources/invalid-ql-id-url.xls - didFinishLoading
+x-apple-ql-id://nonexistent.jpg - didReceiveResponse &lt;NSURLResponse about:, http status code 0&gt;
+x-apple-ql-id://nonexistent.jpg - didFinishLoading
+
</ins></span></pre></div>
<a id="trunkLayoutTestsquicklookinvalidqlidurlhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/quicklook/invalid-ql-id-url.html (0 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/quicklook/invalid-ql-id-url.html                                (rev 0)
+++ trunk/LayoutTests/quicklook/invalid-ql-id-url.html        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;script&gt;
+    if (window.testRunner)
+        testRunner.dumpAsText();
+&lt;/script&gt;
+&lt;style&gt;
+iframe {
+    width: 100vw;
+    height: 100vh;
+}
+&lt;/style&gt;
+&lt;iframe src=&quot;resources/invalid-ql-id-url.xls&quot;&gt;&lt;/iframe&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsquicklooknilresponsemimetypeexpectedtxt"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/quicklook/nil-response-mime-type-expected.txt (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/quicklook/nil-response-mime-type-expected.txt        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/LayoutTests/quicklook/nil-response-mime-type-expected.txt        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -1,7 +0,0 @@
</span><del>-frame &quot;&lt;!--framePath //&lt;!--frame0--&gt;--&gt;&quot; - didStartProvisionalLoadForFrame
-main frame - didFinishDocumentLoadForFrame
-main frame - didHandleOnloadEventsForFrame
-frame &quot;&lt;!--framePath //&lt;!--frame0--&gt;--&gt;&quot; - didFailProvisionalLoadWithError
-frame &quot;&lt;!--framePath //&lt;!--frame0--&gt;--&gt;&quot; - (ErrorCodeCannotShowURL)
-main frame - didFinishLoadForFrame
-
</del></span></pre></div>
<a id="trunkLayoutTestsquicklooknilresponsemimetypehtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/quicklook/nil-response-mime-type.html (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/quicklook/nil-response-mime-type.html        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/LayoutTests/quicklook/nil-response-mime-type.html        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -1,14 +0,0 @@
</span><del>-&lt;!DOCTYPE html&gt;
-&lt;script&gt;
-    if (window.testRunner) {
-        testRunner.dumpAsText();
-        testRunner.dumpFrameLoadCallbacks();
-    }        
-&lt;/script&gt;
-&lt;style&gt;
-iframe {
-    width: 100vw;
-    height: 100vh;
-}
-&lt;/style&gt;
-&lt;iframe src=&quot;resources/nil-response-mime-type.xls&quot;&gt;&lt;/iframe&gt;
</del></span></pre></div>
<a id="trunkLayoutTestsquicklookresourcesinvalidqlidurlxls"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/quicklook/resources/invalid-ql-id-url.xls (0 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/quicklook/resources/invalid-ql-id-url.xls                                (rev 0)
+++ trunk/LayoutTests/quicklook/resources/invalid-ql-id-url.xls        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;html&gt;
+&lt;script&gt;
+    if (window.testRunner)
+        testRunner.dumpResourceLoadCallbacks();
+&lt;/script&gt;
+&lt;body&gt;
+We should not attempt to load the image URL below:
+&lt;br&gt;
+&lt;img src=&quot;x-apple-ql-id://nonexistent.jpg&quot;&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsquicklookresourcesnilresponsemimetypexls"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/quicklook/resources/nil-response-mime-type.xls (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/quicklook/resources/nil-response-mime-type.xls        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/LayoutTests/quicklook/resources/nil-response-mime-type.xls        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -1,7 +0,0 @@
</span><del>-&lt;html&gt;
-&lt;body&gt;
-The image below should not be displayed:
-&lt;br&gt;
-&lt;img src=&quot;http://www.dnsupdate.org/DNSUpdate2.jpg&quot;&gt;
-&lt;/body&gt;
-&lt;/html&gt;
</del></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/Source/WebCore/ChangeLog        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -1,3 +1,71 @@
</span><ins>+2017-01-26  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [QuickLook] REGRESSION (WebKit2): Requests are made to invalid x-apple-ql-id: URLs
+        https://bugs.webkit.org/show_bug.cgi?id=167453
+
+        Reviewed by Brent Fulgham.
+
+        Requests to x-apple-ql-id: URLs should be filtered by
+        -[QLPreviewConverter safeRequestForRequest:]. This method checks that the URL is one of the
+        ones generated for the current preview, and changes it to &quot;about:&quot; if it isn't.
+
+        WebCore::safeQLURLForDocumentURLAndResourceURL() was responsible for finding the
+        QLPreviewConverter instance to use by looking it up in an NSMutableDictionary using the
+        document URL as a key. In WebKit1, this dictionary was populated by the
+        QuickLookHandleClient when new QuickLookHandles were created, but the WebKit2
+        QuickLookHandleClient never did this. As a result, requests to invalid URLs were not being
+        rewritten.
+
+        An easy way to load a QuickLook document with invalid URLs is to create an HTML file with a
+        Microsoft Office extension (e.g. .xls); QuickLook, iWork, and Office support opening HTML
+        files with Office document extensions. In r207155 we applied a Content Security Policy to
+        QuickLook documents that only allows x-apple-ql-id: resources to load. This blocked
+        cross-origin requests from loading, but same-origin requests to URLs that weren't generated
+        by QLPreviewConverter were still allowed to load.
+
+        This change blocks these URLs by calling -[QLPreviewConverter safeRequestForRequest:] in a
+        way that works for both WebKit1 and WebKit2.
+
+        After implementing QuickLook for WebKit2, we found a bug when loading HTML-as-Office
+        documents (webkit.org/b/135651) that presented as a nil MIME type in the preview
+        NSURLResponse returned by QLPreviewConverter. Unfortunately r172159 papered over the actual
+        bug by failing to load previews with nil MIME types.
+
+        The real issue was that we were asking for the preview response before QuickLook had
+        received enough data to determine a MIME type, so this change also removes the bad fix from
+        r172159 and instead waits until QuickLook has converted the document to ask for its preview
+        response. This restores the ability to load HTML files with Office document extensions.
+        These two fixes are combined in a single patch because I don't know how to create an invalid
+        QuickLook URL for testing without loading an HTML-as-Office document.
+
+        Test: quicklook/invalid-ql-id-url.html
+
+        * loader/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::willSendRequestInternal): Called
+        QuickLookHandle::willSendRequest() if m_documentLoader has a QuickLookHandle.
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::load): Removed the call to
+        WebCore::safeQLURLForDocumentURLAndResourceURL().
+        * loader/ios/QuickLook.h: Removed safeQLURLForDocumentURLAndResourceURL() and declared
+        QuickLookHandle::willSendRequest().
+        * loader/ios/QuickLook.mm: Removed _previewResponse and _hasFailed ivars from
+        WebPreviewConverter.
+        (-[WebPreviewConverter initWithResourceLoader:resourceResponse:quickLookHandle:]): Stopped
+        setting _previewResponse.
+        (-[WebPreviewConverter _sendDidReceiveResponseIfNecessary]): Only emptied _bufferedDataArray
+        if we haven't already called -_sendDidReceiveResponseIfNecessary; removed the check for a
+        nil _previewResponse MIME type; accessed -[QLPreviewConverter previewResponse] now that the
+        document has been converted and asserted its MIME type is non-nil.
+        (-[WebPreviewConverter connection:didReceiveData:lengthReceived:]): Removed _hasFailed check.
+        (-[WebPreviewConverter connectionDidFinishLoading:]): Ditto.
+        (isQuickLookPasswordError): Moved the check for password failure errors to here from
+        -connection:didFailWithError: for better readability.
+        (-[WebPreviewConverter connection:didFailWithError:]): Removed _hasFailed check and used
+        more early returns.
+        (WebCore::QuickLookHandle::willSendRequest): Filtered the request through
+        -[QLPreviewConverter safeRequestWithRequest:] if the request URL's scheme is x-apple-ql-id:.
+        (WebCore::safeQLURLForDocumentURLAndResourceURL): Deleted.
+
</ins><span class="cx"> 2017-01-26  Keith Miller  &lt;keith_miller@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         classInfo should take a VM so it is not materialized from the object on each call
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoader.cpp        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/Source/WebCore/loader/ResourceLoader.cpp        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -55,6 +55,10 @@
</span><span class="cx"> #include &quot;UserContentController.h&quot;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+#include &quot;QuickLook.h&quot;
+#endif
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> ResourceLoader::ResourceLoader(Frame&amp; frame, ResourceLoaderOptions options)
</span><span class="lines">@@ -371,6 +375,11 @@
</span><span class="cx">     else
</span><span class="cx">         InspectorInstrumentation::willSendRequest(m_frame.get(), m_identifier, m_frame-&gt;loader().documentLoader(), request, redirectResponse);
</span><span class="cx"> 
</span><ins>+#if USE(QUICK_LOOK)
+    if (auto quickLookHandle = m_documentLoader-&gt;quickLookHandle())
+        quickLookHandle-&gt;willSendRequest(request);
+#endif
+
</ins><span class="cx">     bool isRedirect = !redirectResponse.isNull();
</span><span class="cx">     if (isRedirect)
</span><span class="cx">         platformStrategies()-&gt;loaderStrategy()-&gt;crossOriginRedirectReceived(this, request.url());
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.cpp        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -214,16 +214,6 @@
</span><span class="cx"> 
</span><span class="cx">     m_loading = true;
</span><span class="cx"> 
</span><del>-#if USE(QUICK_LOOK)
-    if (!m_resourceRequest.isNull() &amp;&amp; m_resourceRequest.url().protocolIs(QLPreviewProtocol())) {
-        // When QuickLook is invoked to convert a document, it returns a unique URL in the
-        // NSURLReponse for the main document. To make safeQLURLForDocumentURLAndResourceURL()
-        // work, we need to use the QL URL not the original URL.
-        const URL&amp; documentURL = frameLoader.documentLoader()-&gt;response().url();
-        m_resourceRequest.setURL(safeQLURLForDocumentURLAndResourceURL(documentURL, url()));
-    }
-#endif
-
</del><span class="cx">     if (isCacheValidator()) {
</span><span class="cx">         CachedResource* resourceToRevalidate = m_resourceToRevalidate;
</span><span class="cx">         ASSERT(resourceToRevalidate-&gt;canUseCacheValidator());
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderiosQuickLookh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ios/QuickLook.h (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ios/QuickLook.h        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/Source/WebCore/loader/ios/QuickLook.h        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx"> 
</span><span class="cx"> class QuickLookHandleClient;
</span><span class="cx"> class ResourceLoader;
</span><ins>+class ResourceRequest;
</ins><span class="cx"> class ResourceResponse;
</span><span class="cx"> class SharedBuffer;
</span><span class="cx"> class URL;
</span><span class="lines">@@ -59,8 +60,6 @@
</span><span class="cx"> 
</span><span class="cx"> WEBCORE_EXPORT RetainPtr&lt;NSURLRequest&gt; registerQLPreviewConverterIfNeeded(NSURL *, NSString *mimeType, NSData *);
</span><span class="cx"> 
</span><del>-const URL safeQLURLForDocumentURLAndResourceURL(const URL&amp; documentURL, const String&amp; resourceURL);
-
</del><span class="cx"> WEBCORE_EXPORT const char* QLPreviewProtocol();
</span><span class="cx"> 
</span><span class="cx"> WEBCORE_EXPORT NSString *createTemporaryFileForQuickLook(NSString *fileName);
</span><span class="lines">@@ -72,6 +71,7 @@
</span><span class="cx">     static std::unique_ptr&lt;QuickLookHandle&gt; create(ResourceLoader&amp;, const ResourceResponse&amp;);
</span><span class="cx">     ~QuickLookHandle();
</span><span class="cx"> 
</span><ins>+    void willSendRequest(ResourceRequest&amp;);
</ins><span class="cx">     bool didReceiveData(const char* data, unsigned length);
</span><span class="cx">     bool didReceiveBuffer(const SharedBuffer&amp;);
</span><span class="cx">     bool didFinishLoading();
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderiosQuickLookmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ios/QuickLook.mm (211247 => 211248)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ios/QuickLook.mm        2017-01-27 01:47:52 UTC (rev 211247)
+++ trunk/Source/WebCore/loader/ios/QuickLook.mm        2017-01-27 02:00:17 UTC (rev 211248)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #import &quot;QuickLookHandleClient.h&quot;
</span><span class="cx"> #import &quot;ResourceError.h&quot;
</span><span class="cx"> #import &quot;ResourceLoader.h&quot;
</span><ins>+#import &quot;ResourceRequest.h&quot;
</ins><span class="cx"> #import &quot;SharedBuffer.h&quot;
</span><span class="cx"> #import &lt;wtf/NeverDestroyed.h&gt;
</span><span class="cx"> #import &lt;wtf/Vector.h&gt;
</span><span class="lines">@@ -125,23 +126,6 @@
</span><span class="cx">     return nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-const URL WebCore::safeQLURLForDocumentURLAndResourceURL(const URL&amp; documentURL, const String&amp; resourceURL)
-{
-    id converter = nil;
-    NSURL *nsDocumentURL = documentURL;
-    {
-        LockHolder lock(qlPreviewConverterDictionaryMutex());
-        converter = [QLPreviewConverterDictionary() objectForKey:nsDocumentURL];
-    }
-
-    if (!converter)
-        return URL(ParsedURLString, resourceURL);
-
-    RetainPtr&lt;NSURLRequest&gt; request = adoptNS([[NSURLRequest alloc] initWithURL:[NSURL URLWithString:resourceURL]]);
-    NSURLRequest *safeRequest = [converter safeRequestForRequest:request.get()];
-    return [safeRequest URL];
-}
-
</del><span class="cx"> static Vector&lt;char&gt; createQLPreviewProtocol()
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;char&gt; previewProtocol;
</span><span class="lines">@@ -181,10 +165,8 @@
</span><span class="cx">     RefPtr&lt;QuickLookHandleClient&gt; _client;
</span><span class="cx">     RetainPtr&lt;NSURLResponse&gt; _originalResponse;
</span><span class="cx">     RetainPtr&lt;QLPreviewConverter&gt; _platformConverter;
</span><del>-    RetainPtr&lt;NSURLResponse&gt; _previewResponse;
</del><span class="cx">     RetainPtr&lt;NSMutableArray&gt; _bufferedDataArray;
</span><span class="cx">     BOOL _hasSentDidReceiveResponse;
</span><del>-    BOOL _hasFailed;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (instancetype)initWithResourceLoader:(ResourceLoader&amp;)resourceLoader resourceResponse:(const ResourceResponse&amp;)resourceResponse quickLookHandle:(QuickLookHandle&amp;)quickLookHandle;
</span><span class="lines">@@ -210,7 +192,6 @@
</span><span class="cx">     _client = &amp;testingOrEmptyClient();
</span><span class="cx">     _originalResponse = resourceResponse.nsURLResponse();
</span><span class="cx">     _platformConverter = adoptNS([allocQLPreviewConverterInstance() initWithConnection:nil delegate:self response:_originalResponse.get() options:nil]);
</span><del>-    _previewResponse = [_platformConverter previewResponse];
</del><span class="cx">     _bufferedDataArray = adoptNS([[NSMutableArray alloc] init]);
</span><span class="cx"> 
</span><span class="cx">     LOG(Network, &quot;WebPreviewConverter created with preview file name \&quot;%s\&quot;.&quot;, [_platformConverter previewFileName]);
</span><span class="lines">@@ -252,21 +233,14 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)_sendDidReceiveResponseIfNecessary
</span><span class="cx"> {
</span><del>-    [_bufferedDataArray removeAllObjects];
-
-    if (_hasSentDidReceiveResponse || _hasFailed)
</del><ins>+    if (_hasSentDidReceiveResponse)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    // QuickLook might fail to convert a document without calling connection:didFailWithError: (see &lt;rdar://problem/17927972&gt;).
-    // A nil MIME type is an indication of such a failure, so stop loading the resource and ignore subsequent delegate messages.
-    if (![_previewResponse MIMEType]) {
-        _hasFailed = YES;
-        _resourceLoader-&gt;didFail(_resourceLoader-&gt;cannotShowURLError());
-        return;
-    }
</del><ins>+    [_bufferedDataArray removeAllObjects];
</ins><span class="cx"> 
</span><del>-    ResourceResponse response { _previewResponse.get() };
</del><ins>+    ResourceResponse response { [_platformConverter previewResponse] };
</ins><span class="cx">     response.setIsQuickLook(true);
</span><ins>+    ASSERT(response.mimeType().length());
</ins><span class="cx"> 
</span><span class="cx">     _hasSentDidReceiveResponse = YES;
</span><span class="cx">     _resourceLoader-&gt;didReceiveResponse(response);
</span><span class="lines">@@ -276,8 +250,6 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT_UNUSED(connection, !connection);
</span><span class="cx">     [self _sendDidReceiveResponseIfNecessary];
</span><del>-    if (_hasFailed)
-        return;
</del><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><span class="lines">@@ -288,37 +260,37 @@
</span><span class="cx"> - (void)connectionDidFinishLoading:(NSURLConnection *)connection
</span><span class="cx"> {
</span><span class="cx">     ASSERT_UNUSED(connection, !connection);
</span><del>-    if (_hasFailed)
-        return;
-
</del><span class="cx">     ASSERT(_hasSentDidReceiveResponse);
</span><span class="cx">     _resourceLoader-&gt;didFinishLoading(0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static inline bool isQuickLookPasswordError(NSError *error)
+{
+    return error.code == kQLReturnPasswordProtected &amp;&amp; [error.domain isEqualToString:@&quot;QuickLookErrorDomain&quot;];
+}
+
</ins><span class="cx"> - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
</span><span class="cx"> {
</span><span class="cx">     ASSERT_UNUSED(connection, !connection);
</span><span class="cx"> 
</span><del>-    if (error.code == kQLReturnPasswordProtected &amp;&amp; [error.domain isEqualToString:@&quot;QuickLookErrorDomain&quot;]) {
-        if (!_client-&gt;supportsPasswordEntry()) {
-            _resourceLoader-&gt;didFail(_resourceLoader-&gt;cannotShowURLError());
-            return;
-        }
</del><ins>+    if (!isQuickLookPasswordError(error)) {
+        [self _sendDidReceiveResponseIfNecessary];
+        _resourceLoader-&gt;didFail(error);
+        return;
+    }
</ins><span class="cx"> 
</span><del>-        _client-&gt;didRequestPassword([retainedSelf = retainPtr(self)] (const String&amp; password) {
-            NSDictionary *passwordOption = @{ (NSString *)kQLPreviewOptionPasswordKey : password };
-            auto converterWithPassword = adoptNS([allocQLPreviewConverterInstance() initWithConnection:nil delegate:retainedSelf.get() response:retainedSelf-&gt;_originalResponse.get() options:passwordOption]);
-            [converterWithPassword appendDataArray:retainedSelf-&gt;_bufferedDataArray.get()];
-            [converterWithPassword finishedAppendingData];
-            retainedSelf-&gt;_previewResponse = [converterWithPassword previewResponse];
-            retainedSelf-&gt;_platformConverter = WTFMove(converterWithPassword);
-        });
</del><ins>+    if (!_client-&gt;supportsPasswordEntry()) {
+        _resourceLoader-&gt;didFail(_resourceLoader-&gt;cannotShowURLError());
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    [self _sendDidReceiveResponseIfNecessary];
-    if (!_hasFailed)
-        _resourceLoader-&gt;didFail(error);
</del><ins>+    _client-&gt;didRequestPassword([retainedSelf = retainPtr(self)] (const String&amp; password) {
+        NSDictionary *passwordOption = @{ (NSString *)kQLPreviewOptionPasswordKey : password };
+        auto converterWithPassword = adoptNS([allocQLPreviewConverterInstance() initWithConnection:nil delegate:retainedSelf.get() response:retainedSelf-&gt;_originalResponse.get() options:passwordOption]);
+        [converterWithPassword appendDataArray:retainedSelf-&gt;_bufferedDataArray.get()];
+        [converterWithPassword finishedAppendingData];
+        retainedSelf-&gt;_platformConverter = WTFMove(converterWithPassword);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="lines">@@ -389,6 +361,12 @@
</span><span class="cx">     return std::make_unique&lt;QuickLookHandle&gt;(loader, response);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void QuickLookHandle::willSendRequest(ResourceRequest&amp; request)
+{
+    if (request.url().protocolIs(QLPreviewProtocol()))
+        request = [[m_converter platformConverter] safeRequestForRequest:request.nsURLRequest(DoNotUpdateHTTPBody)];
+}
+
</ins><span class="cx"> bool QuickLookHandle::didReceiveData(const char* data, unsigned length)
</span><span class="cx"> {
</span><span class="cx">     if (m_finishedLoadingDataIntoConverter)
</span></span></pre>
</div>
</div>

</body>
</html>