NetworkProcessSoup.cpp [plain text]
#include "config.h"
#include "NetworkProcess.h"
#include "NetworkCache.h"
#include "NetworkProcessCreationParameters.h"
#include "ResourceCachesToClear.h"
#include "WebCookieManager.h"
#include <WebCore/CertificateInfo.h>
#include <WebCore/FileSystem.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/ResourceHandle.h>
#include <WebCore/SoupNetworkSession.h>
#include <libsoup/soup.h>
#include <wtf/RAMSize.h>
#include <wtf/glib/GRefPtr.h>
#include <wtf/glib/GUniquePtr.h>
using namespace WebCore;
namespace WebKit {
#if !ENABLE(NETWORK_CACHE)
static uint64_t getCacheDiskFreeSize(SoupCache* cache)
{
ASSERT(cache);
GUniqueOutPtr<char> cacheDir;
g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
if (!cacheDir)
return 0;
return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
}
#endif
void NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languages)
{
SoupNetworkSession::defaultSession().setAcceptLanguages(languages);
}
void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
{
ASSERT(!parameters.diskCacheDirectory.isEmpty());
m_diskCacheDirectory = parameters.diskCacheDirectory;
#if ENABLE(NETWORK_CACHE)
SoupNetworkSession::defaultSession().clearCache(WebCore::directoryName(m_diskCacheDirectory));
NetworkCache::Cache::Parameters cacheParameters {
parameters.shouldEnableNetworkCacheEfficacyLogging
#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
, parameters.shouldEnableNetworkCacheSpeculativeRevalidation
#endif
};
NetworkCache::singleton().initialize(m_diskCacheDirectory, cacheParameters);
#else
SoupNetworkSession::defaultSession().clearCache(WebCore::directoryName(m_diskCacheDirectory));
GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(m_diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
SoupNetworkSession::defaultSession().setCache(soupCache.get());
unsigned initialMaxSize = soup_cache_get_max_size(soupCache.get());
soup_cache_set_max_size(soupCache.get(), G_MAXUINT);
soup_cache_load(soupCache.get());
soup_cache_set_max_size(soupCache.get(), initialMaxSize);
#endif
if (!parameters.cookiePersistentStoragePath.isEmpty()) {
supplement<WebCookieManager>()->setCookiePersistentStorage(parameters.cookiePersistentStoragePath,
parameters.cookiePersistentStorageType);
}
supplement<WebCookieManager>()->setHTTPCookieAcceptPolicy(parameters.cookieAcceptPolicy);
if (!parameters.languages.isEmpty())
userPreferredLanguagesChanged(parameters.languages);
setIgnoreTLSErrors(parameters.ignoreTLSErrors);
}
void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
{
unsigned cacheTotalCapacity = 0;
unsigned cacheMinDeadCapacity = 0;
unsigned cacheMaxDeadCapacity = 0;
auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
unsigned pageCacheCapacity = 0;
unsigned long urlCacheMemoryCapacity = 0;
unsigned long urlCacheDiskCapacity = 0;
#if ENABLE(NETWORK_CACHE)
uint64_t diskFreeSize = WebCore::getVolumeFreeSizeForPath(m_diskCacheDirectory.utf8().data()) / WTF::MB;
#else
SoupCache* cache = SoupNetworkSession::defaultSession().cache();
uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / WTF::MB;
#endif
uint64_t memSize = WTF::ramSize() / WTF::MB;
calculateCacheSizes(cacheModel, memSize, diskFreeSize,
cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
#if ENABLE(NETWORK_CACHE)
auto& networkCache = NetworkCache::singleton();
if (networkCache.isEnabled())
networkCache.setCapacity(urlCacheDiskCapacity);
#else
if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
soup_cache_set_max_size(cache, urlCacheDiskCapacity);
#endif
}
void NetworkProcess::setIgnoreTLSErrors(bool ignoreTLSErrors)
{
ResourceHandle::setIgnoreSSLErrors(ignoreTLSErrors);
}
void NetworkProcess::allowSpecificHTTPSCertificateForHost(const CertificateInfo& certificateInfo, const String& host)
{
ResourceHandle::setClientCertificate(host, certificateInfo.certificate());
}
void NetworkProcess::clearCacheForAllOrigins(uint32_t cachesToClear)
{
if (cachesToClear == InMemoryResourceCachesOnly)
return;
clearDiskCache(std::chrono::system_clock::time_point::min(), [] { });
}
void NetworkProcess::clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler)
{
#if ENABLE(NETWORK_CACHE)
NetworkCache::singleton().clear(modifiedSince, WTFMove(completionHandler));
#else
UNUSED_PARAM(modifiedSince);
UNUSED_PARAM(completionHandler);
soup_cache_clear(SoupNetworkSession::defaultSession().cache());
#endif
}
void NetworkProcess::platformTerminate()
{
notImplemented();
}
}