Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Unified Diff: Source/core/fileapi/Blob.cpp

Issue 157363003: Implement Blob.close(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/fileapi/Blob.h ('k') | Source/core/fileapi/Blob.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fileapi/Blob.cpp
diff --git a/Source/core/fileapi/Blob.cpp b/Source/core/fileapi/Blob.cpp
index 4fa8e1f947b7f35a4758164e9c749141686ff264..ddca8af746aef8afc4a1dcdb19c1dbfa3de18c9e 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/DOMURL.h"
+#include "core/dom/ExecutionContext.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(&registrableObject->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,25 @@ 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.
+ DOMURL::revokeObjectUUID(executionContext, 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.
+ // FIXME: spec not yet set in stone in this regard, track updates to it (http://crbug.com/344820.)
+ OwnPtr<BlobData> blobData = BlobData::create();
+ blobData->setContentType(type());
+ m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0);
+ m_hasBeenClosed = true;
+ }
+}
+
void Blob::appendTo(BlobData& blobData) const
{
blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size());
@@ -121,5 +144,4 @@ URLRegistry& Blob::registry() const
return BlobURLRegistry::registry();
}
-
} // namespace WebCore
« no previous file with comments | « Source/core/fileapi/Blob.h ('k') | Source/core/fileapi/Blob.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698