<!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>[224439] 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/224439">224439</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-11-03 16:09:28 -0700 (Fri, 03 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Requests handled by Service Worker should not go through preflighting
https://bugs.webkit.org/show_bug.cgi?id=179250

Patch by Youenn Fablet <youenn@apple.com> on 2017-11-03
Reviewed by Alex Christensen.

Source/WebCore:

Test: http/tests/workers/service/service-worker-crossorigin-fetch.html
In case of cross origin requests needed preflighting that may be served through SW, the following is done:
- Bypass preflight
- Put service workers mode as Only so that if SW is not handling the request, the load will fail
- If load fails, restart DocumentThreadableLoader load with preflight.

Additional testing should be added when we properly handle the case where no fetch event handler is registered in the service worker.

* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::makeCrossOriginAccessRequest):
(WebCore::DocumentThreadableLoader::didFail):
* loader/DocumentThreadableLoader.h:
* loader/ResourceLoaderOptions.h:
* loader/cache/CachedResourceRequest.cpp:
(WebCore::CachedResourceRequest::setSelectedServiceWorkerIdentifierIfNeeded):
* platform/network/ResourceErrorBase.h:

Source/WebKit:

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::scheduleLoad):
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::startFetch):
* WebProcess/Storage/WebServiceWorkerProvider.cpp:
(WebKit::shouldHandleFetch):

LayoutTests:

* http/tests/workers/service/resources/service-worker-crossorigin-fetch-worker.js: Added.
(event.event.request.url.indexOf):
(event.event.request.url.endsWith):
* http/tests/workers/service/resources/service-worker-crossorigin-fetch.js: Added.
(done):
(async.logStatus):
(async.test):
* http/tests/workers/service/service-worker-crossorigin-fetch-expected.txt: Added.
* http/tests/workers/service/service-worker-crossorigin-fetch.html: Added.</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="#trunkSourceWebCoreloaderDocumentThreadableLoadercpp">trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderDocumentThreadableLoaderh">trunk/Source/WebCore/loader/DocumentThreadableLoader.h</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoaderOptionsh">trunk/Source/WebCore/loader/ResourceLoaderOptions.h</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourceRequestcpp">trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceErrorBaseh">trunk/Source/WebCore/platform/network/ResourceErrorBase.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitWebProcessNetworkWebLoaderStrategycpp">trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWClientConnectioncpp">trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebServiceWorkerProvidercpp">trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsworkersserviceresourcesserviceworkercrossoriginfetchworkerjs">trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch-worker.js</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceresourcesserviceworkercrossoriginfetchjs">trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch.js</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceserviceworkercrossoriginfetchexpectedtxt">trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceserviceworkercrossoriginfetchhtml">trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/LayoutTests/ChangeLog 2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-11-03  Youenn Fablet  <youenn@apple.com>
+
+        Requests handled by Service Worker should not go through preflighting
+        https://bugs.webkit.org/show_bug.cgi?id=179250
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/workers/service/resources/service-worker-crossorigin-fetch-worker.js: Added.
+        (event.event.request.url.indexOf):
+        (event.event.request.url.endsWith):
+        * http/tests/workers/service/resources/service-worker-crossorigin-fetch.js: Added.
+        (done):
+        (async.logStatus):
+        (async.test):
+        * http/tests/workers/service/service-worker-crossorigin-fetch-expected.txt: Added.
+        * http/tests/workers/service/service-worker-crossorigin-fetch.html: Added.
+
</ins><span class="cx"> 2017-11-03  Alex Christensen  <achristensen@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         LayoutTest http/tests/loading/basic-auth-resend-wrong-credentials.html is flaky on WK2
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceresourcesserviceworkercrossoriginfetchworkerjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch-worker.js (0 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch-worker.js                                (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch-worker.js   2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+var status = "no status";
+self.addEventListener("fetch", (event) => {
+    if (event.request.url.indexOf("status") !== -1) {
+        event.respondWith(new Response(null, {status: 200, statusText: status}));
+        return;
+    }
+    if (!event.request.url.endsWith(".fromserviceworker")) {
+        state = "unknown url";
+        event.respondWith(new Response(null, {status: 404, statusText: "Not Found"}));
+        return;
+    }
+    // Changing cors fetch into same origin fetch.
+    status = event.request.url.substring(21, event.request.url.length - 18) + " through " + "fetch";
+    event.respondWith(fetch(event.request.url.substring(21, event.request.url.length - 18)));
+});
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceresourcesserviceworkercrossoriginfetchjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch.js (0 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch.js                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/service-worker-crossorigin-fetch.js  2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+function done()
+{
+    finishSWTest();
+}
+
+async function logStatus()
+{
+    var response = await fetch("status");
+    log("Status is " + response.statusText);
+}
+
+async function test()
+{
+    try {
+        // Triggering potential prefligh through custom header.
+        try {
+            var response = await fetch("http://localhost:8080/resources/square100.png.fromserviceworker", {headers: {"custom": "header"}});
+            log("Failed: fetch suceeded unexpectedly");
+        } catch(e) {
+            log("PASS: Fetch failed as expected with: " + e);
+        }        
+
+        await navigator.serviceWorker.register("resources/service-worker-crossorigin-fetch-worker.js", { });
+
+        var response = await fetch("http://localhost:8080/resources/square100.png.fromserviceworker", {headers: {"custom": "header"}});
+        var buffer =  await response.arrayBuffer();
+        log("PASS: Got response with buffer byte length being " + buffer.byteLength);
+
+        await logStatus();
+    } catch(e) {
+        log("Got exception: " + e);
+    }
+    finishSWTest();
+}
+
+test();
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceserviceworkercrossoriginfetchexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch-expected.txt (0 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch-expected.txt                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch-expected.txt  2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+CONSOLE MESSAGE: Fetch API cannot load http://localhost:8080/resources/square100.png.fromserviceworker. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+PASS: Fetch failed as expected with: TypeError: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+PASS: Got response with buffer byte length being 12940
+Status is /resources/square100.png through fetch
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceserviceworkercrossoriginfetchhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch.html (0 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch.html                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-crossorigin-fetch.html  2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+<html>
+<head>
+<script src="resources/sw-test-pre.js"></script>
+</head>
+<body>
+<script src="resources/service-worker-crossorigin-fetch.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebCore/ChangeLog      2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2017-11-03  Youenn Fablet  <youenn@apple.com>
+
+        Requests handled by Service Worker should not go through preflighting
+        https://bugs.webkit.org/show_bug.cgi?id=179250
+
+        Reviewed by Alex Christensen.
+
+        Test: http/tests/workers/service/service-worker-crossorigin-fetch.html
+        In case of cross origin requests needed preflighting that may be served through SW, the following is done:
+        - Bypass preflight
+        - Put service workers mode as Only so that if SW is not handling the request, the load will fail
+        - If load fails, restart DocumentThreadableLoader load with preflight.
+
+        Additional testing should be added when we properly handle the case where no fetch event handler is registered in the service worker.
+
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::makeCrossOriginAccessRequest):
+        (WebCore::DocumentThreadableLoader::didFail):
+        * loader/DocumentThreadableLoader.h:
+        * loader/ResourceLoaderOptions.h:
+        * loader/cache/CachedResourceRequest.cpp:
+        (WebCore::CachedResourceRequest::setSelectedServiceWorkerIdentifierIfNeeded):
+        * platform/network/ResourceErrorBase.h:
+
</ins><span class="cx"> 2017-11-03  Zalan Bujtas  <zalan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Remove redundant LayoutStateMaintainer argument (RenderView&)
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentThreadableLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp 2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp    2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -148,6 +148,17 @@
</span><span class="cx">     if ((m_options.preflightPolicy == ConsiderPreflight && isSimpleCrossOriginAccessRequest(request.httpMethod(), request.httpHeaderFields())) || m_options.preflightPolicy == PreventPreflight)
</span><span class="cx">         makeSimpleCrossOriginAccessRequest(WTFMove(request));
</span><span class="cx">     else {
</span><ins>+#if ENABLE(SERVICE_WORKER)
+        if (m_options.serviceWorkersMode == ServiceWorkersMode::All && m_async) {
+            if (m_options.serviceWorkerIdentifier || document().activeServiceWorker()) {
+                ASSERT(!m_bypassingPreflightForServiceWorkerRequest);
+                m_bypassingPreflightForServiceWorkerRequest = WTFMove(request);
+                m_options.serviceWorkersMode = ServiceWorkersMode::Only;
+                loadRequest(ResourceRequest { m_bypassingPreflightForServiceWorkerRequest.value() }, SkipSecurityCheck);
+                return;
+            }
+        }
+#endif
</ins><span class="cx">         m_simpleRequest = false;
</span><span class="cx">         if (CrossOriginPreflightResultCache::singleton().canSkipPreflight(securityOrigin().toString(), request.url(), m_options.storedCredentialsPolicy, request.httpMethod(), request.httpHeaderFields()))
</span><span class="cx">             preflightSuccess(WTFMove(request));
</span><span class="lines">@@ -392,6 +403,13 @@
</span><span class="cx"> void DocumentThreadableLoader::didFail(unsigned long, const ResourceError& error)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_client);
</span><ins>+#if ENABLE(SERVICE_WORKER)
+    if (m_bypassingPreflightForServiceWorkerRequest) {
+        m_options.serviceWorkersMode = ServiceWorkersMode::None;
+        makeCrossOriginAccessRequest(WTFMove(m_bypassingPreflightForServiceWorkerRequest.value()));
+        return;
+    }
+#endif
</ins><span class="cx">     logErrorAndFail(error);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentThreadableLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.h (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentThreadableLoader.h   2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.h      2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -133,6 +133,9 @@
</span><span class="cx">         std::optional<HTTPHeaderMap> m_originalHeaders;
</span><span class="cx"> 
</span><span class="cx">         ShouldLogError m_shouldLogError;
</span><ins>+#if ENABLE(SERVICE_WORKER)
+        std::optional<ResourceRequest> m_bypassingPreflightForServiceWorkerRequest;
+#endif
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoaderOptionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoaderOptions.h (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoaderOptions.h      2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebCore/loader/ResourceLoaderOptions.h 2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -96,6 +96,7 @@
</span><span class="cx"> enum class ServiceWorkersMode {
</span><span class="cx">     All,
</span><span class="cx">     None,
</span><ins>+    Only // An error will happen if service worker is not handling the fetch. Used to bypass preflight safely.
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> enum class ContentEncodingSniffingPolicy {
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceRequestcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp      2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp 2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -281,7 +281,7 @@
</span><span class="cx">     if (isPotentialNavigationOrSubresourceRequest(m_options.destination))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (m_options.serviceWorkersMode != ServiceWorkersMode::All)
</del><ins>+    if (m_options.serviceWorkersMode == ServiceWorkersMode::None)
</ins><span class="cx">         return;
</span><span class="cx">     if (m_options.serviceWorkerIdentifier)
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceErrorBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceErrorBase.h (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceErrorBase.h        2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebCore/platform/network/ResourceErrorBase.h   2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -60,7 +60,7 @@
</span><span class="cx"> 
</span><span class="cx">     static bool compare(const ResourceError&, const ResourceError&);
</span><span class="cx"> 
</span><del>-    void setType(Type);
</del><ins>+    WEBCORE_EXPORT void setType(Type);
</ins><span class="cx">     Type type() const { return m_type; }
</span><span class="cx"> 
</span><span class="cx"> protected:
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebKit/ChangeLog       2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2017-11-03  Youenn Fablet  <youenn@apple.com>
+
+        Requests handled by Service Worker should not go through preflighting
+        https://bugs.webkit.org/show_bug.cgi?id=179250
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::WebLoaderStrategy::scheduleLoad):
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::startFetch):
+        * WebProcess/Storage/WebServiceWorkerProvider.cpp:
+        (WebKit::shouldHandleFetch):
+
</ins><span class="cx"> 2017-11-03  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r223718): Leaking WebProcessPool after reconfiguration
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessNetworkWebLoaderStrategycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp     2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp        2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -219,6 +219,14 @@
</span><span class="cx">     WebServiceWorkerProvider::singleton().handleFetch(resourceLoader, resource, sessionID, [trackingParameters, sessionID, shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime = maximumBufferingTime(resource), resourceLoader = makeRef(resourceLoader)] (ServiceWorkerClientFetch::Result result) mutable {
</span><span class="cx">         if (result != ServiceWorkerClientFetch::Result::Unhandled)
</span><span class="cx">             return;
</span><ins>+        if (resourceLoader->options().serviceWorkersMode == ServiceWorkersMode::Only) {
+            callOnMainThread([resourceLoader = WTFMove(resourceLoader)] {
+                auto error = internalError(resourceLoader->request().url());
+                error.setType(ResourceError::Type::AccessControl);
+                resourceLoader->didFail(error);
+            });
+            return;
+        }
</ins><span class="cx"> 
</span><span class="cx">         LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled through ServiceWorker handle fetch algorithm", resourceLoader->url().string().latin1().data());
</span><span class="cx">         WebProcess::singleton().webLoaderStrategy().scheduleLoadFromNetworkProcess(resourceLoader.get(), resourceLoader->originalRequest(), trackingParameters, sessionID, shouldClearReferrerOnHTTPSToHTTPRedirect, maximumBufferingTime);
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWClientConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp    2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -114,7 +114,7 @@
</span><span class="cx"> 
</span><span class="cx"> Ref<ServiceWorkerClientFetch> WebSWClientConnection::startFetch(WebServiceWorkerProvider& provider, Ref<WebCore::ResourceLoader>&& loader, uint64_t identifier, ServiceWorkerClientFetch::Callback&& callback)
</span><span class="cx"> {
</span><del>-    ASSERT(loader->options().serviceWorkersMode == ServiceWorkersMode::All);
</del><ins>+    ASSERT(loader->options().serviceWorkersMode != ServiceWorkersMode::None);
</ins><span class="cx">     // FIXME: Decide whether to assert for loader->options().serviceWorkerIdentifier once we have a story for navigation loads.
</span><span class="cx"> 
</span><span class="cx">     send(Messages::WebSWServerConnection::StartFetch(identifier, loader->options().serviceWorkerIdentifier, loader->originalRequest(), loader->options()));
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebServiceWorkerProvidercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp (224438 => 224439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp      2017-11-03 23:02:16 UTC (rev 224438)
+++ trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp 2017-11-03 23:09:28 UTC (rev 224439)
</span><span class="lines">@@ -61,7 +61,7 @@
</span><span class="cx"> 
</span><span class="cx"> static inline bool shouldHandleFetch(const WebSWClientConnection& connection, CachedResource* resource, const ResourceLoaderOptions& options)
</span><span class="cx"> {
</span><del>-    if (options.serviceWorkersMode != ServiceWorkersMode::All)
</del><ins>+    if (options.serviceWorkersMode == ServiceWorkersMode::None)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     if (isPotentialNavigationOrSubresourceRequest(options.destination))
</span></span></pre>
</div>
</div>

</body>
</html>