diff options
| author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
|---|---|---|
| committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
| commit | a4e969f4965059196ca948db781e52f7cfebf19e (patch) | |
| tree | 6ca352808c8fdc52006a0f33f6ae3c593b23867d /Source/WebKit2/NetworkProcess/FileAPI | |
| parent | 41386e9cb918eed93b3f13648cbef387e371e451 (diff) | |
| download | WebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz | |
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Source/WebKit2/NetworkProcess/FileAPI')
| -rw-r--r-- | Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp | 103 | ||||
| -rw-r--r-- | Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h | 19 |
2 files changed, 76 insertions, 46 deletions
diff --git a/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp b/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp index a2ac7d124..025e2fc65 100644 --- a/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp +++ b/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp @@ -26,20 +26,20 @@ #include "config.h" #include "NetworkBlobRegistry.h" -#if ENABLE(BLOB) && ENABLE(NETWORK_PROCESS) - +#include "BlobDataFileReferenceWithSandboxExtension.h" #include "SandboxExtension.h" +#include <WebCore/BlobPart.h> #include <WebCore/BlobRegistryImpl.h> -#include <wtf/MainThread.h> #include <wtf/NeverDestroyed.h> +#include <wtf/RunLoop.h> using namespace WebCore; namespace WebKit { -NetworkBlobRegistry& NetworkBlobRegistry::shared() +NetworkBlobRegistry& NetworkBlobRegistry::singleton() { - ASSERT(isMainThread()); + ASSERT(RunLoop::isMain()); static NeverDestroyed<NetworkBlobRegistry> registry; return registry; } @@ -48,22 +48,20 @@ NetworkBlobRegistry::NetworkBlobRegistry() { } -void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connection, const URL& url, std::unique_ptr<BlobData> data, const Vector<RefPtr<SandboxExtension>>& newSandboxExtensions) +void NetworkBlobRegistry::registerFileBlobURL(NetworkConnectionToWebProcess* connection, const URL& url, const String& path, RefPtr<SandboxExtension>&& sandboxExtension, const String& contentType) { - ASSERT(!m_sandboxExtensions.contains(url.string())); - - // Combine new extensions for File items and existing extensions for inner Blob items. - Vector<RefPtr<SandboxExtension>> sandboxExtensions = newSandboxExtensions; - const BlobDataItemList& items = data->items(); - for (size_t i = 0, count = items.size(); i < count; ++i) { - if (items[i].type == BlobDataItem::Blob) - sandboxExtensions.appendVector(m_sandboxExtensions.get(items[i].url.string())); - } + blobRegistry().registerFileBlobURL(url, BlobDataFileReferenceWithSandboxExtension::create(path, sandboxExtension), contentType); - blobRegistry().registerBlobURL(url, std::move(data)); + ASSERT(!m_blobsForConnection.get(connection).contains(url)); + BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(connection); + if (mapIterator == m_blobsForConnection.end()) + mapIterator = m_blobsForConnection.add(connection, HashSet<URL>()).iterator; + mapIterator->value.add(url); +} - if (!sandboxExtensions.isEmpty()) - m_sandboxExtensions.add(url.string(), sandboxExtensions); +void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connection, const URL& url, Vector<WebCore::BlobPart> blobParts, const String& contentType) +{ + blobRegistry().registerBlobURL(url, WTFMove(blobParts), contentType); ASSERT(!m_blobsForConnection.get(connection).contains(url)); BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(connection); @@ -74,24 +72,49 @@ void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connect void NetworkBlobRegistry::registerBlobURL(NetworkConnectionToWebProcess* connection, const WebCore::URL& url, const WebCore::URL& srcURL) { + // The connection may not be registered if NetworkProcess prevously crashed for any reason. + BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(connection); + if (mapIterator == m_blobsForConnection.end()) + return; + blobRegistry().registerBlobURL(url, srcURL); - SandboxExtensionMap::iterator iter = m_sandboxExtensions.find(srcURL.string()); - if (iter != m_sandboxExtensions.end()) - m_sandboxExtensions.add(url.string(), iter->value); - ASSERT(m_blobsForConnection.contains(connection)); - ASSERT(m_blobsForConnection.find(connection)->value.contains(srcURL)); - m_blobsForConnection.find(connection)->value.add(url); + ASSERT(mapIterator->value.contains(srcURL)); + mapIterator->value.add(url); +} + +void NetworkBlobRegistry::registerBlobURLForSlice(NetworkConnectionToWebProcess* connection, const WebCore::URL& url, const WebCore::URL& srcURL, int64_t start, int64_t end) +{ + // The connection may not be registered if NetworkProcess prevously crashed for any reason. + BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(connection); + if (mapIterator == m_blobsForConnection.end()) + return; + + blobRegistry().registerBlobURLForSlice(url, srcURL, start, end); + + ASSERT(mapIterator->value.contains(srcURL)); + mapIterator->value.add(url); } void NetworkBlobRegistry::unregisterBlobURL(NetworkConnectionToWebProcess* connection, const WebCore::URL& url) { + // The connection may not be registered if NetworkProcess prevously crashed for any reason. + BlobForConnectionMap::iterator mapIterator = m_blobsForConnection.find(connection); + if (mapIterator == m_blobsForConnection.end()) + return; + blobRegistry().unregisterBlobURL(url); - m_sandboxExtensions.remove(url.string()); - ASSERT(m_blobsForConnection.contains(connection)); - ASSERT(m_blobsForConnection.find(connection)->value.contains(url)); - m_blobsForConnection.find(connection)->value.remove(url); + ASSERT(mapIterator->value.contains(url)); + mapIterator->value.remove(url); +} + +uint64_t NetworkBlobRegistry::blobSize(NetworkConnectionToWebProcess* connection, const WebCore::URL& url) +{ + if (!m_blobsForConnection.contains(connection) || !m_blobsForConnection.find(connection)->value.contains(url)) + return 0; + + return blobRegistry().blobSize(url); } void NetworkBlobRegistry::connectionToWebProcessDidClose(NetworkConnectionToWebProcess* connection) @@ -100,19 +123,29 @@ void NetworkBlobRegistry::connectionToWebProcessDidClose(NetworkConnectionToWebP return; HashSet<URL>& blobsForConnection = m_blobsForConnection.find(connection)->value; - for (HashSet<URL>::iterator iter = blobsForConnection.begin(), end = blobsForConnection.end(); iter != end; ++iter) { + for (HashSet<URL>::iterator iter = blobsForConnection.begin(), end = blobsForConnection.end(); iter != end; ++iter) blobRegistry().unregisterBlobURL(*iter); - m_sandboxExtensions.remove(*iter); - } m_blobsForConnection.remove(connection); } -const Vector<RefPtr<SandboxExtension>> NetworkBlobRegistry::sandboxExtensions(const WebCore::URL& url) +Vector<RefPtr<BlobDataFileReference>> NetworkBlobRegistry::filesInBlob(NetworkConnectionToWebProcess& connection, const WebCore::URL& url) { - return m_sandboxExtensions.get(url.string()); -} + if (!m_blobsForConnection.contains(&connection) || !m_blobsForConnection.find(&connection)->value.contains(url)) + return Vector<RefPtr<BlobDataFileReference>>(); + + ASSERT(blobRegistry().isBlobRegistryImpl()); + BlobData* blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(url); + if (!blobData) + return Vector<RefPtr<BlobDataFileReference>>(); + + Vector<RefPtr<BlobDataFileReference>> result; + for (const BlobDataItem& item : blobData->items()) { + if (item.type() == BlobDataItem::Type::File) + result.append(item.file()); + } + return result; } -#endif +} diff --git a/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h b/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h index 16c6adb09..4adde415d 100644 --- a/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h +++ b/Source/WebKit2/NetworkProcess/FileAPI/NetworkBlobRegistry.h @@ -26,14 +26,13 @@ #ifndef NetworkBlobRegistry_h #define NetworkBlobRegistry_h -#if ENABLE(BLOB) && ENABLE(NETWORK_PROCESS) - #include <WebCore/URLHash.h> #include <wtf/HashMap.h> #include <wtf/HashSet.h> namespace WebCore { -class BlobData; +class BlobDataFileReference; +class BlobPart; } namespace WebKit { @@ -45,28 +44,26 @@ class NetworkBlobRegistry { WTF_MAKE_NONCOPYABLE(NetworkBlobRegistry); public: NetworkBlobRegistry(); - static NetworkBlobRegistry& shared(); + static NetworkBlobRegistry& singleton(); - void registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&, std::unique_ptr<WebCore::BlobData>, const Vector<RefPtr<SandboxExtension>>&); + void registerFileBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&, const String& path, RefPtr<SandboxExtension>&&, const String& contentType); + void registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&, Vector<WebCore::BlobPart>, const String& contentType); void registerBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&, const WebCore::URL& srcURL); + void registerBlobURLForSlice(NetworkConnectionToWebProcess*, const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end); void unregisterBlobURL(NetworkConnectionToWebProcess*, const WebCore::URL&); + uint64_t blobSize(NetworkConnectionToWebProcess*, const WebCore::URL&); void connectionToWebProcessDidClose(NetworkConnectionToWebProcess*); - const Vector<RefPtr<SandboxExtension>> sandboxExtensions(const WebCore::URL&); + Vector<RefPtr<WebCore::BlobDataFileReference>> filesInBlob(NetworkConnectionToWebProcess&, const WebCore::URL&); private: ~NetworkBlobRegistry(); - typedef HashMap<String, Vector<RefPtr<SandboxExtension>>> SandboxExtensionMap; - SandboxExtensionMap m_sandboxExtensions; - typedef HashMap<NetworkConnectionToWebProcess*, HashSet<WebCore::URL>> BlobForConnectionMap; BlobForConnectionMap m_blobsForConnection; }; } -#endif // ENABLE(BLOB) && ENABLE(NETWORK_PROCESS) - #endif // NetworkBlobRegistry_h |
