Diff
Modified: trunk/LayoutTests/ChangeLog (287352 => 287353)
--- trunk/LayoutTests/ChangeLog 2021-12-22 09:32:30 UTC (rev 287352)
+++ trunk/LayoutTests/ChangeLog 2021-12-22 10:13:07 UTC (rev 287353)
@@ -1,3 +1,16 @@
+2021-12-22 Youenn Fablet <[email protected]>
+
+ Use requester when calling updateRequestAndAddExtraFields
+ https://bugs.webkit.org/show_bug.cgi?id=234507
+ <rdar://problem/85049490>
+
+ Reviewed by Brent Fulgham.
+
+ * http/wpt/service-workers/navigation-iframe-site-worker.js: Added.
+ * http/wpt/service-workers/navigation-iframe-site.https-expected.txt: Added.
+ * http/wpt/service-workers/navigation-iframe-site.https.html: Added.
+ * http/wpt/service-workers/resources/navigation-iframe-site-frame.html: Added.
+
2021-12-22 Arcady Goldmints-Orlov <[email protected]>
[GTK] Update test expectations and baselines. Unreviewed test gardening.
Added: trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site-worker.js (0 => 287353)
--- trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site-worker.js (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site-worker.js 2021-12-22 10:13:07 UTC (rev 287353)
@@ -0,0 +1,11 @@
+addEventListener("message", (e) => {
+ self.port = e.data.port;
+});
+
+addEventListener("fetch", (e) => {
+ if (self.internals) {
+ self.port.postMessage(self.internals.fetchEventIsSameSite(e) ? "FAIL" : "PASS");
+ return;
+ }
+ self.port.postMessage("PASS");
+});
Added: trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https-expected.txt (0 => 287353)
--- trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https-expected.txt 2021-12-22 10:13:07 UTC (rev 287353)
@@ -0,0 +1,5 @@
+
+PASS Setup worker
+PASS Validate worker gets right request after navigation
+PASS Validate worker gets right request after post navigation
+
Added: trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https.html (0 => 287353)
--- trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https.html 2021-12-22 10:13:07 UTC (rev 287353)
@@ -0,0 +1,68 @@
+<html>
+<head>
+<title>Service Worker Fetch Event</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var scope = "resources/";
+var registration;
+const channel = new MessageChannel;
+
+function withFrame(url)
+{
+ return new Promise((resolve) => {
+ let frame = document.createElement('iframe');
+ frame.src = ""
+ frame._onload_ = function() { resolve(frame); };
+ document.body.appendChild(frame);
+ });
+}
+
+async function registerServiceWorker(scope)
+{
+ var registration = await navigator.serviceWorker.register("navigation-iframe-site-worker.js", { scope : scope });
+ var activeWorker = registration.active;
+ if (activeWorker) {
+ activeWorker.postMessage({ port: channel.port1 }, [channel.port1]);
+ return;
+ }
+ activeWorker = registration.installing;
+ activeWorker.postMessage({ port: channel.port1 }, [channel.port1]);
+ return new Promise(resolve => {
+ activeWorker.addEventListener('statechange', () => {
+ if (activeWorker.state === "activated")
+ resolve(registration);
+ });
+ });
+}
+
+promise_test(async (test) => {
+ registration = await registerServiceWorker(scope);
+}, "Setup worker");
+
+promise_test(async (test) => {
+ const resultPromise = new Promise(resolve => channel.port2._onmessage_ = (event) => resolve(event.data));
+
+ // Cross-origin iframe that will redirect to iframe that will be controlled by registered service worker.
+ const framePromise = withFrame("https://127.0.0.1:9443/WebKit/service-workers/resources/navigation-iframe-site-frame.html");
+
+ assert_equals(await resultPromise, "PASS");
+ const frame = await framePromise;
+ frame.remove();
+}, "Validate worker gets right request after navigation");
+
+promise_test(async (test) => {
+ const resultPromise = new Promise(resolve => channel.port2._onmessage_ = (event) => resolve(event.data));
+
+ // Cross-origin iframe that will redirect to iframe that will be controlled by registered service worker through POST.
+ const framePromise = withFrame("https://127.0.0.1:9443/WebKit/service-workers/resources/navigation-iframe-site-frame.html?post");
+
+ assert_equals(await resultPromise, "PASS");
+ const frame = await framePromise;
+ frame.remove();
+}, "Validate worker gets right request after post navigation");
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/service-workers/resources/navigation-iframe-site-frame.html (0 => 287353)
--- trunk/LayoutTests/http/wpt/service-workers/resources/navigation-iframe-site-frame.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/resources/navigation-iframe-site-frame.html 2021-12-22 10:13:07 UTC (rev 287353)
@@ -0,0 +1,13 @@
+<form method="post" id="myForm" action=""
+<script>
+function doTest()
+{
+ if (window.location.search !== "?post") {
+ window.location = "https://localhost:9443/WebKit/service-workers/resources/";
+ return;
+ }
+ myForm.submit();
+}
+
+doTest();
+</script>
Modified: trunk/Source/WebCore/ChangeLog (287352 => 287353)
--- trunk/Source/WebCore/ChangeLog 2021-12-22 09:32:30 UTC (rev 287352)
+++ trunk/Source/WebCore/ChangeLog 2021-12-22 10:13:07 UTC (rev 287353)
@@ -1,3 +1,24 @@
+2021-12-22 Youenn Fablet <[email protected]>
+
+ Use requester when calling updateRequestAndAddExtraFields
+ https://bugs.webkit.org/show_bug.cgi?id=234507
+ <rdar://problem/85049490>
+
+ Reviewed by Brent Fulgham.
+
+ In case of navigation loads, the requester is the fetch request client.
+ As such, it should be the one used to determine whether the request is cross-origin is not.
+ Pass the requester to updateRequestAndAddExtraFields to do the correct computation.
+ Validate that some request fields are now correctly observed in service workers.
+
+ Test: http/wpt/service-workers/navigation-iframe-site.https.html
+
+ * loader/FrameLoader.cpp:
+ * loader/FrameLoader.h:
+ * testing/ServiceWorkerInternals.cpp:
+ * testing/ServiceWorkerInternals.h:
+ * testing/ServiceWorkerInternals.idl:
+
2021-12-22 Philippe Normand <[email protected]>
REGRESSION(r287021): [EME][Thunder] Build broken
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (287352 => 287353)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2021-12-22 09:32:30 UTC (rev 287352)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2021-12-22 10:13:07 UTC (rev 287353)
@@ -1342,7 +1342,7 @@
if (!referrer.isEmpty())
request.setHTTPReferrer(referrer);
- updateRequestAndAddExtraFields(request, IsMainResource::Yes, newLoadType);
+ updateRequestAndAddExtraFields(request, IsMainResource::Yes, newLoadType, ShouldUpdateAppInitiatedValue::Yes, FrameLoader::IsServiceWorkerNavigationLoad::No, &frameLoadRequest.requester());
ASSERT(newLoadType != FrameLoadType::Same);
@@ -2903,7 +2903,7 @@
return ResourceRequestCachePolicy::UseProtocolCachePolicy;
}
-void FrameLoader::updateRequestAndAddExtraFields(ResourceRequest& request, IsMainResource mainResource, FrameLoadType loadType, ShouldUpdateAppInitiatedValue shouldUpdate, IsServiceWorkerNavigationLoad isServiceWorkerNavigationLoad)
+void FrameLoader::updateRequestAndAddExtraFields(ResourceRequest& request, IsMainResource mainResource, FrameLoadType loadType, ShouldUpdateAppInitiatedValue shouldUpdate, IsServiceWorkerNavigationLoad isServiceWorkerNavigationLoad, Document* initiator)
{
ASSERT(isServiceWorkerNavigationLoad == IsServiceWorkerNavigationLoad::No || mainResource != IsMainResource::Yes);
@@ -2923,14 +2923,16 @@
}
if (request.isSameSiteUnspecified()) {
- auto* initiator = m_frame.document();
- if (isMainResource) {
- auto* ownerFrame = m_frame.tree().parent();
- if (!ownerFrame && m_stateMachine.isDisplayingInitialEmptyDocument())
- ownerFrame = m_opener.get();
- if (ownerFrame)
- initiator = ownerFrame->document();
- ASSERT(ownerFrame || m_frame.isMainFrame());
+ if (!initiator) {
+ initiator = m_frame.document();
+ if (isMainResource) {
+ auto* ownerFrame = m_frame.tree().parent();
+ if (!ownerFrame && m_stateMachine.isDisplayingInitialEmptyDocument())
+ ownerFrame = m_opener.get();
+ if (ownerFrame)
+ initiator = ownerFrame->document();
+ ASSERT(ownerFrame || m_frame.isMainFrame());
+ }
}
addSameSiteInfoToRequestIfNeeded(request, initiator);
}
@@ -3067,7 +3069,7 @@
workingResourceRequest.setHTTPMethod("POST");
workingResourceRequest.setHTTPBody(inRequest.httpBody());
workingResourceRequest.setHTTPContentType(contentType);
- updateRequestAndAddExtraFields(workingResourceRequest, IsMainResource::Yes, loadType);
+ updateRequestAndAddExtraFields(workingResourceRequest, IsMainResource::Yes, loadType, ShouldUpdateAppInitiatedValue::Yes, FrameLoader::IsServiceWorkerNavigationLoad::No, &request.requester());
if (Document* document = m_frame.document())
document->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(workingResourceRequest, ContentSecurityPolicy::InsecureRequestType::Load);
Modified: trunk/Source/WebCore/loader/FrameLoader.h (287352 => 287353)
--- trunk/Source/WebCore/loader/FrameLoader.h 2021-12-22 09:32:30 UTC (rev 287352)
+++ trunk/Source/WebCore/loader/FrameLoader.h 2021-12-22 10:13:07 UTC (rev 287353)
@@ -319,7 +319,7 @@
enum class IsServiceWorkerNavigationLoad : bool { No, Yes };
// For subresource requests the FrameLoadType parameter has no effect and can be skipped.
- void updateRequestAndAddExtraFields(ResourceRequest&, IsMainResource, FrameLoadType = FrameLoadType::Standard, ShouldUpdateAppInitiatedValue = ShouldUpdateAppInitiatedValue::Yes, IsServiceWorkerNavigationLoad = IsServiceWorkerNavigationLoad::No);
+ void updateRequestAndAddExtraFields(ResourceRequest&, IsMainResource, FrameLoadType = FrameLoadType::Standard, ShouldUpdateAppInitiatedValue = ShouldUpdateAppInitiatedValue::Yes, IsServiceWorkerNavigationLoad = IsServiceWorkerNavigationLoad::No, Document* = nullptr);
void scheduleRefreshIfNeeded(Document&, const String& content, IsMetaRefresh);
Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp (287352 => 287353)
--- trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp 2021-12-22 09:32:30 UTC (rev 287352)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp 2021-12-22 10:13:07 UTC (rev 287353)
@@ -188,6 +188,11 @@
return PushSubscription::create(PushSubscriptionData { WTFMove(myEndpoint), expirationTime, WTFMove(myServerVAPIDPublicKey), WTFMove(myClientECDHPublicKey), WTFMove(myAuth) });
}
+bool ServiceWorkerInternals::fetchEventIsSameSite(FetchEvent& event)
+{
+ return event.request().internalRequest().isSameSite();
+}
+
} // namespace WebCore
#endif
Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.h (287352 => 287353)
--- trunk/Source/WebCore/testing/ServiceWorkerInternals.h 2021-12-22 09:32:30 UTC (rev 287352)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.h 2021-12-22 10:13:07 UTC (rev 287353)
@@ -69,6 +69,8 @@
RefPtr<PushSubscription> createPushSubscription(const String& endpoint, std::optional<EpochTimeStamp> expirationTime, const ArrayBuffer& serverVAPIDPublicKey, const ArrayBuffer& clientECDHPublicKey, const ArrayBuffer& auth);
+ bool fetchEventIsSameSite(FetchEvent&);
+
private:
explicit ServiceWorkerInternals(ServiceWorkerIdentifier);
Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.idl (287352 => 287353)
--- trunk/Source/WebCore/testing/ServiceWorkerInternals.idl 2021-12-22 09:32:30 UTC (rev 287352)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.idl 2021-12-22 10:13:07 UTC (rev 287353)
@@ -49,4 +49,6 @@
Promise<boolean> lastNavigationWasAppInitiated();
PushSubscription createPushSubscription(USVString endpoint, EpochTimeStamp? expirationTime, ArrayBuffer serverVAPIDPublicKey, ArrayBuffer clientECDHPublicKey, ArrayBuffer auth);
+
+ boolean fetchEventIsSameSite(FetchEvent event);
};