Title: [288389] trunk/Source
Revision
288389
Author
sihui_...@apple.com
Date
2022-01-21 17:01:12 -0800 (Fri, 21 Jan 2022)

Log Message

Disable CFURLCache in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=234988
<rdar://problem/87619196>

Reviewed by Geoffrey Garen.

Source/WebCore:

_CFURLStorageSessionCopyCache can be slow (see rdar://85418732) and UI process may kill network process for
being unresponsive. Since WebKit does not use CFURLCache, we should disable it to avoid the hang.

* platform/network/NetworkStorageSession.h:
* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier):
* platform/network/cocoa/NetworkStorageSessionCocoa.mm:
(WebCore::createPrivateStorageSession):

Source/WebCore/PAL:

* pal/spi/cf/CFNetworkSPI.h:

Source/WebKit:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::newTestingSession):
(WebKit::NetworkProcess::ensureSession):

Source/WebKitLegacy:

* WebCoreSupport/NetworkStorageSessionMap.cpp:
(NetworkStorageSessionMap::ensureSession):

Source/WTF:

* wtf/PlatformHave.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (288388 => 288389)


--- trunk/Source/WTF/ChangeLog	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WTF/ChangeLog	2022-01-22 01:01:12 UTC (rev 288389)
@@ -1,3 +1,13 @@
+2022-01-21  Sihui Liu  <sihui_...@apple.com>
+
+        Disable CFURLCache in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=234988
+        <rdar://problem/87619196>
+
+        Reviewed by Geoffrey Garen.
+
+        * wtf/PlatformHave.h:
+
 2022-01-21  Mike Gorse  <mgo...@suse.com>
 
         Build failure with g++ 12: std::exchange undefined

Modified: trunk/Source/WTF/wtf/PlatformHave.h (288388 => 288389)


--- trunk/Source/WTF/wtf/PlatformHave.h	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2022-01-22 01:01:12 UTC (rev 288389)
@@ -1152,3 +1152,10 @@
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 120200
 #define HAVE_PLATFORM_SCROLL_MOMENTUM_INTERRUPTION_REASON 1
 #endif
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 120300) \
+    || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150400) \
+    || (PLATFORM(APPLETV) && __TV_OS_VERSION_MAX_ALLOWED >= 150400) \
+    || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MAX_ALLOWED >= 80500)
+#define HAVE_CFNETWORK_DISABLE_CACHE_SPI 1
+#endif

Modified: trunk/Source/WebCore/ChangeLog (288388 => 288389)


--- trunk/Source/WebCore/ChangeLog	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebCore/ChangeLog	2022-01-22 01:01:12 UTC (rev 288389)
@@ -1,3 +1,20 @@
+2022-01-21  Sihui Liu  <sihui_...@apple.com>
+
+        Disable CFURLCache in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=234988
+        <rdar://problem/87619196>
+
+        Reviewed by Geoffrey Garen.
+
+        _CFURLStorageSessionCopyCache can be slow (see rdar://85418732) and UI process may kill network process for
+        being unresponsive. Since WebKit does not use CFURLCache, we should disable it to avoid the hang.
+
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier):
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+        (WebCore::createPrivateStorageSession):
+
 2022-01-21  Tim Horton  <timothy_hor...@apple.com>
 
         imported/w3c/web-platform-tests/css/css-color/parsing/color-valid.html fails in debug

Modified: trunk/Source/WebCore/PAL/ChangeLog (288388 => 288389)


--- trunk/Source/WebCore/PAL/ChangeLog	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebCore/PAL/ChangeLog	2022-01-22 01:01:12 UTC (rev 288389)
@@ -1,3 +1,13 @@
+2022-01-21  Sihui Liu  <sihui_...@apple.com>
+
+        Disable CFURLCache in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=234988
+        <rdar://problem/87619196>
+
+        Reviewed by Geoffrey Garen.
+
+        * pal/spi/cf/CFNetworkSPI.h:
+
 2022-01-18  Alex Christensen  <achristen...@webkit.org>
 
         Use c++2a instead of gnu++2a for Cocoa builds

Modified: trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h (288388 => 288389)


--- trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2022-01-22 01:01:12 UTC (rev 288389)
@@ -359,6 +359,9 @@
 void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
 #endif
 
+#if HAVE(CFNETWORK_DISABLE_CACHE_SPI)
+void _CFURLStorageSessionDisableCache(CFURLStorageSessionRef);
+#endif
 CFURLStorageSessionRef _CFURLStorageSessionCreate(CFAllocatorRef, CFStringRef, CFDictionaryRef);
 CFURLCacheRef _CFURLStorageSessionCopyCache(CFAllocatorRef, CFURLStorageSessionRef);
 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (288388 => 288389)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2022-01-22 01:01:12 UTC (rev 288389)
@@ -120,7 +120,8 @@
 #endif
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
-    WEBCORE_EXPORT static RetainPtr<CFURLStorageSessionRef> createCFStorageSessionForIdentifier(CFStringRef identifier);
+    enum class ShouldDisableCFURLCache : bool { No, Yes };
+    WEBCORE_EXPORT static RetainPtr<CFURLStorageSessionRef> createCFStorageSessionForIdentifier(CFStringRef identifier, ShouldDisableCFURLCache = ShouldDisableCFURLCache::No);
     enum class IsInMemoryCookieStore : bool { No, Yes };
     WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID, RetainPtr<CFURLStorageSessionRef>&&, RetainPtr<CFHTTPCookieStorageRef>&&, IsInMemoryCookieStore = IsInMemoryCookieStore::No);
     WEBCORE_EXPORT explicit NetworkStorageSession(PAL::SessionID);
@@ -301,7 +302,7 @@
 };
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
-WEBCORE_EXPORT RetainPtr<CFURLStorageSessionRef> createPrivateStorageSession(CFStringRef identifier, std::optional<HTTPCookieAcceptPolicy> = std::nullopt);
+WEBCORE_EXPORT RetainPtr<CFURLStorageSessionRef> createPrivateStorageSession(CFStringRef identifier, std::optional<HTTPCookieAcceptPolicy> = std::nullopt, NetworkStorageSession::ShouldDisableCFURLCache = NetworkStorageSession::ShouldDisableCFURLCache::No);
 #endif
 
 }

Modified: trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp (288388 => 288389)


--- trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp	2022-01-22 01:01:12 UTC (rev 288389)
@@ -39,7 +39,7 @@
 
 namespace WebCore {
 
-RetainPtr<CFURLStorageSessionRef> NetworkStorageSession::createCFStorageSessionForIdentifier(CFStringRef identifier)
+RetainPtr<CFURLStorageSessionRef> NetworkStorageSession::createCFStorageSessionForIdentifier(CFStringRef identifier, ShouldDisableCFURLCache shouldDisableCFURLCache)
 {
     auto storageSession = adoptCF(_CFURLStorageSessionCreate(kCFAllocatorDefault, identifier, nullptr));
 
@@ -46,15 +46,25 @@
     if (!storageSession)
         return nullptr;
 
-    auto cache = adoptCF(_CFURLStorageSessionCopyCache(kCFAllocatorDefault, storageSession.get()));
-    if (!cache)
-        return nullptr;
+    if (shouldDisableCFURLCache == ShouldDisableCFURLCache::Yes) {
+#if HAVE(CFNETWORK_DISABLE_CACHE_SPI)
+        _CFURLStorageSessionDisableCache(storageSession.get());
+#else
+        shouldDisableCFURLCache = ShouldDisableCFURLCache::No;
+#endif
+    }
 
-    CFURLCacheSetDiskCapacity(cache.get(), 0);
+    if (shouldDisableCFURLCache == ShouldDisableCFURLCache::No) {
+        auto cache = adoptCF(_CFURLStorageSessionCopyCache(kCFAllocatorDefault, storageSession.get()));
+        if (!cache)
+            return nullptr;
 
-    auto sharedCache = adoptCF(CFURLCacheCopySharedURLCache());
-    CFURLCacheSetMemoryCapacity(cache.get(), CFURLCacheMemoryCapacity(sharedCache.get()));
+        CFURLCacheSetDiskCapacity(cache.get(), 0);
 
+        auto sharedCache = adoptCF(CFURLCacheCopySharedURLCache());
+        CFURLCacheSetMemoryCapacity(cache.get(), CFURLCacheMemoryCapacity(sharedCache.get()));
+    }
+
     if (!NetworkStorageSession::processMayUseCookieAPI())
         return storageSession;
 

Modified: trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNetWin.cpp (288388 => 288389)


--- trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNetWin.cpp	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNetWin.cpp	2022-01-22 01:01:12 UTC (rev 288389)
@@ -79,7 +79,7 @@
     return CFHTTPCookieStorageAcceptPolicyAlways;
 }
 
-RetainPtr<CFURLStorageSessionRef> createPrivateStorageSession(CFStringRef identifier, std::optional<HTTPCookieAcceptPolicy> cookieAcceptPolicy)
+RetainPtr<CFURLStorageSessionRef> createPrivateStorageSession(CFStringRef identifier, std::optional<HTTPCookieAcceptPolicy> cookieAcceptPolicy, NetworkStorageSession::ShouldDisableCFURLCache)
 {
     const void* sessionPropertyKeys[] = { _kCFURLStorageSessionIsPrivate };
     const void* sessionPropertyValues[] = { kCFBooleanTrue };

Modified: trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm (288388 => 288389)


--- trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2022-01-22 01:01:12 UTC (rev 288389)
@@ -171,7 +171,7 @@
     return *m_cookieStorageObserver;
 }
 
-RetainPtr<CFURLStorageSessionRef> createPrivateStorageSession(CFStringRef identifier, std::optional<HTTPCookieAcceptPolicy> cookieAcceptPolicy)
+RetainPtr<CFURLStorageSessionRef> createPrivateStorageSession(CFStringRef identifier, std::optional<HTTPCookieAcceptPolicy> cookieAcceptPolicy, NetworkStorageSession::ShouldDisableCFURLCache shouldDisableCFURLCache)
 {
     const void* sessionPropertyKeys[] = { _kCFURLStorageSessionIsPrivate };
     const void* sessionPropertyValues[] = { kCFBooleanTrue };
@@ -181,6 +181,14 @@
     if (!storageSession)
         return nullptr;
 
+    if (shouldDisableCFURLCache == NetworkStorageSession::ShouldDisableCFURLCache::Yes) {
+#if HAVE(CFNETWORK_DISABLE_CACHE_SPI)
+        _CFURLStorageSessionDisableCache(storageSession.get());
+#else
+        shouldDisableCFURLCache = NetworkStorageSession::ShouldDisableCFURLCache::No;
+#endif
+    }
+
     // The private storage session should have the same properties as the default storage session,
     // with the exception that it should be in-memory only storage.
 
@@ -188,12 +196,13 @@
     // This could occur if there is an issue figuring out where to place a storage on disk (e.g. the
     // sandbox does not allow CFNetwork access).
 
-    auto cache = adoptCF(_CFURLStorageSessionCopyCache(kCFAllocatorDefault, storageSession.get()));
-    if (!cache)
-        return nullptr;
+    if (shouldDisableCFURLCache == NetworkStorageSession::ShouldDisableCFURLCache::No) {
+        auto cache = adoptCF(_CFURLStorageSessionCopyCache(kCFAllocatorDefault, storageSession.get()));
+        if (!cache)
+            return nullptr;
 
-    CFURLCacheSetDiskCapacity(cache.get(), 0); // Setting disk cache size should not be necessary once <rdar://problem/12656814> is fixed.
-    CFURLCacheSetMemoryCapacity(cache.get(), [[NSURLCache sharedURLCache] memoryCapacity]);
+        CFURLCacheSetMemoryCapacity(cache.get(), [[NSURLCache sharedURLCache] memoryCapacity]);
+    }
 
     auto cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
     if (!cookieStorage)

Modified: trunk/Source/WebKit/ChangeLog (288388 => 288389)


--- trunk/Source/WebKit/ChangeLog	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebKit/ChangeLog	2022-01-22 01:01:12 UTC (rev 288389)
@@ -1,3 +1,15 @@
+2022-01-21  Sihui Liu  <sihui_...@apple.com>
+
+        Disable CFURLCache in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=234988
+        <rdar://problem/87619196>
+
+        Reviewed by Geoffrey Garen.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::newTestingSession):
+        (WebKit::NetworkProcess::ensureSession):
+
 2022-01-21  Per Arne Vollan  <pvol...@apple.com>
 
         Inject Launch Services database before NSApplication is initialized

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (288388 => 288389)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-01-22 01:01:12 UTC (rev 288389)
@@ -443,7 +443,7 @@
 {
 #if PLATFORM(COCOA)
     // Session name should be short enough for shared memory region name to be under the limit, otherwise sandbox rules won't work (see <rdar://problem/13642852>).
-    auto session = WebCore::createPrivateStorageSession(makeString("WebKit Test-", getCurrentProcessID()).createCFString().get());
+    auto session = WebCore::createPrivateStorageSession(makeString("WebKit Test-", getCurrentProcessID()).createCFString().get(), std::nullopt, NetworkStorageSession::ShouldDisableCFURLCache::Yes);
     RetainPtr<CFHTTPCookieStorageRef> cookieStorage;
     if (WebCore::NetworkStorageSession::processMayUseCookieAPI()) {
         ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
@@ -475,7 +475,7 @@
     RetainPtr<CFURLStorageSessionRef> storageSession;
     RetainPtr<CFStringRef> cfIdentifier = makeString(identifierBase, ".PrivateBrowsing.", createCanonicalUUIDString()).createCFString();
     if (sessionID.isEphemeral())
-        storageSession = createPrivateStorageSession(cfIdentifier.get());
+        storageSession = createPrivateStorageSession(cfIdentifier.get(), std::nullopt, WebCore::NetworkStorageSession::ShouldDisableCFURLCache::Yes);
     else if (sessionID != PAL::SessionID::defaultSessionID())
         storageSession = WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier(cfIdentifier.get());
 

Modified: trunk/Source/WebKitLegacy/ChangeLog (288388 => 288389)


--- trunk/Source/WebKitLegacy/ChangeLog	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebKitLegacy/ChangeLog	2022-01-22 01:01:12 UTC (rev 288389)
@@ -1,3 +1,14 @@
+2022-01-21  Sihui Liu  <sihui_...@apple.com>
+
+        Disable CFURLCache in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=234988
+        <rdar://problem/87619196>
+
+        Reviewed by Geoffrey Garen.
+
+        * WebCoreSupport/NetworkStorageSessionMap.cpp:
+        (NetworkStorageSessionMap::ensureSession):
+
 2022-01-11  Michael Saboff  <msab...@apple.com>
 
         Fixed installhdr build failures in WebCore and WebKitLegacy

Modified: trunk/Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.cpp (288388 => 288389)


--- trunk/Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.cpp	2022-01-22 00:41:43 UTC (rev 288388)
+++ trunk/Source/WebKitLegacy/WebCoreSupport/NetworkStorageSessionMap.cpp	2022-01-22 01:01:12 UTC (rev 288389)
@@ -90,7 +90,7 @@
     if (sessionID.isEphemeral())
         storageSession = WebCore::createPrivateStorageSession(identifier.get());
     else
-        storageSession = WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier(identifier.get());
+        storageSession = WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier(identifier.get(), WebCore::NetworkStorageSession::ShouldDisableCFURLCache::Yes);
 
     RetainPtr<CFHTTPCookieStorageRef> cookieStorage;
     if (WebCore::NetworkStorageSession::processMayUseCookieAPI()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to