Chromium Code Reviews| Index: Source/core/fileapi/Blob.cpp |
| diff --git a/Source/core/fileapi/Blob.cpp b/Source/core/fileapi/Blob.cpp |
| index 4fa8e1f947b7f35a4758164e9c749141686ff264..e2eb4de8beca604018a4d1e861493410e02cbfa6 100644 |
| --- a/Source/core/fileapi/Blob.cpp |
| +++ b/Source/core/fileapi/Blob.cpp |
| @@ -31,6 +31,8 @@ |
| #include "config.h" |
| #include "core/fileapi/Blob.h" |
| +#include "core/dom/ExecutionContext.h" |
| +#include "core/html/PublicURLManager.h" |
| #include "platform/blob/BlobRegistry.h" |
| #include "platform/blob/BlobURL.h" |
| @@ -46,10 +48,11 @@ public: |
| static URLRegistry& registry(); |
| }; |
| -void BlobURLRegistry::registerURL(SecurityOrigin* origin, const KURL& publicURL, URLRegistrable* blob) |
| +void BlobURLRegistry::registerURL(SecurityOrigin* origin, const KURL& publicURL, URLRegistrable* registrableObject) |
| { |
| - ASSERT(&blob->registry() == this); |
| - BlobRegistry::registerPublicBlobURL(origin, publicURL, static_cast<Blob*>(blob)->blobDataHandle()); |
| + ASSERT(®istrableObject->registry() == this); |
| + Blob* blob = static_cast<Blob*>(registrableObject); |
| + BlobRegistry::registerPublicBlobURL(origin, publicURL, blob->blobDataHandle()); |
| } |
| void BlobURLRegistry::unregisterURL(const KURL& publicURL) |
| @@ -67,6 +70,7 @@ URLRegistry& BlobURLRegistry::registry() |
| Blob::Blob(PassRefPtr<BlobDataHandle> dataHandle) |
| : m_blobDataHandle(dataHandle) |
| + , m_hasBeenClosed(false) |
| { |
| ScriptWrappable::init(this); |
| } |
| @@ -111,6 +115,24 @@ PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte |
| return Blob::create(BlobDataHandle::create(blobData.release(), length)); |
| } |
| +void Blob::close(ExecutionContext* executionContext) |
| +{ |
| + if (!hasBeenClosed()) { |
| + // Dereferencing a Blob that has been closed should result in |
| + // a network error. Revoke URLs registered against it through |
| + // its UUID. |
| + executionContext->publicURLManager().revoke(uuid()); |
| + |
| + // A closed Blob should have size zero, which most consumers |
| + // will treat as an empty Blob. The exception being the FileReader |
| + // read operations which will throw. |
| + OwnPtr<BlobData> blobData = BlobData::create(); |
| + blobData->setContentType(type()); |
| + m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0); |
|
michaeln
2014/02/12 20:33:04
nice and safe :)
|
| + m_hasBeenClosed = true; |
| + } |
| +} |
| + |
| void Blob::appendTo(BlobData& blobData) const |
| { |
| blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); |
| @@ -121,5 +143,4 @@ URLRegistry& Blob::registry() const |
| return BlobURLRegistry::registry(); |
| } |
| - |
| } // namespace WebCore |