Diff
Modified: trunk/Source/WebKit/ChangeLog (292467 => 292468)
--- trunk/Source/WebKit/ChangeLog 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/ChangeLog 2022-04-06 15:20:50 UTC (rev 292468)
@@ -1,3 +1,23 @@
+2022-04-06 Youenn Fablet <you...@apple.com>
+
+ In case of COOP-based process swap, we need to make sure the document gets controlled by its matching service worker registration
+ https://bugs.webkit.org/show_bug.cgi?id=238800
+ <rdar://problem/91288849>
+
+ Reviewed by Chris Dumez.
+
+ Make sure in case loader is transferred to call controlClient in the new WebProcess.
+ To do so, we also update page and frame IDs.
+ Covered by API test.
+
+ * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+ * NetworkProcess/NetworkLoadParameters.h:
+ * NetworkProcess/NetworkResourceLoadParameters.h:
+ * NetworkProcess/NetworkResourceLoader.cpp:
+ * NetworkProcess/NetworkResourceLoader.h:
+ * NetworkProcess/ServiceWorker/WebSWServerConnection.cpp:
+ * NetworkProcess/ServiceWorker/WebSWServerConnection.h:
+
2022-04-06 Kimmo Kinnunen <kkinnu...@apple.com>
Media and WebRTC code uses ThreadMessageReceiverRefCounted with WorkQueues
Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp (292467 => 292468)
--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp 2022-04-06 15:20:50 UTC (rev 292468)
@@ -589,7 +589,7 @@
if (auto existingLoader = session->takeLoaderAwaitingWebProcessTransfer(*existingLoaderToResume)) {
CONNECTION_RELEASE_LOG(Loading, "scheduleResourceLoad: Resuming existing NetworkResourceLoader");
m_networkResourceLoaders.add(identifier, *existingLoader);
- existingLoader->transferToNewWebProcess(*this, identifier);
+ existingLoader->transferToNewWebProcess(*this, loadParameters);
return;
}
CONNECTION_RELEASE_LOG_ERROR(Loading, "scheduleResourceLoad: Could not find existing NetworkResourceLoader to resume, will do a fresh load");
Modified: trunk/Source/WebKit/NetworkProcess/NetworkLoadParameters.h (292467 => 292468)
--- trunk/Source/WebKit/NetworkProcess/NetworkLoadParameters.h 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/NetworkProcess/NetworkLoadParameters.h 2022-04-06 15:20:50 UTC (rev 292468)
@@ -44,9 +44,9 @@
class NetworkLoadParameters {
public:
- WebPageProxyIdentifier webPageProxyID;
- WebCore::PageIdentifier webPageID;
- WebCore::FrameIdentifier webFrameID;
+ mutable WebPageProxyIdentifier webPageProxyID;
+ mutable WebCore::PageIdentifier webPageID;
+ mutable WebCore::FrameIdentifier webFrameID;
RefPtr<WebCore::SecurityOrigin> topOrigin;
RefPtr<WebCore::SecurityOrigin> sourceOrigin;
WTF::ProcessID parentPID { 0 };
Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h (292467 => 292468)
--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h 2022-04-06 15:20:50 UTC (rev 292468)
@@ -56,7 +56,7 @@
Vector<RefPtr<SandboxExtension>> requestBodySandboxExtensions; // Created automatically for the sender.
RefPtr<SandboxExtension> resourceSandboxExtension; // Created automatically for the sender.
mutable Seconds maximumBufferingTime;
- WebCore::FetchOptions options;
+ mutable WebCore::FetchOptions options;
std::optional<WebCore::ContentSecurityPolicyResponseHeaders> cspResponseHeaders;
WebCore::CrossOriginEmbedderPolicy parentCrossOriginEmbedderPolicy;
WebCore::CrossOriginEmbedderPolicy crossOriginEmbedderPolicy;
Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (292467 => 292468)
--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp 2022-04-06 15:20:50 UTC (rev 292468)
@@ -576,13 +576,21 @@
return networkLoadMetrics;
}
-void NetworkResourceLoader::transferToNewWebProcess(NetworkConnectionToWebProcess& newConnection, WebCore::ResourceLoaderIdentifier newCoreIdentifier)
+void NetworkResourceLoader::transferToNewWebProcess(NetworkConnectionToWebProcess& newConnection, const NetworkResourceLoadParameters& parameters)
{
m_connection = newConnection;
- m_parameters.identifier = newCoreIdentifier;
+ m_parameters.identifier = parameters.identifier;
+ m_parameters.webPageProxyID = parameters.webPageProxyID;
+ m_parameters.webPageID = parameters.webPageID;
+ m_parameters.webFrameID = parameters.webFrameID;
+ m_parameters.options.clientIdentifier = parameters.options.clientIdentifier;
#if ENABLE(SERVICE_WORKER)
ASSERT(m_responseCompletionHandler || m_cacheEntryWaitingForContinueDidReceiveResponse || m_serviceWorkerFetchTask);
+ if (m_serviceWorkerRegistration) {
+ if (auto* swConnection = newConnection.swConnection())
+ swConnection->transferServiceWorkerLoadToNewWebProcess(*this, *m_serviceWorkerRegistration);
+ }
#else
ASSERT(m_responseCompletionHandler || m_cacheEntryWaitingForContinueDidReceiveResponse);
#endif
@@ -1208,6 +1216,7 @@
#if ENABLE(SERVICE_WORKER)
if (parameters().options.mode == FetchOptions::Mode::Navigate) {
+ m_serviceWorkerRegistration = { };
if (auto serviceWorkerFetchTask = m_connection->createFetchTask(*this, newRequest)) {
LOADER_RELEASE_LOG("continueWillSendRequest: Created a ServiceWorkerFetchTask to handle the redirect (fetchIdentifier=%" PRIu64 ")", serviceWorkerFetchTask->fetchIdentifier().toUInt64());
m_networkLoad = nullptr;
Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h (292467 => 292468)
--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h 2022-04-06 15:20:50 UTC (rev 292468)
@@ -40,6 +40,7 @@
#include <WebCore/CrossOriginAccessControl.h>
#include <WebCore/PrivateClickMeasurement.h>
#include <WebCore/ResourceResponse.h>
+#include <WebCore/SWServerRegistration.h>
#include <WebCore/SecurityPolicyViolationEvent.h>
#include <WebCore/SharedBuffer.h>
#include <WebCore/Timer.h>
@@ -93,7 +94,7 @@
void start();
void abort();
- void transferToNewWebProcess(NetworkConnectionToWebProcess&, WebCore::ResourceLoaderIdentifier);
+ void transferToNewWebProcess(NetworkConnectionToWebProcess&, const NetworkResourceLoadParameters&);
// Message handlers.
void didReceiveNetworkResourceLoaderMessage(IPC::Connection&, IPC::Decoder&);
@@ -154,6 +155,7 @@
void serviceWorkerDidNotHandle(ServiceWorkerFetchTask*);
void setResultingClientIdentifier(String&& identifier) { m_resultingClientIdentifier = WTFMove(identifier); }
const String& resultingClientIdentifier() const { return m_resultingClientIdentifier; }
+ void setServiceWorkerRegistration(WebCore::SWServerRegistration& serviceWorkerRegistration) { m_serviceWorkerRegistration = serviceWorkerRegistration; }
#endif
std::optional<WebCore::ResourceError> doCrossOriginOpenerHandlingOfResponse(const WebCore::ResourceResponse&);
@@ -288,6 +290,7 @@
#if ENABLE(SERVICE_WORKER)
std::unique_ptr<ServiceWorkerFetchTask> m_serviceWorkerFetchTask;
String m_resultingClientIdentifier;
+ WeakPtr<WebCore::SWServerRegistration> m_serviceWorkerRegistration;
#endif
NetworkResourceLoadIdentifier m_resourceLoadID;
WebCore::ResourceResponse m_redirectResponse;
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (292467 => 292468)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp 2022-04-06 15:20:50 UTC (rev 292468)
@@ -204,6 +204,7 @@
serviceWorkerRegistrationIdentifier = registration->identifier();
controlClient(loader.parameters(), *registration, request);
loader.setResultingClientIdentifier(loader.parameters().options.clientIdentifier->toString());
+ loader.setServiceWorkerRegistration(*registration);
} else {
if (!loader.parameters().serviceWorkerRegistrationIdentifier)
return nullptr;
@@ -666,6 +667,11 @@
sendWithAsyncReply(Messages::WebSWClientConnection::FocusServiceWorkerClient { clientIdentifier }, WTFMove(callback));
}
+void WebSWServerConnection::transferServiceWorkerLoadToNewWebProcess(NetworkResourceLoader& loader, WebCore::SWServerRegistration& registration)
+{
+ controlClient(loader.parameters(), registration, loader.originalRequest());
+}
+
} // namespace WebKit
#undef CONNECTION_MESSAGE_CHECK_COMPLETION
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (292467 => 292468)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h 2022-04-06 15:20:50 UTC (rev 292468)
@@ -84,6 +84,8 @@
std::unique_ptr<ServiceWorkerFetchTask> createFetchTask(NetworkResourceLoader&, const WebCore::ResourceRequest&);
void fetchTaskTimedOut(WebCore::ServiceWorkerIdentifier);
+ void transferServiceWorkerLoadToNewWebProcess(NetworkResourceLoader&, WebCore::SWServerRegistration&);
+
private:
// Implement SWServer::Connection (Messages to the client WebProcess)
void rejectJobInClient(WebCore::ServiceWorkerJobIdentifier, const WebCore::ExceptionData&) final;
Modified: trunk/Tools/ChangeLog (292467 => 292468)
--- trunk/Tools/ChangeLog 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Tools/ChangeLog 2022-04-06 15:20:50 UTC (rev 292468)
@@ -1,3 +1,13 @@
+2022-04-06 Youenn Fablet <you...@apple.com>
+
+ In case of COOP-based process swap, we need to make sure the document gets controlled by its matching service worker registration
+ https://bugs.webkit.org/show_bug.cgi?id=238800
+ <rdar://problem/91288849>
+
+ Reviewed by Chris Dumez.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+
2022-04-06 Carlos Garcia Campos <cgar...@igalia.com>
REGRESSION(r292308): links to results is wrong for some tests
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (292467 => 292468)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm 2022-04-06 15:11:33 UTC (rev 292467)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm 2022-04-06 15:20:50 UTC (rev 292468)
@@ -3077,6 +3077,13 @@
" alert(event.data);"
" };"
"}"
+""
+"function countServiceWorkerClients() {"
+" worker.postMessage('countServiceWorkerClients');"
+" navigator.serviceWorker._onmessage_ = (event) => {"
+" alert(event.data);"
+" };"
+"}"
"</script>"_s;
static constexpr auto ServiceWorkerWindowClientNavigateJS =
@@ -3099,6 +3106,11 @@
" });"
" return;"
" }"
+" if (event.data ="" 'countServiceWorkerClients') {"
+" let currentClients = await self.clients.matchAll();"
+" event.source.postMessage(currentClients.length + ' client(s)');"
+" return;"
+" }"
"});"_s;
@@ -3179,6 +3191,9 @@
[webView1 evaluateJavaScript:[NSString stringWithFormat:@"navigateOtherClientToURL('%@?swap')", baseURL] completionHandler: nil];
EXPECT_WK_STREQ([webView1 _test_waitForAlert], "client");
+
+ [webView1 evaluateJavaScript:@"countServiceWorkerClients()" completionHandler: nil];
+ EXPECT_WK_STREQ([webView1 _test_waitForAlert], "1 client(s)");
}
TEST(ServiceWorker, WindowClientNavigateCrossOrigin)