Source/WebKit/ChangeLog

 12022-03-02 Sihui Liu <sihui_liu@apple.com>
 2
 3 REGRESSION (r289474): cacheStoragePath is empty in NetworkStorageManager::localOriginStorageManager
 4 https://bugs.webkit.org/show_bug.cgi?id=237335
 5
 6 Reviewed by Chris Dumez.
 7
 8 CacheStorage::Engine::storagePath returns emptyString if salt file under rootDirectory cannot be read or
 9 written, so we need to make sure sandbox extension for rootDirectory is consumed before calling storagePath
 10 (in createNetworkStorageManager of NetworkSession).
 11
 12 This patch also refactors code about adding session in network process. Now we would create
 13 NetworkStorageManager when NetworkSession is created.
 14
 15 * NetworkProcess/NetworkConnectionToWebProcess.cpp:
 16 (WebKit::NetworkConnectionToWebProcess::updateQuotaBasedOnSpaceUsageForTesting):
 17 (WebKit::NetworkConnectionToWebProcess::writeBlobsToTemporaryFilesForIndexedDB):
 18 * NetworkProcess/NetworkProcess.cpp:
 19 (WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
 20 (WebKit::NetworkProcess::addStorageSession):
 21 (WebKit::NetworkProcess::addWebsiteDataStore):
 22 (WebKit::NetworkProcess::hasLocalStorage):
 23 (WebKit::NetworkProcess::fetchWebsiteData):
 24 (WebKit::NetworkProcess::deleteWebsiteData):
 25 (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
 26 (WebKit::NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains):
 27 (WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
 28 (WebKit::NetworkProcess::prepareToSuspend):
 29 (WebKit::NetworkProcess::resume):
 30 (WebKit::NetworkProcess::syncLocalStorage):
 31 (WebKit::NetworkProcess::resetQuota):
 32 (WebKit::NetworkProcess::clearStorage):
 33 (WebKit::NetworkProcess::didIncreaseQuota):
 34 (WebKit::NetworkProcess::renameOriginInWebsiteData):
 35 (WebKit::NetworkProcess::uiProcessBundleIdentifier):
 36 (WebKit::NetworkProcess::connectionToWebProcessClosed):
 37 (WebKit::NetworkProcess::ensureSession): Deleted.
 38 * NetworkProcess/NetworkProcess.h:
 39 (WebKit::NetworkProcess::uiProcessBundleIdentifier const): Deleted.
 40 * NetworkProcess/NetworkSession.cpp:
 41 (WebKit::createNetworkStorageManager):
 42 (WebKit::NetworkSession::NetworkSession):
 43 (WebKit::NetworkSession::invalidateAndCancel):
 44 (WebKit::NetworkSession::lowMemoryHandler):
 45 (WebKit::NetworkSession::addServiceWorkerSession): Deleted.
 46 (WebKit::NetworkSession::addStorageManagerSession): Deleted.
 47 * NetworkProcess/NetworkSession.h:
 48 (WebKit::NetworkSession::storageManager):
 49 * NetworkProcess/NetworkSessionCreationParameters.cpp:
 50 (WebKit::NetworkSessionCreationParameters::encode const):
 51 (WebKit::NetworkSessionCreationParameters::decode):
 52 * NetworkProcess/NetworkSessionCreationParameters.h:
 53 * NetworkProcess/RemoteNetworkingContext.h: Removed.
 54 * NetworkProcess/cache/CacheStorageEngine.cpp:
 55 (WebKit::CacheStorage::Engine::requestSpace):
 56 * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
 57 (WebKit::NetworkProcess::uiProcessBundleIdentifier):
 58 * NetworkProcess/curl/RemoteNetworkingContextCurl.cpp: Removed.
 59 * NetworkProcess/mac/RemoteNetworkingContext.mm: Removed.
 60 * NetworkProcess/soup/RemoteNetworkingContextSoup.cpp: Removed.
 61 * PlatformPlayStation.cmake:
 62 * PlatformWin.cmake:
 63 * Shared/WebsiteDataStoreParameters.cpp:
 64 (WebKit::WebsiteDataStoreParameters::encode const):
 65 (WebKit::WebsiteDataStoreParameters::decode):
 66 (WebKit::WebsiteDataStoreParameters::~WebsiteDataStoreParameters): Deleted.
 67 * Shared/WebsiteDataStoreParameters.h:
 68 (): Deleted.
 69 * SourcesCocoa.txt:
 70 * SourcesGTK.txt:
 71 * SourcesWPE.txt:
 72 * UIProcess/Network/NetworkProcessProxy.cpp:
 73 (WebKit::NetworkProcessProxy::addSession):
 74 * UIProcess/WebsiteData/WebsiteDataStore.cpp:
 75 (WebKit::WebsiteDataStore::parameters):
 76 * UIProcess/WebsiteData/WebsiteDataStore.h:
 77 (WebKit::WebsiteDataStore::resolvedIndexedDBDirectory const):
 78 (WebKit::WebsiteDataStore::resolvedIndexedDatabaseDirectory const): Deleted.
 79
1802022-03-02 Youenn Fablet <youenn@apple.com>
281
382 Rename MediaSampleAVFObjC::createImageSample to MediaSampleAVFObjC::createFromPixelBuffer

Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

@@bool NetworkConnectionToWebProcess::didReceiveSyncMessage(IPC::Connection& conne
409409
410410void NetworkConnectionToWebProcess::updateQuotaBasedOnSpaceUsageForTesting(const ClientOrigin& origin)
411411{
412  auto* session = m_networkProcess->networkSession(sessionID());
413  if (!session)
414  return;
415 
416  if (auto* storageManager = session->storageManager())
417  storageManager->resetQuotaUpdatedBasedOnUsageForTesting(origin);
 412 if (auto* session = m_networkProcess->networkSession(sessionID()))
 413 session->storageManager().resetQuotaUpdatedBasedOnUsageForTesting(origin);
418414}
419415
420416void NetworkConnectionToWebProcess::didClose(IPC::Connection& connection)

@@void NetworkConnectionToWebProcess::writeBlobsToTemporaryFilesForIndexedDB(const
1003999 for (auto& file : fileReferences)
10041000 file->revokeFileAccess();
10051001
1006  if (auto* session = networkSession()) {
1007  if (auto* storageManager = session->storageManager())
1008  storageManager->registerTemporaryBlobFilePaths(m_connection, filePaths);
1009  }
 1002 if (auto* session = networkSession())
 1003 session->storageManager().registerTemporaryBlobFilePaths(m_connection, filePaths);
 1004
10101005 completionHandler(WTFMove(filePaths));
10111006 });
10121007}

Source/WebKit/NetworkProcess/NetworkProcess.cpp

5151#include "NetworkStorageManager.h"
5252#include "PreconnectTask.h"
5353#include "PrivateClickMeasurementStore.h"
54 #include "RemoteNetworkingContext.h"
5554#include "ShouldGrandfatherStatistics.h"
5655#include "StorageAccessStatus.h"
5756#include "StorageManagerSet.h"

102101#include "NetworkCacheCoders.h"
103102
104103#if PLATFORM(COCOA)
 104#include "CookieStorageUtilsCF.h"
105105#include "LaunchServicesDatabaseObserver.h"
106106#include "NetworkSessionCocoa.h"
107107#include <wtf/cocoa/Entitlements.h>

@@void NetworkProcess::createNetworkConnectionToWebProcess(ProcessIdentifier ident
382382
383383 connection.setOnLineState(NetworkStateNotifier::singleton().onLine());
384384
385  if (auto* session = networkSession(sessionID)) {
386  if (auto* manager = session->storageManager())
387  manager->startReceivingMessageFromConnection(connection.connection());
388  }
 385 if (auto* session = networkSession(sessionID))
 386 session->storageManager().startReceivingMessageFromConnection(connection.connection());
389387}
390388
391389void NetworkProcess::clearCachedCredentials(PAL::SessionID sessionID)

@@void NetworkProcess::clearCachedCredentials(PAL::SessionID sessionID)
397395 }
398396}
399397
400 void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters)
 398void NetworkProcess::addStorageSession(PAL::SessionID sessionID, bool shouldUseTestingNetworkSession, const Vector<uint8_t>& uiProcessCookieStorageIdentifier, const SandboxExtension::Handle& cookieStoragePathExtensionHandle)
401399{
402  auto sessionID = parameters.networkSessionParameters.sessionID;
 400 auto addResult = m_networkStorageSessions.add(sessionID, nullptr);
 401 if (!addResult.isNewEntry)
 402 return;
403403
404  RemoteNetworkingContext::ensureWebsiteDataStoreSession(*this, parameters);
 404 if (shouldUseTestingNetworkSession) {
 405 addResult.iterator->value = newTestingSession(sessionID);
 406 return;
 407 }
405408
406  if (auto* session = networkSession(sessionID)) {
407  session->addStorageManagerSession(parameters.generalStorageDirectory, parameters.generalStorageDirectoryHandle, parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle, parameters.indexedDatabaseDirectory, parameters.indexedDatabaseDirectoryExtensionHandle, parameters.cacheStorageDirectory, parameters.perOriginStorageQuota, parameters.perThirdPartyOriginStorageQuota, parameters.shouldUseCustomStoragePaths);
 409#if PLATFORM(COCOA)
 410 RetainPtr<CFHTTPCookieStorageRef> uiProcessCookieStorage;
 411 if (!sessionID.isEphemeral() && !uiProcessCookieStorageIdentifier.isEmpty()) {
 412 SandboxExtension::consumePermanently(cookieStoragePathExtensionHandle);
 413 if (sessionID != PAL::SessionID::defaultSessionID())
 414 uiProcessCookieStorage = cookieStorageFromIdentifyingData(uiProcessCookieStorageIdentifier);
 415 }
408416
409 #if ENABLE(SERVICE_WORKER)
410  session->addServiceWorkerSession(parameters.serviceWorkerProcessTerminationDelayEnabled, WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
411 #endif
 417 auto identifierBase = makeString(uiProcessBundleIdentifier(), '.', sessionID.toUInt64());
 418 RetainPtr<CFURLStorageSessionRef> storageSession;
 419 auto cfIdentifier = makeString(identifierBase, ".PrivateBrowsing.", createVersion4UUIDString()).createCFString();
 420 if (sessionID.isEphemeral())
 421 storageSession = createPrivateStorageSession(cfIdentifier.get(), std::nullopt, WebCore::NetworkStorageSession::ShouldDisableCFURLCache::Yes);
 422 else if (sessionID != PAL::SessionID::defaultSessionID())
 423 storageSession = WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier(cfIdentifier.get());
 424
 425 if (NetworkStorageSession::processMayUseCookieAPI()) {
 426 ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
 427 if (!uiProcessCookieStorage && storageSession)
 428 uiProcessCookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
412429 }
 430
 431 addResult.iterator->value = makeUnique<NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(uiProcessCookieStorage));
 432#elif USE(CURL) || USE(SOUP)
 433 addResult.iterator->value = makeUnique<NetworkStorageSession>(sessionID);
 434#endif
 435}
 436
 437void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters)
 438{
 439 auto sessionID = parameters.networkSessionParameters.sessionID;
 440 addStorageSession(sessionID, parameters.networkSessionParameters.shouldUseTestingNetworkSession, parameters.uiProcessCookieStorageIdentifier, parameters.cookieStoragePathExtensionHandle);
 441
 442 m_networkSessions.ensure(sessionID, [&]() {
 443 return NetworkSession::create(*this, parameters.networkSessionParameters);
 444 });
 445
413446}
414447
415448void NetworkProcess::forEachNetworkSession(const Function<void(NetworkSession&)>& functor)

@@std::unique_ptr<WebCore::NetworkStorageSession> NetworkProcess::newTestingSessio
435468#endif
436469}
437470
438 #if PLATFORM(COCOA)
439 void NetworkProcess::ensureSession(PAL::SessionID sessionID, bool shouldUseTestingNetworkSession, const String& identifierBase, RetainPtr<CFHTTPCookieStorageRef>&& cookieStorage)
440 #else
441 void NetworkProcess::ensureSession(PAL::SessionID sessionID, bool shouldUseTestingNetworkSession, const String& identifierBase)
442 #endif
443 {
444  auto addResult = m_networkStorageSessions.add(sessionID, nullptr);
445  if (!addResult.isNewEntry)
446  return;
447 
448  if (shouldUseTestingNetworkSession) {
449  addResult.iterator->value = newTestingSession(sessionID);
450  return;
451  }
452 
453 #if PLATFORM(COCOA)
454  RetainPtr<CFURLStorageSessionRef> storageSession;
455  RetainPtr<CFStringRef> cfIdentifier = makeString(identifierBase, ".PrivateBrowsing.", createVersion4UUIDString()).createCFString();
456  if (sessionID.isEphemeral())
457  storageSession = createPrivateStorageSession(cfIdentifier.get(), std::nullopt, WebCore::NetworkStorageSession::ShouldDisableCFURLCache::Yes);
458  else if (sessionID != PAL::SessionID::defaultSessionID())
459  storageSession = WebCore::NetworkStorageSession::createCFStorageSessionForIdentifier(cfIdentifier.get());
460 
461  if (NetworkStorageSession::processMayUseCookieAPI()) {
462  ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
463  if (!cookieStorage && storageSession)
464  cookieStorage = adoptCF(_CFURLStorageSessionCopyCookieStorage(kCFAllocatorDefault, storageSession.get()));
465  }
466 
467  addResult.iterator->value = makeUnique<NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(cookieStorage));
468 #elif USE(CURL) || USE(SOUP)
469  addResult.iterator->value = makeUnique<NetworkStorageSession>(sessionID);
470 #endif
471 }
472 
473471void NetworkProcess::cookieAcceptPolicyChanged(HTTPCookieAcceptPolicy newPolicy)
474472{
475473 for (auto& connection : m_webProcessConnections.values())

@@void NetworkProcess::clearUserInteraction(PAL::SessionID sessionID, const Regist
999997void NetworkProcess::hasLocalStorage(PAL::SessionID sessionID, const RegistrableDomain& domain, CompletionHandler<void(bool)>&& completionHandler)
1000998{
1001999 auto* session = networkSession(sessionID);
1002  if (!session || !session->storageManager())
 1000 if (!session)
10031001 return completionHandler(false);
10041002
10051003 auto types = OptionSet<WebsiteDataType> { WebsiteDataType::LocalStorage };
1006  session->storageManager()->fetchData(types, [domain, completionHandler = WTFMove(completionHandler)](auto entries) mutable {
 1004 session->storageManager().fetchData(types, [domain, completionHandler = WTFMove(completionHandler)](auto entries) mutable {
10071005 completionHandler(WTF::anyOf(entries, [&domain](auto& entry) {
10081006 return domain.matches(entry.origin);
10091007 }));

@@void NetworkProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<Websit
14641462 }
14651463#endif
14661464
1467  if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager()) {
1468  session->storageManager()->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
 1465 if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session) {
 1466 session->storageManager().fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
14691467 callbackAggregator->m_websiteData.entries.appendVector(WTFMove(entries));
14701468 });
14711469 }

@@void NetworkProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<Websi
15271525 session->clearAlternativeServices(modifiedSince);
15281526#endif
15291527
1530  if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager())
1531  session->storageManager()->deleteDataModifiedSince(websiteDataTypes, modifiedSince, [clearTasksHandler] { });
 1528 if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session)
 1529 session->storageManager().deleteDataModifiedSince(websiteDataTypes, modifiedSince, [clearTasksHandler] { });
15321530}
15331531
15341532static void clearDiskCacheEntries(NetworkCache::Cache* cache, const Vector<SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)

@@void NetworkProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, Optio
16201618 }
16211619#endif
16221620
1623  if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager())
1624  session->storageManager()->deleteData(websiteDataTypes, originDatas, [clearTasksHandler] { });
 1621 if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session)
 1622 session->storageManager().deleteData(websiteDataTypes, originDatas, [clearTasksHandler] { });
16251623
16261624 if (session) {
16271625 HashSet<WebCore::RegistrableDomain> domainsToDeleteNetworkDataFor;

@@void NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains(PAL::Sess
18121810 });
18131811 }
18141812
1815  if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager()) {
1816  session->storageManager()->deleteDataForRegistrableDomains(websiteDataTypes, domainsToDeleteAllNonCookieWebsiteDataFor, [callbackAggregator](auto&& deletedDomains) mutable {
 1813 if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session) {
 1814 session->storageManager().deleteDataForRegistrableDomains(websiteDataTypes, domainsToDeleteAllNonCookieWebsiteDataFor, [callbackAggregator](auto&& deletedDomains) mutable {
18171815 for (auto domain : deletedDomains)
18181816 callbackAggregator->m_domains.add(WTFMove(domain));
18191817 });

@@void NetworkProcess::registrableDomainsWithWebsiteData(PAL::SessionID sessionID,
19291927 });
19301928 }
19311929
1932  if (session && session->storageManager()) {
1933  session->storageManager()->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
 1930 if (session) {
 1931 session->storageManager().fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
19341932 callbackAggregator->m_websiteData.entries.appendVector(WTFMove(entries));
19351933 });
19361934 }

@@void NetworkProcess::prepareToSuspend(bool isSuspensionImminent, CompletionHandl
21022100 if (auto* swServer = session.swServer())
21032101 swServer->startSuspension([callbackAggregator] { });
21042102#endif
2105  if (auto* storageManager = session.storageManager())
2106  storageManager->suspend([callbackAggregator] { });
 2103 session.storageManager().suspend([callbackAggregator] { });
21072104 });
21082105
21092106 for (auto& connection : m_webProcessConnections.values())

@@void NetworkProcess::resume()
21412138 if (auto* swServer = session.swServer())
21422139 swServer->endSuspension();
21432140#endif
2144  if (auto* manager = session.storageManager())
2145  manager->resume();
 2141 session.storageManager().resume();
21462142 });
21472143}
21482144

@@void NetworkProcess::syncLocalStorage(CompletionHandler<void()>&& completionHand
21752171{
21762172 auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
21772173 forEachNetworkSession([&](auto& session) {
2178  if (auto* manager = session.storageManager())
2179  manager->syncLocalStorage([aggregator] { });
 2174 session.storageManager().syncLocalStorage([aggregator] { });
21802175 });
21812176}
21822177
21832178void NetworkProcess::resetQuota(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
21842179{
2185  auto* session = networkSession(sessionID);
2186  if (!session)
2187  return completionHandler();
2188 
2189  auto* storageManager = session->storageManager();
2190  if (!storageManager)
2191  return completionHandler();
 2180 if (auto* session = networkSession(sessionID))
 2181 return session->storageManager().resetQuotaForTesting(WTFMove(completionHandler));
21922182
2193  storageManager->resetQuotaForTesting(WTFMove(completionHandler));
 2183 completionHandler();
21942184}
21952185
21962186void NetworkProcess::clearStorage(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
21972187{
2198  auto* session = networkSession(sessionID);
2199  if (auto* manager = session ? session->storageManager() : nullptr)
2200  manager->clearStorageForTesting(WTFMove(completionHandler));
 2188 if (auto* session = networkSession(sessionID))
 2189 session->storageManager().clearStorageForTesting(WTFMove(completionHandler));
22012190 else
22022191 completionHandler();
22032192}
22042193
22052194void NetworkProcess::didIncreaseQuota(PAL::SessionID sessionID, const ClientOrigin& origin, QuotaIncreaseRequestIdentifier identifier, std::optional<uint64_t> newQuota)
22062195{
2207  auto* session = networkSession(sessionID);
2208  if (!session)
2209  return;
2210 
2211  if (auto* manager = session->storageManager())
2212  manager->didIncreaseQuota(origin, identifier, newQuota);
 2196 if (auto* session = networkSession(sessionID))
 2197 session->storageManager().didIncreaseQuota(origin, identifier, newQuota);
22132198}
22142199
22152200void NetworkProcess::renameOriginInWebsiteData(PAL::SessionID sessionID, const URL& oldName, const URL& newName, OptionSet<WebsiteDataType> dataTypes, CompletionHandler<void()>&& completionHandler)

@@void NetworkProcess::renameOriginInWebsiteData(PAL::SessionID sessionID, const U
22212206 if (oldOrigin.isEmpty() || newOrigin.isEmpty())
22222207 return;
22232208
2224  auto* session = networkSession(sessionID);
2225  if (auto* manager = session ? session->storageManager() : nullptr)
2226  manager->moveData(dataTypes, oldOrigin, newOrigin, [aggregator] { });
 2209 if (auto* session = networkSession(sessionID))
 2210 session->storageManager().moveData(dataTypes, oldOrigin, newOrigin, [aggregator] { });
22272211}
22282212
22292213#if ENABLE(SERVICE_WORKER)

@@void NetworkProcess::removeKeptAliveLoad(NetworkResourceLoader& loader)
24772461
24782462void NetworkProcess::connectionToWebProcessClosed(IPC::Connection& connection, PAL::SessionID sessionID)
24792463{
2480  if (auto* session = networkSession(sessionID)) {
2481  if (auto* manager = session->storageManager())
2482  manager->stopReceivingMessageFromConnection(connection);
2483  }
 2464 if (auto* session = networkSession(sessionID))
 2465 session->storageManager().stopReceivingMessageFromConnection(connection);
24842466}
24852467
24862468NetworkConnectionToWebProcess* NetworkProcess::webProcessConnection(ProcessIdentifier identifier) const

Source/WebKit/NetworkProcess/NetworkProcess.h

@@public:
169169 void forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>&);
170170 WebCore::NetworkStorageSession* storageSession(PAL::SessionID) const;
171171 std::unique_ptr<WebCore::NetworkStorageSession> newTestingSession(PAL::SessionID);
172 #if PLATFORM(COCOA)
173  void ensureSession(PAL::SessionID, bool shouldUseTestingNetworkSession, const String& identifier, RetainPtr<CFHTTPCookieStorageRef>&&);
174 #else
175  void ensureSession(PAL::SessionID, bool shouldUseTestingNetworkSession, const String& identifier);
176 #endif
 172 void addStorageSession(PAL::SessionID, bool shouldUseTestingNetworkSession, const Vector<uint8_t>& uiProcessCookieStorageIdentifier, const SandboxExtension::Handle&);
177173
178174 void processWillSuspendImminentlyForTestingSync(CompletionHandler<void()>&&);
179175 void prepareToSuspend(bool isSuspensionImminent, CompletionHandler<void()>&&);

@@public:
305301 bool parentProcessHasServiceWorkerEntitlement() const { return true; }
306302#endif
307303
308  const String& uiProcessBundleIdentifier() const { return m_uiProcessBundleIdentifier; }
 304 const String& uiProcessBundleIdentifier() const;
309305
310306 void ref() const override { ThreadSafeRefCounted<NetworkProcess>::ref(); }
311307 void deref() const override { ThreadSafeRefCounted<NetworkProcess>::deref(); }

@@private:
483479 bool m_hasSetCacheModel { false };
484480 CacheModel m_cacheModel { CacheModel::DocumentViewer };
485481 bool m_suppressMemoryPressureHandler { false };
486  String m_uiProcessBundleIdentifier;
 482 mutable String m_uiProcessBundleIdentifier;
487483 DownloadManager m_downloadManager;
488484
489485 typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;

@@private:
528524 bool m_ftpEnabled { false };
529525};
530526
 527#if !PLATFORM(COCOA)
 528inline const String& NetworkProcess::uiProcessBundleIdentifier() const
 529{
 530 return m_uiProcessBundleIdentifier;
 531}
 532#endif
 533
531534} // namespace WebKit

Source/WebKit/NetworkProcess/NetworkSession.cpp

@@static UniqueRef<PCM::ManagerInterface> managerOrProxy(NetworkSession& networkSe
111111 return makeUniqueRef<PrivateClickMeasurementManager>(makeUniqueRef<PCM::ClientImpl>(networkSession, networkProcess), pcmStoreDirectory(networkSession, parameters.resourceLoadStatisticsParameters.directory, parameters.resourceLoadStatisticsParameters.privateClickMeasurementStorageDirectory));
112112}
113113
 114static Ref<NetworkStorageManager> createNetworkStorageManager(IPC::Connection* connection, const NetworkSessionCreationParameters& parameters)
 115{
 116 SandboxExtension::consumePermanently(parameters.localStorageDirectoryExtensionHandle);
 117 SandboxExtension::consumePermanently(parameters.indexedDBDirectoryExtensionHandle);
 118 SandboxExtension::consumePermanently(parameters.cacheStorageDirectoryExtensionHandle);
 119 SandboxExtension::consumePermanently(parameters.generalStorageDirectoryHandle);
 120 IPC::Connection::UniqueID connectionID;
 121 if (connection)
 122 connectionID = connection->uniqueID();
 123 return NetworkStorageManager::create(parameters.sessionID, connectionID, parameters.generalStorageDirectory, parameters.localStorageDirectory, parameters.indexedDBDirectory, parameters.cacheStorageDirectory, parameters.perOriginStorageQuota, parameters.perThirdPartyOriginStorageQuota, parameters.shouldUseCustomStoragePaths);
 124}
 125
114126NetworkSession::NetworkSession(NetworkProcess& networkProcess, const NetworkSessionCreationParameters& parameters)
115127 : m_sessionID(parameters.sessionID)
116128 , m_networkProcess(networkProcess)

@@NetworkSession::NetworkSession(NetworkProcess& networkProcess, const NetworkSess
131143 , m_testSpeedMultiplier(parameters.testSpeedMultiplier)
132144 , m_allowsServerPreconnect(parameters.allowsServerPreconnect)
133145 , m_shouldRunServiceWorkersOnMainThreadForTesting(parameters.shouldRunServiceWorkersOnMainThreadForTesting)
 146 , m_storageManager(createNetworkStorageManager(networkProcess.parentProcessConnection(), parameters))
134147#if ENABLE(BUILT_IN_NOTIFICATIONS)
135148 , m_notificationManager(*this, parameters.webPushMachServiceName)
136149#endif

@@NetworkSession::NetworkSession(NetworkProcess& networkProcess, const NetworkSess
169182 setResourceLoadStatisticsEnabled(parameters.resourceLoadStatisticsParameters.enabled);
170183#endif
171184
 185#if ENABLE(SERVICE_WORKER)
 186 SandboxExtension::consumePermanently(parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
 187 m_serviceWorkerInfo = ServiceWorkerInfo {
 188 parameters.serviceWorkerRegistrationDirectory,
 189 parameters.serviceWorkerProcessTerminationDelayEnabled
 190 };
 191#endif
 192
172193#if ENABLE(BUILT_IN_NOTIFICATIONS)
173194 m_networkProcess->addMessageReceiver(Messages::NotificationManagerMessageHandler::messageReceiverName(), m_sessionID.toUInt64(), m_notificationManager);
174195#endif

@@void NetworkSession::invalidateAndCancel()
206227 if (m_resourceLoadStatistics)
207228 m_resourceLoadStatistics->invalidateAndCancel();
208229#endif
209  if (auto manager = std::exchange(m_storageManager, nullptr))
210  manager->close();
 230 m_storageManager->close();
211231 m_cacheEngine = nullptr;
212232#if ASSERT_ENABLED
213233 m_isInvalidated = true;

@@void NetworkSession::lowMemoryHandler(Critical)
568588 if (m_swServer)
569589 m_swServer->handleLowMemoryWarning();
570590#endif
571  if (m_storageManager)
572  m_storageManager->handleLowMemoryWarning();
 591 m_storageManager->handleLowMemoryWarning();
573592}
574593
575594#if ENABLE(SERVICE_WORKER)

@@SWServer& NetworkSession::ensureSWServer()
635654 return *m_swServer;
636655}
637656
638 void NetworkSession::addServiceWorkerSession(bool processTerminationDelayEnabled, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle& handle)
639 {
640  bool hadServiceWorkerInfo = !!m_serviceWorkerInfo;
641  m_serviceWorkerInfo = ServiceWorkerInfo {
642  WTFMove(serviceWorkerRegistrationDirectory),
643  processTerminationDelayEnabled
644  };
645  if (!hadServiceWorkerInfo)
646  SandboxExtension::consumePermanently(handle);
647 }
648 
649657bool NetworkSession::hasServiceWorkerDatabasePath() const
650658{
651659 return m_serviceWorkerInfo && !m_serviceWorkerInfo->databasePath.isEmpty();

@@WebSharedWorkerServer& NetworkSession::ensureSharedWorkerServer()
660668 return *m_sharedWorkerServer;
661669}
662670
663 void NetworkSession::addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle, const String& idbStoragePath, SandboxExtension::Handle& idbStoragePathHandle, const String& cacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyQuota, bool shouldUseCustomStoragePaths)
664 {
665  if (m_storageManager)
666  return;
667 
668  SandboxExtension::consumePermanently(generalStoragePathHandle);
669  SandboxExtension::consumePermanently(localStoragePathHandle);
670  SandboxExtension::consumePermanently(idbStoragePathHandle);
671  IPC::Connection::UniqueID connectionID;
672  if (auto* connection = networkProcess().parentProcessConnection())
673  connectionID = connection->uniqueID();
674  m_storageManager = NetworkStorageManager::create(sessionID(), connectionID, generalStoragePath, localStoragePath, idbStoragePath, cacheStoragePath, defaultOriginQuota, defaultThirdPartyQuota, shouldUseCustomStoragePaths);
675 }
676 
677671void NetworkSession::ensureCacheEngine(Function<void(CacheStorage::Engine&)>&& callback)
678672{
679673 if (m_cacheEngine)

Source/WebKit/NetworkProcess/NetworkSession.h

@@public:
208208 void unregisterSWServerConnection(WebSWServerConnection&);
209209
210210 bool hasServiceWorkerDatabasePath() const;
211 
212  void addServiceWorkerSession(bool processTerminationDelayEnabled, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
213211#endif
214212
215213 WebSharedWorkerServer* sharedWorkerServer() { return m_sharedWorkerServer.get(); }
216214 WebSharedWorkerServer& ensureSharedWorkerServer();
217215
218  NetworkStorageManager* storageManager() { return m_storageManager.get(); }
219  void addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle, const String& idbStoragePath, SandboxExtension::Handle& idbStoragePathHandle, const String& cacheStoragePath, uint64_t defaultOriginQuota, uint64_t defaultThirdPartyQuota, bool shouldUseCustomStoragePaths);
220 
 216 NetworkStorageManager& storageManager() { return m_storageManager.get(); }
221217 CacheStorage::Engine* cacheEngine() { return m_cacheEngine.get(); }
222218 void ensureCacheEngine(Function<void(CacheStorage::Engine&)>&&);
223219 void clearCacheEngine();

@@protected:
320316#endif
321317 std::unique_ptr<WebSharedWorkerServer> m_sharedWorkerServer;
322318
323  RefPtr<NetworkStorageManager> m_storageManager;
 319 Ref<NetworkStorageManager> m_storageManager;
324320 RefPtr<CacheStorage::Engine> m_cacheEngine;
325321 Vector<Function<void(CacheStorage::Engine&)>> m_cacheStorageParametersCallbacks;
326322

Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp

@@void NetworkSessionCreationParameters::encode(IPC::Encoder& encoder) const
9595#if !HAVE(NSURLSESSION_WEBSOCKET)
9696 encoder << shouldAcceptInsecureCertificatesForWebSockets;
9797#endif
 98
 99 encoder << shouldUseCustomStoragePaths;
 100 encoder << perOriginStorageQuota << perThirdPartyOriginStorageQuota;
 101 encoder << localStorageDirectory << localStorageDirectoryExtensionHandle;
 102 encoder << indexedDBDirectory << indexedDBDirectoryExtensionHandle;
 103 encoder << cacheStorageDirectory << cacheStorageDirectoryExtensionHandle;
 104 encoder << generalStorageDirectory << generalStorageDirectoryHandle;
 105#if ENABLE(SERVICE_WORKER)
 106 encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle << serviceWorkerProcessTerminationDelayEnabled;
 107#endif
98108 encoder << resourceLoadStatisticsParameters;
99109}
100110

@@std::optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters
334344 return std::nullopt;
335345#endif
336346
 347 std::optional<bool> shouldUseCustomStoragePaths;
 348 decoder >> shouldUseCustomStoragePaths;
 349 if (!shouldUseCustomStoragePaths)
 350 return std::nullopt;
 351
 352 std::optional<uint64_t> perOriginStorageQuota;
 353 decoder >> perOriginStorageQuota;
 354 if (!perOriginStorageQuota)
 355 return std::nullopt;
 356
 357 std::optional<uint64_t> perThirdPartyOriginStorageQuota;
 358 decoder >> perThirdPartyOriginStorageQuota;
 359 if (!perThirdPartyOriginStorageQuota)
 360 return std::nullopt;
 361
 362 std::optional<String> localStorageDirectory;
 363 decoder >> localStorageDirectory;
 364 if (!localStorageDirectory)
 365 return std::nullopt;
 366
 367 std::optional<SandboxExtension::Handle> localStorageDirectoryExtensionHandle;
 368 decoder >> localStorageDirectoryExtensionHandle;
 369 if (!localStorageDirectoryExtensionHandle)
 370 return std::nullopt;
 371
 372 std::optional<String> indexedDBDirectory;
 373 decoder >> indexedDBDirectory;
 374 if (!indexedDBDirectory)
 375 return std::nullopt;
 376
 377 std::optional<SandboxExtension::Handle> indexedDBDirectoryExtensionHandle;
 378 decoder >> indexedDBDirectoryExtensionHandle;
 379 if (!indexedDBDirectoryExtensionHandle)
 380 return std::nullopt;
 381
 382 std::optional<String> cacheStorageDirectory;
 383 decoder >> cacheStorageDirectory;
 384 if (!cacheStorageDirectory)
 385 return std::nullopt;
 386
 387 std::optional<SandboxExtension::Handle> cacheStorageDirectoryExtensionHandle;
 388 decoder >> cacheStorageDirectoryExtensionHandle;
 389 if (!cacheStorageDirectoryExtensionHandle)
 390 return std::nullopt;
 391
 392 std::optional<String> generalStorageDirectory;
 393 decoder >> generalStorageDirectory;
 394 if (!generalStorageDirectory)
 395 return std::nullopt;
 396
 397 std::optional<SandboxExtension::Handle> generalStorageDirectoryHandle;
 398 decoder >> generalStorageDirectoryHandle;
 399 if (!generalStorageDirectoryHandle)
 400 return std::nullopt;
 401
 402#if ENABLE(SERVICE_WORKER)
 403 std::optional<String> serviceWorkerRegistrationDirectory;
 404 decoder >> serviceWorkerRegistrationDirectory;
 405 if (!serviceWorkerRegistrationDirectory)
 406 return std::nullopt;
 407
 408 std::optional<SandboxExtension::Handle> serviceWorkerRegistrationDirectoryExtensionHandle;
 409 decoder >> serviceWorkerRegistrationDirectoryExtensionHandle;
 410 if (!serviceWorkerRegistrationDirectoryExtensionHandle)
 411 return std::nullopt;
 412
 413 std::optional<bool> serviceWorkerProcessTerminationDelayEnabled;
 414 decoder >> serviceWorkerProcessTerminationDelayEnabled;
 415 if (!serviceWorkerProcessTerminationDelayEnabled)
 416 return std::nullopt;
 417#endif
 418
337419 std::optional<ResourceLoadStatisticsParameters> resourceLoadStatisticsParameters;
338420 decoder >> resourceLoadStatisticsParameters;
339421 if (!resourceLoadStatisticsParameters)

@@std::optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters
394476 , WTFMove(*enablePrivateClickMeasurementDebugMode)
395477#if !HAVE(NSURLSESSION_WEBSOCKET)
396478 , WTFMove(*shouldAcceptInsecureCertificatesForWebSockets)
 479#endif
 480 , *shouldUseCustomStoragePaths
 481 , WTFMove(*perOriginStorageQuota)
 482 , WTFMove(*perThirdPartyOriginStorageQuota)
 483 , WTFMove(*localStorageDirectory)
 484 , WTFMove(*localStorageDirectoryExtensionHandle)
 485 , WTFMove(*indexedDBDirectory)
 486 , WTFMove(*indexedDBDirectoryExtensionHandle)
 487 , WTFMove(*cacheStorageDirectory)
 488 , WTFMove(*cacheStorageDirectoryExtensionHandle)
 489 , WTFMove(*generalStorageDirectory)
 490 , WTFMove(*generalStorageDirectoryHandle)
 491#if ENABLE(SERVICE_WORKER)
 492 , WTFMove(*serviceWorkerRegistrationDirectory)
 493 , WTFMove(*serviceWorkerRegistrationDirectoryExtensionHandle)
 494 , *serviceWorkerProcessTerminationDelayEnabled
397495#endif
398496 , WTFMove(*resourceLoadStatisticsParameters)
399497 }};

Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h

@@struct NetworkSessionCreationParameters {
112112 bool shouldAcceptInsecureCertificatesForWebSockets { false };
113113#endif
114114
 115 bool shouldUseCustomStoragePaths { false };
 116 uint64_t perOriginStorageQuota;
 117 uint64_t perThirdPartyOriginStorageQuota;
 118 String localStorageDirectory;
 119 SandboxExtension::Handle localStorageDirectoryExtensionHandle;
 120 String indexedDBDirectory;
 121 SandboxExtension::Handle indexedDBDirectoryExtensionHandle;
 122 String cacheStorageDirectory;
 123 SandboxExtension::Handle cacheStorageDirectoryExtensionHandle;
 124 String generalStorageDirectory;
 125 SandboxExtension::Handle generalStorageDirectoryHandle;
 126#if ENABLE(SERVICE_WORKER)
 127 String serviceWorkerRegistrationDirectory;
 128 SandboxExtension::Handle serviceWorkerRegistrationDirectoryExtensionHandle;
 129 bool serviceWorkerProcessTerminationDelayEnabled { true };
 130#endif
 131
115132 ResourceLoadStatisticsParameters resourceLoadStatisticsParameters;
116133};
117134

Source/WebKit/NetworkProcess/RemoteNetworkingContext.h

1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  * Copyright (C) 2013 University of Szeged. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24  * THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #pragma once
28 
29 namespace WebKit {
30 
31 class NetworkProcess;
32 struct WebsiteDataStoreParameters;
33 
34 class RemoteNetworkingContext {
35 public:
36  // FIXME: Remove platform-specific code.
37  static void ensureWebsiteDataStoreSession(NetworkProcess&, const WebsiteDataStoreParameters&);
38 };
39 
40 }

Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

@@void Engine::requestSpace(const WebCore::ClientOrigin& origin, uint64_t spaceReq
245245 if (!session)
246246 callback(false);
247247
248  auto* storageManager = session->storageManager();
249  if (!storageManager)
250  callback(false);
251 
252  storageManager->requestSpace(origin, spaceRequested, WTFMove(callback));
 248 session->storageManager().requestSpace(origin, spaceRequested, WTFMove(callback));
253249}
254250
255251Engine::Engine(NetworkSession& networkSession, String&& rootPath)

Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm

@@void NetworkProcess::notifyPreferencesChanged(const String& domain, const String
255255}
256256#endif
257257
 258const String& NetworkProcess::uiProcessBundleIdentifier() const
 259{
 260 if (m_uiProcessBundleIdentifier.isNull())
 261 m_uiProcessBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
 262
 263 return m_uiProcessBundleIdentifier;
 264}
 265
258266} // namespace WebKit

Source/WebKit/NetworkProcess/curl/RemoteNetworkingContextCurl.cpp

1 /*
2  * Copyright (C) 2017 Sony Interactive Entertainment Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "RemoteNetworkingContext.h"
28 
29 #include "NetworkProcess.h"
30 #include "NetworkSession.h"
31 #include "WebsiteDataStoreParameters.h"
32 #include <WebCore/NetworkStorageSession.h>
33 
34 namespace WebKit {
35 
36 using namespace WebCore;
37 
38 void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, const WebsiteDataStoreParameters& parameters)
39 {
40  auto sessionID = parameters.networkSessionParameters.sessionID;
41  if (networkProcess.storageSession(sessionID))
42  return;
43 
44  networkProcess.ensureSession(sessionID, parameters.networkSessionParameters.shouldUseTestingNetworkSession, String::number(sessionID.toUInt64()));
45  networkProcess.setSession(sessionID, NetworkSession::create(networkProcess, parameters.networkSessionParameters));
46 }
47 
48 }

Source/WebKit/NetworkProcess/mac/RemoteNetworkingContext.mm

1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #import "config.h"
27 #import "RemoteNetworkingContext.h"
28 
29 #import "CookieStorageUtilsCF.h"
30 #import "LegacyCustomProtocolManager.h"
31 #import "NetworkProcess.h"
32 #import "NetworkSession.h"
33 #import "NetworkSessionCreationParameters.h"
34 #import "WebErrors.h"
35 #import "WebsiteDataStoreParameters.h"
36 #import <WebCore/NetworkStorageSession.h>
37 #import <WebCore/ResourceError.h>
38 #import <pal/SessionID.h>
39 #import <wtf/MainThread.h>
40 #import <wtf/text/StringConcatenateNumbers.h>
41 
42 namespace WebKit {
43 
44 void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, const WebsiteDataStoreParameters& parameters)
45 {
46  auto sessionID = parameters.networkSessionParameters.sessionID;
47  if (networkProcess.storageSession(sessionID))
48  return;
49 
50  String base = networkProcess.uiProcessBundleIdentifier();
51  if (base.isNull())
52  base = [[NSBundle mainBundle] bundleIdentifier];
53 
54  if (!sessionID.isEphemeral())
55  SandboxExtension::consumePermanently(parameters.cookieStoragePathExtensionHandle);
56 
57  RetainPtr<CFHTTPCookieStorageRef> uiProcessCookieStorage;
58  if (!sessionID.isEphemeral() && !parameters.uiProcessCookieStorageIdentifier.isEmpty() && parameters.networkSessionParameters.sessionID != PAL::SessionID::defaultSessionID())
59  uiProcessCookieStorage = cookieStorageFromIdentifyingData(parameters.uiProcessCookieStorageIdentifier);
60 
61  networkProcess.ensureSession(sessionID, parameters.networkSessionParameters.shouldUseTestingNetworkSession, makeString(base, '.', sessionID.toUInt64()), WTFMove(uiProcessCookieStorage));
62 
63  networkProcess.setSession(sessionID, NetworkSession::create(networkProcess, parameters.networkSessionParameters));
64 }
65 
66 }

Source/WebKit/NetworkProcess/soup/RemoteNetworkingContextSoup.cpp

1 /*
2  * Copyright (C) 2013 Apple Inc. All rights reserved.
3  * Copyright (C) 2013 University of Szeged. All rights reserved.
4  * Copyright (C) 2013 Company 100 Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "config.h"
29 #include "RemoteNetworkingContext.h"
30 
31 #include "NetworkProcess.h"
32 #include "NetworkSession.h"
33 #include "WebsiteDataStoreParameters.h"
34 #include <WebCore/NetworkStorageSession.h>
35 
36 namespace WebKit {
37 using namespace WebCore;
38 
39 void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, const WebsiteDataStoreParameters& parameters)
40 {
41  auto sessionID = parameters.networkSessionParameters.sessionID;
42  if (networkProcess.storageSession(sessionID))
43  return;
44 
45  networkProcess.ensureSession(sessionID, parameters.networkSessionParameters.shouldUseTestingNetworkSession, String::number(sessionID.toUInt64()));
46  networkProcess.setSession(sessionID, NetworkSession::create(networkProcess, parameters.networkSessionParameters));
47 }
48 
49 }

Source/WebKit/PlatformPlayStation.cmake

@@list(APPEND WebKit_SOURCES
4848 NetworkProcess/curl/NetworkProcessCurl.cpp
4949 NetworkProcess/curl/NetworkProcessMainCurl.cpp
5050 NetworkProcess/curl/NetworkSessionCurl.cpp
51  NetworkProcess/curl/RemoteNetworkingContextCurl.cpp
5251
5352 Platform/IPC/unix/AttachmentUnix.cpp
5453 Platform/IPC/unix/ConnectionUnix.cpp

Source/WebKit/PlatformWin.cmake

@@if (${WTF_PLATFORM_WIN_CAIRO})
176176 NetworkProcess/curl/NetworkDataTaskCurl.cpp
177177 NetworkProcess/curl/NetworkProcessCurl.cpp
178178 NetworkProcess/curl/NetworkSessionCurl.cpp
179  NetworkProcess/curl/RemoteNetworkingContextCurl.cpp
180179
181180 Shared/API/c/cairo/WKImageCairo.cpp
182181

Source/WebKit/Shared/WebsiteDataStoreParameters.cpp

3131
3232namespace WebKit {
3333
34 WebsiteDataStoreParameters::~WebsiteDataStoreParameters()
35 {
36 }
 34WebsiteDataStoreParameters::~WebsiteDataStoreParameters() = default;
3735
3836void WebsiteDataStoreParameters::encode(IPC::Encoder& encoder) const
3937{
4038 encoder << networkSessionParameters;
4139 encoder << uiProcessCookieStorageIdentifier;
4240 encoder << cookieStoragePathExtensionHandle;
43  encoder << indexedDatabaseDirectory << indexedDatabaseDirectoryExtensionHandle;
44 
45 #if ENABLE(SERVICE_WORKER)
46  encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle << serviceWorkerProcessTerminationDelayEnabled;
47 #endif
48 
49  encoder << localStorageDirectory << localStorageDirectoryExtensionHandle;
50  encoder << cacheStorageDirectory << cacheStorageDirectoryExtensionHandle;
51  encoder << generalStorageDirectory << generalStorageDirectoryHandle;
52 
53  encoder << perOriginStorageQuota;
54  encoder << perThirdPartyOriginStorageQuota;
55 
56  encoder << shouldUseCustomStoragePaths;
5741}
5842
5943std::optional<WebsiteDataStoreParameters> WebsiteDataStoreParameters::decode(IPC::Decoder& decoder)

@@std::optional<WebsiteDataStoreParameters> WebsiteDataStoreParameters::decode(IPC
7862 return std::nullopt;
7963 parameters.cookieStoragePathExtensionHandle = WTFMove(*cookieStoragePathExtensionHandle);
8064
81  std::optional<String> indexedDatabaseDirectory;
82  decoder >> indexedDatabaseDirectory;
83  if (!indexedDatabaseDirectory)
84  return std::nullopt;
85  parameters.indexedDatabaseDirectory = WTFMove(*indexedDatabaseDirectory);
86 
87  std::optional<SandboxExtension::Handle> indexedDatabaseDirectoryExtensionHandle;
88  decoder >> indexedDatabaseDirectoryExtensionHandle;
89  if (!indexedDatabaseDirectoryExtensionHandle)
90  return std::nullopt;
91  parameters.indexedDatabaseDirectoryExtensionHandle = WTFMove(*indexedDatabaseDirectoryExtensionHandle);
92 
93 #if ENABLE(SERVICE_WORKER)
94  std::optional<String> serviceWorkerRegistrationDirectory;
95  decoder >> serviceWorkerRegistrationDirectory;
96  if (!serviceWorkerRegistrationDirectory)
97  return std::nullopt;
98  parameters.serviceWorkerRegistrationDirectory = WTFMove(*serviceWorkerRegistrationDirectory);
99 
100  std::optional<SandboxExtension::Handle> serviceWorkerRegistrationDirectoryExtensionHandle;
101  decoder >> serviceWorkerRegistrationDirectoryExtensionHandle;
102  if (!serviceWorkerRegistrationDirectoryExtensionHandle)
103  return std::nullopt;
104  parameters.serviceWorkerRegistrationDirectoryExtensionHandle = WTFMove(*serviceWorkerRegistrationDirectoryExtensionHandle);
105 
106  std::optional<bool> serviceWorkerProcessTerminationDelayEnabled;
107  decoder >> serviceWorkerProcessTerminationDelayEnabled;
108  if (!serviceWorkerProcessTerminationDelayEnabled)
109  return std::nullopt;
110  parameters.serviceWorkerProcessTerminationDelayEnabled = WTFMove(*serviceWorkerProcessTerminationDelayEnabled);
111 #endif
112 
113  std::optional<String> localStorageDirectory;
114  decoder >> localStorageDirectory;
115  if (!localStorageDirectory)
116  return std::nullopt;
117  parameters.localStorageDirectory = WTFMove(*localStorageDirectory);
118 
119  std::optional<SandboxExtension::Handle> localStorageDirectoryExtensionHandle;
120  decoder >> localStorageDirectoryExtensionHandle;
121  if (!localStorageDirectoryExtensionHandle)
122  return std::nullopt;
123  parameters.localStorageDirectoryExtensionHandle = WTFMove(*localStorageDirectoryExtensionHandle);
124 
125  std::optional<String> cacheStorageDirectory;
126  decoder >> cacheStorageDirectory;
127  if (!cacheStorageDirectory)
128  return std::nullopt;
129  parameters.cacheStorageDirectory = WTFMove(*cacheStorageDirectory);
130 
131  std::optional<SandboxExtension::Handle> cacheStorageDirectoryExtensionHandle;
132  decoder >> cacheStorageDirectoryExtensionHandle;
133  if (!cacheStorageDirectoryExtensionHandle)
134  return std::nullopt;
135  parameters.cacheStorageDirectoryExtensionHandle = WTFMove(*cacheStorageDirectoryExtensionHandle);
136 
137  std::optional<String> generalStorageDirectory;
138  decoder >> generalStorageDirectory;
139  if (!generalStorageDirectory)
140  return std::nullopt;
141  parameters.generalStorageDirectory = WTFMove(*generalStorageDirectory);
142 
143  std::optional<SandboxExtension::Handle> generalStorageDirectoryHandle;
144  decoder >> generalStorageDirectoryHandle;
145  if (!generalStorageDirectoryHandle)
146  return std::nullopt;
147  parameters.generalStorageDirectoryHandle = WTFMove(*generalStorageDirectoryHandle);
148 
149  std::optional<uint64_t> perOriginStorageQuota;
150  decoder >> perOriginStorageQuota;
151  if (!perOriginStorageQuota)
152  return std::nullopt;
153  parameters.perOriginStorageQuota = *perOriginStorageQuota;
154 
155  std::optional<uint64_t> perThirdPartyOriginStorageQuota;
156  decoder >> perThirdPartyOriginStorageQuota;
157  if (!perThirdPartyOriginStorageQuota)
158  return std::nullopt;
159  parameters.perThirdPartyOriginStorageQuota = *perThirdPartyOriginStorageQuota;
160 
161  std::optional<bool> shouldUseCustomStoragePaths;
162  decoder >> shouldUseCustomStoragePaths;
163  if (!shouldUseCustomStoragePaths)
164  return std::nullopt;
165  parameters.shouldUseCustomStoragePaths = *shouldUseCustomStoragePaths;
166 
16765 return parameters;
16866}
16967

Source/WebKit/Shared/WebsiteDataStoreParameters.h

@@struct WebsiteDataStoreParameters {
5252 Vector<uint8_t> uiProcessCookieStorageIdentifier;
5353 SandboxExtension::Handle cookieStoragePathExtensionHandle;
5454 NetworkSessionCreationParameters networkSessionParameters;
55 
56  String indexedDatabaseDirectory;
57  SandboxExtension::Handle indexedDatabaseDirectoryExtensionHandle;
58 
59 #if ENABLE(SERVICE_WORKER)
60  String serviceWorkerRegistrationDirectory;
61  SandboxExtension::Handle serviceWorkerRegistrationDirectoryExtensionHandle;
62  bool serviceWorkerProcessTerminationDelayEnabled { true };
63 #endif
64 
65  String localStorageDirectory;
66  SandboxExtension::Handle localStorageDirectoryExtensionHandle;
67 
68  String cacheStorageDirectory;
69  SandboxExtension::Handle cacheStorageDirectoryExtensionHandle;
70 
71  String generalStorageDirectory;
72  SandboxExtension::Handle generalStorageDirectoryHandle;
73 
74  uint64_t perOriginStorageQuota;
75  uint64_t perThirdPartyOriginStorageQuota;
76 
77  bool shouldUseCustomStoragePaths { false };
7855};
7956
8057} // namespace WebKit

Source/WebKit/SourcesCocoa.txt

@@NetworkProcess/ios/NetworkConnectionToWebProcessIOS.mm
5454NetworkProcess/ios/NetworkProcessIOS.mm
5555
5656NetworkProcess/mac/NetworkProcessMac.mm
57 NetworkProcess/mac/RemoteNetworkingContext.mm
5857
5958NetworkProcess/webrtc/LibWebRTCSocketClient.cpp
6059NetworkProcess/webrtc/NetworkRTCMonitor.cpp

Source/WebKit/SourcesGTK.txt

@@NetworkProcess/soup/NetworkDataTaskSoup.cpp
4242NetworkProcess/soup/NetworkProcessMainSoup.cpp
4343NetworkProcess/soup/NetworkProcessSoup.cpp
4444NetworkProcess/soup/NetworkSessionSoup.cpp
45 NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
4645NetworkProcess/soup/WebKitDirectoryInputStream.cpp
4746NetworkProcess/soup/WebSocketTaskSoup.cpp
4847

Source/WebKit/SourcesWPE.txt

@@NetworkProcess/soup/NetworkDataTaskSoup.cpp
4242NetworkProcess/soup/NetworkProcessMainSoup.cpp
4343NetworkProcess/soup/NetworkProcessSoup.cpp
4444NetworkProcess/soup/NetworkSessionSoup.cpp
45 NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
4645NetworkProcess/soup/WebKitDirectoryInputStream.cpp
4746NetworkProcess/soup/WebSocketTaskSoup.cpp
4847

Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

@@void NetworkProcessProxy::addSession(WebsiteDataStore& store, SendParametersToNe
14111411 send(Messages::NetworkProcess::AddWebsiteDataStore { store.parameters() }, 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
14121412 auto sessionID = store.sessionID();
14131413 if (!sessionID.isEphemeral())
1414  createSymLinkForFileUpgrade(store.resolvedIndexedDatabaseDirectory());
 1414 createSymLinkForFileUpgrade(store.resolvedIndexedDBDatabaseDirectory());
14151415}
14161416
14171417void NetworkProcessProxy::removeSession(WebsiteDataStore& websiteDataStore)

Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

@@WebsiteDataStoreParameters WebsiteDataStore::parameters()
18431843#if !HAVE(NSURLSESSION_WEBSOCKET)
18441844 networkSessionParameters.shouldAcceptInsecureCertificatesForWebSockets = m_configuration->shouldAcceptInsecureCertificatesForWebSockets();
18451845#endif
1846 
1847  parameters.networkSessionParameters = WTFMove(networkSessionParameters);
1848 
1849  parameters.indexedDatabaseDirectory = resolvedIndexedDatabaseDirectory();
1850  if (!parameters.indexedDatabaseDirectory.isEmpty()) {
 1846 networkSessionParameters.shouldUseCustomStoragePaths = m_configuration->shouldUseCustomStoragePaths();
 1847 networkSessionParameters.perOriginStorageQuota = perOriginStorageQuota();
 1848 networkSessionParameters.perThirdPartyOriginStorageQuota = perThirdPartyOriginStorageQuota();
 1849
 1850 if (auto directory = resolvedLocalStorageDirectory(); !directory.isEmpty()) {
 1851 networkSessionParameters.localStorageDirectory = directory;
18511852 // FIXME: SandboxExtension::createHandleForReadWriteDirectory resolves the directory, but that has already been done. Remove this duplicate work.
1852  if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(parameters.indexedDatabaseDirectory))
1853  parameters.indexedDatabaseDirectoryExtensionHandle = WTFMove(*handle);
 1853 if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(directory))
 1854 networkSessionParameters.localStorageDirectoryExtensionHandle = WTFMove(*handle);
 1855#if PLATFORM(IOS_FAMILY)
 1856 // FIXME: we should move file system operations to background thread.
 1857 FileSystem::makeAllDirectories(directory);
 1858 FileSystem::excludeFromBackup(directory);
 1859#endif
18541860 }
18551861
1856 #if ENABLE(SERVICE_WORKER)
1857  parameters.serviceWorkerRegistrationDirectory = resolvedServiceWorkerRegistrationDirectory();
1858  if (!parameters.serviceWorkerRegistrationDirectory.isEmpty()) {
 1862 if (auto directory = resolvedIndexedDBDatabaseDirectory(); !directory.isEmpty()) {
 1863 networkSessionParameters.indexedDBDirectory = directory;
18591864 // FIXME: SandboxExtension::createHandleForReadWriteDirectory resolves the directory, but that has already been done. Remove this duplicate work.
1860  if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(parameters.serviceWorkerRegistrationDirectory))
1861  parameters.serviceWorkerRegistrationDirectoryExtensionHandle = WTFMove(*handle);
 1865 if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(directory))
 1866 networkSessionParameters.indexedDBDirectoryExtensionHandle = WTFMove(*handle);
18621867 }
1863  parameters.serviceWorkerProcessTerminationDelayEnabled = m_configuration->serviceWorkerProcessTerminationDelayEnabled();
1864 #endif
1865 
1866  auto localStorageDirectory = resolvedLocalStorageDirectory();
1867  if (!localStorageDirectory.isEmpty()) {
1868  parameters.localStorageDirectory = localStorageDirectory;
 1868
 1869#if ENABLE(SERVICE_WORKER)
 1870 if (auto directory = resolvedServiceWorkerRegistrationDirectory(); !directory.isEmpty()) {
 1871 networkSessionParameters.serviceWorkerRegistrationDirectory = directory;
18691872 // FIXME: SandboxExtension::createHandleForReadWriteDirectory resolves the directory, but that has already been done. Remove this duplicate work.
1870  if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(localStorageDirectory))
1871  parameters.localStorageDirectoryExtensionHandle = WTFMove(*handle);
1872 #if PLATFORM(IOS_FAMILY)
1873  FileSystem::makeAllDirectories(localStorageDirectory);
1874  FileSystem::excludeFromBackup(localStorageDirectory);
1875 #endif
1876  }
1877 
1878  auto cacheStorageDirectory = this->cacheStorageDirectory();
1879  if (!cacheStorageDirectory.isEmpty()) {
1880  parameters.cacheStorageDirectory = cacheStorageDirectory;
1881  if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(cacheStorageDirectory))
1882  parameters.cacheStorageDirectoryExtensionHandle = WTFMove(*handle);
 1873 if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(directory))
 1874 networkSessionParameters.serviceWorkerRegistrationDirectoryExtensionHandle = WTFMove(*handle);
18831875 }
1884 
 1876 networkSessionParameters.serviceWorkerProcessTerminationDelayEnabled = m_configuration->serviceWorkerProcessTerminationDelayEnabled();
 1877#endif
 1878
18851879 if (auto directory = generalStorageDirectory(); !directory.isEmpty()) {
1886  parameters.generalStorageDirectory = directory;
 1880 networkSessionParameters.generalStorageDirectory = directory;
18871881 if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(directory))
1888  parameters.generalStorageDirectoryHandle = WTFMove(*handle);
 1882 networkSessionParameters.generalStorageDirectoryHandle = WTFMove(*handle);
18891883 }
1890  parameters.shouldUseCustomStoragePaths = configuration().shouldUseCustomStoragePaths();
18911884
1892  parameters.perOriginStorageQuota = perOriginStorageQuota();
1893  parameters.perThirdPartyOriginStorageQuota = perThirdPartyOriginStorageQuota();
 1885 if (auto directory = cacheStorageDirectory(); !directory.isEmpty()) {
 1886 networkSessionParameters.cacheStorageDirectory = directory;
 1887 if (auto handle = SandboxExtension::createHandleForReadWriteDirectory(directory))
 1888 networkSessionParameters.cacheStorageDirectoryExtensionHandle = WTFMove(*handle);
 1889 }
18941890
 1891 parameters.networkSessionParameters = WTFMove(networkSessionParameters);
18951892#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
18961893 parameters.networkSessionParameters.resourceLoadStatisticsParameters.enabled = m_resourceLoadStatisticsEnabled;
18971894#endif

@@WebsiteDataStoreParameters WebsiteDataStore::parameters()
19001897 parameters.networkSessionParameters.appHasRequestedCrossWebsiteTrackingPermission = hasRequestedCrossWebsiteTrackingPermission();
19011898 parameters.networkSessionParameters.useNetworkLoader = useNetworkLoader();
19021899#endif
1903 
 1900
19041901 return parameters;
19051902}
19061903

Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

@@public:
254254 const String& resolvedDatabaseDirectory() const { return m_resolvedConfiguration->webSQLDatabaseDirectory(); }
255255 const String& resolvedJavaScriptConfigurationDirectory() const { return m_resolvedConfiguration->javaScriptConfigurationDirectory(); }
256256 const String& resolvedCookieStorageFile() const { return m_resolvedConfiguration->cookieStorageFile(); }
257  const String& resolvedIndexedDatabaseDirectory() const { return m_resolvedConfiguration->indexedDBDatabaseDirectory(); }
 257 const String& resolvedIndexedDBDatabaseDirectory() const { return m_resolvedConfiguration->indexedDBDatabaseDirectory(); }
258258 const String& resolvedServiceWorkerRegistrationDirectory() const { return m_resolvedConfiguration->serviceWorkerRegistrationDirectory(); }
259259 const String& resolvedResourceLoadStatisticsDirectory() const { return m_resolvedConfiguration->resourceLoadStatisticsDirectory(); }
260260 const String& resolvedHSTSStorageDirectory() const { return m_resolvedConfiguration->hstsStorageDirectory(); }