Stop using blobRegistry in NetworkProcess
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2019 18:58:21 +0000 (18:58 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2019 18:58:21 +0000 (18:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194027

Reviewed by Youenn Fablet.

Source/WebCore:

Also stop using NetworkBlobRegistry::singleton.
Instead, have the NetworkProcess own a NetworkBlobRegistry which owns a BlobRegistryImpl.
We now have to resolve all blob file references while we still have a
NetworkConnectionToWebProcess/NetworkProcess/NetworkBlobRegistry/BlobRegistryImpl instead of
using the singleton after we have passed everything to the loading code, but it works the same
as it did before.  We must consume the sandbox extension from the BlobRegistryImpl before using
the resolved files, so I pass around a Vector<RefPtr<WebCore::BlobDataFileReference>> so we know
which extensions to revoke.

* platform/network/BlobRegistryImpl.h:
* platform/network/FormData.cpp:
(WebCore::appendBlobResolved):
(WebCore::FormData::resolveBlobReferences):
* platform/network/FormData.h:
* platform/network/cf/FormDataStreamCFNet.cpp:
(WebCore::createHTTPBodyCFReadStream):
* platform/network/curl/CurlFormDataStream.cpp:
(WebCore::CurlFormDataStream::CurlFormDataStream):

Source/WebKit:

* NetworkProcess/Downloads/DownloadManager.cpp:
(WebKit::DownloadManager::startDownload):
* NetworkProcess/Downloads/PendingDownload.cpp:
(WebKit::PendingDownload::PendingDownload):
* NetworkProcess/Downloads/PendingDownload.h:
* NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
(WebKit::NetworkBlobRegistry::registerFileBlobURL):
(WebKit::NetworkBlobRegistry::registerBlobURL):
(WebKit::NetworkBlobRegistry::registerBlobURLOptionallyFileBacked):
(WebKit::NetworkBlobRegistry::registerBlobURLForSlice):
(WebKit::NetworkBlobRegistry::unregisterBlobURL):
(WebKit::NetworkBlobRegistry::blobSize):
(WebKit::NetworkBlobRegistry::writeBlobsToTemporaryFiles):
(WebKit::NetworkBlobRegistry::writeBlobToFilePath):
(WebKit::NetworkBlobRegistry::connectionToWebProcessDidClose):
(WebKit::NetworkBlobRegistry::filesInBlob):
(WebKit::NetworkBlobRegistry::singleton): Deleted.
* NetworkProcess/FileAPI/NetworkBlobRegistry.h:
(WebKit::NetworkBlobRegistry::blobRegistry):
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::didClose):
(WebKit::NetworkConnectionToWebProcess::resolveBlobReferences):
(WebKit::NetworkConnectionToWebProcess::scheduleResourceLoad):
(WebKit::NetworkConnectionToWebProcess::performSynchronousLoad):
(WebKit::NetworkConnectionToWebProcess::loadPing):
(WebKit::NetworkConnectionToWebProcess::preconnectTo):
(WebKit::NetworkConnectionToWebProcess::registerFileBlobURL):
(WebKit::NetworkConnectionToWebProcess::registerBlobURL):
(WebKit::NetworkConnectionToWebProcess::registerBlobURLFromURL):
(WebKit::NetworkConnectionToWebProcess::registerBlobURLOptionallyFileBacked):
(WebKit::NetworkConnectionToWebProcess::registerBlobURLForSlice):
(WebKit::NetworkConnectionToWebProcess::unregisterBlobURL):
(WebKit::NetworkConnectionToWebProcess::blobSize):
(WebKit::NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles):
(WebKit::NetworkConnectionToWebProcess::filesInBlob):
(WebKit::NetworkConnectionToWebProcess::blobRegistry):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkDataTask.cpp:
(WebKit::NetworkDataTask::create):
* NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::NetworkDataTaskBlob):
* NetworkProcess/NetworkDataTaskBlob.h:
* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::NetworkLoad):
(WebKit::NetworkLoad::initialize):
* NetworkProcess/NetworkLoad.h:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::NetworkProcess):
(WebKit::NetworkProcess::removeNetworkConnectionToWebProcess):
* NetworkProcess/NetworkProcess.h:
(WebKit::NetworkProcess::networkBlobRegistry):
* NetworkProcess/NetworkProcessPlatformStrategies.cpp:
(WebKit::NetworkProcessPlatformStrategies::createBlobRegistry):
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::m_shouldCaptureExtraNetworkLoadMetrics):
(WebKit::NetworkResourceLoader::startNetworkLoad):
* NetworkProcess/PreconnectTask.cpp:
* NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
(WebKit::NetworkCache::SpeculativeLoad::SpeculativeLoad):

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

27 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/BlobRegistryImpl.h
Source/WebCore/platform/network/FormData.cpp
Source/WebCore/platform/network/FormData.h
Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp
Source/WebCore/platform/network/curl/CurlFormDataStream.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp
Source/WebKit/NetworkProcess/Downloads/PendingDownload.cpp
Source/WebKit/NetworkProcess/Downloads/PendingDownload.h
Source/WebKit/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp
Source/WebKit/NetworkProcess/FileAPI/NetworkBlobRegistry.h
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkDataTask.cpp
Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp
Source/WebKit/NetworkProcess/NetworkDataTaskBlob.h
Source/WebKit/NetworkProcess/NetworkLoad.cpp
Source/WebKit/NetworkProcess/NetworkLoad.h
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcessPlatformStrategies.cpp
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/PingLoad.cpp
Source/WebKit/NetworkProcess/PingLoad.h
Source/WebKit/NetworkProcess/PreconnectTask.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp

index c068092..6ebd36c 100644 (file)
@@ -1,3 +1,29 @@
+2019-02-05  Alex Christensen  <achristensen@webkit.org>
+
+        Stop using blobRegistry in NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=194027
+
+        Reviewed by Youenn Fablet.
+
+        Also stop using NetworkBlobRegistry::singleton.
+        Instead, have the NetworkProcess own a NetworkBlobRegistry which owns a BlobRegistryImpl.
+        We now have to resolve all blob file references while we still have a
+        NetworkConnectionToWebProcess/NetworkProcess/NetworkBlobRegistry/BlobRegistryImpl instead of
+        using the singleton after we have passed everything to the loading code, but it works the same
+        as it did before.  We must consume the sandbox extension from the BlobRegistryImpl before using
+        the resolved files, so I pass around a Vector<RefPtr<WebCore::BlobDataFileReference>> so we know
+        which extensions to revoke.
+
+        * platform/network/BlobRegistryImpl.h:
+        * platform/network/FormData.cpp:
+        (WebCore::appendBlobResolved):
+        (WebCore::FormData::resolveBlobReferences):
+        * platform/network/FormData.h:
+        * platform/network/cf/FormDataStreamCFNet.cpp:
+        (WebCore::createHTTPBodyCFReadStream):
+        * platform/network/curl/CurlFormDataStream.cpp:
+        (WebCore::CurlFormDataStream::CurlFormDataStream):
+
 2019-02-05  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r240742.
index 172bf1d..e151d3a 100644 (file)
@@ -56,7 +56,6 @@ public:
     Ref<ResourceHandle> createResourceHandle(const ResourceRequest&, ResourceHandleClient*);
     void writeBlobToFilePath(const URL& blobURL, const String& path, Function<void(bool success)>&& completionHandler);
 
-private:
     void appendStorageItems(BlobData*, const BlobDataItemList&, long long offset, long long length);
 
     void registerFileBlobURL(const URL&, Ref<BlobDataFileReference>&&, const String& contentType) override;
@@ -78,6 +77,7 @@ private:
 
     bool populateBlobsForFileWriting(const Vector<String>& blobURLs, Vector<BlobForFileWriting>&);
 
+private:
     HashMap<String, RefPtr<BlobData>> m_blobs;
 };
 
index 7b76a5e..7e94c9a 100644 (file)
@@ -311,14 +311,14 @@ String FormData::flattenToString() const
     return Latin1Encoding().decode(reinterpret_cast<const char*>(bytes.data()), bytes.size());
 }
 
-static void appendBlobResolved(FormData* formData, const URL& url)
+static void appendBlobResolved(BlobRegistry& blobRegistry, FormData& formData, const URL& url)
 {
-    if (!blobRegistry().isBlobRegistryImpl()) {
+    if (!blobRegistry.isBlobRegistryImpl()) {
         LOG_ERROR("Tried to resolve a blob without a usable registry");
         return;
     }
 
-    BlobData* blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(url);
+    auto* blobData = static_cast<BlobRegistryImpl&>(blobRegistry).getBlobDataFromURL(url);
     if (!blobData) {
         LOG_ERROR("Could not get blob data from a registry");
         return;
@@ -327,15 +327,15 @@ static void appendBlobResolved(FormData* formData, const URL& url)
     for (const auto& blobItem : blobData->items()) {
         if (blobItem.type() == BlobDataItem::Type::Data) {
             ASSERT(blobItem.data().data());
-            formData->appendData(blobItem.data().data()->data() + static_cast<int>(blobItem.offset()), static_cast<int>(blobItem.length()));
+            formData.appendData(blobItem.data().data()->data() + static_cast<int>(blobItem.offset()), static_cast<int>(blobItem.length()));
         } else if (blobItem.type() == BlobDataItem::Type::File)
-            formData->appendFileRange(blobItem.file()->path(), blobItem.offset(), blobItem.length(), blobItem.file()->expectedModificationTime());
+            formData.appendFileRange(blobItem.file()->path(), blobItem.offset(), blobItem.length(), blobItem.file()->expectedModificationTime());
         else
             ASSERT_NOT_REACHED();
     }
 }
 
-Ref<FormData> FormData::resolveBlobReferences()
+Ref<FormData> FormData::resolveBlobReferences(BlobRegistry& blobRegistry)
 {
     // First check if any blobs needs to be resolved, or we can take the fast path.
     bool hasBlob = false;
@@ -361,7 +361,7 @@ Ref<FormData> FormData::resolveBlobReferences()
             }, [&] (const FormDataElement::EncodedFileData& fileData) {
                 newFormData->appendFileRange(fileData.filename, fileData.fileStart, fileData.fileLength, fileData.expectedFileModificationTime, fileData.shouldGenerateFile);
             }, [&] (const FormDataElement::EncodedBlobData& blobData) {
-                appendBlobResolved(newFormData.ptr(), blobData.url);
+                appendBlobResolved(blobRegistry, newFormData.get(), blobData.url);
             }
         );
     }
index efaa1f0..3b50e73 100644 (file)
@@ -29,6 +29,7 @@
 
 namespace WebCore {
 
+class BlobRegistry;
 class DOMFormData;
 class Document;
 class File;
@@ -226,7 +227,7 @@ public:
 
     // Resolve all blob references so we only have file and data.
     // If the FormData has no blob references to resolve, this is returned.
-    Ref<FormData> resolveBlobReferences();
+    WEBCORE_EXPORT Ref<FormData> resolveBlobReferences(BlobRegistry&);
 
     bool isEmpty() const { return m_elements.isEmpty(); }
     const Vector<FormDataElement>& elements() const { return m_elements; }
index a74ae5a..67e2f27 100644 (file)
@@ -30,6 +30,7 @@
 #include "FormDataStreamCFNet.h"
 
 #include "BlobData.h"
+#include "BlobRegistry.h"
 #include "FormData.h"
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -372,7 +373,7 @@ static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, vo
 
 RetainPtr<CFReadStreamRef> createHTTPBodyCFReadStream(FormData& formData)
 {
-    auto resolvedFormData = formData.resolveBlobReferences();
+    auto resolvedFormData = formData.resolveBlobReferences(blobRegistry());
 
     // Precompute the content length so CFNetwork doesn't use chunked mode.
     unsigned long long length = 0;
index a837d2e..8129fe0 100644 (file)
@@ -34,6 +34,7 @@
 
 #if USE(CURL)
 
+#include "BlobRegistry.h"
 #include "CurlContext.h"
 #include "Logging.h"
 #include <wtf/MainThread.h>
@@ -50,7 +51,7 @@ CurlFormDataStream::CurlFormDataStream(const FormData* formData)
     m_formData = formData->isolatedCopy();
 
     // Resolve the blob elements so the formData can correctly report it's size.
-    m_formData = m_formData->resolveBlobReferences();
+    m_formData = m_formData->resolveBlobReferences(blobRegistry());
 }
 
 CurlFormDataStream::~CurlFormDataStream()
index f9ef7c7..09d03f4 100644 (file)
@@ -1,3 +1,70 @@
+2019-02-05  Alex Christensen  <achristensen@webkit.org>
+
+        Stop using blobRegistry in NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=194027
+
+        Reviewed by Youenn Fablet.
+
+        * NetworkProcess/Downloads/DownloadManager.cpp:
+        (WebKit::DownloadManager::startDownload):
+        * NetworkProcess/Downloads/PendingDownload.cpp:
+        (WebKit::PendingDownload::PendingDownload):
+        * NetworkProcess/Downloads/PendingDownload.h:
+        * NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
+        (WebKit::NetworkBlobRegistry::registerFileBlobURL):
+        (WebKit::NetworkBlobRegistry::registerBlobURL):
+        (WebKit::NetworkBlobRegistry::registerBlobURLOptionallyFileBacked):
+        (WebKit::NetworkBlobRegistry::registerBlobURLForSlice):
+        (WebKit::NetworkBlobRegistry::unregisterBlobURL):
+        (WebKit::NetworkBlobRegistry::blobSize):
+        (WebKit::NetworkBlobRegistry::writeBlobsToTemporaryFiles):
+        (WebKit::NetworkBlobRegistry::writeBlobToFilePath):
+        (WebKit::NetworkBlobRegistry::connectionToWebProcessDidClose):
+        (WebKit::NetworkBlobRegistry::filesInBlob):
+        (WebKit::NetworkBlobRegistry::singleton): Deleted.
+        * NetworkProcess/FileAPI/NetworkBlobRegistry.h:
+        (WebKit::NetworkBlobRegistry::blobRegistry):
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::didClose):
+        (WebKit::NetworkConnectionToWebProcess::resolveBlobReferences):
+        (WebKit::NetworkConnectionToWebProcess::scheduleResourceLoad):
+        (WebKit::NetworkConnectionToWebProcess::performSynchronousLoad):
+        (WebKit::NetworkConnectionToWebProcess::loadPing):
+        (WebKit::NetworkConnectionToWebProcess::preconnectTo):
+        (WebKit::NetworkConnectionToWebProcess::registerFileBlobURL):
+        (WebKit::NetworkConnectionToWebProcess::registerBlobURL):
+        (WebKit::NetworkConnectionToWebProcess::registerBlobURLFromURL):
+        (WebKit::NetworkConnectionToWebProcess::registerBlobURLOptionallyFileBacked):
+        (WebKit::NetworkConnectionToWebProcess::registerBlobURLForSlice):
+        (WebKit::NetworkConnectionToWebProcess::unregisterBlobURL):
+        (WebKit::NetworkConnectionToWebProcess::blobSize):
+        (WebKit::NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles):
+        (WebKit::NetworkConnectionToWebProcess::filesInBlob):
+        (WebKit::NetworkConnectionToWebProcess::blobRegistry):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * NetworkProcess/NetworkDataTask.cpp:
+        (WebKit::NetworkDataTask::create):
+        * NetworkProcess/NetworkDataTaskBlob.cpp:
+        (WebKit::NetworkDataTaskBlob::NetworkDataTaskBlob):
+        * NetworkProcess/NetworkDataTaskBlob.h:
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::NetworkLoad::NetworkLoad):
+        (WebKit::NetworkLoad::initialize):
+        * NetworkProcess/NetworkLoad.h:
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::NetworkProcess):
+        (WebKit::NetworkProcess::removeNetworkConnectionToWebProcess):
+        * NetworkProcess/NetworkProcess.h:
+        (WebKit::NetworkProcess::networkBlobRegistry):
+        * NetworkProcess/NetworkProcessPlatformStrategies.cpp:
+        (WebKit::NetworkProcessPlatformStrategies::createBlobRegistry):
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::m_shouldCaptureExtraNetworkLoadMetrics):
+        (WebKit::NetworkResourceLoader::startNetworkLoad):
+        * NetworkProcess/PreconnectTask.cpp:
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
+        (WebKit::NetworkCache::SpeculativeLoad::SpeculativeLoad):
+
 2019-02-05  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r240742.
index da377b8..28efe98 100644 (file)
@@ -27,7 +27,7 @@
 #include "DownloadManager.h"
 
 #include "Download.h"
-#include "NetworkBlobRegistry.h"
+#include "NetworkConnectionToWebProcess.h"
 #include "NetworkLoad.h"
 #include "NetworkSession.h"
 #include "PendingDownload.h"
@@ -54,10 +54,10 @@ void DownloadManager::startDownload(NetworkConnectionToWebProcess* connection, P
     parameters.request = request;
     parameters.clientCredentialPolicy = ClientCredentialPolicy::MayAskClientForCredentials;
     if (request.url().protocolIsBlob() && connection)
-        parameters.blobFileReferences = NetworkBlobRegistry::singleton().filesInBlob(*connection, request.url());
+        parameters.blobFileReferences = connection->filesInBlob(request.url());
     parameters.storedCredentialsPolicy = sessionID.isEphemeral() ? StoredCredentialsPolicy::DoNotUse : StoredCredentialsPolicy::Use;
 
-    m_pendingDownloads.add(downloadID, std::make_unique<PendingDownload>(m_client.parentProcessConnectionForDownloads(), WTFMove(parameters), downloadID, *networkSession, suggestedName));
+    m_pendingDownloads.add(downloadID, std::make_unique<PendingDownload>(m_client.parentProcessConnectionForDownloads(), WTFMove(parameters), downloadID, *networkSession, connection ? &connection->blobRegistry() : nullptr, suggestedName));
 }
 
 void DownloadManager::dataTaskBecameDownloadTask(DownloadID downloadID, std::unique_ptr<Download>&& download)
index 566db9d..a27828d 100644 (file)
@@ -36,8 +36,8 @@
 namespace WebKit {
 using namespace WebCore;
 
-PendingDownload::PendingDownload(IPC::Connection* parentProcessConnection, NetworkLoadParameters&& parameters, DownloadID downloadID, NetworkSession& networkSession, const String& suggestedName)
-    : m_networkLoad(std::make_unique<NetworkLoad>(*this, WTFMove(parameters), networkSession))
+PendingDownload::PendingDownload(IPC::Connection* parentProcessConnection, NetworkLoadParameters&& parameters, DownloadID downloadID, NetworkSession& networkSession, WebCore::BlobRegistryImpl* blobRegistry, const String& suggestedName)
+    : m_networkLoad(std::make_unique<NetworkLoad>(*this, blobRegistry, WTFMove(parameters), networkSession))
     , m_parentProcessConnection(parentProcessConnection)
 {
     m_isAllowedToAskUserForCredentials = parameters.clientCredentialPolicy == ClientCredentialPolicy::MayAskClientForCredentials;
index a0c595d..f4b014e 100644 (file)
@@ -34,6 +34,7 @@ class Connection;
 }
 
 namespace WebCore {
+class BlobRegistryImpl;
 class ResourceResponse;
 }
 
@@ -48,7 +49,7 @@ class NetworkSession;
 class PendingDownload : public NetworkLoadClient, public IPC::MessageSender {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    PendingDownload(IPC::Connection*, NetworkLoadParameters&&, DownloadID, NetworkSession&, const String& suggestedName);
+    PendingDownload(IPC::Connection*, NetworkLoadParameters&&, DownloadID, NetworkSession&, WebCore::BlobRegistryImpl*, const String& suggestedName);
     PendingDownload(IPC::Connection*, std::unique_ptr<NetworkLoad>&&, ResponseCompletionHandler&&, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
 
     void continueWillSendRequest(WebCore::ResourceRequest&&);
index 31f2dc4..63998d5 100644 (file)
 namespace WebKit {
 using namespace WebCore;
 
-NetworkBlobRegistry& NetworkBlobRegistry::singleton()
-{
-    ASSERT(RunLoop::isMain());
-    static NeverDestroyed<NetworkBlobRegistry> registry;
-    return registry;
-}
-
-NetworkBlobRegistry::NetworkBlobRegistry()
-{
-}
+NetworkBlobRegistry::NetworkBlobRegistry() = default;
+NetworkBlobRegistry::~NetworkBlobRegistry() = default;
 
 void NetworkBlobRegistry::registerFileBlobURL(NetworkConnectionToWebProcess& connection, const URL& url, const String& path, RefPtr<SandboxExtension>&& sandboxExtension, const String& contentType)
 {
-    blobRegistry().registerFileBlobURL(url, BlobDataFileReferenceWithSandboxExtension::create(path, WTFMove(sandboxExtension)), contentType);
+    m_blobRegistry.registerFileBlobURL(url, BlobDataFileReferenceWithSandboxExtension::create(path, WTFMove(sandboxExtension)), contentType);
 
     ASSERT(!m_blobsForConnection.get(&connection).contains(url));
     BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(&connection);
@@ -61,7 +53,7 @@ void NetworkBlobRegistry::registerFileBlobURL(NetworkConnectionToWebProcess& con
 
 void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess& connection, const URL& url, Vector<WebCore::BlobPart>&& blobParts, const String& contentType)
 {
-    blobRegistry().registerBlobURL(url, WTFMove(blobParts), contentType);
+    m_blobRegistry.registerBlobURL(url, WTFMove(blobParts), contentType);
 
     ASSERT(!m_blobsForConnection.get(&connection).contains(url));
     BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(&connection);
@@ -80,7 +72,7 @@ void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess& connect
         mapIterator = m_blobsForConnection.add(&connection, HashSet<URL>()).iterator;
     }
 
-    blobRegistry().registerBlobURL(url, srcURL);
+    m_blobRegistry.registerBlobURL(url, srcURL);
 
     ASSERT(shouldBypassConnectionCheck || mapIterator->value.contains(srcURL));
     mapIterator->value.add(url);
@@ -88,7 +80,7 @@ void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess& connect
 
 void NetworkBlobRegistry::registerBlobURLOptionallyFileBacked(NetworkConnectionToWebProcess& connection, const URL& url, const URL& srcURL, const String& fileBackedPath, const String& contentType)
 {
-    blobRegistry().registerBlobURLOptionallyFileBacked(url, srcURL, BlobDataFileReferenceWithSandboxExtension::create(fileBackedPath, nullptr), contentType);
+    m_blobRegistry.registerBlobURLOptionallyFileBacked(url, srcURL, BlobDataFileReferenceWithSandboxExtension::create(fileBackedPath, nullptr), contentType);
 
     ASSERT(!m_blobsForConnection.get(&connection).contains(url));
     BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(&connection);
@@ -104,7 +96,7 @@ void NetworkBlobRegistry::registerBlobURLForSlice(NetworkConnectionToWebProcess&
     if (mapIterator == m_blobsForConnection.end())
         return;
 
-    blobRegistry().registerBlobURLForSlice(url, srcURL, start, end);
+    m_blobRegistry.registerBlobURLForSlice(url, srcURL, start, end);
 
     ASSERT(mapIterator->value.contains(srcURL));
     mapIterator->value.add(url);
@@ -117,7 +109,7 @@ void NetworkBlobRegistry::unregisterBlobURL(NetworkConnectionToWebProcess& conne
     if (mapIterator == m_blobsForConnection.end())
         return;
 
-    blobRegistry().unregisterBlobURL(url);
+    m_blobRegistry.unregisterBlobURL(url);
 
     mapIterator->value.remove(url);
 }
@@ -127,17 +119,17 @@ uint64_t NetworkBlobRegistry::blobSize(NetworkConnectionToWebProcess& connection
     if (!m_blobsForConnection.contains(&connection) || !m_blobsForConnection.find(&connection)->value.contains(url))
         return 0;
 
-    return blobRegistry().blobSize(url);
+    return m_blobRegistry.blobSize(url);
 }
 
 void NetworkBlobRegistry::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
 {
-    blobRegistry().writeBlobsToTemporaryFiles(blobURLs, WTFMove(completionHandler));
+    m_blobRegistry.writeBlobsToTemporaryFiles(blobURLs, WTFMove(completionHandler));
 }
 
 void NetworkBlobRegistry::writeBlobToFilePath(const URL& blobURL, const String& path, CompletionHandler<void(bool success)>&& completionHandler)
 {
-    if (!blobRegistry().isBlobRegistryImpl()) {
+    if (!m_blobRegistry.isBlobRegistryImpl()) {
         completionHandler(false);
         ASSERT_NOT_REACHED();
         return;
@@ -147,7 +139,7 @@ void NetworkBlobRegistry::writeBlobToFilePath(const URL& blobURL, const String&
     for (auto& file : blobFiles)
         file->prepareForFileAccess();
 
-    static_cast<BlobRegistryImpl&>(blobRegistry()).writeBlobToFilePath(blobURL, path, [blobFiles = WTFMove(blobFiles), completionHandler = WTFMove(completionHandler)] (bool success) mutable {
+    m_blobRegistry.writeBlobToFilePath(blobURL, path, [blobFiles = WTFMove(blobFiles), completionHandler = WTFMove(completionHandler)] (bool success) mutable {
         for (auto& file : blobFiles)
             file->revokeFileAccess();
         completionHandler(success);
@@ -161,7 +153,7 @@ void NetworkBlobRegistry::connectionToWebProcessDidClose(NetworkConnectionToWebP
 
     HashSet<URL>& blobsForConnection = m_blobsForConnection.find(&connection)->value;
     for (HashSet<URL>::iterator iter = blobsForConnection.begin(), end = blobsForConnection.end(); iter != end; ++iter)
-        blobRegistry().unregisterBlobURL(*iter);
+        m_blobRegistry.unregisterBlobURL(*iter);
 
     m_blobsForConnection.remove(&connection);
 }
@@ -176,8 +168,8 @@ Vector<RefPtr<BlobDataFileReference>> NetworkBlobRegistry::filesInBlob(NetworkCo
 
 Vector<RefPtr<BlobDataFileReference>> NetworkBlobRegistry::filesInBlob(const URL& url)
 {
-    ASSERT(blobRegistry().isBlobRegistryImpl());
-    BlobData* blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(url);
+    ASSERT(m_blobRegistry.isBlobRegistryImpl());
+    BlobData* blobData = m_blobRegistry.getBlobDataFromURL(url);
     if (!blobData)
         return { };
 
index 74d61bb..b64cfed 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <WebCore/BlobRegistryImpl.h>
 #include <wtf/Function.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
@@ -44,7 +45,7 @@ class NetworkBlobRegistry {
 WTF_MAKE_NONCOPYABLE(NetworkBlobRegistry);
 public:
     NetworkBlobRegistry();
-    static NetworkBlobRegistry& singleton();
+    ~NetworkBlobRegistry();
 
     void registerFileBlobURL(NetworkConnectionToWebProcess&, const URL&, const String& path, RefPtr<SandboxExtension>&&, const String& contentType);
     void registerBlobURL(NetworkConnectionToWebProcess&, const URL&, Vector<WebCore::BlobPart>&&, const String& contentType);
@@ -60,12 +61,13 @@ public:
 
     Vector<RefPtr<WebCore::BlobDataFileReference>> filesInBlob(NetworkConnectionToWebProcess&, const URL&);
     Vector<RefPtr<WebCore::BlobDataFileReference>> filesInBlob(const URL&);
+    
+    WebCore::BlobRegistryImpl& blobRegistry() { return m_blobRegistry; }
 
 private:
-    ~NetworkBlobRegistry();
-
     typedef HashMap<NetworkConnectionToWebProcess*, HashSet<URL>> BlobForConnectionMap;
     BlobForConnectionMap m_blobsForConnection;
+    WebCore::BlobRegistryImpl m_blobRegistry;
 };
 
 }
index b20c645..b9828dc 100644 (file)
@@ -26,9 +26,9 @@
 #include "config.h"
 #include "NetworkConnectionToWebProcess.h"
 
+#include "BlobDataFileReferenceWithSandboxExtension.h"
 #include "CacheStorageEngineConnectionMessages.h"
 #include "DataReference.h"
-#include "NetworkBlobRegistry.h"
 #include "NetworkCache.h"
 #include "NetworkMDNSRegisterMessages.h"
 #include "NetworkProcess.h"
@@ -249,7 +249,7 @@ void NetworkConnectionToWebProcess::didClose(IPC::Connection& connection)
     // root activity trackers.
     stopAllNetworkActivityTracking();
 
-    NetworkBlobRegistry::singleton().connectionToWebProcessDidClose(*this);
+    m_networkProcess->networkBlobRegistry().connectionToWebProcessDidClose(*this);
     m_networkProcess->removeNetworkConnectionToWebProcess(*this);
 
 #if USE(LIBWEBRTC)
@@ -311,6 +311,20 @@ void NetworkConnectionToWebProcess::endSuspension()
 #endif
 }
 
+Vector<RefPtr<WebCore::BlobDataFileReference>> NetworkConnectionToWebProcess::resolveBlobReferences(const NetworkResourceLoadParameters& parameters)
+{
+    Vector<RefPtr<WebCore::BlobDataFileReference>> files;
+    if (auto* body = parameters.request.httpBody()) {
+        for (auto& element : body->elements()) {
+            if (auto* blobData = WTF::get_if<FormDataElement::EncodedBlobData>(element.data))
+                files.appendVector(m_networkProcess->networkBlobRegistry().filesInBlob(*this, blobData->url));
+        }
+        const_cast<WebCore::ResourceRequest&>(parameters.request).setHTTPBody(body->resolveBlobReferences(m_networkProcess->networkBlobRegistry().blobRegistry()));
+    }
+
+    return files;
+}
+
 void NetworkConnectionToWebProcess::scheduleResourceLoad(NetworkResourceLoadParameters&& loadParameters)
 {
     auto identifier = loadParameters.identifier;
@@ -342,7 +356,7 @@ void NetworkConnectionToWebProcess::loadPing(NetworkResourceLoadParameters&& loa
     };
 
     // PingLoad manages its own lifetime, deleting itself when its purpose has been fulfilled.
-    new PingLoad(networkProcess(), WTFMove(loadParameters), WTFMove(completionHandler));
+    new PingLoad(*this, networkProcess(), WTFMove(loadParameters), WTFMove(completionHandler));
 }
 
 void NetworkConnectionToWebProcess::setOnLineState(bool isOnLine)
@@ -391,6 +405,8 @@ void NetworkConnectionToWebProcess::prefetchDNS(const String& hostname)
 
 void NetworkConnectionToWebProcess::preconnectTo(uint64_t preconnectionIdentifier, NetworkResourceLoadParameters&& parameters)
 {
+    ASSERT(!parameters.request.httpBody());
+    
 #if ENABLE(SERVER_PRECONNECT)
     new PreconnectTask(networkProcess(), WTFMove(parameters), [this, protectedThis = makeRef(*this), identifier = preconnectionIdentifier] (const ResourceError& error) {
         didFinishPreconnection(identifier, error);
@@ -493,57 +509,65 @@ void NetworkConnectionToWebProcess::deleteCookie(PAL::SessionID sessionID, const
 
 void NetworkConnectionToWebProcess::registerFileBlobURL(const URL& url, const String& path, SandboxExtension::Handle&& extensionHandle, const String& contentType)
 {
-    RefPtr<SandboxExtension> extension = SandboxExtension::create(WTFMove(extensionHandle));
-
-    NetworkBlobRegistry::singleton().registerFileBlobURL(*this, url, path, WTFMove(extension), contentType);
+    m_networkProcess->networkBlobRegistry().registerFileBlobURL(*this, url, path, SandboxExtension::create(WTFMove(extensionHandle)), contentType);
 }
 
 void NetworkConnectionToWebProcess::registerBlobURL(const URL& url, Vector<BlobPart>&& blobParts, const String& contentType)
 {
-    NetworkBlobRegistry::singleton().registerBlobURL(*this, url, WTFMove(blobParts), contentType);
+    m_networkProcess->networkBlobRegistry().registerBlobURL(*this, url, WTFMove(blobParts), contentType);
 }
 
 void NetworkConnectionToWebProcess::registerBlobURLFromURL(const URL& url, const URL& srcURL, bool shouldBypassConnectionCheck)
 {
-    NetworkBlobRegistry::singleton().registerBlobURL(*this, url, srcURL, shouldBypassConnectionCheck);
+    m_networkProcess->networkBlobRegistry().registerBlobURL(*this, url, srcURL, shouldBypassConnectionCheck);
 }
 
 void NetworkConnectionToWebProcess::registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, const String& fileBackedPath, const String& contentType)
 {
-    NetworkBlobRegistry::singleton().registerBlobURLOptionallyFileBacked(*this, url, srcURL, fileBackedPath, contentType);
+    m_networkProcess->networkBlobRegistry().registerBlobURLOptionallyFileBacked(*this, url, srcURL, fileBackedPath, contentType);
 }
 
 void NetworkConnectionToWebProcess::registerBlobURLForSlice(const URL& url, const URL& srcURL, int64_t start, int64_t end)
 {
-    NetworkBlobRegistry::singleton().registerBlobURLForSlice(*this, url, srcURL, start, end);
+    m_networkProcess->networkBlobRegistry().registerBlobURLForSlice(*this, url, srcURL, start, end);
 }
 
 void NetworkConnectionToWebProcess::unregisterBlobURL(const URL& url)
 {
-    NetworkBlobRegistry::singleton().unregisterBlobURL(*this, url);
+    m_networkProcess->networkBlobRegistry().unregisterBlobURL(*this, url);
 }
 
 void NetworkConnectionToWebProcess::blobSize(const URL& url, uint64_t& resultSize)
 {
-    resultSize = NetworkBlobRegistry::singleton().blobSize(*this, url);
+    resultSize = m_networkProcess->networkBlobRegistry().blobSize(*this, url);
 }
 
 void NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
 {
     Vector<RefPtr<BlobDataFileReference>> fileReferences;
     for (auto& url : blobURLs)
-        fileReferences.appendVector(NetworkBlobRegistry::singleton().filesInBlob(*this, { { }, url }));
+        fileReferences.appendVector(m_networkProcess->networkBlobRegistry().filesInBlob(*this, { { }, url }));
 
     for (auto& file : fileReferences)
         file->prepareForFileAccess();
 
-    NetworkBlobRegistry::singleton().writeBlobsToTemporaryFiles(blobURLs, [fileReferences = WTFMove(fileReferences), completionHandler = WTFMove(completionHandler)](auto&& fileNames) mutable {
+    m_networkProcess->networkBlobRegistry().writeBlobsToTemporaryFiles(blobURLs, [fileReferences = WTFMove(fileReferences), completionHandler = WTFMove(completionHandler)](auto&& fileNames) mutable {
         for (auto& file : fileReferences)
             file->revokeFileAccess();
         completionHandler(WTFMove(fileNames));
     });
 }
 
+Vector<RefPtr<WebCore::BlobDataFileReference>> NetworkConnectionToWebProcess::filesInBlob(const URL& url)
+{
+    return m_networkProcess->networkBlobRegistry().filesInBlob(*this, url);
+}
+
+WebCore::BlobRegistryImpl& NetworkConnectionToWebProcess::blobRegistry()
+{
+    return m_networkProcess->networkBlobRegistry().blobRegistry();
+}
+
 void NetworkConnectionToWebProcess::setCaptureExtraNetworkLoadMetricsEnabled(bool enabled)
 {
     m_captureExtraNetworkLoadMetricsEnabled = enabled;
index b820258..a3cae88 100644 (file)
@@ -41,6 +41,7 @@ class SessionID;
 
 namespace WebCore {
 class BlobDataFileReference;
+class BlobRegistryImpl;
 class ResourceError;
 class ResourceRequest;
 struct SameSiteInfo;
@@ -121,6 +122,10 @@ public:
     Optional<NetworkActivityTracker> startTrackingResourceLoad(uint64_t pageID, ResourceLoadIdentifier resourceID, bool isMainResource, const PAL::SessionID&);
     void stopTrackingResourceLoad(ResourceLoadIdentifier resourceID, NetworkActivityTracker::CompletionCode);
 
+    WebCore::BlobRegistryImpl& blobRegistry();
+    Vector<RefPtr<WebCore::BlobDataFileReference>> filesInBlob(const URL&);
+    Vector<RefPtr<WebCore::BlobDataFileReference>> resolveBlobReferences(const NetworkResourceLoadParameters&);
+
 private:
     NetworkConnectionToWebProcess(NetworkProcess&, IPC::Connection::Identifier);
 
index 0c8b97e..c69d650 100644 (file)
@@ -47,9 +47,7 @@ using namespace WebCore;
 
 Ref<NetworkDataTask> NetworkDataTask::create(NetworkSession& session, NetworkDataTaskClient& client, const NetworkLoadParameters& parameters)
 {
-    if (parameters.request.url().protocolIsBlob())
-        return NetworkDataTaskBlob::create(session, client, parameters.request, parameters.contentSniffingPolicy, parameters.blobFileReferences);
-
+    ASSERT(!parameters.request.url().protocolIsBlob());
 #if PLATFORM(COCOA)
     return NetworkDataTaskCocoa::create(session, client, parameters.request, parameters.webFrameID, parameters.webPageID, parameters.storedCredentialsPolicy, parameters.contentSniffingPolicy, parameters.contentEncodingSniffingPolicy, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect, parameters.shouldPreconnectOnly, parameters.isMainFrameNavigation, parameters.networkActivityTracker);
 #endif
index df2afec..a6db241 100644 (file)
@@ -65,7 +65,7 @@ static const char* httpInternalErrorText = "Internal Server Error";
 
 static const char* const webKitBlobResourceDomain = "WebKitBlobResource";
 
-NetworkDataTaskBlob::NetworkDataTaskBlob(NetworkSession& session, NetworkDataTaskClient& client, const ResourceRequest& request, ContentSniffingPolicy shouldContentSniff, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
+NetworkDataTaskBlob::NetworkDataTaskBlob(NetworkSession& session, BlobRegistryImpl& blobRegistry, NetworkDataTaskClient& client, const ResourceRequest& request, ContentSniffingPolicy shouldContentSniff, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
     : NetworkDataTask(session, client, request, StoredCredentialsPolicy::DoNotUse, false, false)
     , m_stream(std::make_unique<AsyncFileStream>(*this))
     , m_fileReferences(fileReferences)
@@ -74,7 +74,7 @@ NetworkDataTaskBlob::NetworkDataTaskBlob(NetworkSession& session, NetworkDataTas
     for (auto& fileReference : m_fileReferences)
         fileReference->prepareForFileAccess();
 
-    m_blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(request.url());
+    m_blobData = blobRegistry.getBlobDataFromURL(request.url());
 
     m_session->registerNetworkDataTask(*this);
     LOG(NetworkSession, "%p - Created NetworkDataTaskBlob for %s", this, request.url().string().utf8().data());
index eb79447..7df999f 100644 (file)
@@ -40,6 +40,7 @@ class AsyncFileStream;
 class BlobDataFileReference;
 class BlobData;
 class BlobDataItem;
+class BlobRegistryImpl;
 }
 
 namespace WebKit {
@@ -48,15 +49,15 @@ class NetworkProcess;
 
 class NetworkDataTaskBlob final : public NetworkDataTask, public WebCore::FileStreamClient {
 public:
-    static Ref<NetworkDataTask> create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, WebCore::ContentSniffingPolicy shouldContentSniff, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
+    static Ref<NetworkDataTask> create(NetworkSession& session, WebCore::BlobRegistryImpl& blobRegistry, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, WebCore::ContentSniffingPolicy shouldContentSniff, const Vector<RefPtr<WebCore::BlobDataFileReference>>& fileReferences)
     {
-        return adoptRef(*new NetworkDataTaskBlob(session, client, request, shouldContentSniff, fileReferences));
+        return adoptRef(*new NetworkDataTaskBlob(session, blobRegistry, client, request, shouldContentSniff, fileReferences));
     }
 
     ~NetworkDataTaskBlob();
 
 private:
-    NetworkDataTaskBlob(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::ContentSniffingPolicy, const Vector<RefPtr<WebCore::BlobDataFileReference>>&);
+    NetworkDataTaskBlob(NetworkSession&, WebCore::BlobRegistryImpl&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::ContentSniffingPolicy, const Vector<RefPtr<WebCore::BlobDataFileReference>>&);
 
     void suspend() override;
     void cancel() override;
index f16f055..b0b1414 100644 (file)
@@ -50,19 +50,23 @@ struct NetworkLoad::Throttle {
     ResponseCompletionHandler responseCompletionHandler;
 };
 
-NetworkLoad::NetworkLoad(NetworkLoadClient& client, NetworkLoadParameters&& parameters, NetworkSession& networkSession)
+NetworkLoad::NetworkLoad(NetworkLoadClient& client, BlobRegistryImpl* blobRegistry, NetworkLoadParameters&& parameters, NetworkSession& networkSession)
     : m_client(client)
     , m_networkProcess(networkSession.networkProcess())
     , m_parameters(WTFMove(parameters))
     , m_loadThrottleLatency(networkSession.loadThrottleLatency())
     , m_currentRequest(m_parameters.request)
 {
-    initialize(networkSession);
+    initialize(networkSession, blobRegistry);
 }
 
-void NetworkLoad::initialize(NetworkSession& networkSession)
+void NetworkLoad::initialize(NetworkSession& networkSession, WebCore::BlobRegistryImpl* blobRegistry)
 {
-    m_task = NetworkDataTask::create(networkSession, *this, m_parameters);
+    if (blobRegistry && m_parameters.request.url().protocolIsBlob())
+        m_task = NetworkDataTaskBlob::create(networkSession, *blobRegistry, *this, m_parameters.request, m_parameters.contentSniffingPolicy, m_parameters.blobFileReferences);
+    else
+        m_task = NetworkDataTask::create(networkSession, *this, m_parameters);
+
     if (!m_parameters.defersLoading)
         m_task->resume();
 }
index ee3d933..019dd73 100644 (file)
 #include <wtf/CompletionHandler.h>
 #include <wtf/text/WTFString.h>
 
+namespace WebCore {
+class BlobRegistryImpl;
+}
+
 namespace WebKit {
 
 class NetworkProcess;
@@ -40,7 +44,7 @@ class NetworkProcess;
 class NetworkLoad final : private NetworkDataTaskClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    NetworkLoad(NetworkLoadClient&, NetworkLoadParameters&&, NetworkSession&);
+    NetworkLoad(NetworkLoadClient&, WebCore::BlobRegistryImpl*, NetworkLoadParameters&&, NetworkSession&);
     ~NetworkLoad();
 
     void setDefersLoading(bool);
@@ -65,7 +69,7 @@ public:
     String description() const;
 
 private:
-    void initialize(NetworkSession&);
+    void initialize(NetworkSession&, WebCore::BlobRegistryImpl*);
 
     // NetworkDataTaskClient
     void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) final;
index 1d41472..e4e4828 100644 (file)
@@ -37,7 +37,6 @@
 #include "LegacyCustomProtocolManager.h"
 #endif
 #include "Logging.h"
-#include "NetworkBlobRegistry.h"
 #include "NetworkConnectionToWebProcess.h"
 #include "NetworkContentRuleListManagerMessages.h"
 #include "NetworkProcessCreationParameters.h"
@@ -150,9 +149,10 @@ NetworkProcess::NetworkProcess(AuxiliaryProcessInitializationParameters&& parame
     });
 #endif
 
-    NetworkStateNotifier::singleton().addListener([this](bool isOnLine) {
-        auto webProcessConnections = m_webProcessConnections;
-        for (auto& webProcessConnection : webProcessConnections)
+    NetworkStateNotifier::singleton().addListener([weakThis = makeWeakPtr(*this)](bool isOnLine) {
+        if (!weakThis)
+            return;
+        for (auto& webProcessConnection : weakThis->m_webProcessConnections)
             webProcessConnection->setOnLineState(isOnLine);
     });
 
@@ -186,10 +186,10 @@ NetworkProximityManager& NetworkProcess::proximityManager()
 
 void NetworkProcess::removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess& connection)
 {
-    size_t vectorIndex = m_webProcessConnections.find(&connection);
-    ASSERT(vectorIndex != notFound);
-
-    m_webProcessConnections.remove(vectorIndex);
+    auto count = m_webProcessConnections.removeAllMatching([&] (const auto& c) {
+        return c.ptr() == &connection;
+    });
+    ASSERT_UNUSED(count, count == 1);
 }
 
 bool NetworkProcess::shouldTerminate()
index 3a129c5..d369e8a 100644 (file)
@@ -28,6 +28,7 @@
 #include "AuxiliaryProcess.h"
 #include "CacheModel.h"
 #include "DownloadManager.h"
+#include "NetworkBlobRegistry.h"
 #include "NetworkContentRuleListManager.h"
 #include "NetworkHTTPSUpgradeChecker.h"
 #include "SandboxExtension.h"
@@ -291,6 +292,8 @@ public:
     void removeCacheEngine(const PAL::SessionID&);
     void requestCacheStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
 
+    NetworkBlobRegistry& networkBlobRegistry() { return m_networkBlobRegistry; }
+
 private:
     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
     std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
@@ -422,7 +425,7 @@ private:
     void ensurePathExists(const String& path);
 
     // Connections to WebProcesses.
-    Vector<RefPtr<NetworkConnectionToWebProcess>> m_webProcessConnections;
+    Vector<Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
 
     String m_diskCacheDirectory;
     bool m_hasSetCacheModel { false };
@@ -445,6 +448,7 @@ private:
     HashMap<PAL::SessionID, Ref<NetworkSession>> m_networkSessions;
     HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
     mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
+    NetworkBlobRegistry m_networkBlobRegistry;
 
 #if PLATFORM(COCOA)
     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
index 60ee591..f234e29 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "NetworkProcessPlatformStrategies.h"
 
-#include <WebCore/BlobRegistryImpl.h>
+#include <WebCore/BlobRegistry.h>
 #include <wtf/NeverDestroyed.h>
 
 namespace WebKit {
@@ -50,7 +50,20 @@ PasteboardStrategy* NetworkProcessPlatformStrategies::createPasteboardStrategy()
 
 BlobRegistry* NetworkProcessPlatformStrategies::createBlobRegistry()
 {
-    return new BlobRegistryImpl;
+    using namespace WebCore;
+    class EmptyBlobRegistry : public WebCore::BlobRegistry {
+        void registerFileBlobURL(const URL&, Ref<BlobDataFileReference>&&, const String& contentType) final { ASSERT_NOT_REACHED(); }
+        void registerBlobURL(const URL&, Vector<BlobPart>&&, const String& contentType) final { ASSERT_NOT_REACHED(); }
+        void registerBlobURL(const URL&, const URL& srcURL) final { ASSERT_NOT_REACHED(); }
+        void registerBlobURLOptionallyFileBacked(const URL&, const URL& srcURL, RefPtr<BlobDataFileReference>&&, const String& contentType) final { ASSERT_NOT_REACHED(); }
+        void registerBlobURLForSlice(const URL&, const URL& srcURL, long long start, long long end) final { ASSERT_NOT_REACHED(); }
+        void unregisterBlobURL(const URL&) final { ASSERT_NOT_REACHED(); }
+        unsigned long long blobSize(const URL&) final { ASSERT_NOT_REACHED(); return 0; }
+        void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&) final { ASSERT_NOT_REACHED(); }
+        bool isBlobRegistryImpl() const { return false; }
+    };
+    static NeverDestroyed<EmptyBlobRegistry> blobRegistry;
+    return &blobRegistry.get();
 }
 
 }
index 34624a1..48cbdda 100644 (file)
@@ -29,7 +29,6 @@
 #include "DataReference.h"
 #include "FormDataReference.h"
 #include "Logging.h"
-#include "NetworkBlobRegistry.h"
 #include "NetworkCache.h"
 #include "NetworkConnectionToWebProcess.h"
 #include "NetworkLoad.h"
@@ -92,6 +91,7 @@ static void sendReplyToSynchronousRequest(NetworkResourceLoader::SynchronousLoad
 NetworkResourceLoader::NetworkResourceLoader(NetworkResourceLoadParameters&& parameters, NetworkConnectionToWebProcess& connection, Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply&& synchronousReply)
     : m_parameters { WTFMove(parameters) }
     , m_connection { connection }
+    , m_fileReferences(connection.resolveBlobReferences(m_parameters))
     , m_defersLoading { parameters.defersLoading }
     , m_isAllowedToAskUserForCredentials { m_parameters.clientCredentialPolicy == ClientCredentialPolicy::MayAskClientForCredentials }
     , m_bufferingTimer { *this, &NetworkResourceLoader::bufferingTimerFired }
@@ -103,13 +103,6 @@ NetworkResourceLoader::NetworkResourceLoader(NetworkResourceLoadParameters&& par
     //        Once bug 116233 is resolved, this ASSERT can just be "m_webPageID && m_webFrameID"
     ASSERT((m_parameters.webPageID && m_parameters.webFrameID) || m_parameters.clientCredentialPolicy == ClientCredentialPolicy::CannotAskClientForCredentials);
 
-    if (originalRequest().httpBody()) {
-        for (const auto& element : originalRequest().httpBody()->elements()) {
-            if (auto* blobData = WTF::get_if<FormDataElement::EncodedBlobData>(element.data))
-                m_fileReferences.appendVector(NetworkBlobRegistry::singleton().filesInBlob(connection, blobData->url));
-        }
-    }
-
     if (synchronousReply || parameters.shouldRestrictHTTPResponseAccess) {
         NetworkLoadChecker::LoadType requestLoadType = isMainFrameLoad() ? NetworkLoadChecker::LoadType::MainFrame : NetworkLoadChecker::LoadType::Other;
         m_networkLoadChecker = std::make_unique<NetworkLoadChecker>(connection.networkProcess(), FetchOptions { m_parameters.options }, m_parameters.sessionID, m_parameters.webPageID, m_parameters.webFrameID, HTTPHeaderMap { m_parameters.originalRequestHeaders }, URL { m_parameters.request.url() }, m_parameters.sourceOrigin.copyRef(), m_parameters.preflightPolicy, originalRequest().httpReferrer(), m_parameters.isHTTPSUpgradeEnabled, shouldCaptureExtraNetworkLoadMetrics(), requestLoadType);
@@ -128,6 +121,7 @@ NetworkResourceLoader::~NetworkResourceLoader()
     ASSERT(RunLoop::isMain());
     ASSERT(!m_networkLoad);
     ASSERT(!isSynchronous() || !m_synchronousLoadData->delayedReply);
+    ASSERT(m_fileReferences.isEmpty());
     if (m_responseCompletionHandler)
         m_responseCompletionHandler(PolicyAction::Ignore);
 }
@@ -282,7 +276,7 @@ void NetworkResourceLoader::startNetworkLoad(ResourceRequest&& request, FirstLoa
         parameters.storedCredentialsPolicy = m_networkLoadChecker->storedCredentialsPolicy();
 
     if (request.url().protocolIsBlob())
-        parameters.blobFileReferences = NetworkBlobRegistry::singleton().filesInBlob(m_connection, originalRequest().url());
+        parameters.blobFileReferences = m_connection->filesInBlob(originalRequest().url());
 
     auto* networkSession = m_connection->networkProcess().networkSession(parameters.sessionID);
     if (!networkSession && parameters.sessionID.isEphemeral()) {
@@ -298,7 +292,7 @@ void NetworkResourceLoader::startNetworkLoad(ResourceRequest&& request, FirstLoa
     }
 
     parameters.request = WTFMove(request);
-    m_networkLoad = std::make_unique<NetworkLoad>(*this, WTFMove(parameters), *networkSession);
+    m_networkLoad = std::make_unique<NetworkLoad>(*this, &m_connection->blobRegistry(), WTFMove(parameters), *networkSession);
 
     RELEASE_LOG_IF_ALLOWED("startNetworkLoad: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ", description = %{public}s)", m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier, m_networkLoad->description().utf8().data());
 
index fb5414c..29685e7 100644 (file)
@@ -29,6 +29,7 @@
 #include "AuthenticationChallengeDisposition.h"
 #include "AuthenticationManager.h"
 #include "Logging.h"
+#include "NetworkConnectionToWebProcess.h"
 #include "NetworkLoadChecker.h"
 #include "NetworkProcess.h"
 #include "WebErrors.h"
@@ -39,12 +40,18 @@ namespace WebKit {
 
 using namespace WebCore;
 
-PingLoad::PingLoad(NetworkProcess& networkProcess, NetworkResourceLoadParameters&& parameters, CompletionHandler<void(const ResourceError&, const ResourceResponse&)>&& completionHandler)
+PingLoad::PingLoad(NetworkConnectionToWebProcess& connection, NetworkProcess& networkProcess, NetworkResourceLoadParameters&& parameters, CompletionHandler<void(const ResourceError&, const ResourceResponse&)>&& completionHandler)
     : m_parameters(WTFMove(parameters))
     , m_completionHandler(WTFMove(completionHandler))
     , m_timeoutTimer(*this, &PingLoad::timeoutTimerFired)
     , m_networkLoadChecker(makeUniqueRef<NetworkLoadChecker>(networkProcess, FetchOptions { m_parameters.options}, m_parameters.sessionID, m_parameters.webPageID, m_parameters.webFrameID, WTFMove(m_parameters.originalRequestHeaders), URL { m_parameters.request.url() }, m_parameters.sourceOrigin.copyRef(), m_parameters.preflightPolicy, m_parameters.request.httpReferrer()))
+    , m_blobFiles(connection.resolveBlobReferences(m_parameters))
 {
+    for (auto& file : m_blobFiles) {
+        if (file)
+            file->prepareForFileAccess();
+    }
+
     m_networkLoadChecker->enableContentExtensionsCheck();
     if (m_parameters.cspResponseHeaders)
         m_networkLoadChecker->setCSPResponseHeaders(WTFMove(m_parameters.cspResponseHeaders.value()));
@@ -79,6 +86,10 @@ PingLoad::~PingLoad()
         m_task->clearClient();
         m_task->cancel();
     }
+    for (auto& file : m_blobFiles) {
+        if (file)
+            file->revokeFileAccess();
+    }
 }
 
 void PingLoad::didFinish(const ResourceError& error, const ResourceResponse& response)
index c375d5e..c4a097e 100644 (file)
@@ -40,7 +40,7 @@ class NetworkProcess;
 
 class PingLoad final : public CanMakeWeakPtr<PingLoad>, private NetworkDataTaskClient {
 public:
-    PingLoad(NetworkProcess&, NetworkResourceLoadParameters&&, CompletionHandler<void(const WebCore::ResourceError&, const WebCore::ResourceResponse&)>&&);
+    PingLoad(NetworkConnectionToWebProcess&, NetworkProcess&, NetworkResourceLoadParameters&&, CompletionHandler<void(const WebCore::ResourceError&, const WebCore::ResourceResponse&)>&&);
     
 private:
     ~PingLoad();
@@ -66,6 +66,7 @@ private:
     RefPtr<NetworkDataTask> m_task;
     WebCore::Timer m_timeoutTimer;
     UniqueRef<NetworkLoadChecker> m_networkLoadChecker;
+    Vector<RefPtr<WebCore::BlobDataFileReference>> m_blobFiles;
 };
 
 }
index a6e2993..d90ccca 100644 (file)
@@ -53,7 +53,7 @@ PreconnectTask::PreconnectTask(NetworkProcess& networkProcess, NetworkLoadParame
     }
 
     ASSERT(parameters.shouldPreconnectOnly == PreconnectOnly::Yes);
-    m_networkLoad = std::make_unique<NetworkLoad>(*this, WTFMove(parameters), *networkSession);
+    m_networkLoad = std::make_unique<NetworkLoad>(*this, nullptr, WTFMove(parameters), *networkSession);
 
     m_timeoutTimer.startOneShot(60000_s);
 }
index 7156fd6..e7fc5b8 100644 (file)
@@ -60,7 +60,7 @@ SpeculativeLoad::SpeculativeLoad(Cache& cache, const GlobalFrameID& globalFrameI
     parameters.contentSniffingPolicy = ContentSniffingPolicy::DoNotSniffContent;
     parameters.contentEncodingSniffingPolicy = ContentEncodingSniffingPolicy::Sniff;
     parameters.request = m_originalRequest;
-    m_networkLoad = std::make_unique<NetworkLoad>(*this, WTFMove(parameters), *cache.networkProcess().networkSession(PAL::SessionID::defaultSessionID()));
+    m_networkLoad = std::make_unique<NetworkLoad>(*this, nullptr, WTFMove(parameters), *cache.networkProcess().networkSession(PAL::SessionID::defaultSessionID()));
 }
 
 SpeculativeLoad::~SpeculativeLoad()