Diff
Modified: trunk/LayoutTests/ChangeLog (220947 => 220948)
--- trunk/LayoutTests/ChangeLog 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/LayoutTests/ChangeLog 2017-08-19 01:29:50 UTC (rev 220948)
@@ -1,3 +1,12 @@
+2017-08-18 Youenn Fablet <[email protected]>
+
+ [Cache API] Add support for being loaded responses
+ https://bugs.webkit.org/show_bug.cgi?id=175732
+
+ Reviewed by Chris Dumez.
+
+ * TestExpectations: Removing some flaky test expectations.
+
2017-08-18 Chris Dumez <[email protected]>
[Beacon] Improve error reporting
Modified: trunk/LayoutTests/TestExpectations (220947 => 220948)
--- trunk/LayoutTests/TestExpectations 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/LayoutTests/TestExpectations 2017-08-19 01:29:50 UTC (rev 220948)
@@ -120,9 +120,7 @@
imported/w3c/web-platform-tests/service-workers/stub-4.6.2-cache.html [ Pass ]
imported/w3c/web-platform-tests/service-workers/stub-4.6.3-cache-storage.html [ Pass ]
imported/w3c/web-platform-tests/service-workers/cache-storage [ Pass ]
-imported/w3c/web-platform-tests/service-workers/cache-storage/window [ Pass Failure ]
-imported/w3c/web-platform-tests/service-workers/cache-storage/common.https.html [ Skip ]
-imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-match.https.html [ Pass Failure ]
+imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https.html [ Pass Failure ]
imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https.html [ Pass Failure ]
# textarea.animate is not supported
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (220947 => 220948)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-08-19 01:29:50 UTC (rev 220948)
@@ -1,5 +1,14 @@
2017-08-18 Youenn Fablet <[email protected]>
+ [Cache API] Add support for being loaded responses
+ https://bugs.webkit.org/show_bug.cgi?id=175732
+
+ Reviewed by Chris Dumez.
+
+ * web-platform-tests/service-workers/cache-storage/common.https-expected.txt:
+
+2017-08-18 Youenn Fablet <[email protected]>
+
[Cache API] Add response body storage
https://bugs.webkit.org/show_bug.cgi?id=175658
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/common.https-expected.txt (220947 => 220948)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/common.https-expected.txt 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/common.https-expected.txt 2017-08-19 01:29:50 UTC (rev 220948)
@@ -1,3 +1,3 @@
-FAIL Window sees cache puts by Worker promise_test: Unhandled rejection with value: object "TypeError: Not implemented"
+PASS Window sees cache puts by Worker
Modified: trunk/Source/WebCore/ChangeLog (220947 => 220948)
--- trunk/Source/WebCore/ChangeLog 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/Source/WebCore/ChangeLog 2017-08-19 01:29:50 UTC (rev 220948)
@@ -1,3 +1,34 @@
+2017-08-18 Youenn Fablet <[email protected]>
+
+ [Cache API] Add support for being loaded responses
+ https://bugs.webkit.org/show_bug.cgi?id=175732
+
+ Reviewed by Chris Dumez.
+
+ Covered by existing and rebased tests.
+
+ Introducing a callback-based method to consume the body when the load is finished.
+ Using that new method in Cache::put and calling batchPutOperation when the load is finished.
+
+ Fixing the case of a fetch response being cloned, in which case its body should be marked as ReadableStream.
+
+ * Modules/cache/Cache.cpp:
+ (WebCore::Cache::put): Changing order of checks to reduce test flakiness risks as there is not yet support for putting responses with ReadableStream.
+ (WebCore::toConnectionRecord):
+ (WebCore::Cache::batchPutOperation):
+ * Modules/cache/Cache.h:
+ * Modules/fetch/FetchBody.cpp:
+ (WebCore::FetchBody::readableStreamBody): Deleted.
+ * Modules/fetch/FetchBody.h:
+ (WebCore::FetchBody::loadingBody):
+ (WebCore::FetchBody::setAsReadableStream):
+ * Modules/fetch/FetchResponse.cpp:
+ (WebCore::FetchResponse::BodyLoader::didSucceed):
+ (WebCore::FetchResponse::BodyLoader::didFail):
+ (WebCore::FetchResponse::consumeBody):
+ (WebCore::FetchResponse::consumeBodyWhenLoaded):
+ * Modules/fetch/FetchResponse.h:
+
2017-08-18 Chris Dumez <[email protected]>
[Beacon] Improve error reporting
Modified: trunk/Source/WebCore/Modules/cache/Cache.cpp (220947 => 220948)
--- trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/Source/WebCore/Modules/cache/Cache.cpp 2017-08-19 01:29:50 UTC (rev 220948)
@@ -150,29 +150,41 @@
}
}
- if (response->isDisturbed()) {
- promise.reject(Exception { TypeError, ASCIILiteral("Response is disturbed or locked") });
+ if (response->status() == 206) {
+ promise.reject(Exception { TypeError, ASCIILiteral("Response is a 206 partial") });
return;
}
- if (response->status() == 206) {
- promise.reject(Exception { TypeError, ASCIILiteral("Response is a 206 partial") });
+ // FIXME: Add support for ReadableStream.
+ if (response->isReadableStreamBody()) {
+ promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a Response with data stored in a ReadableStream is not yet supported") });
return;
}
- // FIXME: Add support for being loaded responses.
- if (response->isLoading()) {
- promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a loading Response is not yet supported") });
+ if (response->isDisturbed()) {
+ promise.reject(Exception { TypeError, ASCIILiteral("Response is disturbed or locked") });
return;
}
- // FIXME: Add support for ReadableStream.
- if (response->isReadableStreamBody()) {
- promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a Response with data stored in a ReadableStream is not yet supported") });
+ if (response->isLoading()) {
+ setPendingActivity(this);
+ response->consumeBodyWhenLoaded([promise = WTFMove(promise), request = request.releaseNonNull(), response = WTFMove(response), this](ExceptionOr<RefPtr<SharedBuffer>>&& result) mutable {
+ if (result.hasException())
+ promise.reject(result.releaseException());
+ else {
+ CacheStorageConnection::ResponseBody body;
+ if (auto buffer = result.releaseReturnValue())
+ body = buffer.releaseNonNull();
+ batchPutOperation(request.get(), response.get(), WTFMove(body), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
+ promise.settle(WTFMove(result));
+ });
+ }
+ unsetPendingActivity(this);
+ });
return;
}
- batchPutOperation(*request, response.get(), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
+ batchPutOperation(*request, response.get(), response->consumeBody(), [promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable {
promise.settle(WTFMove(result));
});
}
@@ -283,7 +295,7 @@
});
}
-static inline CacheStorageConnection::Record toConnectionRecord(const FetchRequest& request, FetchResponse& response)
+static inline CacheStorageConnection::Record toConnectionRecord(const FetchRequest& request, FetchResponse& response, CacheStorageConnection::ResponseBody&& responseBody)
{
// FIXME: Add a setHTTPHeaderFields on ResourceResponseBase.
ResourceResponse cachedResponse = response.resourceResponse();
@@ -295,14 +307,14 @@
return { 0,
request.headers().guard(), WTFMove(cachedRequest), request.fetchOptions(), request.internalRequestReferrer(),
- response.headers().guard(), WTFMove(cachedResponse), response.consumeBody()
+ response.headers().guard(), WTFMove(cachedResponse), WTFMove(responseBody)
};
}
-void Cache::batchPutOperation(const FetchRequest& request, FetchResponse& response, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
+void Cache::batchPutOperation(const FetchRequest& request, FetchResponse& response, CacheStorageConnection::ResponseBody&& responseBody, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
{
Vector<CacheStorageConnection::Record> records;
- records.append(toConnectionRecord(request, response));
+ records.append(toConnectionRecord(request, response, WTFMove(responseBody)));
setPendingActivity(this);
m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, callback = WTFMove(callback)](Vector<uint64_t>&&, CacheStorageConnection::Error error) {
Modified: trunk/Source/WebCore/Modules/cache/Cache.h (220947 => 220948)
--- trunk/Source/WebCore/Modules/cache/Cache.h 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/Source/WebCore/Modules/cache/Cache.h 2017-08-19 01:29:50 UTC (rev 220948)
@@ -69,7 +69,7 @@
Vector<CacheStorageRecord> queryCacheWithTargetStorage(const FetchRequest&, const CacheQueryOptions&, const Vector<CacheStorageRecord>&);
void queryCache(Ref<FetchRequest>&&, CacheQueryOptions&&, WTF::Function<void(const Vector<CacheStorageRecord>&)>&&);
void batchDeleteOperation(const FetchRequest&, CacheQueryOptions&&, WTF::Function<void(ExceptionOr<bool>&&)>&&);
- void batchPutOperation(const FetchRequest&, FetchResponse&, WTF::Function<void(ExceptionOr<void>&&)>&&);
+ void batchPutOperation(const FetchRequest&, FetchResponse&, CacheStorageConnection::ResponseBody&&, WTF::Function<void(ExceptionOr<void>&&)>&&);
void updateRecords(Vector<CacheStorageConnection::Record>&&);
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (220947 => 220948)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2017-08-19 01:29:50 UTC (rev 220948)
@@ -74,13 +74,6 @@
return FetchBody(WTFMove(WTF::get<String>(value)));
}
-FetchBody FetchBody::readableStreamBody()
-{
- FetchBody body;
- body.m_isReadableStream = true;
- return body;
-}
-
void FetchBody::arrayBuffer(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
{
m_consumer.setType(FetchBodyConsumer::Type::ArrayBuffer);
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (220947 => 220948)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.h 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h 2017-08-19 01:29:50 UTC (rev 220948)
@@ -64,8 +64,8 @@
using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, String>;
static FetchBody extract(ScriptExecutionContext&, Init&&, String&);
static FetchBody loadingBody() { return { }; }
- static FetchBody readableStreamBody();
+ void setAsReadableStream() { m_isReadableStream = true; }
void loadingFailed();
void loadingSucceeded();
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (220947 => 220948)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2017-08-19 01:29:50 UTC (rev 220948)
@@ -81,8 +81,9 @@
void FetchResponse::setBodyAsReadableStream()
{
- ASSERT(isBodyNull());
- setBody(FetchBody::readableStreamBody());
+ if (isBodyNull())
+ setBody(FetchBody::loadingBody());
+ body().setAsReadableStream();
updateContentType();
}
@@ -132,6 +133,8 @@
if (m_response.m_readableStreamSource && !m_response.body().consumer().hasData())
m_response.closeStream();
#endif
+ if (auto consumeDataCallback = WTFMove(m_consumeDataCallback))
+ consumeDataCallback(m_response.body().consumer().takeData());
if (m_loader->isStarted()) {
Ref<FetchResponse> protector(m_response);
@@ -145,6 +148,9 @@
if (auto responseCallback = WTFMove(m_responseCallback))
responseCallback(Exception { TypeError, String(error.localizedDescription()) });
+ if (auto consumeDataCallback = WTFMove(m_consumeDataCallback))
+ consumeDataCallback(Exception { TypeError, String(error.localizedDescription()) });
+
#if ENABLE(STREAMS_API)
if (m_response.m_readableStreamSource) {
if (!m_response.m_readableStreamSource->isCancelling())
@@ -260,6 +266,8 @@
FetchResponse::ResponseData FetchResponse::consumeBody()
{
+ ASSERT(!isLoading());
+
if (isBodyNull())
return nullptr;
@@ -269,6 +277,16 @@
return body().take();
}
+void FetchResponse::consumeBodyWhenLoaded(ConsumeDataCallback&& callback)
+{
+ ASSERT(isLoading());
+
+ ASSERT(!m_isDisturbed);
+ m_isDisturbed = true;
+
+ m_bodyLoader->setConsumeDataCallback(WTFMove(callback));
+}
+
void FetchResponse::setBodyData(ResponseData&& data)
{
WTF::switchOn(data, [this](Ref<FormData>& formData) {
@@ -316,7 +334,9 @@
ASSERT(m_bodyLoader);
- RefPtr<SharedBuffer> data = ""
+ setBodyAsReadableStream();
+
+ auto data = ""
if (data) {
if (!m_readableStreamSource->enqueue(data->tryCreateArrayBuffer())) {
stop();
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (220947 => 220948)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2017-08-19 00:30:59 UTC (rev 220947)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2017-08-19 01:29:50 UTC (rev 220948)
@@ -94,8 +94,12 @@
using ResponseData = Variant<std::nullptr_t, Ref<FormData>, Ref<SharedBuffer>>;
ResponseData consumeBody();
void setBodyData(ResponseData&&);
+
bool isLoading() const { return !!m_bodyLoader; }
+ using ConsumeDataCallback = WTF::Function<void(ExceptionOr<RefPtr<SharedBuffer>>&&)>;
+ void consumeBodyWhenLoaded(ConsumeDataCallback&&);
+
const ResourceResponse& resourceResponse() const { return m_response; }
private:
@@ -117,6 +121,8 @@
bool start(ScriptExecutionContext&, const FetchRequest&);
void stop();
+ void setConsumeDataCallback(ConsumeDataCallback&& consumeDataCallback) { m_consumeDataCallback = WTFMove(consumeDataCallback); }
+
#if ENABLE(STREAMS_API)
RefPtr<SharedBuffer> startStreaming();
#endif
@@ -130,6 +136,7 @@
FetchResponse& m_response;
NotificationCallback m_responseCallback;
+ ConsumeDataCallback m_consumeDataCallback;
std::unique_ptr<FetchLoader> m_loader;
};