Changeset 287532 in webkit
- Timestamp:
- Jan 3, 2022 12:17:59 AM (7 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 19 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/wpt/fetch/clone-realm-expected.txt (modified) (1 diff)
-
LayoutTests/http/wpt/fetch/clone-realm.html (modified) (2 diffs)
-
LayoutTests/http/wpt/fetch/resources/clone-realm-iframe.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/cache/DOMCache.cpp (modified) (1 diff)
-
Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (modified) (1 diff)
-
Source/WebCore/Modules/fetch/FetchBodyOwner.h (modified) (1 diff)
-
Source/WebCore/Modules/fetch/FetchRequest.cpp (modified) (3 diffs)
-
Source/WebCore/Modules/fetch/FetchRequest.h (modified) (3 diffs)
-
Source/WebCore/Modules/fetch/FetchRequest.idl (modified) (2 diffs)
-
Source/WebCore/Modules/fetch/FetchResponse.cpp (modified) (8 diffs)
-
Source/WebCore/Modules/fetch/FetchResponse.h (modified) (2 diffs)
-
Source/WebCore/dom/AbortController.cpp (modified) (1 diff)
-
Source/WebCore/dom/AbortSignal.cpp (modified) (2 diffs)
-
Source/WebCore/dom/AbortSignal.h (modified) (2 diffs)
-
Source/WebCore/testing/Internals.cpp (modified) (2 diffs)
-
Source/WebCore/testing/Internals.h (modified) (2 diffs)
-
Source/WebCore/testing/Internals.idl (modified) (2 diffs)
-
Source/WebCore/testing/ServiceWorkerInternals.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r287530 r287532 1 2022-01-03 Youenn Fablet <youenn@apple.com> 2 3 FetchRequest.clone does not need to be called with the current context 4 https://bugs.webkit.org/show_bug.cgi?id=234515 5 6 Reviewed by Darin Adler. 7 8 * http/wpt/fetch/clone-realm-expected.txt: 9 * http/wpt/fetch/clone-realm.html: 10 * http/wpt/fetch/resources/clone-realm-iframe.html: Added. 11 1 12 2022-01-02 Diego Pino Garcia <dpino@igalia.com> 2 13 -
trunk/LayoutTests/http/wpt/fetch/clone-realm-expected.txt
r286970 r287532 1 1 2 PASS Cloning a response fails when its frame is detached 2 PASS Cloning a response succeeds even if its body is stream based 3 PASS Cloning request/response when its frame is detached 3 4 -
trunk/LayoutTests/http/wpt/fetch/clone-realm.html
r286970 r287532 16 16 }); 17 17 } 18 18 19 promise_test(async (t) => { 19 20 const frame = await with_iframe('/'); … … 21 22 await response.clone().text(); 22 23 frame.remove(); 23 try { 24 response.clone(); 25 assert_not_reached(); 26 } catch (e) { 27 assert_equals(e.name, 'InvalidStateError'); 24 response.clone(); 25 }, "Cloning a response succeeds even if its body is stream based"); 26 27 promise_test(async (t) => { 28 let frame = await with_iframe('/WebKit/fetch/resources/clone-realm-iframe.html'); 29 30 if (window.internals) { 31 assert_false(internals.isFetchObjectContextStopped(testResponse), "response before"); 32 assert_false(internals.isFetchObjectContextStopped(testRequest), "request before"); 28 33 } 29 }, "Cloning a response fails when its frame is detached"); 34 35 frame.remove(); 36 37 const clonedResponse = testResponse.clone(); 38 const clonedRequest = testRequest.clone(); 39 40 if (window.internals) { 41 assert_true(internals.isFetchObjectContextStopped(testResponse), "response after"); 42 assert_true(internals.isFetchObjectContextStopped(clonedResponse), "clonedResponse"); 43 assert_true(internals.isFetchObjectContextStopped(testRequest), "request after"); 44 assert_true(internals.isFetchObjectContextStopped(clonedRequest), "clonedRequest"); 45 } 46 }, "Cloning request/response when its frame is detached"); 47 30 48 </script> 31 49 </body> -
trunk/Source/WebCore/ChangeLog
r287529 r287532 1 2022-01-03 Youenn Fablet <youenn@apple.com> 2 3 FetchRequest.clone does not need to be called with the current context 4 https://bugs.webkit.org/show_bug.cgi?id=234515 5 6 Reviewed by Darin Adler. 7 8 Make FetchRequest, FetchResponse and FetchBodyOwner take a ScriptExecutionContext* instead of a ScriptExecutionContext&. 9 This allows cloning FetchRequest and FetchResponse with the context of the original request or response. 10 11 Update call site, as well as for AbortSignal. 12 13 For FetchResponse, we did a change to throw in case of cloning FetchResponse on a stopped context. 14 It appeared that Firefox is not doing that, and Chrome is only doing that in some specific cases. 15 For that reason, it is better to go back to our previous behavior of not throwing. 16 17 To ease testing, we add an internals API to check whether a request/response is linked to a closed context. 18 19 Covered by updated tests. 20 21 * Modules/cache/DOMCache.cpp: 22 * Modules/fetch/FetchBodyOwner.cpp: 23 * Modules/fetch/FetchBodyOwner.h: 24 * Modules/fetch/FetchRequest.cpp: 25 * Modules/fetch/FetchRequest.h: 26 * Modules/fetch/FetchRequest.idl: 27 * Modules/fetch/FetchResponse.cpp: 28 * Modules/fetch/FetchResponse.h: 29 * dom/AbortController.cpp: 30 * dom/AbortSignal.cpp: 31 * dom/AbortSignal.h: 32 * testing/Internals.cpp: 33 * testing/Internals.h: 34 * testing/Internals.idl: 35 * testing/ServiceWorkerInternals.cpp: 36 1 37 2022-01-02 Manuel Rego Casasnovas <rego@igalia.com> 2 38 -
trunk/Source/WebCore/Modules/cache/DOMCache.cpp
r287066 r287532 84 84 auto resourceResponse = record.response; 85 85 resourceResponse.setSource(ResourceResponse::Source::DOMCache); 86 auto response = FetchResponse::create( context, std::nullopt, record.responseHeadersGuard, WTFMove(resourceResponse));86 auto response = FetchResponse::create(&context, std::nullopt, record.responseHeadersGuard, WTFMove(resourceResponse)); 87 87 response->setBodyData(copyResponseBody(record.responseBody), record.responseBodySize); 88 88 return response; -
trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
r287177 r287532 42 42 namespace WebCore { 43 43 44 FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext &context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers)45 : ActiveDOMObject( &context)44 FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext* context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers) 45 : ActiveDOMObject(context) 46 46 , m_body(WTFMove(body)) 47 47 , m_headers(WTFMove(headers)) -
trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h
r287177 r287532 73 73 74 74 protected: 75 FetchBodyOwner(ScriptExecutionContext &, std::optional<FetchBody>&&, Ref<FetchHeaders>&&);75 FetchBodyOwner(ScriptExecutionContext*, std::optional<FetchBody>&&, Ref<FetchHeaders>&&); 76 76 77 77 const FetchBody& body() const { return *m_body; } -
trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp
r287177 r287532 275 275 ExceptionOr<Ref<FetchRequest>> FetchRequest::create(ScriptExecutionContext& context, Info&& input, Init&& init) 276 276 { 277 auto request = adoptRef(*new FetchRequest( context, std::nullopt, FetchHeaders::create(FetchHeaders::Guard::Request), { }, { }, { }));277 auto request = adoptRef(*new FetchRequest(&context, std::nullopt, FetchHeaders::create(FetchHeaders::Guard::Request), { }, { }, { })); 278 278 request->suspendIfNeeded(); 279 279 … … 293 293 Ref<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceRequest&& request, FetchOptions&& options, String&& referrer) 294 294 { 295 auto result = adoptRef(*new FetchRequest( context, WTFMove(body), WTFMove(headers), WTFMove(request), WTFMove(options), WTFMove(referrer)));295 auto result = adoptRef(*new FetchRequest(&context, WTFMove(body), WTFMove(headers), WTFMove(request), WTFMove(options), WTFMove(referrer))); 296 296 result->suspendIfNeeded(); 297 297 return result; … … 327 327 } 328 328 329 ExceptionOr<Ref<FetchRequest>> FetchRequest::clone( ScriptExecutionContext& context)329 ExceptionOr<Ref<FetchRequest>> FetchRequest::clone() 330 330 { 331 331 if (isDisturbedOrLocked()) 332 332 return Exception { TypeError, "Body is disturbed or locked"_s }; 333 333 334 auto clone = adoptRef(*new FetchRequest( context, std::nullopt, FetchHeaders::create(m_headers.get()), ResourceRequest { m_request }, FetchOptions { m_options }, String { m_referrer }));334 auto clone = adoptRef(*new FetchRequest(scriptExecutionContext(), std::nullopt, FetchHeaders::create(m_headers.get()), ResourceRequest { m_request }, FetchOptions { m_options }, String { m_referrer })); 335 335 clone->suspendIfNeeded(); 336 336 clone->cloneBody(*this); -
trunk/Source/WebCore/Modules/fetch/FetchRequest.h
r287177 r287532 74 74 const String& integrity() const { return m_options.integrity; } 75 75 76 ExceptionOr<Ref<FetchRequest>> clone( ScriptExecutionContext&);76 ExceptionOr<Ref<FetchRequest>> clone(); 77 77 78 78 const FetchOptions& fetchOptions() const { return m_options; } … … 86 86 87 87 private: 88 FetchRequest(ScriptExecutionContext &, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceRequest&&, FetchOptions&&, String&& referrer);88 FetchRequest(ScriptExecutionContext*, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceRequest&&, FetchOptions&&, String&& referrer); 89 89 90 90 ExceptionOr<void> initializeOptions(const Init&); … … 104 104 }; 105 105 106 inline FetchRequest::FetchRequest(ScriptExecutionContext &context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceRequest&& request, FetchOptions&& options, String&& referrer)106 inline FetchRequest::FetchRequest(ScriptExecutionContext* context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceRequest&& request, FetchOptions&& options, String&& referrer) 107 107 : FetchBodyOwner(context, WTFMove(body), WTFMove(headers)) 108 108 , m_request(WTFMove(request)) -
trunk/Source/WebCore/Modules/fetch/FetchRequest.idl
r283463 r287532 33 33 [ 34 34 ActiveDOMObject, 35 ExportMacro=WEBCORE_EXPORT, 35 36 Exposed=(Window,Worker), 36 37 GenerateIsReachable=Impl, … … 58 59 readonly attribute AbortSignal signal; 59 60 60 [ CallWith=ScriptExecutionContext,NewObject] FetchRequest clone();61 [NewObject] FetchRequest clone(); 61 62 }; 62 63 -
trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp
r287177 r287532 49 49 } 50 50 51 Ref<FetchResponse> FetchResponse::create(ScriptExecutionContext &context, std::optional<FetchBody>&& body, FetchHeaders::Guard guard, ResourceResponse&& response)51 Ref<FetchResponse> FetchResponse::create(ScriptExecutionContext* context, std::optional<FetchBody>&& body, FetchHeaders::Guard guard, ResourceResponse&& response) 52 52 { 53 53 bool isSynthetic = response.type() == ResourceResponse::Type::Default || response.type() == ResourceResponse::Type::Error; … … 128 128 129 129 // 12. Return r. 130 auto r = adoptRef(*new FetchResponse( context, WTFMove(extractedBody), WTFMove(headers), { }));130 auto r = adoptRef(*new FetchResponse(&context, WTFMove(extractedBody), WTFMove(headers), { })); 131 131 r->suspendIfNeeded(); 132 132 … … 144 144 Ref<FetchResponse> FetchResponse::error(ScriptExecutionContext& context) 145 145 { 146 auto response = adoptRef(*new FetchResponse( context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));146 auto response = adoptRef(*new FetchResponse(&context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { })); 147 147 response->suspendIfNeeded(); 148 148 response->m_internalResponse.setType(Type::Error); … … 160 160 if (!ResourceResponse::isRedirectionStatusCode(status)) 161 161 return Exception { RangeError, makeString("Status code ", status, "is not a redirection status code") }; 162 auto redirectResponse = adoptRef(*new FetchResponse( context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));162 auto redirectResponse = adoptRef(*new FetchResponse(&context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { })); 163 163 redirectResponse->suspendIfNeeded(); 164 164 redirectResponse->m_internalResponse.setHTTPStatusCode(status); … … 168 168 } 169 169 170 FetchResponse::FetchResponse(ScriptExecutionContext &context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)170 FetchResponse::FetchResponse(ScriptExecutionContext* context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response) 171 171 : FetchBodyOwner(context, WTFMove(body), WTFMove(headers)) 172 172 , m_internalResponse(WTFMove(response)) … … 176 176 ExceptionOr<Ref<FetchResponse>> FetchResponse::clone() 177 177 { 178 if (isContextStopped())179 return Exception { InvalidStateError, "Context is stopped"_s };180 181 178 if (isDisturbedOrLocked()) 182 179 return Exception { TypeError, "Body is disturbed or locked"_s }; 183 180 184 ASSERT(scriptExecutionContext());185 auto& context = *scriptExecutionContext();186 187 181 // If loading, let's create a stream so that data is teed on both clones. 188 182 if (isLoading() && !m_readableStreamSource) { 189 auto* globalObject = context.globalObject(); 183 auto* context = scriptExecutionContext(); 184 185 auto* globalObject = context ? context->globalObject() : nullptr; 190 186 if (!globalObject) 191 187 return Exception { InvalidStateError, "Context is stopped"_s }; … … 200 196 m_internalResponse.setHTTPHeaderFields(HTTPHeaderMap { headers().internalHeaders() }); 201 197 202 auto clone = FetchResponse::create( context, std::nullopt, headers().guard(), ResourceResponse { m_internalResponse });198 auto clone = FetchResponse::create(scriptExecutionContext(), std::nullopt, headers().guard(), ResourceResponse { m_internalResponse }); 203 199 clone->cloneBody(*this); 204 200 clone->m_opaqueLoadIdentifier = m_opaqueLoadIdentifier; … … 255 251 InspectorInstrumentation::willFetch(context, request.url().string()); 256 252 257 auto response = adoptRef(*new FetchResponse( context, FetchBody { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));253 auto response = adoptRef(*new FetchResponse(&context, FetchBody { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { })); 258 254 response->suspendIfNeeded(); 259 255 -
trunk/Source/WebCore/Modules/fetch/FetchResponse.h
r287021 r287532 58 58 }; 59 59 60 WEBCORE_EXPORT static Ref<FetchResponse> create(ScriptExecutionContext &, std::optional<FetchBody>&&, FetchHeaders::Guard, ResourceResponse&&);60 WEBCORE_EXPORT static Ref<FetchResponse> create(ScriptExecutionContext*, std::optional<FetchBody>&&, FetchHeaders::Guard, ResourceResponse&&); 61 61 62 62 static ExceptionOr<Ref<FetchResponse>> create(ScriptExecutionContext&, std::optional<FetchBody::Init>&&, Init&&); … … 113 113 114 114 private: 115 FetchResponse(ScriptExecutionContext &, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);115 FetchResponse(ScriptExecutionContext*, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&); 116 116 117 117 void stop() final; -
trunk/Source/WebCore/dom/AbortController.cpp
r285428 r287532 42 42 43 43 AbortController::AbortController(ScriptExecutionContext& context) 44 : m_signal(AbortSignal::create( context))44 : m_signal(AbortSignal::create(&context)) 45 45 { 46 46 } -
trunk/Source/WebCore/dom/AbortSignal.cpp
r286904 r287532 40 40 WTF_MAKE_ISO_ALLOCATED_IMPL(AbortSignal); 41 41 42 Ref<AbortSignal> AbortSignal::create(ScriptExecutionContext &context)42 Ref<AbortSignal> AbortSignal::create(ScriptExecutionContext* context) 43 43 { 44 44 return adoptRef(*new AbortSignal(context)); … … 51 51 if (reason.isUndefined()) 52 52 reason = toJS(&globalObject, &globalObject, DOMException::create(AbortError)); 53 return adoptRef(*new AbortSignal( context, Aborted::Yes, reason));53 return adoptRef(*new AbortSignal(&context, Aborted::Yes, reason)); 54 54 } 55 55 56 AbortSignal::AbortSignal(ScriptExecutionContext &context, Aborted aborted, JSC::JSValue reason)57 : ContextDestructionObserver( &context)56 AbortSignal::AbortSignal(ScriptExecutionContext* context, Aborted aborted, JSC::JSValue reason) 57 : ContextDestructionObserver(context) 58 58 , m_aborted(aborted == Aborted::Yes) 59 59 , m_reason(reason) -
trunk/Source/WebCore/dom/AbortSignal.h
r286904 r287532 43 43 WTF_MAKE_ISO_ALLOCATED_EXPORT(AbortSignal, WEBCORE_EXPORT); 44 44 public: 45 static Ref<AbortSignal> create(ScriptExecutionContext &);45 static Ref<AbortSignal> create(ScriptExecutionContext*); 46 46 47 47 static Ref<AbortSignal> abort(JSDOMGlobalObject&, ScriptExecutionContext&, JSC::JSValue reason); … … 67 67 private: 68 68 enum class Aborted : bool { No, Yes }; 69 explicit AbortSignal(ScriptExecutionContext &, Aborted = Aborted::No, JSC::JSValue reason = JSC::jsUndefined());69 explicit AbortSignal(ScriptExecutionContext*, Aborted = Aborted::No, JSC::JSValue reason = JSC::jsUndefined()); 70 70 71 71 // EventTarget. -
trunk/Source/WebCore/testing/Internals.cpp
r287498 r287532 79 79 #include "ExtendableEvent.h" 80 80 #include "ExtensionStyleSheets.h" 81 #include "FetchRequest.h" 81 82 #include "FetchResponse.h" 82 83 #include "File.h" … … 919 920 } 920 921 922 bool Internals::isFetchObjectContextStopped(const FetchObject& object) 923 { 924 return switchOn(object, [](const RefPtr<FetchRequest>& request) { 925 return request->isContextStopped(); 926 }, [](auto& response) { 927 return response->isContextStopped(); 928 }); 929 } 930 921 931 void Internals::clearMemoryCache() 922 932 { -
trunk/Source/WebCore/testing/Internals.h
r287498 r287532 69 69 class EventListener; 70 70 class ExtendableEvent; 71 class FetchRequest; 71 72 class FetchResponse; 72 73 class File; … … 191 192 void setStrictRawResourceValidationPolicyDisabled(bool); 192 193 194 using FetchObject = std::variant<RefPtr<FetchRequest>, RefPtr<FetchResponse>>; 195 bool isFetchObjectContextStopped(const FetchObject&); 196 193 197 void clearMemoryCache(); 194 198 void pruneMemoryCacheToSize(unsigned size); -
trunk/Source/WebCore/testing/Internals.idl
r287404 r287532 306 306 }; 307 307 308 typedef (FetchRequest or FetchResponse) FetchObject; 309 308 310 [ 309 311 ExportMacro=WEBCORE_TESTSUPPORT_EXPORT, … … 337 339 undefined setOverrideResourceLoadPriority(ResourceLoadPriority priority); 338 340 undefined setStrictRawResourceValidationPolicyDisabled(boolean disabled); 341 342 boolean isFetchObjectContextStopped(FetchObject object); 339 343 340 344 undefined clearBackForwardCache(); -
trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp
r287353 r287532 130 130 response.setType(ResourceResponse::Type::Cors); 131 131 response.setTainting(ResourceResponse::Tainting::Opaque); 132 auto fetchResponse = FetchResponse::create( context, FetchBody::fromFormData(context, formData), FetchHeaders::Guard::Response, WTFMove(response));132 auto fetchResponse = FetchResponse::create(&context, FetchBody::fromFormData(context, formData), FetchHeaders::Guard::Response, WTFMove(response)); 133 133 fetchResponse->initializeOpaqueLoadIdentifierForTesting(); 134 134 return fetchResponse;
Note: See TracChangeset
for help on using the changeset viewer.