Title: [282034] trunk
Revision
282034
Author
katherine_che...@apple.com
Date
2021-09-03 15:48:07 -0700 (Fri, 03 Sep 2021)

Log Message

Safari’s Privacy Report window is completely blank
https://bugs.webkit.org/show_bug.cgi?id=229847
<rdar://problem/80974688>

Reviewed by Chris Dumez.

Source/WebKit:

We should not wait for an IPC reply on a cached web process, because
it will cause long hangs.

In order to test this I added a new SPI to update the
cachedProcessSuspensionDelay (the usual timeout is 30 seconds). I also
moved the initial suspension timer call to be after the responsiveness
check, otherwise the cached process will be resumed very soon.

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(+[WKWebsiteDataStore _setCachedProcessSuspensionDelayForTesting:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/WebProcessCache.cpp:
(WebKit::WebProcessCache::setCachedProcessSuspensionDelayForTesting):
(WebKit::WebProcessCache::addProcess):
(WebKit::WebProcessCache::CachedProcess::CachedProcess):
(WebKit::WebProcessCache::CachedProcess::startSuspensionTimer):
* UIProcess/WebProcessCache.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::sendResourceLoadStatisticsDataImmediately):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::setCachedProcessSuspensionDelayForTesting):
* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (282033 => 282034)


--- trunk/Source/WebKit/ChangeLog	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/ChangeLog	2021-09-03 22:48:07 UTC (rev 282034)
@@ -1,3 +1,34 @@
+2021-09-03  Kate Cheney  <katherine_che...@apple.com>
+
+        Safari’s Privacy Report window is completely blank
+        https://bugs.webkit.org/show_bug.cgi?id=229847
+        <rdar://problem/80974688>
+
+        Reviewed by Chris Dumez.
+
+        We should not wait for an IPC reply on a cached web process, because
+        it will cause long hangs.
+
+        In order to test this I added a new SPI to update the
+        cachedProcessSuspensionDelay (the usual timeout is 30 seconds). I also
+        moved the initial suspension timer call to be after the responsiveness
+        check, otherwise the cached process will be resumed very soon.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (+[WKWebsiteDataStore _setCachedProcessSuspensionDelayForTesting:]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        * UIProcess/WebProcessCache.cpp:
+        (WebKit::WebProcessCache::setCachedProcessSuspensionDelayForTesting):
+        (WebKit::WebProcessCache::addProcess):
+        (WebKit::WebProcessCache::CachedProcess::CachedProcess):
+        (WebKit::WebProcessCache::CachedProcess::startSuspensionTimer):
+        * UIProcess/WebProcessCache.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::sendResourceLoadStatisticsDataImmediately):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::setCachedProcessSuspensionDelayForTesting):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2021-09-03  Alex Christensen  <achristen...@webkit.org>
 
         Simplify PCM::Client interface

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (282033 => 282034)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2021-09-03 22:48:07 UTC (rev 282034)
@@ -544,6 +544,11 @@
 #endif
 }
 
++ (void)_setCachedProcessSuspensionDelayForTesting:(double)delayInSeconds
+{
+    WebKit::WebsiteDataStore::setCachedProcessSuspensionDelayForTesting(Seconds(delayInSeconds));
+}
+
 - (void)_isRelationshipOnlyInDatabaseOnce:(NSURL *)firstPartyURL thirdParty:(NSURL *)thirdPartyURL completionHandler:(void (^)(BOOL))completionHandler
 {
 #if ENABLE(RESOURCE_LOAD_STATISTICS)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (282033 => 282034)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2021-09-03 22:48:07 UTC (rev 282034)
@@ -81,6 +81,8 @@
 - (void)_appBoundDomains:(void (^)(NSArray<NSString *> *))completionHandler WK_API_AVAILABLE(macos(11.0), ios(14.0));
 - (void)_appBoundSchemes:(void (^)(NSArray<NSString *> *))completionHandler WK_API_AVAILABLE(macos(11.0), ios(14.0));
 
++ (void)_setCachedProcessSuspensionDelayForTesting:(double)delayInSeconds WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 - (void)_allowTLSCertificateChain:(NSArray *)certificateChain forHost:(NSString *)host WK_API_AVAILABLE(macos(12.0), ios(15.0));
 
 - (void)_renameOrigin:(NSURL *)oldName to:(NSURL *)newName forDataOfTypes:(NSSet<NSString *> *)dataTypes completionHandler:(void (^)(void))completionHandler;

Modified: trunk/Source/WebKit/UIProcess/WebProcessCache.cpp (282033 => 282034)


--- trunk/Source/WebKit/UIProcess/WebProcessCache.cpp	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/UIProcess/WebProcessCache.cpp	2021-09-03 22:48:07 UTC (rev 282034)
@@ -40,8 +40,13 @@
 
 Seconds WebProcessCache::cachedProcessLifetime { 30_min };
 Seconds WebProcessCache::clearingDelayAfterApplicationResignsActive { 5_min };
-static constexpr Seconds cachedProcessSuspensionDelay { 30_s };
+static Seconds cachedProcessSuspensionDelay { 30_s };
 
+void WebProcessCache::setCachedProcessSuspensionDelayForTesting(Seconds delay)
+{
+    cachedProcessSuspensionDelay = delay;
+}
+
 static uint64_t generateAddRequestIdentifier()
 {
     static uint64_t identifier = 0;
@@ -133,6 +138,10 @@
         m_processesPerRegistrableDomain.remove(it);
     }
 
+#if PLATFORM(MAC)
+    cachedProcess->startSuspensionTimer();
+#endif
+
     WEBPROCESSCACHE_RELEASE_LOG("addProcess: Added process to WebProcess cache (size=%u, capacity=%u)", cachedProcess->process().processIdentifier(), size() + 1, capacity());
     m_processesPerRegistrableDomain.add(registrableDomain, WTFMove(cachedProcess));
 
@@ -268,9 +277,6 @@
     RELEASE_ASSERT_WITH_MESSAGE(!m_process->websiteDataStore().processes().contains(*m_process), "Only processes with pages should be registered with the data store");
     m_process->setIsInProcessCache(true);
     m_evictionTimer.startOneShot(cachedProcessLifetime);
-#if PLATFORM(MAC)
-    m_suspensionTimer.startOneShot(cachedProcessSuspensionDelay);
-#endif
 }
 
 WebProcessCache::CachedProcess::~CachedProcess()
@@ -311,6 +317,11 @@
 }
 
 #if PLATFORM(MAC)
+void WebProcessCache::CachedProcess::startSuspensionTimer()
+{
+    m_suspensionTimer.startOneShot(cachedProcessSuspensionDelay);
+}
+
 void WebProcessCache::CachedProcess::suspensionTimerFired()
 {
     ASSERT(m_process);

Modified: trunk/Source/WebKit/UIProcess/WebProcessCache.h (282033 => 282034)


--- trunk/Source/WebKit/UIProcess/WebProcessCache.h	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/UIProcess/WebProcessCache.h	2021-09-03 22:48:07 UTC (rev 282034)
@@ -58,6 +58,7 @@
 
     enum class ShouldShutDownProcess { No, Yes };
     void removeProcess(WebProcessProxy&, ShouldShutDownProcess);
+    static void setCachedProcessSuspensionDelayForTesting(Seconds);
 
 private:
     static Seconds cachedProcessLifetime;
@@ -71,6 +72,7 @@
 
         Ref<WebProcessProxy> takeProcess();
         WebProcessProxy& process() { ASSERT(m_process); return *m_process; }
+        void startSuspensionTimer();
 
 #if PLATFORM(MAC)
         bool isSuspended() const { return !m_suspensionTimer.isActive(); }

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (282033 => 282034)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-09-03 22:48:07 UTC (rev 282034)
@@ -2035,8 +2035,12 @@
 {
     auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
 
-    for (auto& process : processes())
+    for (auto& process : processes()) {
+        if (!process->pageCount())
+            continue;
+
         process->sendWithAsyncReply(Messages::WebProcess::SendResourceLoadStatisticsDataImmediately(), [callbackAggregator] { });
+    }
 }
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (282033 => 282034)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-09-03 22:48:07 UTC (rev 282034)
@@ -1589,6 +1589,11 @@
 }
 #endif // ENABLE(RESOURCE_LOAD_STATISTICS)
 
+void WebsiteDataStore::setCachedProcessSuspensionDelayForTesting(Seconds delay)
+{
+    WebProcessCache::setCachedProcessSuspensionDelayForTesting(delay);
+}
+
 void WebsiteDataStore::syncLocalStorage(CompletionHandler<void()>&& completionHandler)
 {
     networkProcess().sendWithAsyncReply(Messages::NetworkProcess::SyncLocalStorage(), WTFMove(completionHandler));

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (282033 => 282034)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2021-09-03 22:48:07 UTC (rev 282034)
@@ -259,6 +259,8 @@
     const String& resolvedModelElementCacheDirectory() const { return m_resolvedConfiguration->modelElementCacheDirectory(); }
 #endif
 
+    static void setCachedProcessSuspensionDelayForTesting(Seconds);
+
     void allowSpecificHTTPSCertificateForHost(const WebCertificateInfo*, const String& host);
 
     DeviceIdHashSaltStorage& deviceIdHashSaltStorage() { return m_deviceIdHashSaltStorage.get(); }

Modified: trunk/Tools/ChangeLog (282033 => 282034)


--- trunk/Tools/ChangeLog	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Tools/ChangeLog	2021-09-03 22:48:07 UTC (rev 282034)
@@ -1,3 +1,14 @@
+2021-09-03  Kate Cheney  <katherine_che...@apple.com>
+
+        Safari’s Privacy Report window is completely blank
+        https://bugs.webkit.org/show_bug.cgi?id=229847
+        <rdar://problem/80974688>
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
+        (TEST):
+
 2021-09-03  Devin Rousso  <drou...@apple.com>
 
         [Web App Manifest] Always fetch the first manifest if provided

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm (282033 => 282034)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2021-09-03 22:34:31 UTC (rev 282033)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2021-09-03 22:48:07 UTC (rev 282034)
@@ -38,6 +38,7 @@
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKWebsiteDataStoreConfiguration.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/text/StringConcatenateNumbers.h>
 
 static bool finishedNavigation = false;
 
@@ -1337,6 +1338,62 @@
 
 @end
 
+#if PLATFORM(MAC)
+TEST(ResourceLoadStatistics, DataSummaryWithCachedProcess)
+{
+    auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
+    processPoolConfiguration.get().processSwapsOnNavigation = YES;
+    processPoolConfiguration.get().usesWebProcessCache = YES;
+    processPoolConfiguration.get().processSwapsOnNavigationWithinSameNonHTTPFamilyProtocol = YES;
+    processPoolConfiguration.get().prewarmsProcessesAutomatically = NO;
+    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
+
+    EXPECT_GT([processPool _maximumSuspendedPageCount], 0u);
+    EXPECT_GT([processPool _processCacheCapacity], 0u);
+
+    auto *dataStore = [WKWebsiteDataStore defaultDataStore];
+    [WKWebsiteDataStore _setCachedProcessSuspensionDelayForTesting:0];
+
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [webViewConfiguration setProcessPool:processPool.get()];
+    [webViewConfiguration setWebsiteDataStore:dataStore];
+
+    auto handler = adoptNS([[ResourceLoadStatisticsSchemeHandler alloc] init]);
+
+    const unsigned maxSuspendedPageCount = [processPool _maximumSuspendedPageCount];
+    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"resource-load-statistics"];
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    auto delegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    for (unsigned i = 0; i < maxSuspendedPageCount + 1; i++) {
+        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:makeString("resource-load-statistics://www.domain-", i, ".com")]];
+        [webView loadRequest:request];
+        [delegate waitForDidFinishNavigation];
+
+        EXPECT_EQ(i + 1, [processPool _webProcessCount]);
+        EXPECT_EQ(i + 1, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
+        EXPECT_FALSE([processPool _hasPrewarmedWebProcess]);
+    }
+    
+    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:makeString("resource-load-statistics://www.domain-", maxSuspendedPageCount + 1, ".com")]];
+    [webView loadRequest:request];
+    [delegate waitForDidFinishNavigation];
+
+    // This will timeout if waiting for IPC from a cached process.
+    static bool doneFlag = false;
+    [dataStore _getResourceLoadStatisticsDataSummary:^void(NSArray<_WKResourceLoadStatisticsThirdParty *> *thirdPartyData)
+    {
+        doneFlag = true;
+    }];
+
+    TestWebKitAPI::Util::run(&doneFlag);
+    
+    [WKWebsiteDataStore _setCachedProcessSuspensionDelayForTesting:30];
+}
+#endif
+
 TEST(ResourceLoadStatistics, BackForwardPerPageData)
 {
     auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to