Title: [228210] branches/safari-605-branch

Diff

Modified: branches/safari-605-branch/Source/WebCore/ChangeLog (228209 => 228210)


--- branches/safari-605-branch/Source/WebCore/ChangeLog	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebCore/ChangeLog	2018-02-07 02:45:09 UTC (rev 228210)
@@ -1,5 +1,24 @@
 2018-02-06  Jason Marcell  <[email protected]>
 
+        Cherry-pick r228188. rdar://problem/37293107
+
+    2018-02-06  Youenn Fablet  <[email protected]>
+
+            HasServiceWorkerRegistration bit should be sent when creating a new page
+            https://bugs.webkit.org/show_bug.cgi?id=182410
+
+            Reviewed by Chris Dumez.
+
+            Covered by new API test.
+
+            Changed the default value of service workers being registered to false.
+            Every page created in the process will be responsible to change the value to true,
+            at which time the value will be kept to true for the lifetime of the process.
+
+            * workers/service/ServiceWorkerProvider.h:
+
+2018-02-06  Jason Marcell  <[email protected]>
+
         Cherry-pick r228195. rdar://problem/37292905
 
     2018-02-06  Andy Estes  <[email protected]>

Modified: branches/safari-605-branch/Source/WebCore/workers/service/ServiceWorkerProvider.cpp (228209 => 228210)


--- branches/safari-605-branch/Source/WebCore/workers/service/ServiceWorkerProvider.cpp	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebCore/workers/service/ServiceWorkerProvider.cpp	2018-02-07 02:45:09 UTC (rev 228210)
@@ -49,7 +49,7 @@
 {
     auto* connection = existingServiceWorkerConnectionForSession(sessionID);
     if (!connection)
-        return m_hasRegisteredServiceWorkers;
+        return m_mayHaveRegisteredServiceWorkers;
 
     return connection->mayHaveServiceWorkerRegisteredForOrigin(origin);
 }

Modified: branches/safari-605-branch/Source/WebCore/workers/service/ServiceWorkerProvider.h (228209 => 228210)


--- branches/safari-605-branch/Source/WebCore/workers/service/ServiceWorkerProvider.h	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebCore/workers/service/ServiceWorkerProvider.h	2018-02-07 02:45:09 UTC (rev 228210)
@@ -49,10 +49,10 @@
 
     WEBCORE_EXPORT void registerServiceWorkerClients(PAL::SessionID);
 
-    void setHasRegisteredServiceWorkers(bool value) { m_hasRegisteredServiceWorkers = value; }
+    void setMayHaveRegisteredServiceWorkers() { m_mayHaveRegisteredServiceWorkers = true; }
 
 private:
-    bool m_hasRegisteredServiceWorkers { true };
+    bool m_mayHaveRegisteredServiceWorkers { false };
 };
 
 } // namespace WebCore

Modified: branches/safari-605-branch/Source/WebKit/ChangeLog (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/ChangeLog	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/ChangeLog	2018-02-07 02:45:09 UTC (rev 228210)
@@ -1,5 +1,44 @@
 2018-02-06  Jason Marcell  <[email protected]>
 
+        Cherry-pick r228188. rdar://problem/37293107
+
+    2018-02-06  Youenn Fablet  <[email protected]>
+
+            HasServiceWorkerRegistration bit should be sent when creating a new page
+            https://bugs.webkit.org/show_bug.cgi?id=182410
+
+            Reviewed by Chris Dumez.
+
+            Move the bit computation at page creation time.
+            This allows computing the bit based on the web site data store and not only on the pool configuration.
+            WebPage uses that bit to activate service worker registration matching for the whole process.
+
+            In case there is a service worker process proxy created, the bit is set to true by default.
+
+            Bit is computed by checking for database file presence.
+            This information is cached in a map for efficiency reasons and cleared when a service worker process proxy is created.
+
+            * Shared/WebPageCreationParameters.cpp:
+            (WebKit::WebPageCreationParameters::encode const):
+            (WebKit::WebPageCreationParameters::decode):
+            * Shared/WebPageCreationParameters.h:
+            * Shared/WebProcessCreationParameters.cpp:
+            (WebKit::WebProcessCreationParameters::encode const):
+            (WebKit::WebProcessCreationParameters::decode):
+            * Shared/WebProcessCreationParameters.h:
+            * UIProcess/WebPageProxy.cpp:
+            (WebKit::WebPageProxy::initializeWebPage):
+            * UIProcess/WebProcessPool.cpp:
+            (WebKit::WebProcessPool::establishWorkerContextConnectionToStorageProcess):
+            (WebKit::WebProcessPool::initializeNewWebProcess):
+            (WebKit::WebProcessPool::mayHaveRegisteredServiceWorkers):
+            * WebProcess/WebPage/WebPage.cpp:
+            (WebKit::m_cpuLimit):
+            * WebProcess/WebProcess.cpp:
+            (WebKit::WebProcess::initializeWebProcess):
+
+2018-02-06  Jason Marcell  <[email protected]>
+
         Cherry-pick r228152. rdar://problem/37293023
 
     2018-02-05  Chris Dumez  <[email protected]>

Modified: branches/safari-605-branch/Source/WebKit/Shared/WebPageCreationParameters.cpp (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/Shared/WebPageCreationParameters.cpp	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/Shared/WebPageCreationParameters.cpp	2018-02-07 02:45:09 UTC (rev 228210)
@@ -103,6 +103,9 @@
 #if ENABLE(APPLICATION_MANIFEST)
     encoder << applicationManifest;
 #endif
+#if ENABLE(SERVICE_WORKER)
+    encoder << hasRegisteredServiceWorkers;
+#endif
     encoder << iceCandidateFilteringEnabled;
     encoder << enumeratingAllNetworkInterfacesEnabled;
     encoder << userContentWorlds;
@@ -279,6 +282,10 @@
         return std::nullopt;
     parameters.applicationManifest = WTFMove(*applicationManifest);
 #endif
+#if ENABLE(SERVICE_WORKER)
+    if (!decoder.decode(parameters.hasRegisteredServiceWorkers))
+        return std::nullopt;
+#endif
 
     if (!decoder.decode(parameters.iceCandidateFilteringEnabled))
         return std::nullopt;

Modified: branches/safari-605-branch/Source/WebKit/Shared/WebPageCreationParameters.h (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/Shared/WebPageCreationParameters.h	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/Shared/WebPageCreationParameters.h	2018-02-07 02:45:09 UTC (rev 228210)
@@ -165,6 +165,10 @@
     std::optional<WebCore::ApplicationManifest> applicationManifest;
 #endif
 
+#if ENABLE(SERVICE_WORKER)
+    bool hasRegisteredServiceWorkers { true };
+#endif
+
     // WebRTC members.
     bool iceCandidateFilteringEnabled { true };
     bool enumeratingAllNetworkInterfacesEnabled { false };

Modified: branches/safari-605-branch/Source/WebKit/Shared/WebProcessCreationParameters.cpp (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2018-02-07 02:45:09 UTC (rev 228210)
@@ -127,10 +127,6 @@
     encoder << hasRichContentServices;
 #endif
 
-#if ENABLE(SERVICE_WORKER)
-    encoder << hasRegisteredServiceWorkers;
-#endif
-
 #if ENABLE(NETSCAPE_PLUGIN_API)
     encoder << pluginLoadClientPolicies;
 #endif
@@ -362,11 +358,6 @@
         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: branches/safari-605-branch/Source/WebKit/Shared/WebProcessCreationParameters.h (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/Shared/WebProcessCreationParameters.h	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/Shared/WebProcessCreationParameters.h	2018-02-07 02:45:09 UTC (rev 228210)
@@ -131,10 +131,6 @@
     bool hasRichContentServices { false };
 #endif
 
-#if ENABLE(SERVICE_WORKER)
-    bool hasRegisteredServiceWorkers { true };
-#endif
-
     Seconds terminationTimeout;
 
     TextCheckerState textCheckerState;

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.cpp (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-02-07 02:45:09 UTC (rev 228210)
@@ -730,8 +730,14 @@
     }
 #endif
 
-    process().send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
+    auto parameters = creationParameters();
 
+#if ENABLE(SERVICE_WORKER)
+    parameters.hasRegisteredServiceWorkers = process().processPool().mayHaveRegisteredServiceWorkers(m_websiteDataStore);
+#endif
+
+    process().send(Messages::WebProcess::CreateWebPage(m_pageID, parameters), 0);
+
     m_needsToFinishInitializingWebPageAfterProcessLaunch = true;
     finishInitializingWebPageAfterProcessLaunch();
 }

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.cpp (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-02-07 02:45:09 UTC (rev 228210)
@@ -601,6 +601,8 @@
     if (m_serviceWorkerProcess)
         return;
 
+    m_mayHaveRegisteredServiceWorkers.clear();
+
     WebsiteDataStore* websiteDataStore = nullptr;
     if (sessionID)
         websiteDataStore = WebsiteDataStore::existingNonDefaultDataStoreForSessionID(*sessionID);
@@ -816,13 +818,6 @@
     serviceController.refreshExistingServices();
 #endif
 
-#if ENABLE(SERVICE_WORKER)
-    String serviceWorkerRegistrationDirectory = websiteDataStore.resolvedServiceWorkerRegistrationDirectory();
-    if (serviceWorkerRegistrationDirectory.isEmpty())
-        serviceWorkerRegistrationDirectory = API::WebsiteDataStore::defaultServiceWorkerRegistrationDirectory();
-    parameters.hasRegisteredServiceWorkers = ServiceWorkerProcessProxy::hasRegisteredServiceWorkers(serviceWorkerRegistrationDirectory);
-#endif
-
 #if ENABLE(NETSCAPE_PLUGIN_API)
     parameters.pluginLoadClientPolicies = m_pluginLoadClientPolicies;
 #endif
@@ -1054,6 +1049,21 @@
     if (m_serviceWorkerProcess)
         m_serviceWorkerProcess->setUserAgent(m_serviceWorkerUserAgent);
 }
+
+bool WebProcessPool::mayHaveRegisteredServiceWorkers(const WebsiteDataStore& store)
+{
+    if (serviceWorkerProxy())
+        return true;
+
+    String serviceWorkerRegistrationDirectory = store.resolvedServiceWorkerRegistrationDirectory();
+    if (serviceWorkerRegistrationDirectory.isEmpty())
+        serviceWorkerRegistrationDirectory = API::WebsiteDataStore::defaultDataStoreConfiguration().serviceWorkerRegistrationDirectory;
+
+    return m_mayHaveRegisteredServiceWorkers.ensure(serviceWorkerRegistrationDirectory, [&] {
+        // FIXME: Make this computation on a background thread.
+        return ServiceWorkerProcessProxy::hasRegisteredServiceWorkers(serviceWorkerRegistrationDirectory);
+    }).iterator->value;
+}
 #endif
 
 void WebProcessPool::pageBeginUsingWebsiteDataStore(WebPageProxy& page)

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.h (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.h	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/WebProcessPool.h	2018-02-07 02:45:09 UTC (rev 228210)
@@ -330,6 +330,7 @@
     void setAllowsAnySSLCertificateForServiceWorker(bool allows) { m_allowsAnySSLCertificateForServiceWorker = allows; }
     bool allowsAnySSLCertificateForServiceWorker() const { return m_allowsAnySSLCertificateForServiceWorker; }
     void updateServiceWorkerUserAgent(const String& userAgent);
+    bool mayHaveRegisteredServiceWorkers(const WebsiteDataStore&);
 #endif
 
 #if PLATFORM(COCOA)
@@ -505,6 +506,7 @@
     bool m_allowsAnySSLCertificateForServiceWorker { false };
     String m_serviceWorkerUserAgent;
     std::optional<WebPreferencesStore> m_serviceWorkerPreferences;
+    HashMap<String, bool> m_mayHaveRegisteredServiceWorkers;
 #endif
 
     Ref<WebPageGroup> m_defaultPageGroup;

Modified: branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-02-07 02:45:09 UTC (rev 228210)
@@ -186,6 +186,7 @@
 #include <WebCore/SchemeRegistry.h>
 #include <WebCore/ScriptController.h>
 #include <WebCore/SerializedScriptValue.h>
+#include <WebCore/ServiceWorkerProvider.h>
 #include <WebCore/Settings.h>
 #include <WebCore/ShadowRoot.h>
 #include <WebCore/SharedBuffer.h>
@@ -565,6 +566,11 @@
     setSmartInsertDeleteEnabled(parameters.smartInsertDeleteEnabled);
 #endif
 
+#if ENABLE(SERVICE_WORKER)
+    if (parameters.hasRegisteredServiceWorkers)
+        ServiceWorkerProvider::singleton().setMayHaveRegisteredServiceWorkers();
+#endif
+
 #if ENABLE(WEB_RTC)
     if (!parameters.iceCandidateFilteringEnabled)
         disableICECandidateFiltering();

Modified: branches/safari-605-branch/Source/WebKit/WebProcess/WebProcess.cpp (228209 => 228210)


--- branches/safari-605-branch/Source/WebKit/WebProcess/WebProcess.cpp	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Source/WebKit/WebProcess/WebProcess.cpp	2018-02-07 02:45:09 UTC (rev 228210)
@@ -421,9 +421,7 @@
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    auto& serviceWorkerProvider = WebServiceWorkerProvider::singleton();
-    serviceWorkerProvider.setHasRegisteredServiceWorkers(parameters.hasRegisteredServiceWorkers);
-    ServiceWorkerProvider::setSharedProvider(serviceWorkerProvider);
+    ServiceWorkerProvider::setSharedProvider(WebServiceWorkerProvider::singleton());
 #endif
 
 #if ENABLE(WEBASSEMBLY)

Modified: branches/safari-605-branch/Tools/ChangeLog (228209 => 228210)


--- branches/safari-605-branch/Tools/ChangeLog	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Tools/ChangeLog	2018-02-07 02:45:09 UTC (rev 228210)
@@ -1,3 +1,16 @@
+2018-02-06  Jason Marcell  <[email protected]>
+
+        Cherry-pick r228188. rdar://problem/37293107
+
+    2018-02-06  Youenn Fablet  <[email protected]>
+
+            HasServiceWorkerRegistration bit should be sent when creating a new page
+            https://bugs.webkit.org/show_bug.cgi?id=182410
+
+            Reviewed by Chris Dumez.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+
 2018-02-05  Jason Marcell  <[email protected]>
 
         Cherry-pick r227989. rdar://problem/37145565

Modified: branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (228209 => 228210)


--- branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2018-02-07 02:25:57 UTC (rev 228209)
+++ branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm	2018-02-07 02:45:09 UTC (rev 228210)
@@ -33,6 +33,7 @@
 #import <WebKit/WKURLSchemeTaskPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <WebKit/WKWebsiteDataStoreRef.h>
 #import <WebKit/WebKit.h>
 #import <WebKit/_WKExperimentalFeature.h>
 #import <wtf/Deque.h>
@@ -838,6 +839,96 @@
     done = false;
 }
 
+TEST(ServiceWorkers, HasServiceWorkerRegistrationBit)
+{
+    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
+
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    setConfigurationInjectedBundlePath(configuration.get());
+
+    done = false;
+
+    [[configuration websiteDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    [[configuration websiteDataStore] fetchDataRecordsOfTypes:[NSSet setWithObject:WKWebsiteDataTypeServiceWorkerRegistrations] completionHandler:^(NSArray<WKWebsiteDataRecord *> *websiteDataRecords) {
+
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    RetainPtr<SWMessageHandler> messageHandler = adoptNS([[SWMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
+    RetainPtr<RegularPageMessageHandler> regularPageMessageHandler = adoptNS([[RegularPageMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:regularPageMessageHandler.get() name:@"regularPage"];
+
+    RetainPtr<SWSchemes> handler = adoptNS([[SWSchemes alloc] init]);
+    handler->resources.set("sw://host/regularPageWithoutConnection.html", ResourceInfo { @"text/html", regularPageWithoutConnectionBytes });
+    handler->resources.set("sw://host/regularPageWithConnection.html", ResourceInfo { @"text/html", regularPageWithConnectionBytes });
+    handler->resources.set("sw://host/mainWithScope.html", ResourceInfo { @"text/html", mainBytesWithScope });
+    handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes });
+    handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/_javascript_", scriptBytes });
+    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
+
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    // Load a page that registers a service worker.
+    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/mainWithScope.html"]];
+
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+    webView = nullptr;
+
+    // Now that a sw is registered, let's create a new configuration and try loading a regular page
+    RetainPtr<WKWebViewConfiguration> newConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    setConfigurationInjectedBundlePath(newConfiguration.get());
+
+    [[newConfiguration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
+    [[newConfiguration userContentController] addScriptMessageHandler:regularPageMessageHandler.get() name:@"regularPage"];
+    [newConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
+
+    newConfiguration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+    [newConfiguration.get().websiteDataStore _setServiceWorkerRegistrationDirectory: @"~/nonexistingfolder"];
+
+    [newConfiguration.get().processPool _setMaximumNumberOfProcesses:1];
+
+    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:newConfiguration.get()]);
+    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageWithoutConnection.html"]];
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    // There should be no storage process created.
+    EXPECT_EQ(0, webView.get().configuration.processPool._storageProcessIdentifier);
+
+    // Let's use the web site data store that has service worker and load a page.
+    newConfiguration.get().websiteDataStore = [configuration websiteDataStore];
+
+    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:newConfiguration.get()]);
+    EXPECT_EQ(1u, webView.get().configuration.processPool._webProcessCount);
+    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/regularPageWithConnection.html"]];
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+
+    // Make sure that storage process is launched.
+    EXPECT_NE(0, webView.get().configuration.processPool._storageProcessIdentifier);
+
+    // Make sure that loading the simple page did not start the service worker process.
+    EXPECT_EQ(1u, webView.get().configuration.processPool._webProcessCount);
+
+    [[configuration websiteDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    done = false;
+}
+
 #endif // WK_HAVE_C_SPI
 
 #endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to