Title: [227161] trunk/Source
Revision
227161
Author
[email protected]
Date
2018-01-18 13:12:55 -0800 (Thu, 18 Jan 2018)

Log Message

Do not go to the storage process when loading a main resource if there is no service worker registered
https://bugs.webkit.org/show_bug.cgi?id=181395

Patch by Youenn Fablet <[email protected]> on 2018-01-18
Reviewed by Chris Dumez.

Source/WebCore:

No observable behavior change.
Instead of creating a connection to know whether there is a potential service worker,
Ask the service worker provider that will use the connection if needed.
Otherwise, it will use a default value provided by the UIProcess.

Tested by cleaning all service workers and checking the computed value of the default value,
then observing whether pages registering service workers work well.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::startLoadingMainResource):
* workers/service/ServiceWorkerProvider.cpp:
(WebCore::ServiceWorkerProvider::mayHaveServiceWorkerRegisteredForOrigin):
* workers/service/ServiceWorkerProvider.h:

Source/WebKit:

Add a new web process creation parameter to know whether there is any service worker registered at web process creation time.
If there is none, the web process will then start to load HTTP resources from the network.
The connection to the storage process is then executed when receiving the first bytes of the main resource.
This connection is needed as other web processes may create service workers at any given time.
If there is one registered service worker, the web process will wait for its connection to the storage process to be active.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/ServiceWorkerProcessProxy.cpp:
(WebKit::ServiceWorkerProcessProxy::hasRegisteredServiceWorkers):
* UIProcess/ServiceWorkerProcessProxy.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::initializeNewWebProcess):
* WebProcess/Storage/WebServiceWorkerProvider.cpp:
(WebKit::WebServiceWorkerProvider::existingServiceWorkerConnectionForSession):
* WebProcess/Storage/WebServiceWorkerProvider.h:
* WebProcess/Storage/WebToStorageProcessConnection.h:
(WebKit::WebToStorageProcessConnection::existingServiceWorkerConnectionForSession):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (227160 => 227161)


--- trunk/Source/WebCore/ChangeLog	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebCore/ChangeLog	2018-01-18 21:12:55 UTC (rev 227161)
@@ -1,3 +1,24 @@
+2018-01-18  Youenn Fablet  <[email protected]>
+
+        Do not go to the storage process when loading a main resource if there is no service worker registered
+        https://bugs.webkit.org/show_bug.cgi?id=181395
+
+        Reviewed by Chris Dumez.
+
+        No observable behavior change.
+        Instead of creating a connection to know whether there is a potential service worker,
+        Ask the service worker provider that will use the connection if needed.
+        Otherwise, it will use a default value provided by the UIProcess.
+
+        Tested by cleaning all service workers and checking the computed value of the default value,
+        then observing whether pages registering service workers work well.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::startLoadingMainResource):
+        * workers/service/ServiceWorkerProvider.cpp:
+        (WebCore::ServiceWorkerProvider::mayHaveServiceWorkerRegisteredForOrigin):
+        * workers/service/ServiceWorkerProvider.h:
+
 2018-01-18  Dan Bernstein  <[email protected]>
 
         [Xcode] Streamline and future-proof target-macOS-version-dependent build setting definitions

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (227160 => 227161)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -1589,8 +1589,10 @@
         auto tryLoadingThroughServiceWorker = !frameLoader()->isReloadingFromOrigin() && m_frame->page() && RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled() && SchemeRegistry::canServiceWorkersHandleURLScheme(request.url().protocol().toStringWithoutCopying());
         if (tryLoadingThroughServiceWorker) {
             auto origin = (!m_frame->isMainFrame() && m_frame->document()) ? makeRef(m_frame->document()->topOrigin()) : SecurityOrigin::create(request.url());
-            auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(m_frame->page()->sessionID());
-            if (connection.mayHaveServiceWorkerRegisteredForOrigin(origin)) {
+            auto sessionID = m_frame->page()->sessionID();
+            auto& provider = ServiceWorkerProvider::singleton();
+            if (provider.mayHaveServiceWorkerRegisteredForOrigin(sessionID, origin)) {
+                auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(sessionID);
                 auto url = ""
                 connection.matchRegistration(origin, url, [request = WTFMove(request), protectedThis = WTFMove(protectedThis), this] (auto&& registrationData) mutable {
                     if (!m_mainDocumentError.isNull() || !m_frame)

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerProvider.cpp (227160 => 227161)


--- trunk/Source/WebCore/workers/service/ServiceWorkerProvider.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerProvider.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -43,6 +43,15 @@
     sharedProvider = &newProvider;
 }
 
+bool ServiceWorkerProvider::mayHaveServiceWorkerRegisteredForOrigin(PAL::SessionID sessionID, const WebCore::SecurityOrigin& origin)
+{
+    auto* connection = existingServiceWorkerConnectionForSession(sessionID);
+    if (!connection)
+        return m_hasRegisteredServiceWorkers;
+
+    return connection->mayHaveServiceWorkerRegisteredForOrigin(origin);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerProvider.h (227160 => 227161)


--- trunk/Source/WebCore/workers/service/ServiceWorkerProvider.h	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerProvider.h	2018-01-18 21:12:55 UTC (rev 227161)
@@ -43,7 +43,14 @@
     WEBCORE_EXPORT static ServiceWorkerProvider& singleton();
     WEBCORE_EXPORT static void setSharedProvider(ServiceWorkerProvider&);
 
+    bool mayHaveServiceWorkerRegisteredForOrigin(PAL::SessionID, const WebCore::SecurityOrigin&);
+    virtual SWClientConnection* existingServiceWorkerConnectionForSession(PAL::SessionID) = 0;
     virtual SWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID) = 0;
+
+    void setHasRegisteredServiceWorkers(bool value) { m_hasRegisteredServiceWorkers = value; }
+
+private:
+    bool m_hasRegisteredServiceWorkers { true };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp (227160 => 227161)


--- trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -74,6 +74,11 @@
     return filename;
 }
 
+String serviceWorkerRegistrationDatabaseFilename(const String& databaseDirectory)
+{
+    return FileSystem::pathByAppendingComponent(databaseDirectory, databaseFilename());
+}
+
 RegistrationDatabase::RegistrationDatabase(RegistrationStore& store, const String& databaseDirectory)
     : CrossThreadTaskHandler("ServiceWorker I/O Thread")
     , m_store(store)

Modified: trunk/Source/WebCore/workers/service/server/RegistrationDatabase.h (227160 => 227161)


--- trunk/Source/WebCore/workers/service/server/RegistrationDatabase.h	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebCore/workers/service/server/RegistrationDatabase.h	2018-01-18 21:12:55 UTC (rev 227161)
@@ -37,6 +37,8 @@
 class SQLiteDatabase;
 struct ServiceWorkerContextData;
 
+WEBCORE_EXPORT String serviceWorkerRegistrationDatabaseFilename(const String& databaseDirectory);
+
 class RegistrationDatabase : public CrossThreadTaskHandler {
 WTF_MAKE_FAST_ALLOCATED;
 public:

Modified: trunk/Source/WebKit/ChangeLog (227160 => 227161)


--- trunk/Source/WebKit/ChangeLog	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/ChangeLog	2018-01-18 21:12:55 UTC (rev 227161)
@@ -1,3 +1,33 @@
+2018-01-18  Youenn Fablet  <[email protected]>
+
+        Do not go to the storage process when loading a main resource if there is no service worker registered
+        https://bugs.webkit.org/show_bug.cgi?id=181395
+
+        Reviewed by Chris Dumez.
+
+        Add a new web process creation parameter to know whether there is any service worker registered at web process creation time.
+        If there is none, the web process will then start to load HTTP resources from the network.
+        The connection to the storage process is then executed when receiving the first bytes of the main resource.
+        This connection is needed as other web processes may create service workers at any given time.
+        If there is one registered service worker, the web process will wait for its connection to the storage process to be active.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/ServiceWorkerProcessProxy.cpp:
+        (WebKit::ServiceWorkerProcessProxy::hasRegisteredServiceWorkers):
+        * UIProcess/ServiceWorkerProcessProxy.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::initializeNewWebProcess):
+        * WebProcess/Storage/WebServiceWorkerProvider.cpp:
+        (WebKit::WebServiceWorkerProvider::existingServiceWorkerConnectionForSession):
+        * WebProcess/Storage/WebServiceWorkerProvider.h:
+        * WebProcess/Storage/WebToStorageProcessConnection.h:
+        (WebKit::WebToStorageProcessConnection::existingServiceWorkerConnectionForSession):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+
 2018-01-18  Chris Dumez  <[email protected]>
 
         Regression(r223149): WebProcessProxy::didClose() no longer refs WebPageProxy objects

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (227160 => 227161)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -127,6 +127,10 @@
     encoder << hasRichContentServices;
 #endif
 
+#if ENABLE(SERVICE_WORKER)
+    encoder << hasRegisteredServiceWorkers;
+#endif
+
 #if ENABLE(NETSCAPE_PLUGIN_API)
     encoder << pluginLoadClientPolicies;
 #endif
@@ -361,6 +365,11 @@
         return false;
 #endif
 
+#if ENABLE(SERVICE_WORKER)
+    if (!decoder.decode(parameters.hasRegisteredServiceWorkers))
+        return false;
+#endif
+
 #if ENABLE(NETSCAPE_PLUGIN_API)
     if (!decoder.decode(parameters.pluginLoadClientPolicies))
         return false;

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (227160 => 227161)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2018-01-18 21:12:55 UTC (rev 227161)
@@ -131,6 +131,10 @@
     bool hasRichContentServices { false };
 #endif
 
+#if ENABLE(SERVICE_WORKER)
+    bool hasRegisteredServiceWorkers { true };
+#endif
+
     Seconds terminationTimeout;
 
     TextCheckerState textCheckerState;

Modified: trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp (227160 => 227161)


--- trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -33,6 +33,7 @@
 #include "WebProcessPool.h"
 #include "WebSWContextManagerConnectionMessages.h"
 #include <WebCore/NotImplemented.h>
+#include <WebCore/RegistrationDatabase.h>
 
 namespace WebKit {
 
@@ -53,6 +54,12 @@
 {
 }
 
+bool ServiceWorkerProcessProxy::hasRegisteredServiceWorkers(const String& serviceWorkerDirectory)
+{
+    String registrationFile = WebCore::serviceWorkerRegistrationDatabaseFilename(serviceWorkerDirectory);
+    return WebCore::FileSystem::fileExists(registrationFile);
+}
+
 void ServiceWorkerProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions)
 {
     WebProcessProxy::getLaunchOptions(launchOptions);

Modified: trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h (227160 => 227161)


--- trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h	2018-01-18 21:12:55 UTC (rev 227161)
@@ -36,6 +36,8 @@
     static Ref<ServiceWorkerProcessProxy> create(WebProcessPool&, WebsiteDataStore&);
     ~ServiceWorkerProcessProxy();
 
+    static bool hasRegisteredServiceWorkers(const String& serviceWorkerDirectory);
+
     void didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, Ref<AuthenticationChallengeProxy>&&);
 
     void start(const WebPreferencesStore&, std::optional<PAL::SessionID> initialSessionID);

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (227160 => 227161)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -812,6 +812,10 @@
     serviceController.refreshExistingServices();
 #endif
 
+#if ENABLE(SERVICE_WORKER)
+    parameters.hasRegisteredServiceWorkers = ServiceWorkerProcessProxy::hasRegisteredServiceWorkers(m_configuration->serviceWorkerRegistrationDirectory());
+#endif
+
 #if ENABLE(NETSCAPE_PLUGIN_API)
     parameters.pluginLoadClientPolicies = m_pluginLoadClientPolicies;
 #endif

Modified: trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp (227160 => 227161)


--- trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -59,6 +59,11 @@
     return WebProcess::singleton().ensureWebToStorageProcessConnection(sessionID).serviceWorkerConnectionForSession(sessionID);
 }
 
+WebCore::SWClientConnection* WebServiceWorkerProvider::existingServiceWorkerConnectionForSession(SessionID sessionID)
+{
+    return WebProcess::singleton().ensureWebToStorageProcessConnection(sessionID).existingServiceWorkerConnectionForSession(sessionID);
+}
+
 static inline bool shouldHandleFetch(const ResourceLoaderOptions& options)
 {
     if (options.serviceWorkersMode == ServiceWorkersMode::None)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h (227160 => 227161)


--- trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h	2018-01-18 21:12:55 UTC (rev 227161)
@@ -52,6 +52,7 @@
     friend NeverDestroyed<WebServiceWorkerProvider>;
     WebServiceWorkerProvider();
 
+    WebCore::SWClientConnection* existingServiceWorkerConnectionForSession(PAL::SessionID) final;
     WebCore::SWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID) final;
 
     HashMap<uint64_t, Ref<ServiceWorkerClientFetch>> m_ongoingFetchTasks;

Modified: trunk/Source/WebKit/WebProcess/Storage/WebToStorageProcessConnection.h (227160 => 227161)


--- trunk/Source/WebKit/WebProcess/Storage/WebToStorageProcessConnection.h	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/WebProcess/Storage/WebToStorageProcessConnection.h	2018-01-18 21:12:55 UTC (rev 227161)
@@ -54,6 +54,7 @@
     WebIDBConnectionToServer& idbConnectionToServerForSession(PAL::SessionID);
 #endif
 #if ENABLE(SERVICE_WORKER)
+    WebSWClientConnection* existingServiceWorkerConnectionForSession(PAL::SessionID sessionID) { return m_swConnectionsBySession.get(sessionID); }
     WebSWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID);
 #endif
 

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (227160 => 227161)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-01-18 21:08:52 UTC (rev 227160)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-01-18 21:12:55 UTC (rev 227161)
@@ -417,7 +417,9 @@
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    ServiceWorkerProvider::setSharedProvider(WebServiceWorkerProvider::singleton());
+    auto& serviceWorkerProvider = WebServiceWorkerProvider::singleton();
+    serviceWorkerProvider.setHasRegisteredServiceWorkers(parameters.hasRegisteredServiceWorkers);
+    ServiceWorkerProvider::setSharedProvider(serviceWorkerProvider);
 #endif
 
 #if ENABLE(WEBASSEMBLY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to