Changeset 289533 in webkit
- Timestamp:
- Feb 10, 2022 7:45:10 AM (5 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/tests/navigation/fetch-pagecache-expected.txt (added)
-
LayoutTests/http/tests/navigation/fetch-pagecache.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/cache/DOMCache.cpp (modified) (3 diffs)
-
Source/WebCore/Modules/fetch/FetchResponse.cpp (modified) (2 diffs)
-
Source/WebCore/Modules/fetch/FetchResponse.h (modified) (1 diff)
-
Source/WebCore/Modules/fetch/WindowOrWorkerGlobalScopeFetch.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r289526 r289533 1 2022-02-10 Youenn Fablet <youenn@apple.com> 2 3 Settling of a fetch promise should be delayed in case page is entering page cache 4 https://bugs.webkit.org/show_bug.cgi?id=236292 5 <rdar://88452971> 6 7 Reviewed by Chris Dumez. 8 9 * http/tests/navigation/fetch-pagecache-expected.txt: Added. 10 * http/tests/navigation/fetch-pagecache.html: Added. 11 1 12 2022-02-10 Antti Koivisto <antti@apple.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r289532 r289533 1 2022-02-10 Youenn Fablet <youenn@apple.com> 2 3 Settling of a fetch promise should be delayed in case page is entering page cache 4 https://bugs.webkit.org/show_bug.cgi?id=236292 5 <rdar://88452971> 6 7 Reviewed by Chris Dumez. 8 9 Make sure to enqueue a task before resolving fetch promise as otherwise, page might continue running JavaScript. 10 Do this for worker as well for good measure. 11 We move signal aborted checks to two clients to handle rejecting fetch promise synchronously. 12 13 Test: http/tests/navigation/fetch-pagecache.html 14 15 * Modules/cache/DOMCache.cpp: 16 * Modules/fetch/FetchResponse.cpp: 17 * Modules/fetch/FetchResponse.h: 18 * Modules/fetch/WindowOrWorkerGlobalScopeFetch.cpp: 19 * workers/service/FetchEvent.cpp: 20 1 21 2022-02-10 Chris Dumez <cdumez@apple.com> 2 22 -
trunk/Source/WebCore/Modules/cache/DOMCache.cpp
r287760 r289533 260 260 for (auto& request : requests) { 261 261 auto& requestReference = request.get(); 262 FetchResponse::fetch(*scriptExecutionContext(), requestReference, [this, request = WTFMove(request), taskHandler](ExceptionOr<FetchResponse&>&& result) mutable { 262 if (requestReference.signal().aborted()) { 263 taskHandler->error(Exception { AbortError, "Request signal is aborted"_s }); 264 return; 265 } 266 FetchResponse::fetch(*scriptExecutionContext(), requestReference, [this, request = WTFMove(request), taskHandler](auto&& result) mutable { 263 267 264 268 if (taskHandler->isDone()) … … 270 274 } 271 275 272 auto& response = result.releaseReturnValue(); 276 auto protectedResponse = result.releaseReturnValue(); 277 auto& response = protectedResponse.get(); 273 278 274 279 if (!response.ok()) { … … 296 301 size_t recordPosition = taskHandler->addRecord(toConnectionRecord(request.get(), response, nullptr)); 297 302 298 response.consumeBodyReceivedByChunk([taskHandler = WTFMove(taskHandler), recordPosition, data = SharedBufferBuilder(), response = Ref { response }] (auto&& result) mutable {303 response.consumeBodyReceivedByChunk([taskHandler = WTFMove(taskHandler), recordPosition, data = SharedBufferBuilder(), response = WTFMove(protectedResponse)] (auto&& result) mutable { 299 304 if (taskHandler->isDone()) 300 305 return; -
trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp
r288088 r289533 238 238 void FetchResponse::fetch(ScriptExecutionContext& context, FetchRequest& request, NotificationCallback&& responseCallback, const String& initiator) 239 239 { 240 if (request.signal().aborted()) {241 responseCallback(Exception { AbortError, "Request signal is aborted"_s });242 // FIXME: Cancel request body if it is a stream.243 return;244 }245 246 240 if (request.isReadableStreamBody()) { 247 241 responseCallback(Exception { NotSupportedError, "ReadableStream uploading is not supported"_s }); … … 356 350 357 351 if (auto responseCallback = WTFMove(m_responseCallback)) 358 responseCallback( m_response);352 responseCallback(Ref { m_response }); 359 353 } 360 354 -
trunk/Source/WebCore/Modules/fetch/FetchResponse.h
r288088 r289533 64 64 static ExceptionOr<Ref<FetchResponse>> redirect(ScriptExecutionContext&, const String& url, int status); 65 65 66 using NotificationCallback = Function<void(ExceptionOr< FetchResponse&>&&)>;66 using NotificationCallback = Function<void(ExceptionOr<Ref<FetchResponse>>&&)>; 67 67 static void fetch(ScriptExecutionContext&, FetchRequest&, NotificationCallback&&, const String& initiator); 68 68 -
trunk/Source/WebCore/Modules/fetch/WindowOrWorkerGlobalScopeFetch.cpp
r286419 r289533 30 30 #include "DOMWindow.h" 31 31 #include "Document.h" 32 #include "EventLoop.h" 32 33 #include "FetchResponse.h" 33 34 #include "JSDOMPromiseDeferred.h" … … 40 41 using FetchResponsePromise = DOMPromiseDeferred<IDLInterface<FetchResponse>>; 41 42 42 void WindowOrWorkerGlobalScopeFetch::fetch(DOMWindow& window, FetchRequest::Info&& input, FetchRequest::Init&& init, Ref<DeferredPromise>&& deferred) 43 // https://fetch.spec.whatwg.org/#dom-global-fetch 44 static void doFetch(ScriptExecutionContext& scope, FetchRequest::Info&& input, FetchRequest::Init&& init, FetchResponsePromise&& promise) 43 45 { 44 FetchResponsePromise promise = WTFMove(deferred); 45 46 auto* document = window.document(); 47 if (!document) { 48 promise.reject(InvalidStateError); 46 auto requestOrException = FetchRequest::create(scope, WTFMove(input), WTFMove(init)); 47 if (requestOrException.hasException()) { 48 promise.reject(requestOrException.releaseException()); 49 49 return; 50 50 } 51 51 52 auto request = FetchRequest::create(*document, WTFMove(input), WTFMove(init));53 if (request .hasException()) {54 promise.reject( request.releaseException());52 auto request = requestOrException.releaseReturnValue(); 53 if (request->signal().aborted()) { 54 promise.reject(Exception { AbortError, "Request signal is aborted"_s }); 55 55 return; 56 56 } 57 57 58 FetchResponse::fetch( *document, request.releaseReturnValue(), [promise = WTFMove(promise), userGestureToken = UserGestureIndicator::currentUserGesture()](ExceptionOr<FetchResponse&>&& result) mutable {59 if (!userGestureToken || userGestureToken->hasExpired(UserGestureToken::maximumIntervalForUserGestureForwardingForFetch()) || !userGestureToken->processingUserGesture()){58 FetchResponse::fetch(scope, request.get(), [promise = WTFMove(promise), scope = Ref { scope }](auto&& result) mutable { 59 scope->eventLoop().queueTask(TaskSource::Networking, [promise = WTFMove(promise), result = WTFMove(result)]() mutable { 60 60 promise.settle(WTFMove(result)); 61 return; 62 } 63 64 UserGestureIndicator gestureIndicator(userGestureToken, UserGestureToken::GestureScope::MediaOnly, UserGestureToken::IsPropagatedFromFetch::Yes); 65 promise.settle(WTFMove(result)); 61 }); 66 62 }, cachedResourceRequestInitiators().fetch); 67 63 } 68 64 69 void WindowOrWorkerGlobalScopeFetch::fetch( WorkerGlobalScope& scope, FetchRequest::Info&& input, FetchRequest::Init&& init, Ref<DeferredPromise>&& deferred)65 void WindowOrWorkerGlobalScopeFetch::fetch(DOMWindow& window, FetchRequest::Info&& input, FetchRequest::Init&& init, Ref<DeferredPromise>&& promise) 70 66 { 71 FetchResponsePromise promise = WTFMove(deferred); 72 73 auto request = FetchRequest::create(scope, WTFMove(input), WTFMove(init)); 74 if (request.hasException()) { 75 promise.reject(request.releaseException()); 67 auto* document = window.document(); 68 if (!document) { 69 promise->reject(InvalidStateError); 76 70 return; 77 71 } 72 doFetch(*document, WTFMove(input), WTFMove(init), WTFMove(promise)); 73 } 78 74 79 FetchResponse::fetch(scope, request.releaseReturnValue().get(), [promise = WTFMove(promise)](ExceptionOr<FetchResponse&>&& result) mutable { 80 promise.settle(WTFMove(result)); 81 }, cachedResourceRequestInitiators().fetch);75 void WindowOrWorkerGlobalScopeFetch::fetch(WorkerGlobalScope& scope, FetchRequest::Info&& input, FetchRequest::Init&& init, Ref<DeferredPromise>&& promise) 76 { 77 doFetch(scope, WTFMove(input), WTFMove(init), WTFMove(promise)); 82 78 } 83 79
Note: See TracChangeset
for help on using the changeset viewer.