Reduce use of NetworkProcess::singleton
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jan 2019 18:03:11 +0000 (18:03 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jan 2019 18:03:11 +0000 (18:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193197

Reviewed by Brady Eidson.

Pass it around as a Ref<NetworkProcess> as a step towards reducing global state.
Soup's WebFrameNetworkingContext no longer makes a NetworkSession like all other ports
because networking is no longer done in the WebProcess.

* NetworkProcess/IndexedDB/WebIDBConnectionToClient.cpp:
(WebKit::WebIDBConnectionToClient::create):
(WebKit::WebIDBConnectionToClient::WebIDBConnectionToClient):
(WebKit::WebIDBConnectionToClient::disconnectedFromWebProcess):
(WebKit::WebIDBConnectionToClient::deleteDatabase):
(WebKit::WebIDBConnectionToClient::openDatabase):
(WebKit::WebIDBConnectionToClient::abortTransaction):
(WebKit::WebIDBConnectionToClient::commitTransaction):
(WebKit::WebIDBConnectionToClient::didFinishHandlingVersionChangeTransaction):
(WebKit::WebIDBConnectionToClient::createObjectStore):
(WebKit::WebIDBConnectionToClient::deleteObjectStore):
(WebKit::WebIDBConnectionToClient::renameObjectStore):
(WebKit::WebIDBConnectionToClient::clearObjectStore):
(WebKit::WebIDBConnectionToClient::createIndex):
(WebKit::WebIDBConnectionToClient::deleteIndex):
(WebKit::WebIDBConnectionToClient::renameIndex):
(WebKit::WebIDBConnectionToClient::putOrAdd):
(WebKit::WebIDBConnectionToClient::getRecord):
(WebKit::WebIDBConnectionToClient::getAllRecords):
(WebKit::WebIDBConnectionToClient::getCount):
(WebKit::WebIDBConnectionToClient::deleteRecord):
(WebKit::WebIDBConnectionToClient::openCursor):
(WebKit::WebIDBConnectionToClient::iterateCursor):
(WebKit::WebIDBConnectionToClient::establishTransaction):
(WebKit::WebIDBConnectionToClient::databaseConnectionPendingClose):
(WebKit::WebIDBConnectionToClient::databaseConnectionClosed):
(WebKit::WebIDBConnectionToClient::abortOpenAndUpgradeNeeded):
(WebKit::WebIDBConnectionToClient::didFireVersionChangeEvent):
(WebKit::WebIDBConnectionToClient::openDBRequestCancelled):
(WebKit::WebIDBConnectionToClient::confirmDidCloseFromServer):
(WebKit::WebIDBConnectionToClient::getAllDatabaseNames):
* NetworkProcess/IndexedDB/WebIDBConnectionToClient.h:
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::create):
(WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
(WebKit::NetworkConnectionToWebProcess::didReceiveMessage):
(WebKit::NetworkConnectionToWebProcess::didClose):
(WebKit::NetworkConnectionToWebProcess::createSocketStream):
(WebKit::NetworkConnectionToWebProcess::prefetchDNS):
(WebKit::NetworkConnectionToWebProcess::startDownload):
(WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
(WebKit::NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession):
(WebKit::NetworkConnectionToWebProcess::establishIDBConnectionToServer):
(WebKit::NetworkConnectionToWebProcess::establishSWServerConnection):
* NetworkProcess/NetworkConnectionToWebProcess.h:
(WebKit::NetworkConnectionToWebProcess::networkProcess):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::singleton):
(WebKit::NetworkProcess::initializeNetworkProcess):
(WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
(WebKit::NetworkProcess::addWebsiteDataStore):
(WebKit::fetchDiskCacheEntries):
(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::clearDiskCacheEntries):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
(WebKit::NetworkProcess::getNetworkProcessStatistics):
(WebKit::NetworkProcess::idbServer):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::startNetworkLoad):
(WebKit::NetworkResourceLoader::convertToDownload):
(WebKit::NetworkResourceLoader::isAlwaysOnLoggingAllowed const):
* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::create):
(WebKit::NetworkSession::NetworkSession):
* NetworkProcess/NetworkSession.h:
(WebKit::NetworkSession::networkProcess):
* NetworkProcess/RemoteNetworkingContext.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
(WebKit::NetworkDataTaskCocoa::isAlwaysOnLoggingAllowed const):
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::clearDiskCache):
* NetworkProcess/cocoa/NetworkSessionCocoa.h:
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):
(-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]):
(-[WKNetworkSessionDelegate URLSession:downloadTask:didFinishDownloadingToURL:]):
(-[WKNetworkSessionDelegate URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:]):
(-[WKNetworkSessionDelegate URLSession:dataTask:didBecomeDownloadTask:]):
(WebKit::NetworkSessionCocoa::create):
(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
* NetworkProcess/curl/NetworkSessionCurl.cpp:
(WebKit::NetworkSessionCurl::NetworkSessionCurl):
* NetworkProcess/curl/NetworkSessionCurl.h:
* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
* NetworkProcess/soup/NetworkSessionSoup.cpp:
(WebKit::NetworkSessionSoup::NetworkSessionSoup):
* NetworkProcess/soup/NetworkSessionSoup.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239680 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/IndexedDB/WebIDBConnectionToClient.cpp
Source/WebKit/NetworkProcess/IndexedDB/WebIDBConnectionToClient.h
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/NetworkSession.cpp
Source/WebKit/NetworkProcess/NetworkSession.h
Source/WebKit/NetworkProcess/RemoteNetworkingContext.h
Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm
Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm
Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h
Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp
Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.h
Source/WebKit/NetworkProcess/curl/RemoteNetworkingContextCurl.cpp
Source/WebKit/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.cpp
Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.h
Source/WebKit/NetworkProcess/soup/RemoteNetworkingContextSoup.cpp
Source/WebKit/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp

index 4c199aa..3982ea2 100644 (file)
@@ -1,5 +1,107 @@
 2019-01-07  Alex Christensen  <achristensen@webkit.org>
 
+        Reduce use of NetworkProcess::singleton
+        https://bugs.webkit.org/show_bug.cgi?id=193197
+
+        Reviewed by Brady Eidson.
+
+        Pass it around as a Ref<NetworkProcess> as a step towards reducing global state.
+        Soup's WebFrameNetworkingContext no longer makes a NetworkSession like all other ports
+        because networking is no longer done in the WebProcess.
+
+        * NetworkProcess/IndexedDB/WebIDBConnectionToClient.cpp:
+        (WebKit::WebIDBConnectionToClient::create):
+        (WebKit::WebIDBConnectionToClient::WebIDBConnectionToClient):
+        (WebKit::WebIDBConnectionToClient::disconnectedFromWebProcess):
+        (WebKit::WebIDBConnectionToClient::deleteDatabase):
+        (WebKit::WebIDBConnectionToClient::openDatabase):
+        (WebKit::WebIDBConnectionToClient::abortTransaction):
+        (WebKit::WebIDBConnectionToClient::commitTransaction):
+        (WebKit::WebIDBConnectionToClient::didFinishHandlingVersionChangeTransaction):
+        (WebKit::WebIDBConnectionToClient::createObjectStore):
+        (WebKit::WebIDBConnectionToClient::deleteObjectStore):
+        (WebKit::WebIDBConnectionToClient::renameObjectStore):
+        (WebKit::WebIDBConnectionToClient::clearObjectStore):
+        (WebKit::WebIDBConnectionToClient::createIndex):
+        (WebKit::WebIDBConnectionToClient::deleteIndex):
+        (WebKit::WebIDBConnectionToClient::renameIndex):
+        (WebKit::WebIDBConnectionToClient::putOrAdd):
+        (WebKit::WebIDBConnectionToClient::getRecord):
+        (WebKit::WebIDBConnectionToClient::getAllRecords):
+        (WebKit::WebIDBConnectionToClient::getCount):
+        (WebKit::WebIDBConnectionToClient::deleteRecord):
+        (WebKit::WebIDBConnectionToClient::openCursor):
+        (WebKit::WebIDBConnectionToClient::iterateCursor):
+        (WebKit::WebIDBConnectionToClient::establishTransaction):
+        (WebKit::WebIDBConnectionToClient::databaseConnectionPendingClose):
+        (WebKit::WebIDBConnectionToClient::databaseConnectionClosed):
+        (WebKit::WebIDBConnectionToClient::abortOpenAndUpgradeNeeded):
+        (WebKit::WebIDBConnectionToClient::didFireVersionChangeEvent):
+        (WebKit::WebIDBConnectionToClient::openDBRequestCancelled):
+        (WebKit::WebIDBConnectionToClient::confirmDidCloseFromServer):
+        (WebKit::WebIDBConnectionToClient::getAllDatabaseNames):
+        * NetworkProcess/IndexedDB/WebIDBConnectionToClient.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::create):
+        (WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
+        (WebKit::NetworkConnectionToWebProcess::didReceiveMessage):
+        (WebKit::NetworkConnectionToWebProcess::didClose):
+        (WebKit::NetworkConnectionToWebProcess::createSocketStream):
+        (WebKit::NetworkConnectionToWebProcess::prefetchDNS):
+        (WebKit::NetworkConnectionToWebProcess::startDownload):
+        (WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
+        (WebKit::NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession):
+        (WebKit::NetworkConnectionToWebProcess::establishIDBConnectionToServer):
+        (WebKit::NetworkConnectionToWebProcess::establishSWServerConnection):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        (WebKit::NetworkConnectionToWebProcess::networkProcess):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::singleton):
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        (WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
+        (WebKit::NetworkProcess::addWebsiteDataStore):
+        (WebKit::fetchDiskCacheEntries):
+        (WebKit::NetworkProcess::fetchWebsiteData):
+        (WebKit::clearDiskCacheEntries):
+        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
+        (WebKit::NetworkProcess::getNetworkProcessStatistics):
+        (WebKit::NetworkProcess::idbServer):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::startNetworkLoad):
+        (WebKit::NetworkResourceLoader::convertToDownload):
+        (WebKit::NetworkResourceLoader::isAlwaysOnLoggingAllowed const):
+        * NetworkProcess/NetworkSession.cpp:
+        (WebKit::NetworkSession::create):
+        (WebKit::NetworkSession::NetworkSession):
+        * NetworkProcess/NetworkSession.h:
+        (WebKit::NetworkSession::networkProcess):
+        * NetworkProcess/RemoteNetworkingContext.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
+        (WebKit::NetworkDataTaskCocoa::isAlwaysOnLoggingAllowed const):
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::clearDiskCache):
+        * NetworkProcess/cocoa/NetworkSessionCocoa.h:
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):
+        (-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]):
+        (-[WKNetworkSessionDelegate URLSession:downloadTask:didFinishDownloadingToURL:]):
+        (-[WKNetworkSessionDelegate URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:]):
+        (-[WKNetworkSessionDelegate URLSession:dataTask:didBecomeDownloadTask:]):
+        (WebKit::NetworkSessionCocoa::create):
+        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
+        * NetworkProcess/curl/NetworkSessionCurl.cpp:
+        (WebKit::NetworkSessionCurl::NetworkSessionCurl):
+        * NetworkProcess/curl/NetworkSessionCurl.h:
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
+        * NetworkProcess/soup/NetworkSessionSoup.cpp:
+        (WebKit::NetworkSessionSoup::NetworkSessionSoup):
+        * NetworkProcess/soup/NetworkSessionSoup.h:
+
+2019-01-07  Alex Christensen  <achristensen@webkit.org>
+
         Modernize CacheModel and disk cache fetching and clearing
         https://bugs.webkit.org/show_bug.cgi?id=193164
 
index 1fe1189..7fb2b97 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-Ref<WebIDBConnectionToClient> WebIDBConnectionToClient::create(NetworkConnectionToWebProcess& connection, uint64_t serverConnectionIdentifier, PAL::SessionID sessionID)
+Ref<WebIDBConnectionToClient> WebIDBConnectionToClient::create(NetworkProcess& networkProcess, NetworkConnectionToWebProcess& connection, uint64_t serverConnectionIdentifier, PAL::SessionID sessionID)
 {
-    return adoptRef(*new WebIDBConnectionToClient(connection, serverConnectionIdentifier, sessionID));
+    return adoptRef(*new WebIDBConnectionToClient(networkProcess, connection, serverConnectionIdentifier, sessionID));
 }
 
-WebIDBConnectionToClient::WebIDBConnectionToClient(NetworkConnectionToWebProcess& connection, uint64_t serverConnectionIdentifier, PAL::SessionID sessionID)
+WebIDBConnectionToClient::WebIDBConnectionToClient(NetworkProcess& networkProcess, NetworkConnectionToWebProcess& connection, uint64_t serverConnectionIdentifier, PAL::SessionID sessionID)
     : m_connection(connection)
+    , m_networkProcess(networkProcess)
     , m_identifier(serverConnectionIdentifier)
     , m_sessionID(sessionID)
 {
     relaxAdoptionRequirement();
     m_connectionToClient = IDBServer::IDBConnectionToClient::create(*this);
-    NetworkProcess::singleton().idbServer(m_sessionID).registerConnection(*m_connectionToClient);
+    networkProcess.idbServer(m_sessionID).registerConnection(*m_connectionToClient);
 }
 
 WebIDBConnectionToClient::~WebIDBConnectionToClient()
@@ -65,7 +66,7 @@ WebIDBConnectionToClient::~WebIDBConnectionToClient()
 
 void WebIDBConnectionToClient::disconnectedFromWebProcess()
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).unregisterConnection(*m_connectionToClient);
+    m_networkProcess->idbServer(m_sessionID).unregisterConnection(*m_connectionToClient);
 }
 
 IPC::Connection* WebIDBConnectionToClient::messageSenderConnection()
@@ -216,62 +217,62 @@ void WebIDBConnectionToClient::didGetAllDatabaseNames(uint64_t callbackID, const
 
 void WebIDBConnectionToClient::deleteDatabase(const IDBRequestData& request)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).deleteDatabase(request);
+    m_networkProcess->idbServer(m_sessionID).deleteDatabase(request);
 }
 
 void WebIDBConnectionToClient::openDatabase(const IDBRequestData& request)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).openDatabase(request);
+    m_networkProcess->idbServer(m_sessionID).openDatabase(request);
 }
 
 void WebIDBConnectionToClient::abortTransaction(const IDBResourceIdentifier& transactionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).abortTransaction(transactionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).abortTransaction(transactionIdentifier);
 }
 
 void WebIDBConnectionToClient::commitTransaction(const IDBResourceIdentifier& transactionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).commitTransaction(transactionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).commitTransaction(transactionIdentifier);
 }
 
 void WebIDBConnectionToClient::didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).didFinishHandlingVersionChangeTransaction(databaseConnectionIdentifier, transactionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).didFinishHandlingVersionChangeTransaction(databaseConnectionIdentifier, transactionIdentifier);
 }
 
 void WebIDBConnectionToClient::createObjectStore(const IDBRequestData& request, const IDBObjectStoreInfo& info)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).createObjectStore(request, info);
+    m_networkProcess->idbServer(m_sessionID).createObjectStore(request, info);
 }
 
 void WebIDBConnectionToClient::deleteObjectStore(const IDBRequestData& request, const String& name)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).deleteObjectStore(request, name);
+    m_networkProcess->idbServer(m_sessionID).deleteObjectStore(request, name);
 }
 
 void WebIDBConnectionToClient::renameObjectStore(const IDBRequestData& request, uint64_t objectStoreIdentifier, const String& newName)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).renameObjectStore(request, objectStoreIdentifier, newName);
+    m_networkProcess->idbServer(m_sessionID).renameObjectStore(request, objectStoreIdentifier, newName);
 }
 
 void WebIDBConnectionToClient::clearObjectStore(const IDBRequestData& request, uint64_t objectStoreIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).clearObjectStore(request, objectStoreIdentifier);
+    m_networkProcess->idbServer(m_sessionID).clearObjectStore(request, objectStoreIdentifier);
 }
 
 void WebIDBConnectionToClient::createIndex(const IDBRequestData& request, const IDBIndexInfo& info)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).createIndex(request, info);
+    m_networkProcess->idbServer(m_sessionID).createIndex(request, info);
 }
 
 void WebIDBConnectionToClient::deleteIndex(const IDBRequestData& request, uint64_t objectStoreIdentifier, const String& name)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).deleteIndex(request, objectStoreIdentifier, name);
+    m_networkProcess->idbServer(m_sessionID).deleteIndex(request, objectStoreIdentifier, name);
 }
 
 void WebIDBConnectionToClient::renameIndex(const IDBRequestData& request, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).renameIndex(request, objectStoreIdentifier, indexIdentifier, newName);
+    m_networkProcess->idbServer(m_sessionID).renameIndex(request, objectStoreIdentifier, indexIdentifier, newName);
 }
 
 void WebIDBConnectionToClient::putOrAdd(const IDBRequestData& request, const IDBKeyData& key, const IDBValue& value, unsigned overwriteMode)
@@ -286,77 +287,77 @@ void WebIDBConnectionToClient::putOrAdd(const IDBRequestData& request, const IDB
 
     IndexedDB::ObjectStoreOverwriteMode mode = static_cast<IndexedDB::ObjectStoreOverwriteMode>(overwriteMode);
 
-    NetworkProcess::singleton().idbServer(m_sessionID).putOrAdd(request, key, value, mode);
+    m_networkProcess->idbServer(m_sessionID).putOrAdd(request, key, value, mode);
 }
 
 void WebIDBConnectionToClient::getRecord(const IDBRequestData& request, const IDBGetRecordData& getRecordData)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).getRecord(request, getRecordData);
+    m_networkProcess->idbServer(m_sessionID).getRecord(request, getRecordData);
 }
 
 void WebIDBConnectionToClient::getAllRecords(const IDBRequestData& request, const IDBGetAllRecordsData& getAllRecordsData)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).getAllRecords(request, getAllRecordsData);
+    m_networkProcess->idbServer(m_sessionID).getAllRecords(request, getAllRecordsData);
 }
 
 void WebIDBConnectionToClient::getCount(const IDBRequestData& request, const IDBKeyRangeData& range)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).getCount(request, range);
+    m_networkProcess->idbServer(m_sessionID).getCount(request, range);
 }
 
 void WebIDBConnectionToClient::deleteRecord(const IDBRequestData& request, const IDBKeyRangeData& range)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).deleteRecord(request, range);
+    m_networkProcess->idbServer(m_sessionID).deleteRecord(request, range);
 }
 
 void WebIDBConnectionToClient::openCursor(const IDBRequestData& request, const IDBCursorInfo& info)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).openCursor(request, info);
+    m_networkProcess->idbServer(m_sessionID).openCursor(request, info);
 }
 
 void WebIDBConnectionToClient::iterateCursor(const IDBRequestData& request, const IDBIterateCursorData& data)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).iterateCursor(request, data);
+    m_networkProcess->idbServer(m_sessionID).iterateCursor(request, data);
 }
 
 void WebIDBConnectionToClient::establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo& info)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).establishTransaction(databaseConnectionIdentifier, info);
+    m_networkProcess->idbServer(m_sessionID).establishTransaction(databaseConnectionIdentifier, info);
 }
 
 void WebIDBConnectionToClient::databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).databaseConnectionPendingClose(databaseConnectionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).databaseConnectionPendingClose(databaseConnectionIdentifier);
 }
 
 void WebIDBConnectionToClient::databaseConnectionClosed(uint64_t databaseConnectionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).databaseConnectionClosed(databaseConnectionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).databaseConnectionClosed(databaseConnectionIdentifier);
 }
 
 void WebIDBConnectionToClient::abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).abortOpenAndUpgradeNeeded(databaseConnectionIdentifier, transactionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).abortOpenAndUpgradeNeeded(databaseConnectionIdentifier, transactionIdentifier);
 }
 
 void WebIDBConnectionToClient::didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).didFireVersionChangeEvent(databaseConnectionIdentifier, transactionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).didFireVersionChangeEvent(databaseConnectionIdentifier, transactionIdentifier);
 }
 
 void WebIDBConnectionToClient::openDBRequestCancelled(const IDBRequestData& requestData)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).openDBRequestCancelled(requestData);
+    m_networkProcess->idbServer(m_sessionID).openDBRequestCancelled(requestData);
 }
 
 void WebIDBConnectionToClient::confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).confirmDidCloseFromServer(databaseConnectionIdentifier);
+    m_networkProcess->idbServer(m_sessionID).confirmDidCloseFromServer(databaseConnectionIdentifier);
 }
 
 void WebIDBConnectionToClient::getAllDatabaseNames(uint64_t serverConnectionIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::SecurityOriginData& openingOrigin, uint64_t callbackID)
 {
-    NetworkProcess::singleton().idbServer(m_sessionID).getAllDatabaseNames(serverConnectionIdentifier, topOrigin, openingOrigin, callbackID);
+    m_networkProcess->idbServer(m_sessionID).getAllDatabaseNames(serverConnectionIdentifier, topOrigin, openingOrigin, callbackID);
 }
 
 } // namespace WebKit
index 5926b00..9c74a58 100644 (file)
@@ -50,9 +50,11 @@ struct SecurityOriginData;
 
 namespace WebKit {
 
+class NetworkProcess;
+
 class WebIDBConnectionToClient final : public WebCore::IDBServer::IDBConnectionToClientDelegate, public IPC::MessageSender, public RefCounted<WebIDBConnectionToClient> {
 public:
-    static Ref<WebIDBConnectionToClient> create(NetworkConnectionToWebProcess&, uint64_t serverConnectionIdentifier, PAL::SessionID);
+    static Ref<WebIDBConnectionToClient> create(NetworkProcess&, NetworkConnectionToWebProcess&, uint64_t serverConnectionIdentifier, PAL::SessionID);
 
     virtual ~WebIDBConnectionToClient();
 
@@ -126,13 +128,14 @@ public:
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
 
 private:
-    WebIDBConnectionToClient(NetworkConnectionToWebProcess&, uint64_t serverConnectionIdentifier, PAL::SessionID);
+    WebIDBConnectionToClient(NetworkProcess&, NetworkConnectionToWebProcess&, uint64_t serverConnectionIdentifier, PAL::SessionID);
 
     IPC::Connection* messageSenderConnection() final;
 
     template<class MessageType> void handleGetResult(const WebCore::IDBResultData&);
 
     Ref<NetworkConnectionToWebProcess> m_connection;
+    Ref<NetworkProcess> m_networkProcess;
 
     uint64_t m_identifier;
     PAL::SessionID m_sessionID;
index dfa9974..dc77ac2 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-Ref<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create(IPC::Connection::Identifier connectionIdentifier)
+Ref<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create(NetworkProcess& networkProcess, IPC::Connection::Identifier connectionIdentifier)
 {
-    return adoptRef(*new NetworkConnectionToWebProcess(connectionIdentifier));
+    return adoptRef(*new NetworkConnectionToWebProcess(networkProcess, connectionIdentifier));
 }
 
-NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(IPC::Connection::Identifier connectionIdentifier)
+NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(NetworkProcess& networkProcess, IPC::Connection::Identifier connectionIdentifier)
     : m_connection(IPC::Connection::createServerConnection(connectionIdentifier, *this))
+    , m_networkProcess(networkProcess)
 #if ENABLE(WEB_RTC)
     , m_mdnsRegister(*this)
 #endif
@@ -132,7 +133,7 @@ void NetworkConnectionToWebProcess::didReceiveMessage(IPC::Connection& connectio
     }
 
     if (decoder.messageReceiverName() == Messages::NetworkProcess::messageReceiverName()) {
-        NetworkProcess::singleton().didReceiveNetworkProcessMessage(connection, decoder);
+        m_networkProcess->didReceiveNetworkProcessMessage(connection, decoder);
         return;
     }
 
@@ -180,7 +181,7 @@ void NetworkConnectionToWebProcess::didReceiveMessage(IPC::Connection& connectio
     }
     
     if (decoder.messageReceiverName() == Messages::WebSWServerToContextConnection::messageReceiverName()) {
-        if (auto* contextConnection = NetworkProcess::singleton().connectionToContextProcessFromIPCConnection(connection)) {
+        if (auto* contextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) {
             contextConnection->didReceiveMessage(connection, decoder);
             return;
         }
@@ -227,9 +228,9 @@ void NetworkConnectionToWebProcess::didReceiveSyncMessage(IPC::Connection& conne
 void NetworkConnectionToWebProcess::didClose(IPC::Connection& connection)
 {
 #if ENABLE(SERVICE_WORKER)
-    if (RefPtr<WebSWServerToContextConnection> serverToContextConnection = NetworkProcess::singleton().connectionToContextProcessFromIPCConnection(connection)) {
+    if (RefPtr<WebSWServerToContextConnection> serverToContextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) {
         // Service Worker process exited.
-        NetworkProcess::singleton().connectionToContextProcessWasClosed(serverToContextConnection.releaseNonNull());
+        m_networkProcess->connectionToContextProcessWasClosed(serverToContextConnection.releaseNonNull());
         return;
     }
 #else
@@ -248,7 +249,7 @@ void NetworkConnectionToWebProcess::didClose(IPC::Connection& connection)
     stopAllNetworkActivityTracking();
 
     NetworkBlobRegistry::singleton().connectionToWebProcessDidClose(this);
-    NetworkProcess::singleton().removeNetworkConnectionToWebProcess(this);
+    m_networkProcess->removeNetworkConnectionToWebProcess(this);
 
 #if USE(LIBWEBRTC)
     if (m_rtcProvider) {
@@ -279,7 +280,7 @@ void NetworkConnectionToWebProcess::createSocketStream(URL&& url, PAL::SessionID
     ASSERT(!m_networkSocketStreams.contains(identifier));
     WebCore::SourceApplicationAuditToken token = { };
 #if PLATFORM(COCOA)
-    token = { NetworkProcess::singleton().sourceApplicationAuditData() };
+    token = { m_networkProcess->sourceApplicationAuditData() };
 #endif
     m_networkSocketStreams.set(identifier, NetworkSocketStream::create(WTFMove(url), sessionID, cachePartition, identifier, m_connection, WTFMove(token)));
 }
@@ -384,7 +385,7 @@ void NetworkConnectionToWebProcess::setDefersLoading(ResourceLoadIdentifier iden
 
 void NetworkConnectionToWebProcess::prefetchDNS(const String& hostname)
 {
-    NetworkProcess::singleton().prefetchDNS(hostname);
+    m_networkProcess->prefetchDNS(hostname);
 }
 
 void NetworkConnectionToWebProcess::preconnectTo(uint64_t preconnectionIdentifier, NetworkResourceLoadParameters&& parameters)
@@ -423,17 +424,16 @@ static NetworkStorageSession& storageSession(PAL::SessionID sessionID)
 
 void NetworkConnectionToWebProcess::startDownload(PAL::SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedName)
 {
-    NetworkProcess::singleton().downloadManager().startDownload(this, sessionID, downloadID, request, suggestedName);
+    m_networkProcess->downloadManager().startDownload(this, sessionID, downloadID, request, suggestedName);
 }
 
 void NetworkConnectionToWebProcess::convertMainResourceLoadToDownload(PAL::SessionID sessionID, uint64_t mainResourceLoadIdentifier, DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response)
 {
     RELEASE_ASSERT(RunLoop::isMain());
 
-    auto& networkProcess = NetworkProcess::singleton();
     // In case a response is served from service worker, we do not have yet the ability to convert the load.
     if (!mainResourceLoadIdentifier || response.source() == ResourceResponse::Source::ServiceWorker) {
-        networkProcess.downloadManager().startDownload(this, sessionID, downloadID, request);
+        m_networkProcess->downloadManager().startDownload(this, sessionID, downloadID, request);
         return;
     }
 
@@ -552,7 +552,7 @@ void NetworkConnectionToWebProcess::setCaptureExtraNetworkLoadMetricsEnabled(boo
 
 void NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession()
 {
-    NetworkProcess::singleton().addWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters());
+    m_networkProcess->addWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters());
 }
 
 void NetworkConnectionToWebProcess::removeStorageAccessForFrame(PAL::SessionID sessionID, uint64_t frameID, uint64_t pageID)
@@ -702,7 +702,7 @@ void NetworkConnectionToWebProcess::establishIDBConnectionToServer(PAL::SessionI
     LOG(IndexedDB, "NetworkConnectionToWebProcess::establishIDBConnectionToServer - %" PRIu64, serverConnectionIdentifier);
     ASSERT(!m_webIDBConnections.contains(serverConnectionIdentifier));
     
-    m_webIDBConnections.set(serverConnectionIdentifier, WebIDBConnectionToClient::create(*this, serverConnectionIdentifier, sessionID));
+    m_webIDBConnections.set(serverConnectionIdentifier, WebIDBConnectionToClient::create(m_networkProcess, *this, serverConnectionIdentifier, sessionID));
 }
 
 void NetworkConnectionToWebProcess::removeIDBConnectionToServer(uint64_t serverConnectionIdentifier)
@@ -726,7 +726,7 @@ void NetworkConnectionToWebProcess::unregisterSWConnections()
 
 void NetworkConnectionToWebProcess::establishSWServerConnection(PAL::SessionID sessionID, SWServerConnectionIdentifier& serverConnectionIdentifier)
 {
-    auto& server = NetworkProcess::singleton().swServerForSession(sessionID);
+    auto& server = m_networkProcess->swServerForSession(sessionID);
     auto connection = std::make_unique<WebSWServerConnection>(server, m_connection.get(), sessionID);
     
     serverConnectionIdentifier = connection->identifier();
index 26a10f6..e6119b1 100644 (file)
@@ -50,6 +50,7 @@ enum class IncludeSecureCookies : bool;
 
 namespace WebKit {
 
+class NetworkProcess;
 class NetworkResourceLoader;
 class NetworkSocketStream;
 class WebIDBConnectionToClient;
@@ -62,10 +63,11 @@ struct DataKey;
 
 class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, IPC::Connection::Client {
 public:
-    static Ref<NetworkConnectionToWebProcess> create(IPC::Connection::Identifier);
+    static Ref<NetworkConnectionToWebProcess> create(NetworkProcess&, IPC::Connection::Identifier);
     virtual ~NetworkConnectionToWebProcess();
 
     IPC::Connection& connection() { return m_connection.get(); }
+    NetworkProcess& networkProcess() { return m_networkProcess.get(); }
 
     void didCleanupResourceLoader(NetworkResourceLoader&);
     void setOnLineState(bool);
@@ -120,7 +122,7 @@ public:
     void stopTrackingResourceLoad(ResourceLoadIdentifier resourceID, NetworkActivityTracker::CompletionCode);
 
 private:
-    NetworkConnectionToWebProcess(IPC::Connection::Identifier);
+    NetworkConnectionToWebProcess(NetworkProcess&, IPC::Connection::Identifier);
 
     void didFinishPreconnection(uint64_t preconnectionIdentifier, const WebCore::ResourceError&);
 
@@ -227,6 +229,7 @@ private:
     size_t findNetworkActivityTracker(ResourceLoadIdentifier resourceID);
 
     Ref<IPC::Connection> m_connection;
+    Ref<NetworkProcess> m_networkProcess;
 
     HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
     HashMap<ResourceLoadIdentifier, Ref<NetworkResourceLoader>> m_networkResourceLoaders;
index 39b591d..74d9ef1 100644 (file)
@@ -115,8 +115,8 @@ static void callExitSoon(IPC::Connection*)
 
 NetworkProcess& NetworkProcess::singleton()
 {
-    static NeverDestroyed<NetworkProcess> networkProcess;
-    return networkProcess;
+    static NeverDestroyed<Ref<NetworkProcess>> networkProcess(adoptRef(*new NetworkProcess));
+    return networkProcess.get();
 }
 
 NetworkProcess::NetworkProcess()
@@ -299,7 +299,7 @@ void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&&
         NetworkStorageSession::switchToNewTestingSession();
 
     auto sessionID = parameters.defaultDataStoreParameters.networkSessionParameters.sessionID;
-    SessionTracker::setSession(sessionID, NetworkSession::create(WTFMove(parameters.defaultDataStoreParameters.networkSessionParameters)));
+    SessionTracker::setSession(sessionID, NetworkSession::create(*this, WTFMove(parameters.defaultDataStoreParameters.networkSessionParameters)));
 
 #if ENABLE(INDEXED_DATABASE)
     addIndexedDatabaseSession(sessionID, parameters.defaultDataStoreParameters.indexedDatabaseDirectory, parameters.defaultDataStoreParameters.indexedDatabaseDirectoryExtensionHandle);
@@ -364,7 +364,7 @@ void NetworkProcess::createNetworkConnectionToWebProcess(bool isServiceWorkerPro
 #if USE(UNIX_DOMAIN_SOCKETS)
     IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
 
-    auto connection = NetworkConnectionToWebProcess::create(socketPair.server);
+    auto connection = NetworkConnectionToWebProcess::create(*this, socketPair.server);
     m_webProcessConnections.append(WTFMove(connection));
 
     IPC::Attachment clientSocket(socketPair.client);
@@ -383,7 +383,7 @@ void NetworkProcess::createNetworkConnectionToWebProcess(bool isServiceWorkerPro
     }
 
     // Create a listening connection.
-    auto connection = NetworkConnectionToWebProcess::create(IPC::Connection::Identifier(listeningPort));
+    auto connection = NetworkConnectionToWebProcess::create(*this, IPC::Connection::Identifier(listeningPort));
     m_webProcessConnections.append(WTFMove(connection));
 
     IPC::Attachment clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND);
@@ -395,7 +395,7 @@ void NetworkProcess::createNetworkConnectionToWebProcess(bool isServiceWorkerPro
         CRASH();
     }
 
-    auto connection = NetworkConnectionToWebProcess::create(serverIdentifier);
+    auto connection = NetworkConnectionToWebProcess::create(*this, serverIdentifier);
     m_webProcessConnections.append(WTFMove(connection));
 
     IPC::Attachment clientSocket(clientIdentifier);
@@ -446,7 +446,7 @@ void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters
         addServiceWorkerSession(parameters.networkSessionParameters.sessionID, parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
 #endif
 
-    RemoteNetworkingContext::ensureWebsiteDataStoreSession(WTFMove(parameters));
+    RemoteNetworkingContext::ensureWebsiteDataStoreSession(*this, WTFMove(parameters));
 }
 
 void NetworkProcess::destroySession(PAL::SessionID sessionID)
@@ -567,9 +567,8 @@ void NetworkProcess::setSessionIsControlledByAutomation(PAL::SessionID sessionID
         m_sessionsControlledByAutomation.remove(sessionID);
 }
 
-static void fetchDiskCacheEntries(PAL::SessionID sessionID, OptionSet<WebsiteDataFetchOption> fetchOptions, CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
+static void fetchDiskCacheEntries(NetworkCache::Cache* cache, PAL::SessionID sessionID, OptionSet<WebsiteDataFetchOption> fetchOptions, CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
 {
-    auto* cache = NetworkProcess::singleton().cache();
     if (!cache) {
         RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)] () mutable {
             completionHandler({ });
@@ -672,7 +671,7 @@ void NetworkProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<Websit
 #endif
 
     if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
-        fetchDiskCacheEntries(sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
+        fetchDiskCacheEntries(cache(), sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
             callbackAggregator->m_websiteData.entries.appendVector(entries);
         });
     }
@@ -718,9 +717,8 @@ void NetworkProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<Websi
         clearDiskCache(modifiedSince, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
 }
 
-static void clearDiskCacheEntries(const Vector<SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)
+static void clearDiskCacheEntries(NetworkCache::Cache* cache, const Vector<SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)
 {
-    auto* cache = NetworkProcess::singleton().cache();
     if (!cache) {
         RunLoop::main().dispatch(WTFMove(completionHandler));
         return;
@@ -780,7 +778,7 @@ void NetworkProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, Optio
 #endif
 
     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral())
-        clearDiskCacheEntries(originDatas, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
+        clearDiskCacheEntries(cache(), originDatas, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
 }
 
 void NetworkProcess::downloadRequest(PAL::SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedFilename)
@@ -869,9 +867,8 @@ void NetworkProcess::getNetworkProcessStatistics(uint64_t callbackID)
 {
     StatisticsData data;
 
-    auto& networkProcess = NetworkProcess::singleton();
-    data.statisticsNumbers.set("DownloadsActiveCount", networkProcess.downloadManager().activeDownloadCount());
-    data.statisticsNumbers.set("OutstandingAuthenticationChallengesCount", networkProcess.authenticationManager().outstandingAuthenticationChallengeCount());
+    data.statisticsNumbers.set("DownloadsActiveCount", downloadManager().activeDownloadCount());
+    data.statisticsNumbers.set("OutstandingAuthenticationChallengesCount", authenticationManager().outstandingAuthenticationChallengeCount());
 
     parentProcessConnection()->send(Messages::WebProcessPool::DidGetStatistics(data, callbackID), 0);
 }
@@ -1079,7 +1076,7 @@ IDBServer::IDBServer& NetworkProcess::idbServer(PAL::SessionID sessionID)
     // If there's not, then where did this PAL::SessionID come from?
     ASSERT(!path.isEmpty());
     
-    addResult.iterator->value = IDBServer::IDBServer::create(path, NetworkProcess::singleton());
+    addResult.iterator->value = IDBServer::IDBServer::create(path, *this);
     addResult.iterator->value->setPerOriginQuota(m_idbPerOriginQuota);
     return *addResult.iterator->value;
 }
index 0fa97cf..244d516 100644 (file)
@@ -88,15 +88,15 @@ namespace NetworkCache {
 class Cache;
 }
 
-class NetworkProcess : public ChildProcess, private DownloadManager::Client
+class NetworkProcess : public ChildProcess, private DownloadManager::Client, public ThreadSafeRefCounted<NetworkProcess>
 #if ENABLE(INDEXED_DATABASE)
     , public WebCore::IDBServer::IDBBackingStoreTemporaryFileHandler
 #endif
 {
     WTF_MAKE_NONCOPYABLE(NetworkProcess);
-    friend NeverDestroyed<NetworkProcess>;
     friend NeverDestroyed<DownloadManager>;
 public:
+    ~NetworkProcess();
     static NetworkProcess& singleton();
     static constexpr ProcessType processType = ProcessType::Network;
 
@@ -211,7 +211,6 @@ public:
 
 private:
     NetworkProcess();
-    ~NetworkProcess();
 
     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
 
index b85245a..4b46bee 100644 (file)
@@ -96,7 +96,7 @@ NetworkResourceLoader::NetworkResourceLoader(NetworkResourceLoadParameters&& par
     , m_defersLoading { parameters.defersLoading }
     , m_isAllowedToAskUserForCredentials { m_parameters.clientCredentialPolicy == ClientCredentialPolicy::MayAskClientForCredentials }
     , m_bufferingTimer { *this, &NetworkResourceLoader::bufferingTimerFired }
-    , m_cache { sessionID().isEphemeral() ? nullptr : NetworkProcess::singleton().cache() }
+    , m_cache { sessionID().isEphemeral() ? nullptr : connection.networkProcess().cache() }
 {
     ASSERT(RunLoop::isMain());
     // FIXME: This is necessary because of the existence of EmptyFrameLoaderClient in WebCore.
@@ -286,13 +286,13 @@ void NetworkResourceLoader::startNetworkLoad(ResourceRequest&& request, FirstLoa
 
     auto* networkSession = SessionTracker::networkSession(parameters.sessionID);
     if (!networkSession && parameters.sessionID.isEphemeral()) {
-        NetworkProcess::singleton().addWebsiteDataStore(WebsiteDataStoreParameters::privateSessionParameters(parameters.sessionID));
+        m_connection->networkProcess().addWebsiteDataStore(WebsiteDataStoreParameters::privateSessionParameters(parameters.sessionID));
         networkSession = SessionTracker::networkSession(parameters.sessionID);
     }
     if (!networkSession) {
         WTFLogAlways("Attempted to create a NetworkLoad with a session (id=%" PRIu64 ") that does not exist.", parameters.sessionID.sessionID());
         RELEASE_LOG_ERROR_IF_ALLOWED("startNetworkLoad: Attempted to create a NetworkLoad with a session that does not exist (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ", sessionID=%" PRIu64 ")", m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier, parameters.sessionID.sessionID());
-        NetworkProcess::singleton().logDiagnosticMessage(m_parameters.webPageID, WebCore::DiagnosticLoggingKeys::internalErrorKey(), WebCore::DiagnosticLoggingKeys::invalidSessionIDKey(), WebCore::ShouldSample::No);
+        m_connection->networkProcess().logDiagnosticMessage(m_parameters.webPageID, WebCore::DiagnosticLoggingKeys::internalErrorKey(), WebCore::DiagnosticLoggingKeys::invalidSessionIDKey(), WebCore::ShouldSample::No);
         didFailLoading(internalError(request.url()));
         return;
     }
@@ -353,13 +353,13 @@ void NetworkResourceLoader::convertToDownload(DownloadID downloadID, const Resou
 {
     // This can happen if the resource came from the disk cache.
     if (!m_networkLoad) {
-        NetworkProcess::singleton().downloadManager().startDownload(m_connection.ptr(), m_parameters.sessionID, downloadID, request);
+        m_connection->networkProcess().downloadManager().startDownload(m_connection.ptr(), m_parameters.sessionID, downloadID, request);
         abort();
         return;
     }
 
     ASSERT(m_responseCompletionHandler);
-    NetworkProcess::singleton().downloadManager().convertNetworkLoadToDownload(downloadID, std::exchange(m_networkLoad, nullptr), WTFMove(m_responseCompletionHandler), WTFMove(m_fileReferences), request, response);
+    m_connection->networkProcess().downloadManager().convertNetworkLoadToDownload(downloadID, std::exchange(m_networkLoad, nullptr), WTFMove(m_responseCompletionHandler), WTFMove(m_fileReferences), request, response);
 }
 
 void NetworkResourceLoader::abort()
@@ -937,7 +937,7 @@ void NetworkResourceLoader::invalidateSandboxExtensions()
 
 bool NetworkResourceLoader::isAlwaysOnLoggingAllowed() const
 {
-    if (NetworkProcess::singleton().sessionIsControlledByAutomation(sessionID()))
+    if (m_connection->networkProcess().sessionIsControlledByAutomation(sessionID()))
         return true;
 
     return sessionID().isAlwaysOnLoggingAllowed();
index 5986618..5ba5c1c 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-Ref<NetworkSession> NetworkSession::create(NetworkSessionCreationParameters&& parameters)
+Ref<NetworkSession> NetworkSession::create(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
 {
 #if PLATFORM(COCOA)
-    return NetworkSessionCocoa::create(WTFMove(parameters));
+    return NetworkSessionCocoa::create(networkProcess, WTFMove(parameters));
 #endif
 #if USE(SOUP)
-    return NetworkSessionSoup::create(WTFMove(parameters));
+    return NetworkSessionSoup::create(networkProcess, WTFMove(parameters));
 #endif
 #if USE(CURL)
-    return NetworkSessionCurl::create(WTFMove(parameters));
+    return NetworkSessionCurl::create(networkProcess, WTFMove(parameters));
 #endif
 }
 
@@ -61,8 +61,9 @@ NetworkStorageSession& NetworkSession::networkStorageSession() const
     return *storageSession;
 }
 
-NetworkSession::NetworkSession(PAL::SessionID sessionID)
+NetworkSession::NetworkSession(NetworkProcess& networkProcess, PAL::SessionID sessionID)
     : m_sessionID(sessionID)
+    , m_networkProcess(networkProcess)
 {
 }
 
index 51645b8..c0487da 100644 (file)
@@ -38,11 +38,12 @@ class NetworkStorageSession;
 namespace WebKit {
 
 class NetworkDataTask;
+class NetworkProcess;
 struct NetworkSessionCreationParameters;
 
 class NetworkSession : public RefCounted<NetworkSession> {
 public:
-    static Ref<NetworkSession> create(NetworkSessionCreationParameters&&);
+    static Ref<NetworkSession> create(NetworkProcess&, NetworkSessionCreationParameters&&);
     virtual ~NetworkSession();
 
     virtual void invalidateAndCancel();
@@ -51,16 +52,17 @@ public:
     virtual Seconds loadThrottleLatency() const { return { }; }
 
     PAL::SessionID sessionID() const { return m_sessionID; }
+    NetworkProcess& networkProcess() { return m_networkProcess; }
     WebCore::NetworkStorageSession& networkStorageSession() const;
 
     void registerNetworkDataTask(NetworkDataTask& task) { m_dataTaskSet.add(&task); }
     void unregisterNetworkDataTask(NetworkDataTask& task) { m_dataTaskSet.remove(&task); }
 
 protected:
-    NetworkSession(PAL::SessionID);
+    NetworkSession(NetworkProcess&, PAL::SessionID);
 
     PAL::SessionID m_sessionID;
-
+    Ref<NetworkProcess> m_networkProcess;
     HashSet<NetworkDataTask*> m_dataTaskSet;
 };
 
index f7cfc8c..61d1871 100644 (file)
 
 namespace WebKit {
 
+class NetworkProcess;
 struct WebsiteDataStoreParameters;
 
 class RemoteNetworkingContext {
 public:
     // FIXME: Remove platform-specific code and use SessionTracker.
-    static void ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&);
+    static void ensureWebsiteDataStoreSession(NetworkProcess&, WebsiteDataStoreParameters&&);
 };
 
 }
index 58e1038..51c96fa 100644 (file)
@@ -203,7 +203,7 @@ NetworkDataTaskCocoa::NetworkDataTaskCocoa(NetworkSession& session, NetworkDataT
     NSURLRequest *nsRequest = request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::UpdateHTTPBody);
     applySniffingPoliciesAndBindRequestToInferfaceIfNeeded(nsRequest, shouldContentSniff == WebCore::ContentSniffingPolicy::SniffContent && !url.isLocalFile(), shouldContentEncodingSniff == WebCore::ContentEncodingSniffingPolicy::Sniff);
 #if ENABLE(PROXIMITY_NETWORKING)
-    NetworkProcess::singleton().proximityManager().applyProperties(request, *this, nsRequest);
+    m_session->networkProcess().proximityManager().applyProperties(request, *this, nsRequest);
 #endif
 
     auto& cocoaSession = static_cast<NetworkSessionCocoa&>(m_session.get());
@@ -497,7 +497,7 @@ WebCore::Credential serverTrustCredential(const WebCore::AuthenticationChallenge
 
 bool NetworkDataTaskCocoa::isAlwaysOnLoggingAllowed() const
 {
-    if (NetworkProcess::singleton().sessionIsControlledByAutomation(m_session->sessionID()))
+    if (m_session->networkProcess().sessionIsControlledByAutomation(m_session->sessionID()))
         return true;
 
     return m_session->sessionID().isAlwaysOnLoggingAllowed();
index 1ca9db4..41a0ba9 100644 (file)
@@ -179,7 +179,7 @@ void NetworkProcess::clearDiskCache(WallTime modifiedSince, CompletionHandler<vo
     if (!m_clearCacheDispatchGroup)
         m_clearCacheDispatchGroup = dispatch_group_create();
 
-    auto* cache = NetworkProcess::singleton().cache();
+    auto* cache = this->cache();
     if (!cache) {
         completionHandler();
         return;
index f0071d2..0d671c2 100644 (file)
@@ -44,7 +44,7 @@ class LegacyCustomProtocolManager;
 class NetworkSessionCocoa final : public NetworkSession {
     friend class NetworkDataTaskCocoa;
 public:
-    static Ref<NetworkSession> create(NetworkSessionCreationParameters&&);
+    static Ref<NetworkSession> create(NetworkProcess&, NetworkSessionCreationParameters&&);
     ~NetworkSessionCocoa();
 
     // Must be called before any NetworkSession has been created.
@@ -63,7 +63,7 @@ public:
     static bool allowsSpecificHTTPSCertificateForHost(const WebCore::AuthenticationChallenge&);
 
 private:
-    NetworkSessionCocoa(NetworkSessionCreationParameters&&);
+    NetworkSessionCocoa(NetworkProcess&, NetworkSessionCreationParameters&&);
 
     void invalidateAndCancel() override;
     void clearCredentials() override;
index e4ff173..9ca0f7d 100644 (file)
@@ -326,7 +326,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
             return completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
 
         // Handle server trust evaluation at platform-level if requested, for performance reasons and to use ATS defaults.
-        if (!NetworkProcess::singleton().canHandleHTTPSServerTrustEvaluation())
+        if (!_session->networkProcess().canHandleHTTPSServerTrustEvaluation())
             return completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
     }
 
@@ -366,7 +366,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
     } else {
         auto downloadID = _session->downloadID(taskIdentifier);
         if (downloadID.downloadID()) {
-            if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID)) {
+            if (auto* download = _session->networkProcess().downloadManager().download(downloadID)) {
                 // Received an authentication challenge for a download being resumed.
                 WebCore::AuthenticationChallenge authenticationChallenge { challenge };
                 auto completionHandlerCopy = Block_copy(completionHandler);
@@ -394,7 +394,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
     else if (error) {
         auto downloadID = _session->takeDownloadID(task.taskIdentifier);
         if (downloadID.downloadID()) {
-            if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID)) {
+            if (auto* download = _session->networkProcess().downloadManager().download(downloadID)) {
                 NSData *resumeData = nil;
                 if (id userInfo = error.userInfo) {
                     if ([userInfo isKindOfClass:[NSDictionary class]])
@@ -525,7 +525,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
         return;
 
     auto downloadID = _session->takeDownloadID([downloadTask taskIdentifier]);
-    if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID))
+    if (auto* download = _session->networkProcess().downloadManager().download(downloadID))
         download->didFinish();
 }
 
@@ -537,7 +537,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
     ASSERT_WITH_MESSAGE(![self existingTask:downloadTask], "The NetworkDataTask should be destroyed immediately after didBecomeDownloadTask returns");
 
     auto downloadID = _session->downloadID([downloadTask taskIdentifier]);
-    if (auto* download = WebKit::NetworkProcess::singleton().downloadManager().download(downloadID))
+    if (auto* download = _session->networkProcess().downloadManager().download(downloadID))
         download->didReceiveData(bytesWritten);
 }
 
@@ -554,7 +554,7 @@ static NSURLRequest* updateIgnoreStrictTransportSecuritySettingIfNecessary(NSURL
     if (auto* networkDataTask = [self existingTask:dataTask]) {
         Ref<NetworkDataTaskCocoa> protectedNetworkDataTask(*networkDataTask);
         auto downloadID = networkDataTask->pendingDownloadID();
-        auto& downloadManager = WebKit::NetworkProcess::singleton().downloadManager();
+        auto& downloadManager = _session->networkProcess().downloadManager();
         auto download = std::make_unique<WebKit::Download>(downloadManager, downloadID, downloadTask, _session->sessionID(), networkDataTask->suggestedFilename());
         networkDataTask->transferSandboxExtensionToDownload(*download);
         ASSERT(WebCore::FileSystem::fileExists(networkDataTask->pendingDownloadLocation()));
@@ -599,9 +599,9 @@ void NetworkSessionCocoa::setCTDataConnectionServiceType(const String& type)
 }
 #endif
 
-Ref<NetworkSession> NetworkSessionCocoa::create(NetworkSessionCreationParameters&& parameters)
+Ref<NetworkSession> NetworkSessionCocoa::create(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
 {
-    return adoptRef(*new NetworkSessionCocoa(WTFMove(parameters)));
+    return adoptRef(*new NetworkSessionCocoa(networkProcess, WTFMove(parameters)));
 }
 
 static NSDictionary *proxyDictionary(const URL& httpProxy, const URL& httpsProxy)
@@ -627,8 +627,8 @@ static NSDictionary *proxyDictionary(const URL& httpProxy, const URL& httpsProxy
     ALLOW_DEPRECATED_DECLARATIONS_END
 }
 
-NetworkSessionCocoa::NetworkSessionCocoa(NetworkSessionCreationParameters&& parameters)
-    : NetworkSession(parameters.sessionID)
+NetworkSessionCocoa::NetworkSessionCocoa(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
+    : NetworkSession(networkProcess, parameters.sessionID)
     , m_boundInterfaceIdentifier(parameters.boundInterfaceIdentifier)
     , m_proxyConfiguration(parameters.proxyConfiguration)
     , m_shouldLogCookieInformation(parameters.shouldLogCookieInformation)
@@ -655,7 +655,7 @@ NetworkSessionCocoa::NetworkSessionCocoa(NetworkSessionCreationParameters&& para
     // The WebKit network cache was already queried.
     configuration.URLCache = nil;
 
-    if (auto data = NetworkProcess::singleton().sourceApplicationAuditData())
+    if (auto data = networkProcess.sourceApplicationAuditData())
         configuration._sourceApplicationAuditTokenData = (__bridge NSData *)data.get();
 
     if (!parameters.sourceApplicationBundleIdentifier.isEmpty()) {
@@ -675,7 +675,7 @@ NetworkSessionCocoa::NetworkSessionCocoa(NetworkSessionCreationParameters&& para
 #endif
 
 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
-    NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>()->registerProtocolClass(configuration);
+    networkProcess.supplement<LegacyCustomProtocolManager>()->registerProtocolClass(configuration);
 #endif
 
 #if HAVE(TIMINGDATAOPTIONS)
@@ -686,7 +686,7 @@ NetworkSessionCocoa::NetworkSessionCocoa(NetworkSessionCreationParameters&& para
 
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
     // FIXME: Replace @"kCFStreamPropertyAutoErrorOnSystemChange" with a constant from the SDK once rdar://problem/40650244 is in a build.
-    if (NetworkProcess::singleton().suppressesConnectionTerminationOnSystemChange())
+    if (networkProcess.suppressesConnectionTerminationOnSystemChange())
         configuration._socketStreamProperties = @{ @"kCFStreamPropertyAutoErrorOnSystemChange" : @(NO) };
 #endif
 
index e7d77bc..ec8abcb 100644 (file)
@@ -37,8 +37,8 @@ namespace WebKit {
 
 using namespace WebCore;
 
-NetworkSessionCurl::NetworkSessionCurl(NetworkSessionCreationParameters&& parameters)
-    : NetworkSession(parameters.sessionID)
+NetworkSessionCurl::NetworkSessionCurl(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
+    : NetworkSession(networkProcess, parameters.sessionID)
 {
     if (!parameters.cookiePersistentStorageFile.isEmpty())
         networkStorageSession().setCookieDatabase(makeUniqueRef<CookieJarDB>(parameters.cookiePersistentStorageFile));
index ae12653..fded568 100644 (file)
@@ -33,14 +33,14 @@ struct NetworkSessionCreationParameters;
 
 class NetworkSessionCurl final : public NetworkSession {
 public:
-    static Ref<NetworkSession> create(NetworkSessionCreationParameters&& parameters)
+    static Ref<NetworkSession> create(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
     {
-        return adoptRef(*new NetworkSessionCurl(WTFMove(parameters)));
+        return adoptRef(*new NetworkSessionCurl(networkProcess, WTFMove(parameters)));
     }
     ~NetworkSessionCurl();
 
 private:
-    NetworkSessionCurl(NetworkSessionCreationParameters&&);
+    NetworkSessionCurl(NetworkProcess&, NetworkSessionCreationParameters&&);
 };
 
 } // namespace WebKit
index 504644a..c57f646 100644 (file)
@@ -35,14 +35,14 @@ namespace WebKit {
 
 using namespace WebCore;
 
-void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
+void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, WebsiteDataStoreParameters&& parameters)
 {
     auto sessionID = parameters.networkSessionParameters.sessionID;
     if (NetworkStorageSession::storageSession(sessionID))
         return;
 
     NetworkStorageSession::ensureSession(sessionID, String::number(sessionID.sessionID()));
-    SessionTracker::setSession(sessionID, NetworkSession::create(WTFMove(parameters.networkSessionParameters)));
+    SessionTracker::setSession(sessionID, NetworkSession::create(networkProcess, WTFMove(parameters.networkSessionParameters)));
 }
 
 }
index 8dac904..7616451 100644 (file)
@@ -42,7 +42,7 @@
 namespace WebKit {
 using namespace WebCore;
 
-void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
+void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, WebsiteDataStoreParameters&& parameters)
 {
     auto sessionID = parameters.networkSessionParameters.sessionID;
     if (NetworkStorageSession::storageSession(sessionID))
@@ -67,7 +67,7 @@ void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStorePara
     for (const auto& cookie : parameters.pendingCookies)
         session->setCookie(cookie);
 
-    SessionTracker::setSession(sessionID, NetworkSession::create(WTFMove(parameters.networkSessionParameters)));
+    SessionTracker::setSession(sessionID, NetworkSession::create(networkProcess, WTFMove(parameters.networkSessionParameters)));
 }
 
 }
index 8b030b1..a475007 100644 (file)
@@ -36,8 +36,8 @@
 namespace WebKit {
 using namespace WebCore;
 
-NetworkSessionSoup::NetworkSessionSoup(NetworkSessionCreationParameters&& parameters)
-    : NetworkSession(parameters.sessionID)
+NetworkSessionSoup::NetworkSessionSoup(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
+    : NetworkSession(networkProcess, parameters.sessionID)
 {
     networkStorageSession().setCookieObserverHandler([this] {
         NetworkProcess::singleton().supplement<WebCookieManager>()->notifyCookiesDidChange(m_sessionID);
index 4156345..dd864dd 100644 (file)
@@ -35,16 +35,16 @@ struct NetworkSessionCreationParameters;
 
 class NetworkSessionSoup final : public NetworkSession {
 public:
-    static Ref<NetworkSession> create(NetworkSessionCreationParameters&& parameters)
+    static Ref<NetworkSession> create(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
     {
-        return adoptRef(*new NetworkSessionSoup(WTFMove(parameters)));
+        return adoptRef(*new NetworkSessionSoup(networkProcess, WTFMove(parameters)));
     }
     ~NetworkSessionSoup();
 
     SoupSession* soupSession() const;
 
 private:
-    NetworkSessionSoup(NetworkSessionCreationParameters&&);
+    NetworkSessionSoup(NetworkProcess&, NetworkSessionCreationParameters&&);
 
     void clearCredentials() override;
 };
index ce2bd1d..25869c6 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
+void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, WebsiteDataStoreParameters&& parameters)
 {
     auto sessionID = parameters.networkSessionParameters.sessionID;
     if (NetworkStorageSession::storageSession(sessionID))
         return;
 
     NetworkStorageSession::ensureSession(sessionID, String::number(sessionID.sessionID()));
-    SessionTracker::setSession(sessionID, NetworkSession::create(WTFMove(parameters.networkSessionParameters)));
+    SessionTracker::setSession(sessionID, NetworkSession::create(networkProcess, WTFMove(parameters.networkSessionParameters)));
 }
 
 }
index cf63fa4..a32df62 100644 (file)
@@ -51,7 +51,6 @@ void WebFrameNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStorePa
         return;
 
     NetworkStorageSession::ensureSession(sessionID, String::number(sessionID.sessionID()));
-    SessionTracker::setSession(sessionID, NetworkSession::create(WTFMove(parameters.networkSessionParameters)));
 }
 
 WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)