Title: [228326] trunk
Revision
228326
Author
commit-qu...@webkit.org
Date
2018-02-09 10:27:13 -0800 (Fri, 09 Feb 2018)

Log Message

Add support for cache storage of blob response
https://bugs.webkit.org/show_bug.cgi?id=182637

Patch by Youenn Fablet <you...@apple.com> on 2018-02-09
Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js:
(cache_test.async):
* web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/window/cache-put.https.html:

Source/WebCore:

Covered by updated WPT test.
When putting a blob response in cache, create a readable stream to easily get the body.
Make clear that caching form data is not supported.

* Modules/cache/DOMCache.cpp:
(WebCore::DOMCache::put):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::isBlob const):
(WebCore::FetchBody::isFormData const):
* Modules/fetch/FetchResponse.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (228325 => 228326)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2018-02-09 18:27:13 UTC (rev 228326)
@@ -1,3 +1,17 @@
+2018-02-09  Youenn Fablet  <you...@apple.com>
+
+        Add support for cache storage of blob response
+        https://bugs.webkit.org/show_bug.cgi?id=182637
+
+        Reviewed by Brady Eidson.
+
+        * web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js:
+        (cache_test.async):
+        * web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt:
+        * web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
+        * web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
+        * web-platform-tests/service-workers/cache-storage/window/cache-put.https.html:
+
 2018-02-09  Javier Fernandez  <jfernan...@igalia.com>
 
         [css-align] Implement the new behavior of 'legacy' for justify-items

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js (228325 => 228326)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/script-tests/cache-put.js	2018-02-09 18:27:13 UTC (rev 228326)
@@ -335,4 +335,12 @@
         });
   }, 'Cache.put should store Response.redirect() correctly');
 
+cache_test(async (cache) => {
+    var request = new Request(test_url);
+    var response = new Response(new Blob([test_body]));
+    await cache.put(request, response);
+    var cachedResponse = await cache.match(request);
+    assert_equals(await cachedResponse.text(), test_body);
+  }, 'Cache.put called with simple Request and blob Response');
+
 done();

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt (228325 => 228326)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-put.https-expected.txt	2018-02-09 18:27:13 UTC (rev 228326)
@@ -23,4 +23,5 @@
 PASS Cache.put with a VARY:* Response 
 PASS Cache.put with an embedded VARY:* Response 
 PASS Cache.put should store Response.redirect() correctly 
+PASS Cache.put called with simple Request and blob Response 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt (228325 => 228326)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt	2018-02-09 18:27:13 UTC (rev 228326)
@@ -22,4 +22,6 @@
 PASS Cache.put with a VARY:* Response 
 PASS Cache.put with an embedded VARY:* Response 
 PASS Cache.put should store Response.redirect() correctly 
+PASS Cache.put called with simple Request and blob Response 
+FAIL Cache.put called with simple Request and form data Response promise_test: Unhandled rejection with value: object "NotSupportedError: Not implemented"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https.html (228325 => 228326)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https.html	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https.html	2018-02-09 18:27:13 UTC (rev 228326)
@@ -6,3 +6,16 @@
 <script src=""
 <script src=""
 <script src=""
+<script>
+cache_test(async (cache) => {
+    var formData = new FormData();
+    formData.append("name", "value");
+
+    var request = new Request(test_url);
+    var response = new Response(formData);
+    await cache.put(request, response);
+    var cachedResponse = await cache.match(request);
+    var cachedResponseText = await cachedResponse.text();
+    assert_true(cachedResponseText.indexOf("name=\"name\"\r\n\r\nvalue") !== -1);
+  }, 'Cache.put called with simple Request and form data Response');
+</script>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt (228325 => 228326)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt	2018-02-09 18:27:13 UTC (rev 228326)
@@ -22,4 +22,5 @@
 PASS Cache.put with a VARY:* Response 
 PASS Cache.put with an embedded VARY:* Response 
 PASS Cache.put should store Response.redirect() correctly 
+PASS Cache.put called with simple Request and blob Response 
 

Modified: trunk/Source/WebCore/ChangeLog (228325 => 228326)


--- trunk/Source/WebCore/ChangeLog	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/Source/WebCore/ChangeLog	2018-02-09 18:27:13 UTC (rev 228326)
@@ -1,5 +1,23 @@
 2018-02-09  Youenn Fablet  <you...@apple.com>
 
+        Add support for cache storage of blob response
+        https://bugs.webkit.org/show_bug.cgi?id=182637
+
+        Reviewed by Brady Eidson.
+
+        Covered by updated WPT test.
+        When putting a blob response in cache, create a readable stream to easily get the body.
+        Make clear that caching form data is not supported.
+
+        * Modules/cache/DOMCache.cpp:
+        (WebCore::DOMCache::put):
+        * Modules/fetch/FetchBody.h:
+        (WebCore::FetchBody::isBlob const):
+        (WebCore::FetchBody::isFormData const):
+        * Modules/fetch/FetchResponse.h:
+
+2018-02-09  Youenn Fablet  <you...@apple.com>
+
         Make CoreAudioCaptureSource error logging be release logging
         https://bugs.webkit.org/show_bug.cgi?id=182614
 

Modified: trunk/Source/WebCore/Modules/cache/DOMCache.cpp (228325 => 228326)


--- trunk/Source/WebCore/Modules/cache/DOMCache.cpp	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/Source/WebCore/Modules/cache/DOMCache.cpp	2018-02-09 18:27:13 UTC (rev 228326)
@@ -340,6 +340,15 @@
         return;
     }
 
+    if (response->isBlobFormData()) {
+        promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
+        return;
+    }
+
+    // FIXME: for efficiency, we should load blobs directly instead of going through the readableStream path.
+    if (response->isBlobBody())
+        response->readableStream(*scriptExecutionContext()->execState());
+
     if (response->isBodyReceivedByChunk()) {
         response->consumeBodyReceivedByChunk([promise = WTFMove(promise), request = WTFMove(request), response = WTFMove(response), data = "" pendingActivity = makePendingActivity(*this), this](auto&& result) mutable {
 

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (228325 => 228326)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.h	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h	2018-02-09 18:27:13 UTC (rev 228326)
@@ -85,6 +85,9 @@
         m_readableStream = WTFMove(stream);
     }
 
+    bool isBlob() const { return WTF::holds_alternative<Ref<const Blob>>(m_data); }
+    bool isFormData() const { return WTF::holds_alternative<Ref<FormData>>(m_data); }
+
 private:
     explicit FetchBody(Ref<const Blob>&& data) : m_data(WTFMove(data)) { }
     explicit FetchBody(Ref<const ArrayBuffer>&& data) : m_data(WTFMove(data)) { }
@@ -102,8 +105,6 @@
     void consumeText(Ref<DeferredPromise>&&, const String&);
     void consumeBlob(FetchBodyOwner&, Ref<DeferredPromise>&&);
 
-    bool isBlob() const { return WTF::holds_alternative<Ref<const Blob>>(m_data); }
-    bool isFormData() const { return WTF::holds_alternative<Ref<FormData>>(m_data); }
     bool isArrayBuffer() const { return WTF::holds_alternative<Ref<const ArrayBuffer>>(m_data); }
     bool isArrayBufferView() const { return WTF::holds_alternative<Ref<const ArrayBufferView>>(m_data); }
     bool isURLSearchParams() const { return WTF::holds_alternative<Ref<const URLSearchParams>>(m_data); }

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (228325 => 228326)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2018-02-09 18:10:53 UTC (rev 228325)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2018-02-09 18:27:13 UTC (rev 228326)
@@ -93,6 +93,8 @@
 
     bool isLoading() const { return !!m_bodyLoader; }
     bool isBodyReceivedByChunk() const { return isLoading() || hasReadableStreamBody(); }
+    bool isBlobBody() const { return !isBodyNull() && body().isBlob(); }
+    bool isBlobFormData() const { return !isBodyNull() && body().isFormData(); }
 
     using ConsumeDataByChunkCallback = WTF::Function<void(ExceptionOr<ReadableStreamChunk*>&&)>;
     void consumeBodyReceivedByChunk(ConsumeDataByChunkCallback&&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to