FormDataElement::lengthInBytes should use ThreadableBlobRegistry
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jan 2018 20:41:55 +0000 (20:41 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jan 2018 20:41:55 +0000 (20:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181554

Patch by Youenn Fablet <youenn@apple.com> on 2018-01-12
Reviewed by Chris Dumez.

Source/WebCore:

Covered by updated test.

Fix blobRegistry() use and add support for creating a response that may trigger the issue.

* platform/network/FormData.cpp:
(WebCore::FormDataElement::lengthInBytes const): Was using directly blobRegistry() while ThreadableBlobRegistry is more appropriate
in case this is called from workers.
* Modules/fetch/FetchBody.h:
* Modules/fetch/FetchResponse.h:
* fileapi/Blob.h:
* testing/ServiceWorkerInternals.cpp:
(WebCore::ServiceWorkerInternals::createOpaqueWithBlobBodyResponse):
* testing/ServiceWorkerInternals.h:
* testing/ServiceWorkerInternals.idl:

LayoutTests:

* http/tests/workers/service/resources/service-worker-cache-api-worker.js:
(async):
(event.event.request.url.indexOf): Deleted.
(event.event.request.url.endsWith): Deleted.
(event.event.respondWith.promise.then): Deleted.
* http/tests/workers/service/service-worker-cache-api.https-expected.txt:
* http/tests/workers/service/service-worker-cache-api.https.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226906 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/resources/service-worker-cache-api-worker.js
LayoutTests/http/tests/workers/service/service-worker-cache-api.https-expected.txt
LayoutTests/http/tests/workers/service/service-worker-cache-api.https.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchBody.h
Source/WebCore/Modules/fetch/FetchResponse.h
Source/WebCore/fileapi/Blob.h
Source/WebCore/platform/network/FormData.cpp
Source/WebCore/testing/ServiceWorkerInternals.cpp
Source/WebCore/testing/ServiceWorkerInternals.h
Source/WebCore/testing/ServiceWorkerInternals.idl

index 7bdbe26..d99250b 100644 (file)
@@ -1,5 +1,20 @@
 2018-01-12  Youenn Fablet  <youenn@apple.com>
 
+        FormDataElement::lengthInBytes should use ThreadableBlobRegistry
+        https://bugs.webkit.org/show_bug.cgi?id=181554
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/workers/service/resources/service-worker-cache-api-worker.js:
+        (async):
+        (event.event.request.url.indexOf): Deleted.
+        (event.event.request.url.endsWith): Deleted.
+        (event.event.respondWith.promise.then): Deleted.
+        * http/tests/workers/service/service-worker-cache-api.https-expected.txt:
+        * http/tests/workers/service/service-worker-cache-api.https.html:
+
+2018-01-12  Youenn Fablet  <youenn@apple.com>
+
         WebProcess should pass the registration identifier and not the worker identifier for fetch events
         https://bugs.webkit.org/show_bug.cgi?id=181591
 
index e69b74a..1c47a48 100644 (file)
@@ -18,11 +18,20 @@ function statusResponse()
     return new Response(null, {status: 200, statusText: status});
 }
 
-self.addEventListener("fetch", (event) => {
+self.addEventListener("fetch", async (event) => {
     if (event.request.url.indexOf("status") !== -1) {
         event.respondWith(promise.then(statusResponse, statusResponse));
         return;
     }
+    if (event.request.url.indexOf("opaqueWithBlob") !== -1) {
+        event.respondWith(self.caches.open("opaque").then((cache) => {
+            let response = self.internals.createOpaqueWithBlobBodyResponse();
+            return cache.put("opaque", response);
+        }).then(() => {
+            return new Response("PASS");
+        }));
+        return;
+    }
     if (!event.request.url.endsWith(".fromserviceworker")) {
         state = "unknown url";
         event.respondWith(new Response(null, {status: 404, statusText: "Not Found"}));
index c413065..6879537 100644 (file)
@@ -6,14 +6,23 @@
 </head>
 <body>
 <script>
+var frame;
 promise_test(async (test) => {
-    var frame = await interceptedFrame("resources/service-worker-cache-api-worker.js", "/workers/service/resources/");
+    frame = await interceptedFrame("resources/service-worker-cache-api-worker.js", "/workers/service/resources/");
     var fetch = frame.contentWindow.fetch;
 
     var response = await fetch("/resources/square100.png.fromserviceworker");
     var buffer =  await response.arrayBuffer();
     assert_equals(buffer.byteLength, 12940);
 }, "Testing cache API in service worker");
+
+promise_test(async (test) => {
+    if (!self.internals)
+        return Promise.reject("internals required for this test");
+
+    var response = await frame.contentWindow.fetch("opaqueWithBlob");
+    assert_equals(await response.text(), "PASS");
+}, "Testing cache API with opaque response + blob");
 </script>
 </body>
 </html>
index 43ad735..67d4fd9 100644 (file)
@@ -1,3 +1,26 @@
+2018-01-12  Youenn Fablet  <youenn@apple.com>
+
+        FormDataElement::lengthInBytes should use ThreadableBlobRegistry
+        https://bugs.webkit.org/show_bug.cgi?id=181554
+
+        Reviewed by Chris Dumez.
+
+        Covered by updated test.
+
+        Fix blobRegistry() use and add support for creating a response that may trigger the issue.
+
+
+        * platform/network/FormData.cpp:
+        (WebCore::FormDataElement::lengthInBytes const): Was using directly blobRegistry() while ThreadableBlobRegistry is more appropriate
+        in case this is called from workers.
+        * Modules/fetch/FetchBody.h:
+        * Modules/fetch/FetchResponse.h:
+        * fileapi/Blob.h:
+        * testing/ServiceWorkerInternals.cpp:
+        (WebCore::ServiceWorkerInternals::createOpaqueWithBlobBodyResponse):
+        * testing/ServiceWorkerInternals.h:
+        * testing/ServiceWorkerInternals.idl:
+
 2018-01-12  Jer Noble  <jer.noble@apple.com>
 
         Wrap CDMFairPlayStreaming and related classes in ENABLE(ENCRYPTED_MEDIA) checks
index ac5f4ee..a2475ea 100644 (file)
@@ -58,7 +58,7 @@ public:
     static FetchBody extract(ScriptExecutionContext&, Init&&, String&);
     FetchBody() = default;
 
-    static std::optional<FetchBody> fromFormData(FormData&);
+    WEBCORE_EXPORT static std::optional<FetchBody> fromFormData(FormData&);
 
     void loadingFailed();
     void loadingSucceeded();
index cfc46d2..36f8a1f 100644 (file)
@@ -53,7 +53,7 @@ public:
         std::optional<FetchHeaders::Init> headers;
     };
 
-    static Ref<FetchResponse> create(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
+    WEBCORE_EXPORT static Ref<FetchResponse> create(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
 
     static ExceptionOr<Ref<FetchResponse>> create(ScriptExecutionContext&, std::optional<FetchBody::Init>&&, Init&&);
     static Ref<FetchResponse> error(ScriptExecutionContext&);
@@ -101,6 +101,8 @@ public:
     void setBodySizeWithPadding(uint64_t size) { m_bodySizeWithPadding = size; }
     uint64_t opaqueLoadIdentifier() const { return m_opaqueLoadIdentifier; }
 
+    void initializeOpaqueLoadIdentifierForTesting() { m_opaqueLoadIdentifier = 1; }
+
 private:
     FetchResponse(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
 
index caeddc8..20139c4 100644 (file)
@@ -103,7 +103,7 @@ public:
     }
 
 protected:
-    Blob();
+    WEBCORE_EXPORT Blob();
     Blob(Vector<BlobPartVariant>&&, const BlobPropertyBag&);
     Blob(const SharedBuffer&, const String& contentType);
     Blob(Vector<uint8_t>&&, const String& contentType);
index aa005ef..65accc4 100644 (file)
@@ -143,7 +143,7 @@ uint64_t FormDataElement::lengthInBytes() const
         return 0;
     }
     case Type::EncodedBlob:
-        return blobRegistry().blobSize(m_url);
+        return ThreadableBlobRegistry::blobSize(m_url);
     }
     ASSERT_NOT_REACHED();
     return 0;
index 794865c..090537b 100644 (file)
@@ -66,6 +66,20 @@ Ref<FetchEvent> ServiceWorkerInternals::createBeingDispatchedFetchEvent(ScriptEx
     return event;
 }
 
+Ref<FetchResponse> ServiceWorkerInternals::createOpaqueWithBlobBodyResponse(ScriptExecutionContext& context)
+{
+    auto blob = Blob::create();
+    auto formData = FormData::create();
+    formData->appendBlob(blob->url());
+
+    ResourceResponse response;
+    response.setType(ResourceResponse::Type::Cors);
+    response.setTainting(ResourceResponse::Tainting::Opaque);
+    auto fetchResponse = FetchResponse::create(context, FetchBody::fromFormData(formData), FetchHeaders::create(), WTFMove(response));
+    fetchResponse->initializeOpaqueLoadIdentifierForTesting();
+    return fetchResponse;
+}
+
 } // namespace WebCore
 
 #endif
index 716aea5..9b03c62 100644 (file)
@@ -45,6 +45,7 @@ public:
     void setOnline(bool isOnline);
     void waitForFetchEventToFinish(FetchEvent&, DOMPromiseDeferred<IDLInterface<FetchResponse>>&&);
     Ref<FetchEvent> createBeingDispatchedFetchEvent(ScriptExecutionContext&);
+    Ref<FetchResponse> createOpaqueWithBlobBodyResponse(ScriptExecutionContext&);
 
 private:
     explicit ServiceWorkerInternals(ServiceWorkerIdentifier);
index 2133cc1..42c1db8 100644 (file)
@@ -32,4 +32,5 @@
     void setOnline(boolean isOnline);
     Promise<Response> waitForFetchEventToFinish(FetchEvent event);
     [CallWith=ScriptExecutionContext] FetchEvent createBeingDispatchedFetchEvent();
+    [CallWith=ScriptExecutionContext] FetchResponse createOpaqueWithBlobBodyResponse();
 };