Title: [293941] trunk/Source
Revision
293941
Author
[email protected]
Date
2022-05-06 18:41:06 -0700 (Fri, 06 May 2022)

Log Message

Unreviewed, reverting r293824.
https://bugs.webkit.org/show_bug.cgi?id=240197

Speedometer2/Angular2-TypeScript-TodoMVC 8% regression

Reverted changeset:

"SWOriginStore is no longer needed"
https://bugs.webkit.org/show_bug.cgi?id=240003
https://commits.webkit.org/r293824

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293940 => 293941)


--- trunk/Source/WebCore/ChangeLog	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/ChangeLog	2022-05-07 01:41:06 UTC (rev 293941)
@@ -1,3 +1,16 @@
+2022-05-06  Commit Queue  <[email protected]>
+
+        Unreviewed, reverting r293824.
+        https://bugs.webkit.org/show_bug.cgi?id=240197
+
+        Speedometer2/Angular2-TypeScript-TodoMVC 8% regression
+
+        Reverted changeset:
+
+        "SWOriginStore is no longer needed"
+        https://bugs.webkit.org/show_bug.cgi?id=240003
+        https://commits.webkit.org/r293824
+
 2022-05-06  Patrick Griffis  <[email protected]>
 
         CSP: Fix script-src-elem policies in workers

Modified: trunk/Source/WebCore/Headers.cmake (293940 => 293941)


--- trunk/Source/WebCore/Headers.cmake	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/Headers.cmake	2022-05-07 01:41:06 UTC (rev 293941)
@@ -2044,6 +2044,7 @@
     workers/service/context/ServiceWorkerThreadProxy.h
 
     workers/service/server/RegistrationDatabase.h
+    workers/service/server/SWOriginStore.h
     workers/service/server/SWServer.h
     workers/service/server/SWServerRegistration.h
     workers/service/server/SWServerToContextConnection.h

Modified: trunk/Source/WebCore/Sources.txt (293940 => 293941)


--- trunk/Source/WebCore/Sources.txt	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/Sources.txt	2022-05-07 01:41:06 UTC (rev 293941)
@@ -2801,6 +2801,7 @@
 workers/service/context/ServiceWorkerThreadProxy.cpp
 workers/service/server/RegistrationDatabase.cpp
 workers/service/server/RegistrationStore.cpp
+workers/service/server/SWOriginStore.cpp
 workers/service/server/SWScriptStorage.cpp
 workers/service/server/SWServer.cpp
 workers/service/server/SWServerJobQueue.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (293940 => 293941)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-05-07 01:41:06 UTC (rev 293941)
@@ -1115,6 +1115,7 @@
 		415080371E3F00B00051D75D /* LibWebRTCAudioModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */; };
 		4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */; };
 		41519CB81FD1F02E007F623C /* ServiceWorkerClientQueryOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 413FC4CD1FD1DD8C00541C4B /* ServiceWorkerClientQueryOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		4151E5BB1FBA4C7A00E47E2D /* SWOriginStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 4151E5B71FBA4C7500E47E2D /* SWOriginStore.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		415747471E3869A400E914D8 /* LibWebRTCMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 415747431E38699E00E914D8 /* LibWebRTCMacros.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		415747481E3869A700E914D8 /* LibWebRTCProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 415747441E38699E00E914D8 /* LibWebRTCProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4157EBFA1E3AB67900AC9FE9 /* MockLibWebRTCPeerConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4157EBF91E3AB06800AC9FE9 /* MockLibWebRTCPeerConnection.cpp */; };
@@ -8708,6 +8709,8 @@
 		415080351E3F00AA0051D75D /* LibWebRTCAudioModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCAudioModule.h; path = libwebrtc/LibWebRTCAudioModule.h; sourceTree = "<group>"; };
 		4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SliderThumbElement.h; sourceTree = "<group>"; };
 		4150F9F012B6E0E70008C860 /* SliderThumbElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SliderThumbElement.cpp; sourceTree = "<group>"; };
+		4151E5B71FBA4C7500E47E2D /* SWOriginStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWOriginStore.h; sourceTree = "<group>"; };
+		4151E5B91FBA4C7600E47E2D /* SWOriginStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWOriginStore.cpp; sourceTree = "<group>"; };
 		415747431E38699E00E914D8 /* LibWebRTCMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCMacros.h; path = libwebrtc/LibWebRTCMacros.h; sourceTree = "<group>"; };
 		415747441E38699E00E914D8 /* LibWebRTCProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCProvider.h; path = libwebrtc/LibWebRTCProvider.h; sourceTree = "<group>"; };
 		4157EBF81E3AB06800AC9FE9 /* MockLibWebRTCPeerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockLibWebRTCPeerConnection.h; sourceTree = "<group>"; };
@@ -22425,6 +22428,8 @@
 				51B9140C1FD2782500EE2859 /* RegistrationDatabase.h */,
 				51B9140E1FD2782500EE2859 /* RegistrationStore.cpp */,
 				51B9140B1FD2782500EE2859 /* RegistrationStore.h */,
+				4151E5B91FBA4C7600E47E2D /* SWOriginStore.cpp */,
+				4151E5B71FBA4C7500E47E2D /* SWOriginStore.h */,
 				46273CAE260E59DF006FAA91 /* SWScriptStorage.cpp */,
 				46273CAC260E59DF006FAA91 /* SWScriptStorage.h */,
 				517A52EF1F47535900DCDC0A /* SWServer.cpp */,
@@ -37916,6 +37921,7 @@
 				46ECB6381FD0A3C80088E5AD /* SWClientConnection.h in Headers */,
 				46658DC91FA24B8700F7DD54 /* SWContextManager.h in Headers */,
 				C11A9ECE21403A5C00CFB20A /* SwitchingGPUClient.h in Headers */,
+				4151E5BB1FBA4C7A00E47E2D /* SWOriginStore.h in Headers */,
 				46273CAF260E59EF006FAA91 /* SWScriptStorage.h in Headers */,
 				517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
 				8311C0031FAA2E9500E3C8E5 /* SWServerJobQueue.h in Headers */,

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (293940 => 293941)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -578,6 +578,10 @@
     }
 
     auto origin = (!m_frame->isMainFrame() && m_frame->document()) ? m_frame->document()->topOrigin().data() : SecurityOriginData::fromURL(url);
+    if (!ServiceWorkerProvider::singleton().serviceWorkerConnection().mayHaveServiceWorkerRegisteredForOrigin(origin)) {
+        callback(std::nullopt);
+        return;
+    }
 
     auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnection();
     connection.matchRegistration(WTFMove(origin), url, WTFMove(callback));

Modified: trunk/Source/WebCore/workers/service/SWClientConnection.h (293940 => 293941)


--- trunk/Source/WebCore/workers/service/SWClientConnection.h	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/workers/service/SWClientConnection.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -83,6 +83,7 @@
     virtual void postMessageToServiceWorker(ServiceWorkerIdentifier destination, MessageWithMessagePorts&&, const ServiceWorkerOrClientIdentifier& source) = 0;
 
     virtual SWServerConnectionIdentifier serverConnectionIdentifier() const = 0;
+    virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const = 0;
 
     virtual void registerServiceWorkerClient(const ClientOrigin&, ServiceWorkerClientData&&, const std::optional<ServiceWorkerRegistrationIdentifier>&, String&& userAgent) = 0;
     virtual void unregisterServiceWorkerClient(ScriptExecutionContextIdentifier) = 0;

Modified: trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp (293940 => 293941)


--- trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/workers/service/WorkerSWClientConnection.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -178,6 +178,12 @@
     return identifier;
 }
 
+bool WorkerSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const
+{
+    ASSERT_NOT_REACHED();
+    return true;
+}
+
 void WorkerSWClientConnection::registerServiceWorkerClient(const ClientOrigin& clientOrigin, ServiceWorkerClientData&& data, const std::optional<ServiceWorkerRegistrationIdentifier>& identifier, String&& userAgent)
 {
     callOnMainThread([clientOrigin = clientOrigin.isolatedCopy(), data = "" identifier, userAgent = crossThreadCopy(WTFMove(userAgent))]() mutable {

Modified: trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h (293940 => 293941)


--- trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/workers/service/WorkerSWClientConnection.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -53,6 +53,7 @@
     void didResolveRegistrationPromise(const ServiceWorkerRegistrationKey&) final;
     void postMessageToServiceWorker(ServiceWorkerIdentifier destination, MessageWithMessagePorts&&, const ServiceWorkerOrClientIdentifier& source) final;
     SWServerConnectionIdentifier serverConnectionIdentifier() const final;
+    bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData&) const final;
     void finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier&, ServiceWorkerRegistrationKey&&, WorkerFetchResult&&) final;
     void scheduleJobInServer(const ServiceWorkerJobData&) final;
     void scheduleJob(ServiceWorkerOrClientIdentifier, const ServiceWorkerJobData&) final;

Added: trunk/Source/WebCore/workers/service/server/SWOriginStore.cpp (0 => 293941)


--- trunk/Source/WebCore/workers/service/server/SWOriginStore.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/server/SWOriginStore.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SWOriginStore.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "SecurityOrigin.h"
+
+namespace WebCore {
+
+void SWOriginStore::add(const SecurityOriginData& origin)
+{
+    ++m_originCounts.ensure(origin, [&] {
+        addToStore(origin);
+        return 0;
+    }).iterator->value;
+}
+
+void SWOriginStore::remove(const SecurityOriginData& origin)
+{
+    auto iterator = m_originCounts.find(origin);
+    ASSERT(iterator != m_originCounts.end());
+    if (iterator == m_originCounts.end())
+        return;
+
+    if (--iterator->value)
+        return;
+
+    m_originCounts.remove(iterator);
+    removeFromStore(origin);
+}
+
+void SWOriginStore::clear(const SecurityOriginData& origin)
+{
+    m_originCounts.remove(origin);
+    removeFromStore(origin);
+}
+
+void SWOriginStore::clearAll()
+{
+    m_originCounts.clear();
+    clearStore();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Added: trunk/Source/WebCore/workers/service/server/SWOriginStore.h (0 => 293941)


--- trunk/Source/WebCore/workers/service/server/SWOriginStore.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/server/SWOriginStore.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "SecurityOriginData.h"
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+
+class SWOriginStore {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    virtual ~SWOriginStore() = default;
+
+    void add(const SecurityOriginData&);
+    void remove(const SecurityOriginData&);
+    void clear(const SecurityOriginData&);
+    void clearAll();
+
+    virtual void importComplete() = 0;
+
+private:
+    virtual void addToStore(const SecurityOriginData&) = 0;
+    virtual void removeFromStore(const SecurityOriginData&) = 0;
+    virtual void clearStore() = 0;
+
+    HashMap<SecurityOriginData, uint64_t> m_originCounts;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (293940 => 293941)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -33,6 +33,7 @@
 #include "Logging.h"
 #include "NotificationData.h"
 #include "RegistrationStore.h"
+#include "SWOriginStore.h"
 #include "SWServerJobQueue.h"
 #include "SWServerRegistration.h"
 #include "SWServerToContextConnection.h"
@@ -148,6 +149,7 @@
 {
     ASSERT(!m_importCompleted);
     m_importCompleted = true;
+    m_originStore->importComplete();
 
     auto clearCallbacks = WTFMove(m_clearCompletionCallbacks);
     for (auto& callback : clearCallbacks)
@@ -222,6 +224,7 @@
     if (registration->serviceWorkerPageIdentifier())
         m_serviceWorkerPageIdentifierToRegistrationMap.add(*registration->serviceWorkerPageIdentifier(), *registration);
 
+    m_originStore->add(registration->key().topOrigin());
     auto registrationID = registration->identifier();
     ASSERT(!m_scopeToRegistrationMap.contains(registration->key()));
     m_scopeToRegistrationMap.set(registration->key(), *registration);
@@ -244,6 +247,7 @@
             m_uniqueRegistrationCount--;
     }
 
+    m_originStore->remove(registration->key().topOrigin());
     if (m_registrationStore)
         m_registrationStore->removeRegistration(registration->key());
 }
@@ -282,6 +286,7 @@
     while (!m_registrations.isEmpty())
         m_registrations.begin()->value->clear();
     m_pendingContextDatas.clear();
+    m_originStore->clearAll();
     if (!m_registrationStore)
         return completionHandler();
 
@@ -334,7 +339,7 @@
         return;
     }
 
-    // Calling SWServerRegistration::clear() takes care of updating m_registrations and m_registrationStore.
+    // Calling SWServerRegistration::clear() takes care of updating m_registrations, m_originStore and m_registrationStore.
     for (auto* registration : registrationsToRemove)
         registration->clear();
 
@@ -364,8 +369,9 @@
     m_server.removeClientServiceWorkerRegistration(*this, identifier);
 }
 
-SWServer::SWServer(bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID sessionID, bool shouldRunServiceWorkersOnMainThreadForTesting, bool hasServiceWorkerEntitlement, std::optional<unsigned> overrideServiceWorkerRegistrationCountTestingValue, SoftUpdateCallback&& softUpdateCallback, CreateContextConnectionCallback&& callback, AppBoundDomainsCallback&& appBoundDomainsCallback)
-    : m_sessionID(sessionID)
+SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID sessionID, bool shouldRunServiceWorkersOnMainThreadForTesting, bool hasServiceWorkerEntitlement, std::optional<unsigned> overrideServiceWorkerRegistrationCountTestingValue, SoftUpdateCallback&& softUpdateCallback, CreateContextConnectionCallback&& callback, AppBoundDomainsCallback&& appBoundDomainsCallback)
+    : m_originStore(WTFMove(originStore))
+    , m_sessionID(sessionID)
     , m_isProcessTerminationDelayEnabled(processTerminationDelayEnabled)
     , m_createContextConnectionCallback(WTFMove(callback))
     , m_softUpdateCallback(WTFMove(softUpdateCallback))

Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (293940 => 293941)


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -55,6 +55,7 @@
 namespace WebCore {
 
 class RegistrationStore;
+class SWOriginStore;
 class SWServerJobQueue;
 class SWServerRegistration;
 class SWServerToContextConnection;
@@ -133,7 +134,7 @@
     using SoftUpdateCallback = Function<void(ServiceWorkerJobData&& jobData, bool shouldRefreshCache, ResourceRequest&&, CompletionHandler<void(WorkerFetchResult&&)>&&)>;
     using CreateContextConnectionCallback = Function<void(const WebCore::RegistrableDomain&, std::optional<ProcessIdentifier> requestingProcessIdentifier, std::optional<ScriptExecutionContextIdentifier>, CompletionHandler<void()>&&)>;
     using AppBoundDomainsCallback = Function<void(CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&&)>;
-    WEBCORE_EXPORT SWServer(bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID, bool shouldRunServiceWorkersOnMainThreadForTesting, bool hasServiceWorkerEntitlement, std::optional<unsigned> overrideServiceWorkerRegistrationCountTestingValue, SoftUpdateCallback&&, CreateContextConnectionCallback&&, AppBoundDomainsCallback&&);
+    WEBCORE_EXPORT SWServer(UniqueRef<SWOriginStore>&&, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID, bool shouldRunServiceWorkersOnMainThreadForTesting, bool hasServiceWorkerEntitlement, std::optional<unsigned> overrideServiceWorkerRegistrationCountTestingValue, SoftUpdateCallback&&, CreateContextConnectionCallback&&, AppBoundDomainsCallback&&);
 
     WEBCORE_EXPORT ~SWServer();
 
@@ -177,6 +178,8 @@
     const HashMap<SWServerConnectionIdentifier, std::unique_ptr<Connection>>& connections() const { return m_connections; }
     WEBCORE_EXPORT bool canHandleScheme(StringView) const;
 
+    SWOriginStore& originStore() { return m_originStore; }
+
     void refreshImportedScriptsFinished(const ServiceWorkerJobDataIdentifier&, const ServiceWorkerRegistrationKey&, const Vector<std::pair<URL, ScriptBuffer>>&);
     void scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&, const String& message);
     void scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>&, SWServerWorker&);
@@ -218,7 +221,6 @@
 
     bool isImportCompleted() const { return m_importCompleted; }
     WEBCORE_EXPORT void whenImportIsCompleted(CompletionHandler<void()>&&);
-    WEBCORE_EXPORT void whenImportIsCompletedIfNeeded(CompletionHandler<void()>&&);
 
     void softUpdate(SWServerRegistration&);
 
@@ -282,6 +284,7 @@
     void contextConnectionCreated(SWServerToContextConnection&);
 
     void updateAppInitiatedValueForWorkers(const ClientOrigin&, LastNavigationWasAppInitiated);
+    void whenImportIsCompletedIfNeeded(CompletionHandler<void()>&&);
 
     ResourceRequest createScriptRequest(const URL&, const ServiceWorkerJobData&, SWServerRegistration&);
 
@@ -304,6 +307,7 @@
     HashMap<ScriptExecutionContextIdentifier, ServiceWorkerRegistrationIdentifier> m_clientToControllingRegistration;
     MemoryCompactRobinHoodHashMap<String, ScriptExecutionContextIdentifier> m_visibleClientIdToInternalClientIdMap;
 
+    UniqueRef<SWOriginStore> m_originStore;
     std::unique_ptr<RegistrationStore> m_registrationStore;
     HashMap<RegistrableDomain, Vector<ServiceWorkerContextData>> m_pendingContextDatas;
     HashMap<RegistrableDomain, HashMap<ServiceWorkerIdentifier, Vector<RunServiceWorkerCallback>>> m_serviceWorkerRunRequests;

Modified: trunk/Source/WebKit/ChangeLog (293940 => 293941)


--- trunk/Source/WebKit/ChangeLog	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/ChangeLog	2022-05-07 01:41:06 UTC (rev 293941)
@@ -1,3 +1,16 @@
+2022-05-06  Commit Queue  <[email protected]>
+
+        Unreviewed, reverting r293824.
+        https://bugs.webkit.org/show_bug.cgi?id=240197
+
+        Speedometer2/Angular2-TypeScript-TodoMVC 8% regression
+
+        Reverted changeset:
+
+        "SWOriginStore is no longer needed"
+        https://bugs.webkit.org/show_bug.cgi?id=240003
+        https://commits.webkit.org/r293824
+
 2022-05-06  Wenson Hsieh  <[email protected]>
 
         Don't show "Markup Image" item for images that have already been marked up

Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp (293940 => 293941)


--- trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -46,6 +46,7 @@
 #include "WebPageProxy.h"
 #include "WebPageProxyMessages.h"
 #include "WebProcessProxy.h"
+#include "WebSWOriginStore.h"
 #include "WebSharedWorkerServer.h"
 #include "WebSocketTask.h"
 #include <WebCore/CookieJar.h>
@@ -610,6 +611,25 @@
     return m_navigationPreloaders.get(identifier).get();
 }
 
+WebSWOriginStore* NetworkSession::swOriginStore() const
+{
+    return m_swServer ? &static_cast<WebSWOriginStore&>(m_swServer->originStore()) : nullptr;
+}
+
+void NetworkSession::registerSWServerConnection(WebSWServerConnection& connection)
+{
+    auto* store = swOriginStore();
+    ASSERT(store);
+    if (store)
+        store->registerSWServerConnection(connection);
+}
+
+void NetworkSession::unregisterSWServerConnection(WebSWServerConnection& connection)
+{
+    if (auto* store = swOriginStore())
+        store->unregisterSWServerConnection(connection);
+}
+
 SWServer& NetworkSession::ensureSWServer()
 {
     if (!m_swServer) {
@@ -628,7 +648,7 @@
             completionHandler({ });
         };
 #endif
-        m_swServer = makeUnique<SWServer>(info.processTerminationDelayEnabled, WTFMove(path), m_sessionID, shouldRunServiceWorkersOnMainThreadForTesting(), m_networkProcess->parentProcessHasServiceWorkerEntitlement(), overrideServiceWorkerRegistrationCountTestingValue(), [this](auto&& jobData, bool shouldRefreshCache, auto&& request, auto&& completionHandler) mutable {
+        m_swServer = makeUnique<SWServer>(makeUniqueRef<WebSWOriginStore>(), info.processTerminationDelayEnabled, WTFMove(path), m_sessionID, shouldRunServiceWorkersOnMainThreadForTesting(), m_networkProcess->parentProcessHasServiceWorkerEntitlement(), overrideServiceWorkerRegistrationCountTestingValue(), [this](auto&& jobData, bool shouldRefreshCache, auto&& request, auto&& completionHandler) mutable {
             ServiceWorkerSoftUpdateLoader::start(this, WTFMove(jobData), shouldRefreshCache, WTFMove(request), WTFMove(completionHandler));
         }, [this](auto& registrableDomain, std::optional<ProcessIdentifier> requestingProcessIdentifier, std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier, auto&& completionHandler) {
             ASSERT(!registrableDomain.isEmpty());

Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.h (293940 => 293941)


--- trunk/Source/WebKit/NetworkProcess/NetworkSession.h	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -81,6 +81,7 @@
 class WebResourceLoadStatisticsStore;
 class WebSharedWorkerServer;
 class WebSocketTask;
+class WebSWOriginStore;
 class WebSWServerConnection;
 struct NetworkSessionCreationParameters;
 struct SessionSet;
@@ -202,6 +203,9 @@
 
     WebCore::SWServer* swServer() { return m_swServer.get(); }
     WebCore::SWServer& ensureSWServer();
+    WebSWOriginStore* swOriginStore() const; // FIXME: Can be private?
+    void registerSWServerConnection(WebSWServerConnection&);
+    void unregisterSWServerConnection(WebSWServerConnection&);
 
     bool hasServiceWorkerDatabasePath() const;
 #endif

Added: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWOriginStore.cpp (0 => 293941)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWOriginStore.cpp	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWOriginStore.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(SERVICE_WORKER)
+#include "WebSWOriginStore.h"
+
+#include "WebSWClientConnectionMessages.h"
+#include "WebSWServerConnection.h"
+#include <WebCore/SecurityOrigin.h>
+
+namespace WebKit {
+
+using namespace WebCore;
+
+WebSWOriginStore::WebSWOriginStore()
+    : m_store(*this)
+{
+}
+
+void WebSWOriginStore::addToStore(const SecurityOriginData& origin)
+{
+    m_store.scheduleAddition(computeSharedStringHash(origin.toString()));
+    m_store.flushPendingChanges();
+}
+
+void WebSWOriginStore::removeFromStore(const SecurityOriginData& origin)
+{
+    m_store.scheduleRemoval(computeSharedStringHash(origin.toString()));
+    m_store.flushPendingChanges();
+}
+
+void WebSWOriginStore::clearStore()
+{
+    m_store.clear();
+}
+
+void WebSWOriginStore::importComplete()
+{
+    m_isImported = true;
+    for (auto& connection : m_webSWServerConnections)
+        connection.send(Messages::WebSWClientConnection::SetSWOriginTableIsImported());
+}
+
+void WebSWOriginStore::registerSWServerConnection(WebSWServerConnection& connection)
+{
+    m_webSWServerConnections.add(connection);
+
+    if (!m_store.isEmpty())
+        sendStoreHandle(connection);
+
+    if (m_isImported)
+        connection.send(Messages::WebSWClientConnection::SetSWOriginTableIsImported());
+}
+
+void WebSWOriginStore::unregisterSWServerConnection(WebSWServerConnection& connection)
+{
+    m_webSWServerConnections.remove(connection);
+}
+
+void WebSWOriginStore::sendStoreHandle(WebSWServerConnection& connection)
+{
+    SharedMemory::Handle handle;
+    if (!m_store.createSharedMemoryHandle(handle))
+        return;
+
+#if (OS(DARWIN) || OS(WINDOWS)) && !USE(UNIX_DOMAIN_SOCKETS)
+    uint64_t dataSize = handle.size();
+#else
+    uint64_t dataSize = 0;
+#endif
+    connection.send(Messages::WebSWClientConnection::SetSWOriginTableSharedMemory(SharedMemory::IPCHandle { WTFMove(handle), dataSize }));
+}
+
+void WebSWOriginStore::didInvalidateSharedMemory()
+{
+    for (auto& connection : m_webSWServerConnections)
+        sendStoreHandle(connection);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_WORKER)

Added: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWOriginStore.h (0 => 293941)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWOriginStore.h	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWOriginStore.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "SharedStringHashStore.h"
+#include <WebCore/SWOriginStore.h>
+#include <wtf/WeakHashSet.h>
+
+namespace WebKit {
+
+class WebSWServerConnection;
+
+class WebSWOriginStore final : public WebCore::SWOriginStore, private SharedStringHashStore::Client {
+public:
+    WebSWOriginStore();
+
+    void registerSWServerConnection(WebSWServerConnection&);
+    void unregisterSWServerConnection(WebSWServerConnection&);
+    void importComplete() final;
+
+private:
+    void sendStoreHandle(WebSWServerConnection&);
+
+    void addToStore(const WebCore::SecurityOriginData&) final;
+    void removeFromStore(const WebCore::SecurityOriginData&) final;
+    void clearStore() final;
+
+    // SharedStringHashStore::Client.
+    void didInvalidateSharedMemory() final;
+
+    SharedStringHashStore m_store;
+    bool m_isImported { false };
+    WeakHashSet<WebSWServerConnection> m_webSWServerConnections;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp (293940 => 293941)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -82,10 +82,14 @@
     , m_contentConnection(connection)
     , m_networkProcess(networkProcess)
 {
+    if (auto* session = this->session())
+        session->registerSWServerConnection(*this);
 }
 
 WebSWServerConnection::~WebSWServerConnection()
 {
+    if (auto* session = this->session())
+        session->unregisterSWServerConnection(*this);
     for (const auto& keyValue : m_clientOrigins)
         server().unregisterServiceWorkerClient(keyValue.value, keyValue.key);
     for (auto& completionHandler : m_unregisterJobs.values())
@@ -384,30 +388,18 @@
     send(Messages::WebSWClientConnection::PostMessageToServiceWorkerClient { destinationContextIdentifier, message, sourceServiceWorker->data(), sourceOrigin });
 }
 
-void WebSWServerConnection::matchRegistration(SecurityOriginData&& topOrigin, URL&& clientURL, CompletionHandler<void(std::optional<ServiceWorkerRegistrationData>&&)>&& callback)
+void WebSWServerConnection::matchRegistration(const SecurityOriginData& topOrigin, const URL& clientURL, CompletionHandler<void(std::optional<ServiceWorkerRegistrationData>&&)>&& callback)
 {
-    server().whenImportIsCompletedIfNeeded([weakThis = WeakPtr { *this }, topOrigin = WTFMove(topOrigin), clientURL = WTFMove(clientURL), callback = WTFMove(callback)]() mutable {
-        if (!weakThis) {
-            callback({ });
-            return;
-        }
-        if (auto* registration = weakThis->doRegistrationMatching(topOrigin, clientURL)) {
-            callback(registration->data());
-            return;
-        }
-        callback({ });
-    });
+    if (auto* registration = doRegistrationMatching(topOrigin, clientURL)) {
+        callback(registration->data());
+        return;
+    }
+    callback({ });
 }
 
-void WebSWServerConnection::getRegistrations(SecurityOriginData&& topOrigin, URL&& clientURL, CompletionHandler<void(const Vector<ServiceWorkerRegistrationData>&)>&& callback)
+void WebSWServerConnection::getRegistrations(const SecurityOriginData& topOrigin, const URL& clientURL, CompletionHandler<void(const Vector<ServiceWorkerRegistrationData>&)>&& callback)
 {
-    server().whenImportIsCompletedIfNeeded([weakThis = WeakPtr { *this }, topOrigin = WTFMove(topOrigin), clientURL = WTFMove(clientURL), callback = WTFMove(callback)]() mutable {
-        if (!weakThis) {
-            callback({ });
-            return;
-        }
-        callback(weakThis->server().getRegistrations(topOrigin, clientURL));
-    });
+    callback(server().getRegistrations(topOrigin, clientURL));
 }
 
 void WebSWServerConnection::registerServiceWorkerClient(WebCore::ClientOrigin&& clientOrigin, ServiceWorkerClientData&& data, const std::optional<ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, String&& userAgent)

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h (293940 => 293941)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -112,8 +112,8 @@
 
     void startFetch(ServiceWorkerFetchTask&, WebCore::SWServerWorker&);
 
-    void matchRegistration(WebCore::SecurityOriginData&&, URL&&, CompletionHandler<void(std::optional<WebCore::ServiceWorkerRegistrationData>&&)>&&);
-    void getRegistrations(WebCore::SecurityOriginData&&, URL&&, CompletionHandler<void(const Vector<WebCore::ServiceWorkerRegistrationData>&)>&&);
+    void matchRegistration(const WebCore::SecurityOriginData& topOrigin, const URL& clientURL, CompletionHandler<void(std::optional<WebCore::ServiceWorkerRegistrationData>&&)>&&);
+    void getRegistrations(const WebCore::SecurityOriginData& topOrigin, const URL& clientURL, CompletionHandler<void(const Vector<WebCore::ServiceWorkerRegistrationData>&)>&&);
 
     void terminateWorkerFromClient(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&);
     void whenServiceWorkerIsTerminatedForTesting(WebCore::ServiceWorkerIdentifier, CompletionHandler<void()>&&);

Modified: trunk/Source/WebKit/Sources.txt (293940 => 293941)


--- trunk/Source/WebKit/Sources.txt	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/Sources.txt	2022-05-07 01:41:06 UTC (rev 293941)
@@ -135,6 +135,7 @@
 NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp
 NetworkProcess/ServiceWorker/ServiceWorkerNavigationPreloader.cpp
 NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp
+NetworkProcess/ServiceWorker/WebSWOriginStore.cpp @no-unify
 NetworkProcess/ServiceWorker/WebSWServerConnection.cpp @no-unify
 NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp @no-unify
 
@@ -795,6 +796,7 @@
 WebProcess/Storage/RemoteWorkerFrameLoaderClient.cpp
 WebProcess/Storage/WebSWClientConnection.cpp
 WebProcess/Storage/WebSWContextManagerConnection.cpp
+WebProcess/Storage/WebSWOriginTable.cpp
 WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp
 WebProcess/Storage/WebServiceWorkerProvider.cpp
 WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (293940 => 293941)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-05-07 01:41:06 UTC (rev 293941)
@@ -1434,6 +1434,7 @@
 		83A0ED351F747CCF003299EB /* PreconnectTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 83A0ED321F747CC6003299EB /* PreconnectTask.h */; };
 		83D454D71BE9D3C4006C93BD /* NetworkLoadClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D454D61BE9D3C4006C93BD /* NetworkLoadClient.h */; };
 		83EE575C1DB7D61100C74C50 /* WebValidationMessageClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83EE575A1DB7D60600C74C50 /* WebValidationMessageClient.h */; };
+		83F1A07A1F96E7790045B94E /* WebSWOriginTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 83F1A0781F96E7710045B94E /* WebSWOriginTable.h */; };
 		83F9644E1FA0F76E00C47750 /* SharedStringHashTableReadOnly.h in Headers */ = {isa = PBXBuildFile; fileRef = 83F9644C1FA0F76300C47750 /* SharedStringHashTableReadOnly.h */; };
 		84477853176FCC0800CDC7BB /* InjectedBundleHitTestResultMediaType.h in Headers */ = {isa = PBXBuildFile; fileRef = 84477851176FCAC100CDC7BB /* InjectedBundleHitTestResultMediaType.h */; };
 		8644890B27B47020007A1C66 /* _WKSystemPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = 8644890A27B47020007A1C66 /* _WKSystemPreferences.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1468,6 +1469,8 @@
 		9354242C2703BDCB005CA72C /* WebFileSystemStorageConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9354242A2703BDCB005CA72C /* WebFileSystemStorageConnection.h */; };
 		9356F2DC2152B6B500E6D5DF /* WebSWClientConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A53021F4793B200DCDC0A /* WebSWClientConnection.h */; };
 		9356F2DD2152B6F600E6D5DF /* WebSWServerConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 93BA04E02151ADF4007F455F /* WebSWServerConnection.h */; };
+		9356F2DE2152B71000E6D5DF /* WebSWOriginStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 93BA04DE2151ADF4007F455F /* WebSWOriginStore.h */; };
+		9356F2DF2152B72300E6D5DF /* WebSWOriginStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93BA04DF2151ADF4007F455F /* WebSWOriginStore.cpp */; };
 		9356F2E02152B75200E6D5DF /* WebSWServerToContextConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93BA04DD2151ADF3007F455F /* WebSWServerToContextConnection.cpp */; };
 		9356F2E12152B76600E6D5DF /* WebSWServerConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93BA04E12151ADF4007F455F /* WebSWServerConnection.cpp */; };
 		935B579A26F51933008B48AC /* FileSystemStorageHandleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 935B579826F51270008B48AC /* FileSystemStorageHandleRegistry.h */; };
@@ -5686,6 +5689,8 @@
 		83D454D61BE9D3C4006C93BD /* NetworkLoadClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkLoadClient.h; sourceTree = "<group>"; };
 		83EE57591DB7D60600C74C50 /* WebValidationMessageClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebValidationMessageClient.cpp; sourceTree = "<group>"; };
 		83EE575A1DB7D60600C74C50 /* WebValidationMessageClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebValidationMessageClient.h; sourceTree = "<group>"; };
+		83F1A0771F96E7700045B94E /* WebSWOriginTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWOriginTable.cpp; sourceTree = "<group>"; };
+		83F1A0781F96E7710045B94E /* WebSWOriginTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWOriginTable.h; sourceTree = "<group>"; };
 		83F9644B1FA0F76200C47750 /* SharedStringHashTableReadOnly.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedStringHashTableReadOnly.cpp; sourceTree = "<group>"; };
 		83F9644C1FA0F76300C47750 /* SharedStringHashTableReadOnly.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedStringHashTableReadOnly.h; sourceTree = "<group>"; };
 		84477851176FCAC100CDC7BB /* InjectedBundleHitTestResultMediaType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundleHitTestResultMediaType.h; sourceTree = "<group>"; };
@@ -5801,6 +5806,8 @@
 		93BA04DB2151ADF3007F455F /* WebSWServerToContextConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWServerToContextConnection.h; sourceTree = "<group>"; };
 		93BA04DC2151ADF3007F455F /* WebSWServerToContextConnection.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebSWServerToContextConnection.messages.in; sourceTree = "<group>"; };
 		93BA04DD2151ADF3007F455F /* WebSWServerToContextConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWServerToContextConnection.cpp; sourceTree = "<group>"; };
+		93BA04DE2151ADF4007F455F /* WebSWOriginStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWOriginStore.h; sourceTree = "<group>"; };
+		93BA04DF2151ADF4007F455F /* WebSWOriginStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWOriginStore.cpp; sourceTree = "<group>"; };
 		93BA04E02151ADF4007F455F /* WebSWServerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWServerConnection.h; sourceTree = "<group>"; };
 		93BA04E12151ADF4007F455F /* WebSWServerConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWServerConnection.cpp; sourceTree = "<group>"; };
 		93BDEB00171DD7AF00BFEE1B /* WKPageLoadTypesPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPageLoadTypesPrivate.h; sourceTree = "<group>"; };
@@ -10272,6 +10279,8 @@
 				466BC0381FA266C9002FA9C1 /* WebSWContextManagerConnection.cpp */,
 				466BC0391FA266C9002FA9C1 /* WebSWContextManagerConnection.h */,
 				466BC03A1FA266C9002FA9C1 /* WebSWContextManagerConnection.messages.in */,
+				83F1A0771F96E7700045B94E /* WebSWOriginTable.cpp */,
+				83F1A0781F96E7710045B94E /* WebSWOriginTable.h */,
 			);
 			path = Storage;
 			sourceTree = "<group>";
@@ -11330,6 +11339,8 @@
 				41EB4D3A274CE04500A9272B /* ServiceWorkerNavigationPreloader.h */,
 				41D5C6D9238EB20E00B9B3CB /* ServiceWorkerSoftUpdateLoader.cpp */,
 				41D5C6D8238EB20D00B9B3CB /* ServiceWorkerSoftUpdateLoader.h */,
+				93BA04DF2151ADF4007F455F /* WebSWOriginStore.cpp */,
+				93BA04DE2151ADF4007F455F /* WebSWOriginStore.h */,
 				93BA04E12151ADF4007F455F /* WebSWServerConnection.cpp */,
 				93BA04E02151ADF4007F455F /* WebSWServerConnection.h */,
 				93BA04DA2151ADF3007F455F /* WebSWServerConnection.messages.in */,
@@ -15101,6 +15112,8 @@
 				466BC03C1FA266DA002FA9C1 /* WebSWContextManagerConnection.h in Headers */,
 				460F48901F996F7100CF4B87 /* WebSWContextManagerConnectionMessages.h in Headers */,
 				C11A9ECC214035F800CFB20A /* WebSwitchingGPUClient.h in Headers */,
+				9356F2DE2152B71000E6D5DF /* WebSWOriginStore.h in Headers */,
+				83F1A07A1F96E7790045B94E /* WebSWOriginTable.h in Headers */,
 				9356F2DD2152B6F600E6D5DF /* WebSWServerConnection.h in Headers */,
 				517A52D91F43A9DA00DCDC0A /* WebSWServerConnectionMessages.h in Headers */,
 				515262BC1FB9515D0070E579 /* WebSWServerToContextConnectionMessages.h in Headers */,
@@ -17365,6 +17378,7 @@
 				93D6B78A254CD43E0058DD3A /* WebSpeechRecognitionConnectionMessageReceiver.cpp in Sources */,
 				517A530F1F47A86200DCDC0A /* WebSWClientConnectionMessageReceiver.cpp in Sources */,
 				460F488F1F996F7100CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp in Sources */,
+				9356F2DF2152B72300E6D5DF /* WebSWOriginStore.cpp in Sources */,
 				9356F2E12152B76600E6D5DF /* WebSWServerConnection.cpp in Sources */,
 				517A52D81F43A9DA00DCDC0A /* WebSWServerConnectionMessageReceiver.cpp in Sources */,
 				9356F2E02152B75200E6D5DF /* WebSWServerToContextConnection.cpp in Sources */,

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (293940 => 293941)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -39,6 +39,7 @@
 #include "WebPageProxyMessages.h"
 #include "WebProcess.h"
 #include "WebProcessProxyMessages.h"
+#include "WebSWOriginTable.h"
 #include "WebSWServerConnectionMessages.h"
 #include <WebCore/Document.h>
 #include <WebCore/DocumentLoader.h>
@@ -61,6 +62,7 @@
 
 WebSWClientConnection::WebSWClientConnection()
     : m_identifier(Process::identifier())
+    , m_swOriginTable(makeUniqueRef<WebSWOriginTable>())
 {
 }
 
@@ -76,7 +78,9 @@
 
 void WebSWClientConnection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
 {
-    send(Messages::WebSWServerConnection::ScheduleJobInServer { jobData });
+    runOrDelayTaskForImport([this, jobData] {
+        send(Messages::WebSWServerConnection::ScheduleJobInServer { jobData });
+    });
 }
 
 void WebSWClientConnection::finishFetchingScriptInServer(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, ServiceWorkerRegistrationKey&& registrationKey, WorkerFetchResult&& result)
@@ -126,12 +130,49 @@
     send(Messages::WebSWServerConnection::DidResolveRegistrationPromise { key });
 }
 
+bool WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData& origin) const
+{
+    if (!m_swOriginTable->isImported())
+        return true;
+
+    return m_swOriginTable->contains(origin);
+}
+
+void WebSWClientConnection::setSWOriginTableSharedMemory(const SharedMemory::IPCHandle& ipcHandle)
+{
+    m_swOriginTable->setSharedMemory(ipcHandle.handle);
+}
+
+void WebSWClientConnection::setSWOriginTableIsImported()
+{
+    m_swOriginTable->setIsImported();
+    while (!m_tasksPendingOriginImport.isEmpty())
+        m_tasksPendingOriginImport.takeFirst()();
+}
+
 void WebSWClientConnection::matchRegistration(SecurityOriginData&& topOrigin, const URL& clientURL, RegistrationCallback&& callback)
 {
     ASSERT(isMainRunLoop());
-    sendWithAsyncReply(Messages::WebSWServerConnection::MatchRegistration { topOrigin, clientURL }, WTFMove(callback));
+
+    if (!mayHaveServiceWorkerRegisteredForOrigin(topOrigin)) {
+        callback(std::nullopt);
+        return;
+    }
+
+    runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = WTFMove(topOrigin), clientURL]() mutable {
+        sendWithAsyncReply(Messages::WebSWServerConnection::MatchRegistration { topOrigin, clientURL }, WTFMove(callback));
+    });
 }
 
+void WebSWClientConnection::runOrDelayTaskForImport(Function<void()>&& task)
+{
+    if (m_swOriginTable->isImported()) {
+        task();
+        return;
+    }
+    m_tasksPendingOriginImport.append(WTFMove(task));
+}
+
 void WebSWClientConnection::whenRegistrationReady(const SecurityOriginData& topOrigin, const URL& clientURL, WhenRegistrationReadyCallback&& callback)
 {
     sendWithAsyncReply(Messages::WebSWServerConnection::WhenRegistrationReady { topOrigin, clientURL }, [callback = WTFMove(callback)](auto result) mutable {
@@ -158,7 +199,15 @@
 void WebSWClientConnection::getRegistrations(SecurityOriginData&& topOrigin, const URL& clientURL, GetRegistrationsCallback&& callback)
 {
     ASSERT(isMainRunLoop());
-    sendWithAsyncReply(Messages::WebSWServerConnection::GetRegistrations { topOrigin, clientURL }, WTFMove(callback));
+
+    if (!mayHaveServiceWorkerRegisteredForOrigin(topOrigin)) {
+        callback({ });
+        return;
+    }
+
+    runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = WTFMove(topOrigin), clientURL]() mutable {
+        sendWithAsyncReply(Messages::WebSWServerConnection::GetRegistrations { topOrigin, clientURL }, WTFMove(callback));
+    });
 }
 
 void WebSWClientConnection::connectionToServerLost()

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (293940 => 293941)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -42,6 +42,7 @@
 
 namespace WebKit {
 
+class WebSWOriginTable;
 class WebServiceWorkerProvider;
 
 class WebSWClientConnection final : public WebCore::SWClientConnection, private IPC::MessageSender, public IPC::MessageReceiver {
@@ -57,6 +58,8 @@
     void disconnectedFromWebProcess();
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
 
+    bool mayHaveServiceWorkerRegisteredForOrigin(const WebCore::SecurityOriginData&) const final;
+
     void connectionToServerLost();
 
     bool isThrottleable() const { return m_isThrottleable; }
@@ -107,10 +110,16 @@
     IPC::Connection* messageSenderConnection() const final;
     uint64_t messageSenderDestinationID() const final { return 0; }
 
+    void setSWOriginTableSharedMemory(const SharedMemory::IPCHandle&);
+    void setSWOriginTableIsImported();
+
     void clear();
 
     WebCore::SWServerConnectionIdentifier m_identifier;
 
+    UniqueRef<WebSWOriginTable> m_swOriginTable;
+
+    Deque<Function<void()>> m_tasksPendingOriginImport;
     bool m_isThrottleable { true };
 }; // class WebSWServerConnection
 

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (293940 => 293941)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2022-05-07 01:41:06 UTC (rev 293941)
@@ -35,6 +35,8 @@
     SetRegistrationUpdateViaCache(WebCore::ServiceWorkerRegistrationIdentifier identifier, enum:uint8_t WebCore::ServiceWorkerUpdateViaCache updateViaCache);
     NotifyClientsOfControllerChange(HashSet<WebCore::ScriptExecutionContextIdentifier> contextIdentifiers, struct WebCore::ServiceWorkerData newController)
 
+    SetSWOriginTableIsImported()
+    SetSWOriginTableSharedMemory(WebKit::SharedMemory::IPCHandle handle)
     PostMessageToServiceWorkerClient(WebCore::ScriptExecutionContextIdentifier destinationContextIdentifier, struct WebCore::MessageWithMessagePorts message, struct WebCore::ServiceWorkerData source, String sourceOrigin)
 
     SetServiceWorkerClientIsControlled(WebCore::ScriptExecutionContextIdentifier workerIdentifier, struct WebCore::ServiceWorkerRegistrationData data) -> (bool isSuccess)

Added: trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.cpp (0 => 293941)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(SERVICE_WORKER)
+#include "WebSWOriginTable.h"
+
+#include <WebCore/SecurityOrigin.h>
+
+namespace WebKit {
+using namespace WebCore;
+
+bool WebSWOriginTable::contains(const SecurityOriginData& origin) const
+{
+    return m_serviceWorkerOriginTable.contains(computeSharedStringHash(origin.toString()));
+}
+
+void WebSWOriginTable::setSharedMemory(const SharedMemory::Handle& handle)
+{
+    auto sharedMemory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
+    if (!sharedMemory)
+        return;
+
+    m_serviceWorkerOriginTable.setSharedMemory(sharedMemory.releaseNonNull());
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_WORKER)

Added: trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.h (0 => 293941)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.h	2022-05-07 01:41:06 UTC (rev 293941)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "SharedMemory.h"
+#include "SharedStringHashTableReadOnly.h"
+
+namespace WebCore {
+struct SecurityOriginData;
+}
+
+namespace WebKit {
+
+class WebSWOriginTable {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    WebSWOriginTable() = default;
+
+    bool isImported() const { return m_isImported; }
+    void setIsImported() { m_isImported = true; }
+    bool contains(const WebCore::SecurityOriginData&) const;
+    void setSharedMemory(const SharedMemory::Handle&);
+
+private:
+    SharedStringHashTableReadOnly m_serviceWorkerOriginTable;
+    bool m_isImported { false };
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp (293940 => 293941)


--- trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp	2022-05-07 01:38:09 UTC (rev 293940)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp	2022-05-07 01:41:06 UTC (rev 293941)
@@ -43,7 +43,6 @@
 #include <WebCore/EmptyClients.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageConfiguration.h>
-#include <WebCore/ScriptExecutionContextIdentifier.h>
 #include <WebCore/SharedWorkerContextManager.h>
 #include <WebCore/SharedWorkerThreadProxy.h>
 #include <WebCore/UserAgent.h>
@@ -116,7 +115,7 @@
         initializationData.userAgent = m_userAgent;
 
     if (!initializationData.clientIdentifier)
-        initializationData.clientIdentifier = WebCore::ScriptExecutionContextIdentifier::generate();
+        initializationData.clientIdentifier = ScriptExecutionContextIdentifier::generate();
 
     page->setupForRemoteWorker(workerFetchResult.lastRequestURL, origin.topOrigin, workerFetchResult.referrerPolicy);
     auto sharedWorkerThreadProxy = WebCore::SharedWorkerThreadProxy::create(WTFMove(page), sharedWorkerIdentifier, origin, WTFMove(workerFetchResult), WTFMove(workerOptions), WTFMove(initializationData), WebProcess::singleton().cacheStorageProvider());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to