Move WKProcessPool._registerURLSchemeServiceWorkersCanHandle to _WKWebsiteDataStoreCo...
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Oct 2019 16:43:17 +0000 (16:43 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Oct 2019 16:43:17 +0000 (16:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=202553

Reviewed by Youenn Fablet.

Source/WebCore:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::SWServer):
* workers/service/server/SWServer.h:
(WebCore::SWServer::registeredSchemes const):
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::runRegisterJob):

Source/WebKit:

It was only used for testing, and all the tests that use it still pass with the new SPI.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
(WebKit::NetworkProcess::addWebsiteDataStore):
(WebKit::NetworkProcess::swServerForSession):
(WebKit::NetworkProcess::addServiceWorkerSession):
* NetworkProcess/NetworkProcess.h:
* Shared/AuxiliaryProcess.cpp:
(WebKit::AuxiliaryProcess::registerURLSchemeServiceWorkersCanHandle const): Deleted.
* Shared/AuxiliaryProcess.h:
* Shared/AuxiliaryProcess.messages.in:
* Shared/WebsiteDataStoreParameters.cpp:
(WebKit::WebsiteDataStoreParameters::encode const):
(WebKit::WebsiteDataStoreParameters::decode):
* Shared/WebsiteDataStoreParameters.h:
* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _registerURLSchemeServiceWorkersCanHandle:]): Deleted.
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
(-[_WKWebsiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:]):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::ensureNetworkProcess):
(WebKit::WebProcessPool::initializeNewWebProcess):
(WebKit::WebProcessPool::registerURLSchemeServiceWorkersCanHandle): Deleted.
* UIProcess/WebProcessPool.h:
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:
(WebKit::WebsiteDataStoreConfiguration::copy):
* UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:
(WebKit::WebsiteDataStoreConfiguration::serviceWorkerRegisteredSchemes const):
(WebKit::WebsiteDataStoreConfiguration::registerServiceWorkerScheme):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
* TestWebKitAPI/Tests/WebKitCocoa/StorageQuota.mm:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250728 268f45cc-cd09-0410-ab3c-d52691b4dbfc

25 files changed:
Source/WebCore/ChangeLog
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Source/WebCore/workers/service/server/SWServerJobQueue.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/Shared/AuxiliaryProcess.cpp
Source/WebKit/Shared/AuxiliaryProcess.h
Source/WebKit/Shared/AuxiliaryProcess.messages.in
Source/WebKit/Shared/WebsiteDataStoreParameters.cpp
Source/WebKit/Shared/WebsiteDataStoreParameters.h
Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm
Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h
Source/WebKit/WebProcess/WebProcess.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/StorageQuota.mm

index 2bf7d44..df347fd 100644 (file)
@@ -1,3 +1,17 @@
+2019-10-04  Alex Christensen  <achristensen@webkit.org>
+
+        Move WKProcessPool._registerURLSchemeServiceWorkersCanHandle to _WKWebsiteDataStoreConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=202553
+
+        Reviewed by Youenn Fablet.
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::SWServer):
+        * workers/service/server/SWServer.h:
+        (WebCore::SWServer::registeredSchemes const):
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::runRegisterJob):
+
 2019-10-04  youenn fablet  <youenn@apple.com>
 
         AbortSignal does not always emit the abort signal
index 108eff5..d3ba788 100644 (file)
@@ -299,10 +299,11 @@ void SWServer::Connection::syncTerminateWorker(ServiceWorkerIdentifier identifie
         m_server.syncTerminateWorker(*worker);
 }
 
-SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID sessionID, CreateContextConnectionCallback&& callback)
+SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore, HashSet<String>&& registeredSchemes, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID sessionID, CreateContextConnectionCallback&& callback)
     : m_originStore(WTFMove(originStore))
     , m_sessionID(sessionID)
     , m_isProcessTerminationDelayEnabled(processTerminationDelayEnabled)
+    , m_registeredSchemes(WTFMove(registeredSchemes))
     , m_createContextConnectionCallback(WTFMove(callback))
 {
     ASSERT(!registrationDatabaseDirectory.isEmpty() || m_sessionID.isEphemeral());
index 9f86d1a..f42c1af 100644 (file)
@@ -125,7 +125,7 @@ public:
     };
 
     using CreateContextConnectionCallback = Function<void(const WebCore::RegistrableDomain&)>;
-    WEBCORE_EXPORT SWServer(UniqueRef<SWOriginStore>&&, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID, CreateContextConnectionCallback&&);
+    WEBCORE_EXPORT SWServer(UniqueRef<SWOriginStore>&&, HashSet<String>&& registeredSchemes, bool processTerminationDelayEnabled, String&& registrationDatabaseDirectory, PAL::SessionID, CreateContextConnectionCallback&&);
 
     WEBCORE_EXPORT ~SWServer();
 
@@ -164,6 +164,7 @@ public:
     Connection* connection(SWServerConnectionIdentifier identifier) const { return m_connections.get(identifier); }
 
     const HashMap<SWServerConnectionIdentifier, std::unique_ptr<Connection>>& connections() const { return m_connections; }
+    const HashSet<String> registeredSchemes() const { return m_registeredSchemes; }
 
     SWOriginStore& originStore() { return m_originStore; }
 
@@ -255,6 +256,7 @@ private:
     PAL::SessionID m_sessionID;
     bool m_importCompleted { false };
     bool m_isProcessTerminationDelayEnabled { true };
+    HashSet<String> m_registeredSchemes;
     Vector<CompletionHandler<void()>> m_clearCompletionCallbacks;
     Vector<Function<void(const HashSet<SecurityOriginData>&)>> m_getOriginsWithRegistrationsCallbacks;
     HashMap<RegistrableDomain, SWServerToContextConnection*> m_contextConnections;
index 616bc96..503e328 100644 (file)
@@ -260,7 +260,7 @@ void SWServerJobQueue::runRegisterJob(const ServiceWorkerJobData& job)
 {
     ASSERT(job.type == ServiceWorkerJobType::Register);
 
-    if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL) && !SchemeRegistry::isServiceWorkerContainerCustomScheme(job.scriptURL.protocol().toStringWithoutCopying()))
+    if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL) && !m_server.registeredSchemes().contains(job.scriptURL.protocol().toStringWithoutCopying()))
         return rejectCurrentJob(ExceptionData { SecurityError, "Script URL is not potentially trustworthy"_s });
 
     // If the origin of job's script url is not job's referrer's origin, then:
index bfcdfc2..83246c0 100644 (file)
@@ -1,3 +1,47 @@
+2019-10-04  Alex Christensen  <achristensen@webkit.org>
+
+        Move WKProcessPool._registerURLSchemeServiceWorkersCanHandle to _WKWebsiteDataStoreConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=202553
+
+        Reviewed by Youenn Fablet.
+
+        It was only used for testing, and all the tests that use it still pass with the new SPI.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        (WebKit::NetworkProcess::addWebsiteDataStore):
+        (WebKit::NetworkProcess::swServerForSession):
+        (WebKit::NetworkProcess::addServiceWorkerSession):
+        * NetworkProcess/NetworkProcess.h:
+        * Shared/AuxiliaryProcess.cpp:
+        (WebKit::AuxiliaryProcess::registerURLSchemeServiceWorkersCanHandle const): Deleted.
+        * Shared/AuxiliaryProcess.h:
+        * Shared/AuxiliaryProcess.messages.in:
+        * Shared/WebsiteDataStoreParameters.cpp:
+        (WebKit::WebsiteDataStoreParameters::encode const):
+        (WebKit::WebsiteDataStoreParameters::decode):
+        * Shared/WebsiteDataStoreParameters.h:
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _registerURLSchemeServiceWorkersCanHandle:]): Deleted.
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
+        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
+        (-[_WKWebsiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:]):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::ensureNetworkProcess):
+        (WebKit::WebProcessPool::initializeNewWebProcess):
+        (WebKit::WebProcessPool::registerURLSchemeServiceWorkersCanHandle): Deleted.
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:
+        (WebKit::WebsiteDataStoreConfiguration::copy):
+        * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.h:
+        (WebKit::WebsiteDataStoreConfiguration::serviceWorkerRegisteredSchemes const):
+        (WebKit::WebsiteDataStoreConfiguration::registerServiceWorkerScheme):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+
 2019-10-04  youenn fablet  <youenn@apple.com>
 
         Allow to suspend RTCPeerConnection when not connected
index 2fb7809..b430488 100644 (file)
@@ -323,10 +323,7 @@ void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&&
 #if ENABLE(SERVICE_WORKER)
     if (parentProcessHasServiceWorkerEntitlement()) {
         bool serviceWorkerProcessTerminationDelayEnabled = true;
-        addServiceWorkerSession(PAL::SessionID::defaultSessionID(), serviceWorkerProcessTerminationDelayEnabled, parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
-
-        for (auto& scheme : parameters.urlSchemesServiceWorkersCanHandle)
-            registerURLSchemeServiceWorkersCanHandle(scheme);
+        addServiceWorkerSession(PAL::SessionID::defaultSessionID(), serviceWorkerProcessTerminationDelayEnabled, { }, WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
     }
 #endif
     initializeStorageQuota(parameters.defaultDataStoreParameters);
@@ -452,7 +449,7 @@ void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters
 
 #if ENABLE(SERVICE_WORKER)
     if (parentProcessHasServiceWorkerEntitlement())
-        addServiceWorkerSession(parameters.networkSessionParameters.sessionID, parameters.serviceWorkerProcessTerminationDelayEnabled, parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
+        addServiceWorkerSession(parameters.networkSessionParameters.sessionID, parameters.serviceWorkerProcessTerminationDelayEnabled, WTFMove(parameters.serviceWorkerRegisteredSchemes), WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
 #endif
 
     m_storageManagerSet->add(parameters.networkSessionParameters.sessionID, parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle);
@@ -2393,11 +2390,12 @@ SWServer& NetworkProcess::swServerForSession(PAL::SessionID sessionID)
     auto result = m_swServers.ensure(sessionID, [&] {
         auto info = m_serviceWorkerInfo.get(sessionID);
         auto path = info.databasePath;
+        auto registeredSchemes = info.registeredSchemes;
         // There should already be a registered path for this PAL::SessionID.
         // If there's not, then where did this PAL::SessionID come from?
         ASSERT(sessionID.isEphemeral() || !path.isEmpty());
 
-        return makeUnique<SWServer>(makeUniqueRef<WebSWOriginStore>(), info.processTerminationDelayEnabled, WTFMove(path), sessionID, [this, sessionID](auto& registrableDomain) {
+        return makeUnique<SWServer>(makeUniqueRef<WebSWOriginStore>(), WTFMove(registeredSchemes), info.processTerminationDelayEnabled, WTFMove(path), sessionID, [this, sessionID](auto& registrableDomain) {
             ASSERT(!registrableDomain.isEmpty());
             parentProcessConnection()->send(Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess { registrableDomain, sessionID }, 0);
         });
@@ -2428,11 +2426,12 @@ void NetworkProcess::unregisterSWServerConnection(WebSWServerConnection& connect
         store->unregisterSWServerConnection(connection);
 }
 
-void NetworkProcess::addServiceWorkerSession(PAL::SessionID sessionID, bool processTerminationDelayEnabled, String& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle& handle)
+void NetworkProcess::addServiceWorkerSession(PAL::SessionID sessionID, bool processTerminationDelayEnabled, HashSet<String>&& registeredSchemes, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle& handle)
 {
     ServiceWorkerInfo info {
-        serviceWorkerRegistrationDirectory,
+        WTFMove(serviceWorkerRegistrationDirectory),
         processTerminationDelayEnabled,
+        WTFMove(registeredSchemes)
     };
     auto addResult = m_serviceWorkerInfo.add(sessionID, WTFMove(info));
     if (addResult.isNewEntry) {
index 3a6256f..1a342f9 100644 (file)
@@ -459,7 +459,7 @@ private:
     
     WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
 
-    void addServiceWorkerSession(PAL::SessionID, bool processTerminationDelayEnabled, String& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
+    void addServiceWorkerSession(PAL::SessionID, bool processTerminationDelayEnabled, HashSet<String>&& registeredSchemes, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
 #endif
 
     void postStorageTask(CrossThreadTask&&);
@@ -527,6 +527,7 @@ private:
     struct ServiceWorkerInfo {
         String databasePath;
         bool processTerminationDelayEnabled { true };
+        HashSet<String> registeredSchemes;
     };
     HashMap<PAL::SessionID, ServiceWorkerInfo> m_serviceWorkerInfo;
     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
index 61272e2..14ea5e4 100644 (file)
@@ -195,11 +195,6 @@ void AuxiliaryProcess::shutDown()
     terminate();
 }
 
-void AuxiliaryProcess::registerURLSchemeServiceWorkersCanHandle(const String& urlScheme) const
-{
-    WebCore::SchemeRegistry::registerURLSchemeServiceWorkersCanHandle(urlScheme);
-}
-
 #if !PLATFORM(COCOA)
 void AuxiliaryProcess::platformInitialize()
 {
index 19253e2..996b927 100644 (file)
@@ -121,7 +121,6 @@ protected:
 
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
-    void registerURLSchemeServiceWorkersCanHandle(const String&) const;
 #if OS(LINUX)
     void didReceiveMemoryPressureEvent(bool isCritical);
 #endif
index 33d6570..0cf3f9a 100644 (file)
@@ -22,7 +22,6 @@
 
 messages -> AuxiliaryProcess {
     ShutDown()
-    RegisterURLSchemeServiceWorkersCanHandle(String scheme)
     SetProcessSuppressionEnabled(bool flag)
 
 #if OS(LINUX)
index c0fcf9c..a89d3bb 100644 (file)
@@ -51,6 +51,7 @@ void WebsiteDataStoreParameters::encode(IPC::Encoder& encoder) const
 
 #if ENABLE(SERVICE_WORKER)
     encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle << serviceWorkerProcessTerminationDelayEnabled;
+    encoder << serviceWorkerRegisteredSchemes;
 #endif
 
     encoder << localStorageDirectory << localStorageDirectoryExtensionHandle;
@@ -127,6 +128,12 @@ Optional<WebsiteDataStoreParameters> WebsiteDataStoreParameters::decode(IPC::Dec
     if (!serviceWorkerProcessTerminationDelayEnabled)
         return WTF::nullopt;
     parameters.serviceWorkerProcessTerminationDelayEnabled = WTFMove(*serviceWorkerProcessTerminationDelayEnabled);
+    
+    Optional<HashSet<String>> serviceWorkerRegisteredSchemes;
+    decoder >> serviceWorkerRegisteredSchemes;
+    if (!serviceWorkerRegisteredSchemes)
+        return WTF::nullopt;
+    parameters.serviceWorkerRegisteredSchemes = WTFMove(*serviceWorkerRegisteredSchemes);
 #endif
 
     Optional<String> localStorageDirectory;
index 095f09d..546181a 100644 (file)
@@ -66,6 +66,7 @@ struct WebsiteDataStoreParameters {
     String serviceWorkerRegistrationDirectory;
     SandboxExtension::Handle serviceWorkerRegistrationDirectoryExtensionHandle;
     bool serviceWorkerProcessTerminationDelayEnabled { true };
+    HashSet<String> serviceWorkerRegisteredSchemes;
 #endif
 
     String localStorageDirectory;
index 4ad3478..c2a9566 100644 (file)
@@ -189,11 +189,6 @@ static WKProcessPool *sharedProcessPool;
     _processPool->allowSpecificHTTPSCertificateForHost(WebKit::WebCertificateInfo::create(WebCore::CertificateInfo((__bridge CFArrayRef)certificateChain)).ptr(), host);
 }
 
-- (void)_registerURLSchemeServiceWorkersCanHandle:(NSString *)scheme
-{
-    _processPool->registerURLSchemeServiceWorkersCanHandle(scheme);
-}
-
 - (void)_registerURLSchemeAsCanDisplayOnlyIfCanRequest:(NSString *)scheme
 {
     _processPool->registerURLSchemeAsCanDisplayOnlyIfCanRequest(scheme);
index b580238..ef8bb56 100644 (file)
 
 // Test only.
 - (void)_setAllowsAnySSLCertificateForServiceWorker:(BOOL)allows WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
-- (void)_registerURLSchemeServiceWorkersCanHandle:(NSString *)scheme WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
 - (void)_getActivePagesOriginsInWebProcessForTesting:(pid_t)pid completionHandler:(void(^)(NSArray<NSString *> *))completionHandler WK_API_AVAILABLE(macos(10.14.4), ios(12.2));
 - (BOOL)_networkProcessHasEntitlementForTesting:(NSString *)entitlement WK_API_AVAILABLE(macos(10.14.4), ios(12.2));
 - (void)_clearPermanentCredentialsForProtectionSpace:(NSURLProtectionSpace *)protectionSpace WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
index 912edcc..277fb12 100644 (file)
@@ -71,6 +71,7 @@ WK_CLASS_AVAILABLE(macos(10.13), ios(11.0))
 @property (nonatomic) BOOL suppressesConnectionTerminationOnSystemChange WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 // Testing only.
+- (void)registerURLSchemeServiceWorkersCanHandleForTesting:(NSString *)scheme WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic) BOOL allLoadsBlockedByDeviceManagementRestrictionsForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
index bf12906..e0e0927 100644 (file)
@@ -400,6 +400,11 @@ static void checkURLArgument(NSURL *url)
     _configuration->setAllLoadsBlockedByDeviceManagementRestrictionsForTesting(blocked);
 }
 
+- (void)registerURLSchemeServiceWorkersCanHandleForTesting:(NSString *)scheme
+{
+    _configuration->registerServiceWorkerScheme(scheme);
+}
+
 - (API::Object&)_apiObject
 {
     return *_configuration;
index 991e27e..8b66de0 100644 (file)
@@ -544,9 +544,6 @@ NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* with
     if (!parameters.serviceWorkerRegistrationDirectory)
         parameters.serviceWorkerRegistrationDirectory =  WebKit::WebsiteDataStore::defaultServiceWorkerRegistrationDirectory();
     SandboxExtension::createHandleForReadWriteDirectory(parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
-
-    if (!m_schemesServiceWorkersCanHandle.isEmpty())
-        parameters.urlSchemesServiceWorkersCanHandle = copyToVector(m_schemesServiceWorkersCanHandle);
 #endif
 
     auto localStorageDirectory = m_websiteDataStore ? m_websiteDataStore->resolvedLocalStorageDirectory() : nullString();
@@ -924,7 +921,8 @@ void WebProcessPool::initializeNewWebProcess(WebProcessProxy& process, WebsiteDa
     parameters.urlSchemesRegisteredAsCORSEnabled = copyToVector(m_schemesToRegisterAsCORSEnabled);
     parameters.urlSchemesRegisteredAsAlwaysRevalidated = copyToVector(m_schemesToRegisterAsAlwaysRevalidated);
     parameters.urlSchemesRegisteredAsCachePartitioned = copyToVector(m_schemesToRegisterAsCachePartitioned);
-    parameters.urlSchemesServiceWorkersCanHandle = copyToVector(m_schemesServiceWorkersCanHandle);
+    if (websiteDataStore)
+        parameters.urlSchemesServiceWorkersCanHandle = copyToVector(websiteDataStore->configuration().serviceWorkerRegisteredSchemes());
     parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest = copyToVector(m_schemesToRegisterAsCanDisplayOnlyIfCanRequest);
 
     parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath;
@@ -1536,14 +1534,6 @@ void WebProcessPool::registerURLSchemeAsCachePartitioned(const String& urlScheme
     sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCachePartitioned(urlScheme));
 }
 
-void WebProcessPool::registerURLSchemeServiceWorkersCanHandle(const String& urlScheme)
-{
-    m_schemesServiceWorkersCanHandle.add(urlScheme);
-    sendToAllProcesses(Messages::AuxiliaryProcess::RegisterURLSchemeServiceWorkersCanHandle(urlScheme));
-    if (m_networkProcess)
-        m_networkProcess->send(Messages::AuxiliaryProcess::RegisterURLSchemeServiceWorkersCanHandle(urlScheme), 0);
-}
-
 void WebProcessPool::registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String& urlScheme)
 {
     m_schemesToRegisterAsCanDisplayOnlyIfCanRequest.add(urlScheme);
index 021014e..612e392 100644 (file)
@@ -272,7 +272,6 @@ public:
     void registerURLSchemeAsDisplayIsolated(const String&);
     void registerURLSchemeAsCORSEnabled(const String&);
     void registerURLSchemeAsCachePartitioned(const String&);
-    void registerURLSchemeServiceWorkersCanHandle(const String&);
     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&);
 
     VisitedLinkStore& visitedLinkStore() { return m_visitedLinkStore.get(); }
@@ -650,7 +649,6 @@ private:
     HashSet<String> m_schemesToRegisterAsCORSEnabled;
     HashSet<String> m_schemesToRegisterAsAlwaysRevalidated;
     HashSet<String> m_schemesToRegisterAsCachePartitioned;
-    HashSet<String> m_schemesServiceWorkersCanHandle;
     HashSet<String> m_schemesToRegisterAsCanDisplayOnlyIfCanRequest;
 
     bool m_alwaysUsesComplexTextCodePath { false };
index 8c2416d..58d1f90 100644 (file)
@@ -180,6 +180,7 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
     if (!parameters.serviceWorkerRegistrationDirectory.isEmpty())
         SandboxExtension::createHandleForReadWriteDirectory(parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
     parameters.serviceWorkerProcessTerminationDelayEnabled = m_configuration->serviceWorkerProcessTerminationDelayEnabled();
+    parameters.serviceWorkerRegisteredSchemes = m_configuration->serviceWorkerRegisteredSchemes();
 #endif
 
     parameters.localStorageDirectory = resolvedLocalStorageDirectory();
index 5475874..f9b9ed5 100644 (file)
@@ -54,6 +54,7 @@ Ref<WebsiteDataStoreConfiguration> WebsiteDataStoreConfiguration::copy()
     auto copy = WebsiteDataStoreConfiguration::create(m_isPersistent);
 
     copy->m_serviceWorkerProcessTerminationDelayEnabled = this->m_serviceWorkerProcessTerminationDelayEnabled;
+    copy->m_serviceWorkerRegisteredSchemes = this->m_serviceWorkerRegisteredSchemes;
     copy->m_fastServerTrustEvaluationEnabled = this->m_fastServerTrustEvaluationEnabled;
     copy->m_networkCacheSpeculativeValidationEnabled = this->m_networkCacheSpeculativeValidationEnabled;
     copy->m_cacheStorageDirectory = this->m_cacheStorageDirectory;
index 84caaf7..20525e6 100644 (file)
@@ -117,6 +117,9 @@ public:
     bool serviceWorkerProcessTerminationDelayEnabled() const { return m_serviceWorkerProcessTerminationDelayEnabled; }
     void setServiceWorkerProcessTerminationDelayEnabled(bool enabled) { m_serviceWorkerProcessTerminationDelayEnabled = enabled; }
 
+    const HashSet<String> serviceWorkerRegisteredSchemes() const { return m_serviceWorkerRegisteredSchemes; }
+    void registerServiceWorkerScheme(String&& scheme) { m_serviceWorkerRegisteredSchemes.add(scheme); }
+    
     const String& sourceApplicationBundleIdentifier() const { return m_sourceApplicationBundleIdentifier; }
     void setSourceApplicationBundleIdentifier(String&& identifier) { m_sourceApplicationBundleIdentifier = WTFMove(identifier); }
 
@@ -179,6 +182,7 @@ private:
     bool m_testingSessionEnabled { false };
     bool m_suppressesConnectionTerminationOnSystemChange { false };
     unsigned m_testSpeedMultiplier { 1 };
+    HashSet<String> m_serviceWorkerRegisteredSchemes;
 #if PLATFORM(COCOA)
     RetainPtr<CFDictionaryRef> m_proxyConfiguration;
 #endif
index 7e45843..e9af2c7 100644 (file)
@@ -379,7 +379,7 @@ void WebProcess::initializeWebProcess(WebProcessCreationParameters&& parameters)
         registerURLSchemeAsCachePartitioned(scheme);
 
     for (auto& scheme : parameters.urlSchemesServiceWorkersCanHandle)
-        registerURLSchemeServiceWorkersCanHandle(scheme);
+        WebCore::SchemeRegistry::registerURLSchemeServiceWorkersCanHandle(scheme);
 
     for (auto& scheme : parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest)
         registerURLSchemeAsCanDisplayOnlyIfCanRequest(scheme);
index 177541b..610c4ba 100644 (file)
@@ -1,5 +1,15 @@
 2019-10-04  Alex Christensen  <achristensen@webkit.org>
 
+        Move WKProcessPool._registerURLSchemeServiceWorkersCanHandle to _WKWebsiteDataStoreConfiguration
+        https://bugs.webkit.org/show_bug.cgi?id=202553
+
+        Reviewed by Youenn Fablet.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/StorageQuota.mm:
+
+2019-10-04  Alex Christensen  <achristensen@webkit.org>
+
         Simplify sandbox enabling macros
         https://bugs.webkit.org/show_bug.cgi?id=202536
 
index 9cca702..57004bf 100644 (file)
@@ -26,6 +26,7 @@
 #import "config.h"
 
 #import "PlatformUtilities.h"
+#import "TCPServer.h"
 #import "Test.h"
 #import "TestNavigationDelegate.h"
 #import "TestWKWebView.h"
@@ -469,6 +470,13 @@ self.addEventListener("message", (event) => {
 
 )SWRESOURCE";
 
+static WKWebsiteDataStore *dataStoreWithRegisteredServiceWorkerScheme(NSString *scheme)
+{
+    _WKWebsiteDataStoreConfiguration *configuration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
+    [configuration registerURLSchemeServiceWorkersCanHandleForTesting:scheme];
+    return [[[WKWebsiteDataStore alloc] _initWithConfiguration:configuration] autorelease];
+}
+
 TEST(ServiceWorkers, Basic)
 {
     ASSERT(mainBytes);
@@ -476,14 +484,17 @@ TEST(ServiceWorkers, Basic)
 
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+    
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
-    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -494,7 +505,6 @@ TEST(ServiceWorkers, Basic)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -504,7 +514,7 @@ TEST(ServiceWorkers, Basic)
 
     webView = nullptr;
 
-    [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeServiceWorkerRegistrations] completionHandler:^(NSArray<WKWebsiteDataRecord *> *websiteDataRecords) {
+    [dataStore fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeServiceWorkerRegistrations] completionHandler:^(NSArray<WKWebsiteDataRecord *> *websiteDataRecords) {
         EXPECT_EQ(1u, [websiteDataRecords count]);
         EXPECT_TRUE([websiteDataRecords[0].displayName isEqualToString:@"sw host"]);
 
@@ -515,6 +525,57 @@ TEST(ServiceWorkers, Basic)
     done = false;
 }
 
+TEST(ServiceWorkers, BasicDefaultSession)
+{
+    using namespace TestWebKitAPI;
+    TCPServer server([] (int socket) {
+        NSString *format = @"HTTP/1.1 200 OK\r\n"
+        "Content-Type: %s\r\n"
+        "Content-Length: %d\r\n\r\n"
+        "%s";
+        NSString *firstResponse = [NSString stringWithFormat:format, "text/html", strlen(mainBytes), mainBytes];
+        NSString *secondResponse = [NSString stringWithFormat:format, "application/javascript", strlen(scriptBytes), scriptBytes];
+
+        TCPServer::read(socket);
+        TCPServer::write(socket, firstResponse.UTF8String, firstResponse.length);
+        TCPServer::read(socket);
+        TCPServer::write(socket, secondResponse.UTF8String, secondResponse.length);
+    });
+
+    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
+
+    // Start with a clean slate data store
+    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    auto messageHandler = adoptNS([[SWMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    webView = nullptr;
+
+    [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeServiceWorkerRegistrations] completionHandler:^(NSArray<WKWebsiteDataRecord *> *websiteDataRecords) {
+        EXPECT_EQ(1u, [websiteDataRecords count]);
+        EXPECT_WK_STREQ(websiteDataRecords[0].displayName, "127.0.0.1");
+
+        done = true;
+    }];
+
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+}
+
 @interface SWCustomUserAgentDelegate : NSObject <WKNavigationDelegate> {
     NSString *_userAgent;
 }
@@ -576,14 +637,17 @@ TEST(ServiceWorkers, UserAgentOverride)
 {
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     auto messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] initWithExpectedMessage:@"Message from worker: Foo Custom UserAgent"]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -595,7 +659,6 @@ TEST(ServiceWorkers, UserAgentOverride)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     auto delegate = adoptNS([[SWCustomUserAgentDelegate alloc] initWithUserAgent:@"Foo Custom UserAgent"]);
     [webView setNavigationDelegate:delegate.get()];
@@ -614,6 +677,7 @@ TEST(ServiceWorkers, UserAgentOverride)
     configuration = nullptr;
 
     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] initWithExpectedMessage:@"Message from worker: Bar Custom UserAgent"]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -625,7 +689,6 @@ TEST(ServiceWorkers, UserAgentOverride)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     delegate = adoptNS([[SWCustomUserAgentDelegate alloc] initWithUserAgent:@"Bar Custom UserAgent"]);
     [webView setNavigationDelegate:delegate.get()];
@@ -645,14 +708,17 @@ TEST(ServiceWorkers, RestoreFromDisk)
 
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+    
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
-    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     RetainPtr<SWMessageHandlerForRestoreFromDiskTest> messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"PASS: Registration was successful and service worker was activated"]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -663,7 +729,6 @@ TEST(ServiceWorkers, RestoreFromDisk)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -678,6 +743,7 @@ TEST(ServiceWorkers, RestoreFromDisk)
     done = false;
 
     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
     messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"PASS: Registration already has an active worker"]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
 
@@ -687,7 +753,6 @@ TEST(ServiceWorkers, RestoreFromDisk)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -701,8 +766,10 @@ TEST(ServiceWorkers, CacheStorageRestoreFromDisk)
     ASSERT(mainCacheStorageBytes);
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+    
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
 
@@ -715,13 +782,13 @@ TEST(ServiceWorkers, CacheStorageRestoreFromDisk)
     handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainCacheStorageBytes });
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
     auto messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"No cache storage data"]);
 
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     // Trigger creation of network process.
     [webView.get().configuration.processPool _syncNetworkProcessCookies];
@@ -737,13 +804,13 @@ TEST(ServiceWorkers, CacheStorageRestoreFromDisk)
     messageHandler = nullptr;
 
     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
     messageHandler = adoptNS([[SWMessageHandlerForRestoreFromDiskTest alloc] initWithExpectedMessage:@"Some cache storage data: my cache"]);
 
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -760,14 +827,17 @@ TEST(ServiceWorkers, FetchAfterRestoreFromDisk)
 
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+    
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     RetainPtr<SWMessageHandlerForFetchTest> messageHandler = adoptNS([[SWMessageHandlerForFetchTest alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -779,7 +849,6 @@ TEST(ServiceWorkers, FetchAfterRestoreFromDisk)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -794,6 +863,7 @@ TEST(ServiceWorkers, FetchAfterRestoreFromDisk)
     done = false;
 
     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
     messageHandler = adoptNS([[SWMessageHandlerForFetchTest alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
 
@@ -804,7 +874,6 @@ TEST(ServiceWorkers, FetchAfterRestoreFromDisk)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -820,14 +889,17 @@ TEST(ServiceWorkers, InterceptFirstLoadAfterRestoreFromDisk)
 
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     RetainPtr<SWMessageHandlerWithExpectedMessage> messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -838,7 +910,6 @@ TEST(ServiceWorkers, InterceptFirstLoadAfterRestoreFromDisk)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     expectedMessage = "Service Worker activated";
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
@@ -854,6 +925,7 @@ TEST(ServiceWorkers, InterceptFirstLoadAfterRestoreFromDisk)
     done = false;
 
     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
     messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
 
@@ -863,7 +935,6 @@ TEST(ServiceWorkers, InterceptFirstLoadAfterRestoreFromDisk)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     expectedMessage = "Intercepted by worker";
     request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
@@ -877,14 +948,17 @@ TEST(ServiceWorkers, WaitForPolicyDelegate)
 {
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     RetainPtr<SWMessageHandlerWithExpectedMessage> messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -895,7 +969,6 @@ TEST(ServiceWorkers, WaitForPolicyDelegate)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     // Register a service worker and activate it.
     expectedMessage = "Service Worker activated";
@@ -912,6 +985,7 @@ TEST(ServiceWorkers, WaitForPolicyDelegate)
     done = false;
 
     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
     messageHandler = adoptNS([[SWMessageHandlerWithExpectedMessage alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
 
@@ -921,7 +995,6 @@ TEST(ServiceWorkers, WaitForPolicyDelegate)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     // Verify service worker is intercepting load.
     expectedMessage = "Intercepted by worker";
@@ -932,7 +1005,6 @@ TEST(ServiceWorkers, WaitForPolicyDelegate)
     done = false;
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     auto delegate = adoptNS([[TestSWAsyncNavigationDelegate alloc] init]);
     [webView setNavigationDelegate:delegate.get()];
     [webView setUIDelegate:delegate.get()];
@@ -949,7 +1021,6 @@ TEST(ServiceWorkers, WaitForPolicyDelegate)
     EXPECT_FALSE(navigationFailed);
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     [webView setNavigationDelegate:delegate.get()];
     [webView setUIDelegate:delegate.get()];
 
@@ -970,8 +1041,7 @@ void setConfigurationInjectedBundlePath(WKWebViewConfiguration* configuration)
 {
     WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
     configuration.processPool = (WKProcessPool *)context.get();
-    auto pool = configuration.processPool;
-    [pool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
+    configuration.websiteDataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
 }
 
 @interface RegularPageMessageHandler : NSObject <WKScriptMessageHandler>
@@ -1333,8 +1403,9 @@ TEST(ServiceWorkers, CacheStorageInPrivateBrowsingMode)
     handler->resources.set("sw://host/writeCache.html", ResourceInfo { @"text/html", writeCacheBytes });
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
-    configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
-    [configuration.get().processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
+    _WKWebsiteDataStoreConfiguration *dataStoreConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease];
+    [dataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];
+    configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration] autorelease];
 
     auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     auto *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/writeCache.html"]];
@@ -1388,15 +1459,20 @@ TEST(ServiceWorkers, ServiceWorkerCacheAccessEphemeralSession)
 {
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+    
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
     
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
-    setConfigurationInjectedBundlePath(configuration.get());
+
+    auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+    [configuration setProcessPool:(WKProcessPool *)context.get()];
+    [configuration setWebsiteDataStore:dataStore];
     
     auto defaultPreferences = [configuration preferences];
     [defaultPreferences _setSecureContextChecksEnabled:NO];
@@ -1417,7 +1493,9 @@ TEST(ServiceWorkers, ServiceWorkerCacheAccessEphemeralSession)
     }];
     TestWebKitAPI::Util::run(&openedCache);
 
-    configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+    _WKWebsiteDataStoreConfiguration *nonPersistentConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease];
+    [nonPersistentConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];
+    configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:nonPersistentConfiguration] autorelease];
 
     auto messageHandler = adoptNS([[SWMessageHandlerForCacheStorage alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -1543,7 +1621,10 @@ TEST(ServiceWorkers, ServiceWorkerAndCacheStorageDefaultDirectories)
 
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
     setConfigurationInjectedBundlePath(configuration.get());
 
     RetainPtr<DirectoryPageMessageHandler> directoryPageMessageHandler = adoptNS([[DirectoryPageMessageHandler alloc] init]);
@@ -1565,7 +1646,6 @@ TEST(ServiceWorkers, ServiceWorkerAndCacheStorageDefaultDirectories)
         TestWebKitAPI::Util::spinRunLoop(0.1);
 
     webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageGrabbingCacheStorageDirectory.html"]];
     [webView loadRequest:request];
@@ -1588,7 +1668,10 @@ TEST(ServiceWorkers, ServiceWorkerAndCacheStorageSpecificDirectories)
     [WKWebsiteDataStore defaultDataStore];
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     setConfigurationInjectedBundlePath(configuration.get());
@@ -1606,7 +1689,6 @@ TEST(ServiceWorkers, ServiceWorkerAndCacheStorageSpecificDirectories)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -1647,6 +1729,7 @@ TEST(ServiceWorkers, NonDefaultSessionID)
     RetainPtr<_WKWebsiteDataStoreConfiguration> websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
     websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = serviceWorkersPath;
     websiteDataStoreConfiguration.get()._indexedDBDatabaseDirectory = idbPath;
+    [websiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];
 
     configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()] autorelease];
 
@@ -1660,7 +1743,6 @@ TEST(ServiceWorkers, NonDefaultSessionID)
 
     expectedMessage = "PASS: activation successful";
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]];
     [webView loadRequest:request];
@@ -1704,6 +1786,9 @@ TEST(ServiceWorkers, ProcessPerSite)
     // Disable this delay for the purpose of testing.
     _WKWebsiteDataStoreConfiguration *dataStoreConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
     dataStoreConfiguration.serviceWorkerProcessTerminationDelayEnabled = NO;
+    [dataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw1"];
+    [dataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw2"];
+
     auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration]);
     
     // Start with a clean slate data store
@@ -1732,8 +1817,6 @@ TEST(ServiceWorkers, ProcessPerSite)
     [configuration setURLSchemeHandler:handler2.get() forURLScheme:@"sw2"];
 
     WKProcessPool *processPool = configuration.get().processPool;
-    [processPool _registerURLSchemeServiceWorkersCanHandle:@"sw1"];
-    [processPool _registerURLSchemeServiceWorkersCanHandle:@"sw2"];
 
     RetainPtr<WKWebView> webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
@@ -1791,14 +1874,17 @@ TEST(ServiceWorkers, ParallelProcessLaunch)
 {
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw1");
+
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     auto messageHandler = adoptNS([[SWMessageHandler alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -1811,7 +1897,6 @@ TEST(ServiceWorkers, ParallelProcessLaunch)
     [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"sw1"];
 
     auto *processPool = configuration.get().processPool;
-    [processPool _registerURLSchemeServiceWorkersCanHandle:@"sw1"];
 
     auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     NSURLRequest *request1 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host/main.html"]];
@@ -1832,8 +1917,10 @@ TEST(ServiceWorkers, ThrottleCrash)
 
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw1");
+
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
@@ -1851,6 +1938,7 @@ TEST(ServiceWorkers, ThrottleCrash)
     }];
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 #if PLATFORM(MAC)
     [[configuration preferences] _setAppNapEnabled:YES];
 #endif
@@ -1858,7 +1946,6 @@ TEST(ServiceWorkers, ThrottleCrash)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"sw1"];
 
     auto *processPool = configuration.get().processPool;
-    [processPool _registerURLSchemeServiceWorkersCanHandle:@"sw1"];
 
     auto webView1 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow: YES]);
     [webView1 setNavigationDelegate:navigationDelegate.get()];
@@ -1880,6 +1967,7 @@ TEST(ServiceWorkers, ThrottleCrash)
     [[webView2Configuration preferences] _setAppNapEnabled:NO];
 #endif
     [webView2Configuration setProcessPool:processPool];
+    [webView2Configuration setWebsiteDataStore:dataStore];
     [[webView2Configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     [webView2Configuration setURLSchemeHandler:handler.get() forURLScheme:@"sw1"];
     webView2Configuration.get()._relatedWebView = webView1.get();
@@ -1900,14 +1988,17 @@ TEST(ServiceWorkers, LoadData)
 
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -1918,7 +2009,6 @@ TEST(ServiceWorkers, LoadData)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     auto delegate = adoptNS([[TestSWAsyncNavigationDelegate alloc] init]);
     [webView setNavigationDelegate:delegate.get()];
@@ -1963,6 +2053,7 @@ TEST(ServiceWorkers, RestoreFromDiskNonDefaultStore)
 
         auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
         websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = swDBPath;
+        [websiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];
         auto nonDefaultDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
         configuration.get().websiteDataStore = nonDefaultDataStore.get();
 
@@ -1975,7 +2066,6 @@ TEST(ServiceWorkers, RestoreFromDiskNonDefaultStore)
         [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
         auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-        [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
         protectedProcessPool = webView.get().configuration.processPool;
 
         [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]];
@@ -1991,6 +2081,7 @@ TEST(ServiceWorkers, RestoreFromDiskNonDefaultStore)
 
         auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
         websiteDataStoreConfiguration.get()._serviceWorkerRegistrationDirectory = swDBPath;
+        [websiteDataStoreConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw"];
         auto nonDefaultDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()]);
         configuration.get().websiteDataStore = nonDefaultDataStore.get();
 
@@ -2003,7 +2094,6 @@ TEST(ServiceWorkers, RestoreFromDiskNonDefaultStore)
         [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
         auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-        [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
         [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]];
 
@@ -2016,14 +2106,17 @@ TEST(ServiceWorkers, SuspendNetworkProcess)
 {
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw");
+    
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -2034,7 +2127,6 @@ TEST(ServiceWorkers, SuspendNetworkProcess)
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-    [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
 
     auto delegate = adoptNS([[TestSWAsyncNavigationDelegate alloc] init]);
     [webView setNavigationDelegate:delegate.get()];
@@ -2101,14 +2193,17 @@ TEST(ServiceWorkers, ProcessPerSession)
 {
     [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
 
+    auto* dataStore = dataStoreWithRegisteredServiceWorkerScheme(@"sw1");
+    
     // Start with a clean slate data store
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
     done = false;
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     auto messageHandler = adoptNS([[SWMessageHandler alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
@@ -2121,11 +2216,10 @@ TEST(ServiceWorkers, ProcessPerSession)
     [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"sw1"];
 
     WKProcessPool *processPool = configuration.get().processPool;
-    [processPool _registerURLSchemeServiceWorkersCanHandle:@"sw1"];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw1://host/main.html"]];
 
-    configuration.get().websiteDataStore = [WKWebsiteDataStore defaultDataStore];
+    configuration.get().websiteDataStore = dataStore;
 
     auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     [webView1 loadRequest:request];
@@ -2134,7 +2228,9 @@ TEST(ServiceWorkers, ProcessPerSession)
 
     EXPECT_EQ(1U, processPool._serviceWorkerProcessCount);
 
-    configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+    _WKWebsiteDataStoreConfiguration *nonPersistentConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration] autorelease];
+    [nonPersistentConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"sw1"];
+    configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:nonPersistentConfiguration] autorelease];
 
     auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     [webView2 loadRequest:request];
index a694071..6bb7e96 100644 (file)
@@ -227,6 +227,8 @@ TEST(WebKit, QuotaDelegate)
     done = false;
     _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
     storeConfiguration.perOriginStorageQuota = 1024 * 400;
+    [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt1"];
+    [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt2"];
     WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease];
     [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
@@ -242,12 +244,10 @@ TEST(WebKit, QuotaDelegate)
     auto handler1 = adoptNS([[StorageSchemes alloc] init]);
     handler1->resources.set("qt1://test1.html", ResourceInfo { @"text/html", TestBytes });
     [configuration setURLSchemeHandler:handler1.get() forURLScheme:@"QT1"];
-    [configuration.get().processPool _registerURLSchemeServiceWorkersCanHandle:@"qt1"];
 
     auto handler2 = adoptNS([[StorageSchemes alloc] init]);
     handler2->resources.set("qt2://test2.html", ResourceInfo { @"text/html", TestBytes });
     [configuration setURLSchemeHandler:handler2.get() forURLScheme:@"QT2"];
-    [configuration.get().processPool _registerURLSchemeServiceWorkersCanHandle:@"qt2"];
 
     auto webView1 = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]);
     auto delegate1 = adoptNS([[QuotaDelegate alloc] init]);
@@ -290,6 +290,7 @@ TEST(WebKit, QuotaDelegateReload)
     done = false;
     _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
     storeConfiguration.perOriginStorageQuota = 1024 * 400;
+    [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt"];
     WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease];
     [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
@@ -305,7 +306,6 @@ TEST(WebKit, QuotaDelegateReload)
     auto handler = adoptNS([[StorageSchemes alloc] init]);
     handler->resources.set("qt://test1.html", ResourceInfo { @"text/html", TestBytes });
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"QT"];
-    [configuration.get().processPool _registerURLSchemeServiceWorkersCanHandle:@"qt"];
     
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]);
     auto delegate = adoptNS([[QuotaDelegate alloc] init]);
@@ -337,6 +337,7 @@ TEST(WebKit, QuotaDelegateNavigateFragment)
 {
     done = false;
     _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
+    [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt"];
     storeConfiguration.perOriginStorageQuota = 1024 * 400;
     WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease];
     [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
@@ -353,7 +354,6 @@ TEST(WebKit, QuotaDelegateNavigateFragment)
     auto handler = adoptNS([[StorageSchemes alloc] init]);
     handler->resources.set("qt://test1.html", ResourceInfo { @"text/html", TestBytes });
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"QT"];
-    [configuration.get().processPool _registerURLSchemeServiceWorkersCanHandle:@"qt"];
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]);
     auto delegate = adoptNS([[QuotaDelegate alloc] init]);
@@ -388,12 +388,17 @@ TEST(WebKit, QuotaDelegateNavigateFragment)
 TEST(WebKit, DefaultQuota)
 {
     done = false;
-    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+    _WKWebsiteDataStoreConfiguration *storeConfiguration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
+    [storeConfiguration registerURLSchemeServiceWorkersCanHandleForTesting:@"qt"];
+    WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration] autorelease];
+
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
 
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setWebsiteDataStore:dataStore];
 
     auto messageHandler = adoptNS([[QuotaMessageHandler alloc] init]);
     [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"qt"];
@@ -401,7 +406,6 @@ TEST(WebKit, DefaultQuota)
     auto handler = adoptNS([[StorageSchemes alloc] init]);
     handler->resources.set("qt://test1.html", ResourceInfo { @"text/html", TestUrlBytes });
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"QT"];
-    [configuration.get().processPool _registerURLSchemeServiceWorkersCanHandle:@"qt"];
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get() addToWindow:YES]);
     auto delegate = adoptNS([[QuotaDelegate alloc] init]);