Title: [223994] trunk
Revision
223994
Author
[email protected]
Date
2017-10-25 16:32:49 -0700 (Wed, 25 Oct 2017)

Log Message

Add service worker handle fetch support for all subresource requests
https://bugs.webkit.org/show_bug.cgi?id=178769

Patch by Youenn Fablet <[email protected]> on 2017-10-25
Reviewed by Chris Dumez.

Source/WebCore:

Test: http/tests/workers/service/image-fetch.https.html

Moving DocumentThreadableLoader logic to CachedResourceLoader to apply it for all resource loads.
Setting the selected service worker identifier for subresource only at the moment.

Testing is limited to images, future wpt tests should cover other subresource cases.

* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::prepareFetch):
* loader/cache/CachedResourceRequest.cpp:
(WebCore::CachedResourceRequest::setSelectedServiceWorkerIdentifierIfNeeded):
* loader/cache/CachedResourceRequest.h:

LayoutTests:

* http/tests/workers/service/image-fetch.https-expected.txt: Added.
* http/tests/workers/service/image-fetch.https.html: Added.
* http/tests/workers/service/resources/image-fetch-worker.js: Added.
(event.event.request.url.indexOf):
(event.event.request.url.endsWith):
* http/tests/workers/service/resources/image-fetch.js: Added.
(done):
(async.loadedImage):
(async.erroredImage):
(async.logStatus):
(async.test):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (223993 => 223994)


--- trunk/LayoutTests/ChangeLog	2017-10-25 23:24:15 UTC (rev 223993)
+++ trunk/LayoutTests/ChangeLog	2017-10-25 23:32:49 UTC (rev 223994)
@@ -1,3 +1,22 @@
+2017-10-25  Youenn Fablet  <[email protected]>
+
+        Add service worker handle fetch support for all subresource requests
+        https://bugs.webkit.org/show_bug.cgi?id=178769
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/workers/service/image-fetch.https-expected.txt: Added.
+        * http/tests/workers/service/image-fetch.https.html: Added.
+        * http/tests/workers/service/resources/image-fetch-worker.js: Added.
+        (event.event.request.url.indexOf):
+        (event.event.request.url.endsWith):
+        * http/tests/workers/service/resources/image-fetch.js: Added.
+        (done):
+        (async.loadedImage):
+        (async.erroredImage):
+        (async.logStatus):
+        (async.test):
+
 2017-10-25  Simon Fraser  <[email protected]>
 
         Aliasing of text in CSS specs is blocky and ugly

Added: trunk/LayoutTests/http/tests/workers/service/image-fetch.https-expected.txt (0 => 223994)


--- trunk/LayoutTests/http/tests/workers/service/image-fetch.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/image-fetch.https-expected.txt	2017-10-25 23:32:49 UTC (rev 223994)
@@ -0,0 +1,6 @@
+
+Status is no status
+Status is https://127.0.0.1:8443/resources/square100.png
+PASS: Loaded image
+Image size: 100x100
+

Added: trunk/LayoutTests/http/tests/workers/service/image-fetch.https.html (0 => 223994)


--- trunk/LayoutTests/http/tests/workers/service/image-fetch.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/image-fetch.https.html	2017-10-25 23:32:49 UTC (rev 223994)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+    <img id="image" _onload_="loadedImage()" _onerror_="erroredImage()"></img>
+    <script src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/workers/service/resources/image-fetch-worker.js (0 => 223994)


--- trunk/LayoutTests/http/tests/workers/service/resources/image-fetch-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/image-fetch-worker.js	2017-10-25 23:32:49 UTC (rev 223994)
@@ -0,0 +1,14 @@
+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")) {
+        status = "unknown url";
+        event.respondWith(new Response(null, {status: 404, statusText: "Not Found"}));
+        return;
+    }
+    status = event.request.url.substring(0, event.request.url.length - 18);
+    event.respondWith(fetch(status));
+});

Added: trunk/LayoutTests/http/tests/workers/service/resources/image-fetch.js (0 => 223994)


--- trunk/LayoutTests/http/tests/workers/service/resources/image-fetch.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/image-fetch.js	2017-10-25 23:32:49 UTC (rev 223994)
@@ -0,0 +1,40 @@
+function done()
+{
+    finishSWTest();
+}
+
+async function loadedImage()
+{
+    log("PASS: Loaded image");
+    log("Image size: " + image.width + "x" + image.height);
+    finishSWTest();
+}
+
+async function erroredImage()
+{
+    log("FAIL: image loading failed");
+    await logStatus();
+    finishSWTest();
+}
+
+async function logStatus()
+{
+    var response = await fetch("status");
+    log("Status is " + response.statusText);
+}
+
+async function test()
+{
+    try {
+        await navigator.serviceWorker.register("resources/image-fetch-worker.js", { });
+
+        await logStatus();
+        image.src = ""
+        await logStatus();
+    } catch(e) {
+        log("Got exception: " + e);
+        await logStatus();
+    }
+}
+
+test();

Modified: trunk/Source/WebCore/ChangeLog (223993 => 223994)


--- trunk/Source/WebCore/ChangeLog	2017-10-25 23:24:15 UTC (rev 223993)
+++ trunk/Source/WebCore/ChangeLog	2017-10-25 23:32:49 UTC (rev 223994)
@@ -1,3 +1,25 @@
+2017-10-25  Youenn Fablet  <[email protected]>
+
+        Add service worker handle fetch support for all subresource requests
+        https://bugs.webkit.org/show_bug.cgi?id=178769
+
+        Reviewed by Chris Dumez.
+
+        Test: http/tests/workers/service/image-fetch.https.html
+
+        Moving DocumentThreadableLoader logic to CachedResourceLoader to apply it for all resource loads.
+        Setting the selected service worker identifier for subresource only at the moment.
+
+        Testing is limited to images, future wpt tests should cover other subresource cases.
+
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::prepareFetch):
+        * loader/cache/CachedResourceRequest.cpp:
+        (WebCore::CachedResourceRequest::setSelectedServiceWorkerIdentifierIfNeeded):
+        * loader/cache/CachedResourceRequest.h:
+
 2017-10-25  Simon Fraser  <[email protected]>
 
         Aliasing of text in CSS specs is blocky and ugly

Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp (223993 => 223994)


--- trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2017-10-25 23:24:15 UTC (rev 223993)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2017-10-25 23:32:49 UTC (rev 223994)
@@ -103,11 +103,6 @@
 {
     relaxAdoptionRequirement();
 
-#if ENABLE(SERVICE_WORKER)
-    if (m_options.serviceWorkersMode == ServiceWorkersMode::All && !m_options.serviceWorkerIdentifier)
-        m_options.serviceWorkerIdentifier = document.selectedServiceWorkerIdentifier();
-#endif
-
     // Setting a referrer header is only supported in the async code path.
     ASSERT(m_async || m_referrer.isEmpty());
 

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (223993 => 223994)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2017-10-25 23:24:15 UTC (rev 223993)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2017-10-25 23:32:49 UTC (rev 223994)
@@ -686,9 +686,15 @@
 void CachedResourceLoader::prepareFetch(CachedResource::Type type, CachedResourceRequest& request)
 {
     // Implementing step 1 to 7 of https://fetch.spec.whatwg.org/#fetching
+    auto* document = this->document();
 
-    if (!request.origin() && document())
-        request.setOrigin(document()->securityOrigin());
+    if (document) {
+        if (!request.origin())
+            request.setOrigin(document->securityOrigin());
+#if ENABLE(SERVICE_WORKER)
+        request.setSelectedServiceWorkerIdentifierIfNeeded(document->selectedServiceWorkerIdentifier());
+#endif
+    }
 
     request.setAcceptHeaderIfNone(type);
 

Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp (223993 => 223994)


--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp	2017-10-25 23:24:15 UTC (rev 223993)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp	2017-10-25 23:32:49 UTC (rev 223994)
@@ -273,4 +273,21 @@
     m_options.destination = destination;
 }
 
+#if ENABLE(SERVICE_WORKER)
+void CachedResourceRequest::setSelectedServiceWorkerIdentifierIfNeeded(uint64_t serviceWorkerIdentifier)
+{
+    if (isNonSubresourceRequest(m_options.destination))
+        return;
+    if (isPotentialNavigationOrSubresourceRequest(m_options.destination))
+        return;
+
+    if (m_options.serviceWorkersMode != ServiceWorkersMode::All)
+        return;
+    if (m_options.serviceWorkerIdentifier)
+        return;
+
+    m_options.serviceWorkerIdentifier = serviceWorkerIdentifier;
+}
+#endif
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.h (223993 => 223994)


--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.h	2017-10-25 23:24:15 UTC (rev 223993)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.h	2017-10-25 23:32:49 UTC (rev 223994)
@@ -95,6 +95,10 @@
 
     static String splitFragmentIdentifierFromRequestURL(ResourceRequest&);
 
+#if ENABLE(SERVICE_WORKER)
+    void setSelectedServiceWorkerIdentifierIfNeeded(uint64_t serviceWorkerIdentifier);
+#endif
+
 private:
     ResourceRequest m_resourceRequest;
     String m_charset;

Modified: trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp (223993 => 223994)


--- trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp	2017-10-25 23:24:15 UTC (rev 223993)
+++ trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp	2017-10-25 23:32:49 UTC (rev 223994)
@@ -64,12 +64,11 @@
     if (options.serviceWorkersMode != ServiceWorkersMode::All)
         return false;
 
-    // FIXME: We should probably assert that options.serviceWorkersIdentifier is not null.
     if (isPotentialNavigationOrSubresourceRequest(options.destination))
         return false;
 
     // FIXME: Implement non-subresource request loads.
-    if (isNonSubresourceRequest(options.destination))
+    if (isNonSubresourceRequest(options.destination) || !options.serviceWorkerIdentifier)
         return false;
 
     if (!resource)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to