https://bugs.webkit.org/show_bug.cgi?id=199817
Reviewed by Geoff Garen.
Source/WebKit:
I also added SPI to set the path of the NetworkCache with an API test.
If this new SPI is not used, it falls back to getting the cache location from the NetworkProcess to maintain compatibility.
We still get options, cache size, and cache model from the NetworkProcess. Those should be migrated with new SPI later.
Clearing the cache and other operations now iterate the NetworkSessions instead of assuming there is only one cache.
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
(WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains):
(WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
(WebKit::NetworkProcess::setCacheModel):
* NetworkProcess/NetworkProcess.h:
(WebKit::NetworkProcess::diskCacheDirectory const):
(WebKit::NetworkProcess::cacheOptions const):
(WebKit::NetworkProcess::cache): Deleted.
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::m_shouldCaptureExtraNetworkLoadMetrics):
* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::NetworkSession):
* NetworkProcess/NetworkSession.h:
(WebKit::NetworkSession::cache):
* NetworkProcess/NetworkSessionCreationParameters.cpp:
(WebKit::NetworkSessionCreationParameters::encode const):
(WebKit::NetworkSessionCreationParameters::decode):
* NetworkProcess/NetworkSessionCreationParameters.h:
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::open):
(WebKit::NetworkCache::Cache::Cache):
* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
(WebKit::NetworkProcess::clearDiskCache):
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
* NetworkProcess/curl/NetworkSessionCurl.cpp:
(WebKit::NetworkSessionCurl::NetworkSessionCurl):
* NetworkProcess/soup/NetworkSessionSoup.cpp:
(WebKit::NetworkSessionSoup::NetworkSessionSoup):
* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _initWithConfiguration:]):
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
* UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
(-[_WKWebsiteDataStoreConfiguration networkCacheDirectory]):
(-[_WKWebsiteDataStoreConfiguration setNetworkCacheDirectory:]):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):
* UIProcess/WebsiteData/WebsiteDataStore.h:
(WebKit::WebsiteDataStore::resolvedNetworkCacheDirectory const):
Tools:
* TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
(TEST):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[WKWebView synchronouslyLoadRequest:]):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247567
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2019-07-18 Alex Christensen <achristensen@webkit.org>
+
+ Move NetworkCache ownership from NetworkProcess to NetworkSession
+ https://bugs.webkit.org/show_bug.cgi?id=199817
+
+ Reviewed by Geoff Garen.
+
+ I also added SPI to set the path of the NetworkCache with an API test.
+ If this new SPI is not used, it falls back to getting the cache location from the NetworkProcess to maintain compatibility.
+ We still get options, cache size, and cache model from the NetworkProcess. Those should be migrated with new SPI later.
+ Clearing the cache and other operations now iterate the NetworkSessions instead of assuming there is only one cache.
+
+ * NetworkProcess/NetworkProcess.cpp:
+ (WebKit::NetworkProcess::fetchWebsiteData):
+ (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
+ (WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains):
+ (WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
+ (WebKit::NetworkProcess::setCacheModel):
+ * NetworkProcess/NetworkProcess.h:
+ (WebKit::NetworkProcess::diskCacheDirectory const):
+ (WebKit::NetworkProcess::cacheOptions const):
+ (WebKit::NetworkProcess::cache): Deleted.
+ * NetworkProcess/NetworkResourceLoader.cpp:
+ (WebKit::m_shouldCaptureExtraNetworkLoadMetrics):
+ * NetworkProcess/NetworkSession.cpp:
+ (WebKit::NetworkSession::NetworkSession):
+ * NetworkProcess/NetworkSession.h:
+ (WebKit::NetworkSession::cache):
+ * NetworkProcess/NetworkSessionCreationParameters.cpp:
+ (WebKit::NetworkSessionCreationParameters::encode const):
+ (WebKit::NetworkSessionCreationParameters::decode):
+ * NetworkProcess/NetworkSessionCreationParameters.h:
+ * NetworkProcess/cache/NetworkCache.cpp:
+ (WebKit::NetworkCache::Cache::open):
+ (WebKit::NetworkCache::Cache::Cache):
+ * NetworkProcess/cache/NetworkCache.h:
+ * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+ (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
+ (WebKit::NetworkProcess::clearDiskCache):
+ * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+ (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
+ * NetworkProcess/curl/NetworkSessionCurl.cpp:
+ (WebKit::NetworkSessionCurl::NetworkSessionCurl):
+ * NetworkProcess/soup/NetworkSessionSoup.cpp:
+ (WebKit::NetworkSessionSoup::NetworkSessionSoup):
+ * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+ (-[WKWebsiteDataStore _initWithConfiguration:]):
+ * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
+ * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
+ (-[_WKWebsiteDataStoreConfiguration networkCacheDirectory]):
+ (-[_WKWebsiteDataStoreConfiguration setNetworkCacheDirectory:]):
+ * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+ (WebKit::WebsiteDataStore::parameters):
+ * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+ (WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):
+ * UIProcess/WebsiteData/WebsiteDataStore.h:
+ (WebKit::WebsiteDataStore::resolvedNetworkCacheDirectory const):
+
2019-07-18 Chris Dumez <cdumez@apple.com>
Regression(r247486) Multiple Layout Tests in http/tests/cache/* are crashing on iOS Debug WK2
});
}
#endif
-
if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
- fetchDiskCacheEntries(cache(), sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
- callbackAggregator->m_websiteData.entries.appendVector(entries);
- });
+ for (auto& session : networkSessions().values()) {
+ fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
+ callbackAggregator->m_websiteData.entries.appendVector(entries);
+ });
+ }
}
}
}
#endif
- if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral())
- clearDiskCacheEntries(cache(), originDatas, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
+ if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
+ for (auto& session : networkSessions().values())
+ clearDiskCacheEntries(session->cache(), originDatas, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
+ }
if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
if (auto* session = storageSession(sessionID)) {
});
}
#endif
-
+
if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
- fetchDiskCacheEntries(cache(), sessionID, fetchOptions, [this, domainsToDeleteAllButCookiesFor, callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
+ for (auto& session : networkSessions().values()) {
+ fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [domainsToDeleteAllButCookiesFor, callbackAggregator = callbackAggregator.copyRef(), session = session.copyRef()](auto entries) mutable {
- Vector<SecurityOriginData> entriesToDelete;
- for (auto& entry : entries) {
- if (!domainsToDeleteAllButCookiesFor.contains(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host)))
- continue;
- entriesToDelete.append(entry.origin);
- callbackAggregator->m_domains.add(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host));
- }
- clearDiskCacheEntries(cache(), entriesToDelete, [callbackAggregator = callbackAggregator.copyRef()] { });
- });
+ Vector<SecurityOriginData> entriesToDelete;
+ for (auto& entry : entries) {
+ if (!domainsToDeleteAllButCookiesFor.contains(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host)))
+ continue;
+ entriesToDelete.append(entry.origin);
+ callbackAggregator->m_domains.add(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host));
+ }
+ clearDiskCacheEntries(session->cache(), entriesToDelete, [callbackAggregator = callbackAggregator.copyRef()] { });
+ });
+ }
}
auto dataTypesForUIProcess = WebsiteData::filter(websiteDataTypes, WebsiteDataProcessType::UI);
#endif
if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
- fetchDiskCacheEntries(cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
- callbackAggregator->m_websiteData.entries.appendVector(entries);
- });
+ for (auto& session : networkSessions().values()) {
+ fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
+ callbackAggregator->m_websiteData.entries.appendVector(entries);
+ });
+ }
}
}
#endif // ENABLE(RESOURCE_LOAD_STATISTICS)
diskFreeSize /= KB * 1000;
calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
}
-
- if (m_cache)
- m_cache->setCapacity(urlCacheDiskCapacity);
+
+ for (auto& session : networkSessions().values()) {
+ if (auto* cache = session->cache())
+ cache->setCapacity(urlCacheDiskCapacity);
+ }
}
void NetworkProcess::setCanHandleHTTPSServerTrustEvaluation(bool value)
class WebSWOriginStore;
#endif
-namespace CacheStorage {
-class Engine;
+namespace NetworkCache {
+enum class CacheOption : uint8_t;
}
-namespace NetworkCache {
-class Cache;
+namespace CacheStorage {
+class Engine;
}
class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client, public ThreadSafeRefCounted<NetworkProcess>
AuthenticationManager& authenticationManager();
DownloadManager& downloadManager();
- NetworkCache::Cache* cache() { return m_cache.get(); }
-
void setSession(const PAL::SessionID&, Ref<NetworkSession>&&);
NetworkSession* networkSession(const PAL::SessionID&) const final;
NetworkSession* networkSessionByConnection(IPC::Connection&) const;
void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
void removeKeptAliveLoad(NetworkResourceLoader&);
+ const String& diskCacheDirectory() const { return m_diskCacheDirectory; }
+ const OptionSet<NetworkCache::CacheOption>& cacheOptions() const { return m_cacheOptions; }
+
private:
void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
- RefPtr<NetworkCache::Cache> m_cache;
-
typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
NetworkProcessSupplementMap m_supplements;
uint32_t m_downloadMonitorSpeedMultiplier { 1 };
HashMap<IPC::Connection::UniqueID, PAL::SessionID> m_sessionByConnection;
+
+ OptionSet<NetworkCache::CacheOption> m_cacheOptions;
};
} // namespace WebKit
, m_fileReferences(connection.resolveBlobReferences(m_parameters))
, m_isAllowedToAskUserForCredentials { m_parameters.clientCredentialPolicy == ClientCredentialPolicy::MayAskClientForCredentials }
, m_bufferingTimer { *this, &NetworkResourceLoader::bufferingTimerFired }
- , m_cache { sessionID().isEphemeral() ? nullptr : connection.networkProcess().cache() }
, m_shouldCaptureExtraNetworkLoadMetrics(m_connection->captureExtraNetworkLoadMetricsEnabled())
{
ASSERT(RunLoop::isMain());
+
+ if (auto* session = connection.networkProcess().networkSession(sessionID()))
+ m_cache = session->cache();
+
// FIXME: This is necessary because of the existence of EmptyFrameLoaderClient in WebCore.
// Once bug 116233 is resolved, this ASSERT can just be "m_webPageID && m_webFrameID"
ASSERT((m_parameters.webPageID && m_parameters.webFrameID) || m_parameters.clientCredentialPolicy == ClientCredentialPolicy::CannotAskClientForCredentials);
#include "NetworkSession.h"
#include "AdClickAttributionManager.h"
+#include "Logging.h"
#include "NetworkProcess.h"
#include "NetworkProcessProxyMessages.h"
#include "NetworkResourceLoadParameters.h"
return storageSession;
}
-NetworkSession::NetworkSession(NetworkProcess& networkProcess, PAL::SessionID sessionID, String&& localStorageDirectory, SandboxExtension::Handle& handle)
- : m_sessionID(sessionID)
+NetworkSession::NetworkSession(NetworkProcess& networkProcess, const NetworkSessionCreationParameters& parameters)
+ : m_sessionID(parameters.sessionID)
, m_networkProcess(networkProcess)
- , m_adClickAttribution(makeUniqueRef<AdClickAttributionManager>(sessionID))
- , m_storageManager(StorageManager::create(WTFMove(localStorageDirectory)))
-{
- SandboxExtension::consumePermanently(handle);
+ , m_adClickAttribution(makeUniqueRef<AdClickAttributionManager>(parameters.sessionID))
+ , m_storageManager(StorageManager::create(String(parameters.localStorageDirectory)))
+{
+ if (!m_sessionID.isEphemeral()) {
+ String networkCacheDirectory = parameters.networkCacheDirectory;
+ if (networkCacheDirectory.isNull())
+ networkCacheDirectory = networkProcess.diskCacheDirectory();
+ else
+ SandboxExtension::consumePermanently(parameters.networkCacheDirectoryExtensionHandle);
+
+ m_cache = NetworkCache::Cache::open(networkProcess, networkCacheDirectory, networkProcess.cacheOptions());
+ if (!m_cache)
+ RELEASE_LOG_ERROR(NetworkCache, "Failed to initialize the WebKit network disk cache");
+ }
+
+ SandboxExtension::consumePermanently(parameters.localStorageDirectoryExtensionHandle);
m_adClickAttribution->setPingLoadFunction([this, weakThis = makeWeakPtr(this)](NetworkResourceLoadParameters&& loadParameters, CompletionHandler<void(const WebCore::ResourceError&, const WebCore::ResourceResponse&)>&& completionHandler) {
if (!weakThis)
return;
struct NetworkSessionCreationParameters;
enum class WebsiteDataType;
-
+
+namespace NetworkCache {
+class Cache;
+}
+
class NetworkSession : public RefCounted<NetworkSession>, public CanMakeWeakPtr<NetworkSession> {
public:
static Ref<NetworkSession> create(NetworkProcess&, NetworkSessionCreationParameters&&);
void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
void removeKeptAliveLoad(NetworkResourceLoader&);
+ NetworkCache::Cache* cache() { return m_cache.get(); }
+
PrefetchCache& prefetchCache() { return m_prefetchCache; }
void clearPrefetchCache() { m_prefetchCache.clear(); }
virtual void addWebSocketTask(WebSocketTask&) { }
protected:
- NetworkSession(NetworkProcess&, PAL::SessionID, String&& localStorageDirectory, SandboxExtension::Handle&);
+ NetworkSession(NetworkProcess&, const NetworkSessionCreationParameters&);
PAL::SessionID m_sessionID;
Ref<NetworkProcess> m_networkProcess;
#if !ASSERT_DISABLED
bool m_isInvalidated { false };
#endif
+ RefPtr<NetworkCache::Cache> m_cache;
};
} // namespace WebKit
#if USE(CURL)
, { }, { }
#endif
- , { }, { }, false, { }, { }, { }, { }, { }, { }, { }
+ , { }, { }, false, { }, { }, { }, { }, { }, { }, { }, { }, { }
};
}
encoder << resourceLoadStatisticsManualPrevalentResource;
encoder << localStorageDirectory << localStorageDirectoryExtensionHandle;
+ encoder << networkCacheDirectory << networkCacheDirectoryExtensionHandle;
encoder << deviceManagementRestrictionsEnabled;
encoder << allLoadsBlockedByDeviceManagementRestrictionsForTesting;
if (!localStorageDirectoryExtensionHandle)
return WTF::nullopt;
+ Optional<String> networkCacheDirectory;
+ decoder >> networkCacheDirectory;
+ if (!networkCacheDirectory)
+ return WTF::nullopt;
+
+ Optional<SandboxExtension::Handle> networkCacheDirectoryExtensionHandle;
+ decoder >> networkCacheDirectoryExtensionHandle;
+ if (!networkCacheDirectoryExtensionHandle)
+ return WTF::nullopt;
+
Optional<bool> deviceManagementRestrictionsEnabled;
decoder >> deviceManagementRestrictionsEnabled;
if (!deviceManagementRestrictionsEnabled)
, WTFMove(*resourceLoadStatisticsManualPrevalentResource)
, WTFMove(*localStorageDirectory)
, WTFMove(*localStorageDirectoryExtensionHandle)
+ , WTFMove(*networkCacheDirectory)
+ , WTFMove(*networkCacheDirectoryExtensionHandle)
}};
}
String localStorageDirectory;
SandboxExtension::Handle localStorageDirectoryExtensionHandle;
+ String networkCacheDirectory;
+ SandboxExtension::Handle networkCacheDirectoryExtensionHandle;
};
} // namespace WebKit
return resource;
}
-RefPtr<Cache> Cache::open(NetworkProcess& networkProcess, const String& cachePath, OptionSet<Option> options)
+RefPtr<Cache> Cache::open(NetworkProcess& networkProcess, const String& cachePath, OptionSet<CacheOption> options)
{
- auto storage = Storage::open(cachePath, options.contains(Option::TestingMode) ? Storage::Mode::AvoidRandomness : Storage::Mode::Normal);
+ auto storage = Storage::open(cachePath, options.contains(CacheOption::TestingMode) ? Storage::Mode::AvoidRandomness : Storage::Mode::Normal);
LOG(NetworkCache, "(NetworkProcess) opened cache storage, success %d", !!storage);
}
#endif
-Cache::Cache(NetworkProcess& networkProcess, Ref<Storage>&& storage, OptionSet<Option> options)
+Cache::Cache(NetworkProcess& networkProcess, Ref<Storage>&& storage, OptionSet<CacheOption> options)
: m_storage(WTFMove(storage))
, m_networkProcess(networkProcess)
{
#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
- if (options.contains(Option::SpeculativeRevalidation)) {
+ if (options.contains(CacheOption::SpeculativeRevalidation)) {
m_lowPowerModeNotifier = std::make_unique<WebCore::LowPowerModeNotifier>([this](bool isLowPowerModeEnabled) {
ASSERT(WTF::RunLoop::isMain());
if (isLowPowerModeEnabled)
}
#endif
- if (options.contains(Option::RegisterNotify)) {
+ if (options.contains(CacheOption::RegisterNotify)) {
#if PLATFORM(COCOA)
// Triggers with "notifyutil -p com.apple.WebKit.Cache.dump".
int token;
using GlobalFrameID = std::pair<WebCore::PageIdentifier, uint64_t /*webFrameID*/>;
-class Cache : public RefCounted<Cache> {
-public:
- enum class Option {
- // In testing mode we try to eliminate sources of randomness. Cache does not shrink and there are no read timeouts.
- TestingMode = 1 << 0,
- RegisterNotify = 1 << 1,
+enum class CacheOption : uint8_t {
+ // In testing mode we try to eliminate sources of randomness. Cache does not shrink and there are no read timeouts.
+ TestingMode = 1 << 0,
+ RegisterNotify = 1 << 1,
#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
- SpeculativeRevalidation = 1 << 2,
+ SpeculativeRevalidation = 1 << 2,
#endif
- };
- static RefPtr<Cache> open(NetworkProcess&, const String& cachePath, OptionSet<Option>);
+};
+
+class Cache : public RefCounted<Cache> {
+public:
+ static RefPtr<Cache> open(NetworkProcess&, const String& cachePath, OptionSet<CacheOption>);
void setCapacity(size_t);
~Cache();
private:
- Cache(NetworkProcess&, Ref<Storage>&&, OptionSet<Option> options);
+ Cache(NetworkProcess&, Ref<Storage>&&, OptionSet<CacheOption>);
Key makeCacheKey(const WebCore::ResourceRequest&);
return;
SandboxExtension::consumePermanently(parameters.diskCacheDirectoryExtensionHandle);
- OptionSet<NetworkCache::Cache::Option> cacheOptions { NetworkCache::Cache::Option::RegisterNotify };
+ m_cacheOptions = { NetworkCache::CacheOption::RegisterNotify };
if (parameters.shouldUseTestingNetworkSession)
- cacheOptions.add(NetworkCache::Cache::Option::TestingMode);
+ m_cacheOptions.add(NetworkCache::CacheOption::TestingMode);
#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
if (parameters.shouldEnableNetworkCacheSpeculativeRevalidation)
- cacheOptions.add(NetworkCache::Cache::Option::SpeculativeRevalidation);
+ m_cacheOptions.add(NetworkCache::CacheOption::SpeculativeRevalidation);
#endif
- m_cache = NetworkCache::Cache::open(*this, m_diskCacheDirectory, cacheOptions);
- if (!m_cache)
- RELEASE_LOG_ERROR(NetworkCache, "Failed to initialize the WebKit network disk cache");
-
// Disable NSURLCache.
auto urlCache(adoptNS([[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]));
[NSURLCache setSharedURLCache:urlCache.get()];
if (!m_clearCacheDispatchGroup)
m_clearCacheDispatchGroup = dispatch_group_create();
- auto* cache = this->cache();
- if (!cache) {
- completionHandler();
- return;
- }
-
auto group = m_clearCacheDispatchGroup;
- dispatch_group_async(group, dispatch_get_main_queue(), makeBlockPtr([cache, modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
- cache->clear(modifiedSince, WTFMove(completionHandler));
+ dispatch_group_async(group, dispatch_get_main_queue(), makeBlockPtr([this, protectedThis = makeRef(*this), modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
+ auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
+ for (auto& session : networkSessions().values()) {
+ if (auto* cache = session->cache())
+ cache->clear(modifiedSince, [aggregator = aggregator.copyRef()] () { });
+ }
}).get());
}
}
NetworkSessionCocoa::NetworkSessionCocoa(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
- : NetworkSession(networkProcess, parameters.sessionID, WTFMove(parameters.localStorageDirectory), parameters.localStorageDirectoryExtensionHandle)
+ : NetworkSession(networkProcess, parameters)
, m_boundInterfaceIdentifier(parameters.boundInterfaceIdentifier)
, m_sourceApplicationBundleIdentifier(parameters.sourceApplicationBundleIdentifier)
, m_sourceApplicationSecondaryIdentifier(parameters.sourceApplicationSecondaryIdentifier)
using namespace WebCore;
NetworkSessionCurl::NetworkSessionCurl(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
- : NetworkSession(networkProcess, parameters.sessionID, WTFMove(parameters.localStorageDirectory), parameters.localStorageDirectoryExtensionHandle)
+ : NetworkSession(networkProcess, parameters)
{
if (!parameters.cookiePersistentStorageFile.isEmpty())
networkStorageSession()->setCookieDatabase(makeUniqueRef<CookieJarDB>(parameters.cookiePersistentStorageFile));
ResourceCachesToClear resourceCachesToClear = static_cast<ResourceCachesToClear>(cachesToClear);
if (resourceCachesToClear == InMemoryResourceCachesOnly)
return;
- if (m_cache)
- m_cache->clear();
+ for (auto& session : networkSessions().values()) {
+ if (auto* cache = session->cache())
+ cache->clear();
+ }
}
void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
#include "NetworkCache.h"
#include "NetworkProcessCreationParameters.h"
+#include "NetworkSession.h"
#include "ResourceCachesToClear.h"
#include "WebCookieManager.h"
#include "WebKitCachedResolver.h"
#include <WebCore/ResourceHandle.h>
#include <WebCore/SoupNetworkSession.h>
#include <libsoup/soup.h>
+#include <wtf/CallbackAggregator.h>
#include <wtf/FileSystem.h>
#include <wtf/RAMSize.h>
#include <wtf/glib/GRefPtr.h>
SoupNetworkSession::clearOldSoupCache(FileSystem::directoryName(m_diskCacheDirectory));
- OptionSet<NetworkCache::Cache::Option> cacheOptions { NetworkCache::Cache::Option::RegisterNotify };
+ OptionSet<NetworkCache::CacheOption> cacheOptions { NetworkCache::CacheOption::RegisterNotify };
#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
if (parameters.shouldEnableNetworkCacheSpeculativeRevalidation)
- cacheOptions.add(NetworkCache::Cache::Option::SpeculativeRevalidation);
+ cacheOptions.add(NetworkCache::CacheOption::SpeculativeRevalidation);
#endif
- m_cache = NetworkCache::Cache::open(*this, m_diskCacheDirectory, cacheOptions);
-
supplement<WebCookieManager>()->setHTTPCookieAcceptPolicy(parameters.cookieAcceptPolicy, OptionalCallbackID());
if (!parameters.languages.isEmpty())
void NetworkProcess::clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&& completionHandler)
{
- if (!m_cache) {
- completionHandler();
- return;
+ auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
+ for (auto& session : networkSessions().values()) {
+ if (auto* cache = session->cache())
+ cache->clear(modifiedSince, [aggregator = aggregator.copyRef()] () { });
}
- m_cache->clear(modifiedSince, WTFMove(completionHandler));
}
void NetworkProcess::platformTerminate()
using namespace WebCore;
NetworkSessionSoup::NetworkSessionSoup(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
- : NetworkSession(networkProcess, parameters.sessionID, WTFMove(parameters.localStorageDirectory), parameters.localStorageDirectoryExtensionHandle)
+ : NetworkSession(networkProcess, parameters)
{
networkStorageSession()->setCookieObserverHandler([this] {
this->networkProcess().supplement<WebCookieManager>()->notifyCookiesDidChange(m_sessionID);
config->setCacheStorageDirectory(configuration._cacheStorageDirectory.path);
if (configuration._serviceWorkerRegistrationDirectory)
config->setServiceWorkerRegistrationDirectory(configuration._serviceWorkerRegistrationDirectory.path);
+ if (configuration.networkCacheDirectory)
+ config->setNetworkCacheDirectory(configuration.networkCacheDirectory.path);
} else {
RELEASE_ASSERT(!configuration._webStorageDirectory);
RELEASE_ASSERT(!configuration._webSQLDatabaseDirectory);
RELEASE_ASSERT(!configuration._resourceLoadStatisticsDirectory);
RELEASE_ASSERT(!configuration._cacheStorageDirectory);
RELEASE_ASSERT(!configuration._serviceWorkerRegistrationDirectory);
+ RELEASE_ASSERT(!configuration.networkCacheDirectory);
}
if (configuration.sourceApplicationBundleIdentifier)
@property (nonatomic, copy, setter=_setResourceLoadStatisticsDirectory:) NSURL *_resourceLoadStatisticsDirectory WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
@property (nonatomic, copy, setter=_setCacheStorageDirectory:) NSURL *_cacheStorageDirectory WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
@property (nonatomic, copy, setter=_setServiceWorkerRegistrationDirectory:) NSURL *_serviceWorkerRegistrationDirectory WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
+@property (nonatomic, nullable, copy) NSURL *networkCacheDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
// Testing only.
@property (nonatomic) BOOL allLoadsBlockedByDeviceManagementRestrictionsForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
_configuration->setIndexedDBDatabaseDirectory(url.path);
}
+- (NSURL *)networkCacheDirectory
+{
+ return [NSURL fileURLWithPath:_configuration->networkCacheDirectory() isDirectory:YES];
+}
+
+- (void)setNetworkCacheDirectory:(NSURL *)url
+{
+ if (!_configuration->isPersistent())
+ [NSException raise:NSInvalidArgumentException format:@"Cannot set networkCacheDirectory on a non-persistent _WKWebsiteDataStoreConfiguration."];
+ checkURLArgument(url);
+ _configuration->setNetworkCacheDirectory(url.path);
+}
+
- (NSURL *)_webSQLDatabaseDirectory
{
return [NSURL fileURLWithPath:_configuration->webSQLDatabaseDirectory() isDirectory:YES];
if (!localStorageDirectory.isEmpty())
SandboxExtension::createHandleForReadWriteDirectory(localStorageDirectory, localStorageDirectoryExtensionHandle);
+ auto networkCacheDirectory = resolvedNetworkCacheDirectory();
+ SandboxExtension::Handle networkCacheDirectoryExtensionHandle;
+ if (!networkCacheDirectory.isEmpty())
+ SandboxExtension::createHandleForReadWriteDirectory(networkCacheDirectory, networkCacheDirectoryExtensionHandle);
+
bool shouldIncludeLocalhostInResourceLoadStatistics = isSafari;
WebsiteDataStoreParameters parameters;
parameters.networkSessionParameters = {
m_configuration->allLoadsBlockedByDeviceManagementRestrictionsForTesting(),
WTFMove(resourceLoadStatisticsManualPrevalentResource),
WTFMove(localStorageDirectory),
- WTFMove(localStorageDirectoryExtensionHandle)
+ WTFMove(localStorageDirectoryExtensionHandle),
+ WTFMove(networkCacheDirectory),
+ WTFMove(networkCacheDirectoryExtensionHandle),
};
networkingHasBegun();
m_resolvedConfiguration->setIndexedDBDatabaseDirectory(resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->indexedDBDatabaseDirectory()));
if (!m_configuration->deviceIdHashSaltsStorageDirectory().isEmpty())
m_resolvedConfiguration->setDeviceIdHashSaltsStorageDirectory(resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->deviceIdHashSaltsStorageDirectory()));
+ if (!m_configuration->networkCacheDirectory().isEmpty())
+ m_resolvedConfiguration->setNetworkCacheDirectory(resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->networkCacheDirectory()));
if (!m_configuration->resourceLoadStatisticsDirectory().isEmpty())
m_resolvedConfiguration->setResourceLoadStatisticsDirectory(resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->resourceLoadStatisticsDirectory()));
if (!m_configuration->serviceWorkerRegistrationDirectory().isEmpty() && m_resolvedConfiguration->serviceWorkerRegistrationDirectory().isEmpty())
void resolveDirectoriesIfNecessary();
const String& resolvedApplicationCacheDirectory() const { return m_resolvedConfiguration->applicationCacheDirectory(); }
const String& resolvedLocalStorageDirectory() const { return m_resolvedConfiguration->localStorageDirectory(); }
+ const String& resolvedNetworkCacheDirectory() const { return m_resolvedConfiguration->networkCacheDirectory(); }
const String& resolvedMediaCacheDirectory() const { return m_resolvedConfiguration->mediaCacheDirectory(); }
const String& resolvedMediaKeysDirectory() const { return m_resolvedConfiguration->mediaKeysStorageDirectory(); }
const String& resolvedDatabaseDirectory() const { return m_resolvedConfiguration->webSQLDatabaseDirectory(); }
+2019-07-18 Alex Christensen <achristensen@webkit.org>
+
+ Move NetworkCache ownership from NetworkProcess to NetworkSession
+ https://bugs.webkit.org/show_bug.cgi?id=199817
+
+ Reviewed by Geoff Garen.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
+ (TEST):
+ * TestWebKitAPI/cocoa/TestWKWebView.h:
+ * TestWebKitAPI/cocoa/TestWKWebView.mm:
+ (-[WKWebView synchronouslyLoadRequest:]):
+
2019-07-18 Youenn Fablet <youenn@apple.com>
Make sure to set kCTFontFallbackOptionAttribute to kCTFontFallbackOptionSystem for system fonts
#import "config.h"
#import "PlatformUtilities.h"
+#import "TCPServer.h"
#import "Test.h"
#import "TestNavigationDelegate.h"
#import "TestWKWebView.h"
EXPECT_TRUE([websiteDataStore._sourceApplicationBundleIdentifier isEqualToString:@"otheridentifier"]);
EXPECT_TRUE([[websiteDataStoreConfiguration sourceApplicationBundleIdentifier] isEqualToString:@"testidentifier"]);
}
+
+TEST(WebKit, NetworkCacheDirectory)
+{
+ using namespace TestWebKitAPI;
+ TCPServer server([] (int socket) {
+ TCPServer::read(socket);
+ const char* response =
+ "HTTP/1.1 200 OK\r\n"
+ "Cache-Control: max-age=1000000\r\n"
+ "Content-Length: 6\r\n\r\n"
+ "Hello!";
+ TCPServer::write(socket, response, strlen(response));
+ });
+
+ NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"CustomPathsTest"] isDirectory:YES];
+
+ auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+ [websiteDataStoreConfiguration setNetworkCacheDirectory:tempDir];
+
+ auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [webViewConfiguration setWebsiteDataStore:[[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()] autorelease]];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+ [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
+ NSString *path = tempDir.path;
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ while (![fileManager fileExistsAtPath:path])
+ Util::spinRunLoop();
+ NSError *error = nil;
+ [fileManager removeItemAtPath:path error:&error];
+ EXPECT_FALSE(error);
+}
- (void)loadTestPageNamed:(NSString *)pageName;
- (void)synchronouslyLoadHTMLString:(NSString *)html;
- (void)synchronouslyLoadHTMLString:(NSString *)html baseURL:(NSURL *)url;
+- (void)synchronouslyLoadRequest:(NSURLRequest *)request;
- (void)synchronouslyLoadTestPageNamed:(NSString *)pageName;
- (BOOL)_synchronouslyExecuteEditCommand:(NSString *)command argument:(NSString *)argument;
- (void)expectElementTagsInOrder:(NSArray<NSString *> *)tagNames;
[self loadRequest:request];
}
+- (void)synchronouslyLoadRequest:(NSURLRequest *)request
+{
+ [self loadRequest:request];
+ [self _test_waitForDidFinishNavigation];
+}
+
- (void)synchronouslyLoadHTMLString:(NSString *)html baseURL:(NSURL *)url
{
[self loadHTMLString:html baseURL:url];